procfs: workarounds for AppArmor design flaw
I maintainer di solito rispondono entro 1 giorno
Nessuno ha ancora preso questa issue.
Valutazione
- Difficoltà
- 5/5
- Tempo stimato
- Più di una settimana
- Idoneità per principianti
- 25/100
- Tipo di issue
- Bug
- Chiarezza
- Abbastanza chiara
- Stato di attività
- Ferma
- Stack tecnologico
- linux, rust
- Ambito
- operating-systems, security
Direzione di ricerca
Start by reading the detached procfs mount discussion and the linked AppArmor workaround in /etc/apparmor.d/abstractions/lxc/container-base; the issue explains how path based AppArmor rules misidentify paths on detached mounts. The issue does not specify a change to make or tests to run, and notes that a possible runc workaround could cause mount lifetime problems, so the desired outcome needs to be established before implementation.
Scritto dal modello di indicizzazione a partire dal testo della issue.
Descrizione
Okay, I've figured it out. This is really dumb. tl;dr: This is really an AppArmor bug (or even a design flaw if you prefer).
For context, the file we are trying to write to is
/proc/sys/net/ipv4/ip_unprivileged_port_start. @stgraber figured out that the problematic AppArmor rules are the rules they have which block writing to most/sysfiles. How is it possible that one affects the other?Well, the problem is that runc now uses a detached mount of
procfsto operate on (this avoids mount race attacks). Because detached mounts have not been attached to the filesystem,d_name(the kernel's facility for generating names for dentries) just generates a name that looks like/fooif you try to open a filefooinside the detachedprocfsmount. AFAICS this is what AppArmor uses to determine what file you are trying to write to (because AppArmor is path-based, andd_nameis the only way to get pathnames from dentries).This means that when we try to write to
/proc/sys/net/ipv4/ip_unprivileged_port_start, AppArmor sees this as us trying to write to/sys/net/ipv4/ip_unprivileged_port_startwhich is forbidden by the/sysdenial rules. I have attached a program that can show this behaviour using a detachedtmpfsmount, it's very trivial to trigger:% ./aa-bug & c1:~ # ./aa-bug & fd: /proc/2061/fd/5 [1] 2061 c1:~ # mkdir /proc/2061/fd/5/sys c1:~ # mkdir /proc/2061/fd/5/sys/foo mkdir: cannot create directory ‘/proc/2061/fd/5/sys/foo’: Permission deniedThere is a trivial workaround for this particular sysctl:
- deny /sys/[^fdck]*{,/**} wklx, + deny /sys/[^fdckn]*{,/**} wklx,(In
/etc/apparmor.d/abstractions/lxc/container-base.)But this doesn't help in the general case for all sysctls. @stgraber has just submitted https://github.com/lxc/incus/pull/2624 which just removes these rules entirely. I think AppArmor should not do this, because it's incredibly broken (literally any detached mount could match against a rule by accident), but this is unfortunately how AppArmor's design works.
From runc's side, we could in theory use this to our advantage -- if we created a
tmpfswith a subpath like.go-away-apparmorand then attached our procfs mount to that path, we might be able to subvert AppArmor. However, this has a risk of causing lifetime issues that would require a rework of how we do lookups -- thetmpfsmust not be closed after we attach to it because it will lazy-unmount the procfs...
Originally posted by @cyphar in #12484
- Lingua principale
- Rust
- Stelle
- 146
- Fork
- 12
- Merge medio
- 1g 16h
- PR unite (30g)
- 20
Preparare l'ambiente
- Include un Dockerfile o un file Docker Compose
- Nessun modello di pull request
- Nessuna guida per i contributori
Come iniziare
- Leggi tutta la issue e poi la guida ai contributi del progetto.
- Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
- Fai un fork del repository e lavora su un branch.
- Apri una pull request che faccia riferimento al numero della issue.
Altre issue di cyphar/libpathrs
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 68/100
cyphar/libpathrs#434 · 4 commenti ·
I maintainer di solito rispondono entro 1 giorno
-
rust tests
Difficoltà 4/5 3-5 giorni Idoneità per principianti 38/100
I maintainer di solito rispondono entro 1 giorno
-
api/procfs linux/upstream
Difficoltà 4/5 3-5 giorni Idoneità per principianti 44/100
I maintainer di solito rispondono entro 1 giorno
-
api/cffi bindings/go bindings/python ideas welcome
Difficoltà 5/5 Più di una settimana Idoneità per principianti 25/100
I maintainer di solito rispondono entro 1 giorno
-
linux/upstream
Difficoltà 5/5 Più di una settimana Idoneità per principianti 35/100
cyphar/libpathrs#377 · 3 commenti ·
I maintainer di solito rispondono entro 1 giorno
Tutte le issue di cyphar/libpathrs
Issue simili
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 73/100
haowjy/mars-agents#228 ·
I maintainer di solito rispondono entro 1 giorno
-
Difficoltà 1/5 Meno di un'ora Idoneità per principianti 68/100
redlib-org/redlib#604 ·
I maintainer di solito rispondono entro 3 giorni
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 68/100
I maintainer di solito rispondono entro 2 giorni
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 68/100
dividebysandwich/rust-dos#240 ·
I maintainer di solito rispondono entro 1 giorno
-
A-UI C-Bug S-Needs-Triage
Difficoltà 2/5 1-3 ore Idoneità per principianti 75/100
bevyengine/bevy#26330 ·
I maintainer di solito rispondono entro 2 giorni