2
0
mirror of https://gitlab.com/apparmor/apparmor synced 2025-09-02 15:25:27 +00:00

Compare commits

..

10 Commits

Author SHA1 Message Date
John Johansen
b4dfdf50f5 Prepare for 4.0.3 release
- Bump version
- bump library version

Signed-off-by: John Johansen <john.johansen@canonical.com>
2024-08-14 18:39:36 -07:00
Georgia Garcia
5dd04c3389 Merge profiles: runc: allow /usr/bin/runc as well as /usr/sbin/runc
Docker, Inc's `containerd.io` package installs runc onto `/usr/bin/runc` rather than `/usr/sbin/runc`.

```
$ wget https://download.docker.com/linux/ubuntu/dists/noble/pool/stable/amd64/containerd.io_1.7.20-1_amd64.deb
$ dpkg -c containerd.io_1.7.20-1_amd64.deb | grep /runc
-rwxr-xr-x root/root   9806280 2024-08-08 23:20 ./usr/bin/runc
```

Similar to 9ab45d "profiles: support distributions which merge sbin into bin".

MR: https://gitlab.com/apparmor/apparmor/-/merge_requests/1300
Approved-by: Georgia Garcia <georgia.garcia@canonical.com>
Merged-by: Georgia Garcia <georgia.garcia@canonical.com>


(cherry picked from commit a50283bad0)

2333fbcf profiles: runc: allow /usr/bin/runc as well as /usr/sbin/runc

Co-authored-by: Georgia Garcia <georgia.garcia@canonical.com>
2024-08-14 12:31:26 +00:00
John Johansen
1e9e52f243 Merge abstractions/base: allow reading of fips_enabled
Commonly used by applications to determine if Linux is running in
FIPS mode. As we already allow access to FIPS specific library files
as part of base, allow this there as well.

Signed-off-by: Georg Pfuetzenreuter <mail@georg-pfuetzenreuter.net>

MR: https://gitlab.com/apparmor/apparmor/-/merge_requests/1286
Approved-by: John Johansen <john@jjmx.net>
Merged-by: John Johansen <john@jjmx.net>
(cherry picked from commit e787f4d69d)
Signed-off-by: John Johansen <john.johansen@canonical.com>
2024-08-07 00:39:02 -07:00
Ryan Lee
9f57cbcb15 Fix SWIG prototype declaration of aa_getpeercon_raw
Unsigned int vs int probably wouldn't have caused issues, but just in case

Signed-off-by: Ryan Lee <ryan.lee@canonical.com>
(cherry picked from commit 91bac34afd)
Signed-off-by: Georgia Garcia <georgia.garcia@canonical.com>
2024-08-06 17:26:23 -03:00
Ryan Lee
8146d3a6a3 Explicitly initialize component in test_walk_one
This removes the assumption that the stack is zeroed and silences the corresponding compiler warning

Signed-off-by: Ryan Lee <ryan.lee@canonical.com>
(cherry picked from commit 552d9d9f7a)
Signed-off-by: Georgia Garcia <georgia.garcia@canonical.com>
2024-08-06 17:26:06 -03:00
Georgia Garcia
d3d1c02b4e Merge Fix incorrect strnlen length in aa_load.c load_policy_dir
POSIX states that d_name has up to NAME_MAX (255) characters, and glibc
stores d_name as an array of size NAME_MAX+1 (256). Thus, supplying
PATH_MAX (4096) as the max length could trigger a buffer overrun. This
could be an even bigger issue on other libcs, as POSIX states that d_name
can be unsized.

Fortunately, this does not seem to cause actual issues, as the length is
only used to compare d_name to a short fixed string. However, it'd be better
to pass the actual correct max length to strnlen.

MR: https://gitlab.com/apparmor/apparmor/-/merge_requests/1290
Approved-by: Georgia Garcia <georgia.garcia@canonical.com>
Merged-by: Georgia Garcia <georgia.garcia@canonical.com>


(cherry picked from commit d1da63dc5a)

322a98c8 Fix incorrect strnlen length in aa_load.c load_policy_dir

