Skip to content

Commit f236aad

Browse files
authored
Update the strict runc patches for 1.3.0 (#5204)
1 parent 0e74d83 commit f236aad

File tree

3 files changed

+139
-0
lines changed

3 files changed

+139
-0
lines changed
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
From 5cdb43bdc26e81be36d93fd8b81b7de6ad152c22 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 17d36ed1..fb159f3c 100644
12+
--- a/libcontainer/apparmor/apparmor_linux.go
13+
+++ b/libcontainer/apparmor/apparmor_linux.go
14+
@@ -53,9 +53,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+
@@ -69,5 +69,5 @@ func applyProfile(name string) error {
28+
return nil
29+
}
30+
31+
- return changeOnExec(name)
32+
+ return changeProfile(name)
33+
}
34+
--
35+
2.49.0
36+
Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
From 259ebdf71e84433f55c1b28efb206ccc3a1b2736 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 2/3] 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 92c6ef77..e9a55e31 100644
20+
--- a/libcontainer/setns_init_linux.go
21+
+++ b/libcontainer/setns_init_linux.go
22+
@@ -62,11 +62,6 @@ func (l *linuxSetnsInit) Init() error {
23+
return fmt.Errorf("failed to setup pidfd: %w", 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+
if l.config.Config.Umask != nil {
32+
unix.Umask(int(*l.config.Config.Umask))
33+
}
34+
@@ -106,6 +101,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+
if l.config.Config.Personality != nil {
44+
if err := setupPersonality(l.config.Config); err != nil {
45+
return err
46+
--
47+
2.49.0
48+
Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
From 7f91e445a8731856e2d22b2295d8438e07cf2bf7 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 | 17 +++++++++--------
9+
1 file changed, 9 insertions(+), 8 deletions(-)
10+
11+
diff --git a/libcontainer/standard_init_linux.go b/libcontainer/standard_init_linux.go
12+
index 384750bf..ccd9297a 100644
13+
--- a/libcontainer/standard_init_linux.go
14+
+++ b/libcontainer/standard_init_linux.go
15+
@@ -126,9 +126,6 @@ func (l *linuxStandardInit) Init() error {
16+
return &os.SyscallError{Syscall: "setdomainname", 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+
@@ -149,11 +146,6 @@ func (l *linuxStandardInit) Init() error {
26+
if err != nil {
27+
return fmt.Errorf("can't get pdeath signal: %w", err)
28+
}
29+
- if l.config.NoNewPrivileges {
30+
- if err := unix.Prctl(unix.PR_SET_NO_NEW_PRIVS, 1, 0, 0, 0); err != nil {
31+
- return &os.SyscallError{Syscall: "prctl(SET_NO_NEW_PRIVS)", Err: err}
32+
- }
33+
- }
34+
35+
if err := setupScheduler(l.config); err != nil {
36+
return err
37+
@@ -169,6 +161,15 @@ func (l *linuxStandardInit) Init() error {
38+
if err := syncParentReady(l.pipe); err != nil {
39+
return fmt.Errorf("sync ready: %w", err)
40+
}
41+
+ if err := apparmor.ApplyProfile(l.config.AppArmorProfile); err != nil {
42+
+ return fmt.Errorf("apply apparmor profile: %w", err)
43+
+ }
44+
+ if l.config.NoNewPrivileges {
45+
+ if err := unix.Prctl(unix.PR_SET_NO_NEW_PRIVS, 1, 0, 0, 0); err != nil {
46+
+ return fmt.Errorf("set nonewprivileges: %w", err)
47+
+ }
48+
+ }
49+
+
50+
if err := selinux.SetExecLabel(l.config.ProcessLabel); err != nil {
51+
return fmt.Errorf("can't set process label: %w", err)
52+
}
53+
--
54+
2.43.0
55+

0 commit comments

Comments
 (0)