diff options
author | Tom Hromatka <tom.hromatka@oracle.com> | 2022-03-18 12:57:29 -0600 |
---|---|---|
committer | Tom Hromatka <tom.hromatka@oracle.com> | 2022-03-18 12:57:29 -0600 |
commit | 89644faae8489e9af8363efed0f2904d55d922db (patch) | |
tree | 1e220697dfe62b43c299aad14b56c196fd91bcd8 | |
parent | 2b998990f3ac7a52ccedbd3ba8bd4e301b6d2552 (diff) | |
download | libseccomp-89644faae8489e9af8363efed0f2904d55d922db.tar.gz |
bpf: pfc: Add handling for 0 syscalls in the binary tree
Handle the unlikely case where a user has chosen the
binary tree optimization but has zero syscalls in their
filter.
Fixes: https://github.com/seccomp/libseccomp/issues/370
Fixes: a3732b32b8e67 ("bpf:pfc: Add optimization option to use a binary tree")
Signed-off-by: Tom Hromatka <tom.hromatka@oracle.com>
Acked-by: Paul Moore <paul@paul-moore.com>
(cherry picked from commit 2de3b87122c18b58b3e2b32ab2e81ac43774a7aa)
-rw-r--r-- | src/gen_bpf.c | 3 | ||||
-rw-r--r-- | src/gen_pfc.c | 3 |
2 files changed, 6 insertions, 0 deletions
diff --git a/src/gen_bpf.c b/src/gen_bpf.c index 5f88972..90c38cc 100644 --- a/src/gen_bpf.c +++ b/src/gen_bpf.c @@ -1342,6 +1342,9 @@ static int _get_bintree_levels(unsigned int syscall_cnt) { unsigned int i = 2, max_level = SYSCALLS_PER_NODE * 2; + if (syscall_cnt == 0) + return 0; + while (max_level < syscall_cnt) { max_level <<= 1; i++; diff --git a/src/gen_pfc.c b/src/gen_pfc.c index 405f080..2e38eb6 100644 --- a/src/gen_pfc.c +++ b/src/gen_pfc.c @@ -271,6 +271,9 @@ static int _get_bintree_levels(unsigned int syscall_cnt, /* Only use a binary tree if requested */ return 0; + if (syscall_cnt == 0) + return 0; + do { max_level = SYSCALLS_PER_NODE << i; i++; |