Skip to content

Commit

Permalink
lsm: fixup lsm_process_label_set_at return values
Browse files Browse the repository at this point in the history
Always return -1 on error (some code paths returned -1, some
returned negative error codes), don't assume 'errno' is set
afterwards, as the function already prints errors and not
all code paths will have a usable errno value.

Signed-off-by: Wolfgang Bumiller <w.bumiller@proxmox.com>
  • Loading branch information
Blub authored and Christian Brauner committed Jul 31, 2018
1 parent 11c52cb commit 28968d7
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 5 deletions.
2 changes: 1 addition & 1 deletion src/lxc/lsm/apparmor.c
Expand Up @@ -241,7 +241,7 @@ static int apparmor_process_label_set(const char *inlabel, struct lxc_conf *conf
ret = lsm_process_label_set_at(label_fd, label, on_exec);
close(label_fd);
if (ret < 0) {
SYSERROR("Failed to change apparmor profile to %s", label);
ERROR("Failed to change apparmor profile to %s", label);
return -1;
}

Expand Down
12 changes: 8 additions & 4 deletions src/lxc/lsm/lsm.c
Expand Up @@ -142,28 +142,32 @@ int lsm_process_label_set_at(int label_fd, const char *label, bool on_exec)

if (on_exec) {
ERROR("Changing AppArmor profile on exec not supported");
return -EINVAL;
return -1;
}

len = strlen(label) + strlen("changeprofile ") + 1;
command = malloc(len);
if (!command)
return -1;
goto on_error;

ret = snprintf(command, len, "changeprofile %s", label);
if (ret < 0 || (size_t)ret >= len) {
int saved_errno = errno;
free(command);
return -1;
errno = saved_errno;
goto on_error;
}

ret = lxc_write_nointr(label_fd, command, len - 1);
free(command);
} else if (strcmp(name, "SELinux") == 0) {
ret = lxc_write_nointr(label_fd, label, strlen(label));
} else {
ret = -EINVAL;
errno = EINVAL;
ret = -1;
}
if (ret < 0) {
on_error:
SYSERROR("Failed to set %s label \"%s\"", name, label);
return -1;
}
Expand Down

0 comments on commit 28968d7

Please sign in to comment.