]> git.baikalelectronics.ru Git - kernel.git/commit
[SECURITY] fix namespaced fscaps when !CONFIG_SECURITY
authorSerge Hallyn <shallyn@cisco.com>
Mon, 16 Nov 2020 03:55:31 +0000 (21:55 -0600)
committerJames Morris <jamorris@linux.microsoft.com>
Sat, 5 Dec 2020 00:24:11 +0000 (16:24 -0800)
commit27f6f9c82465feacf746bc2270037c72356f819e
treec211ce51c5ce295de01d86d82fa5d04a4009d27e
parent84f4a9652c8a9177dded2c36fe1349fabea25124
[SECURITY] fix namespaced fscaps when !CONFIG_SECURITY

Namespaced file capabilities were introduced in f142a909d302 .
When userspace reads an xattr for a namespaced capability, a
virtualized representation of it is returned if the caller is
in a user namespace owned by the capability's owning rootid.
The function which performs this virtualization was not hooked
up if CONFIG_SECURITY=n.  Therefore in that case the original
xattr was shown instead of the virtualized one.

To test this using libcap-bin (*1),

$ v=$(mktemp)
$ unshare -Ur setcap cap_sys_admin-eip $v
$ unshare -Ur setcap -v cap_sys_admin-eip $v
/tmp/tmp.lSiIFRvt8Y: OK

"setcap -v" verifies the values instead of setting them, and
will check whether the rootid value is set.  Therefore, with
this bug un-fixed, and with CONFIG_SECURITY=n, setcap -v will
fail:

$ v=$(mktemp)
$ unshare -Ur setcap cap_sys_admin=eip $v
$ unshare -Ur setcap -v cap_sys_admin=eip $v
nsowner[got=1000, want=0],/tmp/tmp.HHDiOOl9fY differs in []

Fix this bug by calling cap_inode_getsecurity() in
security_inode_getsecurity() instead of returning
-EOPNOTSUPP, when CONFIG_SECURITY=n.

*1 - note, if libcap is too old for getcap to have the '-n'
option, then use verify-caps instead.

Bugzilla: https://bugzilla.kernel.org/show_bug.cgi?id=209689
Cc: Hervé Guillemet <herve@guillemet.org>
Acked-by: Casey Schaufler <casey@schaufler-ca.com>
Signed-off-by: Serge Hallyn <shallyn@cisco.com>
Signed-off-by: Andrew G. Morgan <morgan@kernel.org>
Signed-off-by: James Morris <jamorris@linux.microsoft.com>
include/linux/security.h