block: ublk: switch to ioctl command encoding
Subsystems (2)
PATCH v3 1/1 block: ublk: switch to ioctl command encoding
All ublk commands(control, IO) should have taken ioctl command encoding from the beginning, because ioctl command encoding defines each code uniquely, so driver can figure out wrong command sent from userspace easily; 2) it might help security subsystem for audit uring cmd[1].
Unfortunately we didn't do that way, and it could be one lesson for ublk driver.
So switch to ioctl command encoding now, we still support commands encoded in old way, but they become legacy definition. Any new command should take ioctl encoding.
See ublksrv code for switching to ioctl command encoding in [2].
[1] https://lore.kernel.org/io-uring/CAHC9VhSVzujW9LOj5Km80AjU0EfAuukoLrxO6BEfnXeK_s6bAg@mail.gmail.com/
[2] https://github.com/ming1/ubdsrv/commits/ioctl_cmd_encoding
---
V3:
- rename config option to BLKDEV_UBLK_LEGACY_OPCODES, suggested by Christoph
- add helper of ublk_check_cmd_op()
- commit log style & patch style change
V2:
- simplify implementation
- add config option of BLK_DEV_UBLK_NO_OLD_CMD, suggested by Christoph
- improve commit log, and fix typo
drivers/block/Kconfig | 17 +++++++++++++ drivers/block/ublk_drv.c | 47 +++++++++++++++++++++++++---------- include/uapi/linux/ublk_cmd.h | 43 ++++++++++++++++++++++++++++++++ 3 files changed, 94 insertions(+), 13 deletions(-)
drivers/block/Kconfig +17 -0
@@ -385,6 +385,23 @@ config BLK_DEV_UBLK can handle batch more effectively, but task_work_add() isn't exported for module, so ublk has to be built to kernel. +config BLKDEV_UBLK_LEGACY_OPCODES + bool "Support legacy command opcode" + depends on BLK_DEV_UBLK + default y + help + ublk driver started to take plain command encoding, which turns out + one bad way. The traditional ioctl command opcode encodes more + info and basically defines each code uniquely, so opcode conflict + is avoided, and driver can handle wrong command easily, meantime it + may help security subsystem to audit io_uring command. + + Say Y if your application still uses legacy command opcode. + + Say N if you don't want to support legacy command opcode. It is + suggested to enable N if your application(ublk server) switches to + ioctl command encoding. + source "drivers/block/rnbd/Kconfig" endif # BLK_DEV
drivers/block/ublk_drv.c +34 -13
105 lines not on this page · raw message
include/uapi/linux/ublk_cmd.h +43 -0
71 lines not on this page · raw message
Signature · 1 line
2.38.1
Looks good:
Quoted 9 lines · Ming Lei
All ublk
commands(control, IO)should have taken ioctl command encoding from the beginning, because ioctl command encoding defines each code uniquely, so driver can figure out wrong command sent from userspace easily; 2) it might help security subsystem for audit uring cmd[1].Unfortunately we didn't do that way, and it could be one lesson for ublk driver.
[...]
Applied, thanks!
[1/1] block: ublk: switch to ioctl command encoding
commit: 2d786e66c9662d84cbeab981ce3a371d2fb5a4bb
Best regards,
Signature · 1 line
Jens Axboe