Skip to content
This repository was archived by the owner on Oct 31, 2024. It is now read-only.

Commit 8f3d568

Browse files
Ming Leigregkh
Ming Lei
authored andcommittedOct 22, 2024
ublk: don't allow user copy for unprivileged device
commit 42aafd8 upstream. 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> Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
1 parent d28b256 commit 8f3d568

File tree

2 files changed

+17
-2
lines changed

2 files changed

+17
-2
lines changed
 

‎drivers/block/ublk_drv.c

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

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

‎include/uapi/linux/ublk_cmd.h

+7-1
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)
This repository has been archived.