Article View: linux.kernel.netdev
Article #24308[PATCH net v2 2/3] net/nfc: llcp: take the skb reference before queueing it to the socket
From: Piyus Kedia
Date: Mon, 30 Nov 2026 01:22
Date: Mon, 30 Nov 2026 01:22
112 lines
14310 bytes
14310 bytes
nfc_llcp_recv_ui() and nfc_llcp_recv_hdlc() queue a received frame to an
LLCP socket and only then take the reference meant to keep it alive:
if (!sock_queue_rcv_skb(&llcp_sock->sk, skb)) {
/*
* UI frames will be freed from the socket layer, so we
* need to keep them alive until someone receives them.
*/
skb_get(skb);
} else {
pr_err("Receive queue is full\n");
}
sock_queue_rcv_skb() takes over the caller's reference and publishes the
skb on sk_receive_queue at refcount one, so a concurrent recvmsg() - or
the socket's own teardown - can dequeue and free it before the skb_get()
runs. The increment then lands in freed memory:
refcount_t: addition on 0; use-after-free.
__refcount_add
skb_get
nfc_llcp_recv_hdlc
nfc_llcp_rx_skb
nfc_llcp_recv_agf
nfc_llcp_rx_skb
nfc_llcp_rx_work
BUG: KASAN: slab-use-after-free in nfc_llcp_rx_skb
Write of size 4 at addr ffff888055abe5e4 by task kworker/1:2/56
Both handlers are reached from nfc_llcp_rx_skb(), and the aggregated-frame
path widens the window by dispatching sub-frames through it in a loop.
Take the reference before queueing and release it again when the queueing
fails. That is the ownership rule the rest of the tree follows, including
the raw-socket copy in this same file:
if (sock_queue_rcv_skb(sk, nskb))
kfree_skb(nskb);
sock_queue_rcv_skb() does not free the skb on any of its failure paths, so
the explicit kfree_skb() balances only the reference taken here.
How this was found: by AI-driven fuzzing built on top of syzkaller. Its
analysis was then checked by hand against the code, the fault was
reproduced on net.git main under KASAN, and the patched kernel is clean on
the same reproducer with ordinary NFC LLCP traffic unaffected.
Fixes: 1727cf937401 ("NFC: llcp: Fix Rx memory leak")
Link: https://lore.kernel.org/netdev/20261123023519.3350997-1-piyus@iiitd.ac.in/
Signed-off-by: Kapil Vaswani <kapil@presceralabs.ai>
Signed-off-by: Piyus Kedia <piyus@iiitd.ac.in>
---
net/nfc/llcp_core.c | 33 +++++++++++++++++++--------------
1 file changed, 19 insertions(+), 14 deletions(-)
diff --git a/net/nfc/llcp_core.c b/net/nfc/llcp_core.c
index 74bf817007cf..e988c95cc172 100644
--- a/net/nfc/llcp_core.c
+++ b/net/nfc/llcp_core.c
@@ -922,14 +922,16 @@ static void nfc_llcp_recv_ui(struct nfc_llcp_local *local,
/* There is no sequence with UI frames */
skb_pull(skb, LLCP_HEADER_SIZE);
- if (!sock_queue_rcv_skb(&llcp_sock->sk, skb)) {
- /*
- * UI frames will be freed from the socket layer, so we
- * need to keep them alive until someone receives them.
- */
- skb_get(skb);
- } else {
+ /*
+ * UI frames will be freed from the socket layer, so we need to keep
+ * them alive until someone receives them. Take the reference before
+ * the skb is queued: once it is on the receive queue a concurrent
+ * recvmsg() may already have freed it.
+ */
+ skb_get(skb);
+ if (sock_queue_rcv_skb(&llcp_sock->sk, skb)) {
pr_err("Receive queue is full\n");
+ kfree_skb(skb);
}
nfc_llcp_sock_put(llcp_sock);
@@ -1136,14 +1138,17 @@ static void nfc_llcp_recv_hdlc(struct nfc_llcp_local *local,
pr_err("Received out of sequence I PDU\n");
skb_pull(skb, LLCP_HEADER_SIZE + LLCP_SEQUENCE_SIZE);
- if (!sock_queue_rcv_skb(&llcp_sock->sk, skb)) {
- /*
- * I frames will be freed from the socket layer, so we
- * need to keep them alive until someone receives them.
- */
- skb_get(skb);
- } else {
+ /*
+ * I frames will be freed from the socket layer, so we need to
+ * keep them alive until someone receives them. Take the
+ * reference before the skb is queued: once it is on the
+ * receive queue a concurrent recvmsg() may already have freed
+ * it.
+ */
+ skb_get(skb);
+ if (sock_queue_rcv_skb(&llcp_sock->sk, skb)) {
pr_err("Receive queue is full\n");
+ kfree_skb(skb);
}
}
--
2.34.1
Technical Details
Message-ID:
<20261130012208.1962491-3-piyus@iiitd.ac.in>Path:
mbox-mo1.pugleaf.net!srv.newsdeef.eu!news.mb-net.net!open-news-network.org!2.eu.feeder.erje.net!feeder.erje.net!feeder1.feed.ams11.usenet.farm!feed.usenet.farm!feeder.usenetexpress.com!tr3.eu1.usenetexpress.com!news.neodome.net!usenet.network!.POSTED!vger.kernel.org!netdev+bounces-373756-linux-kernel-netdev=dewy.ruReferences:
<20261130012208.1962491-1-piyus@iiitd.ac.in>Show Full Headers
Complete Article Headers
Path: mbox-mo1.pugleaf.net!srv.newsdeef.eu!news.mb-net.net!open-news-network.org!2.eu.feeder.erje.net!feeder.erje.net!feeder1.feed.ams11.usenet.farm!feed.usenet.farm!feeder.usenetexpress.com!tr3.eu1.usenetexpress.com!news.neodome.net!usenet.network!.POSTED!vger.kernel.org!netdev+bounces-373756-linux-kernel-netdev=dewy.ru From: piyus@iiitd.ac.in (Piyus Kedia) Newsgroups: linux.kernel.netdev Subject: [PATCH net v2 2/3] net/nfc: llcp: take the skb reference before queueing it to the socket Date: Mon, 30 Nov 2026 06:52:07 +0530 Organization: Usenet Network Message-ID: <20261130012208.1962491-3-piyus@iiitd.ac.in> References: <20261130012208.1962491-1-piyus@iiitd.ac.in> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Injection-Info: usenet.network; logging-data="1301964"; mail-complaints-to="abuse@usenet.network" Cancel-Lock: sha1:ag/V1/uq536EeraCrne1NfxNDVs= sha256:w5K9SmT6v0qRlk0bctH/jG7KHuJFEx3f38TtsVqrWkU= sha1:mYqt+yKkZhOG4/YdHa+SKaO6gOw= sha256:Qos+n+c/7CFT7fJ1J8H9+JZmVzENZJEpxJo39hmwfus= 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 20C8F125FB9; Mon, 30 Nov 2026 04:22:51 +0300 (MSK) X-Virus-Scanned: Debian amavisd-new at usenet.network X-Spam-Flag: NO X-Spam-Score: -3.051 X-Spam-Status: No, score=-3.051 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, HEADER_FROM_DIFFERENT_DOMAINS=0.249, 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 (1024-bit key) header.d=iiitd.ac.in 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 yix_md9qFzMK; Mon, 30 Nov 2026 04:22:48 +0300 (MSK) X-Received-SPF: Pass (mailfrom) identity=mailfrom; client-ip=172.234.253.10; helo=sea.lore.kernel.org; envelope-from=netdev+bounces-373756-linux-kernel-netdev=dewy.ru@vger.kernel.org; receiver=<UNKNOWN> X-Authentication-Results: OpenDMARC; dmarc=none (p=none dis=none) header.from=iiitd.ac.in X-Received: from sea.lore.kernel.org (sea.lore.kernel.org [172.234.253.10]) by mail.dewy.ru (Postfix) with ESMTPS id 9DA36125FB8; Mon, 30 Nov 2026 04:22:39 +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 7FDB025272; Mon, 30 Nov 2026 01:22:25 +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=1796001745; b=mgv8Vp/V08WAHGuc1Jijs43YsPxtUQZoXLqVKJtnnynN6u/w/BvPZTDCx5EfCwuxx8By q7y+Piz9yA6oSToxejCfOCj6cg0Zv7I6mfRGiDabLB7lzjlz99J42HvLOdNyK3JVcW4i5 wt1V5oee1SGs7ZDawCNXUQamB9tBE40CFLu94LNZArooOwfM7BObwF3KU/ELb/R1vtrUo 9IyHX80WyVWGv2OnBDKkFb87dlsXG70A+ySW4Fr8N2rda/LnflYkxJcaWnIYEJ+rNBg6d z0Th53sYeo568SeGyaxeVsrJkZBj7BsibYeNiIjdgpfmxUH6afi/IhHBZWQVt4SizvA== X-ARC-Message-Signature: i=2; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796001745; 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:In-Reply-To:References:X-Mailing-List:List-Id:List-Post: List-Help:List-Subscribe:List-Unsubscribe:List-Owner:Precedence: MIME-Version:Content-Transfer-Encoding; bh=OVCU+LtMN8HyJkx7e358b+NpJ8xF16MuyquKPR2rXzc=; b=bzuDy179tlnoSaQhBFudBvUjVCXFszPGycF5lSkvL5cXuKo4bGLh0uIIaA2vbRvDxI+m 4wifp70encVygOuVZMhjSOO2OlwQcce8fFiK1GO9Nw6nbFCg8A1RaWSgcok2Wla2JWrqi xjIllAf6Kvd551hbKe7mT3lHi9Jpj4Z4vFirZBYIrKjJdXve40alkMnvaIodOgrrMUQj3 d3YuLHRfUfzXeQBkdS0+ByTrMy7jvyvSS0vGDWQ6Mtl7Qc6rkWKJ9X+bpc+cAskUXjCNc lAy4ruWhJVbTGCsv1pseHlbOj1X1+X7cpgg/Mu76P9ior+OVHmW2V/A4gWQsNi8x0/g== X-ARC-Authentication-Results: i=2; smtp.subspace.kernel.org; dkim=pass header.d=iiitd.ac.in header.i=@iiitd.ac.in header.a=rsa-sha256 header.s=google header.b=cP890vNa; dmarc=none header.from=iiitd.ac.in; spf=pass smtp.mailfrom=iiitd.ac.in; 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 3B221606A31C; Mon, 30 Nov 2026 01:22:25 +0000 (UTC) X-Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=iiitd.ac.in header.i=@iiitd.ac.in header.a=rsa-sha256 header.s=google header.b=cP890vNa X-Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=209.85.214.175 X-ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796001744; b=REfOD+SD5fZD8bEZMvSV49bOiJOpQBtltVffqea8McziFnJDIQ4PSRvXt0YkzD6f+soY 36C6Q5/06P/nx7u4SZ9p8BKEG1LKk/z8qd2OefRzGikPoLEYVhk1CszOgv91JZR85tqaG Og1niArze6XkvabquKfU/XPCN0JDZflWfWL2IF612PZ8BP3p8lMeWBOSw3Qgytg92cPSA 4NPpwnBaKf2Tb1iqne6UobCSIpSUWdfwiJi60vRwPgcP/ylxzxLlBlkbcKg3sVWF2cPwG 7fTWji7YqroBZ6UneLucYnXj3grZeGchjl0hGmVRA8RUvGFfFAL68jTEWmAiRuMuYbA== X-ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796001744; 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:In-Reply-To:References: MIME-Version:Content-Transfer-Encoding; bh=OVCU+LtMN8HyJkx7e358b+NpJ8xF16MuyquKPR2rXzc=; b=nHoUtWY7pn2aL7s5OsD3J7MadR1DzQ8/9A7+hlsYGZ2A7DcJPwKkMKrcrd0GGVDciuXv NLZ9mxqXti5cdA8emhtoBRJ4m9Y3tKxxRNKH2ju0n84+UR+SITSgfHJG4RdCPDEvmjzhl WD2+wn0uyybJ/ottDW8EXCXc0aEurvL5Q7b+W8O4QhQmWrUKDN67Naop5Ve0ObwaO2Yp+ F04ja7bHSvAlWGVN4npVQz/kHusXbpk1FqvucLoZRHMnEZLyElmj7cDcGfRAe+C4dN+dJ J/fGH/nnd1mrDtx94ZCv3TEQpDSV3QxqCc+nbOELPPjN3ER9UVWm+4BqeuHTuimjZOw== X-ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=none header.from=iiitd.ac.in; spf=pass smtp.mailfrom=iiitd.ac.in; dkim=pass header.d=iiitd.ac.in header.i=@iiitd.ac.in header.a=rsa-sha256 header.s=google header.b=cP890vNa; arc=none smtp.remote-ip=209.85.214.175 X-Received: from mail-pl1-f175.google.com (mail-pl1-f175.google.com [209.85.214.175]) (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 81F57606A32C for <netdev@vger.kernel.org>; Mon, 30 Nov 2026 01:22:23 +0000 (UTC) X-DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org 81F57606A32C X-Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=iiitd.ac.in X-Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=iiitd.ac.in X-Received: by mail-pl1-f175.google.com with SMTP id d9443c01a7336-2f048476ab9so68366265ad.0 for <netdev@vger.kernel.org>; Sun, 29 Nov 2026 17:22:23 -0800 (PST) X-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=iiitd.ac.in; s=google; t=1796001743; x=1796606543; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to:content-type; bh=OVCU+LtMN8HyJkx7e358b+NpJ8xF16MuyquKPR2rXzc=; b=cP890vNaiac69cu1PRKDkGkotglgY+yqJwC7AdNtjtGa3JfPzP9Je6ycysUWFKRGzg xxLHV7GnWsc3+hQ2sE3jp8tOTCUyGz9M7V4e+w+yzF6OlJSWP/wn6bQMpuOaE3h9KHkP 1ocVxmXhJJhAleMjOXp9OAHFYXYOIu8Prrr/8= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20260707; t=1796001743; x=1796606543; h=content-transfer-encoding:mime-version:references:in-reply-to :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=OVCU+LtMN8HyJkx7e358b+NpJ8xF16MuyquKPR2rXzc=; b=gVGZMiiQepja3g4fLOokIp6ToZ1X7AXwfVU+X8/ecoU/eB/07Llr0Yb7yWpxj0/ujn QimgbZHLVRFUzeNFMvokOZws2FLdVMMXvvQLlfj0jLJIDs5HozG/zs0nbzhza+Ka0lRz 3AC4qnpmQpc7/eC+nO1PTVKUsyQac7DcCZrkb6tUf/tuaT6AMvd5e+M1wiZHE/prknMo 3nxxUsI/etgt7/3yEcOtZIYHHK9P+m3wKwzOsOm/4d7cZZtO9KZuX8BgRILV8VT+2Kg6 6i9f9ic0SBYD8neYXGmAAii52NHU1WADgYo7TBeyXgJfnWf92aiowah2GZlVw0ai6EkC TZ/Q== X-Forwarded-Encrypted: i=1; AL+hErGPOhGnzThOa7EGHT6qeuEt51v3Ly1Fq7eVD3x2US0wWk3bGFplsGN9EsQz1P/5yhfxfG4iIjk=@vger.kernel.org X-Gm-Message-State: APuU4Z9VDrafkx/HVBHC66Z6YaFVEldwv7EDHSpVxw9zHvqtX6SOBxYn p6szzEqkWtwzOFFtCXaAEEi/H61vD6fOQfkKHiPmabQRkfHGSbFE3lDlIpsIq6IAFw4= X-Gm-Gg: AZFdTZcC6umca9rzdbTvICziwzRrqjFCttv8C2K9IeHa1AVf8VwLvQUhbNYl2zCiC17 n0ejP/IaE8f1l0JFoalplpw+cQEUut+1qMKVxi8NF6ZuQSYRUvh8l2FGwsjt0UMNtFPqyfWEUdi cB0IrtlTdBmXYq5iRu+y7R0lSMtDMY9dlPwwinolMiPpWXJEctGq1PXRDnwh6DOdQUZE/kQaez5 Y4VQs2q6nefCQr8JsPY/3T+8UgD5twwkkBgnd6V5cJlJCacqJAgK57t45U/1dCFUQ22bSQBYHGw FoGExJm8CH+pG/ujd0gIMlxJXCnX1GdaR0ZY9TzWxcgvTiGKFMezzky4TZl/FC2nSP9EUfU9DNs C5hAK/OC6l7kBByfkVrQIcU2o0SvTmxfPb1Kt1cgY/DMDl1mHOk8xNNI+06/a/l3pLOu7VLiIFw 4+8UCB48jew0ZXZC2Y3ukxP7I5kjSllLoD5vSH5UgCIhEUND6mCtQizOubb93FUglX7hF5N5Ha+ HHI1d8v6Y3uf1WQgu8iHTyj6EcMuYEVKpnLa4EtCATjRsN/5y2YLpC9g5G5qGIc3s0lbSov+cvX R5Hz1CkYL4rKaPsE5IC0OESJLiRjPBgRjDOSdll/Vxt96ZfM7dwz4hDfgv54jIPpPpknMqOgXiR 7ahfBactLdE8N6PDNlJvh5YIclc9XGtOX4EhWGrfR+2ZB2AVWxAb5soH5Bka7+5kf X-Received: by 2002:a17:902:e802:b0:2ef:f280:40ae with SMTP id d9443c01a7336-2f03f0fcd9bmr370255495ad.12.1796001742926; Sun, 29 Nov 2026 17:22:22 -0800 (PST) X-Received: from iiitd-S2600STB.iiitd.edu.in ([103.25.231.160]) by smtp.gmail.com with ESMTPSA id d9443c01a7336-2f0bc695f31sm98858205ad.49.2026.11.29.17.22.19 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 29 Nov 2026 17:22:22 -0800 (PST) X-Cc: oe-linux-nfc@lists.linux.dev, netdev@vger.kernel.org, linux-kernel@vger.kernel.org, Kapil Vaswani <kapil@presceralabs.ai> X-Mailer: git-send-email 2.34.1 X-In-Reply-To: <20261130012208.1962491-1-piyus@iiitd.ac.in> 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