nvme: sanitize metadata bounce buffer for reads
PATCH 1/1 nvme: sanitize metadata bounce buffer for reads
From: Keith Busch <[email protected]>
User can request more metadata bytes than the device will write. Ensure kernel buffer is initialized so we're not leaking unsanitized memory on the copy-out.
--- drivers/nvme/host/ioctl.c | 2 ++ 1 file changed, 2 insertions(+)
drivers/nvme/host/ioctl.c +2 -0
@@ -39,6 +39,8 @@ static void *nvme_add_user_metadata(struct request *req, void __user *ubuf, ret = -EFAULT ;if ((req_op (req) ==REQ_OP_DRV_OUT ) &©_from_user (buf, ubuf, len)) goto out_free_meta; +else +memset (buf,0 , len); bip =bio_integrity_alloc (bio,GFP_KERNEL ,1 );if (IS_ERR (bip)) {
Signature · 1 line
2.34.1
Jens Axboe
maintainerQuoted 17 lines · Keith Busch
From: Keith Busch <[email protected]>
User can request more metadata bytes than the device will write. Ensure kernel buffer is initialized so we're not leaking unsanitized memory on the copy-out.
Fixes 0b7f1f26f95a51a ("nvme: use the block layer for userspace passthrough metadata")Signed-off-by Keith Busch <[email protected]>--- drivers/nvme/host/ioctl.c | 2 ++ 1 file changed, 2 insertions(+)drivers/nvme/host/ioctl.c +0
-0
drivers/nvme/host/ioctl.c static void *nvme_add_user_metadata(struct request *req, void __user *ubuf, · line 43
Quoted 5 lines
drivers/nvme/host/ioctl.c +2
-0@@ -39,6 +39,8 @@ static void *nvme_add_user_metadata(struct request *req, void __user *ubuf, ret = -EFAULT ;if ((req_op (req) ==REQ_OP_DRV_OUT ) &©_from_user (buf, ubuf, len)) goto out_free_meta; +else +memset (buf,0 , len);
Do you need this else?
Signature · 1 line
Jens Axboe
Keith Busch
maintainerQuoted 7 lines · Jens Axboe
drivers/nvme/host/ioctl.c static void *nvme_add_user_metadata(struct request *req, void __user *ubuf, · line 43
Quoted 4 lines · Keith Busch
drivers/nvme/host/ioctl.c +2
-0if ((req_op (req) ==REQ_OP_DRV_OUT ) &©_from_user (buf, ubuf, len)) goto out_free_meta; +else +memset (buf,0 , len);Do you need this else?
The 'if' condition just above copies user data into the 'buf', so yes, we need the else to separate how buf is initialized for each direction.
Jens Axboe
maintainerQuoted 11 lines · Keith Busch
Quoted 7 lines · Jens Axboe
drivers/nvme/host/ioctl.c static void *nvme_add_user_metadata(struct request *req, void __user *ubuf, · line 43
Quoted 4 lines · Keith Busch
drivers/nvme/host/ioctl.c +2
-0if ((req_op (req) ==REQ_OP_DRV_OUT ) &©_from_user (buf, ubuf, len)) goto out_free_meta; +else +memset (buf,0 , len);Do you need this else?
The 'if' condition just above copies user data into the 'buf', so yes, we need the else to separate how buf is initialized for each direction.
It still looks wrong to me. If it's writing to the drive AND we fail copying in data, -EFAULT. But the opposite of that isn't that it's a read from device.
if (req_op(req) == REQ_OP_DRV_OUT) {
ret = -EFAULT;
if (copy_from_user(buf, ubuf, len))
goto out_free_meta;
} else {
memset(buf, 0, len);
}would look more readable, as it splits it on direction, rather than on direction and the status of the copy. And follows the normal idioms for erroring on the copy condition.
Signature · 1 line
Jens Axboe
Keith Busch
maintainerQuoted 12 lines · Jens Axboe
It still looks wrong to me. If it's writing to the drive AND we fail copying in data,
-EFAULT. But the opposite of that isn't that it's a read from device.if (req_op(req) == REQ_OP_DRV_OUT) { ret = -EFAULT; if (copy_from_user(buf, ubuf, len)) goto out_free_meta; } else { memset(buf, 0, len); }
Quoted 3 lines
would look more readable, as it splits it on direction, rather than on direction and the status of the copy. And follows the normal idioms for erroring on the copy condition.
Thanks! When you put it that way, the mistake was clear! Fixing for v2.