Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

ublk: check recovery flags for validity

Setting UBLK_F_USER_RECOVERY_REISSUE without also setting
UBLK_F_USER_RECOVERY is currently silently equivalent to not setting any
recovery flags at all, even though that's obviously not intended. Check
for this case and fail add_dev (with a paranoid warning to aid debugging
any program which might rely on the old behavior) with EINVAL if it is
detected.

Signed-off-by: Uday Shankar <ushankar@purestorage.com>
Reviewed-by: Ming Lei <ming.lei@redhat.com>
Link: https://lore.kernel.org/r/20241007182419.3263186-2-ushankar@purestorage.com
Signed-off-by: Jens Axboe <axboe@kernel.dk>

authored by

Uday Shankar and committed by
Jens Axboe
d00c0ea1 110234da

+11
+11
drivers/block/ublk_drv.c
··· 62 62 | UBLK_F_USER_COPY \ 63 63 | UBLK_F_ZONED) 64 64 65 + #define UBLK_F_ALL_RECOVERY_FLAGS (UBLK_F_USER_RECOVERY \ 66 + | UBLK_F_USER_RECOVERY_REISSUE) 67 + 65 68 /* All UBLK_PARAM_TYPE_* should be included here */ 66 69 #define UBLK_PARAM_TYPE_ALL \ 67 70 (UBLK_PARAM_TYPE_BASIC | UBLK_PARAM_TYPE_DISCARD | \ ··· 2374 2371 info.flags &= ~UBLK_F_UNPRIVILEGED_DEV; 2375 2372 else if (!(info.flags & UBLK_F_UNPRIVILEGED_DEV)) 2376 2373 return -EPERM; 2374 + 2375 + /* forbid nonsense combinations of recovery flags */ 2376 + if ((info.flags & UBLK_F_USER_RECOVERY_REISSUE) && 2377 + !(info.flags & UBLK_F_USER_RECOVERY)) { 2378 + pr_warn("%s: invalid recovery flags %llx\n", __func__, 2379 + info.flags & UBLK_F_ALL_RECOVERY_FLAGS); 2380 + return -EINVAL; 2381 + } 2377 2382 2378 2383 /* 2379 2384 * unprivileged device can't be trusted, but RECOVERY and