Merge Set up overlayfs_fuse test that uses a FUSE implementation of overlayfs

This also reorganizes the overlayfs tests slightly in order to maximize code reuse between the old test and the new one.

Signed-off-by: Ryan Lee <ryan.lee@canonical.com>

MR: https://gitlab.com/apparmor/apparmor/-/merge_requests/1503
Approved-by: Georgia Garcia <georgia.garcia@canonical.com>
Merged-by: Georgia Garcia <georgia.garcia@canonical.com>
This commit is contained in:
Georgia Garcia 2025-01-24 20:28:57 +00:00
commit dfb7abf2a6
6 changed files with 69 additions and 7 deletions

View file

@ -135,7 +135,7 @@ test-build-regression:
script: script:
# Additional dependencies required by regression tests # Additional dependencies required by regression tests
- printf '\e[0K%s:%s:%s[collapsed=true]\r\e[0K%s\n' section_start "$(date +%s)" install_extra_deps "Installing additional dependencies..." - printf '\e[0K%s:%s:%s[collapsed=true]\r\e[0K%s\n' section_start "$(date +%s)" install_extra_deps "Installing additional dependencies..."
- apt-get install --no-install-recommends -y attr libdbus-1-dev liburing-dev - apt-get install --no-install-recommends -y attr fuse-overlayfs libdbus-1-dev liburing-dev
- printf '\e[0K%s:%s:%s\r\e[0K\n' section_end "$(date +%s)" install_extra_deps - printf '\e[0K%s:%s:%s\r\e[0K\n' section_end "$(date +%s)" install_extra_deps
- make -C tests/regression/apparmor -j $(nproc) - make -C tests/regression/apparmor -j $(nproc)

View file

@ -191,6 +191,15 @@ Install attr or equivalent package to build and run this test${nl}\
************************************************************************${nl}) ************************************************************************${nl})
endif endif
# Only do overlayfs_fuse test if we have the required fuse-overlayfs binary
ifeq (,$(shell command -v fuse-overlayfs))
$(warning ${nl}\
************************************************************************${nl}\
No fuse-overlayfs skipping overlayfs_fuse tests ...${nl}\
Install fuse-overlayfs or equivalent package to build and run this test${nl}\
************************************************************************${nl})
endif
#only do dbus if proper libs are installl #only do dbus if proper libs are installl
ifneq (,$(shell pkg-config --exists dbus-1 && echo TRUE)) ifneq (,$(shell pkg-config --exists dbus-1 && echo TRUE))
SRC+=dbus_eavesdrop.c dbus_message.c dbus_service.c dbus_unrequested_reply.c SRC+=dbus_eavesdrop.c dbus_message.c dbus_service.c dbus_unrequested_reply.c
@ -279,7 +288,7 @@ TESTS=aa_exec \
named_pipe \ named_pipe \
namespaces \ namespaces \
net_raw \ net_raw \
overlayfs \ overlayfs_kernel \
open \ open \
openat \ openat \
pipe \ pipe \
@ -311,6 +320,11 @@ TESTS=aa_exec \
longpath \ longpath \
nfs nfs
# Only do overlayfs_fuse test if we have the required fuse-overlayfs binary
ifneq (,$(shell command -v fuse-overlayfs))
TESTS+=overlayfs_fuse
endif
# Only do xattrs_profile test if we have the required setfattr binary # Only do xattrs_profile test if we have the required setfattr binary
ifneq (,$(shell command -v setfattr)) ifneq (,$(shell command -v setfattr))
TESTS+=xattrs_profile TESTS+=xattrs_profile

View file

