From: Nicolas Thibert <nithibert@gmail.com>
To: linux-bluetooth@vger.kernel.org
Cc: Luiz Augusto von Dentz <luiz.dentz@gmail.com>
Subject: [PATCH BlueZ v3 1/2] adapter: Fix key_count endianness in MGMT_OP_SET_BLOCKED_KEYS
Date: Wed, 2 Dec 2026 16:17:37 +0100 [thread overview]
Message-ID: <20261202151738.1146722-2-nithibert@gmail.com> (raw)
In-Reply-To: <20261202151738.1146722-1-nithibert@gmail.com>
set_blocked_keys() writes the native-endian key count directly into
the __le16 key_count field of struct mgmt_cp_set_blocked_keys, without
cpu_to_le16(). This is a no-op on little-endian hosts, which is why it
has gone unnoticed, but corrupts the value on big-endian hosts.
Confirmed live on MIPS big-endian (OpenWrt/ath79): key_count=2 is read
by the kernel as 512 (0x0200), and the command fails with "expected
8706 bytes, got 36 bytes" in dmesg and "Failed to set blocked keys:
Invalid Parameters" in the bluetoothd logs. With the fix, the command
succeeds.
---
src/adapter.c | 5 +++--
1 file changed, 3 insertions(+), 2 deletions(-)
diff --git a/src/adapter.c b/src/adapter.c
index 1ec1c70..7bdabf9 100644
--- a/src/adapter.c
+++ b/src/adapter.c
@@ -10553,10 +10553,11 @@ static bool set_blocked_keys(struct btd_adapter *adapter)
sizeof(blocked_keys)] = { 0 };
struct mgmt_cp_set_blocked_keys *cp =
(struct mgmt_cp_set_blocked_keys *)buffer;
+ const uint16_t key_count = ARRAY_SIZE(blocked_keys);
int i;
- cp->key_count = ARRAY_SIZE(blocked_keys);
- for (i = 0; i < cp->key_count; ++i) {
+ cp->key_count = cpu_to_le16(key_count);
+ for (i = 0; i < key_count; ++i) {
cp->keys[i].type = blocked_keys[i].type;
memcpy(cp->keys[i].val, blocked_keys[i].val,
sizeof(cp->keys[i].val));
--
2.34.1
next prev parent reply other threads:[~2026-12-02 15:17 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-12-02 15:17 [PATCH BlueZ v3 0/2] Fix mgmt endianness on big-endian hosts Nicolas Thibert
2026-12-02 15:17 ` Nicolas Thibert [this message]
2026-12-02 15:17 ` [PATCH BlueZ v3 2/2] advertising: Fix duration and interval endianness Nicolas Thibert
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=20261202151738.1146722-2-nithibert@gmail.com \
--to=nithibert@gmail.com \
--cc=linux-bluetooth@vger.kernel.org \
--cc=luiz.dentz@gmail.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