Skip to contentSkip to conversation

obexd: only run one instance at once

PATCH In review Andrew Sayers 3 participants 8 messages Apr 18, 2025 Bluetooth drivers

lore
Share & tools
lore
#0 lore raw

v2 cover obexd: only run one instance at once

Obex is a device-oriented protocol, so only one instance can run per device. But Linux file security is user-oriented, so obexd should be a user service. Tell systemd to only run this service for the first non-system user to log in.

This series causes systemd not to run obexd if it would just generate errors, after adding a new bluez.tmpfiles file that distributors will need to install.

---

V1 -> V2 add a hint in obex.service.in about installing the tmpfile
(recommended by Luiz Augusto von Dentz)

Andrew Sayers (2):
build: add bluez.tmpfiles
obexd: only run one instance at once

 .gitignore                | 1 +
 configure.ac              | 1 +
 obexd/src/obex.service.in | 9 +++++++++
 tools/bluez.tmpfiles.in   | 1 +
 4 files changed, 12 insertions(+)
#1 lore raw

PATCH v2 1/2 build: add bluez.tmpfiles

Systemd tmpfiles ensure the status of particular files. Add a file that bluez can use in future.

Distributors should install the new "tools/bluez.tmpfiles" file, e.g. by moving it to debian/bluez.tmpfile or using Fedora's %{_tmpfilesdir} variable.

---
 .gitignore              | 1 +
 configure.ac            | 1 +
 tools/bluez.tmpfiles.in | 0
 3 files changed, 2 insertions(+)
 create mode 100644 tools/bluez.tmpfiles.in
.gitignore +1 -0
index 108c3b820..e4431443f 100644
@@ -157,6 +157,7 @@ obexd/src/obex.service
 obexd/src/org.bluez.obex.service
 tools/obex-client-tool
 tools/obex-server-tool
+tools/bluez.tmpfiles
 unit/test-gobex
 unit/test-gobex-apparam
 unit/test-gobex-header
configure.ac +1 -0
index 1e089aaa7..4ebd513d6 100644
@@ -530,5 +530,6 @@ AC_CONFIG_FILES(
 	src/bluetooth.service
 	tools/bluetooth-logger.service
 	tools/mpris-proxy.service
+	tools/bluez.tmpfiles
 )
 AC_OUTPUT
tools/bluez.tmpfiles.in new file +0 -0
new file mode 100644
index 000000000..e69de29bb
Signature · 1 line
2.49.0
#2 lore raw

Re: [PATCH BlueZ v2 1/2] build: add bluez.tmpfiles

Hi Andrew,

Quoted 7 lines · Andrew Sayers

Systemd tmpfiles ensure the status of particular files. Add a file that bluez can use in future.

Distributors should install the new "tools/bluez.tmpfiles" file, e.g. by moving it to debian/bluez.tmpfile or using Fedora's %{_tmpfilesdir} variable.

I thought we would not be adding this anymore with the addition to '-' prefix and the added comments that should be left to distros to figure it out.

Quoted 38 lines
---
 .gitignore              | 1 +
 configure.ac            | 1 +
 tools/bluez.tmpfiles.in | 0
 3 files changed, 2 insertions(+)
 create mode 100644 tools/bluez.tmpfiles.in
.gitignore +1 -0
index 108c3b820..e4431443f 100644
@@ -157,6 +157,7 @@ obexd/src/obex.service
 obexd/src/org.bluez.obex.service
 tools/obex-client-tool
 tools/obex-server-tool
+tools/bluez.tmpfiles
 unit/test-gobex
 unit/test-gobex-apparam
 unit/test-gobex-header
configure.ac +1 -0
index 1e089aaa7..4ebd513d6 100644
@@ -530,5 +530,6 @@ AC_CONFIG_FILES(
        src/bluetooth.service
        tools/bluetooth-logger.service
        tools/mpris-proxy.service
+       tools/bluez.tmpfiles
 )
 AC_OUTPUT
tools/bluez.tmpfiles.in new file +0 -1
new file mode 100644
index 000000000..e69de29bb
--

2.49.0

Signature · 1 line
Luiz Augusto von Dentz
#3 lore raw

Re: [PATCH BlueZ v2 1/2] build: add bluez.tmpfiles

Quoted 7 lines · Luiz Augusto von Dentz

Hi Andrew,

Quoted 3 lines · Andrew Sayers

Systemd tmpfiles ensure the status of particular files. Add a file that bluez can use in future.

Quoted 6 lines
Quoted 3 lines

