core: expose SUID/SGID restriction as new unit setting RestrictSUIDSGID=
This commit is contained in:
@@ -1404,6 +1404,7 @@ static bool context_has_no_new_privileges(const ExecContext *c) {
|
||||
return context_has_address_families(c) ||
|
||||
c->memory_deny_write_execute ||
|
||||
c->restrict_realtime ||
|
||||
c->restrict_suid_sgid ||
|
||||
exec_context_restrict_namespaces_set(c) ||
|
||||
c->protect_kernel_tunables ||
|
||||
c->protect_kernel_modules ||
|
||||
@@ -1509,6 +1510,19 @@ static int apply_restrict_realtime(const Unit* u, const ExecContext *c) {
|
||||
return seccomp_restrict_realtime();
|
||||
}
|
||||
|
||||
static int apply_restrict_suid_sgid(const Unit* u, const ExecContext *c) {
|
||||
assert(u);
|
||||
assert(c);
|
||||
|
||||
if (!c->restrict_suid_sgid)
|
||||
return 0;
|
||||
|
||||
if (skip_seccomp_unavailable(u, "RestrictSUIDSGID="))
|
||||
return 0;
|
||||
|
||||
return seccomp_restrict_suid_sgid();
|
||||
}
|
||||
|
||||
static int apply_protect_sysctl(const Unit *u, const ExecContext *c) {
|
||||
assert(u);
|
||||
assert(c);
|
||||
@@ -3567,6 +3581,12 @@ static int exec_child(
|
||||
return log_unit_error_errno(unit, r, "Failed to apply realtime restrictions: %m");
|
||||
}
|
||||
|
||||
r = apply_restrict_suid_sgid(unit, context);
|
||||
if (r < 0) {
|
||||
*exit_status = EXIT_SECCOMP;
|
||||
return log_unit_error_errno(unit, r, "Failed to apply SUID/SGID restrictions: %m");
|
||||
}
|
||||
|
||||
r = apply_restrict_namespaces(unit, context);
|
||||
if (r < 0) {
|
||||
*exit_status = EXIT_SECCOMP;
|
||||
@@ -4218,6 +4238,7 @@ void exec_context_dump(const ExecContext *c, FILE* f, const char *prefix) {
|
||||
"%sIgnoreSIGPIPE: %s\n"
|
||||
"%sMemoryDenyWriteExecute: %s\n"
|
||||
"%sRestrictRealtime: %s\n"
|
||||
"%sRestrictSUIDSGID: %s\n"
|
||||
"%sKeyringMode: %s\n"
|
||||
"%sProtectHostname: %s\n",
|
||||
prefix, c->umask,
|
||||
@@ -4237,6 +4258,7 @@ void exec_context_dump(const ExecContext *c, FILE* f, const char *prefix) {
|
||||
prefix, yes_no(c->ignore_sigpipe),
|
||||
prefix, yes_no(c->memory_deny_write_execute),
|
||||
prefix, yes_no(c->restrict_realtime),
|
||||
prefix, yes_no(c->restrict_suid_sgid),
|
||||
prefix, exec_keyring_mode_to_string(c->keyring_mode),
|
||||
prefix, yes_no(c->protect_hostname));
|
||||
|
||||
|
||||
Reference in New Issue
Block a user