Article View: linux.kernel.netdev
Article #12135Re: [PATCH net-next v2] l2tp: bump tunnel stats before dropping the session reference
From: Simon Horman
Date: Fri, 06 Nov 2026 10:11
Date: Fri, 06 Nov 2026 10:11
53 lines
9942 bytes
9942 bytes
On Tue, Nov 03, 2026 at 04:42:49PM +0800, Linkui Xiao wrote:
> From: Linkui Xiao <xiaolinkui@kylinos.cn>
>
> l2tp_udp_encap_recv() derives the tunnel pointer from the session it
> has just looked up, so the session reference is the only thing keeping
> the tunnel alive. Both error paths of the function drop the reference
> before jumping to the invalid label, which still dereferences the
> tunnel:
>
> tunnel = session->tunnel;
>
> if (version != tunnel->version) {
> l2tp_session_put(session);
> goto invalid;
> }
> ...
> invalid:
> atomic_long_inc(&tunnel->stats.rx_invalid);
>
> Reorder the error paths so the statistics are updated before the
> reference is dropped, removing the dependency on the tunnel staying
> allocated after its last reference is gone.
>
> Currently this is safe by accident: the only live entry point is the
> UDP encap_rcv hook, which is invoked under rcu_read_lock(), and the
> tunnel is freed by kfree_rcu(), so the tunnel memory outlives the
> dereference. Making the order explicitly correct keeps the function
> safe regardless of the calling context, instead of relying on every
> future caller holding an RCU read-side reference.
>
> The put on the version mismatch path came later, with commit
> 4d10edfd1475 ("l2tp: Fix memleak in l2tp_udp_encap_recv()."), which
> plugged a session leak.
>
> Found by inspection.
> Signed-off-by: Linkui Xiao <xiaolinkui@kylinos.cn>
> ---
> Changes in v2:
> - Describe the change as hardening instead of a reachable
> use-after-free: the socket backlog path pointed at by the v1 commit
> message cannot be reached, and the live receive path always holds an
> RCU read-side reference, so the old ordering is currently safe
> (Sashiko AI review).
> - Drop the backport tags (the Fixes tag and the Cc to stable)
> accordingly and retitle the patch.
> - Correct the index line: the v1 patch carried the blob hashes of an
> earlier draft of this change, so its new hash did not match the file
> the diff actually produces.
> v1:
> - Link: https://lore.kernel.org/all/20261027063657.1359170-1-xiaolinkui@126.com/
Reviewed-by: Simon Horman <horms@kernel.org>
Technical Details
Message-ID:
<20261106101137.GF865646@horms.kernel.org>Path:
mbox-mo1.pugleaf.net!archive.usenet.blueworldhosting.com!usenet.blueworldhosting.com!diablo1.usenet.blueworldhosting.com!usenet.network!.POSTED!vger.kernel.org!netdev+bounces-357916-linux-kernel-netdev=dewy.ruReferences:
<20261103084249.1337657-1-xiaolinkui@126.com>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-357916-linux-kernel-netdev=dewy.ru From: horms@kernel.org (Simon Horman) Newsgroups: linux.kernel.netdev Subject: Re: [PATCH net-next v2] l2tp: bump tunnel stats before dropping the session reference Date: Fri, 6 Nov 2026 10:11:37 +0000 Organization: Usenet Network Message-ID: <20261106101137.GF865646@horms.kernel.org> References: <20261103084249.1337657-1-xiaolinkui@126.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Injection-Info: usenet.network; logging-data="3846007"; mail-complaints-to="abuse@usenet.network" Cancel-Lock: sha1:5XCY66rWZlWQD1dK4NccXGyA1TE= sha256:24/eZHdq1649A0n1N4CGTYmyEQGjL2o63yNjTRChnkk= sha1:dbQTN95lMpaCl8HsBnylyKYXYVY= sha256:FRG9xLvgOorvtZ3zYyoXQqDDXTdDAiIN5kfuVQphzeI= Content-Disposition: inline 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 045841131F5; Fri, 6 Nov 2026 13:22:31 +0300 (MSK) X-Virus-Scanned: Debian amavisd-new at usenet.network X-Spam-Flag: NO X-Spam-Score: -3.401 X-Spam-Status: No, score=-3.401 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] 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 1u6KmmciJv73; Fri, 6 Nov 2026 13:22:24 +0300 (MSK) X-Received-SPF: Pass (mailfrom) identity=mailfrom; client-ip=172.105.105.114; helo=tor.lore.kernel.org; envelope-from=netdev+bounces-357916-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 A1AD71131D5; Fri, 6 Nov 2026 13:22:14 +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 B63F23487E; Fri, 6 Nov 2026 10:11:55 +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=1793959904; b=RGq3kpQ3PanpYz4HZla+u/xTmFfx6/A+pKPD9IVasdEmaaV8rtn/Mxa77ZvHztezrNEH QZrDRMmFUF9h1rY/Vdb7Ixm3S08JV0+yzIRRmNd0UNIOrsi/PRxvEBJjl7lQpA8b7YKLE ctMwzEP9/sjnWelLmW38nVXxGnmdGMTt75ud/Y8KZ4p3ZmqLIcn+6ebmCDYi9PVyjeZ2a UPztQUPU3xpZcCq9X2CrKSYVOwSRWpGrkrN+j92SKyeOpV7oNUJxDAJU0chEQMCizAhOr IXlSo1wQz5Qrt5lYfDfHmbkCA6+Yv7cjCjAJleVYn2G8R4rwzIBkSYqku1V2RbftcLw== X-ARC-Message-Signature: i=2; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1793959904; h=X-Original-To:Received:Received:DKIM-Signature:Date:From:To:Cc: Subject:Message-ID:References:X-Mailing-List:List-Id:List-Post: List-Help:List-Subscribe:List-Unsubscribe:List-Owner:Precedence: MIME-Version:Content-Type:Content-Disposition:In-Reply-To; bh=NVbdOhY0Y8hSqBaccRJIemSs5pQgbapaJJc/jw4bTlA=; b=xe6NP7r4C7kszgSkOnh/zFCxaBdvKxJ++tRGOr6BCtDYuwJFVzOZe6NBJCi7MmSGZZf+ KuPTEYoCi+NgrRGB4bH+LT+cZMocBgF0ZIRak8uPfynNI1W2Qu+BQVOI1x0s/5sNr6AXS vyuuEjbAq5qkgIjL7aNat28BmvMuy2IU5Lm1nJ/B5KgtR2/ubtH8BmLfSa2ps40gM3m+Z LR3tc5BKfPWLW9JvUWxBxYVWDRJQG0CP2fQJVDChy5dsSfU4Sfk151CRe8EwkCziuLLHB 9dBS5ENE7Frf7ZraZLLAPMc3+yanvcQq9atSXtivJ44w0xMgUExcmaPB3yEcxcdHpVw== 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="AF0/cyYI"; 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 E10A1606D807; Fri, 6 Nov 2026 10:11:43 +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=AF0/cyYI 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=1793959903; b=R/zMB9QmOsBHnjDischOuAKK4LulcO6ZNYqKJOhZ4QWPAEZpcL4F46OVDmWQIHV9S44z 7cjNYdLoDN0t4IFfO3pu2bWG7V2iz/2qIBWakLq0XN2KJGzwa6TVqOpM/F3xFi/2reH93 WhFI86DWam+N3KKAQ0gE7rqDE8DresoqkpjmkREwEtkvcPRXbp6p17/Dt5MOyoQf++ekO xTngQyxCVjATACPEsPzJehWHgYuLZZAb6gI4PkpZ0I7Dr8XDiMijg1fzsUhpjxiC/mW+5 F9wpwEbHPLktJIZkniJ5H7UcFGwtbUHRVAj55MUMdF4kIpOqwrM25GSKAp91zNJ2Kig== X-ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1793959903; h=Received:DKIM-Signature:Date:From:To:Cc:Subject:Message-ID: References:MIME-Version:Content-Type:Content-Disposition:In-Reply-To; bh=NVbdOhY0Y8hSqBaccRJIemSs5pQgbapaJJc/jw4bTlA=; b=KQbaGjLRCPemmg0iaSLF+bqsQFeSKexZLjKhdBSeYO/IHiWucFinRHIFWHsb/2jhk0FX 3jlT5DUyQ1SdYcn1Xn88nZkgBd3QoEA0a4XP5iZClzKn7C9lz5pdXRumIOcidhVjeC/ej mGUW3IGk2SgKNRPxa3NQhfvQJU0PEtZAxoYdYhVoKhpYippCH5CMc/cYR+xBnVyJ3VJZZ HGK6U3VMmKrjPv+QsesrgmOEVNmwUF7P6RsF4hK/4iR7ag/qtAZ3sWB0mrjYHCcsS1ZoH bk+Oop+KJZ7XsFenlgWQ1ilrjPXt1zQQTYJ+JezFh66yxR+F20wAy4JJxbUnHjIebzQ== 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="AF0/cyYI"; 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 C38C3606A32F; Fri, 6 Nov 2026 10:11:42 +0000 (UTC) X-Received: by smtp.kernel.org (Postfix) with ESMTPSA id C83761F008A3; Fri, 6 Nov 2026 10:11:39 +0000 (UTC) X-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org; s=k20260515; t=1793959902; bh=NVbdOhY0Y8hSqBaccRJIemSs5pQgbapaJJc/jw4bTlA=; h=Date:From:To:Cc:Subject:References:In-Reply-To; b=AF0/cyYIERpgU0HBQxi/PdKZp0ySQN/ch9rNzlnzK2Yx3SgOkGMggfUBGB4tnknIy FYUwNMp6vwHdhojBUcl1OoypKlIZGO1vkNnRQN5CwTImzu4+nVCH2mhzqqm8Dm/Tjb pbhPEFfx0rNwLFDiVkO+LgwPcDrRhC0EOqppkK7vev1kWZvd3BIni/u351TuiHHqxh mTvXjX3o+m+iMn2AHLiuTbLfHcBf01Oj2Ez2KcoJR9tbhwQLXRxqH7+PzqQsXoe1eO vPCx2JxRwUFq7pgnZfMnXzpkrGthYv6bdNMyn759+zoUy3qr/IuQUxultlWZYkxID2 F1nLp1YvZHjmw== X-Cc: davem@davemloft.net, edumazet@kernel.org, kuba@kernel.org, pabeni@redhat.com, michael.bommarito@gmail.com, gnault@redhat.com, alice.kernel@fastmail.im, kuniyu@google.com, nicoyip.dev@gmail.com, mail@david-bauer.net, netdev@vger.kernel.org, linux-kernel@vger.kernel.org, Linkui Xiao <xiaolinkui@kylinos.cn> 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: <20261103084249.1337657-1-xiaolinkui@126.com>