capabilities: Don't allow writing ambiguous v3 file capabilities
authorEric W. Biederman <ebiederm@xmission.com>
Thu, 17 Dec 2020 15:42:00 +0000 (09:42 -0600)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Thu, 4 Mar 2021 10:37:52 +0000 (11:37 +0100)
commit54b4e5df958c6ec1cb4afe502e045369ab5557f6
treecd7d23a49109e2e0533dd47a824a696b44ee3589
parentbf24c51d62d1a59ae8b05e70fe0409cef41729c1
capabilities: Don't allow writing ambiguous v3 file capabilities

[ Upstream commit 95ebabde382c371572297915b104e55403674e73 ]

The v3 file capabilities have a uid field that records the filesystem
uid of the root user of the user namespace the file capabilities are
valid in.

When someone is silly enough to have the same underlying uid as the
root uid of multiple nested containers a v3 filesystem capability can
be ambiguous.

In the spirit of don't do that then, forbid writing a v3 filesystem
capability if it is ambiguous.

Fixes: 8db6c34f1dbc ("Introduce v3 namespaced file capabilities")
Reviewed-by: Andrew G. Morgan <morgan@kernel.org>
Reviewed-by: Serge Hallyn <serge@hallyn.com>
Signed-off-by: Eric W. Biederman <ebiederm@xmission.com>
Signed-off-by: Sasha Levin <sashal@kernel.org>
security/commoncap.c