ovl: permit overlayfs mounts in user namespaces (taints kernel)
authorNicolas Schier <nicolas@fjasle.eu>
Mon, 19 Nov 2018 19:36:14 +0000 (20:36 +0100)
committerBen Hutchings <benh@debian.org>
Thu, 3 Oct 2024 21:58:46 +0000 (23:58 +0200)
commit26881470fe8673bd2bacc744955720b12132018f
treecfbf8250fca8d18f4c4073200a2a3f998afaaff9
parent3bd5403341ad0eac4bc6d8c4fc35b2f3430bd536
ovl: permit overlayfs mounts in user namespaces (taints kernel)

Permit overlayfs mounts within user namespaces to allow utilisation of e.g.
unprivileged LXC overlay snapshots.

Except by the Ubuntu community [1], overlayfs mounts in user namespaces are
expected to be a security risk [2] and thus are not enabled on upstream
Linux kernels.  For the non-Ubuntu users that have to stick to unprivileged
overlay-based LXCs, this meant to patch and compile the kernel manually.
Instead, adding the kernel tainting 'permit_mounts_in_userns' module
parameter allows a kind of a user-friendly way to enable the feature.

Testable with:

    sudo modprobe overlay permit_mounts_in_userns=1
    sudo sysctl -w kernel.unprivileged_userns_clone=1
    mkdir -p lower upper work mnt
    unshare --map-root-user --mount \
        mount -t overlay none mnt \
              -o lowerdir=lower,upperdir=upper,workdir=work

[1]: Ubuntu allows unprivileged mounting of overlay filesystem
https://lists.ubuntu.com/archives/kernel-team/2014-February/038091.html

[2]: User namespaces + overlayfs = root privileges
https://lwn.net/Articles/671641/

Signed-off-by: Nicolas Schier <nicolas@fjasle.eu>
[bwh: Forward-ported to 5.6: adjust context]

Gbp-Pq: Topic debian
Gbp-Pq: Name overlayfs-permit-mounts-in-userns.patch
fs/overlayfs/super.c