criu/test
Andrei Vagin 1325b8a3b3 apparmor: fix write check, and implement runtime fallback
When checkpointing tasks confined by stacked AppArmor profiles inside an
AppArmor namespace, CRIU compiles a permissive parasite profile using
apparmor_parser and writes it to the namespace policy replacement
interface
(/sys/kernel/security/apparmor/policy/namespaces/<ns>/.replace).

Previously, get_suspend_policy() invoked apparmor_parser with flags
(-QWL) requesting cache file generation and read the resulting cache
file. On modern AppArmor 4.x kernels, cache files include cache metadata
headers that cause the kernel policy unpacker to reject the binary blob
with EPROTONOSUPPORT (-93, "invalid profile format"). Replace the cache
mechanism by invoking apparmor_parser with the -o flag to output a clean
binary policy stream directly.

Furthermore, when writing a replacement profile blob to an AppArmor
.replace interface, successful writes return the total size of the
profile load data structure consumed or updated in the kernel (e.g.,
5233 bytes for stacked profiles), rather than the exact byte length of
the input payload (e.g., 727 bytes for a parasite profile). Checking if
(n != len) erroneously treats a successful replacement write as a
failure. Fix policy write validation to check if (n < 0).

Across Linux kernel versions, AppArmor enforces different requirements
for policy replacement blobs written to a namespace .replace interface:
- Older kernels (AppArmor 3.x / early 4.x on Ubuntu 22.04) expect blobs
  compiled without namespace headers (-n <ns>); specifying -n causes
  the kernel to load the replacement into a nested sub-namespace
  (<ns>//<ns>), leaving the active profile unchanged and causing socket
  permission failures during dump.
- Modern kernels (AppArmor 4.x on Ubuntu 26.04) reject blobs compiled
  without namespace headers with EPROTONOSUPPORT (-93, "invalid profile
  format").

Update get_suspend_policy() and write_aa_policy() to implement runtime
fallback: first try compiling without -n <ns> and writing directly to
the namespace interface for older kernels. If writing fails (n < 0),
retry compilation passing -n <ns> and write to the root interface to
satisfy modern kernels.

In addition, when restoring tasks confined by profiles inside an
AppArmor namespace on AppArmor 4.x kernels, the host root unconfined
profile remains stacked with the target namespace profile when viewed
from the root namespace (e.g., "unconfined//&:ns:profile"). Update
checkprofile() in the apparmor_stacking test to recognize and allow the
"unconfined//&" prefix when verifying restored profiles.

Assisted-by: Gemini
Signed-off-by: Andrei Vagin <avagin@google.com>
2026-07-08 20:27:12 -07:00
..
compel Run 'make indent' on header files 2021-09-03 10:31:00 -07:00
cuda-checkpoint test: add get-state to mocked cuda-checkpoint tool 2025-03-21 12:40:31 -07:00
exhaustive test/exhaustive: fix file handle leak in get_pipe_rw 2026-07-07 15:02:33 +01:00
inhfd test/inhfd: remove redundant mnt_id initialization 2026-07-08 09:51:25 +01:00
javaTests test/javaTests: update org.testng:testng (Maven) 2023-04-15 21:17:21 -07:00
jenkins compel: remove hardware breakpoint usage 2026-03-08 23:01:54 -07:00
libfault zdtm: add support for LD_PRELOAD tests 2024-09-11 16:02:11 -07:00
others test/rpc: fix file handle leak in status fd reader 2026-07-07 15:02:33 +01:00
pki test: create new tls certificates 2021-09-03 10:31:00 -07:00
plugins zdtm: add inventory test plugins 2025-03-21 12:40:31 -07:00
zdtm apparmor: fix write check, and implement runtime fallback 2026-07-08 20:27:12 -07:00
.gitignore zdtm: Add javaTests output to .gitignore 2021-09-03 10:31:00 -07:00
abrt.sh test/abrt: skip core dumps from the seccomp_filter test 2019-04-20 20:25:26 -07:00
crit-recode.py test/crit-recode: fix file handle leak in image read 2026-07-07 15:02:33 +01:00
empty-netns-prep.sh test: don't use nsenter in tests 2017-05-19 09:17:20 +03:00
groups.desc zdtm.py: Generator of groups of tests 2015-12-08 14:54:41 +03:00
inhfd.desc zdtm.py: Add inhfd tests for --inherit-fd option 2015-10-19 12:42:01 +03:00
Makefile test: fix clean target paths for libcriu, rpc, and crit 2026-06-12 09:54:46 +01:00
pycriu lib: use separate packages for pycriu and crit 2023-11-27 16:47:16 -08:00
umount2.c zdtm: add a program to umount a test root 2016-09-26 15:42:40 +03:00
zdtm.desc test: Get rid of live directory 2016-02-20 13:40:52 +03:00
zdtm.py zdtm: exercise --image-io-mode=direct in the test suite 2026-07-08 09:52:16 +01:00
zdtm_ct.c zdtm: Update netns purpose comment in zdtm_ct. 2023-10-22 13:29:25 -07:00
zdtm_mount_cgroups zdtm: use unique holder for cgroups 2022-04-28 17:53:52 -07:00
zdtm_umount_cgroups zdtm: use unique holder for cgroups 2022-04-28 17:53:52 -07:00