🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: linux.kernel.netdev
Article #8958

Re: [PATCH net v2] ipv6: raw: fix use-after-free in rawv6_send_hdrinc()

#8958
From: David Laight
Date: Fri, 30 Oct 2026 16:05
69 lines
13772 bytes
On Mon, 26 Oct 2026 12:48:08 +0800
Zhou Qiuyue <n0ps1edzz@gmail.com> wrote:

> rawv6_send_hdrinc() caches the route before handing the skb to
> l3mdev_ip6_out(). The VRF output path may replace skb->dst and release
> the original route, leaving the cached pointer stale.
> 
> The function later dereferences that pointer for statistics accounting
> and as the output device passed to NF_HOOK(). Its RCU read-side critical
> section starts after l3mdev_ip6_out(), so it cannot prevent the old route
> from being reclaimed in between.

Doesn't it also pass the wrong rt->dst.dev value to NF_HOOK() ?

> Reload the route from the current skb destination after
> l3mdev_ip6_out() returns.

Have you looked at just saving rt->rt6i_dev locally?
The rcu free of the temporary rt_info is expensive.
Last I looked it has to kmalloc() a little structure and later adds
latency to the softint code.
The thing is some applications can send a lot of packets through this path
(and I mean upwards of 50000 per second).
So even a kmalloc/kfree in this function would be better.

That might even save the rcu_read_lock() being needed.

David

> 
> KASAN reports a slab-use-after-free in rawv6_sendmsg(), with the route
> allocated by ip6_dst_alloc(), freed by dst_destroy() from rcu_core(), and
> the related RCU callback queued from vrf_l3_out().
> 
> Fixes: 4c1feac58e06 ("net: vrf: Flip IPv6 output path from FIB lookup hook to out hook")
> Cc: stable@vger.kernel.org
> Signed-off-by: Zhou Qiuyue <n0ps1edzz@gmail.com>
> ---
> Changes in v2:
> - Rebased onto the current net tree at 7076f684d513.
> - Regenerated the patch with git-format-patch so it applies cleanly.
> - Corrected the Fixes tag to the commit that made the IPv6 VRF path reachable.
> - Shortened the code comment and added the required recipients.
> 
> v1: https://lore.kernel.org/r/6adad51d.8fc0b0c9.1ec657.1868@mx.google.com
> 
> Thank you to Hangbin Liu for reviewing v1 and pointing out the submission
> issues.
> 
>  net/ipv6/raw.c | 3 +++
>  1 file changed, 3 insertions(+)
> 
> diff --git a/net/ipv6/raw.c b/net/ipv6/raw.c
> index b965258cf..bdea82543 100644
> --- a/net/ipv6/raw.c
> +++ b/net/ipv6/raw.c
> @@ -654,6 +654,9 @@ static int rawv6_send_hdrinc(struct sock *sk, struct msghdr *msg, int length,
>  	if (unlikely(!skb))
>  		return 0;
>  
> +	/* l3mdev_ip6_out() may have replaced the skb dst. */
> +	rt = dst_rt6_info(skb_dst(skb));
> +
>  	/* Acquire rcu_read_lock() in case we need to use rt->rt6i_idev
>  	 * in the error path. Since skb has been freed, the dst could
>  	 * have been queued for deletion.
> 
> base-commit: 7076f684d5132e6a6145e1da2fa74771ecd052e5
Technical Details
Message-ID: <20261030160532.4832d994@pumpkin>
Path: mbox-mo1.pugleaf.net!archive.usenet.blueworldhosting.com!usenet.blueworldhosting.com!diablo1.usenet.blueworldhosting.com!eternal-september.org!feeder.eternal-september.org!usenet.network!.POSTED!vger.kernel.org!netdev+bounces-353836-linux-kernel-netdev=dewy.ru
References: <20261026044808.613-1-n0ps1edzz@gmail.com>

Show Full Headers
Complete Article Headers
Path: mbox-mo1.pugleaf.net!archive.usenet.blueworldhosting.com!usenet.blueworldhosting.com!diablo1.usenet.blueworldhosting.com!eternal-september.org!feeder.eternal-september.org!usenet.network!.POSTED!vger.kernel.org!netdev+bounces-353836-linux-kernel-netdev=dewy.ru
From: david.laight.linux@gmail.com (David Laight)
Newsgroups: linux.kernel.netdev
Subject: Re: [PATCH net v2] ipv6: raw: fix use-after-free in
 rawv6_send_hdrinc()
Date: Fri, 30 Oct 2026 16:05:32 +0000
Organization: Usenet Network
Message-ID: <20261030160532.4832d994@pumpkin>
References: <20261026044808.613-1-n0ps1edzz@gmail.com>
MIME-Version: 1.0
Content-Type: text/plain; charset=US-ASCII
Content-Transfer-Encoding: 7bit
Injection-Info: usenet.network;
	logging-data="2270542"; mail-complaints-to="abuse@usenet.network"
Cancel-Lock: sha1:W1GfXHFlvDVaTUdWTvYcGAfo7ck= sha256:IKkZqqnTS7ney7iXubwyFUHR7f2TK1yD2vmTljHbEPI=
	sha1:IdoDEBQhga2uYvn3KVPcNoqSjFQ= sha256:FK69G1g3eiic+7shl6ADgFr9qaA/jyYGjgNUrJp9w/4=
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 7B72F125CA0; Fri, 30 Oct 2026 19:06:08 +0300 (MSK)
X-Virus-Scanned: Debian amavisd-new at usenet.network
X-Spam-Flag: NO
X-Spam-Score: -3.048
X-Spam-Status: No, score=-3.048 tagged_above=-9999 required=6.31
	tests=[DCC_REPUT_70_89=0.1, DKIM_SIGNED=0.1, DKIM_VALID=-0.1,
	DKIM_VALID_AU=-0.1, FREEMAIL_FORGED_FROMDOMAIN=0.001,
	FREEMAIL_FROM=0.001, HEADER_FROM_DIFFERENT_DOMAINS=0.25,
	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=gmail.com
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 zqywl2_qvP62;
	Fri, 30 Oct 2026 19:06: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-353836-linux-kernel-netdev=dewy.ru@vger.kernel.org; receiver=<UNKNOWN> 
X-Authentication-Results: OpenDMARC; dmarc=fail (p=none dis=none) header.from=gmail.com
X-Received: from tor.lore.kernel.org (tor.lore.kernel.org [172.105.105.114])
	by mail.dewy.ru (Postfix) with ESMTPS id 0CE99125CA1; Fri, 30 Oct 2026 19:05:50 +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 03DA12B7A7; Fri, 30 Oct 2026 16:05:43 +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=1793376342;
	b=PpDz6X36V9WLCT9OM+ZX7aWPhheRbB9AKLG3QaGKE2Ov6AL62yS7klNvEAKaTNr2ir1M
	 xbbhACK75DCL99F57G1AWn0aigAoxkocRiIOSoUGaPGOSxxkxMPO4GerKdo2jSliNbJkO
	 xK+/Mf/Qbgmlw7I48xQX71tqnX6woK1nTQLFAfswtE4CXyTSR+T/LyAZ3TqMY2LiJVZlv
	 kuxX26u4+XKPdJ4ZbeCs9wMn9+jkSRG+NLYoew/zjYETEr6gyFroBAZf2YFIVz7hoJgQC
	 lz2+HiFFM0Qqu7zPT/byB6UOrK3UPN4/hDzfo8r5NqgSimL3/rDmT7ZwbBd+ieQicFA==
X-ARC-Message-Signature: i=2; d=subspace.kernel.org; s=arc20261015;
	a=rsa-sha256; c=relaxed/relaxed; t=1793376342;
	h=X-Original-To:Received:DMARC-Filter:Received:DKIM-Signature:
	 X-Google-DKIM-Signature:X-Gm-Message-State:X-Gm-Gg:X-Received:
	 Received:Date:From:To:Cc:Subject:Message-ID:In-Reply-To:References:
	 X-Mailer:X-Mailing-List:List-Id:List-Post:List-Help:List-Subscribe:
	 List-Unsubscribe:List-Owner:Precedence:MIME-Version:Content-Type:
	 Content-Transfer-Encoding;
	bh=UVN9g4RWdwp5/he8LF058qsOA18MIA0nq3SVY0VenDU=;
	b=k0LnuviBUckzLWqH4WEcm/AioxX1TRZuaHSBSTavzgiq/yDwrxBesegljgEAEMTRSW6W
	 zwiGZlY3PtJvtSP3llLL+2Yzwk/7qOwHTLeOo2JIYOvvzC6VAwF4F7EEolkPoRhsS8Bi4
	 c0eQIlvxL2qYVotxyJk1kWVLsPtGnv4sNxCL8u3zaT2lcCDVH+TYhhXvymDF3ho5O2ve5
	 88SkVX5lwWm/VzLhy2tgeE3W3efYA3GBtM0f+My7rei1oNQVGCbR2hGtqkVHGor9I54lu
	 JUeOxJNCxOqDRUwmZhzQ+YuF4n6L9eQ5TFP/vRb5W6DCPDeKf2Cd7WJFiZM1+j32B2A==
X-ARC-Authentication-Results: i=2; smtp.subspace.kernel.org; 
	dkim=pass header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20260707 header.b="g/b6FOCz";
	dmarc=pass header.from=gmail.com;
	spf=pass smtp.mailfrom=gmail.com;
	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 94D01606A322;
	Fri, 30 Oct 2026 16:05:42 +0000 (UTC)
X-Authentication-Results: smtp.subspace.kernel.org;
	dkim=pass (2048-bit key, unprotected) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20260707 header.b=g/b6FOCz
X-Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=209.85.221.47
X-ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none;
	t=1793376336;
	b=XyAUe2aGF5rhgXpBzbnU6xpXN/YtgosXFgXkNnjNXeFZWCKEeRujH+RhBe8EoS4eZvqX
	 3V8f82pkEdUdFgB9LQkB65+6/AOLGWa0caeGk7YHOi6zqI1SK9iSiXtXpvSex6twheQoV
	 o++89apQJzldneXKQE/Enz7+IuxcdxAz3OGCnVCmnR9lYxE6g95ARTjoXTTq5v7U7h/Bz
	 9KxNiGbqa5YG0nnwbbWjWn79MNiQRoyONDNrDc0J1KB3peoAiBVssXqdGCQQ7maBL1wsA
	 o3I00QbI0kobCfpkBCt5nTsCtr8lXugpMbZd/aaQ2iUTMmUt81wo6P9AihFNgN4xAuA==
X-ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015;
	a=rsa-sha256; c=relaxed/relaxed; t=1793376336;
	h=DMARC-Filter:Received:DKIM-Signature:X-Google-DKIM-Signature:
	 X-Gm-Message-State:X-Gm-Gg:X-Received:Received:Date:From:To:Cc:
	 Subject:Message-ID:In-Reply-To:References:X-Mailer:MIME-Version:
	 Content-Type:Content-Transfer-Encoding;
	bh=UVN9g4RWdwp5/he8LF058qsOA18MIA0nq3SVY0VenDU=;
	b=lqsB3Bsk86B45YlwLAJvU4x/SC85y8qngjX9wIgqcS1exAZauvjVLA+jFohYYWPIVHJ1
	 yNJtZrWgOyX6k3cdJeY035ZF+yEcw7QpPWszePnXJTSpmvnne+Ppvj+AcJ2K+e4ir+sdS
	 UdGi8JlLZ7E0N6emEjIGtdodxnvB/jhXX3a5Oedxpzpza64lfAUwrSTOXzDIp09Of1tC5
	 AXPbyYHmxcsMK5gAkVcJ+rpktWrM/OcrhzKqdFb51jTaEqlgFGLEjX12SHzNtGcH3L9dK
	 beh1qVnVN/6Ec79q5wEt0yLV0MeDB7+ZKHgaEs/rcoXH8r2lQTacr/+vEVE14T04d0A==
X-ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; 
	dmarc=pass header.from=gmail.com;
	spf=pass smtp.mailfrom=gmail.com;
	dkim=pass header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20260707 header.b="g/b6FOCz";
	arc=none smtp.remote-ip=209.85.221.47
X-Received: from mail-wr1-f47.google.com (mail-wr1-f47.google.com [209.85.221.47])
	(using TLSv1.3 with cipher TLS_AES_128_GCM_SHA256 (128/128 bits)
	 key-exchange X25519 server-signature ECDSA (prime256v1) server-digest SHA256)
	(No client certificate requested)
	by smtp.subspace.kernel.org (Postfix) with ESMTPS id 61624606A31F
	for <netdev@vger.kernel.org>; Fri, 30 Oct 2026 16:05:36 +0000 (UTC)
X-DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org 61624606A31F
X-Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com
X-Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com
X-Received: by mail-wr1-f47.google.com with SMTP id ffacd0b85a97d-48e20edd106so740555f8f.1
        for <netdev@vger.kernel.org>; Fri, 30 Oct 2026 09:05:36 -0700 (PDT)
X-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
        d=gmail.com; s=20260707; t=1793376335; x=1793981135; darn=vger.kernel.org;
        h=content-transfer-encoding:content-type:mime-version:references
         :in-reply-to:message-id:subject:cc:to:from:date:from:to:cc:subject
         :date:message-id:reply-to:content-type;
        bh=UVN9g4RWdwp5/he8LF058qsOA18MIA0nq3SVY0VenDU=;
        b=g/b6FOCzOFlOpRQPAWM7QQdQwfA/v+03wjKewq/H51+O3q089hlqictJUYXPfi7F4t
         fON86ko4exfQhOzHAkWFRwIZplM7VlN2tpOEkLMCOIThqhO0XVrMoGcXlIVpPT5+cdkc
         sV3GACLdrhk3fr8IOW00299gkrCyhuG15mrAFWXCnMDnfjt6bAHRLiC5LLDxebhHn1fd
         vuE28u2nYX55IGHqqO+55MqcAWtlefC5QB83vV0XJz3k/6d12b9W9QoZyagAJ6v3FKQB
         HaTsvZCQ4UgcxryKdADU+XTi1uvu7lcSz8VrD1CKxf4pnYY2yhQJ61ZAJJgi6szEgZZI
         idIA==
X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
        d=1e100.net; s=20260707; t=1793376335; x=1793981135;
        h=content-transfer-encoding:content-type:mime-version:references
         :in-reply-to:message-id:subject:cc:to:from:date:x-gm-gg
         :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to
         :content-type;
        bh=UVN9g4RWdwp5/he8LF058qsOA18MIA0nq3SVY0VenDU=;
        b=Kz9j1rEKGL54e38qW5VedWfPPCbwSVAC11hEs657+5USVi35zSDxGdKehcBY9wFxfJ
         OP3rqvEaqiiRYeaq51Li3lKJtTRqvwkuxfy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ud
	T6WLCcXASYck=
X-Received: by 2002:a05:6000:4284:b0:48e:3678:5112 with SMTP id ffacd0b85a97d-48e6e2ef7b0mr6204489f8f.21.1793376334674;
        Fri, 30 Oct 2026 09:05:34 -0700 (PDT)
X-Received: from pumpkin (82-69-66-36.dsl.in-addr.zen.co.uk. [82.69.66.36])
        by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-48e71b77f06sm3987846f8f.21.2026.10.30.09.05.32
        (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256);
        Fri, 30 Oct 2026 09:05:33 -0700 (PDT)
X-Cc: netdev@vger.kernel.org, David Ahern <dsahern@kernel.org>, Ido Schimmel
 <idosch@nvidia.com>, "David S. Miller" <davem@davemloft.net>, Eric Dumazet
 <edumazet@kernel.org>, Jakub Kicinski <kuba@kernel.org>, Paolo Abeni
 <pabeni@redhat.com>, Simon Horman <horms@kernel.org>, Hangbin Liu
 <hangbin.liu@linux.dev>, linux-kernel@vger.kernel.org,
 stable@vger.kernel.org
X-In-Reply-To: <20261026044808.613-1-n0ps1edzz@gmail.com>
X-Mailer: Claws Mail 4.1.1 (GTK 3.24.38; arm-unknown-linux-gnueabihf)
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