From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=100.103.45.18 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796384030; b=hB8WBXdujeTxvVrLCDaux6r8BpYR0NG9+xPtCd+VAE+KgcnqzUuM4K+1E3mJ+egaznAh ald9LEceJvbWmp5bsbd4N/j6KUCC+tURNRdNPs9d9d2bCQUFn+EVVV0w2sr4Bwq8GBE7p M4rl5/KIKwRS6FSOPNO5z25sD/Hr8bBjq/CTMdC+MRDYNOgQQS66mb0RzkPCR2ZD7Zxs9 FpuKanxoI6yOdVuDeuzMi/O1CjHJjXU6XWfIsKOaPEn7RrqLp8rzbLz3dbcY4UEDm1rIE g7m/bciSDH6/VzIIBXtLlQ8ZpACxaZm/WPXB+JKqA1BQhWAMmNjyEwW94hu9xeVaUgA== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796384030; h=Received:DKIM-Signature:From:To:Cc:Subject:Date:Message-ID:X-Mailer: In-Reply-To:References:User-Agent:X-stable:X-Patchwork-Hint: MIME-Version:Content-Transfer-Encoding; bh=ezRzZOW8kzN9qYExdyjzpnC9H0OiE2fm7VtWX+DV8Kw=; b=j7QN+ZYDRMOOjmIzl+ITHYXtcKwhVka1WzTTw62oekoyYGVGeUC+LFZ+MDlaH4/cIBtx E7TVmi2wLoGDFzU0y2L1aWL/qmSCA6ZW+cEoewGsEqfqB9hvuPkht0rsAmThseQNJSI7+ qfQDOOViQV/ptVmJdZgkHZzQXfksr3T6/cRM/y1oRCYr9jlZONe333toybsflrCLpsaEK qLwN1Fp0ONn0MzUcWVBM6na/5qAxFenn6yfct9YCa7e96i+HiJ4sl2WdM/TzjVMEHGB6+ /LcFXpMpMKf3NBHmUKou9N4KE3v4ZCKbgN90AALCEzSLQwPrg6fpuuscu90qv0WL9Gw== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass header.d=linuxfoundation.org header.i=@linuxfoundation.org header.a=rsa-sha256 header.s=korg header.b=D+xwyfRI; arc=none smtp.remote-ip=100.103.45.18 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 D9F55606A322; Fri, 4 Dec 2026 11:33:50 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.a=rsa-sha256 header.s=korg header.b=D+xwyfRI Received: by smtp.kernel.org (Postfix) with ESMTPSA id 05FAE1F000C2; Fri, 4 Dec 2026 11:33:49 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linuxfoundation.org; s=korg; t=1796384030; bh=ezRzZOW8kzN9qYExdyjzpnC9H0OiE2fm7VtWX+DV8Kw=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=D+xwyfRIzx8tn+OmepGmK6QC8MT70gG9wc4yM+VOu9gsJbWaFtePpdalGBYygByAw ZXRXrxM/Oy9SXhNmRvH0zitRUtL2fCfvjz7Ii9Avit6iTQvSgI73cFhTIW4R2fOgP+ evWW5OKzURZSnTvhlm8fkItHsrm8rTlMTfda1VVs= From: Greg Kroah-Hartman To: stable@vger.kernel.org Cc: Greg Kroah-Hartman , patches@lists.linux.dev, Daniel Wade , Xia Yan , Nikolay Aleksandrov , Jakub Kicinski Subject: [PATCH 6.12 467/555] net: bridge: fix skb leak of reinjected link-local frames Date: Fri, 4 Dec 2026 19:08:30 +0900 Message-ID: <20261204100627.109887441@linuxfoundation.org> X-Mailer: git-send-email 2.56.1 In-Reply-To: <20261204100603.988357525@linuxfoundation.org> References: <20261204100603.988357525@linuxfoundation.org> User-Agent: quilt/0.69 X-stable: review X-Patchwork-Hint: ignore X-Mailing-List: patches@lists.linux.dev List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list MIME-Version: 1.0 Content-Transfer-Encoding: 8bit 6.12-stable review patch. If anyone has any objections, please let me know. ------------------ From: Daniel Wade commit 98382d41f92f048cf3cbb7af415f48a722b19ebc upstream. br_handle_frame() passes the link-local frames it neither forwards nor delivers (01:80:c2:00:00:02 to 0d and 0f, unless set in the group forward mask) through NF_HOOK() at NF_BR_LOCAL_IN. Since commit 3b2e2904deb3 ("net: bridge: fix per-port af_packet sockets") the okfn only learns the source and returns 1, which becomes RX_HANDLER_PASS. That commit sent the nf_queue case to RX_HANDLER_CONSUMED, which is right for the synchronous return, but the frame comes back: on reinjection nf_reinject() calls the okfn and ignores its return value, because every other okfn consumes the skb. This one no longer does, so nothing frees the frame. NFQA_CFG_F_FAIL_OPEN leaks it the same way with no verdict at all, when the queue or the listener's socket is full. Each frame leaks an skb, and one sent from a local socket keeps that socket charged, so neither it nor the network namespace holding it is freed. Bridge, rule and queue need only CAP_NET_ADMIN in a netns, so with user namespaces an unprivileged user can exhaust kernel memory. nf_reinject() cannot free the skb on a 1 from the okfn, because other okfns return NET_RX_DROP, which is 1, after freeing it. Call nf_hook() instead of NF_HOOK() and do the learning and the RX_HANDLER_PASS return in br_handle_frame() on 1, as the 0x00 and 0x0e cases already do and as vrf_rcv_nfhook() does. The okfn then runs only for a reinjected frame, which br_handle_frame() has already reported consumed and cannot pass on the port, so it learns from the frame and frees it. These frames were not delivered before this change either. Also set *pskb before the new RX_HANDLER_PASS, as the other such returns do; skb_share_check() may have replaced the skb, and the commit above added that return without the assignment. Discovered by an AI code review agent and reproduced on unmodified mainline under KASAN: an unprivileged user in a new user and network namespace bridged a veth, queued link-local frames to an NFQUEUE listener that accepted every one, and leaked an skb per frame. With this patch the reinjected frames are freed and nothing leaks. Fixes: 3b2e2904deb3 ("net: bridge: fix per-port af_packet sockets") Cc: stable@vger.kernel.org Signed-off-by: Daniel Wade Reviewed-by: Xia Yan Acked-by: Nikolay Aleksandrov Link: https://patch.msgid.link/20261115130211.7724-1-danjwade95@gmail.com Signed-off-by: Jakub Kicinski Signed-off-by: Greg Kroah-Hartman --- net/bridge/br_input.c | 18 +++++++++++++----- 1 file changed, 13 insertions(+), 5 deletions(-) --- a/net/bridge/br_input.c +++ b/net/bridge/br_input.c @@ -241,13 +241,18 @@ static void __br_handle_local_finish(str br_fdb_update(p->br, p, eth_hdr(skb)->h_source, vid, 0); } -/* note: already called with rcu_read_lock */ +/* okfn of the link-local NF_BR_LOCAL_IN hook in br_handle_frame(). It is + * only called when a queued frame is reinjected, after br_handle_frame() + * returned RX_HANDLER_CONSUMED for it, so the frame can no longer be + * passed up on the port and has to be freed here. + * note: already called with rcu_read_lock + */ static int br_handle_local_finish(struct net *net, struct sock *sk, struct sk_buff *skb) { __br_handle_local_finish(skb); + kfree_skb(skb); - /* return 1 to signal the okfn() was called so it's ok to use the skb */ - return 1; + return 0; } static int nf_hook_bridge_pre(struct sk_buff *skb, struct sk_buff **pskb) @@ -404,11 +409,14 @@ static rx_handler_result_t br_handle_fra /* The else clause should be hit when nf_hook(): * - returns < 0 (drop/error) * - returns = 0 (stolen/nf_queue) - * Thus return 1 from the okfn() to signal the skb is ok to pass + * On 1 the frame is passed on here. The okfn() only runs if a + * queued frame is reinjected later, and must consume it then. */ - if (NF_HOOK(NFPROTO_BRIDGE, NF_BR_LOCAL_IN, + if (nf_hook(NFPROTO_BRIDGE, NF_BR_LOCAL_IN, dev_net(skb->dev), NULL, skb, skb->dev, NULL, br_handle_local_finish) == 1) { + *pskb = skb; + __br_handle_local_finish(skb); return RX_HANDLER_PASS; } else { return RX_HANDLER_CONSUMED;