Distributors should install the new "tools/bluez.tmpfiles" file, e.g. by moving it to debian/bluez.tmpfile or using Fedora's %{_tmpfilesdir} variable.

I thought we would not be adding this anymore with the addition to '-' prefix and the added comments that should be left to distros to figure it out.

Ah sorry, I thought you meant to add the comment *instead of* the '-'. Leaving it to distro's feels a bit dangerous, but Pauli Virtanen's idea seems like a better approach anyway (thanks Pauli!).

I'll take a look at that and should be back with a v3 next week.

Quoted 40 lines
Quoted 39 lines
---
  .gitignore              | 1 +
  configure.ac            | 1 +
  tools/bluez.tmpfiles.in | 0
  3 files changed, 2 insertions(+)

create mode 100644 tools/bluez.tmpfiles.in

.gitignore +1 -0
index 108c3b820..e4431443f 100644
@@ -157,6 +157,7 @@ obexd/src/obex.service
  obexd/src/org.bluez.obex.service
  tools/obex-client-tool
  tools/obex-server-tool
+tools/bluez.tmpfiles
  unit/test-gobex
  unit/test-gobex-apparam
  unit/test-gobex-header
configure.ac +1 -0
index 1e089aaa7..4ebd513d6 100644
@@ -530,5 +530,6 @@ AC_CONFIG_FILES(
         src/bluetooth.service
         tools/bluetooth-logger.service
         tools/mpris-proxy.service
+       tools/bluez.tmpfiles
  )
  AC_OUTPUT
tools/bluez.tmpfiles.in new file +0 -1
new file mode 100644
index 000000000..e69de29bb
--

2.49.0

#4 lore raw

Re: [PATCH BlueZ v2 1/2] build: add bluez.tmpfiles

pe, 2025-04-18 kello 17:40 +0100, Andrew Sayers kirjoitti:

Quoted 15 lines · Luiz Augusto von Dentz
Quoted 7 lines

Hi Andrew,

Quoted 3 lines · Andrew Sayers

Systemd tmpfiles ensure the status of particular files. Add a file that bluez can use in future.

Quoted 6 lines
Quoted 3 lines

Distributors should install the new "tools/bluez.tmpfiles" file, e.g. by moving it to debian/bluez.tmpfile or using Fedora's %{_tmpfilesdir} variable.

I thought we would not be adding this anymore with the addition to '-' prefix and the added comments that should be left to distros to figure it out.

Quoted 5 lines

Ah sorry, I thought you meant to add the comment *instead of* the '-'. Leaving it to distro's feels a bit dangerous, but Pauli Virtanen's idea seems like a better approach anyway (thanks Pauli!).

I'll take a look at that and should be back with a v3 next week.

Note though that the seat state monitoring also has some drawbacks, e.g. ssh logins are not considered "active" so for headless / system- wide obexd configurations you'd probably want some command-line or configuration option to disable the feature.

Quoted 39 lines
Quoted 39 lines
Quoted 38 lines
---
  .gitignore              | 1 +
  configure.ac            | 1 +
  tools/bluez.tmpfiles.in | 0
  3 files changed, 2 insertions(+)

create mode 100644 tools/bluez.tmpfiles.in

.gitignore +1 -0
index 108c3b820..e4431443f 100644
@@ -157,6 +157,7 @@ obexd/src/obex.service
  obexd/src/org.bluez.obex.service
  tools/obex-client-tool
  tools/obex-server-tool
+tools/bluez.tmpfiles
  unit/test-gobex
  unit/test-gobex-apparam
  unit/test-gobex-header
configure.ac +1 -0
index 1e089aaa7..4ebd513d6 100644
@@ -530,5 +530,6 @@ AC_CONFIG_FILES(
         src/bluetooth.service
         tools/bluetooth-logger.service
         tools/mpris-proxy.service
+       tools/bluez.tmpfiles
  )
  AC_OUTPUT
tools/bluez.tmpfiles.in new file +0 -1
new file mode 100644
index 000000000..e69de29bb
--

2.49.0

Signature · 1 line
Pauli Virtanen
#5 lore raw

Re: [PATCH BlueZ v2 1/2] build: add bluez.tmpfiles

Hi Pauli,

Quoted 21 lines · Pauli Virtanen

pe, 2025-04-18 kello 17:40 +0100, Andrew Sayers kirjoitti:

Quoted 19 lines · Luiz Augusto von Dentz
Quoted 7 lines

Hi Andrew,

Quoted 3 lines · Andrew Sayers

