๐Ÿš€ go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: linux.kernel.netdev
Article #21419

Re: [PATCH net-next] sctp: diag: set sin6_scope_id for IPv6 link-local lookup addresses

#21419
From: netdev-bot+sashiko
Date: Tue, 24 Nov 2026 00:50
130 lines
12853 bytes
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
Technical Details
Message-ID: <179548140847.3135.8828188577061386396@kernel.org>
Path: mbox-mo1.pugleaf.net!news-wdc.pugleaf.net!usenet.blueworldhosting.com!diablo1.usenet.blueworldhosting.com!usenet.network!.POSTED!vger.kernel.org!netdev+bounces-369892-linux-kernel-netdev=dewy.ru
References: <409da01d058fee776791de001ffd222069f06090.1795394936.git.lucien.xin@gmail.com>

Show Full Headers
Complete Article Headers
Path: mbox-mo1.pugleaf.net!news-wdc.pugleaf.net!usenet.blueworldhosting.com!diablo1.usenet.blueworldhosting.com!usenet.network!.POSTED!vger.kernel.org!netdev+bounces-369892-linux-kernel-netdev=dewy.ru
From: netdev-bot+sashiko@kernel.org
Newsgroups: linux.kernel.netdev
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
Organization: Usenet Network
Message-ID: <179548140847.3135.8828188577061386396@kernel.org>
References: <409da01d058fee776791de001ffd222069f06090.1795394936.git.lucien.xin@gmail.com>
MIME-Version: 1.0
Content-Type: text/plain; charset="utf-8"
Content-Transfer-Encoding: 8bit
Injection-Info: usenet.network;
	logging-data="4019489"; mail-complaints-to="abuse@usenet.network"
Cancel-Lock: sha1:xDIRHFd6h2HnTdGSe4lkBs49olE= sha256:t7/blQ76VYme795eVcFJZHm/ttbADIuyha8QGf7vKQY=
	sha1:6X7sCtxfdCHyXdEf468mAYT9Kws= sha256:mFFrmBHKZ/V1dN4U75PPqhsGUqq6ItF0/UcKwQAYbhs=
List-ID: <netdev.vger.kernel.org>
X-Mailpost-Empty-Hdrs: X-Spam-Level
X-Received: from localhost (localhost [127.0.0.1])
	by mail.dewy.ru (Postfix) with ESMTP id 4A48B125DC9; Tue, 24 Nov 2026 03:50:26 +0300 (MSK)
X-Virus-Scanned: Debian amavisd-new at usenet.network
X-Spam-Flag: NO
X-Spam-Score: -3.4
X-Spam-Status: No, score=-3.4 tagged_above=-9999 required=6.31
	tests=[DCC_REPUT_70_89=0.1, DKIMWL_WL_HIGH=-0.001, DKIM_SIGNED=0.1,
	DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1,
	MAILING_LIST_MULTI=-1, RCVD_IN_DNSWL_MED=-2.3, SPF_HELO_NONE=0.001,
	SPF_PASS=-0.001, URIBL_BLOCKED=0.001] autolearn=ham autolearn_force=no
X-Authentication-Results: mail.dewy.ru (amavisd-new); dkim=pass (2048-bit key)
	header.d=kernel.org
X-Received: from mail.dewy.ru ([127.0.0.1])
	by localhost (mail.dewy.ru [127.0.0.1]) (amavisd-new, port 10024)
	with ESMTP id kuDbMCcg0dGw;
	Tue, 24 Nov 2026 03:50:22 +0300 (MSK)
X-Received-SPF: Pass (mailfrom) identity=mailfrom; client-ip=172.234.253.10; helo=sea.lore.kernel.org; envelope-from=netdev+bounces-369892-linux-kernel-netdev=dewy.ru@vger.kernel.org; receiver=<UNKNOWN> 
X-Authentication-Results: OpenDMARC; dmarc=pass (p=quarantine dis=none) header.from=kernel.org
X-Received: from sea.lore.kernel.org (sea.lore.kernel.org [172.234.253.10])
	by mail.dewy.ru (Postfix) with ESMTPS id D6D73125DC7; Tue, 24 Nov 2026 03:50:13 +0300 (MSK)
