Article View: linux.kernel.netdev
Article #9300[PATCH net] bpf: lwt: Free the skb when bpf_xmit() fails to expand the headroom
From: Yuqiang Sun
Date: Sun, 01 Nov 2026 18:23
Date: Sun, 01 Nov 2026 18:23
66 lines
13262 bytes
13262 bytes
When an LWT xmit program returns BPF_OK, bpf_xmit() makes sure that
the skb still has room for the link layer header. If
pskb_expand_head() fails there, bpf_xmit() returns -ENOMEM without
freeing the skb. Its callers, lwtunnel_xmit() and then
ip_finish_output2() or ip6_finish_output2(), take any return value
other than LWTUNNEL_XMIT_CONTINUE to mean that the skb has been
consumed, so nothing frees it.
Each such failure leaks the skb, together with what it holds: its dst
and its charge to the sending socket, so the socket is never freed
either. The other error paths of bpf_xmit() (BPF_DROP, an illegal
return code, a changed protocol, a failed reroute) all free the skb.
Free it here too.
The leak was found with kbound, a static analysis prototype for
ownership mismatches at kernel interfaces, on v7.2.12; it is present in
mainline.
Build-tested with x86_64 and arm64 allmodconfig (W=1, sparse): no new
warnings. Run-tested on QEMU (x86_64, KVM) with KASAN: a route through a
dummy device with an LWT xmit program that pushes one byte with
bpf_skb_change_head(), so the headroom check has to expand the head, and
failslab limited to allocations under bpf_xmit(). Each of 10 pings then
fails with ENOMEM. Without this patch each leaves a raw socket behind
(RAW slab objects 6 -> 16); with it none does (6 -> 6), and nothing else
is reported. Without injection both kernels go from 6 to 6.
Fixes: 3a0af8fd61f9 ("bpf: BPF for lightweight tunnel infrastructure")
Cc: stable@vger.kernel.org
Signed-off-by: Yuqiang Sun <izaiahsun@gmail.com>
---
Notes:
The bug was found with kbound, a research static analysis prototype.
The patch, the changelog and the test setup were written with the help
of an AI coding assistant (Claude); I have reviewed and tested them as
described above.
The runs were on mainline d135ab453a74; the code this patch touches is
the same there and in net, which it is based on.
net/core/lwt_bpf.c | 4 +++-
1 file changed, 3 insertions(+), 1 deletion(-)
diff --git a/net/core/lwt_bpf.c b/net/core/lwt_bpf.c
index da49364ec63d..dfb2f9253e81 100644
--- a/net/core/lwt_bpf.c
+++ b/net/core/lwt_bpf.c
@@ -304,8 +304,10 @@ static int bpf_xmit(struct sk_buff *skb)
* made before LWT xmit.
*/
ret = xmit_check_headroom(skb, hroom);
- if (unlikely(ret))
+ if (unlikely(ret)) {
+ kfree_skb(skb);
return ret;
+ }
return LWTUNNEL_XMIT_CONTINUE;
case BPF_REDIRECT:
base-commit: cb284914e749388eef402938bdb3115fe1f6d337
--
2.53.0
Technical Details
Message-ID:
<20261101182343.17991-1-izaiahsun@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-354279-linux-kernel-netdev=dewy.ruShow 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-354279-linux-kernel-netdev=dewy.ru
From: izaiahsun@gmail.com (Yuqiang Sun)
Newsgroups: linux.kernel.netdev
Subject: [PATCH net] bpf: lwt: Free the skb when bpf_xmit() fails to expand the headroom
Date: Mon, 2 Nov 2026 02:23:43 +0800
Organization: Usenet Network
Message-ID: <20261101182343.17991-1-izaiahsun@gmail.com>
MIME-Version: 1.0
Content-Transfer-Encoding: 8bit
Injection-Info: usenet.network;
logging-data="2738737"; mail-complaints-to="abuse@usenet.network"
Cancel-Lock: sha1:Y4JunTtDF78ZbCQBpUiKocS50Lo= sha256:5jR3fx8CwhP32IWRvxjwPHRREU4tg023mnZB67o5meY=
sha1:viwn48Fd0ws7gih7OH0hfkKyk5M= sha256:Y2++mEaAZ2oZ5ihSqiii2zgeqWHx9j+8xIjdO8XBsrQ=
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 3EA20112355; Sun, 1 Nov 2026 21:25:02 +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 KXmzK0CHL1K5;
Sun, 1 Nov 2026 21:24:59 +0300 (MSK)
X-Received-SPF: Pass (mailfrom) identity=mailfrom; client-ip=172.234.253.10; helo=sea.lore.kernel.org; envelope-from=netdev+bounces-354279-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 sea.lore.kernel.org (sea.lore.kernel.org [172.234.253.10])
by mail.dewy.ru (Postfix) with ESMTPS id 3B0A7112341; Sun, 1 Nov 2026 21:24:50 +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 F040F23BC9; Sun, 1 Nov 2026 18:24:06 +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=1793557446;
b=hwykj7sFnOP4oc2DJiKg7skC8Ewdb8w2CfReFW6SLaXhAJtlIVPtg4YgMl7ssz7nxWnA
F9ueBbaKJssUcrWOmAKB19P+L1CKrlfA0OgIVxEXmFK0IjaxS9iEIr1pxQs9CDbDd64c1
UyjtoeKbeAvQtwBdIFv0uTaGxDGG9cILj/xOE1r1r6hmn6n7e8u3w5v21Al30JTWd9NTV
cjzydtUC4z4p180juTJRH49VebRmvfThIWUSyDezTMk7oMn8HK0WfuSo0Pv28h55WUOyr
cicvSiPDjcrJ26xCst756guMFBCMiqJDGO14EKASfA8Rn37w8dlIXweE3Sx9uOEqeIw==
X-ARC-Message-Signature: i=2; d=subspace.kernel.org; s=arc20261015;
a=rsa-sha256; c=relaxed/relaxed; t=1793557446;
h=X-Original-To:Received:DMARC-Filter:Received:DKIM-Signature:
X-Google-DKIM-Signature:X-Forwarded-Encrypted:X-Gm-Message-State:
X-Gm-Gg:X-Received:Received:From:To:Cc:Subject:Date:Message-ID:
X-Mailer:X-Mailing-List:List-Id:List-Post:List-Help:List-Subscribe:
List-Unsubscribe:List-Owner:Precedence:MIME-Version:
Content-Transfer-Encoding;
bh=PousPftMuxge1de4JgtYSbXjOqqZ3UAm2KBK0fUdmuE=;
b=Gw9SSICMhQJJN+c6HJiubELd95BVRxr2uc5JswD3HV0H+l7DM13VGRDzvLV8vlWbqW1I
o8DhdfJhl3/hTC9PqTzZtN83VMchIRCyjGr0INd9WQtDFABJjRbOoCafZihBOOpYUkOzM
taDSboMop1YQ830tUKlHFEsnQeDb2x8nZlKuvHCJ6Bp0EetuP3GCYj4sSSPsrUuA9VTwR
Pl8IfO3l1lIX1CxLZ5Nb6hGhOT9eGS0s+IjpHqD3tlkEQReF6OD5B9tLbeCGlk2RDa5e9
avmgS4SyGXxgJvv4KIQUWokKzSn1tcD/V4ovx4O04T3KAwEDxOfoDHBBVjc2BFpzXDw==
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=jSFaeFYu;
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 C6E0D606A32C;
Sun, 1 Nov 2026 18:24:06 +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=jSFaeFYu
X-Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=74.125.82.174
X-ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none;
t=1793557435;
b=HArJtlGOhP6tdiAPJLxIWaRrOqiP/cRwp5qqTDmOWCfwa15RV47tispHllPWw4BPgrR2
k91i+1LMHaEhvm5mYBGUA2UDBCC7CtrFz8qCFmxVMoPdK0AB0eFCk16X3//mMUVDOfGs2
rpGCMvtF6/URZ5axgFiQGi8ZZWXkGts44FSSlGtpjHcW+UH8LEMy5f1XfwcljXn2+o5nZ
HdU6CDdpmnomNJLvHuD2BtwHBMUS0zYTgif365o8K5CJXe+WvIFXymyhVSXKLndjLtMdC
vuKhOo9H5SVgUj8/5KxmO1R8cCPBm0oWKQ/Zg+iFHkmQzm31KfN+4dIUwnTqvszdvlw==
X-ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015;
a=rsa-sha256; c=relaxed/relaxed; t=1793557435;
h=DMARC-Filter:Received:DKIM-Signature:X-Google-DKIM-Signature:
X-Forwarded-Encrypted:X-Gm-Message-State:X-Gm-Gg:X-Received:Received:
From:To:Cc:Subject:Date:Message-ID:X-Mailer:MIME-Version:
Content-Transfer-Encoding;
bh=PousPftMuxge1de4JgtYSbXjOqqZ3UAm2KBK0fUdmuE=;
b=YQWKuQuvF5q6rFJMbZVisjD0IX1dhZrtkV+HhKgYmpMmOx/zDGx41n70rmYdSHaoNGRJ
sOLNh8tLEEtsVdqjAxLNAFfIT/rfQ/v9I8lbcsl933E0PZs3l0TlF869JFWguoPQPD0Kf
jgENHiNsD9ijx5hjcUtk8BaJh3OY9Q/J5E8iSmyhxLhjSmFrIcIYGtgWTPwscx5BWrw+C
6tRl3fvMH8ho7aQbVCMn2fvnUu9gd5nvOe2fQRXCArvZptrDhkBElg94eUGLYcPwQq5xJ
x7WQLPDylN86Ty9n32MOajbDWdJxAkPgnPXfor9i6/hiSvKS88kZ4mg7ny+8fkybRqA==
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=jSFaeFYu;
arc=none smtp.remote-ip=74.125.82.174
X-Received: from mail-dy1-f174.google.com (mail-dy1-f174.google.com [74.125.82.174])
(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 3B0E7606A324
for <netdev@vger.kernel.org>; Sun, 1 Nov 2026 18:23:55 +0000 (UTC)
X-DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org 3B0E7606A324
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-dy1-f174.google.com with SMTP id 5a478bee46e88-36a18fc7a38so3493346eec.1
for <netdev@vger.kernel.org>; Sun, 01 Nov 2026 10:23:55 -0800 (PST)
X-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
d=gmail.com; s=20260707; t=1793557434; x=1794162234; darn=vger.kernel.org;
h=content-transfer-encoding:mime-version:message-id:date:subject:cc
:to:from:from:to:cc:subject:date:message-id:reply-to:content-type;
bh=PousPftMuxge1de4JgtYSbXjOqqZ3UAm2KBK0fUdmuE=;
b=jSFaeFYuK/zwL+ige/xGHmU4b5Ji2VCn1jiK5QiS2ac9ZOVljLBgogYTjdJtZeAvVe
E6A/aFGnyDJZAEicrf9Cz4yQfDorfvGJTLIMlqgPpIh0Pmcd3hcnkQnOxitpF2/597lZ
o25RBf8S7etBYJcRT4rputGTabU14ly7UIyemBAprUfCiAtZH1ssDoRsuJoCFz1Gwlzu
sM7+6oyQuztxUNRLzhFhXTaTV8an2LUi69zW0xRIcvs07fgz6g5feOshuDRA5c9hztI7
rQtG7FiY+Il4e61X0NIWWHRxVetattD5Ft+mXkSQ7rJymROdkFcR3LOX8lNDZXZiKcxr
xD0g==
X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
d=1e100.net; s=20260707; t=1793557434; x=1794162234;
h=content-transfer-encoding:mime-version:message-id:date:subject:cc
:to:from:x-gm-gg:x-gm-message-state:from:to:cc:subject:date
:message-id:reply-to:content-type;
bh=PousPftMuxge1de4JgtYSbXjOqqZ3UAm2KBK0fUdmuE=;
b=fa8UmUJXyvc1cLcGdPIiAnG0EnjWgSlZYQym1VhpkFCE/yIXzgW3i7NNoAfUhTXs2V
0bOBQI1K0Vz3494rj2XG7jTsPeRsrH7ArUCgtQxCpsDYJovAPAQ2UH+/F8o2g7Ki75FJ
dYKteMpo10Z97mGbxZ4VuLQR2XKhzsUoi3NT0G0Yw5jOdI+KEclUel8uH9CMF/CpttvE
4RB1FFXIRn/JzFNqpliGzuJrCrTUQufeAAs6vSJIQx3HG2k2Bf7e6fg3dRd6SDfpuIVd
ZHj2pSPh3rtYPyGW74ch6PyGORhNHhtkNCaa/H0BZJ+hEFeWWO4jpKshNC8kogx9RCaQ
z33g==
X-Forwarded-Encrypted: i=1; AKwUvBx0Uty0sc4QEj5Ql9v7ycwZ8I/WizbR2fXm3cU4Bz6mWuBQhcyALZZFxYVIgKFRpZ57huUxuaE=@vger.kernel.org
X-Gm-Message-State: AFq9FYILrogc8HhvWmM6X1CJmnEd7Ovs8dgeyTN0kwBAxj9O5Im9hb3y
7MlLTZBwUmz0MXo+GWAtO9aHetrYCeBJbADmuqEhJJliJ2mNMxn0zJ4e
X-Gm-Gg: AYBFou0evKbpo7rIuvm/ZSiSiUIi6fMnUpOos3j3klX6baynvT5hOj5rb4EZuAZ5JKI
ESkUvqD2Ggn3mERqfboWGrccaKFBtb9sEiGjlG3ijSJ/nR2ZXV9RvHj8fBrh6PKMcWpdM5w8DbP
cy4hYwB/0gMPZL8n7o+hJSKhzoHTy+7/TzZxe96JSUl4SHsDAQEit2/ta2XE5Lnu3TfsNKF0ytm
qMPqymj5z17XQ5HfBda8HMu7KvRuZ5/dQjYCBMd6VlnRGjNFIkONBjz8q38m7p+KWsiZ1Xnn2Qj
hmw1vndHHH18QK0WCn3sezYumvro7LBJG8ZiWxV0SfXotSLpB5CNNnbwDyJT6fEgfwoUMVeBqaN
/2y1OSzK/kOnnbmN0sVazIunoYd529ILz0XLMmRxOlTKX92+onlfUN68PyjZgSuS3NRiPLzu9q6
N9tRyB+CX4dYhwHTe3HBswDiqN8UVgey9zAF06S5/0YVZo1i+9E24EC81iffZt+YbFl7wkrzbaz
qXooeqvXk+gAViYaDEUTuIauoP54/U4PpUvbwkpjdWiq8B3Tv3FTSWIHQRlLgxOdreQIBFMVvqe
6fyvEUOWHEN8tXbFRBhP5tjGPMKGpzvO1aEDxVSITuNoMJRc4bYkXqJPtzc39Qr3gg==
X-Received: by 2002:a05:7300:e9cf:10b0:369:f126:9ce2 with SMTP id 5a478bee46e88-36a42481f39mr14812550eec.41.1793557434277;
Sun, 01 Nov 2026 10:23:54 -0800 (PST)
X-Received: from localhost.localdomain ([2400:d802:dd7:8000:50b9:9b10:1e19:1f0a])
by smtp.gmail.com with ESMTPSA id 5a478bee46e88-36a428fa380sm27298976eec.12.2026.11.01.10.23.49
(version=TLS1_3 cipher=TLS_CHACHA20_POLY1305_SHA256 bits=256/256);
Sun, 01 Nov 2026 10:23:53 -0800 (PST)
X-Cc: horms@kernel.org,
daniel@iogearbox.net,
martin.lau@kernel.org,
ast@kernel.org,
tgraf@suug.ch,
zirajs7@gmail.com,
bpf@vger.kernel.org,
netdev@vger.kernel.org,
linux-kernel@vger.kernel.org,
stable@vger.kernel.org
X-Mailer: git-send-email 2.54.0
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