Skip to content

Commit

Permalink
linux: ignore unknown capabilities
Browse files Browse the repository at this point in the history
opencontainers/runtime-spec#1094 introduced a
change where unknown capabilities must be ignored.  The runtime MUST
log a warning instead of failing with an error.

Signed-off-by: Giuseppe Scrivano <[email protected]>
  • Loading branch information
giuseppe committed Mar 29, 2021
1 parent 496e81b commit 738fa30
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 2 deletions.
5 changes: 4 additions & 1 deletion src/libcrun/linux.c
Original file line number Diff line number Diff line change
Expand Up @@ -2395,7 +2395,10 @@ read_caps (unsigned long caps[2], char **values, size_t len, libcrun_error_t *er
{
cap_value_t cap;
if (cap_from_name (values[i], &cap) < 0)
return crun_make_error (err, 0, "unknown cap: `%s`", values[i]);
{
libcrun_warning ("unknown cap: `%s`", values[i]);
continue;
}
if (cap < 32)
caps[0] |= CAP_TO_MASK_0 (cap);
else
Expand Down
19 changes: 18 additions & 1 deletion tests/test_capabilities.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,22 @@ def test_some_caps():
return -1
return 0

def test_unknown_caps():
conf = base_config()
conf['process']['args'] = ['/init', 'cat', '/proc/self/status']
add_all_namespaces(conf)
conf['process']['capabilities'] = {}
# unknown caps must be ignored
for i in ['bounding', 'effective', 'inheritable', 'permitted', 'ambient']:
conf['process']['capabilities'][i] = ['CAP_UNKNOWN', 'UNKNOWN_CAP']
out, _ = run_and_get_output(conf)
proc_status = parse_proc_status(out)

for i in ['CapInh', 'CapPrm', 'CapEff', 'CapBnd', 'CapAmb']:
if proc_status[i] != "0000000000000000":
return -1
return 0

def test_new_privs():
conf = base_config()
conf['process']['args'] = ['/init', 'cat', '/proc/self/status']
Expand Down Expand Up @@ -136,7 +152,8 @@ def test_some_caps_permitted_non_root():
"some-caps-bounding-non-root" : test_some_caps_bounding_non_root,
"some-caps-inheritable-non-root" : test_some_caps_inheritable_non_root,
"some-caps-ambient-non-root" : test_some_caps_ambient_non_root,
"some-caps-permitted-non-root" : test_some_caps_permitted_non_root
"some-caps-permitted-non-root" : test_some_caps_permitted_non_root,
"unknown-caps" : test_unknown_caps,
}

if __name__ == "__main__":
Expand Down

0 comments on commit 738fa30

Please sign in to comment.