@ -11,6 +11,12 @@
# Verifies that file rules work in an overlayfs # Verifies that file rules work in an overlayfs
#=END #=END
if [ "$1" != "kernel" ] && [ "$1" != "fuse" ]; then
echo "FAIL: no parameter/invalid parameter specified"
echo "(expected 'kernel' or 'fuse')"
exit 1
fi
pwd=$(dirname "$0") pwd=$(dirname "$0")
pwd=$(cd "$pwd" || exit ; /bin/pwd) pwd=$(cd "$pwd" || exit ; /bin/pwd)
@ -49,17 +55,26 @@ mount "${loop_device_other}" "${overlayfs_other}"
mkdir "${overlayfs_upper}" mkdir "${overlayfs_upper}"
mkdir "${overlayfs_workdir}" mkdir "${overlayfs_workdir}"
mount -t overlay -o lowerdir="${overlayfs_lower}",upperdir="${overlayfs_upper}",workdir="${overlayfs_workdir}" none "${mount_target}"|| fatalerror 'Unable to set up overlayfs' # The behavior when changing the contents of lowerdir or upperdir
# after mounting the overlay is described as "undefined"
# Hopefully this isn't UB in the C standard/compiler sense
# Concretely: kernel overlayfs propagates changes, fuse-overlayfs doesn't
fallocate -l 16K "${overlayfs_lower}/lower_file" fallocate -l 16K "${overlayfs_lower}/lower_file"
touch "${overlayfs_lower}/lower_file_2" touch "${overlayfs_lower}/lower_file_2"
fallocate -l 16K "${overlayfs_upper}/upper_file" fallocate -l 16K "${overlayfs_upper}/upper_file"
touch "${overlayfs_upper}/upper_file_2" touch "${overlayfs_upper}/upper_file_2"
fallocate -l 16K "${mount_target}/overlay_file"
# echo is also a builtin, making things a bit more complicated # echo is also a builtin, making things a bit more complicated
cp "$(type -P echo)" "${overlayfs_lower}/lower_echo" cp "$(type -P echo)" "${overlayfs_lower}/lower_echo"
cp "$(type -P echo)" "${overlayfs_upper}/upper_echo" cp "$(type -P echo)" "${overlayfs_upper}/upper_echo"
if [ "$1" == "fuse" ]; then
fuse-overlayfs -o lowerdir="${overlayfs_lower}",upperdir="${overlayfs_upper}",workdir="${overlayfs_workdir}" "${mount_target}"|| fatalerror 'Unable to set up overlayfs'
else
mount -t overlay -o lowerdir="${overlayfs_lower}",upperdir="${overlayfs_upper}",workdir="${overlayfs_workdir}" none "${mount_target}"|| fatalerror 'Unable to set up overlayfs'
fi
fallocate -l 16K "${mount_target}/overlay_file"
settest overlayfs "${bin}/complain" settest overlayfs "${bin}/complain"
genprofile "${mount_target}/lower_file:r" "${mount_target}/upper_file:r" "${mount_target}/overlay_file:r" genprofile "${mount_target}/lower_file:r" "${mount_target}/upper_file:r" "${mount_target}/overlay_file:r"
@ -107,7 +122,11 @@ runchecktest "Exec in overlayfs mount (lower)" pass exec "${mount_target}/lower_
runchecktest "Exec in overlayfs mount (upper)" pass exec "${mount_target}/upper_echo" PASS runchecktest "Exec in overlayfs mount (upper)" pass exec "${mount_target}/upper_echo" PASS
runchecktest "Exec in overlayfs mount (overlay)" pass exec "${mount_target}/overlay_echo" PASS runchecktest "Exec in overlayfs mount (overlay)" pass exec "${mount_target}/overlay_echo" PASS
umount "${mount_target}" && rmdir "${mount_target}" if [ "$1" == "fuse" ]; then
fusermount -u "${mount_target}" && rmdir "${mount_target}"
else
umount "${mount_target}" && rmdir "${mount_target}"
fi
umount "${loop_device_lower}" && rm -r "${overlayfs_lower}" umount "${loop_device_lower}" && rm -r "${overlayfs_lower}"
umount "${loop_device_other}" && rm -r "${overlayfs_other}" umount "${loop_device_other}" && rm -r "${overlayfs_other}"

View file

@ -0,0 +1,14 @@
#! /bin/bash
# Copyright (C) 2024 Canonical, Ltd.
#
# This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License as
# published by the Free Software Foundation, version 2 of the
# License.
#=NAME overlayfs_fuse
#=DESCRIPTION
# Verifies that file rules work in a (fuse) overlayfs
#=END
source "./overlayfs_common.inc" fuse

View file

@ -0,0 +1,14 @@
#! /bin/bash
# Copyright (C) 2024 Canonical, Ltd.
#
# This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License as
# published by the Free Software Foundation, version 2 of the
# License.
#=NAME overlayfs_kernel
#=DESCRIPTION
# Verifies that file rules work in a (kernel) overlayfs
#=END
source "./overlayfs_common.inc" kernel

View file

@ -47,7 +47,8 @@ environment:
TEST/onexec: 1 TEST/onexec: 1
TEST/open: 1 TEST/open: 1
TEST/openat: 1 TEST/openat: 1
TEST/overlayfs: 1 TEST/overlayfs_fuse: 1
TEST/overlayfs_kernel: 1
TEST/pipe: 1 TEST/pipe: 1
TEST/pivot_root: 1 TEST/pivot_root: 1
TEST/posix_ipc: 1 TEST/posix_ipc: 1