Co-authored-by: Georgia Garcia <georgia.garcia@canonical.com>
2024-08-06 20:14:04 +00:00
John Johansen
eb523cf53b Merge firefox: add fcitx portal rules from Ubuntu 20.04/focal
The Ubuntu 20.04/focal packaging of Firefox added these rules to their AppArmor profile recently, relating to the [Fcitx portal](https://fcitx-im.org/wiki/Using_Fcitx_with_container).

MR: https://gitlab.com/apparmor/apparmor/-/merge_requests/1280
Approved-by: John Johansen <john@jjmx.net>
Merged-by: John Johansen <john@jjmx.net>
(cherry picked from commit fac2e25219)
Signed-off-by: John Johansen <john.johansen@canonical.com>
2024-08-05 09:17:33 -07:00
John Johansen
507be2a990 Merge test: detect if setuid environ test in running under nosuid
If the test ran under a fs mounted with nosuid option, then these bits
would be ignored and the test would fail. In that case, detect it and
run the test in a tmpfs mountpoint without nosuid.

Signed-off-by: Georgia Garcia <georgia.garcia@canonical.com>

MR: https://gitlab.com/apparmor/apparmor/-/merge_requests/1285
Approved-by: John Johansen <john@jjmx.net>
Merged-by: John Johansen <john@jjmx.net>
(cherry picked from commit bc68bc51ca)
Signed-off-by: John Johansen <john.johansen@canonical.com>
2024-08-05 09:15:57 -07:00
John Johansen
3c24bc68b6 Merge fix regression test failures for when /tmp is mounted as tmpfs
MR: https://gitlab.com/apparmor/apparmor/-/merge_requests/1283
Approved-by: John Johansen <john@jjmx.net>
Merged-by: John Johansen <john@jjmx.net>
(cherry picked from commit 1fc944bb67)
Signed-off-by: John Johansen <john.johansen@canonical.com>
2024-08-05 09:15:36 -07:00
John Johansen
0193009b8b Merge libapparmor: fix undefined reference to aa_split_overlay_str
The linkage of aa-load with the dynamic libapparmor fails with:
aa_load.c:273: undefined reference to `aa_split_overlay_str'

That is because when aa_split_overlay_str was added to libapparmor,
the function was not added to the library map.

Fixes: 50054ff0 ("add aa_split_overlay_str")
Signed-off-by: Georgia Garcia <georgia.garcia@canonical.com>

MR: https://gitlab.com/apparmor/apparmor/-/merge_requests/1288
Approved-by: John Johansen <john@jjmx.net>
Merged-by: John Johansen <john@jjmx.net>
(cherry picked from commit ed3bc55d35)
Signed-off-by: John Johansen <john.johansen@canonical.com>
2024-08-05 09:11:29 -07:00
15 changed files with 107 additions and 81 deletions

View File

@@ -172,7 +172,8 @@ static int load_policy_dir(const char *dir_path)
while ((dir = readdir(d)) != NULL) {
/* Only check regular files for now */
if (dir->d_type == DT_REG) {
len = strnlen(dir->d_name, PATH_MAX);
/* As per POSIX dir->d_name has at most NAME_MAX characters */
len = strnlen(dir->d_name, NAME_MAX);
/* Ignores .features */
if (strncmp(dir->d_name, CACHE_FEATURES_FILE, len) == 0) {
continue;

View File

@@ -1 +1 @@
4.0.2
4.0.3

View File

@@ -32,10 +32,10 @@ INCLUDES = $(all_includes)
#
# After changing the AA_LIB_* variables, also update EXPECTED_SO_NAME.
AA_LIB_CURRENT = 19
AA_LIB_CURRENT = 20
AA_LIB_REVISION = 0
AA_LIB_AGE = 18
EXPECTED_SO_NAME = libapparmor.so.1.18.0
AA_LIB_AGE = 19
EXPECTED_SO_NAME = libapparmor.so.1.19.0
SUFFIXES = .pc.in .pc

View File

@@ -127,6 +127,7 @@ APPARMOR_3.0 {
APPARMOR_3.1 {
global:
aa_features_check;
aa_split_overlay_str;
local:
*;
} APPARMOR_3.0;

View File

@@ -135,7 +135,7 @@ static int do_test_walk_one(const char **str, const struct component *component,
static int test_walk_one(void)
{
struct component c;
struct component c = (struct component) { NULL, 0 };
const char *str;
int rc = 0;

View File

@@ -55,7 +55,7 @@ extern int aa_getprocattr_raw(pid_t tid, const char *attr, char *buf, int len,
extern int aa_getprocattr(pid_t tid, const char *attr, char **buf, char **mode);
extern int aa_gettaskcon(pid_t target, char **label, char **mode);
extern int aa_getcon(char **label, char **mode);
extern int aa_getpeercon_raw(int fd, char *buf, int *len, char **mode);
extern int aa_getpeercon_raw(int fd, char *buf, socklen_t *len, char **mode);
extern int aa_getpeercon(int fd, char **label, char **mode);
extern int aa_query_label(uint32_t mask, char *query, size_t size, int *allow,
int *audit);

View File

@@ -98,6 +98,9 @@
# best place -- but many profiles require it, and it is quite harmless.
@{PROC}/sys/kernel/ngroups_max r,
# Used to determine if Linux is running in FIPS mode
@{PROC}/sys/crypto/fips_enabled r,
# glibc's sysconf(3) routine to determine free memory, etc
@{PROC}/meminfo r,
@{PROC}/stat r,

View File

@@ -4,7 +4,7 @@
abi <abi/4.0>,
include <tunables/global>
profile runc /usr/sbin/runc flags=(unconfined) {
profile runc /usr/{bin,sbin}/runc flags=(unconfined) {
userns,
# Site-specific additions and overrides. See local/README for details.

View File

@@ -28,6 +28,7 @@ profile firefox @{MOZ_LIBDIR}/@{MOZ_APP_NAME}{,*[^s][^h]} {
include <abstractions/dbus-strict>
include <abstractions/dbus-session-strict>
include <abstractions/dconf>
include <abstractions/fcitx>
include <abstractions/fonts>
include <abstractions/gnome>
include <abstractions/ibus>

View File

@@ -23,12 +23,13 @@ settest unix_fd_server
disk_img=$tmpdir/disk_img
new_root=$tmpdir/new_root/
put_old=${new_root}put_old/
root_was_shared="no"
fstype="ext2"
file=$tmpdir/file
socket=$tmpdir/unix_fd_test
att_dis_client=$pwd/attach_disconnected
. $bin/mount.inc
attach_disconnected_cleanup() {
if [ ! -z "$loop_device" ]; then
losetup -d $loop_device
@@ -39,10 +40,7 @@ attach_disconnected_cleanup() {
umount "$new_root"
fi
if [ "$root_was_shared" = "yes" ] ; then
[ -n "$VERBOSE" ] && echo 'notice: re-mounting / as shared'
mount --make-shared /
fi
prop_cleanup
}
do_onexit="attach_disconnected_cleanup"
@@ -50,24 +48,6 @@ if [ ! -b /dev/loop0 ] ; then
modprobe loop
fi
# systemd mounts / and everything under it MS_SHARED. This breaks
# pivot_root entirely, so attempt to detect it, and remount /
# MS_PRIVATE temporarily.
FINDMNT=/bin/findmnt
if [ -x "${FINDMNT}" ] && ${FINDMNT} -no PROPAGATION / > /dev/null 2>&1 ; then
if [ "$(${FINDMNT} -no PROPAGATION /)" = "shared" ] ; then
root_was_shared="yes"
fi
elif [ "$(ps hp1 -ocomm)" = "systemd" ] ; then
# no findmnt or findmnt doesn't know the PROPAGATION column,
# but init is systemd so assume rootfs is shared
root_was_shared="yes"
fi
if [ "${root_was_shared}" = "yes" ] ; then
[ -n "$VERBOSE" ] && echo 'notice: re-mounting / as private'
mount --make-private /
fi
dd if=/dev/zero of="$disk_img" bs=1024 count=512 2> /dev/null
/sbin/mkfs -t "$fstype" -F "$disk_img" > /dev/null 2> /dev/null
# mounting will be done by the test binary

View File

@@ -85,6 +85,32 @@ runchecktest "ENVIRON (shell script): confined/complain & sensitive env" pass ${
# TEST environment filtering still works on setuid apps
removeprofile
tmpfs_dir=${tmpdir}/tmpfs_dir
remove_mnt() {
mountpoint -q "$tmpfs_dir"
if [ $? -eq 0 ] ; then
umount "$tmpfs_dir"
fi
}
do_onexit="remove_mnt"
# setuid apps mounted in a fs with "nosuid" option do not honor those
# bits during execution, so run the test in a mounted tmpdir without nosuid
FINDMNT=/bin/findmnt
if [ -x "${FINDMNT}" ] && ${FINDMNT} -no TARGET,OPTIONS -T $tmpdir > /dev/null 2>&1 ; then
output="$(${FINDMNT} -no TARGET,OPTIONS -T $tmpdir)"
target="$(echo $output | cut -d' ' -f1)"
options="$(echo $output | cut -d' ' -f2)"
case "$options" in
*nosuid* )
echo " $target is mounted with nosuid, creating a new mountpoint..."
setuid_helper=${tmpfs_dir}/env_check
mkdir ${tmpfs_dir}
mount -t tmpfs tmpfs ${tmpfs_dir}
;;
esac
fi
cp $helper ${setuid_helper}
chown nobody ${setuid_helper}
chmod u+s ${setuid_helper}

View File

@@ -0,0 +1,30 @@
root_was_shared="no"
root="/"
# systemd mounts / and everything under it MS_SHARED. This breaks
# pivot_root and mount "move" operations entirely, so attempt to
# detect from which mount point the test is running from, and remount
# it MS_PRIVATE temporarily.
FINDMNT=/bin/findmnt
if [ -x "${FINDMNT}" ] && ${FINDMNT} -no TARGET,PROPAGATION -T $tmpdir > /dev/null 2>&1 ; then
output="$(${FINDMNT} -no TARGET,PROPAGATION -T $tmpdir)"
root="$(echo $output | cut -d' ' -f1)"
if [ "$(echo $output | cut -d' ' -f2)" == "shared" ] ; then
root_was_shared="yes"
fi
elif [ "$(ps hp1 -ocomm)" = "systemd" ] ; then
# no findmnt or findmnt doesn't know the PROPAGATION column,
# but init is systemd so assume rootfs is shared
root_was_shared="yes"
fi
if [ "${root_was_shared}" = "yes" ] ; then
[ -n "$VERBOSE" ] && echo "notice: re-mounting $root as private"
mount --make-private $root
fi
prop_cleanup() {
if [ "${root_was_shared}" = "yes" ] ; then
[ -n "$VERBOSE" ] && echo "notice: re-mounting $root as shared"
mount --make-shared $root
fi
}

View File

@@ -32,7 +32,8 @@ mount_point2=$tmpdir/mountpoint2
mount_bad=$tmpdir/mountbad
loop_device="unset"
fstype="ext2"
root_was_shared="no"
. $bin/mount.inc
setup_mnt() {
/bin/mount -n -t${fstype} ${loop_device} ${mount_point}
@@ -59,9 +60,7 @@ mount_cleanup() {
then
/sbin/losetup -d ${loop_device} &> /dev/null
fi
if [ "${root_was_shared}" = "yes" ] ; then
mount --make-shared /
fi
prop_cleanup
}
do_onexit="mount_cleanup"
@@ -81,23 +80,6 @@ fi
loop_device=$(losetup -f) || fatalerror 'Unable to find a free loop device'
/sbin/losetup "$loop_device" ${mount_file} > /dev/null 2> /dev/null
# systemd mounts / and everything under it MS_SHARED which does
# not work with "move", so attempt to detect it, and remount /
# MS_PRIVATE temporarily. snippet from pivot_root.sh
FINDMNT=/bin/findmnt
if [ -x "${FINDMNT}" ] && ${FINDMNT} -no PROPAGATION / > /dev/null 2>&1 ; then
if [ "$(${FINDMNT} -no PROPAGATION /)" == "shared" ] ; then
root_was_shared="yes"
fi
elif [ "$(ps hp1 -ocomm)" = "systemd" ] ; then
# no findmnt or findmnt doesn't know the PROPAGATION column,
# but init is systemd so assume rootfs is shared
root_was_shared="yes"
fi
if [ "${root_was_shared}" = "yes" ] ; then
mount --make-private /
fi
options=(
# default and non-default options
"rw,ro"

View File

@@ -25,7 +25,8 @@ put_old=${new_root}put_old/
bad=$tmpdir/BAD/
proc=$new_root/proc
fstype="ext2"
root_was_shared="no"
. $bin/mount.inc
pivot_root_cleanup() {
mountpoint -q "$proc"
@@ -38,10 +39,7 @@ pivot_root_cleanup() {
umount "$new_root"
fi
if [ "${root_was_shared}" = "yes" ] ; then
[ -n "$VERBOSE" ] && echo 'notice: re-mounting / as shared'
mount --make-shared /
fi
prop_cleanup
}
do_onexit="pivot_root_cleanup"
@@ -50,24 +48,6 @@ if [ ! -b /dev/loop0 ] ; then
modprobe loop
fi
# systemd mounts / and everything under it MS_SHARED. This breaks
# pivot_root entirely, so attempt to detect it, and remount /
# MS_PRIVATE temporarily.
FINDMNT=/bin/findmnt
if [ -x "${FINDMNT}" ] && ${FINDMNT} -no PROPAGATION / > /dev/null 2>&1 ; then
if [ "$(${FINDMNT} -no PROPAGATION /)" = "shared" ] ; then
root_was_shared="yes"
fi
elif [ "$(ps hp1 -ocomm)" = "systemd" ] ; then
# no findmnt or findmnt doesn't know the PROPAGATION column,
# but init is systemd so assume rootfs is shared
root_was_shared="yes"
fi
if [ "${root_was_shared}" = "yes" ] ; then
[ -n "$VERBOSE" ] && echo 'notice: re-mounting / as private'
mount --make-private /
fi
# Create disk image since pivot_root doesn't allow old root and new root to be
# on the same filesystem
dd if=/dev/zero of="$disk_img" bs=1024 count=512 2> /dev/null

View File

@@ -27,16 +27,38 @@ bin=$pwd
## A. SWAP
##
# check if we can run the test at all
swap_file=$tmpdir/swapfile
# check if we can run the test in tmpdir
fstype=$(stat -f --format '%T' "${tmpdir}")
if [ "${fstype}" = "tmpfs" ] ; then
echo "ERROR: tmpdir '${tmpdir}' is of type tmpfs; can't mount a swapfile on it" 1>&2
echo "ERROR: skipping swap tests" 1>&2
num_testfailures=1
exit
# create a mountpoint not tmpfs
mount_file=$tmpdir/mountfile
mount_point=$tmpdir/mountpoint
fstype="ext2"
dd if=/dev/zero of=${mount_file} bs=1024 count=900 2> /dev/null
/sbin/mkfs -t${fstype} -F ${mount_file} > /dev/null 2> /dev/null
/bin/mkdir ${mount_point}
loop_device=$(losetup -f) || fatalerror 'Unable to find a free loop device'
/sbin/losetup "$loop_device" ${mount_file} > /dev/null 2> /dev/null
/bin/mount -n -t${fstype} ${loop_device} ${mount_point}
swap_file=$mount_point/swapfile
fi
swap_file=$tmpdir/swapfile
remove_mnt() {
mountpoint -q "${mount_point}"
if [ $? -eq 0 ] ; then
/bin/umount -t${fstype} ${mount_point}
fi
if [ -n "$loop_device" ]
then
/sbin/losetup -d ${loop_device} &> /dev/null
fi
}
do_onexit="remove_mnt"
# ppc64el wants this to be larger than 640KiB
# arm/small machines want this as small as possible