Skip to content

Commit fdcc9d3

Browse files
committed
apparmor: use safe procfs API for labels
EnsureProcHandle only protects us against a tmpfs mount, but the risk of a procfs path being used (such as /proc/self/sched) has been known for a while. Now that filepath-securejoin has a reasonably safe procfs API, switch to it. Fixes: GHSA-cgrx-mc8f-2prm CVE-2025-52881 Signed-off-by: Aleksa Sarai <[email protected]>
1 parent aee7d3f commit fdcc9d3

File tree

1 file changed

+7
-4
lines changed

1 file changed

+7
-4
lines changed

libcontainer/apparmor/apparmor_linux.go

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,9 @@ import (
66
"os"
77
"sync"
88

9+
"golang.org/x/sys/unix"
10+
11+
"github.com/opencontainers/runc/internal/pathrs"
912
"github.com/opencontainers/runc/libcontainer/utils"
1013
)
1114

@@ -36,15 +39,15 @@ func setProcAttr(attr, value string) error {
3639
// Under AppArmor you can only change your own attr, so there's no reason
3740
// to not use /proc/thread-self/ (instead of /proc/<tid>/, like libapparmor
3841
// does).
39-
attrPath, closer := utils.ProcThreadSelf(attrSubPath)
40-
defer closer()
41-
42-
f, err := os.OpenFile(attrPath, os.O_WRONLY, 0)
42+
f, closer, err := pathrs.ProcThreadSelfOpen(attrSubPath, unix.O_WRONLY|unix.O_CLOEXEC)
4343
if err != nil {
4444
return err
4545
}
46+
defer closer()
4647
defer f.Close()
4748

49+
// NOTE: This is not really necessary since securejoin.ProcThreadSelf
50+
// verifies this in a far stricter sense than EnsureProcHandle.
4851
if err := utils.EnsureProcHandle(f); err != nil {
4952
return err
5053
}

0 commit comments

Comments
 (0)