Skip to contentSkip to conversation

obexd: only run one instance at once

PATCH Superseded Andrew Sayers 3 participants 7 messages Apr 16, 2025 – Apr 18, 2025 Bluetooth drivers

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore
#0 lore raw

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.

---

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

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

PATCH 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 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.

Not really following the purpose of this one, it just in order to tell the packages to create this file? Is this specific to obexd lock file? If it is then we probably should have it somewhere under obexd folder.

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 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.

Not really following the purpose of this one, it just in order to tell the packages to create this file? Is this specific to obexd lock file? If it is then we probably should have it somewhere under obexd folder.

We need a directory for the lock file that's guaranteed to be world-writable, but in some distributions (e.g. Fedora), /run/lock is only writable by root. systemd-tmpfiles is systemd's solution to this problem - config files like this go in /usr/lib/tmpfiles.d and tell systemd to create files at boot time. In this case, patch 2/2 adds an instruction to create /run/lock/bluez.

Distro's need to install this in some distro-specific way, so I split it out into its own commit to make it easier for them to spot.  As that's a bit of extra work for them, I've proposed creating a more general file that can be reused in the (plausible but not probable) case another temporary file is required some time in the future. Happy to make the file obex-specific instead if that's better, in which case I'll call the temp directory /run/lock/obex.

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

#4 lore raw

PATCH 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 | 6 ++++++
 tools/bluez.tmpfiles.in   | 1 +
 2 files changed, 7 insertions(+)
obexd/src/obex.service.in +6 -0
index cf4d8c985..42d2185fb 100644
@@ -1,10 +1,16 @@
 [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
+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
#5 lore raw
Quoted 61 lines · 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 | 6 ++++++
  tools/bluez.tmpfiles.in   | 1 +
  2 files changed, 7 insertions(+)
obexd/src/obex.service.in +1 -0
index cf4d8c985..42d2185fb 100644
@@ -1,10 +1,16 @@
  [Unit]
  Description=Bluetooth OBEX service
+# This is a user-specific service, but bluetooth is a device-specific protocol.

obexd/src/obex.service.in line 13

Quoted 10 lines
obexd/src/obex.service.in +5 -0
+# 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
+ExecStartPre=touch /run/lock/bluez/obexd.lock
+ExecStopPost=rm -f /run/lock/bluez/obexd.lock

Recent experience with the equivalent FluidSynth patch shows that, if a package maintainer upgrades without adding the tmpfile, the above causes the service to fail in ways that users find confusing.

One solution would be to prefix a '-' to make systemd ignore errors:

+-ExecStartPre=touch /run/lock/bluez/obexd.lock
+-ExecStopPost=rm -f /run/lock/bluez/obexd.lock

That would reduce a missing tmpfile from a crash to just log spam. But if the tmpfile gains a more important use case in future, you might uncover bugs in distro's that never installed the tmpfile.

An alternative would be to add a comment like:

+# 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

That wouldn't fix the problem, but would make it easier to debug, and hopefully nudge users to file a useful report with their distro.

Quoted 9 lines
obexd/src/obex.service.in +0 -0
  [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
#6 lore raw

Hi Andrew,

Quoted 94 lines · Andrew Sayers
Quoted 61 lines · 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 | 6 ++++++
  tools/bluez.tmpfiles.in   | 1 +
  2 files changed, 7 insertions(+)
obexd/src/obex.service.in +1 -0
index cf4d8c985..42d2185fb 100644
@@ -1,10 +1,16 @@
  [Unit]
  Description=Bluetooth OBEX service
+# This is a user-specific service, but bluetooth is a device-specific protocol.

obexd/src/obex.service.in line 13

Quoted 10 lines
obexd/src/obex.service.in +5 -0
+# 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
+ExecStartPre=touch /run/lock/bluez/obexd.lock
+ExecStopPost=rm -f /run/lock/bluez/obexd.lock

Recent experience with the equivalent FluidSynth patch shows that, if a package maintainer upgrades without adding the tmpfile, the above causes the service to fail in ways that users find confusing.

One solution would be to prefix a '-' to make systemd ignore errors:

+-ExecStartPre=touch /run/lock/bluez/obexd.lock
+-ExecStopPost=rm -f /run/lock/bluez/obexd.lock

That would reduce a missing tmpfile from a crash to just log spam. But if the tmpfile gains a more important use case in future, you might uncover bugs in distro's that never installed the tmpfile.

An alternative would be to add a comment like:

obexd/src/obex.service.in +4 -0
+# 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
Quoted 2 lines

That wouldn't fix the problem, but would make it easier to debug, and hopefully nudge users to file a useful report with their distro.

Yeah, let's do that, can you send an update to the series?

Quoted 9 lines
Quoted 9 lines
obexd/src/obex.service.in +0 -0
  [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
Luiz Augusto von Dentz