Incorrect handling of apparmor `bpf` capability
Affects | Status | Importance | Assigned to | Milestone | |
---|---|---|---|---|---|
apparmor (Ubuntu) |
In Progress
|
High
|
Unassigned | ||
Focal |
Fix Released
|
Undecided
|
Unassigned | ||
snapd (Ubuntu) |
Incomplete
|
Undecided
|
Unassigned |
Bug Description
[ Impact ]
The apparmor_parser before the 3.0 release would build its capability list from the installed kernel headers. The apparmor_parser was built against a kernel without support for cap 'bpf'
This was fixed in 3.0 by having a static caps list (with full mapping info) and the dynamic auto-generated list (against the kernel headers) that is used to check that the static list has not become stale. In addition the parser can pull kernel supported caps straight from the apparmor kernel module (it will however be missing the mapping info).
Backporting the patches from 3.0 fixes the issue.
[ Test Plan ]
Before the fix, the following profile fails loading:
# echo "profile foo { capability bpf, }" | apparmor_parser -Q
AppArmor parser error, in stdin line 1: Invalid capability bpf.
# echo $?
1
After the fix, it works as expected:
# echo "profile foo { capability bpf, }" | apparmor_parser -Q
# echo $?
0
[ Where problems could occur ]
With these changes, the parser can change its behavior based on a few things.
1. the kernel its built against. This would not change behavior when run in a container vs at system level.
2. If a feature-file is specified, via --features-file, --policy-features, or --kernel-features. This allows overriding the normal policy and kernel examination that the parser does when compiling policy.
3. If /sys/kernel/
[ Other Info ]
The patches for focal (apparmor-2.13) can be found at:
https:/
As mentioned before, these patches are already running on apparmor-3.0.
Changed in apparmor (Ubuntu): | |
importance: | Undecided → High |
status: | New → In Progress |
Thanks for the report, I just tried to reproduce this on both updated impish and updated jammy and couldn't reproduce. I notice on impish specifically that my focal container does not get the /var/lib/ snapd/apparmor/ snap-confine/ cap-bpf file which is expected because the apparmor_parser for focal does not know about the bpf capability. What's confusing is how/why your container saw this, because again snapd actually tries to compile a program with apparmor_parser with "capability bpf," in it and only if that succeeds will it generate that snippet to include in snap-confine's policy.
So for this to have happened to you, the apparmor_parser that snapd sees inside the focal container must have been able to successfully compile with that snippet.
You mentioned on IRC that this was a privileged container, is there anyway that in addition to being a privileged container somehow it had a newer apparmor_parser in the container too?