From: Hangbin Liu <hangbin.liu@linux.dev>
To: Hui Peng <benquike@gmail.com>
Cc: Andrea Mayer <andrea.mayer@uniroma2.it>,
"David S . Miller" <davem@davemloft.net>,
Eric Dumazet <edumazet@google.com>,
Jakub Kicinski <kuba@kernel.org>, Paolo Abeni <pabeni@redhat.com>,
Simon Horman <horms@kernel.org>,
netdev@vger.kernel.org, linux-kernel@vger.kernel.org
Subject: Re: [PATCH] ipv6: sr: fix 16-byte kernel heap leak in seg6_genl_set_tunsrc()
Date: Sun, 20 Sep 2026 15:01:56 +0800 [thread overview]
Message-ID: <aq-E5MPYZS5s9_bk@fedora> (raw)
In-Reply-To: <20260919204807.2812472-1-benquike@gmail.com>
Hi Hui Peng,
On Sat, Sep 19, 2026 at 08:48:06PM +0000, Hui Peng wrote:
> seg6_genl_policy[SEG6_ATTR_DST] uses NLA_BINARY with
> .len = sizeof(struct in6_addr), which only caps the maximum attribute
> length and allows 0-byte SEG6_ATTR_DST attributes.
>
> seg6_genl_set_tunsrc() then unconditionally copies
> sizeof(struct in6_addr) (16 bytes) from
> nla_data(info->attrs[SEG6_ATTR_DST]) into sdata->tun_src via kmemdup(),
> reading 16 bytes of uninitialized skb->head heap memory past skb->tail
> and exposing it to userspace via SEG6_CMD_GET_TUNSRC.
>
> Enforce NLA_POLICY_EXACT_LEN(sizeof(struct in6_addr)) in
> seg6_genl_policy and validate nla_len(info->attrs[SEG6_ATTR_DST]) in
> seg6_genl_set_tunsrc().
>
> Fixes: 915d7e5e5930 ("ipv6: sr: add code base for control plane support of SR-IPv6")
> Assisted-by: LLM
> Signed-off-by: Hui Peng <benquike@gmail.com>
> ---
> diff --git a/net/ipv6/seg6.c b/net/ipv6/seg6.c
> --- a/net/ipv6/seg6.c
> +++ b/net/ipv6/seg6.c
> @@ -138,8 +138,8 @@ out:
> static struct genl_family seg6_genl_family;
>
> static const struct nla_policy seg6_genl_policy[SEG6_ATTR_MAX + 1] = {
> - [SEG6_ATTR_DST] = { .type = NLA_BINARY,
> - .len = sizeof(struct in6_addr) },
> + [SEG6_ATTR_DST] =
> + NLA_POLICY_EXACT_LEN(sizeof(struct in6_addr)),
After you setting the policy here.
> [SEG6_ATTR_DSTLEN] = { .type = NLA_S32, },
> [SEG6_ATTR_HMACKEYID] = { .type = NLA_U32, },
> [SEG6_ATTR_SECRET] = { .type = NLA_BINARY, },
> @@ -242,7 +242,8 @@ static int seg6_genl_set_tunsrc(struct sk_buff *skb, struct genl_info *info)
>
> sdata = seg6_pernet(net);
>
> - if (!info->attrs[SEG6_ATTR_DST])
> + if (!info->attrs[SEG6_ATTR_DST] ||
> + nla_len(info->attrs[SEG6_ATTR_DST]) != sizeof(struct in6_addr))
> return -EINVAL;
There is not need to re-check the length again.
Thanks
Hangbin
next prev parent reply other threads:[~2026-09-20 7:02 UTC|newest]
Thread overview: 8+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-09-19 20:48 [PATCH] ipv6: sr: fix 16-byte kernel heap leak in seg6_genl_set_tunsrc() Hui Peng
2026-09-20 7:01 ` Hangbin Liu [this message]
2026-09-21 4:40 ` [PATCH net v2] ipv6: sr: enforce exact attribute length for SEG6_ATTR_DST Hui Peng
2026-09-21 6:34 ` Hangbin Liu
2026-09-21 22:07 ` Justin Iurman
2026-09-23 22:52 ` Andrea Mayer
2026-09-24 1:34 ` Jakub Kicinski
2026-09-24 1:40 ` patchwork-bot+netdevbpf
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=aq-E5MPYZS5s9_bk@fedora \
--to=hangbin.liu@linux.dev \
--cc=andrea.mayer@uniroma2.it \
--cc=benquike@gmail.com \
--cc=davem@davemloft.net \
--cc=edumazet@google.com \
--cc=horms@kernel.org \
--cc=kuba@kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=netdev@vger.kernel.org \
--cc=pabeni@redhat.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.