From: Paolo Abeni <pabeni@redhat.com>
To: sunichi <sunyiqixm@gmail.com>,
davem@davemloft.net, edumazet@google.com, kuba@kernel.org
Cc: horms@kernel.org, kuniyu@google.com, gnault@redhat.com,
leitao@debian.org, netdev@vger.kernel.org,
linux-kernel@vger.kernel.org
Subject: Re: [PATCH] net/mpls: fix missing NULL check in mpls_valid_fib_dump_req
Date: Thu, 26 Mar 2026 11:25:30 +0100 [thread overview]
Message-ID: <c5c71526-047b-480d-bf4f-6ebc47357f49@redhat.com> (raw)
In-Reply-To: <20260323071515.1945612-1-sunyiqixm@gmail.com>
On 3/23/26 8:15 AM, sunichi wrote:
> The attribute tb[RTA_OIF] is dereferenced without verifying if it is NULL.
> If this attribute is missing in the user netlink message, it will cause a
> NULL pointer dereference and kernel panic.
>
> Add the necessary check before using the pointer to prevent the crash.
>
> Signed-off-by: sunichi <sunyiqixm@gmail.com>
> ---
> net/mpls/af_mpls.c | 2 ++
> 1 file changed, 2 insertions(+)
>
> diff --git a/net/mpls/af_mpls.c b/net/mpls/af_mpls.c
> index d5417688f69e..28bbea30aae3 100644
> --- a/net/mpls/af_mpls.c
> +++ b/net/mpls/af_mpls.c
> @@ -2174,6 +2174,8 @@ static int mpls_valid_fib_dump_req(struct net *net, const struct nlmsghdr *nlh,
> int ifindex;
>
> if (i == RTA_OIF) {
> + if (!tb[i])
> + return -EINVAL;
> ifindex = nla_get_u32(tb[i]);
> filter->dev = dev_get_by_index_rcu(net, ifindex);
> if (!filter->dev)
If you reorder the check I think it will lead to better code:
---
diff --git a/net/mpls/af_mpls.c b/net/mpls/af_mpls.c
index b32311f5cbf7..41510dce5329 100644
--- a/net/mpls/af_mpls.c
+++ b/net/mpls/af_mpls.c
@@ -2170,13 +2170,16 @@ static int mpls_valid_fib_dump_req(struct net
*net, const struct nlmsghdr *nlh,
for (i = 0; i <= RTA_MAX; ++i) {
int ifindex;
+ if (!tb[i])
+ continue;
+
if (i == RTA_OIF) {
ifindex = nla_get_u32(tb[i]);
filter->dev = dev_get_by_index_rcu(net, ifindex);
if (!filter->dev)
return -ENODEV;
filter->filter_set = 1;
- } else if (tb[i]) {
+ } else {
NL_SET_ERR_MSG_MOD(extack, "Unsupported
attribute in dump request");
return -EINVAL;
}
prev parent reply other threads:[~2026-03-26 10:25 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-03-23 7:15 [PATCH] net/mpls: fix missing NULL check in mpls_valid_fib_dump_req sunichi
2026-03-23 8:52 ` Nikolay Aleksandrov
2026-03-23 10:07 ` sunichi
2026-03-26 10:25 ` Paolo Abeni [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=c5c71526-047b-480d-bf4f-6ebc47357f49@redhat.com \
--to=pabeni@redhat.com \
--cc=davem@davemloft.net \
--cc=edumazet@google.com \
--cc=gnault@redhat.com \
--cc=horms@kernel.org \
--cc=kuba@kernel.org \
--cc=kuniyu@google.com \
--cc=leitao@debian.org \
--cc=linux-kernel@vger.kernel.org \
--cc=netdev@vger.kernel.org \
--cc=sunyiqixm@gmail.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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox