🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: linux.kernel.netdev
Article #8721

[PATCH net 3/5] nfc: nci: consume the loopback response exactly once

#8721
From: Joas Antonio dos Santos
Date: Thu, 29 Oct 2026 23:17
68 lines
13583 bytes
nci_nfcc_loopback_cb() stores the received data packet in
conn_info->rx_skb and completes the request, and nci_nfcc_loopback()
returns conn_info->rx_skb to the caller, which frees it.  The pointer
is never cleared.

Any NCI response with a zero status also completes the request, as
nci_req_complete() only checks NCI_REQ_PEND.  If the NFCC sends one
instead of the data packet, nci_nfcc_loopback() returns the skb of the
previous loopback, which was already freed, or NULL.  st_nci_loopback()
then copies skb->data into its vendor command reply and frees the skb
again.

With an emulated NFCC on virtual_ncidev answering the second loopback
with an unsolicited CORE_SET_CONFIG_RSP, nci_nfcc_loopback() returns 0
and the skb of the first loopback, and KASAN reports a
slab-use-after-free as soon as the caller reads it.

Detach the skb from conn_info when consuming it, free it when the
caller does not want it, and return -EPROTO when the request was
completed without a data packet.

Fixes: 1c53855f6be2 ("nfc: nci: Add nci_nfcc_loopback to the nci core")
Cc: stable@vger.kernel.org
Signed-off-by: Joas Antonio dos Santos <joasantonio108@gmail.com>
Assisted-by: Yaga Agent HackerSec Claude:claude-opus-5-5
---
 net/nfc/nci/core.c | 18 +++++++++++++++---
 1 file changed, 15 insertions(+), 3 deletions(-)

