From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=209.85.214.180 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796001744; b=sH08XsqS6gL1HcHkHHWcWetPP7bWgHrfBLdhgxuQHRsG34nVooiUIgPj1hGSvVENFsuP kpUqy74UmcnkehxsQudnPs8DlS6HKhzWBnQRFUd6ZGI1RBW+Fhstw6dbisuD2xnCTVcsB aWozLnYzfI0z27Z9rOvmVUl8MWsIlZsFyTAkATO/kT683MNyk84zUTj0Uwa3tB+xJpTG1 zqcTwi7Bo6gTq/FjMa1y0gysYbIRt7yq3Lth7nzTnF5tyFVxQoD54E2tSAWi5xA+ZCjt0 FzNP78CY1FpTDPLv0f5WGCdNm1yDCihuH3svoz1fRrGCfBY4oJ1GgiPDtMhn1FUm+Dg== 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=WGCZUoNnLsz1ewIp+NbgxcuLo9MYVb2k7AQsJ0t3OkqvUPvCZx1Q/SX+b8ptO6axQldQ Qx7YST79qHL1H0k2mtNn3DQC4tuO2sy8hWySnXIT9TYurSEIy+xT1ojQWlmUHL0kbPOgx R8AMLUO+TOA2rE5SAN1OW1T3NGt4r/iKixYu/UnBX3SrnfRFuNozQGCXTJBQWunymm+kr 9DyWoRHjCeGm+Jf7M7iNNO1fMJm9rXn0UaFiSvHtvLEZMFGAqGBxl3C+2POIRKt0UlTmR wbUeEimeVu+AbmT7/YmMi07bAdVI/DE7XByAu27zlASYHTGRa8hAYIb5AYse9ITBF1Q== 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.180 Received: from mail-pl1-f180.google.com (mail-pl1-f180.google.com [209.85.214.180]) (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 99F1C606A330 for ; Mon, 30 Nov 2026 01:22:23 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org 99F1C606A330 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=iiitd.ac.in Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=iiitd.ac.in 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 Received: by mail-pl1-f180.google.com with SMTP id d9443c01a7336-2f048476ab9so68366305ad.0 for ; Sun, 29 Nov 2026 17:22:23 -0800 (PST) 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=eDCI+dZ+SZG+++Y1njfVVHAs2TBDGT54t/cHLYdhjC8h5gkl4mDrpeRRiooBfVY4f1 eRMWTxHQdmupxIpjkbzol/gaJikIbtQw51RYLJyYRRk6qTOKAqXX8Jncg1hPwIOhV51S 2s1dD5TQpWBK/aqR/SIodzs7QVRNemSG7Sbe1F6fARL8R6Jyv0zmg5dP4or0EMur3XgZ gEe2ew1yfyrOffPGY7vHktfGWVmQhMzQDQdW8jbIBArwEIi0FrESdIjJOIpGSuQSWpZE vblOj9T24ADoM6/b3CJxehtBX6G/t7X0o4NZcCxy0PgmFN3RT6uBGEsNNN/r+UYZ4g0n bBEw== X-Forwarded-Encrypted: i=1; AL+hErHxZiMn5dfQ8yovbNkKPCpTT0m+tdo0tDUYGuOUQwXIc2c6F3aJH7/jZtsrLICyZGAAMLgajnyqXPT2+o8=@vger.kernel.org X-Gm-Message-State: APuU4Z8b7okZkq38loOEsIVwmXd4blseu+l04DHThPM78MtRNYnuAlC4 rAfqjpm/Dk8STIOZgI+TX7isVJLUcZWIvKDkUj4nDaPh66H31Vj5Uww0ICeh9Bt9VHE= X-Gm-Gg: AZFdTZc9s0RVqUQssw23P5lappNXlfCut7YYxFhMz/pAWWu5YKeU+NC4Z+IFJ5Sf84v 44oR/kFf6a0q+hEwDeFP6oye4nnQHNU6bYJ/eORia2E4dmIAU+nWdUPyXMA/qEdZbfr22TYLmzg /NUrCf3K3YQ1/Tyv+NkCyENBWQyCJQsJHSc53vAF8XRaPxLxi6ps377e7pZbWipcZLZbm4jdHr4 JNaFgZhMwTmCzdKazBgbZxZIe6lJAlN414+yNuij4Tl/YG8kGDzBKUc615tVPlQyYVx3BzyGyda 93xnaY5NYSHpu6A1CQWyyt8X0KAVuplnqCFfvY0l3j127CgmXM5RdM/zFjl3Hur/Hpp6ARKLixA /oHMdrubG/2xmHVxhz7jtTmm02qseVkYC+B7GY1XLlJk6vO1FloEya5IwhfgVQDEI9MD/GAjH8Z cLTXdTeDTfrTMWzsRfvNViwV0TDKv203KRfUmhTWAO2/VnCIgzeMkFQX6/pZCOnEhGGHEYTsCsO Vq7BKcDCc1A9YIsK6G1VYp0AXgcAMtvYOu2clSskAcEieyP1OjuUKbbd+EFCgm23cV+0v+lWCDo GKinRZ2QrOOvrngI2xLpd+nU7l7etxBqUHirtb9z3lMwxMuCPITcF3fs+4hvaCt96nye3fubcVh xq8W+Hjr4dY+eyyIsDlgOxegZyArm7chFLI3ZklXSIvvPO6og/ZBVpCqimhe7e4jA 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) 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) From: Piyus Kedia To: David Heidelberg , "David S. Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni , Willem de Bruijn , Simon Horman Cc: oe-linux-nfc@lists.linux.dev, netdev@vger.kernel.org, linux-kernel@vger.kernel.org, Kapil Vaswani 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 Message-Id: <20261130012208.1962491-3-piyus@iiitd.ac.in> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20261130012208.1962491-1-piyus@iiitd.ac.in> References: <20261130012208.1962491-1-piyus@iiitd.ac.in> X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list MIME-Version: 1.0 Content-Transfer-Encoding: 8bit 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 Signed-off-by: Piyus Kedia --- 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