]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
core/namespace: allow using ProtectSubset=pid and ProtectHostname=true together
authorChristian Brauner <brauner@kernel.org>
Fri, 21 Jan 2022 12:08:19 +0000 (13:08 +0100)
committerChristian Brauner <brauner@kernel.org>
Mon, 24 Jan 2022 08:41:28 +0000 (09:41 +0100)
If a service requests both ProtectSubset=pid and ProtectHostname=true
then it will currently fail to start. The ProcSubset=pid option
instructs systemd to mount procfs for the service with subset=pid which
hides all entries other than /proc/<pid>. Consequently trying to
interact with the two files /proc/sys/kernel/{hostname,domainname}
covered by ProtectHostname=true will fail.

Fix this by only performing this check when ProtectSubset=pid is not
requested. Essentially ProtectSubset=pid implies/provides
ProtectHostname=true.

src/core/namespace.c

index ecbd23833c6d9308ed697fe3a45fb4eecec490d6..e55e9df702cda7d584ee38975eff8f1bf987a85d 100644 (file)
@@ -2157,14 +2157,19 @@ int setup_namespace(
                                 goto finish;
                 }
 
+                /* Note, if proc is mounted with subset=pid then neither of the
+                 * two paths will exist, i.e. they are implicitly protected by
+                 * the mount option. */
                 if (ns_info->protect_hostname) {
                         *(m++) = (MountEntry) {
                                 .path_const = "/proc/sys/kernel/hostname",
                                 .mode = READONLY,
+                                .ignore = ignore_protect_proc,
                         };
                         *(m++) = (MountEntry) {
                                 .path_const = "/proc/sys/kernel/domainname",
                                 .mode = READONLY,
+                                .ignore = ignore_protect_proc,
                         };
                 }