๐Ÿš€ go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: linux.kernel.netdev
Article #7515

Re: [PATCH net] seg6: fix tun_src RCU lifetime on namespace teardown

#7515
From: Eric Dumazet
Date: Mon, 26 Oct 2026 14:20
73 lines
11465 bytes
Le lun. 26 oct. 2026 ร  15:05, Andrea Mayer <andrea.mayer@uniroma2.it> a รฉcrit :
>
> On Sun, 25 Oct 2026 22:22:22 +0000
> Tristan Madani <tristmd@gmail.com> wrote:
>
> > Found by manual code inspection while auditing RCU lifetime
> > patterns in the seg6 subsystem.  The issue is theoretical --
> > found by reading the source, not triggered in production.
>
> Hi Tristan,
> thanks for the info.
>
> The pre_exit in this patch introduces a NULL deref. It sets tun_src to
> NULL before the netns devices are removed, while set_tun_src() can
> still read it.
>
> I ran a stress test on net with KASAN. A userspace program sends UDP
> packets in a loop from init_net through a veth into a test netns, where
> a seg6 encap route without a per-route tunsrc forwards them. Meanwhile,
> the test netns is created and deleted repeatedly.
>
> With this patch applied, KASAN reported a null-ptr-deref in
> set_tun_src() and the kernel panicked:
>
>  BUG: KASAN: null-ptr-deref in set_tun_src+0xd1/0x240
>  Read of size 8 at addr 0000000000000000 by task udp_flood_user/379
>  Call Trace:
>   <IRQ>
>   set_tun_src+0xd1/0x240
>   __seg6_do_srh_encap+0x410/0x710
>   seg6_do_srh+0x65e/0x6a0
>   seg6_input_core+0x87/0x4c0
>   lwtunnel_input+0x18d/0x420
>   ipv6_rcv+0x44f/0x460
>   __netif_receive_skb_one_core+0xd6/0x130
>   process_backlog+0x2cc/0xa00
>   __napi_poll.constprop.0+0x56/0x270
>   net_rx_action+0x327/0x730
>   handle_softirqs+0x15a/0x6c0
>   do_softirq+0xb4/0xf0
>   </IRQ>
>   <TASK>
>   __local_bh_enable_ip+0xdd/0x100
>   __dev_queue_xmit+0x538/0x1030
>   ip6_finish_output+0x280/0x640
>   ip6_output+0x118/0x380
>   ip6_send_skb+0x99/0x210
>   udp_v6_send_skb+0x397/0x760
>   udpv6_sendmsg+0x1100/0x14d0
>   __sys_sendto+0x219/0x2d0
>   ...
>  Kernel panic - not syncing: Fatal exception in interrupt
>
> Without this patch, I ran the same test with 1000 netns deletions and
> KASAN reported nothing.
>
> Ciao,
> Andrea

Right, and there is no bug to fix in the first place.

ip6_segments_ops is a pernet subsys, so seg6_net_exit() runs after
all netns devices have been unregistered (default_device_exit_batch()
and the RCU grace periods in netdev_run_todo()). At that point no
packet can reach set_tun_src() for this netns, and no socket can
issue SEG6_CMD_GET_TUNSRC either.

pre_exit runs before devices are dismantled, hence the crash Andrea
reported.

pw-bot: rejected
Technical Details
Message-ID: <CAL4WiirtzVke8V8f6LJEWdOCDNevGxdQCFhXxEGiEMq-TNbsVA@mail.gmail.com>
Path: mbox-mo1.pugleaf.net!archive.usenet.blueworldhosting.com!usenet.blueworldhosting.com!diablo1.usenet.blueworldhosting.com!usenet.network!.POSTED!vger.kernel.org!netdev+bounces-351937-linux-kernel-netdev=dewy.ru
References: <179278529389.3327.1530536500905686255@kernel.org> <20261025222222.1064464-1-tristan@talencesecurity.com> <20261026150541.a5a34642db9d1523f839f644@uniroma2.it>