X-Received: from smtp.subspace.kernel.org (conduit.subspace.kernel.org [100.77.114.92])
	by sea.lore.kernel.org (Postfix) with ESMTP id BE2D633D68; Tue, 24 Nov 2026 00:50:10 +0000 (UTC)
X-Authentication-Results: smtp.subspace.kernel.org; arc=pass header.oldest-pass=0 smtp.remote-ip=127.0.0.1
X-ARC-Seal: i=2; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=pass;
	t=1795481410;
	b=OKw2XGp/2EPYBHoOxmFivjyTdSnz50HzJ1PcoGT9npwbmcxJizdZAa4VG8jNd1LNBNeL
	 CUFCCOLlvRuaSBFMh+qtxd+uGz6tWP/s/aZTAITFPRbBXwvRNUHTOBBbkeeh+q3z1SZsy
	 ZTNTF7LGSzhJNqdrSkRs8/8dWkJl/utDgqrBA1uu54qlQBvBUjIEALNSvhKlWMW9cbq6H
	 1Qn0FOFkWzytWEXJZqbc9Gv+2fvV/yzAVeGDQZVRHTBd94Jtf8zD5q2XTBvv4RJZ7LuwD
	 UT/xwfz8JffmDkStvTptp+S5pYBx1w8O03p2H1GAcVQgdp4MY7EDxgNKk2xWiND3Tqw==
X-ARC-Message-Signature: i=2; d=subspace.kernel.org; s=arc20261015;
	a=rsa-sha256; c=relaxed/relaxed; t=1795481410;
	h=X-Original-To:Received:Received:DKIM-Signature:Subject:From:To:Cc:
	 Date:Message-ID:In-Reply-To:References:X-sashiko-severity:
	 Content-Type:Content-Transfer-Encoding:X-Mailing-List:List-Id:
	 List-Post:List-Help:List-Subscribe:List-Unsubscribe:List-Owner:
	 Precedence:MIME-Version;
	bh=4KWptGHQxTDlm9noJyMVFUeMMm2hkEYym8kr8eGf88M=;
	b=A37jYeN4Hryj3crSYHXLTMdU6LgarqdAp9NY3TanxeddBv8yrMYv3cgnW7RHrJevPaL1
	 /ebaQ0SD/aF3LOWpLttUePlJpOs2kqqymnmWe3/dF9Kt0gBSEwifIFqEZOFVAdABJ4ZGz
	 M7/AUUiQ76VRquvOpg71uRmxbO20GAR3/ktRWcIv033ZckDbrRpQAk7Ps5Q6HLeAjsG0a
	 C3e8YxgWqgxb5P9KonWtbAo1gvUJKsAiVxz1+FRyb/raFHEO6zzM0CfwJ2gJwOY5sKR0w
	 wH3pnOlP0ey9N7mcXWH/KUiHpTfWukgzwhBGugY5bEHhYozC6vuN/cH6Iy809bD0Zgw==
X-ARC-Authentication-Results: i=2; smtp.subspace.kernel.org; 
	dkim=pass header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b=COxMOhzy;
	arc=pass header.oldest-pass=0 smtp.remote-ip=127.0.0.1
X-Received: from localhost.localdomain (localhost [127.0.0.1])
	by smtp.subspace.kernel.org (Postfix) with ESMTP id 95650606A32D;
	Tue, 24 Nov 2026 00:50:10 +0000 (UTC)
X-Authentication-Results: smtp.subspace.kernel.org;
	dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b=COxMOhzy
X-Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=100.103.45.18
X-ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none;
	t=1795481409;
	b=xgVvq5h8qzq0topBcgd/UGVycSEDw7Im5Kf/MKl2j38t1e6EVEqO7pibSjMeFUwy1wCc
	 96ajZZ9PMbxe8N1DF0kX+D8OcWMfZRo3bhgJ4lWpEdhUgKzmwwxDVcua71hFgXNBTcoBZ
	 epw431/0ddDyq7pCxAMm1gJYF78q41cyMIc0UgV2zfax+UmZuOvnrB9bDo1mVnTi1G06E
	 goV+xM+n9mAU89oh1SdxXBY/C7VafTwYDO/DQHvoxn96vthl5fL924PlWKzyXhqWUrPZR
	 53bYzGTdSeSyCXIa8V/3k6UC14CeIcd+ByOou9WwhLw+6Vnbi/28/hXtjrAiaD/Gu0A==
