From: Syed Abdul Khaliq <abdul@bugqore.com>
To: linux-kernel@vger.kernel.org
Subject: [PATCH] nfc: llcp: validate TLV length to prevent out-of-bounds read
Date: Thu, 02 Jul 2026 14:21:31 +0530 [thread overview]
Message-ID: <178298229140.44037.18255999514826696970@bugqore.com> (raw)
nfc_llcp_parse_gb_tlv() and nfc_llcp_parse_connection_tlv() walk a TLV
array taken from an LLCP PDU received from a remote peer. The loop is
bounded only by "offset < tlv_array_len", so it reads the length byte
tlv[1] and, via llcp_tlv8()/llcp_tlv16(), the value bytes tlv[2] and
tlv[3] without checking that the full TLV (2 + length bytes) actually
fits inside the array.
A truncated or malformed TLV therefore triggers an out-of-bounds read of
the received skb data. For example a CONNECT PDU whose payload after the
2-byte LLCP header is a single MIUX type byte gives tlv_array_len == 1:
tlv[1] is read one byte past the buffer, and the MIUX handler goes on to
read tlv[2]/tlv[3] via llcp_tlv16(). A TLV whose length field runs past
the end of the array makes the following iteration dereference tlv well
beyond the buffer. nfc_llcp_parse_connection_tlv() parses the data
directly out of the received skb (net/nfc/llcp_core.c), so the read runs
off the end of the slab allocation.
Reject any TLV that does not fully fit in the remaining array before
reading its length and value.
Signed-off-by: Syed Abdul Khaliq <abdul@bugqore.com>
---
diff --git a/net/nfc/llcp_commands.c b/net/nfc/llcp_commands.c
index 291f26facb..4e22788f95 100644
--- a/net/nfc/llcp_commands.c
+++ b/net/nfc/llcp_commands.c
@@ -201,6 +201,13 @@ int nfc_llcp_parse_gb_tlv(struct nfc_llcp_local *local,
return -ENODEV;
while (offset < tlv_array_len) {
+ if (tlv_array_len - offset < 2 ||
+ tlv[1] > tlv_array_len - offset - 2) {
+ pr_err("Malformed TLV, offset %d array length %d\n",
+ offset, tlv_array_len);
+ return -EINVAL;
+ }
+
type = tlv[0];
length = tlv[1];
@@ -251,6 +258,13 @@ int nfc_llcp_parse_connection_tlv(struct nfc_llcp_sock *sock,
return -ENOTCONN;
while (offset < tlv_array_len) {
+ if (tlv_array_len - offset < 2 ||
+ tlv[1] > tlv_array_len - offset - 2) {
+ pr_err("Malformed TLV, offset %d array length %d\n",
+ offset, tlv_array_len);
+ return -EINVAL;
+ }
+
type = tlv[0];
length = tlv[1];
--
2.50.1 (Apple Git-155)
reply other threads:[~2026-07-02 8:51 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=178298229140.44037.18255999514826696970@bugqore.com \
--to=abdul@bugqore.com \
--cc=linux-kernel@vger.kernel.org \
/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
all inboxes | Powered by JetHome®