Show Full Headers
Complete Article Headers
Path: mbox-mo1.pugleaf.net!archive.usenet.blueworldhosting.com!usenet.blueworldhosting.com!diablo1.usenet.blueworldhosting.com!usenet.network!.POSTED!vger.kernel.org!netdev+bounces-351937-linux-kernel-netdev=dewy.ru
From: edumazet@kernel.org (Eric Dumazet)
Newsgroups: linux.kernel.netdev
Subject: Re: [PATCH net] seg6: fix tun_src RCU lifetime on namespace teardown
Date: Mon, 26 Oct 2026 15:20:34 +0100
Organization: Usenet Network
Message-ID: <CAL4WiirtzVke8V8f6LJEWdOCDNevGxdQCFhXxEGiEMq-TNbsVA@mail.gmail.com>
References: <179278529389.3327.1530536500905686255@kernel.org>
 <20261025222222.1064464-1-tristan@talencesecurity.com> <20261026150541.a5a34642db9d1523f839f644@uniroma2.it>
MIME-Version: 1.0
Content-Type: text/plain; charset="UTF-8"
Content-Transfer-Encoding: quoted-printable
Injection-Info: usenet.network;
	logging-data="1325374"; mail-complaints-to="abuse@usenet.network"
Cancel-Lock: sha1:TKFTb4KobcjqPGwn8ENApMyMKvg= sha256:F+bGEXG1N0NXaGcCx1SGV1okoOZ15UENFUrjIfgUYX8=
	sha1:5a2dCD8Wn+mdxgrRE8y42nrHudM= sha256:rI9uuH06KSQZ9uwNj+tlxCl+C2wfz1xaD0ii6jGdoZY=
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 44B11125BAA; Mon, 26 Oct 2026 17:23:03 +0300 (MSK)
X-Virus-Scanned: Debian amavisd-new at usenet.network
X-Spam-Flag: NO
X-Spam-Score: -3.739
X-Spam-Status: No, score=-3.739 tagged_above=-9999 required=6.31
	tests=[DCC_REPUT_70_89=0.1, DKIMWL_WL_HIGH=-0.339, 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] 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 dr39rqBwuQ9U;
	Mon, 26 Oct 2026 17:23:00 +0300 (MSK)
X-Received-SPF: Pass (mailfrom) identity=mailfrom; client-ip=172.105.105.114; helo=tor.lore.kernel.org; envelope-from=netdev+bounces-351937-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 tor.lore.kernel.org (tor.lore.kernel.org [172.105.105.114])
	by mail.dewy.ru (Postfix) with ESMTPS id EDB61125BA8; Mon, 26 Oct 2026 17:22:51 +0300 (MSK)
X-Received: from smtp.subspace.kernel.org (conduit.subspace.kernel.org [100.77.114.92])
	by tor.lore.kernel.org (Postfix) with ESMTP id AB4E629A7A; Mon, 26 Oct 2026 14:20:51 +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=1793024448;
	b=j8zCY7aRhoKy+UKr/g52mYwuGR7CNnjTWbUC4n5kJtbQN17f/HZBBKHudYSH65Vo8GQR
	 ICW0Q91HjoJm23vE/GH9SbRQUkkG2hFpB7tZLU6AozYO4n5LrWBl0bbefXFUkCNBk5PV/
	 3iMllE2dx1R1tM+AyBQaN893K9oxMd8bPmXawq03yDYEMCu90XeGB3M8XcyDp3AyKaiRE
	 bdTG+IMivEystNq4y5KmCCe7UvohpamsIJlOklUnN/wDdBGd+h3eAe0zTjfdejS7hjzj4
	 nAdog//DO0O9JDcZTcfeieItG9WIwZK+9yQbH/fnVy00+5RFwh2gAvf60kGIQ07TXgw==
