Skip to content

Commit 42aafd8

Browse files
Ming Leiaxboe
authored andcommitted
ublk: don't allow user copy for unprivileged device
UBLK_F_USER_COPY requires userspace to call write() on ublk char device for filling request buffer, and unprivileged device can't be trusted. So don't allow user copy for unprivileged device. Cc: stable@vger.kernel.org Fixes: 1172d5b ("ublk: support user copy") Signed-off-by: Ming Lei <ming.lei@redhat.com> Link: https://lore.kernel.org/r/20241016134847.2911721-1-ming.lei@redhat.com Signed-off-by: Jens Axboe <axboe@kernel.dk>
1 parent e972b08 commit 42aafd8

File tree

2 files changed

+17
-2
lines changed

2 files changed

+17
-2
lines changed

drivers/block/ublk_drv.c

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2380,10 +2380,19 @@ static int ublk_ctrl_add_dev(struct io_uring_cmd *cmd)
23802380
* TODO: provide forward progress for RECOVERY handler, so that
23812381
* unprivileged device can benefit from it
23822382
*/
2383-
if (info.flags & UBLK_F_UNPRIVILEGED_DEV)
2383+
if (info.flags & UBLK_F_UNPRIVILEGED_DEV) {
23842384
info.flags &= ~(UBLK_F_USER_RECOVERY_REISSUE |
23852385
UBLK_F_USER_RECOVERY);
23862386

2387+
/*
2388+
* For USER_COPY, we depends on userspace to fill request
2389+
* buffer by pwrite() to ublk char device, which can't be
2390+
* used for unprivileged device
2391+
*/
2392+
if (info.flags & UBLK_F_USER_COPY)
2393+
return -EINVAL;
2394+
}
2395+
23872396
/* the created device is always owned by current user */
23882397
ublk_store_owner_uid_gid(&info.owner_uid, &info.owner_gid);
23892398

include/uapi/linux/ublk_cmd.h

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -175,7 +175,13 @@
175175
/* use ioctl encoding for uring command */
176176
#define UBLK_F_CMD_IOCTL_ENCODE (1UL << 6)
177177

178-
/* Copy between request and user buffer by pread()/pwrite() */
178+
/*
179+
* Copy between request and user buffer by pread()/pwrite()
180+
*
181+
* Not available for UBLK_F_UNPRIVILEGED_DEV, otherwise userspace may
182+
* deceive us by not filling request buffer, then kernel uninitialized
183+
* data may be leaked.
184+
*/
179185
#define UBLK_F_USER_COPY (1UL << 7)
180186

181187
/*

0 commit comments

Comments
 (0)