Public bug reported:

[ Impact ]

WirePlumber sometimes crashes when the Bluetooth adapter goes away, for
example when bluetoothd restarts. All audio devices disappear until systemd
restarts it. On my laptop it happens in about 3% of bluetoothd restarts
(18 of 600). No Bluetooth device needs to be connected.

The journal shows one of:

  wireplumber: corrupted size vs. prev_size
  wireplumber: malloc(): unaligned tcache chunk detected
  kernel: wireplumber[...]: segfault at 9 ip ... in libglib-2.0.so.0

The cause is in the BLE MIDI code of libspa-0.2-bluetooth. Three GDBusProxy
subclasses override finalize and do not call the parent finalize, so GLib
keeps a weak pointer into the freed proxy. When BlueZ removes the adapter,
GLib writes NULL through that pointer into freed memory.

Fix proposed upstream:
https://gitlab.freedesktop.org/pipewire/pipewire/-/merge_requests/3129

I found this whilst verifying LP: #2160089. That fix is unrelated; the
crash rate is the same with and without it.

[ Test Plan ]

On real hardware with a Bluetooth adapter, logged in to a desktop
session:

1. Note the WirePlumber PID:
     pgrep -x wireplumber
2. Restart bluetoothd 150 times:
     for i in $(seq 150); do sudo systemctl restart bluetooth; sleep 5; done
3. Check the PID again and the journal:
     pgrep -x wireplumber
     journalctl --user -u wireplumber -b | grep -E "corrupted|malloc\(\)|dumped"

Without the fix: the PID changes and the journal shows crashes (4 to 7 per
150 restarts here).
With the fix: same PID, nothing in the journal.

Also check that Bluetooth audio still works: connect a headset, play audio,
switch between A2DP and HFP.

[ Where problems could occur ]

The change only touches the BLE MIDI proxies in the Bluetooth plugin
(midi-enum.c, midi-server.c). The parent finalize now runs where it did not
before, so any mistake would show up as a crash or a GLib warning from
WirePlumber when a BLE MIDI device or the adapter is removed, or at
WirePlumber shutdown. Bluetooth audio does not use this code.

I have no BLE MIDI device, so BLE MIDI itself is untested.

[ Other Info ]

Confirmed with AddressSanitizer builds of libspa-0.2-bluetooth and GLib on
resolute (pipewire 1.6.2-1ubuntu1.3): heap-use-after-free write in
g_nullify_pointer on the first bluetoothd restart. With the patch, 150
restarts give no report, and 150 restarts on a normal build give no crash.

The same code is in 1.6.8 (stonking, tenacious) and 1.6.11
(tenacious-proposed). I have only reproduced it on resolute.

Workaround: disable the monitor in
~/.config/wireplumber/wireplumber.conf.d/no-bluez-midi.conf

  wireplumber.profiles = {
    main = {
      monitor.bluez-midi = disabled
    }
  }

Possibly the same crash upstream:
https://gitlab.freedesktop.org/pipewire/wireplumber/-/work_items/1003
https://gitlab.freedesktop.org/pipewire/wireplumber/-/work_items/951

** Affects: pipewire (Ubuntu)
     Importance: High
     Assignee: Charles (charles05)
         Status: In Progress

** Affects: pipewire (Ubuntu Resolute)
     Importance: High
     Assignee: Charles (charles05)
         Status: Triaged

** Affects: pipewire (Ubuntu Stonking)
     Importance: High
     Assignee: Charles (charles05)
         Status: Triaged

** Affects: pipewire (Ubuntu Tenacious)
     Importance: High
     Assignee: Charles (charles05)
         Status: In Progress


** Tags: resolute stonking tenacious

** Also affects: pipewire (Ubuntu Resolute)
   Importance: Undecided
       Status: New

** Also affects: pipewire (Ubuntu Stonking)
   Importance: Undecided
       Status: New

** Also affects: pipewire (Ubuntu Tenacious)
   Importance: Undecided
       Status: New

** Changed in: pipewire (Ubuntu Stonking)
   Importance: Undecided => High

** Changed in: pipewire (Ubuntu Tenacious)
   Importance: Undecided => High

** Changed in: pipewire (Ubuntu Resolute)
   Importance: Undecided => High

** Changed in: pipewire (Ubuntu Resolute)
       Status: New => In Progress

** Changed in: pipewire (Ubuntu Stonking)
       Status: New => In Progress

** Changed in: pipewire (Ubuntu Tenacious)
       Status: New => In Progress

** Changed in: pipewire (Ubuntu Tenacious)
     Assignee: (unassigned) => Charles (charles05)

** Changed in: pipewire (Ubuntu Stonking)
    Milestone: None => stonking-updates

** Changed in: pipewire (Ubuntu Resolute)
    Milestone: None => resolute-updates

** Changed in: pipewire (Ubuntu Stonking)
     Assignee: (unassigned) => Charles (charles05)

** Changed in: pipewire (Ubuntu Resolute)
     Assignee: (unassigned) => Charles (charles05)

** Changed in: pipewire (Ubuntu Stonking)
       Status: In Progress => Triaged

** Changed in: pipewire (Ubuntu Resolute)
       Status: In Progress => Triaged

-- 
You received this bug notification because you are a member of Ubuntu
Bugs, which is subscribed to Ubuntu.
https://bugs.launchpad.net/bugs/2174961

Title:
  [SRU] WirePlumber crashes with heap corruption when bluetoothd
  restarts

To manage notifications about this bug go to:
https://bugs.launchpad.net/ubuntu/+source/pipewire/+bug/2174961/+subscriptions


-- 
ubuntu-bugs mailing list
[email protected]
https://lists.ubuntu.com/mailman/listinfo/ubuntu-bugs

Reply via email to