cap: fix conversions on getxattr
authorMiklos Szeredi <mszeredi@redhat.com>
Thu, 28 Jan 2021 09:22:48 +0000 (10:22 +0100)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Wed, 17 Feb 2021 10:02:22 +0000 (11:02 +0100)
commit02dee03d48314b77a3c60091aa10fa721c3d1edd
treee7b001896c7ffe96eaa898d483c7b0364913bb02
parentcbb9404a50521cdee71346d162b72d3cde270b9e
cap: fix conversions on getxattr

[ Upstream commit f2b00be488730522d0fb7a8a5de663febdcefe0a ]

If a capability is stored on disk in v2 format cap_inode_getsecurity() will
currently return in v2 format unconditionally.

This is wrong: v2 cap should be equivalent to a v3 cap with zero rootid,
and so the same conversions performed on it.

If the rootid cannot be mapped, v3 is returned unconverted.  Fix this so
that both v2 and v3 return -EOVERFLOW if the rootid (or the owner of the fs
user namespace in case of v2) cannot be mapped into the current user
namespace.

Signed-off-by: Miklos Szeredi <mszeredi@redhat.com>
Acked-by: "Eric W. Biederman" <ebiederm@xmission.com>
Signed-off-by: Sasha Levin <sashal@kernel.org>
security/commoncap.c