diff options
author | Tom Hromatka <tom.hromatka@oracle.com> | 2022-03-16 11:19:14 -0600 |
---|---|---|
committer | Tom Hromatka <tom.hromatka@oracle.com> | 2022-03-18 12:55:24 -0600 |
commit | 2de3b87122c18b58b3e2b32ab2e81ac43774a7aa (patch) | |
tree | 44f3921b7975e2dd28afe9966bdf9a7033663501 | |
parent | 5731b3c338f8f18b1d2b3aa300bbcb97af0fb34c (diff) | |
download | libseccomp-2de3b87122c18b58b3e2b32ab2e81ac43774a7aa.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>
-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 c878f44..7131761 100644 --- a/src/gen_bpf.c +++ b/src/gen_bpf.c @@ -1348,6 +1348,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 c7fb536..4916055 100644 --- a/src/gen_pfc.c +++ b/src/gen_pfc.c @@ -275,6 +275,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++; |