[PATCH openEuler-1.0-LTS] nvme: sanitize metadata bounce buffer for reads

From: Keith Busch <kbusch@kernel.org> mainline inclusion from mainline-v6.1-rc1 commit 2b32c76e2b0154b98b9322ae7546b8156cd703e6 category: bugfix bugzilla: https://gitee.com/src-openeuler/kernel/issues/I8UJF0 CVE: NA Reference: https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/commit/?i... ---------------------------------------- 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") 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> Conflicts: Commit 2405252a680e ("nvme: move the ioctl code to a separate file") move nvme_add_user_metadata() from drivers/nvme/host/core.c to drivers/nvme/host/ioctl.c; Commit 38c0ddab7b93 ("nvme: refactor nvme_add_user_metadata") changed to use REQ_OP_DRV_OUT to identify the write request. Signed-off-by: Li Lingfeng <lilingfeng3@huawei.com> --- drivers/nvme/host/core.c | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/drivers/nvme/host/core.c b/drivers/nvme/host/core.c index 151ab076822b..b4d8aa84b744 100644 --- a/drivers/nvme/host/core.c +++ b/drivers/nvme/host/core.c @@ -856,9 +856,13 @@ static void *nvme_add_user_metadata(struct bio *bio, void __user *ubuf, if (!buf) goto out; - ret = -EFAULT; - if (write && copy_from_user(buf, ubuf, len)) - goto out_free_meta; + if (write) { + 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)) { -- 2.31.1

反馈: 您发送到kernel@openeuler.org的补丁/补丁集,已成功转换为PR! PR链接地址: https://gitee.com/openeuler/kernel/pulls/3864 邮件列表地址:https://mailweb.openeuler.org/hyperkitty/list/kernel@openeuler.org/message/7... FeedBack: The patch(es) which you have sent to kernel@openeuler.org mailing list has been converted to a pull request successfully! Pull request link: https://gitee.com/openeuler/kernel/pulls/3864 Mailing list address: https://mailweb.openeuler.org/hyperkitty/list/kernel@openeuler.org/message/7...
participants (2)
-
Li Lingfeng
-
patchwork bot