diff --git a/net/nfc/nci/core.c b/net/nfc/nci/core.c
index 73e3a9647..8e2a755ce 100644
--- a/net/nfc/nci/core.c
+++ b/net/nfc/nci/core.c
@@ -428,7 +428,7 @@ int nci_nfcc_loopback(struct nci_dev *ndev, const void *data, size_t data_len,
 	int r;
 	struct nci_loopback_data loopback_data;
 	struct nci_conn_info *conn_info;
-	struct sk_buff *skb;
+	struct sk_buff *skb, *rx_skb;
 	int conn_id = nci_get_conn_info_by_dest_type_params(ndev,
 					NCI_DESTINATION_NFCC_LOOPBACK, NULL);
 
@@ -464,8 +464,20 @@ int nci_nfcc_loopback(struct nci_dev *ndev, const void *data, size_t data_len,
 	ndev->cur_conn_id = conn_id;
 	r = nci_request(ndev, nci_send_data_req, &loopback_data,
 			msecs_to_jiffies(NCI_DATA_TIMEOUT));
-	if (r == NCI_STATUS_OK && resp)
-		*resp = conn_info->rx_skb;
+	if (r == NCI_STATUS_OK) {
+		/* Consume the stored data packet exactly once, see
+		 * nci_nfcc_loopback_cb().
+		 */
+		rx_skb = conn_info->rx_skb;
+		conn_info->rx_skb = NULL;
+		if (!rx_skb)
+			return -EPROTO;
+
+		if (resp)
+			*resp = rx_skb;
+		else
+			kfree_skb(rx_skb);
+	}
 
 	return r;
 }
-- 
2.43.0
Technical Details
Message-ID: <179331585573.30322.5511229003943288914@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-353511-linux-kernel-netdev=dewy.ru
References: <179331585573.30322.4049957541187612575@gmail.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-353511-linux-kernel-netdev=dewy.ru
From: joasantonio108@gmail.com (Joas Antonio dos Santos)
Newsgroups: linux.kernel.netdev
Subject: [PATCH net 3/5] nfc: nci: consume the loopback response exactly once
Date: Thu, 29 Oct 2026 20:17:35 -0300
Organization: Usenet Network
Message-ID: <179331585573.30322.5511229003943288914@gmail.com>
References: <179331585573.30322.4049957541187612575@gmail.com>
MIME-Version: 1.0
Content-Type: text/plain; charset="utf-8"
Content-Transfer-Encoding: 8bit
Injection-Info: usenet.network;
	logging-data="2120010"; mail-complaints-to="abuse@usenet.network"
Cancel-Lock: sha1:BIPCYS2V4zV1leuI2u18Yi3Uwxk= sha256:TViJCsF2SnLE8oMlrUtZ3WD1L7EjTrvMvvD1CFqCO4Q=
	sha1:0gi479L/haxkCD/Myg5ZYmac97c= sha256:IvbZR1cOW0AnlqG6r3MvUXa+rrLYS1L3rtDoPoiwdkA=
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 B21BD125C7C; Fri, 30 Oct 2026 02:20:10 +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 uU5ZfW__E3vZ;
	Fri, 30 Oct 2026 02:20:08 +0300 (MSK)
X-Received-SPF: Pass (mailfrom) identity=mailfrom; client-ip=172.234.253.10; helo=sea.lore.kernel.org; envelope-from=netdev+bounces-353511-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 2F170125C6E; Fri, 30 Oct 2026 02:20:00 +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 2DDA92A633; Thu, 29 Oct 2026 23:18:10 +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=1793315890;
	b=jF4H2KcRerSLWyHnMFCBr1t7BgY/QF2xZwQRcaCvt73aHi30AbggD4bzSUQ+cwkezqoQ
	 zcifQdBkXjOUv2AzzYKf3x5K9/kmfis9L8se/DxOWTLw/ggQOAXKQLz1FSa+6eWYVWU7p
	 d84/dqjg39sMAJOfXQLw21vgIKgwM3W8DU+EtJZ2R3kjKMLrEJTGPrQ3XGQEOckWdsR3o
	 Ui2cZm1BFgd9ewgmWOK8fh4sjDVZeiJZrNUhb5sbcOfm8BQiSCdgVHl1AfHZezmeJ3f4j
	 T7PHb4GVTkP+qGdAQPyPq39rv1iYvazDRKy5kwlSZQnFS25rjmXwN5k0KaCKhcHKlUA==
X-ARC-Message-Signature: i=2; d=subspace.kernel.org; s=arc20261015;
	a=rsa-sha256; c=relaxed/relaxed; t=1793315890;
	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:
	 In-Reply-To:References:Content-Type:Content-Transfer-Encoding:
	 X-Mailing-List:List-Id:List-Post:List-Help:List-Subscribe:
	 List-Unsubscribe:List-Owner:Precedence:MIME-Version;
	bh=Xpiy1fahTzksVX2ucGYHJCrX4DFe6BxdxTQ9XfdjhmY=;
	b=bnnJc96BxVv2MhXVPXZz5Pon+7QIcT7TTYB13xg44fZa6NT2wUdtcpOTsjPhjQHSLBjQ
	 BXGSmNRtSvr/Xyl5C85qQ4n71R0n3Aub4RFAdjOuFldszDWVyNeA7NKKXRjkWgc8uDp/q
	 giAYu/vSWmPMXnFI2ZF8g1Tox6/1V11aexOPbMphbFrMWiMLQAd2HfH0xFUFv2lfDJh73
	 cn2+GR2tgMA0RjDgVTjlQP290BwPjVES2p4NSdXJVeqaY/jkavoWhm0Y/KTFANrw//qFF
	 hPyoQyX2k3UZAtPKdjGzfW+LLBRJTcxjdclojpdbdkKkhZ8fQI3smvSvUoC7NAARPng==
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=g6YoL8+b;
	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 051B2606A321;
	Thu, 29 Oct 2026 23:18:10 +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=g6YoL8+b
X-Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=209.85.222.44
X-ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none;
	t=1793315889;
	b=0nQGquqYAsPrz+akc1nRHcHFs6ntdEQ9FAjM+TNIKYrufBVWOcs/UmAumaIcaIr2e62h
	 babssx6E85Uj6qkwje38xgXlYx+Dllp7x970bA0WwQRbe9ibbFOf8xmTYhd1NC+CdKgmc
	 cNf6fJa1pfsGulKdMGcFmbd76fhAagy9ffpTDLUapfmiZH29b802/zM4bWrWN6L8BJmHp
	 rhblTSJFMA/WC6EZ7eEdl8w9kAsZ1r5E3zyyIW3XnEvf30r6KNO4pRJPzuMFcFDRGGprD
	 W/e3NwzvwnfVn12DsSp5DwheBncjS4lymsLxj762txPgey85zcfHWfTTCh2ZvloWFGA==
X-ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015;
	a=rsa-sha256; c=relaxed/relaxed; t=1793315889;
	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:In-Reply-To:References:
	 Content-Type:Content-Transfer-Encoding:MIME-Version;
	bh=Xpiy1fahTzksVX2ucGYHJCrX4DFe6BxdxTQ9XfdjhmY=;
	b=183oWtibAOkpGwmcxyaSpGvsPoijysPgE05SOIfeph2DRchhngHbIGV7O2IyOZ7zEZwB
	 AzARdoRqVsQfWwonADI4csHy36XM81q0gO7ZsN14FV8xgoqEDWk+IfBSrKdsagRWSWfXo
	 n2WDKCjHxNL81Gyo2aar0py7DfdVosD3tmdRaMKExOxdxeQEyw6LHNnDP5+wi+X4St3hM
	 R4S9JUPY6OufRnc2EDzhIqFhVbDzC8zvcpAI0BbQEI7dGOKz8TBfJIU/SbszIqQ1KWev5
	 m4mVedE4X2Tq5Hwb3zUnB2moVmoGbwePYMzpT7KEkMLidZVbxLtorKSE+1zMs/zsUFg==
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=g6YoL8+b;
	arc=none smtp.remote-ip=209.85.222.44
X-Received: from mail-ua1-f44.google.com (mail-ua1-f44.google.com [209.85.222.44])
	(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 C6E6C606A320
	for <netdev@vger.kernel.org>; Thu, 29 Oct 2026 23:18:08 +0000 (UTC)
X-DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org C6E6C606A320
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-ua1-f44.google.com with SMTP id a1e0cc1a2514c-990fbae94f5so74403241.3
        for <netdev@vger.kernel.org>; Thu, 29 Oct 2026 16:18:08 -0700 (PDT)
X-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
        d=gmail.com; s=20260707; t=1793315888; x=1793920688; darn=vger.kernel.org;
        h=mime-version:content-transfer-encoding:content-type:references
         :in-reply-to:message-id:date:subject:cc:to:from:from:to:cc:subject
         :date:message-id:reply-to:content-type;
        bh=Xpiy1fahTzksVX2ucGYHJCrX4DFe6BxdxTQ9XfdjhmY=;
        b=g6YoL8+bqk59iYQ7kof6bxfFfXCqXet9J+PNuvC4HunJFJAUPPkl7as0TIN+2aC20G
         u3NZGt88u97DXe6wpqCYDfdW/5YmOCinYP31IupN+KFmNT3MO4nu4vEb+rMLGiTC+mCp
         dLyiR+1lerwbua+0mmRpst10/cVCrpERoLL3eLctyl2PvUTau69TM0T39HbrbkWZwggW
         /zc9ZHh0GXkWtz6QcMWFT0L9CF7oTq/7FzCcfip1Al8do5F0akyE3OIEJE2zGkQ5vsFs
         X/G3MYE9Eekplv8D6SDXKUZUlUVlikQhHy/fl5zqDfh7osdLInZr1u1DWnsefSgbl9Q5
         N67A==
X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
        d=1e100.net; s=20260707; t=1793315888; x=1793920688;
        h=mime-version:content-transfer-encoding:content-type: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=Xpiy1fahTzksVX2ucGYHJCrX4DFe6BxdxTQ9XfdjhmY=;
        b=jOaiI/OpiD7y2TUn/jxguwAgepvHSa0qzKPSTJd/i0az1g+4/qMG4gyay9C0Op3yNS
         NUtgDS3cd/Y+Yl+1IiIl6BGFi3I/YpYPw/yMWk+/PZhuQ8urAp9GourLAzYRgnfk0Y8q
         uU7Mk8wshps3sIocZDXhz54Wx8JxsLGyFNE0vF4Ce2Giy588bJlCNv+aNGncct3FPFOr
         PSNfLDh8zcWTy8i861KTEfn0c/wkPc7Seh71XRi1qCZxfOW2hc39OSgk8MOQMaqUWMGL
         1MnBzTo5ugCCSO/8ti4ccyAXchXmgmBnnIF1ZdkzotAf9mtaWm9x59AZ+VOz/+F4uQjP
         OPEA==
X-Forwarded-Encrypted: i=1; AKwUvBxlPIETDcsH25iDRXEa5i/bclDymppQDyRWM7WBlsw6T5Nsfjf7poqyWunqW3O85MzX6ZIEdyY=@vger.kernel.org
X-Gm-Message-State: AFq9FYI97Cc3FdG/h9GoDj8ZYSHZk4IEFEcf5/6bpiVyMCIRSfursI9l
	zv452ptU2DF/lwZU0++fmHpoBew0xVIfw/62xjplrYFk9spKNv1l+n7E
X-Gm-Gg: AYBFou0pOW93s1C00g5aJ7XpJb1KjUaoVjJAbpRKEGzBfy9mvMvs+p/1N6QYWmHH2HS
	qrQd5cjwdLT/P6doIhiP106qFX4Arg4CvhgaaaLXDk1Ga3oHAK84Iu8yOs4MWNH8FtS/sLAJIgT
	MlNF8CPAOKIkJAKyspsruajHRG7QNKtBCzFfxds7S7EHTadp5TPVVpCkVtVqSiqFOv1JtBhsllR
	kNPTS7SvZPSd7r9fcyg4SKtZaKNZ007CIPwgRjeTAZWuVesShzQ7KnQjatBrYd0zaeaKd4neMw4
	xwyte816XSZEJElBHBY91Ebn1nDPT13wsiTZ8Jug4q+aC3dpLju/Zh61vAh/P4WRJLTHPlZV6T6
	TifB8WCB6nfurj62LEM2JERkkZnaxSPZDTQHVhuK5GAjikIVwseuuA1hGu9XYmEnU13+JieryFY
	cKu35I9EuCf3XFv/shJrEoYDGQhZfLXXXIJy+h49jwUTJGpqJPHgbPlBxx14tRkJSTgRi5TUSal
	l8AQ7tvBMFLboxj3cQ3CS256F26JnoC3H4t5QSNSgqbPWHZSTmKlelgkmieTVZOoXSMr2MoTEVu
	eFzEc9rqLUDRgHl6jhPpspYiEg8ZDCWTCh81qyQhXgwyIDOFt+YJu1QE9dIkQ7EKsyOXp3DN1IF
	+uuuySLy4i9pA3AjdSgWU16zuvCh6rtKJBg==
X-Received: by 2002:a67:e112:0:b0:79e:2b00:b4da with SMTP id ada2fe7eead31-7d07262b7c0mr332764137.6.1793315887662;
        Thu, 29 Oct 2026 16:18:07 -0700 (PDT)
X-Received: from [192.168.15.16] ([2804:1b3:a2c1:77a1:5cd:8fee:f3c:4da7])
        by smtp.gmail.com with ESMTPSA id a1e0cc1a2514c-992ee4e7453sm319509241.11.2026.10.29.16.18.04
        (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256);
        Thu, 29 Oct 2026 16:18:07 -0700 (PDT)
X-Cc: David S. Miller <davem@davemloft.net>, Eric Dumazet <edumazet@kernel.org>,
 Jakub Kicinski <kuba@kernel.org>, Paolo Abeni <pabeni@redhat.com>,
 Simon Horman <horms@kernel.org>, Zhenghang Xiao <kipreyyy@gmail.com>,
 Sanghyun Park <sanghyun.park.cnu@gmail.com>, oe-linux-nfc@lists.linux.dev,
 netdev@vger.kernel.org, linux-kernel@vger.kernel.org
X-In-Reply-To: <179331585573.30322.4049957541187612575@gmail.com>
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