X Tutup
Skip to content

Commit 1753d30

Browse files
topimiettinenyuwata
authored andcommitted
Revert "Mount all fs nosuid when NoNewPrivileges=yes"
This reverts commit d8e3c31. A poorly documented fact is that SELinux unfortunately uses nosuid mount flag to specify that also a fundamental feature of SELinux, domain transitions, must not be allowed either. While this could be mitigated case by case by changing the SELinux policy to use `nosuid_transition`, such mitigations would probably have to be added everywhere if systemd used automatic nosuid mount flags when `NoNewPrivileges=yes` would be implied. This isn't very desirable from SELinux policy point of view since also untrusted mounts in service's mount namespaces could start triggering domain transitions. Alternatively there could be directives to override this behavior globally or for each service (for example, new directives `SUIDPaths=`/`NoSUIDPaths=` or more generic mount flag applicators), but since there's little value of the commit by itself (setting NNP already disables most setuid functionality), it's simpler to revert the commit. Such new directives could be used to implement the original goal.
1 parent 2fbb5df commit 1753d30

File tree

4 files changed

+3
-39
lines changed

4 files changed

+3
-39
lines changed

man/systemd.exec.xml

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -675,10 +675,9 @@ CapabilityBoundingSet=~CAP_B CAP_C</programlisting>
675675
<varname>SystemCallArchitectures=</varname>,
676676
<varname>SystemCallFilter=</varname>, or
677677
<varname>SystemCallLog=</varname> are specified. Note that even if this setting is overridden
678-
by them, <command>systemctl show</command> shows the original value of this setting. In case the
679-
service will be run in a new mount namespace anyway, all file systems are mounted with MS_NOSUID
680-
flag. Also see <ulink url="https://www.kernel.org/doc/html/latest/userspace-api/no_new_privs.html">
681-
No New Privileges Flag</ulink>.</para></listitem>
678+
by them, <command>systemctl show</command> shows the original value of this setting. Also see
679+
<ulink url="https://www.kernel.org/doc/html/latest/userspace-api/no_new_privs.html">No New
680+
Privileges Flag</ulink>.</para></listitem>
682681
</varlistentry>
683682

684683
<varlistentry>

src/core/execute.c

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3189,8 +3189,6 @@ static int apply_mount_namespace(
31893189
.protect_proc = context->protect_proc,
31903190
.proc_subset = context->proc_subset,
31913191
.private_ipc = context->private_ipc || context->ipc_namespace_path,
3192-
/* If NNP is on, we can turn on MS_NOSUID, since it won't have any effect anymore. */
3193-
.mount_nosuid = context->no_new_privileges,
31943192
};
31953193
} else if (!context->dynamic_user && root_dir)
31963194
/*

src/core/namespace.c

Lines changed: 0 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -1464,27 +1464,6 @@ static int make_noexec(const MountEntry *m, char **deny_list, FILE *proc_self_mo
14641464
return 0;
14651465
}
14661466

1467-
static int make_nosuid(const MountEntry *m, FILE *proc_self_mountinfo) {
1468-
bool submounts = false;
1469-
int r = 0;
1470-
1471-
assert(m);
1472-
assert(proc_self_mountinfo);
1473-
1474-
submounts = !IN_SET(m->mode, EMPTY_DIR, TMPFS);
1475-
1476-
if (submounts)
1477-
r = bind_remount_recursive_with_mountinfo(mount_entry_path(m), MS_NOSUID, MS_NOSUID, NULL, proc_self_mountinfo);
1478-
else
1479-
r = bind_remount_one_with_mountinfo(mount_entry_path(m), MS_NOSUID, MS_NOSUID, proc_self_mountinfo);
1480-
if (r == -ENOENT && m->ignore)
1481-
return 0;
1482-
if (r < 0)
1483-
return log_debug_errno(r, "Failed to re-mount '%s'%s: %m", mount_entry_path(m),
1484-
submounts ? " and its submounts" : "");
1485-
return 0;
1486-
}
1487-
14881467
static bool namespace_info_mount_apivfs(const NamespaceInfo *ns_info) {
14891468
assert(ns_info);
14901469

@@ -1681,17 +1660,6 @@ static int apply_mounts(
16811660
}
16821661
}
16831662

1684-
/* Fourth round, flip the nosuid bits without a deny list. */
1685-
if (ns_info->mount_nosuid)
1686-
for (MountEntry *m = mounts; m < mounts + *n_mounts; ++m) {
1687-
r = make_nosuid(m, proc_self_mountinfo);
1688-
if (r < 0) {
1689-
if (error_path && mount_entry_path(m))
1690-
*error_path = strdup(mount_entry_path(m));
1691-
return r;
1692-
}
1693-
}
1694-
16951663
return 1;
16961664
}
16971665

src/core/namespace.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,6 @@ struct NamespaceInfo {
7474
bool mount_apivfs;
7575
bool protect_hostname;
7676
bool private_ipc;
77-
bool mount_nosuid;
7877
ProtectHome protect_home;
7978
ProtectSystem protect_system;
8079
ProtectProc protect_proc;

0 commit comments

Comments
 (0)
X Tutup