All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] RDMA/nldev: validate dynamic counter attribute length
@ 2026-07-06  9:12 Pengpeng Hou
  2026-07-06 23:23 ` yanjun.zhu
  0 siblings, 1 reply; 2+ messages in thread
From: Pengpeng Hou @ 2026-07-06  9:12 UTC (permalink / raw)
  To: Jason Gunthorpe
  Cc: Pengpeng, Leon Romanovsky, Michael Guralnik, Edward Srouji,
	Patrisious Haddad, Zhu Yanjun, Edward Adam Davis, linux-rdma,
	linux-kernel

From: Pengpeng <pengpeng@iscas.ac.cn>

nldev_stat_set_counter_dynamic_doit() iterates nested hardware counter
attributes and reads each entry with nla_get_u32(). The nested container
proof does not by itself prove that each child attribute carries a
four-byte payload.

Reject hardware counter entries whose payload is shorter than a u32
before reading the index.

Signed-off-by: Pengpeng <pengpeng@iscas.ac.cn>
---
 drivers/infiniband/core/nldev.c | 5 +++++
 1 file changed, 5 insertions(+)

diff --git a/drivers/infiniband/core/nldev.c b/drivers/infiniband/core/nldev.c
index 02a0a9c0a4a6..40b323131c7b 100644
--- a/drivers/infiniband/core/nldev.c
+++ b/drivers/infiniband/core/nldev.c
@@ -2133,6 +2133,11 @@ static int nldev_stat_set_counter_dynamic_doit(struct nlattr *tb[],
 
 	nla_for_each_nested(entry_attr, tb[RDMA_NLDEV_ATTR_STAT_HWCOUNTERS],
 			    rem) {
+		if (nla_len(entry_attr) < sizeof(u32)) {
+			ret = -EINVAL;
+			goto out;
+		}
+
 		index = nla_get_u32(entry_attr);
 		if ((index >= stats->num_counters) ||
 		    !(stats->descs[index].flags & IB_STAT_FLAG_OPTIONAL)) {
-- 
2.43.0


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

end of thread, other threads:[~2026-07-06 23:23 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-07-06  9:12 [PATCH] RDMA/nldev: validate dynamic counter attribute length Pengpeng Hou
2026-07-06 23:23 ` yanjun.zhu

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.