Skip to content

Commit

Permalink
basic: Fix capability_ambient_set_apply for kernels < 4.3
Browse files Browse the repository at this point in the history
systemd/systemd#14133 made
capability_ambient_set_apply() acquire capabilities that were explicitly
asked for and drop all others. This change means the function is called
even with an empty capability set, opening up a code path for users
without ambient capabilities to call this function. This function will
error with EINVAL out on kernels < 4.3 because PR_CAP_AMBIENT is not
understood. This turns capability_ambient_set_apply() into a noop for
kernels < 4.3

Fixes systemd/systemd#15225

(cherry picked from commit 7ea4392)
  • Loading branch information
kkuehlz authored and keszybz committed Apr 1, 2020
1 parent e4b7c40 commit 1a2f596
Showing 1 changed file with 4 additions and 0 deletions.
4 changes: 4 additions & 0 deletions src/basic/capability-util.c
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,10 @@ int capability_ambient_set_apply(uint64_t set, bool also_inherit) {
unsigned long i;
int r;

/* Check that we can use PR_CAP_AMBIENT or quit early. */
if (!ambient_capabilities_supported())
return 0;

/* Add the capabilities to the ambient set. */

if (also_inherit) {
Expand Down

0 comments on commit 1a2f596

Please sign in to comment.