Linux-NVME Archive on lore.kernel.org
 help / color / mirror / Atom feed
* [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

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