🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: linux.kernel.netdev
Article #20666

[PATCH net 2/3] net/nfc: llcp: take the skb reference before queueing it to the socket

#20666
From: Piyus Kedia
Date: Mon, 23 Nov 2026 02:35
112 lines
14519 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.

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 74bf81700..e988c95cc 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: <20261123023519.3350997-2-piyus@iiitd.ac.in>
Path: mbox-mo1.pugleaf.net!news-lax.pugleaf.net!usenet.blueworldhosting.com!diablo1.usenet.blueworldhosting.com!usenet.network!.POSTED!vger.kernel.org!netdev+bounces-368968-linux-kernel-netdev=dewy.ru
References: <20261123023519.3350997-1-piyus@iiitd.ac.in>

Show Full Headers
Complete Article Headers
Path: mbox-mo1.pugleaf.net!news-lax.pugleaf.net!usenet.blueworldhosting.com!diablo1.usenet.blueworldhosting.com!usenet.network!.POSTED!vger.kernel.org!netdev+bounces-368968-linux-kernel-netdev=dewy.ru
From: piyus@iiitd.ac.in (Piyus Kedia)
Newsgroups: linux.kernel.netdev
Subject: [PATCH net 2/3] net/nfc: llcp: take the skb reference before queueing it to the socket
Date: Mon, 23 Nov 2026 08:05:19 +0530
Organization: Usenet Network
Message-ID: <20261123023519.3350997-2-piyus@iiitd.ac.in>
References: <20261123023519.3350997-1-piyus@iiitd.ac.in>
MIME-Version: 1.0
Content-Transfer-Encoding: 8bit
Injection-Info: usenet.network;
	logging-data="3773102"; mail-complaints-to="abuse@usenet.network"
Cancel-Lock: sha1:YT7ZiE62AXhgAblRFIpr9JPZuiE= sha256:3w42zm8meDZyWwo2qLRXm3gr6472Eqrn9axXpQWhpCc=
	sha1:gwv+Ctwq84FEDDtbpm7uz5ojX8A= sha256:ztwxTRvV7EgZ0J9dSK+MFlmgwPa79cajdGjirZxXQKE=
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 7F7BE125D89; Mon, 23 Nov 2026 05:36:39 +0300 (MSK)
X-Virus-Scanned: Debian amavisd-new at usenet.network
X-Spam-Flag: NO
X-Spam-Score: -3.05
X-Spam-Status: No, score=-3.05 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, URIBL_BLOCKED=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 z75EoVA6dcmf;
	Mon, 23 Nov 2026 05:36:33 +0300 (MSK)
X-Received-SPF: Pass (mailfrom) identity=mailfrom; client-ip=172.234.253.10; helo=sea.lore.kernel.org; envelope-from=netdev+bounces-368968-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 B4761125D87; Mon, 23 Nov 2026 05:36:23 +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 C0A2B2DB27; Mon, 23 Nov 2026 02:35:31 +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=1795401330;
	b=RPeuo9lVIwvYWPzy/NEc3tY8pzDtpHO1yABwV1U1X/xl7WZCu4pCG8xCpx/VOtsooQP4
	 l2w1nLyyz9ok78CKp7GelT3eMRHx0MF+nWtSjuiflwq6eF2BuAS+7V3uBimonnq+IEOqr
	 xQ0ydNZImIT4yytJkOWsU+Fn6JVHWosH8PnxQMVd8uGYWH/Ysj1wbCpUw6Wc86peHes4t
	 5T8mIp9UeKistH2A91XqzMmAa1W1n+2jHwWBaqkL1cWpt+D37SZsbjXpMjHyz2vtvJiiU
	 /fWK+Wj9WMv08mqiAtNLGGhzGhTzWtjgDUuhloXCLCFx/pbaBD2kbZBwmProM8IwphQ==
