All of lore.kernel.org
 help / color / mirror / Atom feed
From: Tuo Li <islituo@gmail.com>
To: kbusch@kernel.org, axboe@fb.com, hch@lst.de, sagi@grimberg.me
Cc: linux-nvme@lists.infradead.org, linux-kernel@vger.kernel.org,
	baijiaju1990@gmail.com, Tuo Li <islituo@gmail.com>,
	TOTE Robot <oslab@tsinghua.edu.cn>
Subject: [PATCH] lightnvm: fix possible uninitialized-variable access in nvme_nvm_submit_user_cmd()
Date: Sat, 31 Jul 2021 00:30:42 -0700	[thread overview]
Message-ID: <20210731073042.49139-1-islituo@gmail.com> (raw)

The variable metadata_dma is not initialized at the beginning of the
function nvme_nvm_submit_user_cmd(). If the parameter ubuf is NULL, it
remains uninitialized at the label err_meta. However, it is accessed
through the function dma_pool_free() if meta_buf is not NULL and
meta_len is not zero. In fact, ubuf, meta_buf and meta_len can come from
user space which indicates this can happen.

To fix this possible bug, only when ubuf and meta_buf are not NULL, and
bufflen and meta_len are not zero, the function dma_pool_free() is
called.

Reported-by: TOTE Robot <oslab@tsinghua.edu.cn>
Signed-off-by: Tuo Li <islituo@gmail.com>
---
 drivers/nvme/host/lightnvm.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/nvme/host/lightnvm.c b/drivers/nvme/host/lightnvm.c
index e9d9ad47f70f..3d9fd098bd83 100644
--- a/drivers/nvme/host/lightnvm.c
+++ b/drivers/nvme/host/lightnvm.c
@@ -835,7 +835,7 @@ static int nvme_nvm_submit_user_cmd(struct request_queue *q,
 			ret = -EFAULT;
 	}
 err_meta:
-	if (meta_buf && meta_len)
+	if (ubuf && bufflen && meta_buf && meta_len)
 		dma_pool_free(dev->dma_pool, metadata, metadata_dma);
 err_map:
 	if (bio)
-- 
2.25.1


_______________________________________________
Linux-nvme mailing list
Linux-nvme@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-nvme

WARNING: multiple messages have this Message-ID (diff)
From: Tuo Li <islituo@gmail.com>
To: kbusch@kernel.org, axboe@fb.com, hch@lst.de, sagi@grimberg.me
Cc: linux-nvme@lists.infradead.org, linux-kernel@vger.kernel.org,
	baijiaju1990@gmail.com, Tuo Li <islituo@gmail.com>,
	TOTE Robot <oslab@tsinghua.edu.cn>
Subject: [PATCH] lightnvm: fix possible uninitialized-variable access in nvme_nvm_submit_user_cmd()
Date: Sat, 31 Jul 2021 00:30:42 -0700	[thread overview]
Message-ID: <20210731073042.49139-1-islituo@gmail.com> (raw)

The variable metadata_dma is not initialized at the beginning of the
function nvme_nvm_submit_user_cmd(). If the parameter ubuf is NULL, it
remains uninitialized at the label err_meta. However, it is accessed
through the function dma_pool_free() if meta_buf is not NULL and
meta_len is not zero. In fact, ubuf, meta_buf and meta_len can come from
user space which indicates this can happen.

To fix this possible bug, only when ubuf and meta_buf are not NULL, and
bufflen and meta_len are not zero, the function dma_pool_free() is
called.

Reported-by: TOTE Robot <oslab@tsinghua.edu.cn>
Signed-off-by: Tuo Li <islituo@gmail.com>
---
 drivers/nvme/host/lightnvm.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/nvme/host/lightnvm.c b/drivers/nvme/host/lightnvm.c
index e9d9ad47f70f..3d9fd098bd83 100644
--- a/drivers/nvme/host/lightnvm.c
+++ b/drivers/nvme/host/lightnvm.c
@@ -835,7 +835,7 @@ static int nvme_nvm_submit_user_cmd(struct request_queue *q,
 			ret = -EFAULT;
 	}
 err_meta:
-	if (meta_buf && meta_len)
+	if (ubuf && bufflen && meta_buf && meta_len)
 		dma_pool_free(dev->dma_pool, metadata, metadata_dma);
 err_map:
 	if (bio)
-- 
2.25.1


             reply	other threads:[~2021-07-31  7:31 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-07-31  7:30 Tuo Li [this message]
2021-07-31  7:30 ` [PATCH] lightnvm: fix possible uninitialized-variable access in nvme_nvm_submit_user_cmd() Tuo Li

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20210731073042.49139-1-islituo@gmail.com \
    --to=islituo@gmail.com \
    --cc=axboe@fb.com \
    --cc=baijiaju1990@gmail.com \
    --cc=hch@lst.de \
    --cc=kbusch@kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-nvme@lists.infradead.org \
    --cc=oslab@tsinghua.edu.cn \
    --cc=sagi@grimberg.me \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.