* [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
* Re: [PATCH] RDMA/nldev: validate dynamic counter attribute length
2026-07-06 9:12 [PATCH] RDMA/nldev: validate dynamic counter attribute length Pengpeng Hou
@ 2026-07-06 23:23 ` yanjun.zhu
0 siblings, 0 replies; 2+ messages in thread
From: yanjun.zhu @ 2026-07-06 23:23 UTC (permalink / raw)
To: Pengpeng Hou, Jason Gunthorpe
Cc: Leon Romanovsky, Michael Guralnik, Edward Srouji,
Patrisious Haddad, Edward Adam Davis, linux-rdma, linux-kernel
On 7/6/26 2:12 AM, Pengpeng Hou wrote:
> 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)) {
Maybe nla_len(entry_attr) > sizeof(u32) should also not be allowed?
As such, nla_len(entry_attr) != sizeof(u32) should be better?
Except the above, I am fine with this.
Reviewed-by: Zhu Yanjun <yanjun.zhu@linux.dev>
Zhu Yanjun
> + ret = -EINVAL;
> + goto out;
> + }
> +
> index = nla_get_u32(entry_attr);
> if ((index >= stats->num_counters) ||
> !(stats->descs[index].flags & IB_STAT_FLAG_OPTIONAL)) {
^ permalink raw reply [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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox