Skip to contentSkip to conversation

build: Always define confdir and statedir

PATCH Applied Bastien Nocera 4 participants 11 messages Jan 26, 2022 – Apr 12, 2022

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH 1/4 build: Always define confdir and statedir

As we will need those paths to lock down on them.

---
 Makefile.am | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)
Makefile.am +3 -3
index e391d7ae8..2ba25e687 100644
@@ -28,14 +28,14 @@ AM_CFLAGS = $(MISC_CFLAGS) $(WARNING_CFLAGS) $(UDEV_CFLAGS) $(LIBEBOOK_CFLAGS) \
 				$(LIBEDATASERVER_CFLAGS) $(ell_cflags)
 AM_LDFLAGS = $(MISC_LDFLAGS)
 
+confdir = $(sysconfdir)/bluetooth
+statedir = $(localstatedir)/lib/bluetooth
+
 if DATAFILES
 dbusdir = $(DBUS_CONFDIR)/dbus-1/system.d
 dbus_DATA = src/bluetooth.conf
 
-confdir = $(sysconfdir)/bluetooth
 conf_DATA =
-
-statedir = $(localstatedir)/lib/bluetooth
 state_DATA =
 endif
 
Signature · 1 line
2.34.1
#1 lore raw

PATCH 2/4 systemd: Add PrivateTmp and NoNewPrivileges options

From: Craig Andrews <[email protected]>

PrivateTmp makes bluetoothd's /tmp and /var/tmp be inside a different namespace. This is useful to secure access to temporary files of the process.

NoNewPrivileges ensures that service process and all its children can never gain new privileges through execve(), lowering the risk of possible privilege escalations.

---
 src/bluetooth.service.in | 6 ++++++
 1 file changed, 6 insertions(+)
src/bluetooth.service.in +6 -0
index f9faaa452..7c2f60bb4 100644
@@ -12,8 +12,14 @@ NotifyAccess=main
 #Restart=on-failure
 CapabilityBoundingSet=CAP_NET_ADMIN CAP_NET_BIND_SERVICE
 LimitNPROC=1
+
+# Filesystem lockdown
 ProtectHome=true
 ProtectSystem=full
+PrivateTmp=true
+
+# Privilege escalation
+NoNewPrivileges=true
 
 [Install]
 WantedBy=bluetooth.target
Signature · 1 line
2.34.1
#2 lore raw

PATCH 3/4 systemd: Add more filesystem lockdown

In reply to Bastien Nocera

We can only access the configuration file as read-only and read-write to the Bluetooth cache directory and sub-directories.

---
 Makefile.am              | 3 +++
 src/bluetooth.service.in | 4 ++++
 2 files changed, 7 insertions(+)
Makefile.am +3 -0
index 2ba25e687..82125c482 100644
@@ -622,6 +622,9 @@ MAINTAINERCLEANFILES = Makefile.in \
 
 SED_PROCESS = $(AM_V_GEN)$(MKDIR_P) $(dir $@) && \
 		$(SED) -e 's,@pkglibexecdir\@,$(pkglibexecdir),g' \
+		       -e 's,@libexecdir\@,$(libexecdir),g' \
+		       -e 's,@statedir\@,$(statedir),g' \
+		       -e 's,@confdir\@,$(confdir),g' \
 		< $< > $@
 
 if RUN_RST2MAN
src/bluetooth.service.in +4 -0
index 7c2f60bb4..4daedef2a 100644
@@ -17,6 +17,10 @@ LimitNPROC=1
 ProtectHome=true
 ProtectSystem=full
 PrivateTmp=true
+ProtectKernelTunables=true
+ProtectControlGroups=true
+ReadWritePaths=@statedir@
+ReadOnlyPaths=@confdir@
 
 # Privilege escalation
 NoNewPrivileges=true
Signature · 1 line
2.34.1
#3 lore raw

PATCH 4/4 systemd: More lockdown

In reply to Bastien Nocera

bluetoothd does not need to execute mapped memory, or real-time access, so block those.

---
 src/bluetooth.service.in | 6 ++++++
 1 file changed, 6 insertions(+)
src/bluetooth.service.in +6 -0
index 4daedef2a..f18801866 100644
@@ -22,9 +22,15 @@ ProtectControlGroups=true
 ReadWritePaths=@statedir@
 ReadOnlyPaths=@confdir@
 
+# Execute Mappings
+MemoryDenyWriteExecute=true
+
 # Privilege escalation
 NoNewPrivileges=true
 
+# Real-time
+RestrictRealtime=true
+
 [Install]
 WantedBy=bluetooth.target
 Alias=dbus-org.bluez.service
Signature · 1 line
2.34.1
#4 lore raw
In reply to Bastien Nocera

Some patches from 2017 to use systemd lockdown. They've been used for 5 years by Fedora and RHEL.

Cheers

Quoted 29 lines · Bastien Nocera

As we will need those paths to lock down on them.
---
 Makefile.am | 6 +++---

 1 file changed, 3 insertions(+), 3 deletions(-)
Makefile.am +0 -0
index e391d7ae8..2ba25e687 100644
@@ -28,14 +28,14 @@ AM_CFLAGS = $(MISC_CFLAGS) $(WARNING_CFLAGS)
 $(UDEV_CFLAGS) $(LIBEBOOK_CFLAGS) \
                                 $(LIBEDATASERVER_CFLAGS)
 $(ell_cflags)
  AM_LDFLAGS = $(MISC_LDFLAGS)

Makefile.am +3 -0
+confdir = $(sysconfdir)/bluetooth
+statedir = $(localstatedir)/lib/bluetooth
+

 if DATAFILES
 dbusdir = $(DBUS_CONFDIR)/dbus-1/system.d
 dbus_DATA = src/bluetooth.conf

-confdir = $(sysconfdir)/bluetooth
 conf_DATA =

Makefile.am +0 -2
-
-statedir = $(localstatedir)/lib/bluetooth

 state_DATA =
 endif

maintainer
#5 lore raw

Hi Bastien,

Quoted 25 lines

Some patches from 2017 to use systemd lockdown. They've been used for 5 years by Fedora and RHEL.

Quoted 22 lines

As we will need those paths to lock down on them.

---
 Makefile.am | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)
Makefile.am +3 -0
index e391d7ae8..2ba25e687 100644
@@ -28,14 +28,14 @@ AM_CFLAGS = $(MISC_CFLAGS) $(WARNING_CFLAGS)
 $(UDEV_CFLAGS) $(LIBEBOOK_CFLAGS) \
                                $(LIBEDATASERVER_CFLAGS)
 $(ell_cflags)
 AM_LDFLAGS = $(MISC_LDFLAGS)
 
+confdir = $(sysconfdir)/bluetooth
+statedir = $(localstatedir)/lib/bluetooth
+
 if DATAFILES
 dbusdir = $(DBUS_CONFDIR)/dbus-1/system.d
 dbus_DATA = src/bluetooth.conf
 
Quoted 7 lines
Quoted 7 lines
Makefile.am +0 -3
-confdir = $(sysconfdir)/bluetooth
 conf_DATA =
-
-statedir = $(localstatedir)/lib/bluetooth
 state_DATA =

endif

seems I missed that one. Can you please be more specific what this change does.

Regards

Marcel

#6 lore raw
Quoted 30 lines · Marcel Holtmann

Hi Bastien,

Quoted 28 lines

Some patches from 2017 to use systemd lockdown. They've been used for 5
years by Fedora and RHEL.

Quoted 24 lines

As we will need those paths to lock down on them.
---
 Makefile.am | 6 +++---

 1 file changed, 3 insertions(+), 3 deletions(-)
Makefile.am +0 -0
index e391d7ae8..2ba25e687 100644
@@ -28,14 +28,14 @@ AM_CFLAGS = $(MISC_CFLAGS) $(WARNING_CFLAGS)
 $(UDEV_CFLAGS) $(LIBEBOOK_CFLAGS) \
                                 $(LIBEDATASERVER_CFLAGS)
 $(ell_cflags)
  AM_LDFLAGS = $(MISC_LDFLAGS)

Makefile.am +3 -0
+confdir = $(sysconfdir)/bluetooth
+statedir = $(localstatedir)/lib/bluetooth
+

 if DATAFILES
 dbusdir = $(DBUS_CONFDIR)/dbus-1/system.d
 dbus_DATA = src/bluetooth.conf

-confdir = $(sysconfdir)/bluetooth
 conf_DATA =

Quoted 8 lines
Quoted 5 lines
Quoted 5 lines
Makefile.am +0 -2
-
-statedir = $(localstatedir)/lib/bluetooth

 state_DATA =
 endif

seems I missed that one. Can you please be more specific what this change does.

This change specifically? Check the next patches in the series, and you'll see pretty quickly.

For the rest of the patchset, check this man page for details on each of the directives:
https://www.freedesktop.org/software/systemd/man/systemd.exec.html#Security

There's a fair amount of other directives we could use on top of those ones, but we can add them iteratively (and it makes bisecting easier, in case we forget about a particular use case).

Cheers

#7 lore raw
Quoted 11 lines · Bastien Nocera

This change specifically? Check the next patches in the series, and you'll see pretty quickly.

For the rest of the patchset, check this man page for details on each of the directives:
https://www.freedesktop.org/software/systemd/man/systemd.exec.html#Security

There's a fair amount of other directives we could use on top of those
ones, but we can add them iteratively (and it makes bisecting easier, in case we forget about a particular use case).

Did you have any more questions about this patchset?

#8 lore raw

Hi Bastien,

Quoted 9 lines · Bastien Nocera
Quoted 7 lines · Bastien Nocera

This change specifically? Check the next patches in the series, and you'll see pretty quickly.

For the rest of the patchset, check this man page for details on each of the directives:
https://www.freedesktop.org/software/systemd/man/systemd.exec.html#Security

Quoted 6 lines
Quoted 4 lines

There's a fair amount of other directives we could use on top of those
ones, but we can add them iteratively (and it makes bisecting easier, in case we forget about a particular use case).

Did you have any more questions about this patchset?

Looks like we have some problems with these changes:

https://github.com/bluez/bluez/issues/329

Signature · 1 line
Luiz Augusto von Dentz
#9 lore raw
In reply to Bastien Nocera

This is automated email and please do not reply to this email!

Dear submitter,

Thank you for submitting the patches to the linux bluetooth mailing list. This is a CI test results with your patch series:
PW Link:https://patchwork.kernel.org/project/bluetooth/list/?series=608628

---Test result---

Test Summary:

CheckPatch                    PASS      5.68 seconds
GitLint                       PASS      3.84 seconds
Prep - Setup ELL              PASS      41.84 seconds
Build - Prep                  PASS      0.71 seconds
Build - Configure             PASS      8.38 seconds
Build - Make                  PASS      1292.67 seconds
Make Check                    PASS      11.33 seconds
Make Check w/Valgrind         PASS      448.95 seconds
Make Distcheck                PASS      231.67 seconds
Build w/ext ELL - Configure   PASS      8.74 seconds
Build w/ext ELL - Make        PASS      1305.94 seconds
Incremental Build with patchesPASS      5303.63 seconds

---
Regards,
Linux Bluetooth

maintainer Applied
#10 lore raw

Hi Bastien,

Quoted 27 lines · On Wed, Jan 26, 2022 at 1:28 PM <[email protected]> wrote:

This is automated email and please do not reply to this email!

Dear submitter,

Thank you for submitting the patches to the linux bluetooth mailing list. This is a CI test results with your patch series:
PW Link:https://patchwork.kernel.org/project/bluetooth/list/?series=608628

---Test result---

Test Summary:

CheckPatch                    PASS      5.68 seconds
GitLint                       PASS      3.84 seconds
Prep - Setup ELL              PASS      41.84 seconds
Build - Prep                  PASS      0.71 seconds
Build - Configure             PASS      8.38 seconds
Build - Make                  PASS      1292.67 seconds
Make Check                    PASS      11.33 seconds
Make Check w/Valgrind         PASS      448.95 seconds
Make Distcheck                PASS      231.67 seconds
Build w/ext ELL - Configure   PASS      8.74 seconds
Build w/ext ELL - Make        PASS      1305.94 seconds
Incremental Build with patchesPASS      5303.63 seconds
Quoted 3 lines

---
Regards,
Linux Bluetooth

Applied, thanks.

Signature · 1 line
Luiz Augusto von Dentz