* [PATCH] nvmet: Fix out-of-bounds access in nvmet_enable_port
@ 2025-04-18 8:02 Richard Weinberger
2025-04-18 8:04 ` Damien Le Moal
` (3 more replies)
0 siblings, 4 replies; 5+ messages in thread
From: Richard Weinberger @ 2025-04-18 8:02 UTC (permalink / raw)
To: linux-kernel
Cc: linux-nvme, dlemoal, kbusch, kch, sagi, hch, upstream+nvme,
Richard Weinberger
When trying to enable a port that has no transport configured yet,
nvmet_enable_port() uses NVMF_TRTYPE_MAX (255) to query the transports
array, causing an out-of-bounds access:
[ 106.058694] BUG: KASAN: global-out-of-bounds in nvmet_enable_port+0x42/0x1da
[ 106.058719] Read of size 8 at addr ffffffff89dafa58 by task ln/632
[...]
[ 106.076026] nvmet: transport type 255 not supported
Since commit 200adac75888, NVMF_TRTYPE_MAX is the default state as configured by
nvmet_ports_make().
Avoid this by checking for NVMF_TRTYPE_MAX before proceeding.
Fixes: 200adac75888 ("nvme: Add PCI transport type")
Signed-off-by: Richard Weinberger <richard@nod.at>
---
drivers/nvme/target/core.c | 3 +++
1 file changed, 3 insertions(+)
diff --git a/drivers/nvme/target/core.c b/drivers/nvme/target/core.c
index 71f8d06998d6..245475c43127 100644
--- a/drivers/nvme/target/core.c
+++ b/drivers/nvme/target/core.c
@@ -324,6 +324,9 @@ int nvmet_enable_port(struct nvmet_port *port)
lockdep_assert_held(&nvmet_config_sem);
+ if (port->disc_addr.trtype == NVMF_TRTYPE_MAX)
+ return -EINVAL;
+
ops = nvmet_transports[port->disc_addr.trtype];
if (!ops) {
up_write(&nvmet_config_sem);
--
2.48.1
^ permalink raw reply related [flat|nested] 5+ messages in thread* Re: [PATCH] nvmet: Fix out-of-bounds access in nvmet_enable_port
2025-04-18 8:02 [PATCH] nvmet: Fix out-of-bounds access in nvmet_enable_port Richard Weinberger
@ 2025-04-18 8:04 ` Damien Le Moal
2025-04-18 10:54 ` Sagi Grimberg
` (2 subsequent siblings)
3 siblings, 0 replies; 5+ messages in thread
From: Damien Le Moal @ 2025-04-18 8:04 UTC (permalink / raw)
To: Richard Weinberger, linux-kernel
Cc: linux-nvme, kbusch, kch, sagi, hch, upstream+nvme
On 4/18/25 17:02, Richard Weinberger wrote:
> When trying to enable a port that has no transport configured yet,
> nvmet_enable_port() uses NVMF_TRTYPE_MAX (255) to query the transports
> array, causing an out-of-bounds access:
>
> [ 106.058694] BUG: KASAN: global-out-of-bounds in nvmet_enable_port+0x42/0x1da
> [ 106.058719] Read of size 8 at addr ffffffff89dafa58 by task ln/632
> [...]
> [ 106.076026] nvmet: transport type 255 not supported
>
> Since commit 200adac75888, NVMF_TRTYPE_MAX is the default state as configured by
> nvmet_ports_make().
> Avoid this by checking for NVMF_TRTYPE_MAX before proceeding.
>
> Fixes: 200adac75888 ("nvme: Add PCI transport type")
> Signed-off-by: Richard Weinberger <richard@nod.at>
My bad :) Thanks for the fix !
Reviewed-by: Damien Le Moal <dlemoal@kernel.org>
--
Damien Le Moal
Western Digital Research
^ permalink raw reply [flat|nested] 5+ messages in thread* Re: [PATCH] nvmet: Fix out-of-bounds access in nvmet_enable_port
2025-04-18 8:02 [PATCH] nvmet: Fix out-of-bounds access in nvmet_enable_port Richard Weinberger
2025-04-18 8:04 ` Damien Le Moal
@ 2025-04-18 10:54 ` Sagi Grimberg
2025-04-22 6:33 ` Chaitanya Kulkarni
2025-04-22 7:50 ` Christoph Hellwig
3 siblings, 0 replies; 5+ messages in thread
From: Sagi Grimberg @ 2025-04-18 10:54 UTC (permalink / raw)
To: Richard Weinberger, linux-kernel
Cc: linux-nvme, dlemoal, kbusch, kch, hch, upstream+nvme
Reviewed-by: Sagi Grimberg <sagi@grimberg.me>
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [PATCH] nvmet: Fix out-of-bounds access in nvmet_enable_port
2025-04-18 8:02 [PATCH] nvmet: Fix out-of-bounds access in nvmet_enable_port Richard Weinberger
2025-04-18 8:04 ` Damien Le Moal
2025-04-18 10:54 ` Sagi Grimberg
@ 2025-04-22 6:33 ` Chaitanya Kulkarni
2025-04-22 7:50 ` Christoph Hellwig
3 siblings, 0 replies; 5+ messages in thread
From: Chaitanya Kulkarni @ 2025-04-22 6:33 UTC (permalink / raw)
To: Richard Weinberger, linux-kernel@vger.kernel.org
Cc: linux-nvme@lists.infradead.org, dlemoal@kernel.org,
kbusch@kernel.org, Chaitanya Kulkarni, sagi@grimberg.me,
hch@lst.de, upstream+nvme@sigma-star.at
On 4/18/25 01:02, Richard Weinberger wrote:
> When trying to enable a port that has no transport configured yet,
> nvmet_enable_port() uses NVMF_TRTYPE_MAX (255) to query the transports
> array, causing an out-of-bounds access:
>
> [ 106.058694] BUG: KASAN: global-out-of-bounds in nvmet_enable_port+0x42/0x1da
> [ 106.058719] Read of size 8 at addr ffffffff89dafa58 by task ln/632
> [...]
> [ 106.076026] nvmet: transport type 255 not supported
>
> Since commit 200adac75888, NVMF_TRTYPE_MAX is the default state as configured by
> nvmet_ports_make().
> Avoid this by checking for NVMF_TRTYPE_MAX before proceeding.
>
> Fixes: 200adac75888 ("nvme: Add PCI transport type")
> Signed-off-by: Richard Weinberger<richard@nod.at>
Looks good.
Reviewed-by: Chaitanya Kulkarni <kch@nvidia.com>
-ck
^ permalink raw reply [flat|nested] 5+ messages in thread* Re: [PATCH] nvmet: Fix out-of-bounds access in nvmet_enable_port
2025-04-18 8:02 [PATCH] nvmet: Fix out-of-bounds access in nvmet_enable_port Richard Weinberger
` (2 preceding siblings ...)
2025-04-22 6:33 ` Chaitanya Kulkarni
@ 2025-04-22 7:50 ` Christoph Hellwig
3 siblings, 0 replies; 5+ messages in thread
From: Christoph Hellwig @ 2025-04-22 7:50 UTC (permalink / raw)
To: Richard Weinberger
Cc: linux-kernel, linux-nvme, dlemoal, kbusch, kch, sagi, hch,
upstream+nvme
Thanks,
applied to nvme-6.15.
^ permalink raw reply [flat|nested] 5+ messages in thread
end of thread, other threads:[~2025-04-22 8:37 UTC | newest]
Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-04-18 8:02 [PATCH] nvmet: Fix out-of-bounds access in nvmet_enable_port Richard Weinberger
2025-04-18 8:04 ` Damien Le Moal
2025-04-18 10:54 ` Sagi Grimberg
2025-04-22 6:33 ` Chaitanya Kulkarni
2025-04-22 7:50 ` Christoph Hellwig
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox