Linux bluetooth development
 help / color / mirror / Atom feed
* [PATCH BlueZ 0/3] Cancel pending HoG reports before detach
@ 2026-09-22  1:15 Nicholas Hammond
  2026-09-22  1:15 ` [PATCH BlueZ 1/3] input/hog: Cancel pending report requests on detach Nicholas Hammond
                   ` (2 more replies)
  0 siblings, 3 replies; 7+ messages in thread
From: Nicholas Hammond @ 2026-09-22  1:15 UTC (permalink / raw)
  To: linux-bluetooth

From: Nick Hammond <blender7@gmail.com>

This series fixes outstanding HID report callbacks surviving HoG detach.

The investigation started with a bluetoothd crash on Ubuntu BlueZ
5.72-0ubuntu5.5 while reconnecting an MX Keys S keyboard after switching
hosts. The saved stack passes through report_reply/get_report_cb,
read_blob_helper and attrib_callback_result. The original core and device
identifiers are intentionally not included.

On current master (17e624d1c), getrep_att and setrep_att still bypass the
gatt_op queue cancelled by bt_hog_detach. If another owner retains the
GAttrib connection, a late response can invoke a callback after its HoG
object/report is freed. A surviving HoG object can also receive a stale
reply after detach.

A socketpair test on that revision reproduces the read, long-read and
write use-after-free under AddressSanitizer. For example, the long-read
case reports:

  ERROR: AddressSanitizer: heap-use-after-free
    get_report_cb       profiles/input/hog-lib.c:929
    read_blob_helper    attrib/gatt.c:791
    attrib_callback_result attrib/gattrib.c:235
    handle_rsp          src/shared/att.c:913

This is a lifetime regression test with a shared live GAttrib reference,
not an over-the-air reproducer or a claim of unauthenticated reachability.
It does not establish that every historical keyboard outage had this
cause.

Patch 1 cancels the separately tracked report requests before dropping
attrib. Patches 2 and 3 add and register five hardware-independent tests.
The test includes hog-lib.c to access private report state, avoiding new
production APIs and unrelated discovery traffic.

Validation on current master plus this series:
- AddressSanitizer with detect_leaks=1: all five new tests pass.
- Existing test-hog (6), test-gattrib (6), test-gatt (193): all pass.
- checkpatch --no-tree --no-signoff: no errors or warnings.
- A backport to Ubuntu 5.72 is installed on the affected host; keyboard
  and mouse reconnected after restarting the daemon. Long-term stability
  is not yet established.

To reproduce the failures, apply only patches 2 and 3 to the base revision
and build with --enable-asan. Run unit/test-hog-lifetime -p followed by
/hog/detach/read, /hog/detach/blob or /hog/detach/write. Each detects a
use-after-free without patch 1. /hog/reconnect catches the stale reply;
/hog/normal passes before and after the fix.

AI assistance disclosure: Codex:gpt-6 analyzed the saved crash, prepared
the fix and tests, and ran the validation commands. This contribution
includes Assisted-by tags. No claim of an independent human code review
is made.

Thanks,
Nick Hammond

Nick Hammond (3):
  input/hog: Cancel pending report requests on detach
  unit: Test pending HoG reports across detach
  build: Register the HoG report lifetime tests

 Makefile.am              |  14 ++++
 profiles/input/hog-lib.c |  11 +++
 unit/test-hog-lifetime.c | 152 +++++++++++++++++++++++++++++++++++++++
 3 files changed, 177 insertions(+)
 create mode 100644 unit/test-hog-lifetime.c


base-commit: 17e624d1cd9a4d94f90e0ca008548456c3455492
-- 
2.43.0

^ permalink raw reply	[flat|nested] 7+ messages in thread

end of thread, other threads:[~2026-10-07 12:06 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-09-22  1:15 [PATCH BlueZ 0/3] Cancel pending HoG reports before detach Nicholas Hammond
2026-09-22  1:15 ` [PATCH BlueZ 1/3] input/hog: Cancel pending report requests on detach Nicholas Hammond
2026-09-22  6:36   ` Cancel pending HoG reports before detach bluez.test.bot
2026-10-07 12:06   ` bluez.test.bot
2026-09-22  1:15 ` [PATCH BlueZ 2/3] unit: Test pending HoG reports across detach Nicholas Hammond
2026-09-22 14:25   ` Luiz Augusto von Dentz
2026-09-22  1:15 ` [PATCH BlueZ 3/3] build: Register the HoG report lifetime tests Nicholas Hammond

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox