Skip to content

Commit

Permalink
libct/seccomp: enable binary tree optimization
Browse files Browse the repository at this point in the history
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]>
  • Loading branch information
kolyshkin committed Aug 4, 2022
1 parent 2a14cec commit 1658a9a
Showing 1 changed file with 14 additions and 0 deletions.
14 changes: 14 additions & 0 deletions libcontainer/seccomp/seccomp_linux.go
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,20 @@ func InitSeccomp(config *configs.Seccomp) (int, error) {
}
}

// Enable libseccomp binary tree optimization. The number 8 is chosen
// semi-arbitrarily, considering the following:
// 1. libseccomp <= 2.5.4 misbehaves when binary tree optimization
// is enabled and there are 0 rules.
// 2. All known libseccomp versions (2.5.0 to 2.5.4) generate a binary
// tree with 4 syscalls per node.
if len(config.Syscalls) > 8 {
err = filter.SetOptimize(2)
if err != nil {
// The error is not fatal and is probably means we have older libseccomp.
logrus.Debugf("seccomp binary tree optimization not available: %v", err)
}
}

// Unset no new privs bit
if err := filter.SetNoNewPrivsBit(false); err != nil {
return -1, fmt.Errorf("error setting no new privileges: %w", err)
Expand Down

0 comments on commit 1658a9a

Please sign in to comment.