X-ARC-Message-Signature: i=2; d=subspace.kernel.org; s=arc20261015;
	a=rsa-sha256; c=relaxed/relaxed; t=1795401330;
	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=V9tZJEHgi9zuzkPjoAHZgtifbl5VP5I7TzEdZTDXpvA=;
	b=lO/66MC60Ok1IRmyB8HviwzKpPrzeefjXFC1qN0AEXDWDeoXYduYqlls7xPQYqRhsqo8
	 IeWHMoMtKC77a928fzMm/dKKeW/RA8nTfl6ZzAP19yzTQTL7sBAu5lg0fR+bTVXzYYv3y
	 TAilxYnEA/zG1EGC7butYcdguIvWUTnoleuYXVFFCLHcNCmdyThASAG3mEHenlLFIQxY0
	 LGZnyZ/h9EOFegLHNgFnQ+kw3Q9wGzJp3r1aYlEKXciBiWu37BBUNOi8aHILXORgU10ce
	 b0WHyr3fRL8d403h8Uj0Dp/D1C5mcPVaRDglV2OnmPMIIdLg02JMCyZSTYpCX+d+vMw==
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="VvB/gHVf";
	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 654A6606A687;
	Mon, 23 Nov 2026 02:35:30 +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=VvB/gHVf
X-Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=209.85.214.172
X-ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none;
	t=1795401329;
	b=hwWqd2EQww88Nyr/axfe/RjGHOXIhbZGSiyXDA4c59bk2ryVf/2AJrNpawozx8UTyvj9
	 L7RxV8Z/ifkMEJNc1Y8QK/CRpWGLPnCVijv258g+5OR5tGIwZjA2NAaasJvj4IQrAnp8T
	 a9yT1LpOqGKbwtKHhFHqypIkGVSJ2wGw15O2mGDQP2FiMp1btT8e4gElCc4Xv52lLFNig
	 /h8bfQwfsDGNud2YJUkJnv3dfPd1ZqAlpDJnZPvMt1/B7NhW/dmFlfzp9D8ZiahzWFkSk
	 g/UqSB9ay0nEY6R81dD/cW3XCYubRF1pEGr1D+Ogx37YFlTpngScpiqKwmSxCxMGTNQ==
X-ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015;
	a=rsa-sha256; c=relaxed/relaxed; t=1795401329;
	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=V9tZJEHgi9zuzkPjoAHZgtifbl5VP5I7TzEdZTDXpvA=;
	b=YiHJkG9JmQj6iHxx9+543LmX0bJyupS9MjASYIjFGxrrmwY5nqDG1phxMdKDZS1mTFuq
	 pSgrBQBoetoE2NkUIfHSYmS1ScUW7Xyfs9kTyNNVsXxtGbTX8cCweag/exSSTWuKKZBq9
	 ZxnTl0Zps/tIW5BS/Rmc/90iYsvAn0OWV1CHia+5dBFQXryaAo8Ov12xIgBkgXhHLBG3q
	 x0VVRf+YOwdx0VaFB9Puvv9V+H4t+HlvLhmPeGSmVTPTwNVV4lROI5Ate/SsTu5lVqGQt
	 bNEyUIANxMidY0MmNCGMnVBpMdL5x2uXYdJIO5on8LQ7EcxNN347BKoUtVs6UHrjYNg==
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="VvB/gHVf";
	arc=none smtp.remote-ip=209.85.214.172
X-Received: from mail-pl1-f172.google.com (mail-pl1-f172.google.com [209.85.214.172])
	(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 E5C15606A331
	for <netdev@vger.kernel.org>; Mon, 23 Nov 2026 02:35:28 +0000 (UTC)
X-DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org E5C15606A331
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-f172.google.com with SMTP id d9443c01a7336-2f0464dd6b6so14777555ad.1
        for <netdev@vger.kernel.org>; Sun, 22 Nov 2026 18:35:28 -0800 (PST)
X-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
        d=iiitd.ac.in; s=google; t=1795401328; x=1796006128; 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=V9tZJEHgi9zuzkPjoAHZgtifbl5VP5I7TzEdZTDXpvA=;
        b=VvB/gHVfJLWn6n5wEIFsFijRGKd7mKTFlb2ToYtj8fFMD51k7tp2A48f3VANoQ07mZ
         qkdVQuiIdId4E/jI9cpMSUeTbqqsxUpcRscDfxi1b8GbGBsheFytaVRYCqPNTCzAUSiH
         PzLCLsWBU7/Um0FX04qV7WyQl/abRPSo3MzGI=
X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
        d=1e100.net; s=20260707; t=1795401328; x=1796006128;
        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=V9tZJEHgi9zuzkPjoAHZgtifbl5VP5I7TzEdZTDXpvA=;
        b=Fy/hSmuBbGQcfiaTCIxmW90ryM2LBDVNN1IiY00ZpWUxKlYL1Is3T26j5/WLtlxldi
         wShGbDae8YbOhlyRT/BmjCBykcfWRcol4QhUWRU3pEOuGZHXB7AnUfjcfbx1WmTHi/Fm
         wicKZK09Fde2yOcMrjygwhduPp7jESIwK4QGQ1oQJKlIUgvVjJVegdV/fJlMw8/92D7/
         ezVp/tfp5MMJXKyYmnEcabp0+IvgOmPOjFqsFyrjHz6CtYk/pjAh8vf1UBLq3x3mvy1I
         3602bCdNdA9muLGTBjtlZHHOsiG6Rr7QwNjjOwpA0kspkfFdaK3Q3IkF6Wc6K+F5ysxP
         dKNA==
X-Forwarded-Encrypted: i=1; AL+hErE8Z+spI/cPp6YUrW3H+rrF6ujbodyAom6IN+QfFCRTNP5S+oCGe4Nm/ijoyrARrh9uDlzbf00=@vger.kernel.org
X-Gm-Message-State: APuU4Z+Z2lRyxYJM66fSkCv8pHRiWjecaoF4iZgzkgWywtkMLoPGrhSN
	b3kWJMNiWk+hzNY9wYeLLKuswcDFg4IlxgfB7zEG5Vqu5hnv9ld4X944gOGxnlfZy6I=
X-Gm-Gg: AZFdTZdXRSaTQhmO2xu74FAJvYVgT+GQqpJ+plDckRUeOVxg3QJ/KvmmzVZSPxo/JYR
	Vc2819wONc5NEYxo5QWDdVQPbVoPkgXSD6/PjeSckGJjfsOnmduiqSG3GPKqc74na3k61aVheOh
	3AcO1A2zAfnFmNu/EyUkmZWCBZdS4Jmd8+N/TL1ZBwA1dFrXoQbtUAAyXpHiaQaQzbUvw8+jdlU
	QQTFcw9qhdPJE5WmtYv3N+N/JpPmJ71vL6IU/YHoxoBXqcW9BGNVcSEHsoopfAGLIJ6PZP0D2V1
	DLFSxFi+pDTIiUJcxlx3J3g5bfMcv7PjpZVRGXIiPN8n8SNSfjHetualg0X6/dDmX5RGibkmF5b
	cv57Dob0334j+BoxaVHwCmUIoYZowJpK8A72iowJ/TNU2y/9jSyBjetmGKaU0C59cNqosmwubB3
	eybad6IXDe5KBS/rrUlVgRgtfRx07Ptexv4HAulVtNt54roT0hzbbcwq6C5O8ODobnJJnkd88KS
	GqmINe21f4wu1ZWDFPFoHrsXe2iJLCV3THCGhz3Zoh9LdQ+Byp/7Jq/tAik5ArRmzibOArfS/m6
	rDKYYlnhk0p9grrzQZ4IlpYB32M8EKLi0tWT2SJcQXYrPlao7t8xs8ZcqeDRXDsL+Xc1OItfbTF
	e9oINMY4zd/6cgb7pPrtJ5Kmv21FIZSbz4rzv4BAKn+kK7cjDqTOrZL1XeQY+A5xhUkmhMdxH7W
	xLILwLdFH/iQ==
X-Received: by 2002:a17:902:d2c6:b0:2ef:f312:b842 with SMTP id d9443c01a7336-2f03f1b426emr100861095ad.46.1795401328203;
        Sun, 22 Nov 2026 18:35:28 -0800 (PST)
X-Received: from iiitd-S2600STB.iiitd.edu.in ([103.25.231.160])
        by smtp.gmail.com with ESMTPSA id d9443c01a7336-2f03f1215e2sm44320685ad.63.2026.11.22.18.35.25
        (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256);
        Sun, 22 Nov 2026 18:35:27 -0800 (PST)
X-Cc: oe-linux-nfc@lists.linux.dev,
	linux-kernel@vger.kernel.org,
	Kapil Vaswani <kapil@presceralabs.ai>,
	Piyus Kedia <piyus@iiitd.ac.in>
X-Mailer: git-send-email 2.34.1
X-In-Reply-To: <20261123023519.3350997-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