X-ARC-Message-Signature: i=2; d=subspace.kernel.org; s=arc20261015;
	a=rsa-sha256; c=relaxed/relaxed; t=1793024448;
	h=X-Original-To:Received:Received:DKIM-Signature:Received:
	 X-Forwarded-Encrypted:X-Gm-Message-State:X-Received:X-Mailing-List:
	 List-Id:List-Post:List-Help:List-Subscribe:List-Unsubscribe:
	 List-Owner:Precedence:MIME-Version:References:In-Reply-To:From:Date:
	 X-Gmail-Original-Message-ID:X-Gm-Features:Message-ID:Subject:To:Cc:
	 Content-Type:Content-Transfer-Encoding;
	bh=AmlF0+0aAM2fRJ2RV4wjFXkBSJJqDWyBurX+4vn392I=;
	b=s1f4+8f+XtK7WhbPiPdLOyoK5LA5yo4FVhShjZGoG+JMpwlKzRSD5gyh0PDMiAcuqeXr
	 5jG37wsP8QufrNStScVlpFp2vPOh+Ai1i7d6h8pTUIk41hCkKcKI70RbR7UXJIeGxxQGq
	 LF97DQlVs4UNiaWuKBDCPkH3chB0DtPfPY0l1G/sssft40uhTGtT1eegqxkis/xzjC7Qi
	 FuYsYZw35i3/EYyCUk3AEuftOrf3kmasl0lxfFBBTvpungVPTWKngJ5X2wD7pnWwdeiEU
	 uncM0CIfnVZN6YN3dVjiGVo8xQ1lnbqJ4UOvsKF1dBaZ1FQn6y/mJOLO1unKsk1CXiA==
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=PwrHKO5q;
	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 0CC99606A332;
	Mon, 26 Oct 2026 14:20:48 +0000 (UTC)
X-Authentication-Results: smtp.subspace.kernel.org;
	dkim=pass (2048-bit key, unprotected) header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b=PwrHKO5q
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=1793024447;
	b=Hy/xgyKUBR4jpCbRzhvNdcTuxgJiSvPnyB/vtDbOl191bIzQZyJL0U+IhfoHv8iG/WLU
	 Ei1Gh5Yo8Z8Jj5ENudaqZfXNvaInS4F3teusrVc+pAPruGeBpDTNRZE8rIi9e/jeWxJty
	 rRfabkDuGflI/By0HUm2/les/R68ITSEj7uNgV60LD9lohMo76jxs8fxEg1lF53bW+jkH
	 nqMc0daqDQnwdVoi9w5SBlDDTLv9B9X/K6s8ybFwoCuqoclirqN6dMxSLdt5QmsUn/Aql
	 WYiio2FuC2QdBQ8fJjzB6IoursHsJ5/cj0Bn8B4muRSU7gGecsE10EXrL+sXVn75TJg==
X-ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015;
	a=rsa-sha256; c=relaxed/relaxed; t=1793024447;
	h=Received:DKIM-Signature:Received:X-Forwarded-Encrypted:
	 X-Gm-Message-State:X-Received:MIME-Version:References:In-Reply-To:
	 From:Date:X-Gmail-Original-Message-ID:X-Gm-Features:Message-ID:
	 Subject:To:Cc:Content-Type:Content-Transfer-Encoding;
	bh=AmlF0+0aAM2fRJ2RV4wjFXkBSJJqDWyBurX+4vn392I=;
	b=jeZDRBlrB6TXBoVyjnIy9Czuv8q8I3beBAmW1BLrKpfLltkw9e1EEk29TjuNZA0SyoYc
	 h0z0KqS7zOkKTlVZ5rpZ/bF1QCw0o5V+MIDML8IxQ0YqMFUMiTZA22NmVwV3ZPrY2KNpP
	 PVV2I7QGNmJLfjvXYRR2e94m/dcGq0U4aUmT6W/bHlYOKE8HWUIOH8raoDGJm7TlI6xli
	 YPWS9HfG+7dGUQarV6IVHbsjYPRFKoKmllEtm7uicJcmyoX1eH2/zQLrdBFmrjj6UuOc1
	 K3KIUmTLuRPKkuuHu/ybyNtePCcVpuYObo/wEU/PZnljXj3hSaSopOI/oQVGPWqfbHQ==
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=PwrHKO5q;
	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 E7E9C606A321
	for <netdev@vger.kernel.org>; Mon, 26 Oct 2026 14:20:46 +0000 (UTC)
