From: "yanjun.zhu" <yanjun.zhu@linux.dev>
To: Pengpeng Hou <pengpeng@iscas.ac.cn>, Jason Gunthorpe <jgg@ziepe.ca>
Cc: Leon Romanovsky <leon@kernel.org>,
Michael Guralnik <michaelgur@nvidia.com>,
Edward Srouji <edwards@nvidia.com>,
Patrisious Haddad <phaddad@nvidia.com>,
Edward Adam Davis <eadavis@qq.com>,
linux-rdma@vger.kernel.org, linux-kernel@vger.kernel.org
Subject: Re: [PATCH] RDMA/nldev: validate dynamic counter attribute length
Date: Mon, 6 Jul 2026 16:23:23 -0700 [thread overview]
Message-ID: <5e449fbb-f48c-4acd-9f50-674c7834ed68@linux.dev> (raw)
In-Reply-To: <20260706091243.76784-1-pengpeng@iscas.ac.cn>
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)) {
prev parent reply other threads:[~2026-07-06 23:23 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-07-06 9:12 [PATCH] RDMA/nldev: validate dynamic counter attribute length Pengpeng Hou
2026-07-06 23:23 ` yanjun.zhu [this message]
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=5e449fbb-f48c-4acd-9f50-674c7834ed68@linux.dev \
--to=yanjun.zhu@linux.dev \
--cc=eadavis@qq.com \
--cc=edwards@nvidia.com \
--cc=jgg@ziepe.ca \
--cc=leon@kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-rdma@vger.kernel.org \
--cc=michaelgur@nvidia.com \
--cc=pengpeng@iscas.ac.cn \
--cc=phaddad@nvidia.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
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.