X-ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015;
	a=rsa-sha256; c=relaxed/relaxed; t=1795481409;
	h=Received:DKIM-Signature:Subject:From:To:Cc:Date:Message-ID:
	 In-Reply-To:References:X-sashiko-severity:Content-Type:
	 Content-Transfer-Encoding:MIME-Version;
	bh=4KWptGHQxTDlm9noJyMVFUeMMm2hkEYym8kr8eGf88M=;
	b=p3aNBdICKLIJ5+NyExuud15IMIfq3kQQTD3N9W2rnqyZXdxuWC+IUiS+2e5r8mM9Ws/d
	 mwujFOeCTJsYLlZIms0CgD3yPxaj56EFYL6wUX754rr0Dpd70CxcakonZ4Ln6AQBpmTuu
	 GLkETyCoOphY/e/VleuD4aES7PWWh5i0jepbfKOdnHwUqrbWnXSz/8cZ3531BVDzcecgf
	 Mj97COtxVffpWk+phTM6e9qcywmyx67IY5Wob2/1uqXUdyFXV5RrM1vG0QyF38jsdpKka
	 fSMhwIdaMELNs44q9ZB47tuR6KtEi5UOeDGUS80JDyaQFZTnxHy61xIlhwpYePhfd0g==
X-ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; 
	dkim=pass header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b=COxMOhzy;
	arc=none smtp.remote-ip=100.103.45.18
X-Received: from smtp.kernel.org (quasi.space.kernel.org [100.103.45.18])
	(using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)
	 key-exchange X25519 server-signature ECDSA (prime256v1))
	(No client certificate requested)
	by smtp.subspace.kernel.org (Postfix) with ESMTPS id B3CE9606A321;
	Tue, 24 Nov 2026 00:50:09 +0000 (UTC)
X-Received: by smtp.kernel.org (Postfix) with ESMTPSA id E50161F000D3;
	Tue, 24 Nov 2026 00:50:08 +0000 (UTC)
X-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org;
	s=k20260515; t=1795481409;
	bh=4KWptGHQxTDlm9noJyMVFUeMMm2hkEYym8kr8eGf88M=;
	h=Subject:From:To:Cc:Date:In-Reply-To:References;
	b=COxMOhzyGkPH+01W1GFSnTYC5P8RTUBqvgnjy4jQtz8jESqX+YJTss5eujf0QEpnJ
	 aQM9h/mCZWkNz+767U7U7gs6k9H/Ck5bypvhk9JsjkN8zY3uFAMiPCB84ZfePN1hEs
	 dB07A6wWVZCBrjBdX15lR2+Ikq3ev4FYpShNkVv/9gun4HzP5ybIdGm3aFwhL4df9K
	 i3ETe4gCLW1okQdL9dnpkxZPrMmeVHlKvVGB7f6wKN0X8tD58JJCSTzxqFVlErVg/7
	 e1Ff5nuuN2cwNOnjXr4rMPZHziD0n6MXpDeLg8XVd3s5fF9NLNPltSH8uPvUmi70kF
	 QZyJl/RisU8oA==
X-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
X-In-Reply-To: <409da01d058fee776791de001ffd222069f06090.1795394936.git.lucien.xin@gmail.com>
X-sashiko-severity: Medium
X-Mailing-List: netdev@vger.kernel.org
X-List-Post: <mailto:netdev@vger.kernel.org>
X-List-Help: <mailto:netdev+help@vger.kernel.org>
X-List-Subscribe: <mailto:netdev+subscribe@vger.kernel.org>
X-List-Unsubscribe: <mailto:netdev+unsubscribe@vger.kernel.org>
X-List-Owner: <mailto:netdev+owner@vger.kernel.org>
X-Precedence: list