Netdev List
 help / color / mirror / Atom feed
From: netdev-bot+sashiko@kernel.org
To: lucien.xin@gmail.com
Cc: netdev@vger.kernel.org, linux-sctp@vger.kernel.org,
	davem@davemloft.net, kuba@kernel.org, edumazet@kernel.org,
	pabeni@redhat.com, horms@kernel.org, marcelo.leitner@gmail.com
Subject: Re: [PATCH net-next] sctp: diag: set sin6_scope_id for IPv6 link-local lookup addresses
Date: Tue, 24 Nov 2026 00:50:08 +0000	[thread overview]
Message-ID: <179548140847.3135.8828188577061386396@kernel.org> (raw)
In-Reply-To: <409da01d058fee776791de001ffd222069f06090.1795394936.git.lucien.xin@gmail.com>

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

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

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] sctp_diag_dump_one() (net/sctp/diag.c:458 and 464) uses the
  single req->id.idiag_if as the scope id for both laddr and paddr.
- [Low] The patch fixes a long-standing bug but has no Fixes: tag and no
  Reported-by: tag.

--

sctp: diag: set sin6_scope_id for IPv6 link-local lookup addresses

This patch sets sin6_scope_id from req->id.idiag_if on the IPv6 laddr
and paddr lookup addresses built in sctp_diag_dump_one(). The goal is to
let exact SOCK_DIAG_BY_FAMILY queries match IPv6 link-local associations
when the caller supplies the correct interface index.

> As gomaja noticed, sctp_diag_dump_one() builds IPv6 lookup addresses on the
> stack but never sets sin6_scope_id.

[Severity: Low]
Should this patch have Fixes: and Reported-by: tags?

The laddr and paddr union in sctp_diag_dump_one() has been declared
without an initializer since commit 8f840e47f190 ("sctp: add the
sctp_diag.c file"). So on the IPv6 path, sin6_scope_id has been
uninitialized stack data since that commit.

For link-local peers, the scope of the transport's ipaddr is non-zero.
Both sctp_v6_from_skb() and sctp_v6_from_addr_param() set it from the
iif. This means __sctp_v6_cmp_addr() reads the uninitialized value
through two paths:

  sctp_hash_cmp()->sctp_cmp_addr_exact()
  sctp_bind_addr_match()->sctp_inet6_cmp_addr()

As a result, whether an exact query matches has depended on leftover
stack contents, and KMSAN could flag the read.

Would it make sense to add a Fixes: 8f840e47f190 tag, so stable tooling
picks this up, and a Reported-by: tag for gomaja?

> diff --git a/net/sctp/diag.c b/net/sctp/diag.c
> index c2a0de2adf6fd..dc199e3e96b1c 100644
> --- a/net/sctp/diag.c
> +++ b/net/sctp/diag.c
> @@ -455,11 +455,13 @@ static int sctp_diag_dump_one(struct netlink_callback *cb,
>  		memcpy(&laddr.v6.sin6_addr, req->id.idiag_src,
>  		       sizeof(laddr.v6.sin6_addr));
>  		laddr.v6.sin6_family = AF_INET6;
> +		laddr.v6.sin6_scope_id = req->id.idiag_if;

[Severity: Medium]
Can using idiag_if as the scope for laddr make an exact query fail, even
when the sockid is copied straight from the kernel's own dump?

On the dump side, inet_diag_msg_sctpasoc_fill() takes idiag_src and
idiag_if from different places:

net/sctp/diag.c:inet_diag_msg_sctpasoc_fill() {
    ...
	laddr = list_entry(asoc->base.bind_addr.address_list.next,
			   struct sctp_sockaddr_entry, list)->a;
	paddr = asoc->peer.primary_path->ipaddr;
	dst = asoc->peer.primary_path->dst;
    ...
	r->id.idiag_if = dst ? dst->dev->ifindex : 0;
    ...
}

So idiag_src comes from the first bind entry, which has its own
sin6_scope_id. idiag_if comes from the primary path's dst device.

Here is an example. A multi-homed socket calls bindx() with fe80::a%eth0
and then fe80::b%eth1, and its peer is fe80::p%eth1.
sctp_inet6_bind_verify() allows these binds without setting
sk_bound_dev_if.

sctp_add_bind_addr() uses list_add_tail_rcu(), and sctp_bind_addr_copy()
keeps that order. The dump therefore reports idiag_src=fe80::a,
idiag_dst=fe80::p and idiag_if=eth1.

When that sockid is sent back, laddr.sin6_scope_id is set to eth1. The
lookup then goes through:

sctp_transport_lookup_process()
  sctp_addrs_lookup_transport()
    sctp_bind_addr_match()
      sctp_inet6_cmp_addr()
        __sctp_v6_cmp_addr()

__sctp_v6_cmp_addr() rejects the fe80::a entry because both scopes are
non-zero and differ:

	if ((ipv6_addr_type(&addr1->v6.sin6_addr) & IPV6_ADDR_LINKLOCAL) &&
	    addr1->v6.sin6_scope_id && addr2->v6.sin6_scope_id &&
	    addr1->v6.sin6_scope_id != addr2->v6.sin6_scope_id)
		return 0;

The other bind entry has a different address, so the query returns
-ENOENT.

In this case no non-zero idiag_if works for both laddr and paddr. Only
idiag_if == 0 works, and only for sockets not bound to a device.
Wildcard-bound sockets on hosts with several NICs might hit the same
problem, depending on the order of local_addr_list.

The transport hash lookup is keyed on paddr, and dif already filters on
the bound device. Would it be better to set only the scope id on paddr,
or to leave the laddr scope at 0 so it acts as a wildcard?

>  
>  		paddr.v6.sin6_port = req->id.idiag_dport;
>  		memcpy(&paddr.v6.sin6_addr, req->id.idiag_dst,
>  		       sizeof(paddr.v6.sin6_addr));
>  		paddr.v6.sin6_family = AF_INET6;
> +		paddr.v6.sin6_scope_id = req->id.idiag_if;
>  	}

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

      reply	other threads:[~2026-11-24  0:50 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-11-23  0:48 [PATCH net-next] sctp: diag: set sin6_scope_id for IPv6 link-local lookup addresses Xin Long
2026-11-24  0:50 ` netdev-bot+sashiko [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=179548140847.3135.8828188577061386396@kernel.org \
    --to=netdev-bot+sashiko@kernel.org \
    --cc=davem@davemloft.net \
    --cc=edumazet@kernel.org \
    --cc=horms@kernel.org \
    --cc=kuba@kernel.org \
    --cc=linux-sctp@vger.kernel.org \
    --cc=lucien.xin@gmail.com \
    --cc=marcelo.leitner@gmail.com \
    --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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox