Skip to content

Conversation

@tomponline
Copy link
Member

When nesting is enabled, it's possible for the container to get a clean copy of /proc or /sys mounted anywhere without AppArmor being able to mediate. So there's little point in trying to apply safety checks on top of the main /proc and /sys.

On top of that, we've recently discovered that AppArmor doesn't properly handle file access relative to a file descriptor, causing a bunch of those checks to deny access when they shouldn't.

Related to lxc/incus#2623

Fixes #16902

(cherry picked from commit 1fbe4bffb9748cc3b07aaf5db310d463c1e827d0)

License: Apache-2.0

…n nesting enabled

When nesting is enabled, it's possible for the container to get a clean
copy of /proc or /sys mounted anywhere without AppArmor being able to
mediate. So there's little point in trying to apply safety checks on top
of the main /proc and /sys.

On top of that, we've recently discovered that AppArmor doesn't properly
handle file access relative to a file descriptor, causing a bunch of
those checks to deny access when they shouldn't.

Related to lxc/incus#2623

Fixes canonical#16902

Signed-off-by: Stéphane Graber <stgraber@stgraber.org>
(cherry picked from commit 1fbe4bffb9748cc3b07aaf5db310d463c1e827d0)
Signed-off-by: Thomas Parrott <thomas.parrott@canonical.com>
License: Apache-2.0
@tomponline tomponline self-assigned this Nov 11, 2025
@tomponline tomponline requested a review from Copilot November 11, 2025 09:55
@tomponline tomponline changed the title lxd/apparmor/instance/lxc: Don't bother with sys/proc protections when nesting enabled (from Incus) Container: Don't bother with sys/proc protections when nesting enabled (from Incus) Nov 11, 2025
Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull Request Overview

This PR cherry-picks a security enhancement from Incus that conditionally disables AppArmor protections for /proc and /sys when container nesting is enabled. When nesting is active, containers can mount clean copies of these filesystems anywhere without AppArmor mediation, rendering the main protections ineffective. Additionally, AppArmor has issues with file descriptor-relative access that cause spurious denials.

Key changes:

  • Wrapped /proc/sys and /sys safety checks in {{- if not .nesting }} conditionals
  • Applied the same conditional logic to AppArmor stacking-related /sys/kernel protections

@tomponline tomponline requested a review from mihalicyn November 11, 2025 10:45
@tomponline tomponline marked this pull request as ready for review November 11, 2025 10:45
Copy link
Member

@mihalicyn mihalicyn left a comment

Choose a reason for hiding this comment

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

LGTM

@tomponline tomponline merged commit 3e14478 into canonical:main Nov 11, 2025
76 checks passed
tomponline added a commit to tomponline/lxd-ci that referenced this pull request Nov 11, 2025
Related to canonical/lxd#16927

Signed-off-by: Thomas Parrott <thomas.parrott@canonical.com>
tomponline added a commit to tomponline/lxd-ci that referenced this pull request Nov 11, 2025
Related to canonical/lxd#16927

Signed-off-by: Thomas Parrott <thomas.parrott@canonical.com>
tomponline added a commit that referenced this pull request Nov 11, 2025
tomponline added a commit to canonical/lxd-ci that referenced this pull request Nov 11, 2025
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.

docker does not work inside LXD containers since runc 1.3.3

2 participants