Skip to content

Commit f966995

Browse files
authored
Add updated strict patches for runc (#4774)
1 parent bd1ef3b commit f966995

File tree

3 files changed

+139
-0
lines changed

3 files changed

+139
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
From a367e391600dfab0d9eb3deaec4db300a2fb1fa1 Mon Sep 17 00:00:00 2001
2+
From: Alberto Mardegan <[email protected]>
3+
Date: Wed, 16 Jun 2021 15:04:16 +0300
4+
Subject: [PATCH 1/3] apparmor: change profile immediately, not on exec
5+
6+
---
7+
libcontainer/apparmor/apparmor_linux.go | 8 ++++----
8+
1 file changed, 4 insertions(+), 4 deletions(-)
9+
10+
diff --git a/libcontainer/apparmor/apparmor_linux.go b/libcontainer/apparmor/apparmor_linux.go
11+
index 8b1483c..292cfa6 100644
12+
--- a/libcontainer/apparmor/apparmor_linux.go
13+
+++ b/libcontainer/apparmor/apparmor_linux.go
14+
@@ -48,9 +48,9 @@ func setProcAttr(attr, value string) error {
15+
return err
16+
}
17+
18+
-// changeOnExec reimplements aa_change_onexec from libapparmor in Go
19+
-func changeOnExec(name string) error {
20+
- if err := setProcAttr("exec", "exec "+name); err != nil {
21+
+// changeProfile reimplements aa_change_profile from libapparmor in Go
22+
+func changeProfile(name string) error {
23+
+ if err := setProcAttr("current", "changeprofile "+name); err != nil {
24+
return fmt.Errorf("apparmor failed to apply profile: %w", err)
25+
}
26+
return nil
27+
@@ -64,5 +64,5 @@ func applyProfile(name string) error {
28+
return nil
29+
}
30+
31+
- return changeOnExec(name)
32+
+ return changeProfile(name)
33+
}
34+
--
35+
2.34.1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
From b145a4ac9e9cd09e82d35e0998c6ddee80854275 Mon Sep 17 00:00:00 2001
2+
From: Angelos Kolaitis <[email protected]>
3+
Date: Thu, 1 Feb 2024 11:23:08 +0200
4+
Subject: [PATCH] setns_init_linux: set the NNP flag after changing the
5+
apparmor profile
6+
7+
With the current version of the AppArmor kernel module, it's not
8+
possible to switch the AppArmor profile if the NoNewPrivileges flag is
9+
set. So, we invert the order of the two operations.
10+
11+
Adjusts the previous patch for runc version v1.1.12
12+
13+
Co-Authored-By: Alberto Mardegan <[email protected]>
14+
---
15+
libcontainer/setns_init_linux.go | 10 +++++-----
16+
1 file changed, 5 insertions(+), 5 deletions(-)
17+
18+
diff --git a/libcontainer/setns_init_linux.go b/libcontainer/setns_init_linux.go
19+
index bb358901..6c1b16bd 100644
20+
--- a/libcontainer/setns_init_linux.go
21+
+++ b/libcontainer/setns_init_linux.go
22+
@@ -57,11 +57,6 @@ func (l *linuxSetnsInit) Init() error {
23+
return err
24+
}
25+
}
26+
- if l.config.NoNewPrivileges {
27+
- if err := unix.Prctl(unix.PR_SET_NO_NEW_PRIVS, 1, 0, 0, 0); err != nil {
28+
- return err
29+
- }
30+
- }
31+
32+
// Tell our parent that we're ready to exec. This must be done before the
33+
// Seccomp rules have been applied, because we need to be able to read and
34+
@@ -93,6 +88,11 @@ func (l *linuxSetnsInit) Init() error {
35+
if err := apparmor.ApplyProfile(l.config.AppArmorProfile); err != nil {
36+
return err
37+
}
38+
+ if l.config.NoNewPrivileges {
39+
+ if err := unix.Prctl(unix.PR_SET_NO_NEW_PRIVS, 1, 0, 0, 0); err != nil {
40+
+ return err
41+
+ }
42+
+ }
43+
44+
// Check for the arg before waiting to make sure it exists and it is
45+
// returned as a create time error.
46+
--
47+
2.43.0
48+
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
From f9e0ca2f29c6c77ea9bc9c52929dac3915545dd9 Mon Sep 17 00:00:00 2001
2+
From: Alberto Mardegan <[email protected]>
3+
Date: Thu, 17 Jun 2021 14:31:35 +0300
4+
Subject: [PATCH] standard_init_linux: change AppArmor profile as late as
5+
possible
6+
7+
---
8+
libcontainer/standard_init_linux.go | 18 +++++++++---------
9+
1 file changed, 9 insertions(+), 9 deletions(-)
10+
11+
diff --git a/libcontainer/standard_init_linux.go b/libcontainer/standard_init_linux.go
12+
index d9a6a224..e4d603e4 100644
13+
--- a/libcontainer/standard_init_linux.go
14+
+++ b/libcontainer/standard_init_linux.go
15+
@@ -127,10 +127,6 @@ func (l *linuxStandardInit) Init() error {
16+
return &os.SyscallError{Syscall: "sethostname", Err: err}
17+
}
18+
}
19+
- if err := apparmor.ApplyProfile(l.config.AppArmorProfile); err != nil {
20+
- return fmt.Errorf("unable to apply apparmor profile: %w", err)
21+
- }
22+
-
23+
for key, value := range l.config.Config.Sysctl {
24+
if err := writeSystemProperty(key, value); err != nil {
25+
return err
26+
@@ -150,11 +146,6 @@ func (l *linuxStandardInit) Init() error {
27+
if err != nil {
28+
return fmt.Errorf("can't get pdeath signal: %w", err)
29+
}
30+
- if l.config.NoNewPrivileges {
31+
- if err := unix.Prctl(unix.PR_SET_NO_NEW_PRIVS, 1, 0, 0, 0); err != nil {
32+
- return &os.SyscallError{Syscall: "prctl(SET_NO_NEW_PRIVS)", Err: err}
33+
- }
34+
- }
35+
36+
// Tell our parent that we're ready to exec. This must be done before the
37+
// Seccomp rules have been applied, because we need to be able to read and
38+
@@ -162,6 +153,15 @@ func (l *linuxStandardInit) Init() error {
39+
if err := syncParentReady(l.pipe); err != nil {
40+
return fmt.Errorf("sync ready: %w", err)
41+
}
42+
+ if err := apparmor.ApplyProfile(l.config.AppArmorProfile); err != nil {
43+
+ return fmt.Errorf("apply apparmor profile: %w", err)
44+
+ }
45+
+ if l.config.NoNewPrivileges {
46+
+ if err := unix.Prctl(unix.PR_SET_NO_NEW_PRIVS, 1, 0, 0, 0); err != nil {
47+
+ return fmt.Errorf("set nonewprivileges: %w", err)
48+
+ }
49+
+ }
50+
+
51+
if err := selinux.SetExecLabel(l.config.ProcessLabel); err != nil {
52+
return fmt.Errorf("can't set process label: %w", err)
53+
}
54+
--
55+
2.43.0
56+

0 commit comments

Comments
 (0)