Netdev List
 help / color / mirror / Atom feed
From: Eric Dumazet <edumazet@google.com>
To: "David S . Miller" <davem@davemloft.net>,
	Jakub Kicinski <kuba@kernel.org>,
	 Paolo Abeni <pabeni@redhat.com>
Cc: Simon Horman <horms@kernel.org>,
	netdev@vger.kernel.org, eric.dumazet@gmail.com,
	 Eric Dumazet <edumazet@google.com>,
	Shuangpeng Bai <shuangpeng.kernel@gmail.com>,
	 David Heidelberg <david@ixit.cz>,
	oe-linux-nfc@lists.linux.dev
Subject: [PATCH net] nfc: llcp: fix UAF on socket in nfc_llcp_tx_work()
Date: Fri, 21 Aug 2026 14:13:58 +0000	[thread overview]
Message-ID: <20260821141358.3546366-1-edumazet@google.com> (raw)

Shuangpeng Bai reported a slab-use-after-free in nfc_llcp_tx_work():

  BUG: KASAN: slab-use-after-free in _raw_spin_lock_irqsave
  Write of size 4 at addr ffff88811da9cb94 by task kworker/0:0/9
  Call Trace:
   _raw_spin_lock_irqsave (kernel/locking/spinlock.c:166)
   skb_queue_tail (net/core/skbuff.c:4114)
   nfc_llcp_tx_work (net/nfc/llcp_core.c:848)

When transmitting an I-frame, nfc_llcp_tx_work() creates a copy via
skb_copy() to keep in tx_pending_queue. If the socket is closed
concurrently, freeing the original skb during nfc_data_exchange()
drops sk_wmem_alloc to 0 and destroys the socket before copy_skb is
queued to llcp_sock->tx_pending_queue.

Call skb_set_owner_w(copy_skb, sk) to keep the socket alive while
copy_skb is queued.

Fixes: be02b6b62400 ("NFC: Queue a copy of the transmitted LLCP skb")
Reported-by: Shuangpeng Bai <shuangpeng.kernel@gmail.com>
Closes: https://lore.kernel.org/netdev/20260819050031.2725592-1-shuangpeng.kernel@gmail.com/
Signed-off-by: Eric Dumazet <edumazet@google.com>
---
Cc: David Heidelberg <david@ixit.cz>
Cc: oe-linux-nfc@lists.linux.dev
---
 net/nfc/llcp_core.c | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)

diff --git a/net/nfc/llcp_core.c b/net/nfc/llcp_core.c
index cac1b5487064d0c5b4966bb6a75aa26e67131049..49cb632268c0c2841e3b44dde124c7966267b709 100644
--- a/net/nfc/llcp_core.c
+++ b/net/nfc/llcp_core.c
@@ -786,8 +786,11 @@ static void nfc_llcp_tx_work(struct work_struct *work)
 			print_hex_dump_debug("LLCP Tx: ", DUMP_PREFIX_OFFSET,
 					     16, 1, skb->data, skb->len, true);
 
-			if (ptype == LLCP_PDU_I)
+			if (ptype == LLCP_PDU_I) {
 				copy_skb = skb_copy(skb, GFP_ATOMIC);
+				if (copy_skb)
+					skb_set_owner_w(copy_skb, sk);
+			}
 
 			__net_timestamp(skb);
 
-- 
2.55.0.766.g2966f0265a-goog


             reply	other threads:[~2026-08-21 14:14 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-08-21 14:13 Eric Dumazet [this message]
2026-08-21 14:20 ` [PATCH net] nfc: llcp: fix UAF on socket in nfc_llcp_tx_work() Shuangpeng

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20260821141358.3546366-1-edumazet@google.com \
    --to=edumazet@google.com \
    --cc=davem@davemloft.net \
    --cc=david@ixit.cz \
    --cc=eric.dumazet@gmail.com \
    --cc=horms@kernel.org \
    --cc=kuba@kernel.org \
    --cc=netdev@vger.kernel.org \
    --cc=oe-linux-nfc@lists.linux.dev \
    --cc=pabeni@redhat.com \
    --cc=shuangpeng.kernel@gmail.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox