[PATCH 15/36] cmd/snap-confine: Prevent user-controlled race in setup_private_mount
authorAlex Murray <alex.murray@canonical.com>
Thu, 18 Nov 2021 00:33:45 +0000 (11:03 +1030)
committerMarkus Koschany <apo@debian.org>
Tue, 13 Jun 2023 09:28:53 +0000 (10:28 +0100)
commitee1516aa63be20b5dbd8bb426f4b93d956a3d86d
tree87f342ea327d291209037c6a4c6586fe6f20bcc8
parenta4d207cb157a6ace55100e1ddf6923756f5c30c1
[PATCH 15/36] cmd/snap-confine: Prevent user-controlled race in setup_private_mount

When setting up the private mount namespace for a snap, snap-confine tries
to reuse the existing /tmp/snap.$SNAP_NAME directory if it already
exists. However, a user could create this directory before snap-confine is
executed and hence snap-confine would reuse it, along with any contents
that already existed. This could allow a user to symlink their own contents
into this directory and snap-confine would then mount that into the snap's
mount namespace. Finally this could allow an unprivileged attacker to cause
snap-confine to escape confinement by causing it to be executed under a
less restrictive AppArmor profile when this vulnerability is combined with
others. Fix this by moving the erroneous directory out of the way if it
doesn't have the expected permissions / ownership so we can re-create it
with the correct restrictive permissions.

This resolves CVE-2021-44731.

Signed-off-by: Alex Murray <alex.murray@canonical.com>
Gbp-Pq: Topic cve202144730
Gbp-Pq: Name 0015-cmd-snap-confine-Prevent-user-controlled-race-in-set.patch
cmd/snap-confine/mount-support-test.c
cmd/snap-confine/mount-support.c