This work aims to allow userspace to create and destroy block devices in a race-free way, and to allow them to be exposed to other Xen VMs via blkback without races. Changes since v1: - Several device-mapper fixes added. - The diskseq is now a separate Xenstore node, rather than being part of physical-device. - Potentially backwards-incompatible changes to device-mapper now require userspace opt-in. - The code has been tested: I have a block script written in C that uses these changes to successfully boot a Xen VM. - The core block layer is almost completely untouched. Instead of exposing a block device inode directly to userspace, device-mapper ioctls that create a block device now return that device's diskseq. Userspace can then use that diskseq to safely open the device. Furthermore, ioctls that operate on an existing device-mapper device now accept a diskseq parameter, which can be used to prevent races. There are a few changes that make device-mapper's table validation stricter. Two of them are clear-cut fixes for memory safety bugs: one prevents a misaligned pointer dereference in the kernel, and the other prevents pointer arithmetic overflow that could cause the kernel to dereference a userspace pointer, especially on 32-bit systems. One fixes a double-fetch bug that happens to be harmless right now, but would make distribution backports of subsequent patches unsafe. The remaining fixes prevent totally nonsensical tables from being accepted. This includes parameter strings that overlap the subsequent target spec, and target specs that overlap the 'struct dm_ioctl' or each other. I doubt there is any userspace extant that generates such tables. Finally, one patch forbids device-mapper devices to be named ".", "..", or "control". Since device-mapper devices are often accessed via /dev/mapper/NAME, such names would likely greatly confuse userspace. I consider this to be an extension of the existing check that prohibits device mapper names or UUIDs from containing '/'. Demi Marie Obenour (16): device-mapper: Check that target specs are sufficiently aligned device-mapper: Avoid pointer arithmetic overflow device-mapper: do not allow targets to overlap 'struct dm_ioctl' device-mapper: Better error message for too-short target spec device-mapper: Target parameters must not overlap next target spec device-mapper: Avoid double-fetch of version device-mapper: Allow userspace to opt-in to strict parameter checks device-mapper: Allow userspace to provide expected diskseq device-mapper: Allow userspace to suppress uevent generation device-mapper: Refuse to create device named "control" device-mapper: "." and ".." are not valid symlink names device-mapper: inform caller about already-existing device xen-blkback: Implement diskseq checks block, loop: Increment diskseq when releasing a loop device xen-blkback: Minor cleanups xen-blkback: Inform userspace that device has been opened block/genhd.c | 1 + drivers/block/loop.c | 6 + drivers/block/xen-blkback/blkback.c | 8 +- drivers/block/xen-blkback/xenbus.c | 147 ++++++++-- drivers/md/dm-core.h | 2 + drivers/md/dm-ioctl.c | 432 ++++++++++++++++++++++------ drivers/md/dm.c | 5 +- include/linux/device-mapper.h | 2 +- include/uapi/linux/dm-ioctl.h | 67 ++++- 9 files changed, 551 insertions(+), 119 deletions(-) -- Sincerely, Demi Marie Obenour (she/her/hers) Invisible Things Lab