X-Received: by smtp.kernel.org (Postfix) with ESMTPSA id 822E31F031E8
	for <netdev@vger.kernel.org>; Mon, 26 Oct 2026 14:20:46 +0000 (UTC)
X-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org;
	s=k20260515; t=1793024446;
	bh=AmlF0+0aAM2fRJ2RV4wjFXkBSJJqDWyBurX+4vn392I=;
	h=References:In-Reply-To:From:Date:Subject:To:Cc;
	b=PwrHKO5qtJxFxRGL1vGL4JNW8fYL9264QY5VABTbch1W/dcwzLpgjUqGj/urzbo9E
	 0e2w6D5H9unmPYvIpHrm+qvIJW6BgV9qch9v/TWQ/uMoqRtPul6ao+kJRwJUGmNb10
	 GpX+/RfBNqRdOAxcFdo8ik4GWr089+Exfk9OHK3PquqEf19qG47JwzBLmA7gjzm+ie
	 HnRJNoBVVzGjl5I44Gd1rLthKrXjSL9DTz47XF/SdhbfV1Md5hQTV/K2GqxH3nOCqP
	 1SGaAQ87/uKKBq4FBrOujGqClneAKphm67ZhBntCtdKtN5loSvSMSvv0qMJ79FRDsI
	 fZPhLhUz80/iw==
X-Received: by mail-oa1-f46.google.com with SMTP id 586e51a60fabf-43bf9548df4so2717383fac.0
        for <netdev@vger.kernel.org>; Mon, 26 Oct 2026 07:20:46 -0700 (PDT)
X-Forwarded-Encrypted: i=1; AKwUvBwjD+lmI1iz+yQovK6lrosI+L97Sv0KDm7yIyVz3tXRq42SBknVo6K5pGBoPSaM4RXZI7DB3Lo=@vger.kernel.org
X-Gm-Message-State: AFq9FYKelhJ/yXyelnZo7olLz2rgyfcwUoZ1cWvHDF9elelXId57Jmn/
	DfhmTVpr4eNuSC5JhiVSJD3UgPiAXe25vy4IokhpXE+SlKAC20Sb7KEMhMM56E7+zLm3COzpMte
	vthJz40Ck+RtFODOlZgxpBYqaMYC0rzg=
X-Received: by 2002:a05:6871:419b:b0:49d:c9ed:21f2 with SMTP id
 586e51a60fabf-4a83f42e1c8mr3861088fac.18.1793024445749; Mon, 26 Oct 2026
 07:20:45 -0700 (PDT)
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
X-In-Reply-To: <20261026150541.a5a34642db9d1523f839f644@uniroma2.it>
X-Gmail-Original-Message-ID: <CAL4WiirtzVke8V8f6LJEWdOCDNevGxdQCFhXxEGiEMq-TNbsVA@mail.gmail.com>
X-Gm-Features: AclHuK8L92wlrbdXy0m1rYg5r51z1Kquhpb4YkZm0AcuyqBb82vwpDIOASY1obs
X-Cc: Tristan Madani <tristmd@gmail.com>, netdev-bot+sinfo@kernel.org, davem@davemloft.net, 
	kuba@kernel.org, pabeni@redhat.com, horms@kernel.org, 
	tristan@talencesecurity.com, david.lebrun@uclouvain.be, 
	linux-kernel@vger.kernel.org, netdev@vger.kernel.org, stable@vger.kernel.org, 
	stefano.salsano@uniroma2.it