Systemd tmpfiles ensure the status of particular files. Add a file that bluez can use in future.

Quoted 6 lines
Quoted 3 lines

Distributors should install the new "tools/bluez.tmpfiles" file, e.g. by moving it to debian/bluez.tmpfile or using Fedora's %{_tmpfilesdir} variable.

I thought we would not be adding this anymore with the addition to '-' prefix and the added comments that should be left to distros to figure it out.

Ah sorry, I thought you meant to add the comment *instead of* the '-'. Leaving it to distro's feels a bit dangerous, but Pauli Virtanen's idea seems like a better approach anyway (thanks Pauli!).

Quoted 6 lines
Quoted 1 line

I'll take a look at that and should be back with a v3 next week.

Note though that the seat state monitoring also has some drawbacks, e.g. ssh logins are not considered "active" so for headless / system- wide obexd configurations you'd probably want some command-line or configuration option to disable the feature.

I wonder if it wouldn't make sense to add seat options directly into the systemd service file so it does the monitoring by itself rather than each component having to do it on its own.

Quoted 42 lines
Quoted 31 lines
Quoted 31 lines
Quoted 31 lines
---
  .gitignore              | 1 +
  configure.ac            | 1 +
  tools/bluez.tmpfiles.in | 0
  3 files changed, 2 insertions(+)

create mode 100644 tools/bluez.tmpfiles.in

.gitignore +1 -0
index 108c3b820..e4431443f 100644
@@ -157,6 +157,7 @@ obexd/src/obex.service
  obexd/src/org.bluez.obex.service
  tools/obex-client-tool
  tools/obex-server-tool
+tools/bluez.tmpfiles
  unit/test-gobex
  unit/test-gobex-apparam
  unit/test-gobex-header
configure.ac +1 -0
index 1e089aaa7..4ebd513d6 100644
@@ -530,5 +530,6 @@ AC_CONFIG_FILES(
         src/bluetooth.service
         tools/bluetooth-logger.service
         tools/mpris-proxy.service
+       tools/bluez.tmpfiles
  )
  AC_OUTPUT
Quoted 8 lines
Quoted 8 lines
Quoted 7 lines
tools/bluez.tmpfiles.in new file +0 -1
new file mode 100644
index 000000000..e69de29bb
--

2.49.0

--
Pauli Virtanen

Signature · 1 line
Luiz Augusto von Dentz
#6 lore raw

PATCH v2 2/2 obexd: only run one instance at once

In reply to Andrew Sayers

Obex is a device-oriented protocol, so only one instance can run per device. But Linux file security is user-oriented, so obexd should be a user service. Tell systemd to only run this service for the first non-system user to log in.

Without this patch, errors like the following will occur if you use the "switch account" feature of your desktop environment, then log in with another account:

Mar 26 15:20:38 andrews-2024-laptop bluetoothd[873]: src/profile.c:register_profile() :1.2016 tried to register 00001133-0000-1000-8000-00805f9b34fb which is already registered
Mar 26 15:20:38 andrews-2024-laptop bluetoothd[873]: src/profile.c:register_profile() :1.2016 tried to register 00001132-0000-1000-8000-00805f9b34fb which is already registered
Mar 26 15:20:38 andrews-2024-laptop bluetoothd[873]: src/profile.c:register_profile() :1.2016 tried to register 0000112f-0000-1000-8000-00805f9b34fb which is already registered
Mar 26 15:20:38 andrews-2024-laptop bluetoothd[873]: src/profile.c:register_profile() :1.2016 tried to register 00001104-0000-1000-8000-00805f9b34fb which is already registered
Mar 26 15:20:38 andrews-2024-laptop bluetoothd[873]: src/profile.c:register_profile() :1.2016 tried to register 00001106-0000-1000-8000-00805f9b34fb which is already registered
Mar 26 15:20:38 andrews-2024-laptop bluetoothd[873]: src/profile.c:register_profile() :1.2016 tried to register 00001105-0000-1000-8000-00805f9b34fb which is already registered
Mar 26 15:20:38 andrews-2024-laptop bluetoothd[873]: src/profile.c:register_profile() :1.2016 tried to register 00005005-0000-1000-8000-0002ee000001 which is already registered
Mar 26 15:20:38 andrews-2024-laptop obexd[1795560]: bluetooth: RequestProfile error: org.bluez.Error.NotPermitted, UUID already registered
Mar 26 15:20:38 andrews-2024-laptop obexd[1795560]: bluetooth: RequestProfile error: org.bluez.Error.NotPermitted, UUID already registered
Mar 26 15:20:38 andrews-2024-laptop obexd[1795560]: bluetooth: RequestProfile error: org.bluez.Error.NotPermitted, UUID already registered
Mar 26 15:20:38 andrews-2024-laptop obexd[1795560]: bluetooth: RequestProfile error: org.bluez.Error.NotPermitted, UUID already registered
Mar 26 15:20:38 andrews-2024-laptop obexd[1795560]: bluetooth: RequestProfile error: org.bluez.Error.NotPermitted, UUID already registered
Mar 26 15:20:38 andrews-2024-laptop obexd[1795560]: bluetooth: RequestProfile error: org.bluez.Error.NotPermitted, UUID already registered
Mar 26 15:20:38 andrews-2024-laptop obexd[1795560]: bluetooth: RequestProfile error: org.bluez.Error.NotPermitted, UUID already registered

