Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

s/apparmor: include files in apparmor kernel features #15130

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

olivercalder
Copy link
Member

@olivercalder olivercalder commented Feb 25, 2025

Previously, only directories under /sys/kernel/security/apparmor/features were included in the probed kernel features list. However, boolean files are sometimes used to indicate support for particular features as well.

This commit extends the probed features to include the presence of files, as well as directories.

Though we are looking in a sysfs, /sys/kernel/security/apparmor/features is entirely managed by apparmorfs, so it should not be a problem to include files there in the kernel features (and by extension in the system key).

This is required by #15089 so that the version support checks can use apparmor.KernelFeatures to check for the presence of the protocol version boolean files, indicating kernel support for particular versions.

Copy link

codecov bot commented Feb 25, 2025

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 78.06%. Comparing base (a272aac) to head (244ecd6).
Report is 77 commits behind head on master.

Additional details and impacted files
@@            Coverage Diff             @@
##           master   #15130      +/-   ##
==========================================
- Coverage   78.07%   78.06%   -0.01%     
==========================================
  Files        1182     1185       +3     
  Lines      157743   158252     +509     
==========================================
+ Hits       123154   123545     +391     
- Misses      26943    27028      +85     
- Partials     7646     7679      +33     
Flag Coverage Δ
unittests 78.06% <100.00%> (-0.01%) ⬇️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

Copy link

github-actions bot commented Feb 25, 2025

Fri Feb 28 19:34:29 UTC 2025
The following results are from: https://github.com/canonical/snapd/actions/runs/13590453901

Failures:

Preparing:

  • google-core:ubuntu-core-24-64:tests/regression/lp-1797556
  • google-core:ubuntu-core-24-64:tests/main/snap-user-dir-perms-fixed:root
  • google-core:ubuntu-core-24-64:tests/main/interfaces-desktop-host-fonts-core
  • google-core:ubuntu-core-24-64:tests/main/snap-user-dir-perms-fixed:test

Executing:

  • google-core:ubuntu-core-24-64:tests/regression/lp-2065077
  • google-core:ubuntu-core-24-64:tests/main/snap-confine-undesired-mode-group
  • google-core:ubuntu-core-24-64:tests/smoke/install
  • google-core:ubuntu-core-24-64:tests/regression/lp-1813365
  • google-core:ubuntu-core-24-64:tests/core/xdg-open-on-core
  • google-core:ubuntu-core-24-64:tests/main/interfaces-many-core-provided
  • google-core:ubuntu-core-24-64:tests/main/parallel-install-store
  • google-core:ubuntu-core-24-64:tests/main/parallel-install-local
  • google-core:ubuntu-core-24-64:tests/core/create-user-2
  • google-core:ubuntu-core-24-64:tests/core/remove-user
  • google-core:ubuntu-core-24-64:tests/smoke/sandbox
  • google-core:ubuntu-core-24-64:tests/main/snap-session-agent-socket-activation
  • google-core:ubuntu-core-24-64:tests/main/snap-session-agent-service-control
  • google-core:ubuntu-core-24-64:tests/main/snap-routine-portal-info
  • google-core:ubuntu-core-24-64:tests/main/snap-remove-terminate:fork_bomb
  • google-core:ubuntu-core-24-64:tests/main/regression-home-snap-root-owned
  • google-core:ubuntu-core-24-64:tests/main/snapshot-cross-revno
  • google-core:ubuntu-core-24-64:tests/main/snapshot-users
  • google-core:ubuntu-core-24-64:tests/main/snap-user-service-start-on-install
  • google-core:ubuntu-core-24-64:tests/main/dbus-activation-session
  • google-core:ubuntu-core-24-64:tests/main/interfaces-personal-files
  • google-core:ubuntu-core-24-64:tests/main/interfaces-mount-observe
  • google-core:ubuntu-core-24-64:tests/main/interfaces-system-observe
  • google-core:ubuntu-core-24-64:tests/main/snap-confine-tmp-mount
  • google-core:ubuntu-core-24-64:tests/main/snap-user-service-socket-activation
  • google-core:ubuntu-core-24-64:tests/main/interfaces-browser-support:disallow
  • google-core:ubuntu-core-24-64:tests/main/snap-user-service
  • google-core:ubuntu-core-24-64:tests/main/snap-user-service-upgrade-failure
  • google-core:ubuntu-core-24-64:tests/main/sudo-env
  • google-core:ubuntu-core-24-64:tests/main/interfaces-shared-memory-private
  • google-core:ubuntu-core-24-64:tests/main/parallel-install-basic
  • google-core:ubuntu-core-24-64:tests/main/refresh-app-awareness:strict
  • google-core:ubuntu-core-24-64:tests/main/cgroup-tracking:root
  • google-core:ubuntu-core-24-64:tests/main/snap-user-service-restart-on-upgrade
  • google-core:ubuntu-core-24-64:tests/main/system-usernames:daemon
  • google-core:ubuntu-core-24-64:tests/main/snap-debug-stacktrace
  • google-core:ubuntu-core-24-64:tests/main/interfaces-browser-support:allow
  • google-core:ubuntu-core-24-64:tests/main/snap-download
  • google-core:ubuntu-core-24-64:tests/main/snap-session-agent-unavailable-to-snaps
  • google-core:ubuntu-core-24-64:tests/main/system-usernames:snap_daemon

