Netdev List
 help / color / mirror / Atom feed
* [PATCH net v2] sctp: diag: fix stack garbage in IPv6 scope_id during dump_one lookup
@ 2026-11-25 15:49 Xin Long
  2026-11-26 15:49 ` netdev-bot+sashiko
  2026-12-02 12:40 ` patchwork-bot+netdevbpf
  0 siblings, 2 replies; 6+ messages in thread
From: Xin Long @ 2026-11-25 15:49 UTC (permalink / raw)
  To: network dev, linux-sctp
  Cc: davem, kuba, Eric Dumazet, Paolo Abeni, Simon Horman,
	Marcelo Ricardo Leitner

As gomaja noticed, sctp_diag_dump_one() builds IPv6 lookup addresses on
the stack but never initializes sin6_scope_id or sin6_flowinfo. For
link-local addresses, __sctp_v6_cmp_addr() compares scope_ids when both
are non-zero, so stack garbage in these fields can cause sporadic lookup
failures.

Zero-initialize both laddr and paddr to ensure sin6_scope_id is 0, which
acts as a wildcard in __sctp_v6_cmp_addr(), matching any scope, just as
TCP and UDP handle idiag_if purely as a device filter (dif) parameter
without conflating it with IPv6 scope_id.

The dif check in sctp_addrs_lookup_transport() already filters by
sk_bound_dev_if, so scope_id on the lookup addresses is unnecessary.

Fixes: 8f840e47f190 ("sctp: add the sctp_diag.c file")
Signed-off-by: Xin Long <lucien.xin@gmail.com>
---
v2:
  - Add a Fixes tag and target net.git.
  - Fix the issue by zero-initializing laddr/paddr instead of explicitly
    setting sin6_scope_id to 0 (reported by Clashiko).
---
 net/sctp/diag.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/net/sctp/diag.c b/net/sctp/diag.c
index c2a0de2adf6f..564a5b51e6ce 100644
--- a/net/sctp/diag.c
+++ b/net/sctp/diag.c
@@ -433,7 +433,7 @@ static int sctp_diag_dump_one(struct netlink_callback *cb,
 	struct sk_buff *skb = cb->skb;
 	struct net *net = sock_net(skb->sk);
 	const struct nlmsghdr *nlh = cb->nlh;
-	union sctp_addr laddr, paddr;
+	union sctp_addr laddr = {}, paddr = {};
 	int dif = req->id.idiag_if;
 	struct sctp_comm_param commp = {
 		.skb = skb,
-- 
2.47.1


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

* Re: [PATCH net v2] sctp: diag: fix stack garbage in IPv6 scope_id during dump_one lookup
@ 2026-11-25 15:53 netdev-bot+sinfo
  0 siblings, 0 replies; 6+ messages in thread
From: netdev-bot+sinfo @ 2026-11-25 15:53 UTC (permalink / raw)
  To: Xin Long
  Cc: network dev, linux-sctp, davem, kuba, Eric Dumazet, Paolo Abeni,
	Simon Horman, Marcelo Ricardo Leitner

Hi!

This is an automated message. This series looks like a fix, but its
commit messages seem to be missing some information:

 - Whether the issue was actually triggered, or is only theoretical
   (e.g. found by LLM and not proven at runtime). If it was triggered
   please include the symptoms, like the stack trace or kernel messages.

Please do not repost the series just to address the above. Instead,
reply to this email with the missing information, so that reviewers
can take it into account.

*IMPORTANT*: If you do repost (for other reasons) - please include
the relevant info in the cover letter or commit messages.
-- 
The evaluation is done by an LLM so it may be wrong, if you think
that is the case please reply and explain.

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

* Re: [PATCH net v2] sctp: diag: fix stack garbage in IPv6 scope_id during dump_one lookup
  2026-11-25 15:49 [PATCH net v2] sctp: diag: fix stack garbage in IPv6 scope_id during dump_one lookup Xin Long
@ 2026-11-26 15:49 ` netdev-bot+sashiko
  2026-11-26 20:27   ` Xin Long
  2026-12-02 12:40 ` patchwork-bot+netdevbpf
  1 sibling, 1 reply; 6+ messages in thread
From: netdev-bot+sashiko @ 2026-11-26 15:49 UTC (permalink / raw)
  To: lucien.xin
  Cc: netdev, linux-sctp, davem, kuba, edumazet, pabeni, horms,
	marcelo.leitner

Thank you for your contribution! Sashiko AI review found 1 potential
issue(s) to consider.

Critical: 0 · High: 0 · Medium: 1 · Low: 0

If you believe none of the issues are legitimate, please reply to each
issue of Medium severity or higher and explain why the AI is wrong.
If any of them are legitimate and you plan to respin, please let patchwork
know by including "pw-bot: cr" as a separate line at the end of your reply
(one such reply per series is enough).

- [Medium] The commit message justifies the wildcard scope_id with: "The
  dif check in sctp_addrs_lookup_transport() already filters by…

--

sctp: diag: fix stack garbage in IPv6 scope_id during dump_one lookup

This commit zero-initializes the laddr and paddr lookup addresses in
sctp_diag_dump_one(). As a result, sin6_scope_id and sin6_flowinfo no
longer hold stack garbage. A zero sin6_scope_id then acts as a wildcard in
__sctp_v6_cmp_addr(), and idiag_if is used only as a dif filter.

> diff --git a/net/sctp/diag.c b/net/sctp/diag.c
> index c2a0de2adf6fd..564a5b51e6ce3 100644
> --- a/net/sctp/diag.c
> +++ b/net/sctp/diag.c
> @@ -433,7 +433,7 @@ static int sctp_diag_dump_one(struct netlink_callback *cb,
>  	struct sk_buff *skb = cb->skb;
>  	struct net *net = sock_net(skb->sk);
>  	const struct nlmsghdr *nlh = cb->nlh;
> -	union sctp_addr laddr, paddr;
> +	union sctp_addr laddr = {}, paddr = {};
>  	int dif = req->id.idiag_if;

[Severity: Medium]

The commit message says:

  The dif check in sctp_addrs_lookup_transport() already filters by
  sk_bound_dev_if, so scope_id on the lookup addresses is unnecessary.

Does this hold for SCTP the way it does for TCP and UDP?

For TCP, connect() to a link-local peer binds the socket to the scope
interface, so a dif filter on sk_bound_dev_if is enough. SCTP does not
seem to set sk_bound_dev_if from the peer's scope. The scope is kept only
in the transport address:

net/sctp/ipv6.c:sctp_v6_get_dst() {
    ...
	if (ipv6_addr_type(&daddr->v6.sin6_addr) & IPV6_ADDR_LINKLOCAL)
		fl6->flowi6_oif = daddr->v6.sin6_scope_id;
	else if (asoc)
		fl6->flowi6_oif = asoc->base.sk->sk_bound_dev_if;
    ...
}

On the dump side, idiag_if also reports something other than
sk_bound_dev_if:

net/sctp/diag.c:inet_diag_msg_sctpasoc_fill() {
    ...
	r->id.idiag_if = dst ? dst->dev->ifindex : 0;
    ...
}

For a link-local peer, this is in effect the peer's scope interface.

On the lookup side, the call chain
sctp_transport_lookup_process()->sctp_addrs_lookup_transport() passes dif
to sctp_sk_bound_dev_eq(). For an unbound socket (bound_dev_if == 0),
inet_bound_dev_eq() returns !sdif || l3mdev_accept. That is true by
default, so any dif passes.

With sin6_scope_id now always 0, __sctp_v6_cmp_addr() matches link-local
transports on every interface. sctp_hash_transport() treats two different
non-zero scope_ids as distinct. So an unbound socket can hold associations
to fe80::X%ethA and fe80::X%ethB on the same port at the same time.

Suppose a dump_one request echoes back a dumped tuple (addresses, ports
and the reported idiag_if). Can it pick the wrong association in that
case? sctp_addrs_lookup_transport() returns the first matching rhlist
entry:

- With INET_DIAG_NOCOOKIE, that entry could be a different association,
  possibly on another socket.
- With a cookie set, the lookup could return -ESTALE even though the
  requested association exists.

The same ambiguity existed before whenever the stack garbage happened to
be 0. This patch makes the wildcard the intended behaviour.

Would it make sense to keep the zero-init and, for link-local addresses,
also set sin6_scope_id from req->id.idiag_if? The commit message could
then be updated to match.

-- 
Sashiko AI review · https://netdev-ai.bots.linux.dev/sashiko/#/patchset/7cc69548f249ff63527a663c22d9dc918d3c3e84.1795621751.git.lucien.xin%40gmail.com

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

* Re: [PATCH net v2] sctp: diag: fix stack garbage in IPv6 scope_id during dump_one lookup
  2026-11-26 15:49 ` netdev-bot+sashiko
@ 2026-11-26 20:27   ` Xin Long
  2026-12-02 12:30     ` Paolo Abeni
  0 siblings, 1 reply; 6+ messages in thread
From: Xin Long @ 2026-11-26 20:27 UTC (permalink / raw)
  To: netdev-bot+sashiko
  Cc: netdev, linux-sctp, davem, kuba, edumazet, pabeni, horms,
	marcelo.leitner

On Thu, Nov 26, 2026 at 10:49 AM <netdev-bot+sashiko@kernel.org> wrote:
>
> Thank you for your contribution! Sashiko AI review found 1 potential
> issue(s) to consider.
>
> Critical: 0 · High: 0 · Medium: 1 · Low: 0
>
> If you believe none of the issues are legitimate, please reply to each
> issue of Medium severity or higher and explain why the AI is wrong.
> If any of them are legitimate and you plan to respin, please let patchwork
> know by including "pw-bot: cr" as a separate line at the end of your reply
> (one such reply per series is enough).
>
> - [Medium] The commit message justifies the wildcard scope_id with: "The
>   dif check in sctp_addrs_lookup_transport() already filters by…
>
> --
>
> sctp: diag: fix stack garbage in IPv6 scope_id during dump_one lookup
>
> This commit zero-initializes the laddr and paddr lookup addresses in
> sctp_diag_dump_one(). As a result, sin6_scope_id and sin6_flowinfo no
> longer hold stack garbage. A zero sin6_scope_id then acts as a wildcard in
> __sctp_v6_cmp_addr(), and idiag_if is used only as a dif filter.
>
> > diff --git a/net/sctp/diag.c b/net/sctp/diag.c
> > index c2a0de2adf6fd..564a5b51e6ce3 100644
> > --- a/net/sctp/diag.c
> > +++ b/net/sctp/diag.c
> > @@ -433,7 +433,7 @@ static int sctp_diag_dump_one(struct netlink_callback *cb,
> >       struct sk_buff *skb = cb->skb;
> >       struct net *net = sock_net(skb->sk);
> >       const struct nlmsghdr *nlh = cb->nlh;
> > -     union sctp_addr laddr, paddr;
> > +     union sctp_addr laddr = {}, paddr = {};
> >       int dif = req->id.idiag_if;
>
> [Severity: Medium]
>
> The commit message says:
>
>   The dif check in sctp_addrs_lookup_transport() already filters by
>   sk_bound_dev_if, so scope_id on the lookup addresses is unnecessary.
>
> Does this hold for SCTP the way it does for TCP and UDP?
>
> For TCP, connect() to a link-local peer binds the socket to the scope
> interface, so a dif filter on sk_bound_dev_if is enough. SCTP does not
> seem to set sk_bound_dev_if from the peer's scope. The scope is kept only
> in the transport address:
>
> net/sctp/ipv6.c:sctp_v6_get_dst() {
>     ...
>         if (ipv6_addr_type(&daddr->v6.sin6_addr) & IPV6_ADDR_LINKLOCAL)
>                 fl6->flowi6_oif = daddr->v6.sin6_scope_id;
>         else if (asoc)
>                 fl6->flowi6_oif = asoc->base.sk->sk_bound_dev_if;
>     ...
> }
>
> On the dump side, idiag_if also reports something other than
> sk_bound_dev_if:
>
> net/sctp/diag.c:inet_diag_msg_sctpasoc_fill() {
>     ...
>         r->id.idiag_if = dst ? dst->dev->ifindex : 0;
>     ...
> }
>
> For a link-local peer, this is in effect the peer's scope interface.
>
> On the lookup side, the call chain
> sctp_transport_lookup_process()->sctp_addrs_lookup_transport() passes dif
> to sctp_sk_bound_dev_eq(). For an unbound socket (bound_dev_if == 0),
> inet_bound_dev_eq() returns !sdif || l3mdev_accept. That is true by
> default, so any dif passes.
>
> With sin6_scope_id now always 0, __sctp_v6_cmp_addr() matches link-local
> transports on every interface. sctp_hash_transport() treats two different
> non-zero scope_ids as distinct. So an unbound socket can hold associations
> to fe80::X%ethA and fe80::X%ethB on the same port at the same time.
This is very uncommon.

I would rather NOT set sin6_scope_id from req->id.idiag_if to support this case.

Even if we want to support it, it should go to a separate patch in the future.

Thanks.

>
> Suppose a dump_one request echoes back a dumped tuple (addresses, ports
> and the reported idiag_if). Can it pick the wrong association in that
> case? sctp_addrs_lookup_transport() returns the first matching rhlist
> entry:
>
> - With INET_DIAG_NOCOOKIE, that entry could be a different association,
>   possibly on another socket.
> - With a cookie set, the lookup could return -ESTALE even though the
>   requested association exists.
>
> The same ambiguity existed before whenever the stack garbage happened to
> be 0. This patch makes the wildcard the intended behaviour.
>
> Would it make sense to keep the zero-init and, for link-local addresses,
> also set sin6_scope_id from req->id.idiag_if? The commit message could
> then be updated to match.
>
> --
> Sashiko AI review · https://netdev-ai.bots.linux.dev/sashiko/#/patchset/7cc69548f249ff63527a663c22d9dc918d3c3e84.1795621751.git.lucien.xin%40gmail.com

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

* Re: [PATCH net v2] sctp: diag: fix stack garbage in IPv6 scope_id during dump_one lookup
  2026-11-26 20:27   ` Xin Long
@ 2026-12-02 12:30     ` Paolo Abeni
  0 siblings, 0 replies; 6+ messages in thread
From: Paolo Abeni @ 2026-12-02 12:30 UTC (permalink / raw)
  To: Xin Long, netdev-bot+sashiko
  Cc: netdev, linux-sctp, davem, kuba, edumazet, horms, marcelo.leitner

On 11/26/26 21:27, Xin Long wrote:
> On Thu, Nov 26, 2026 at 10:49 AM <netdev-bot+sashiko@kernel.org> wrote:
>>
>> Thank you for your contribution! Sashiko AI review found 1 potential
>> issue(s) to consider.
>>
>> Critical: 0 · High: 0 · Medium: 1 · Low: 0
>>
>> If you believe none of the issues are legitimate, please reply to each
>> issue of Medium severity or higher and explain why the AI is wrong.
>> If any of them are legitimate and you plan to respin, please let patchwork
>> know by including "pw-bot: cr" as a separate line at the end of your reply
>> (one such reply per series is enough).
>>
>> - [Medium] The commit message justifies the wildcard scope_id with: "The
>>    dif check in sctp_addrs_lookup_transport() already filters by…
>>
>> --
>>
>> sctp: diag: fix stack garbage in IPv6 scope_id during dump_one lookup
>>
>> This commit zero-initializes the laddr and paddr lookup addresses in
>> sctp_diag_dump_one(). As a result, sin6_scope_id and sin6_flowinfo no
>> longer hold stack garbage. A zero sin6_scope_id then acts as a wildcard in
>> __sctp_v6_cmp_addr(), and idiag_if is used only as a dif filter.
>>
>>> diff --git a/net/sctp/diag.c b/net/sctp/diag.c
>>> index c2a0de2adf6fd..564a5b51e6ce3 100644
>>> --- a/net/sctp/diag.c
>>> +++ b/net/sctp/diag.c
>>> @@ -433,7 +433,7 @@ static int sctp_diag_dump_one(struct netlink_callback *cb,
>>>        struct sk_buff *skb = cb->skb;
>>>        struct net *net = sock_net(skb->sk);
>>>        const struct nlmsghdr *nlh = cb->nlh;
>>> -     union sctp_addr laddr, paddr;
>>> +     union sctp_addr laddr = {}, paddr = {};
>>>        int dif = req->id.idiag_if;
>>
>> [Severity: Medium]
>>
>> The commit message says:
>>
>>    The dif check in sctp_addrs_lookup_transport() already filters by
>>    sk_bound_dev_if, so scope_id on the lookup addresses is unnecessary.
>>
>> Does this hold for SCTP the way it does for TCP and UDP?
>>
>> For TCP, connect() to a link-local peer binds the socket to the scope
>> interface, so a dif filter on sk_bound_dev_if is enough. SCTP does not
>> seem to set sk_bound_dev_if from the peer's scope. The scope is kept only
>> in the transport address:
>>
>> net/sctp/ipv6.c:sctp_v6_get_dst() {
>>      ...
>>          if (ipv6_addr_type(&daddr->v6.sin6_addr) & IPV6_ADDR_LINKLOCAL)
>>                  fl6->flowi6_oif = daddr->v6.sin6_scope_id;
>>          else if (asoc)
>>                  fl6->flowi6_oif = asoc->base.sk->sk_bound_dev_if;
>>      ...
>> }
>>
>> On the dump side, idiag_if also reports something other than
>> sk_bound_dev_if:
>>
>> net/sctp/diag.c:inet_diag_msg_sctpasoc_fill() {
>>      ...
>>          r->id.idiag_if = dst ? dst->dev->ifindex : 0;
>>      ...
>> }
>>
>> For a link-local peer, this is in effect the peer's scope interface.
>>
>> On the lookup side, the call chain
>> sctp_transport_lookup_process()->sctp_addrs_lookup_transport() passes dif
>> to sctp_sk_bound_dev_eq(). For an unbound socket (bound_dev_if == 0),
>> inet_bound_dev_eq() returns !sdif || l3mdev_accept. That is true by
>> default, so any dif passes.
>>
>> With sin6_scope_id now always 0, __sctp_v6_cmp_addr() matches link-local
>> transports on every interface. sctp_hash_transport() treats two different
>> non-zero scope_ids as distinct. So an unbound socket can hold associations
>> to fe80::X%ethA and fe80::X%ethB on the same port at the same time.
> This is very uncommon.
> 
> I would rather NOT set sin6_scope_id from req->id.idiag_if to support this case.
> 
> Even if we want to support it, it should go to a separate patch in the future.
BTW please note that this kind of changes - broken from day1 long time in the
past, with little impact, are net-next material at this point of the cycle.

/P

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

* Re: [PATCH net v2] sctp: diag: fix stack garbage in IPv6 scope_id during dump_one lookup
  2026-11-25 15:49 [PATCH net v2] sctp: diag: fix stack garbage in IPv6 scope_id during dump_one lookup Xin Long
  2026-11-26 15:49 ` netdev-bot+sashiko
@ 2026-12-02 12:40 ` patchwork-bot+netdevbpf
  1 sibling, 0 replies; 6+ messages in thread
From: patchwork-bot+netdevbpf @ 2026-12-02 12:40 UTC (permalink / raw)
  To: Xin Long
  Cc: netdev, linux-sctp, davem, kuba, edumazet, pabeni, horms,
	marcelo.leitner

Hello:

This patch was applied to netdev/net-next.git (main)
by Paolo Abeni <pabeni@redhat.com>:

On Wed, 25 Nov 2026 10:49:11 -0500 you wrote:
> As gomaja noticed, sctp_diag_dump_one() builds IPv6 lookup addresses on
> the stack but never initializes sin6_scope_id or sin6_flowinfo. For
> link-local addresses, __sctp_v6_cmp_addr() compares scope_ids when both
> are non-zero, so stack garbage in these fields can cause sporadic lookup
> failures.
> 
> Zero-initialize both laddr and paddr to ensure sin6_scope_id is 0, which
> acts as a wildcard in __sctp_v6_cmp_addr(), matching any scope, just as
> TCP and UDP handle idiag_if purely as a device filter (dif) parameter
> without conflating it with IPv6 scope_id.
> 
> [...]

Here is the summary with links:
  - [net,v2] sctp: diag: fix stack garbage in IPv6 scope_id during dump_one lookup
    https://git.kernel.org/netdev/net-next/c/fe4597b13a53

You are awesome, thank you!
-- 
Deet-doot-dot, I am a bot.
https://korg.docs.kernel.org/patchwork/pwbot.html



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

end of thread, other threads:[~2026-12-02 12:40 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-11-25 15:49 [PATCH net v2] sctp: diag: fix stack garbage in IPv6 scope_id during dump_one lookup Xin Long
2026-11-26 15:49 ` netdev-bot+sashiko
2026-11-26 20:27   ` Xin Long
2026-12-02 12:30     ` Paolo Abeni
2026-12-02 12:40 ` patchwork-bot+netdevbpf
  -- strict thread matches above, loose matches on Subject: below --
2026-11-25 15:53 netdev-bot+sinfo

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox