From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=209.85.221.47 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796208957; b=wxG/qxmSP5shQXbteYF32eb8s+sK425WPIU3sKkdlso+4tqW9LFVAI8/hpT0fkOMMFNB Ae2E4jVoGo51vyxpORSMmothtgpvWaABqLV/HmA6aLlRORjyN8lHtPTb3wDGvdKYmT7cy rszB8o43XjSpWP20tjPORMsJ+Q85a2pOkMG8ryjVbQhk/hrY0liss3GXhZmD1PJ5D/jcB dqNNUmfI6TF2GWMpVmxA3rcif/4KxOTupsN+sJFeD+o0vg4zhCoH3hSbRKKSXTeqWH1TR Eu+rICRm6LJRF9DCRBKqvud8G2zG6qWltZxScu0WXuAsuSrR6Y31TQ3spj0sMPxMNuA== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796208957; h=DMARC-Filter:Received:DKIM-Signature:X-Google-DKIM-Signature: X-Gm-Message-State:X-Gm-Gg:X-Received:Received:From:To:Subject:Date: Message-Id:X-Mailer:MIME-Version:Content-Transfer-Encoding; bh=lNwOMagwX8ANTyOFkH9vGf7bHeVAPcyHW9kbHY07SqA=; b=bA+xwb4465j1uB4L5b2U7Enc+GE/uM1TiontPuC73ZBvNpPyKGqb9lpv5KBNs/2N6HFD Ii7gU4FynuiigVQMagZScwk1SbZ1+YLBnRNZKjRSMHdI7zgYNVBaZNOjtlyWuO7IJ3E8X l/mq66jblcuW9q8zf0i5qJaqcqjRbvnmSxcbzBPSB3iV7tkJ0w283gs3mbLWrr4czljYe y+3Of2P+++goAJaQwup0FPpb3L626zzTsaxXZ2EhSeQWQCmVVT7ylXkJuxjtTZgp3KJY7 t9aQC332QdV9wovcWaa9W2sxufVjDQ2bxhNNqvugXHjgdNGNlPQzze2Ie5jG/dVIVbw== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20260707 header.b=wSqCWd3h; arc=none smtp.remote-ip=209.85.221.47 Received: from mail-wr1-f47.google.com (mail-wr1-f47.google.com [209.85.221.47]) (using TLSv1.3 with cipher TLS_AES_128_GCM_SHA256 (128/128 bits) key-exchange X25519 server-signature ECDSA (prime256v1) server-digest SHA256) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id EAE91606A31A for ; Wed, 2 Dec 2026 10:55:56 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org EAE91606A31A 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.a=rsa-sha256 header.s=20260707 header.b=wSqCWd3h Received: by mail-wr1-f47.google.com with SMTP id ffacd0b85a97d-490d59c3edaso8827556f8f.1 for ; Wed, 02 Dec 2026 02:55:56 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20260707; t=1796208955; x=1796813755; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:message-id:date:subject:to :from:from:to:cc:subject:date:message-id:reply-to:content-type; bh=lNwOMagwX8ANTyOFkH9vGf7bHeVAPcyHW9kbHY07SqA=; b=wSqCWd3hhNNshH3MROVX55erOcbJig6ifhAXnFLnleHVsMuBq2lrbRuucaqP96HcI0 swPwaZ24pRIHVVCeWnFzBqGMPvryvMCCnXKifUhWhi/WsdZgkv6mVCDZTXnr0MWqJk+h JsiYvvD1HTxOIQMh/qHnKNBphmxnxZ+rn7IGgk5DbjDl+1h9cuDlkDpTrTMT9nbnuqhn zlTIMQpqq59f4QP5QKQLTmS1ztXwYOz4sTlEIsNX6lwAnzy1PllYEaVR3N8i4EEKRaJM OjNtf31ALJqOcgRdC4mkRWKvytR+frnLgUZniBei9BtEGleyFzz8TWdEC7mW/k7nUAEE yMDg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20260707; t=1796208955; x=1796813755; h=content-transfer-encoding:mime-version:message-id:date:subject:to :from:x-gm-gg:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to:content-type; bh=lNwOMagwX8ANTyOFkH9vGf7bHeVAPcyHW9kbHY07SqA=; b=uVOiC6dPcUk25wPzXEcRDtiKaGc9CQGQW9AEoo6jW+gJ3vg3b4tDIaq3G7pOBgkrdZ 6eRNe9IC7VXgmwdG28GpzeGB4Ql56taOKZ+wprVqzm/ew1AV28oQkHayQSQ/oS5JMnUd U+eSpQThZSWhP7G7D3YpnHg40jsCE2Glj8Njbd3QgjI+/BsNQREWvxTjyt/XAvC5jy2m y7ZpttSrIpvulkYMbWbdlT9+b6AG6kkaf9NzTOovrgEtj00wABij9zvDHg/oJxhxIdnZ ZaF9aM7ddQOYf/9f3/uXQ/Nfupsd8zgXHs2X/uFSfxGLslz64uPH+B1LJqC3v2L4qXNk CFUA== X-Gm-Message-State: APuU4Z9o83EAkP65JLppBe8Pt0lrHw6rDmVUWebqqeGEiBggzMOr1qwN bjFTME1jVA76v49t5eRdg0Xia46QU8TDYhew9nmtOe1/1C2NImdm8ZRDlNPAiRlH3R0= X-Gm-Gg: AZFdTZeE2AUzAMYRc9ChH4cXoQ/20iuc9RQh3Onlv4qU9/+l68i4GzbBEPZZxURFhvZ gztYwrEShUYNpz41YiFKmA3JAHO1gqTdsx6DBNPLa9KmEY6G7EQJQmSkk4y87E9wL8lrQdAvI8j H7dHvhPXDmjAoAGPsOEmhK3HZT6vn8jtWgvwb8ujHWkMsqYQApL3s8MAdks2S8ooX/8ddNZPwWQ AaA2vtSKHDQzJodLTON5u6AHr35JXAz2IC9Jzf5x7/sY3toExdtCWPM/e74o5B+VlKKjkDuUmyE yVdibsMEp0BKd3rmB8UDNwS7MXFwr3MYDFJ+qE+6JFh+YxN+Ax4cUDTPMQ/t94sOG1NZGHXXDpZ vY59SFBr/OCB6cMXJEOazxZZsXahC0KrT7ZiyKg/SVkf3r1zrCdK3zODrlX8pjg7STaY2DjBH8E HSabempUJGSNpF9Tv0CdX9YuFmB0s4f3iu/qoPLxb0vTbdzUSRCs/31SMxaMM1cLG+27x3xMX+w C7cudAV2rs79FIsYVPXnhQ20Zpofw6TefbWZBoZS7cJPFWnYsTn/h9Qxf/AFebKCoMk7lymeorj N+URHnOi1IyaLtQw08U6a4AIwphO24eYJqedZE/FhW4PStd8TfftgZdT3nijdtpAt6CIMAI5XE4 dK5/aUGeQzcPQjEUj5Njp5bdYk4rOXeVi9Ss9MocnZdvHJF5PYEgZpV4= X-Received: by 2002:a05:6000:2382:b0:4a7:1fca:e537 with SMTP id ffacd0b85a97d-4abb0886cbamr79433110f8f.9.1796208955262; Wed, 02 Dec 2026 02:55:55 -0800 (PST) Received: from MYL150-3871.blob.core.windows.net (57.11.28.93.rev.sfr.net. [93.28.11.57]) by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-4ab6bb989b3sm76394086f8f.51.2026.12.02.02.55.54 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 02 Dec 2026 02:55:54 -0800 (PST) From: Nicolas Thibert To: linux-bluetooth@vger.kernel.org Subject: [RESEND PATCH BlueZ v2] adapter/advertising: fix mgmt endian bug Date: Wed, 2 Dec 2026 11:55:38 +0100 Message-Id: <20261202105538.974578-1-nithibert@gmail.com> X-Mailer: git-send-email 2.34.1 X-Mailing-List: linux-bluetooth@vger.kernel.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Several places in adapter.c and advertising.c write a native-endian value directly into a __le16/__le32 field of an mgmt command struct, skipping the cpu_to_le16()/cpu_to_le32() conversion used everywhere else in this codebase for the same purpose. This is a no-op on little-endian hosts (where cpu_to_le16()/cpu_to_le32() are themselves no-ops), which is why it has gone unnoticed, but corrupts the value on big-endian hosts. Confirmed live on MIPS big-endian (OpenWrt/ath79): set_blocked_keys() sends key_count=2 (2 blocked keys), which the kernel's __le16_to_cpu() correctly interprets as 512 (0x0002 byte-swapped is 0x0200) since the wire bytes were never actually swapped to little- endian on the way out -- producing "expected 8706 bytes, got 36 bytes" / "Failed to set blocked keys: Invalid Parameters" errors in dmesg/bluetoothd logs. add_advertising()'s cp->duration and refresh_extended_adv()'s cp.duration/cp.min_interval/cp.max_interval have the identical bug. It is inert with bluetoothctl's default (0) duration/interval values (0 byte-swapped is still 0), but A/B tested live (patch removed vs. applied, bluetoothctl's advertise submenu "interval 100 100" set explicitly) confirms this is not just a theoretical correctness fix: with the bug present, the device stops being discoverable by a real BLE scanner the moment a non-default interval is requested, and becomes discoverable again immediately once patched. Any application that sets an explicit advertising interval or duration hits this. v2: use cpu_to_le16()/cpu_to_le32() instead of htobs()/htobl(), as requested by Luiz. Retested live on the same MIPS big-endian board (blocked keys + explicit advertising interval): behaves identically to the v1 fix, no regressions. --- Resend: v2 passed the CI but the CI pull request was closed after two weeks without the series being applied. Rebased on current master, no change since v2. src/adapter.c | 5 +++-- src/advertising.c | 8 ++++---- 2 files changed, 7 insertions(+), 6 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)); diff --git a/src/advertising.c b/src/advertising.c index d07068c..ecb730c 100644 --- a/src/advertising.c +++ b/src/advertising.c @@ -1060,7 +1060,7 @@ static int refresh_legacy_adv(struct btd_adv_client *client, cp->flags = htobl(flags); cp->instance = client->instance; - cp->duration = client->duration; + cp->duration = cpu_to_le16(client->duration); cp->adv_data_len = adv_data_len; cp->scan_rsp_len = scan_rsp_len; memcpy(cp->data, adv_data, adv_data_len); @@ -1111,13 +1111,13 @@ static int refresh_extended_adv(struct btd_adv_client *client, */ if (client->duration) { - cp.duration = client->duration; + cp.duration = cpu_to_le16(client->duration); flags |= MGMT_ADV_PARAM_DURATION; } if (client->min_interval && client->max_interval) { - cp.min_interval = client->min_interval; - cp.max_interval = client->max_interval; + cp.min_interval = cpu_to_le32(client->min_interval); + cp.max_interval = cpu_to_le32(client->max_interval); flags |= MGMT_ADV_PARAM_INTERVALS; } -- 2.34.1