Restoring:

  • google-core:ubuntu-core-24-64:tests/regression/lp-1797556
  • google-core:ubuntu-core-24-64:tests/main/snap-user-dir-perms-fixed:root
  • google-core:ubuntu-core-24-64:tests/main/snap-routine-portal-info
  • google-core:ubuntu-core-24-64:tests/main/snap-user-dir-perms-fixed:test

Copy link
Contributor

@zyga zyga left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

Looking at the code we could save some garbage by using a bytes.Buffer and passing it so that we edit the tail of the path. Separately I think we could simplify quite a bit of our "root dir is here" code with https://pkg.go.dev/io/fs#Sub - so to pass an fs.FS of appropriate subtype and use fs.Sub to peek into deeper layers.

@@ -683,12 +681,12 @@ func probeKernelFeaturesInDirRecursively(dir string, prefix string) ([]string, e
}
features := make([]string, 0, len(dentries))
for _, fi := range dentries {
featureName := fi.Name()
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

won't this make /sys/kernel/securtiy/apparmor/features/capability show up as a kernel feature now?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, as-is it would show up as a feature. The file itself won't be read, though. Is this something we want to avoid?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure if capability is indicative of any particular feature in AppArmor, I'm assuming it's not and as such it'd be better to skip it.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It looks like the boolean files we care about should all be subdirectories of /sys/kernel/security/apparmor/features/policy/, so perhaps this change could be narrowed to only include files under that directory? I don't think there's harm in including all files, but we could be more selective.

More info on the tagging support checks here, for example: https://docs.google.com/document/d/1_WvEM9Qi2Je2Vwulzv5TzHwLJ8ld0W8gTNESZZd9VsY/edit?tab=t.0#heading=h.f728esb5to7y

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

looking at https://elixir.bootlin.com/linux/v6.13.4/source/security/apparmor/apparmorfs.c#L2404 capability seems to be an actual 'feature'. It's actually quite confusing how we're approaching this e.g. there's just one network_v8 entry, even though network_v8/af_mask has multiple values inside, but we have 10+ entries for kernel:policy:permstable32:.*. Maybe we should have been more selective about the features we list and only include the ones we know/care about rather than adding all of them simply because entries are there.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reply from the kernel team about what it is/means was this:

it lists the capabilities that are supported in that kernel. capabilities are not encoded the same way that the other rules are (using the dfa). each capability is represented as a bit of a uint64_t

@olivercalder olivercalder removed the request for review from ndyer February 27, 2025 14:51
Copy link
Contributor

@bboozzoo bboozzoo left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@olivercalder olivercalder force-pushed the expand-apparmor-kernel-features-to-files branch from 354c448 to 15298ad Compare February 27, 2025 18:24
Previously, only directories under /sys/kernel/security/apparmor/features
were included in the probed kernel features list. However, boolean files
are sometimes used to indicate support for particular features as well.

This commit extends the probed features to include the presence of
files, as well as directories.

Though we are looking in a sysfs, /sys/kernel/security/apparmor/features
is entirely managed by apparmorfs, so it should not be a problem to
include files there in the kernel features (and by extension in the
system key).

Signed-off-by: Oliver Calder <[email protected]>
@olivercalder olivercalder force-pushed the expand-apparmor-kernel-features-to-files branch from 15298ad to 244ecd6 Compare February 28, 2025 14:43
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants