public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
* [PATCH] RDMA/ionic: bound node_desc sysfs read with %.64s
@ 2026-04-07  9:20 Kai Zen
  2026-04-09 15:51 ` Jason Gunthorpe
  0 siblings, 1 reply; 2+ messages in thread
From: Kai Zen @ 2026-04-07  9:20 UTC (permalink / raw)
  To: Abhijit Gangurde, Allen Hubbe; +Cc: linux-rdma, linux-kernel

node_desc[64] in struct ib_device is not guaranteed to be NUL-
terminated. The core IB sysfs handler uses "%.64s" for exactly this
reason (drivers/infiniband/core/sysfs.c:1307), since node_desc_store()
performs a raw memcpy of up to IB_DEVICE_NODE_DESC_MAX bytes with no
NUL termination:

  memcpy(desc.node_desc, buf, min_t(int, count, IB_DEVICE_NODE_DESC_MAX));

If exactly 64 bytes are written via the node_desc sysfs file, the
array contains no NUL byte. The ionic hca_type_show() handler uses
unbounded "%s" and will read past the end of node_desc into adjacent
fields of struct ib_device until it encounters a NUL.

Match the core handler and bound the format specifier.

Verified against torvalds/linux.git master at bfe62a45.

Signed-off-by: Kai Aizen <kai.aizen.dev@gmail.com>
---
 drivers/infiniband/hw/ionic/ionic_ibdev.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/infiniband/hw/ionic/ionic_ibdev.c
b/drivers/infiniband/hw/ionic/ionic_ibdev.c
--- a/drivers/infiniband/hw/ionic/ionic_ibdev.c
+++ b/drivers/infiniband/hw/ionic/ionic_ibdev.c
@@ -185,7 +185,7 @@ static ssize_t hca_type_show(struct device *device,
        struct ionic_ibdev *dev =
                rdma_device_to_drv_device(device, struct ionic_ibdev, ibdev);

-       return sysfs_emit(buf, "%s\n", dev->ibdev.node_desc);
+       return sysfs_emit(buf, "%.64s\n", dev->ibdev.node_desc);
 }
 static DEVICE_ATTR_RO(hca_type);

--
2.43.0

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2026-04-09 15:51 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-04-07  9:20 [PATCH] RDMA/ionic: bound node_desc sysfs read with %.64s Kai Zen
2026-04-09 15:51 ` Jason Gunthorpe

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox