From: Dudu Lu <phx0fer@gmail.com>
To: netdev@vger.kernel.org
Cc: davem@davemloft.net, edumazet@google.com, kuba@kernel.org,
pabeni@redhat.com, Dudu Lu <phx0fer@gmail.com>
Subject: [PATCH] nfc: nci: Add skb length validation in nci_core_init_rsp_packet
Date: Mon, 13 Apr 2026 17:01:02 +0800 [thread overview]
Message-ID: <20260413090102.77980-1-phx0fer@gmail.com> (raw)
nci_core_init_rsp_packet_v1() and nci_core_init_rsp_packet_v2() cast
skb->data to response structures and dereference fields without first
checking that skb->len is large enough. A malicious or malformed NFCC
can send a short response packet, causing an out-of-bounds read.
Add minimum length checks at the start of both functions. For v1, check
that at least sizeof(nci_core_init_rsp_1) bytes are available before
accessing rsp_1 fields, and validate the dynamic offset before accessing
rsp_2. For v2, check that at least sizeof(nci_core_init_rsp_nci_ver2)
bytes are available.
Signed-off-by: Dudu Lu <phx0fer@gmail.com>
---
net/nfc/nci/rsp.c | 11 +++++++++++
1 file changed, 11 insertions(+)
diff --git a/net/nfc/nci/rsp.c b/net/nfc/nci/rsp.c
index 9eeb862825c5..01972c806b45 100644
--- a/net/nfc/nci/rsp.c
+++ b/net/nfc/nci/rsp.c
@@ -1,3 +1,14 @@
+ if (skb->len < sizeof(*rsp)) {
+ pr_err("short NCI_CORE_INIT_RSP v2 packet\n");
+ return NCI_STATUS_SYNTAX_ERROR;
+ }
+ if (skb->len < 6 + rsp_1->num_supported_rf_interfaces +
+ sizeof(*rsp_2)) {
+ pr_err("short NCI_CORE_INIT_RSP v1 packet\n");
+ return NCI_STATUS_SYNTAX_ERROR;
+ }
+ if (skb->len < sizeof(*rsp_1))
+ return NCI_STATUS_SYNTAX_ERROR;
// SPDX-License-Identifier: GPL-2.0-only
/*
* The NFC Controller Interface is the communication protocol between an
--
2.39.3 (Apple Git-145)
reply other threads:[~2026-04-13 9:01 UTC|newest]
Thread overview: [no followups] expand[flat|nested] mbox.gz Atom feed
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=20260413090102.77980-1-phx0fer@gmail.com \
--to=phx0fer@gmail.com \
--cc=davem@davemloft.net \
--cc=edumazet@google.com \
--cc=kuba@kernel.org \
--cc=netdev@vger.kernel.org \
--cc=pabeni@redhat.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