Skip to content

bug: linux-pipewire: unplugging a PipeWire camera logs a freed string (use-after-free) (upstream PR #13698) #392

Closed

Description

@rdoupe

Upstream OBS bug, found by pobrn with AddressSanitizer and a removable USB camera and fixed in their open PR obsproject/obs-studio#13698 (opened 2026-07-25, approved by tytan652 the same day, not merged). There is no upstream issue for it. The code is unchanged upstream and in this fork.

Location

  • plugins/linux-pipewire/camera-portal.c lines 1032-1033, on_registry_global_remove_cb(): g_hash_table_iter_remove() removes the unplugged device from connection->devices, then blog() logs device_id, which is that entry's key.
  • Same file, line 1141: the table is created with bfree as its key destructor, so the key is freed by the remove, before it is logged. The key is the bstrdup() of the device's node name from line 1010.

Class

Use-after-free (read of a freed string, on the PipeWire thread).

How it is reached

  1. Add a "Video Capture Device (PipeWire)" source (any camera, any selected device).
  2. Unplug a camera that PipeWire lists.

Every unplug logs [pipewire-camera] Removed device ... from freed memory. Depending on the allocator, the log line shows a corrupted name or the old one; under AddressSanitizer OBS aborts, with the trace in the upstream PR: freed at line 1032, read at line 1033.

Reproduced headless here: the real camera portal code against a fake org.freedesktop.portal.Camera on a private D-Bus bus and a private PipeWire daemon (own runtime dir, no session manager, no devices), with a video source node in the test playing the camera. Unplugging it (destroying the node) logs Removed device XXXXXXXXXXXXXXX instead of the node's name when freed keys are overwritten, and AddressSanitizer reports the same heap-use-after-free as the upstream report.

Proposed fix and failing test

Fix: log the device before removing it from the table (pobrn's patch from obsproject/obs-studio#13698, ported with them as the author).

RED test (cmocka, test_pipewire_camera_unplug, Linux, private PipeWire and private D-Bus, X display for obs_startup(); skips without them): plugs the test camera in, waits for the camera portal to list it, unplugs it and checks the log line. The test links with --wrap so it sees the camera portal's device ids being freed: a freed id is overwritten with 'X' and, without AddressSanitizer, kept allocated until the end, so the failure is deterministic in a normal build. 1 of 2 cases fails today (the guard, that the camera is listed, passes); under AddressSanitizer the process aborts at the read.

Not part of this issue:

  • pipewire_camera_destroy() (libobs's destruction thread) and access_camera() change connection->sources without the PipeWire loop lock while the registry callbacks iterate it on the PipeWire thread; the device table is also read from the UI thread while the PipeWire thread changes it. Unloading the module destroys the device proxies without the loop lock (PipeWire warns impl_ext_end_proxy called from wrong context). Real, but narrow and not deterministic; no user report.
  • Startup crash in camera portal: on_registry_global_cb reads connection->obs_pw before it is assigned obsproject/obs-studio#13971 (TheMorpheus407, closed upstream): a startup race in which on_registry_global_cb() reads connection->obs_pw before it is assigned. The test holds the registry events until the camera portal's first roundtrip so that race cannot crash it.

Activity

  1. rdoupe commented on Oct 12, 2026

    @rdoupe
    CollaboratorAuthor

    Claiming: this issue.

    1. RED: test_pipewire_camera_unplug (1 of 2 failing without ASan; heap-use-after-free under ASan): the real camera portal code against a fake Camera portal and a private PipeWire; unplugging the camera node must log its real id, not freed memory.
    2. GREEN: log the id before removing it from the device table (pobrn's linux-pipewire: Fix use-after-free in log message obsproject/obs-studio#13698, unchanged, with pobrn as author).
      PR today.
  2. added a commit that references this issue on Oct 12, 2026
    a8ee5bf
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions