* [PATCH] drivers: nvme: target: core: deref after null
@ 2024-06-07 13:43 Alexander Sapozhnikov
2024-06-10 4:34 ` Chaitanya Kulkarni
` (2 more replies)
0 siblings, 3 replies; 4+ messages in thread
From: Alexander Sapozhnikov @ 2024-06-07 13:43 UTC (permalink / raw)
To: Christoph Hellwig, Sagi Grimberg, Chaitanya Kulkarni
Cc: Alexandr Sapozhnikov, linux-nvme, linux-kernel, lvc-project
From: Alexandr Sapozhnikov <alsp705@gmail.com>
After having been compared to a NULL value at core.c:813,
pointer '(**sq->ctrl).sqs' is dereferenced at core.c:838.
Found by Linux Verification Center (linuxtesting.org) with SVACE.
Signed-off-by: Alexandr Sapozhnikov <alsp705@gmail.com>
---
drivers/nvme/target/core.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/drivers/nvme/target/core.c b/drivers/nvme/target/core.c
index 06f0c587f343..5a67d2bc0c55 100644
--- a/drivers/nvme/target/core.c
+++ b/drivers/nvme/target/core.c
@@ -827,7 +827,7 @@ void nvmet_sq_destroy(struct nvmet_sq *sq)
*/
ctrl = sq->ctrl;
- if (ctrl) {
+ if (ctrl && ctrl->sqs) {
/*
* The teardown flow may take some time, and the host may not
* send us keep-alive during this period, hence reset the
--
2.39.2
^ permalink raw reply related [flat|nested] 4+ messages in thread
* Re: [PATCH] drivers: nvme: target: core: deref after null
2024-06-07 13:43 [PATCH] drivers: nvme: target: core: deref after null Alexander Sapozhnikov
@ 2024-06-10 4:34 ` Chaitanya Kulkarni
2024-06-10 6:54 ` Markus Elfring
2024-06-10 10:02 ` Sagi Grimberg
2 siblings, 0 replies; 4+ messages in thread
From: Chaitanya Kulkarni @ 2024-06-10 4:34 UTC (permalink / raw)
To: Alexander Sapozhnikov
Cc: linux-nvme@lists.infradead.org, Chaitanya Kulkarni, Sagi Grimberg,
linux-kernel@vger.kernel.org, Christoph Hellwig,
lvc-project@linuxtesting.org
On 6/7/24 06:43, Alexander Sapozhnikov wrote:
> From: Alexandr Sapozhnikov <alsp705@gmail.com>
>
> After having been compared to a NULL value at core.c:813,
> pointer '(**sq->ctrl).sqs' is dereferenced at core.c:838.
really didn't understand the NULL check mentioned above :-
812 */
813 if (ctrl && ctrl->sqs && ctrl->sqs[0] == sq)
814 nvmet_async_events_failall(ctrl);
from what I know it checks the non NULL ctrl->sqs and then
validates the sq is admin queue before calling failing the async
events ...
> Found by Linux Verification Center (linuxtesting.org) with SVACE.
>
> Signed-off-by: Alexandr Sapozhnikov <alsp705@gmail.com>
> ---
> drivers/nvme/target/core.c | 2 +-
> 1 file changed, 1 insertion(+), 1 deletion(-)
>
> diff --git a/drivers/nvme/target/core.c b/drivers/nvme/target/core.c
> index 06f0c587f343..5a67d2bc0c55 100644
> --- a/drivers/nvme/target/core.c
> +++ b/drivers/nvme/target/core.c
> @@ -827,7 +827,7 @@ void nvmet_sq_destroy(struct nvmet_sq *sq)
> */
> ctrl = sq->ctrl;
>
> - if (ctrl) {
> + if (ctrl && ctrl->sqs) {
> /*
> * The teardown flow may take some time, and the host may not
> * send us keep-alive during this period, hence reset the
do we need more fine grained check where ctrl->sqs is actually
accessed :-
diff --git a/drivers/nvme/target/core.c b/drivers/nvme/target/core.c
index 06f0c587f343..a70cad5a6262 100644
--- a/drivers/nvme/target/core.c
+++ b/drivers/nvme/target/core.c
@@ -835,7 +835,8 @@ void nvmet_sq_destroy(struct nvmet_sq *sq)
* controller teardown as a result of a keep-alive
expiration.
*/
ctrl->reset_tbkas = true;
- sq->ctrl->sqs[sq->qid] = NULL;
+ if (sq->ctrl->sqs)
+ sq->ctrl->sqs[sq->qid] = NULL;
nvmet_ctrl_put(ctrl);
sq->ctrl = NULL; /* allows reusing the queue later */
}
-ck
^ permalink raw reply related [flat|nested] 4+ messages in thread
* Re: [PATCH] drivers: nvme: target: core: deref after null
2024-06-07 13:43 [PATCH] drivers: nvme: target: core: deref after null Alexander Sapozhnikov
2024-06-10 4:34 ` Chaitanya Kulkarni
@ 2024-06-10 6:54 ` Markus Elfring
2024-06-10 10:02 ` Sagi Grimberg
2 siblings, 0 replies; 4+ messages in thread
From: Markus Elfring @ 2024-06-10 6:54 UTC (permalink / raw)
To: Alexandr Sapozhnikov, linux-nvme, lvc-project, Chaitanya Kulkarni,
Christoph Hellwig, Sagi Grimberg
Cc: LKML
> After having been compared to a NULL value at core.c:813,
> pointer '(**sq->ctrl).sqs' is dereferenced at core.c:838.
* Please choose another imperative wording for an improved change description.
https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/tree/Documentation/process/submitting-patches.rst?h=v6.10-rc2#n94
* Would you like to add the tag “Fixes” accordingly?
* How do you think about to use the summary phrase “Avoid null pointer dereference
in nvmet_sq_destroy()”?
* Is the subsystem specification “nvmet” more appropriate?
Regards,
Markus
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [PATCH] drivers: nvme: target: core: deref after null
2024-06-07 13:43 [PATCH] drivers: nvme: target: core: deref after null Alexander Sapozhnikov
2024-06-10 4:34 ` Chaitanya Kulkarni
2024-06-10 6:54 ` Markus Elfring
@ 2024-06-10 10:02 ` Sagi Grimberg
2 siblings, 0 replies; 4+ messages in thread
From: Sagi Grimberg @ 2024-06-10 10:02 UTC (permalink / raw)
To: Alexander Sapozhnikov, Christoph Hellwig, Chaitanya Kulkarni
Cc: linux-nvme, linux-kernel, lvc-project
On 07/06/2024 16:43, Alexander Sapozhnikov wrote:
> From: Alexandr Sapozhnikov <alsp705@gmail.com>
>
> After having been compared to a NULL value at core.c:813,
> pointer '(**sq->ctrl).sqs' is dereferenced at core.c:838.
>
> Found by Linux Verification Center (linuxtesting.org) with SVACE.
>
> Signed-off-by: Alexandr Sapozhnikov <alsp705@gmail.com>
> ---
> drivers/nvme/target/core.c | 2 +-
> 1 file changed, 1 insertion(+), 1 deletion(-)
>
> diff --git a/drivers/nvme/target/core.c b/drivers/nvme/target/core.c
> index 06f0c587f343..5a67d2bc0c55 100644
> --- a/drivers/nvme/target/core.c
> +++ b/drivers/nvme/target/core.c
> @@ -827,7 +827,7 @@ void nvmet_sq_destroy(struct nvmet_sq *sq)
> */
> ctrl = sq->ctrl;
>
> - if (ctrl) {
> + if (ctrl && ctrl->sqs) {
> /*
> * The teardown flow may take some time, and the host may not
> * send us keep-alive during this period, hence reset the
This is a redundant check. sq->ctrl and sq->ctrl->sqs have the same
lifetime. If
sq->ctrl was assigned, it means that it was allocated and needs a final
put to
fully cleanup. ctrl->sqs is allocated in nvmet_alloc_ctrl and freed in
nvmet_free_ctrl
which is the final reference.
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2024-06-10 10:02 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2024-06-07 13:43 [PATCH] drivers: nvme: target: core: deref after null Alexander Sapozhnikov
2024-06-10 4:34 ` Chaitanya Kulkarni
2024-06-10 6:54 ` Markus Elfring
2024-06-10 10:02 ` Sagi Grimberg
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox