obexd: only run one instance at once
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(+)
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
@@ -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
@@ -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
Signature · 1 line
2.49.0
Luiz Augusto von Dentz
maintainerRe: [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 todebian/bluez.tmpfileor 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
Signed-off-by Andrew Sayers <[email protected]>--- .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@@ -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-headerconfigure.ac +1
-0@@ -530,5 +530,6 @@ AC_CONFIG_FILES( src/bluetooth.service tools/bluetooth-logger.service tools/mpris-proxy.service + tools/bluez.tmpfiles ) AC_OUTPUTtools/bluez.tmpfiles.in new file +0
-1--2.49.0
Signature · 1 line
Luiz Augusto von Dentz
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 todebian/bluez.tmpfileor 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
Signed-off-by Andrew Sayers <[email protected]>--- .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@@ -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-headerconfigure.ac +1
-0@@ -530,5 +530,6 @@ AC_CONFIG_FILES( src/bluetooth.service tools/bluetooth-logger.service tools/mpris-proxy.service + tools/bluez.tmpfiles ) AC_OUTPUTtools/bluez.tmpfiles.in new file +0
-1--2.49.0
PATCH 2/2 obexd: only run one instance at once
In reply to Andrew SayersObex 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
@@ -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
@@ -0,0 +1 @@ +d /run/lock/bluez 0777 root root
Signature · 1 line
2.49.0
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 registeredThe 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/1528This 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.
Signed-off-by Andrew Sayers <[email protected]>--- obexd/src/obex.service.in | 6 ++++++ tools/bluez.tmpfiles.in | 1 + 2 files changed, 7 insertions(+)obexd/src/obex.service.in +1
-0@@ -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.servicetools/bluez.tmpfiles.in +1
-0@@ -0,0 +1 @@ +d /run/lock/bluez 0777 root root
Luiz Augusto von Dentz
maintainerHi 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 registeredThe 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/1528This 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.
Signed-off-by Andrew Sayers <[email protected]>--- obexd/src/obex.service.in | 6 ++++++ tools/bluez.tmpfiles.in | 1 + 2 files changed, 7 insertions(+)obexd/src/obex.service.in +1
-0@@ -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.lockRecent 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.lockThat 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.servicetools/bluez.tmpfiles.in +1
-0@@ -0,0 +1 @@ +d /run/lock/bluez 0777 root root
Signature · 1 line
Luiz Augusto von Dentz