Skip to content

contrib/apparmor: allow signals/ptrace for stacked-label exec processes - #13905

Closed
partiallymaxi wants to merge 1 commit into
containerd:mainfrom
partiallymaxi:apparmor-stacked-label-peers
Closed

partiallymaxi wants to merge 1 commit into
containerd:mainfrom
partiallymaxi:apparmor-stacked-label-peers

Conversation

@partiallymaxi

@partiallymaxi partiallymaxi commented Aug 4, 2026 •

Copy link
Copy Markdown

On kernels with AppArmor label stacking enabled by default (>= 6.17), processes entered through the runtime exec API carry the stacked label <profile>//&unconfined, while the container's init tree keeps the plain <profile> label. The profile's peer rules only match the plain label, so every signal sent by an exec-spawned process is denied, including root killing its own child and a process signalling itself.

This breaks timeout(1), exec-based debugging, and any exec'd client that signals its own children (observed: Slurm's srun wedging at exit).

The abi <abi/3.0> pin from #12864 doesn't help: signal mediation is part of the 3.0 ABI, and the pin changes mediation semantics, not the task's label. This PR adds symmetric signal and ptrace peer rules for the stacked label. Related: #12726, k3s-io/k3s#13625, moby/moby#47720.

Repro (containerd 2.1.4 / kernel 7.0; passes on 1.7.2 / kernel 6.5):

$ kubectl exec <pod> -- bash -c 'sleep 30 & kill -9 $!'
bash: kill: Permission denied

Verified on Ubuntu 25.10 (kernel 6.17.0-40) by driving the labels directly with aa-exec: unpatched rules deny kill-own-child and self-signal from the stacked label; patched rules restore both, plain-label behavior is unchanged, and stacked tasks still cannot signal unconfined (host) processes.

Security considerations: the new peer string matches only tasks whose entire label is <profile>//&unconfined, i.e. the runtime-exec sessions themselves. Host processes (plain unconfined) do not match and gain nothing new; the scope mirrors the existing peer=<profile> rule, and ptrace remains gated by Yama and capability checks.

Happy to switch to the glob form (peer="<profile>//**") if preferred; the explicit stack is the minimal grant matching what the kernel emits today. A cherry-pick to release/2.1 would be appreciated (affected fleet runs 2.1.4).

Copilot AI lite review requested due to automatic review settings August 4, 2026 23:48
@github-project-automation github-project-automation Bot moved this to Needs Triage in Pull Request Review Aug 4, 2026

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Pull request overview

Updates the default AppArmor profile template to handle Linux kernels where AppArmor label stacking causes runtime exec sessions to run under a stacked label (<profile>//&unconfined). This prevents signal and ptrace denials between exec-spawned processes and the container’s init tree under the same base profile.

Changes:

  • Add signal peer rules allowing stacked-label ({{.Name}}//&unconfined) tasks to signal each other and non-stacked tasks under the same profile.
  • Add matching ptrace peer rules for the same stacked-label exec session case.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@partiallymaxi
partiallymaxi force-pushed the apparmor-stacked-label-peers branch from 16c942e to fb89396 Compare August 4, 2026 23:53
Copilot AI review requested due to automatic review settings August 6, 2026 23:46
@partiallymaxi
partiallymaxi force-pushed the apparmor-stacked-label-peers branch from fb89396 to b1753cd Compare August 6, 2026 23:46

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Pull request overview

Copilot reviewed 1 out of 1 changed files in this pull request and generated no new comments.

@lexfrei

lexfrei commented Aug 14, 2026

Copy link
Copy Markdown

We hit the same bug from different directions. I've written up the coverage comparison in #12887, including a live-kernel table, since the two are easier to judge side by side than separately.

Short version: the literal //&unconfined covers the reported case, and a glob additionally covers stacks deeper than two components and the reverse component order, which shows up whenever the stacked component sorts before the profile name. You offered to switch to the glob form in your description, so this may come down to just that. I'm fine with either PR being the one that lands, and would rather the right rule ends up in the tree than mine specifically.

On kernels with AppArmor label stacking enabled by default (>= 6.17),
processes entered through the runtime exec API carry the stacked label
"<profile>//&unconfined" while the container's init tree carries the
plain "<profile>" label. The template's peer rules only match the plain
label, so every signal sent by an exec-spawned process is denied with
EPERM, including root killing its own child, a process signalling
itself, and timeout(1) killing its timed-out command. Exec-based
probes, debugging sessions, and clients that signal their own children
break (observed live: Slurm's srun wedging forever at exit).

The abi <abi/3.0> pin does not help: signal mediation is part of the
3.0 ABI, and the pin changes mediation semantics, not the task's label,
so peer string matching against the stacked label still fails.

Verified on Ubuntu 25.10 (kernel 6.17.0-40, stacking default-on) via
aa-exec stacked-label repro: unpatched rules deny kill of own child and
self-signal from the stacked label; patched rules restore both,
plain-label behavior unchanged, and stacked tasks still cannot signal
unconfined (host) processes.

Signed-off-by: Maxi Saparov <[email protected]>
Copilot AI review requested due to automatic review settings August 21, 2026 16:12
@partiallymaxi
partiallymaxi force-pushed the apparmor-stacked-label-peers branch from b1753cd to 2e3ace0 Compare August 21, 2026 16:12

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Pull request overview

Copilot reviewed 1 out of 1 changed files in this pull request and generated 1 comment.

Comment on lines +68 to +69
# Exec sessions carry a stacked label on kernels with label stacking (>= 6.17).
signal (send,receive) peer="{{.Name}}//&unconfined",
@kubernetes-prow

Copy link
Copy Markdown

PR needs rebase.

Details

Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes-sigs/prow repository.

@partiallymaxi

Copy link
Copy Markdown
Author

closing in favor of #12887

@github-project-automation github-project-automation Bot moved this from Needs Triage to Done in Pull Request Review Nov 18, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

Development

Successfully merging this pull request may close these issues.

3 participants