Skip to content

Commit 2b32c76

Browse files
committed
nvme: sanitize metadata bounce buffer for reads
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: 0b7f1f2 ("nvme: use the block layer for userspace passthrough metadata") Reviewed-by: Jens Axboe <axboe@kernel.dk> Reviewed-by: Christoph Hellwig <hch@lst.de> Reviewed-by: Kanchan Joshi <joshi.k@samsung.com> Reviewed-by: Chaitanya Kulkarni <kch@nvidia.com> Signed-off-by: Keith Busch <kbusch@kernel.org>
1 parent 4ae55a7 commit 2b32c76

1 file changed

Lines changed: 7 additions & 3 deletions

File tree

drivers/nvme/host/ioctl.c

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -108,9 +108,13 @@ static void *nvme_add_user_metadata(struct request *req, void __user *ubuf,
108108
if (!buf)
109109
goto out;
110110

111-
ret = -EFAULT;
112-
if ((req_op(req) == REQ_OP_DRV_OUT) && copy_from_user(buf, ubuf, len))
113-
goto out_free_meta;
111+
if (req_op(req) == REQ_OP_DRV_OUT) {
112+
ret = -EFAULT;
113+
if (copy_from_user(buf, ubuf, len))
114+
goto out_free_meta;
115+
} else {
116+
memset(buf, 0, len);
117+
}
114118

115119
bip = bio_integrity_alloc(bio, GFP_KERNEL, 1);
116120
if (IS_ERR(bip)) {

0 commit comments

Comments
 (0)