Skip to content

Commit 1658a9a

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 2a14cec commit 1658a9a

File tree

1 file changed

+14
-0
lines changed

1 file changed

+14
-0
lines changed

libcontainer/seccomp/seccomp_linux.go

+14
Original file line numberDiff line numberDiff line change
@@ -110,6 +110,20 @@ func InitSeccomp(config *configs.Seccomp) (int, error) {
110110
}
111111
}
112112

113+
// Enable libseccomp binary tree optimization. The number 8 is chosen
114+
// semi-arbitrarily, considering the following:
115+
// 1. libseccomp <= 2.5.4 misbehaves when binary tree optimization
116+
// is enabled and there are 0 rules.
117+
// 2. All known libseccomp versions (2.5.0 to 2.5.4) generate a binary
118+
// tree with 4 syscalls per node.
119+
if len(config.Syscalls) > 8 {
120+
err = filter.SetOptimize(2)
121+
if err != nil {
122+
// The error is not fatal and is probably means we have older libseccomp.
123+
logrus.Debugf("seccomp binary tree optimization not available: %v", err)
124+
}
125+
}
126+
113127
// Unset no new privs bit
114128
if err := filter.SetNoNewPrivsBit(false); err != nil {
115129
return -1, fmt.Errorf("error setting no new privileges: %w", err)

0 commit comments

Comments
 (0)