From nobody Mon Jun 15 10:46:31 2026 Received: from mail-yx1-f48.google.com (mail-yx1-f48.google.com [74.125.224.48]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id E76E43DD524 for ; Thu, 9 Apr 2026 15:08:28 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=74.125.224.48 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1775747310; cv=none; b=KXtCYYIJvGzGINHswWKwLlGAFB0XmDNIdvXRCFfb9Gmfq/VjHoqXeWCxYDh17JKTed2Zv+safmcYe5dJbdH4M+qc4OdWutV0SozuiZ3iSxwBGIfjC/0H08gtqwR3vqTnyo/OL23sXOnM19+qf5vPt3xclg1dNkv6THjCSDhXNOo= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1775747310; c=relaxed/simple; bh=tsWV9xKNk8ZRfQF0qdjf8bnZvwJ4yjJqcyzT5DpB9KQ=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=he4RA8VYI4DRP1QFcNADAYVRMO+lUidshdT5usAOT1CEiiB1x4c4Wn8yYbZ/TY+YCFVVKGZ3m8nILeZAmeLPsu/RfuCpBazkk33eJC8QwFlgCYyE6gpol3fYKJ90UfM8Mk8deBg1Rvoyi0yMLJnteFOCQX+hQv2Y0m768u98Uvk= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=H+dHj5FT; arc=none smtp.client-ip=74.125.224.48 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="H+dHj5FT" Received: by mail-yx1-f48.google.com with SMTP id 956f58d0204a3-649278a69c5so856978d50.3 for ; Thu, 09 Apr 2026 08:08:28 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20251104; t=1775747308; x=1776352108; 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; bh=0zmbdYu+fcv9A3MvczPkc6WO3ccIW1T8auH+a7GvTMc=; b=H+dHj5FTl48dyFoew8YjzvftvoX11yYQ6COMIaw9Ty/8SUnZ6PFN9D12dnkqNICO/r 04IKT7XqsyJhzEvY3VZcktHvYIL1IRwWNN9MpBNptCq43sWJrpgM3rbwo27EutOsaLZf 50DqpSqH+nYJBLv23ZcY/3qHv2n7tzvI4Hjam7HfolJiJs8svUc+wiUNWNy6DC1yFV+5 PspPIB8D7zIBUHD0GKg8KnxDtaWYHrMYBBhkDBB5DNHqaH1UdwEc8nQwvApKeFsHJeSR b5AOdtzIXoCIiqPkzPtc7WtChexzc6kkqYKPgTeJS6L9nJGSwDnXdD0QbuQAsqh2HSKU GrBg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1775747308; x=1776352108; 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; bh=0zmbdYu+fcv9A3MvczPkc6WO3ccIW1T8auH+a7GvTMc=; b=CCBOBPC802zTuVd3kVI47Yu02JoClfnsjkDv9vi49Vrm+jEOpv9WC1ig6XuhPwsU8T blD0rbB5k/CHaSg//8Yvncnpbzxv7a/GkFxDQGgncJG7xsmTwf6dp2JvQ5UlWLn0/p1M Aam/9zWZ9wylx5Dkt8THfKZ/qX1hSwId97OYf3PdrBbKYnoSHp315Xp+nmNcfQtDTvAj UNvqLVLSWb72rNixAbxeqFK3R7kdc9QUSboPF0Pr0HPnRyDflJri3hG1N2XSoGuPPmR5 cPdFxOXAAP9txOIKzgzY7p52nGfiAMfWIP0kywsLcN4QBM7w7kf+XXg+42Ef4I5Fv8S2 ljVg== X-Forwarded-Encrypted: i=1; AJvYcCWNlcGAYw2iCwGY92xwjnMxz2Ykv6Vs/YJ8aB3H7ymwFROym0Ik4viWox2FyViaNflz//MRANd20t7Xjgg=@vger.kernel.org X-Gm-Message-State: AOJu0YyRAo0TiDsK5Kwt7nkaEbvUsOjsvdR3BbadQg07KfJab3Uv6UT7 m+AXwxw5SGJfGaRCIci4F7NBHxUU2DdiQLnUbSne5+QJVWQTLjYr2qxH X-Gm-Gg: AeBDieu7AgtlpzbeFsP5lcmQGF5SfdUTUm9YvrtrzoP9GAFP1MCJLb3wN7MDEq9rJbY Y/8Z9OaCBugyUSKjYQ3KAI/L0F6VhjJGpgF+mmwbIz006yKGwjc8k4lAIfTWNwOTSKO0LbtE0PJ mAmzF2XOrjUFeTXl6Jt0OEBempCJ45PQMLlm/ZUV2j+u4bi/HjNwf9n4aE9NaFiz4pmoGuGoBB1 Sg7lyKTrNgPMxYkdrH4sekZGYcF5qU5EDCGB8uGO1F9e2HTheN85DFLAhkgWNAjwpdNf/822UZt 4S/0Aje6mEPccuR6Bn/BOV8TvUWQ0gbZhYia3jMDg09wn66fcvOlmpkwghcj2g8STBDOSWsqycn MWkuerYp9pe4KEfGvBNDj3XhpXoVZaqyTgQFKZbalsI14s+hvTdaUFvEdEfASOMmBkUhHYIWbpA L0Qc7IAt8xUyKiNq1911b9acDshfrb05VQ9RDr1ScfWQNQMoIO/oqKpdgiYV+umgKvermNzAxB4 LucIMTo44MJGOWh35XXoy0bKOlP X-Received: by 2002:a05:690e:4841:b0:650:15ad:33cf with SMTP id 956f58d0204a3-6504883dc62mr17719652d50.50.1775747307656; Thu, 09 Apr 2026 08:08:27 -0700 (PDT) Received: from TDC4045031631.e0cglfehwr0e5gttmepj3hi3hf.ux.internal.cloudapp.net ([20.63.37.123]) by smtp.gmail.com with ESMTPSA id 956f58d0204a3-6503a828f3csm11157265d50.3.2026.04.09.08.08.26 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 09 Apr 2026 08:08:27 -0700 (PDT) From: Ashutosh Desai To: netdev@vger.kernel.org Cc: Eric Dumazet , davem@davemloft.net, kuba@kernel.org, pabeni@redhat.com, horms@kernel.org, linux-kernel@vger.kernel.org, Ashutosh Desai Subject: [PATCH v2] nfc: hci: fix OOB heap read on short HCP frames Date: Thu, 9 Apr 2026 15:08:25 +0000 Message-Id: <20260409150825.2217133-1-ashutoshdesai993@gmail.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: References: Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Both nfc_hci_recv_from_llc() and nfc_hci_msg_rx_work() cast skb->data to struct hcp_packet and read the message header byte without verifying the data is present in the linear sk_buff area. The same issue exists in the NCI HCI path via nci_hci_data_received_cb() and nci_hci_msg_rx_work(). The initial fix checked skb->len, but that counts bytes in non-linear fragments too. skb->data only covers the linear head, so a fragmented skb with len >=3D 2 but the payload in a fragment would still result in an out-of-bounds read. Eric Dumazet pointed this out. Switch to pskb_may_pull() which validates that the requested bytes are available and pulls fragment data into the linear area if needed, which is the correct approach here. Suggested-by: Eric Dumazet Signed-off-by: Ashutosh Desai --- net/nfc/hci/core.c | 9 +++++++++ net/nfc/nci/hci.c | 9 +++++++++ 2 files changed, 18 insertions(+) diff --git a/net/nfc/hci/core.c b/net/nfc/hci/core.c index 0d33c81a1..b8fe59f44 100644 --- a/net/nfc/hci/core.c +++ b/net/nfc/hci/core.c @@ -134,6 +134,10 @@ static void nfc_hci_msg_rx_work(struct work_struct *wo= rk) u8 instruction; =20 while ((skb =3D skb_dequeue(&hdev->msg_rx_queue)) !=3D NULL) { + if (!pskb_may_pull(skb, NFC_HCI_HCP_HEADER_LEN)) { + kfree_skb(skb); + continue; + } pipe =3D skb->data[0]; skb_pull(skb, NFC_HCI_HCP_PACKET_HEADER_LEN); message =3D (struct hcp_message *)skb->data; @@ -904,6 +908,11 @@ static void nfc_hci_recv_from_llc(struct nfc_hci_dev *= hdev, struct sk_buff *skb) * unblock waiting cmd context. Otherwise, enqueue to dispatch * in separate context where handler can also execute command. */ + if (!pskb_may_pull(hcp_skb, NFC_HCI_HCP_HEADER_LEN)) { + kfree_skb(hcp_skb); + return; + } + packet =3D (struct hcp_packet *)hcp_skb->data; type =3D HCP_MSG_GET_TYPE(packet->message.header); if (type =3D=3D NFC_HCI_HCP_RESPONSE) { diff --git a/net/nfc/nci/hci.c b/net/nfc/nci/hci.c index 40ae8e5a7..4243ca9b1 100644 --- a/net/nfc/nci/hci.c +++ b/net/nfc/nci/hci.c @@ -412,6 +412,10 @@ static void nci_hci_msg_rx_work(struct work_struct *wo= rk) =20 for (; (skb =3D skb_dequeue(&hdev->msg_rx_queue)); kcov_remote_stop()) { kcov_remote_start_common(skb_get_kcov_handle(skb)); + if (!pskb_may_pull(skb, NCI_HCI_HCP_HEADER_LEN)) { + kfree_skb(skb); + continue; + } pipe =3D NCI_HCP_MSG_GET_PIPE(skb->data[0]); skb_pull(skb, NCI_HCI_HCP_PACKET_HEADER_LEN); message =3D (struct nci_hcp_message *)skb->data; @@ -482,6 +486,11 @@ void nci_hci_data_received_cb(void *context, * unblock waiting cmd context. Otherwise, enqueue to dispatch * in separate context where handler can also execute command. */ + if (!pskb_may_pull(hcp_skb, NCI_HCI_HCP_HEADER_LEN)) { + kfree_skb(hcp_skb); + return; + } + packet =3D (struct nci_hcp_packet *)hcp_skb->data; type =3D NCI_HCP_MSG_GET_TYPE(packet->message.header); if (type =3D=3D NCI_HCI_HCP_RESPONSE) { --=20 2.34.1