The above errors indicate the service completely failed to register, so this does not change the user experience beyond removing the above messages. Specifically, the first user who logs in to a multi-user system still retains obex access to devices paired by users who log in later.

This is based on a pair of recent changes to the FluidSynth daemon:

https://github.com/FluidSynth/fluidsynth/pull/1491
https://github.com/FluidSynth/fluidsynth/pull/1528

This was discussed in the comments for a GitHub advisory available at
https://github.com/bluez/bluez/security/advisories/GHSA-fpgq-25xf-jcwv
but comments are not shown in the published version of the advisory. To summarise the useful conversation with Luiz Augusto von Dentz:

Obex requires access to the user's home directory, so an attacker can only transfer files between locations the user controls. That may be a problem if the user who runs obexd is different to the user who paired the device, but solving that would involve pairing per-user, which causes other problems. Bluetooth connections can be initiated by peripherals, so switching user could trigger re-pairing and cause the original user to lose access to the device. This may seem reasonable for file access, but for example users would likely object to constantly re-pairing their Bluetooth keyboard.

---
 obexd/src/obex.service.in | 9 +++++++++
 tools/bluez.tmpfiles.in   | 1 +
 2 files changed, 10 insertions(+)
obexd/src/obex.service.in +9 -0
index cf4d8c985..f269bc513 100644
@@ -1,10 +1,19 @@
 [Unit]
 Description=Bluetooth OBEX service
+# This is a user-specific service, but bluetooth is a device-specific protocol.
+# Only run one instance at a time, even if multiple users log in at once:
+ConditionPathExists=!/run/lock/bluez/obexd.lock
+ConditionUser=!@system
 
 [Service]
 Type=dbus
 BusName=org.bluez.obex
 ExecStart=@PKGLIBEXECDIR@/obexd
 
+# If the service fails on the following line, please ensure
+# the bluez tmpfile has been installed in /usr/lib/tmpfiles.d/
+ExecStartPre=touch /run/lock/bluez/obexd.lock
+ExecStopPost=rm -f /run/lock/bluez/obexd.lock
+
 [Install]
 Alias=dbus-org.bluez.obex.service
tools/bluez.tmpfiles.in +1 -0
index e69de29bb..05b8ad65c 100644
@@ -0,0 +1 @@
+d /run/lock/bluez 0777 root root
Signature · 1 line
2.49.0
#7 lore raw
In reply to Andrew Sayers

Hi,

pe, 2025-04-18 kello 16:30 +0100, Andrew Sayers kirjoitti:

Quoted 3 lines

Obex is a device-oriented protocol, so only one instance can run per device. But Linux file security is user-oriented, so obexd should be a user service. Tell systemd to only run this service for the first non-system user to log in.

Sound servers have this same problem. As there's no concept of multiple users in BlueZ, the solution there is to monitor systemd/elogind seat state, and detach the user process from bluetoothd if the seat is inactive.

How to do the monitoring, see:
https://gitlab.freedesktop.org/pipewire/wireplumber/-/blob/master/modules/module-logind.c#L52

Quoted 19 lines

This series causes systemd not to run obexd if it would just generate errors, after adding a new bluez.tmpfiles file that distributors will need to install.

---

V1 -> V2 add a hint in obex.service.in about installing the tmpfile
(recommended by Luiz Augusto von Dentz)

Andrew Sayers (2):
build: add bluez.tmpfiles
obexd: only run one instance at once

 .gitignore                | 1 +
 configure.ac              | 1 +
 obexd/src/obex.service.in | 9 +++++++++
 tools/bluez.tmpfiles.in   | 1 +
 4 files changed, 12 insertions(+)