Skip to content

Commit f52aed0

Browse files
committed
libct/seccomp: enable binary tree optimization
This makes libseccomp produce a BPF which uses a binary tree for syscalls (instead of linear set of if statements). It does not make sense to enable binary tree for small set of rules, so don't do that if we have less than 8 syscalls (the number is chosen arbitrarily). Signed-off-by: Kir Kolyshkin <[email protected]>
1 parent 6f5b4ff commit f52aed0

File tree

1 file changed

+9
-0
lines changed

1 file changed

+9
-0
lines changed

libcontainer/seccomp/seccomp_linux.go

+9
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,15 @@ func InitSeccomp(config *configs.Seccomp) (int, error) {
8686
}
8787
}
8888

89+
// Enable libseccomp binary tree optimization.
90+
if len(config.Syscalls) > 8 {
91+
err = filter.SetOptimize(2)
92+
if err != nil {
93+
// The error is not fatal and is probably means we have older libseccomp.
94+
logrus.Debugf("seccomp binary tree optimization not available: %v", err)
95+
}
96+
}
97+
8998
// Unset no new privs bit
9099
if err := filter.SetNoNewPrivsBit(false); err != nil {
91100
return -1, fmt.Errorf("error setting no new privileges: %w", err)

0 commit comments

Comments
 (0)