public inbox for linux-bluetooth@vger.kernel.org
 help / color / mirror / Atom feed
From: Dudu Lu <phx0fer@gmail.com>
To: linux-bluetooth@vger.kernel.org
Cc: marcel@holtmann.org, luiz.dentz@gmail.com, Dudu Lu <phx0fer@gmail.com>
Subject: [PATCH] Bluetooth: bnep: Fix endianness in bnep_rx_frame() extension parsing
Date: Mon, 13 Apr 2026 16:44:41 +0800	[thread overview]
Message-ID: <20260413084442.68604-1-phx0fer@gmail.com> (raw)

In bnep_rx_frame(), the extension header parsing for
BNEP_FILTER_NET_TYPE_SET and BNEP_FILTER_MULTI_ADDR_SET uses
*(u16 *)(skb->data + 1) to read the 2-byte length field.  This
performs a native-endian read, but the BNEP protocol specifies this
field in big-endian (network byte order).

On little-endian architectures (x86, ARM), the bytes are swapped,
causing the length to be wildly incorrect.  For example, a length
of 3 (0x00 0x03) is read as 768 (0x0300).  This causes either:
- skb_pull failure (length too large) -> frame dropped
- Insufficient pull (length too small) -> frame parsing corruption

The same file correctly uses get_unaligned_be16() for identical
fields in bnep_ctrl_set_netfilter() (line 110) and
bnep_ctrl_set_mcfilter() (line 156), confirming the inconsistency.

Replace *(u16 *)(skb->data + 1) with get_unaligned_be16(skb->data + 1).

Fixes: 1da177e4c3f4 ("Linux-2.6.12-rc2")
Signed-off-by: Dudu Lu <phx0fer@gmail.com>
---
 net/bluetooth/bnep/core.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/net/bluetooth/bnep/core.c b/net/bluetooth/bnep/core.c
index d44987d4515c..2d1cb2061045 100644
--- a/net/bluetooth/bnep/core.c
+++ b/net/bluetooth/bnep/core.c
@@ -332,7 +332,7 @@ static int bnep_rx_frame(struct bnep_session *s, struct sk_buff *skb)
 		case BNEP_FILTER_MULTI_ADDR_SET:
 		case BNEP_FILTER_NET_TYPE_SET:
 			/* Pull: ctrl type (1 b), len (2 b), data (len bytes) */
-			if (!skb_pull(skb, 3 + *(u16 *)(skb->data + 1) * 2))
+			if (!skb_pull(skb, 3 + get_unaligned_be16(skb->data + 1) * 2))
 				goto badframe;
 			break;
 		default:
-- 
2.39.3 (Apple Git-145)


             reply	other threads:[~2026-04-13  8:44 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-04-13  8:44 Dudu Lu [this message]
2026-04-13  9:41 ` Bluetooth: bnep: Fix endianness in bnep_rx_frame() extension parsing bluez.test.bot
2026-04-13 16:54 ` [PATCH] " Luiz Augusto von Dentz

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=20260413084442.68604-1-phx0fer@gmail.com \
    --to=phx0fer@gmail.com \
    --cc=linux-bluetooth@vger.kernel.org \
    --cc=luiz.dentz@gmail.com \
    --cc=marcel@holtmann.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