smack: Add DefaultSmackProcessLabel to user.conf and system.conf

DefaultSmackProcessLabel tells systemd what label to assign to its child
process in case SmackProcessLabel is not set in the service file. By
default, when DefaultSmackProcessLabel is not set child processes inherit
label from systemd.

If DefaultSmackProcessLabel is set to "/" (which is an invalid character
for a SMACK label) the DEFAULT_SMACK_PROCESS_LABEL set during compilation
is ignored and systemd act as if the option was unset.
This commit is contained in:
Łukasz Stelmach
2022-07-12 22:47:32 +01:00
committed by Luca Boccassi
parent 8880c3be82
commit aa5ae9711e
9 changed files with 53 additions and 6 deletions
+4 -6
View File
@@ -3240,6 +3240,7 @@ static int setup_credentials(
#if ENABLE_SMACK
static int setup_smack(
const Manager *manager,
const ExecContext *context,
int executable_fd) {
int r;
@@ -3251,20 +3252,17 @@ static int setup_smack(
r = mac_smack_apply_pid(0, context->smack_process_label);
if (r < 0)
return r;
}
#ifdef SMACK_DEFAULT_PROCESS_LABEL
else {
} else if (manager->default_smack_process_label) {
_cleanup_free_ char *exec_label = NULL;
r = mac_smack_read_fd(executable_fd, SMACK_ATTR_EXEC, &exec_label);
if (r < 0 && !IN_SET(r, -ENODATA, -EOPNOTSUPP))
return r;
r = mac_smack_apply_pid(0, exec_label ? : SMACK_DEFAULT_PROCESS_LABEL);
r = mac_smack_apply_pid(0, exec_label ? : manager->default_smack_process_label);
if (r < 0)
return r;
}
#endif
return 0;
}
@@ -4853,7 +4851,7 @@ static int exec_child(
/* LSM Smack needs the capability CAP_MAC_ADMIN to change the current execution security context of the
* process. This is the latest place before dropping capabilities. Other MAC context are set later. */
if (use_smack) {
r = setup_smack(context, executable_fd);
r = setup_smack(unit->manager, context, executable_fd);
if (r < 0 && !context->smack_process_label_ignore) {
*exit_status = EXIT_SMACK_PROCESS_LABEL;
return log_unit_error_errno(unit, r, "Failed to set SMACK process label: %m");