Skip to contentSkip to conversation

nvme: sanitize metadata bounce buffer for reads

PATCH In review Keith Busch 5 participants 5 messages Oct 16, 2023 – Oct 17, 2023 NVMe

lore
Share & tools
lore
#0 lore raw

PATCH v2 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 are not leaking unsanitized memory on the completion's copy-out.

Fixes 0b7f1f26f95a51a ("nvme: use the block layer for userspace passthrough metadata")

---
v1->v2:

correctly split data direction handling (axboe)

 drivers/nvme/host/ioctl.c | 10 +++++++---
 1 file changed, 7 insertions(+), 3 deletions(-)
drivers/nvme/host/ioctl.c +7 -3
index 788b36e7915ab..eb2ef3e149614 100644
@@ -36,9 +36,13 @@ static void *nvme_add_user_metadata(struct request *req, void __user *ubuf,
 	if (!buf)
 		goto out;
 
-	ret = -EFAULT;
-	if ((req_op(req) == REQ_OP_DRV_OUT) && copy_from_user(buf, ubuf, len))
-		goto out_free_meta;
+	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);
+	}
 
 	bip = bio_integrity_alloc(bio, GFP_KERNEL, 1);
 	if (IS_ERR(bip)) {
Signature · 1 line
2.34.1
maintainer Reviewed-by on v2 1/1
#1 lore raw
Quoted 27 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 are not leaking unsanitized memory on the completion's copy-out.

Fixes 0b7f1f26f95a51a ("nvme: use the block layer for userspace passthrough metadata")

---
v1->v2:

correctly split data direction handling (axboe)

 drivers/nvme/host/ioctl.c | 10 +++++++---
 1 file changed, 7 insertions(+), 3 deletions(-)
drivers/nvme/host/ioctl.c +0 -3
index 788b36e7915ab..eb2ef3e149614 100644
@@ -36,9 +36,13 @@ static void *nvme_add_user_metadata(struct request *req, void __user *ubuf,
 	if (!buf)
 		goto out;
 
-	ret = -EFAULT;
-	if ((req_op(req) == REQ_OP_DRV_OUT) && copy_from_user(buf, ubuf, len))
-		goto out_free_meta;

drivers/nvme/host/ioctl.c static void *nvme_add_user_metadata(struct request *req, void __user *ubuf, · line 48

Quoted 10 lines
drivers/nvme/host/ioctl.c +7 -0
+	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);
+	}
 
 	bip = bio_integrity_alloc(bio, GFP_KERNEL, 1);
 	if (IS_ERR(bip)) {
Signature · 1 line
Jens Axboe
Reviewed-by on v2 1/1
#4 lore raw
In reply to Keith Busch
Quoted 10 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 are not leaking unsanitized memory on the completion's copy-out.

Fixes 0b7f1f26f95a51a ("nvme: use the block layer for userspace passthrough metadata")

---

V2 has a fix for comment posted on v1, looks good.

-ck