-
Notifications
You must be signed in to change notification settings - Fork 176
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
BUG: enabled binary tree optimization with no rules results in default action being ignored #370
Comments
Oh, that's fun :/ Although like you said the practical impact of this should be very close to nil. Still, this could be potentially bad so let's go ahead and add it to the v2.5.4 milestone. Any objections? |
Agreed. |
A bit more info which may be useful in chasing this down ... I modified a copy of "01-sim-allow.c" to this: #include <errno.h>
#include <unistd.h>
#include <seccomp.h>
#include "util.h"
int main(int argc, char *argv[])
{
int rc;
struct util_options opts;
scmp_filter_ctx ctx = NULL;
rc = util_getopt(argc, argv, &opts);
if (rc < 0)
goto out;
ctx = seccomp_init(SCMP_ACT_ALLOW);
if (ctx == NULL)
return ENOMEM;
#if 1
rc = seccomp_attr_set(ctx, SCMP_FLTATR_CTL_OPTIMIZE, 2);
if (rc < 0)
goto out;
#endif
rc = util_filter_output(&opts, ctx);
if (rc)
goto out;
out:
seccomp_release(ctx);
return (rc < 0 ? -rc : rc);
} When run without the binary tree optimization I get this:
When run with the binary tree optimization I get this:
The x86_64/x32 check is correct on both, but in the binary tree case the syscall number is reloaded (line 0005) and the only return option is "KILL". |
Well, as a quick-hack this "works": diff --git a/src/gen_bpf.c b/src/gen_bpf.c
index c878f443..54c28c5e 100644
--- a/src/gen_bpf.c
+++ b/src/gen_bpf.c
@@ -1692,6 +1692,7 @@ static struct bpf_blk *_gen_bpf_arch(struct bpf_state *state,
goto arch_failure;
blk_cnt += blks_added;
+#if 0
if (bintree_levels > 0) {
_BPF_INSTR(instr, _BPF_OP(state->arch, BPF_LD + BPF_ABS),
_BPF_JMP_NO, _BPF_JMP_NO,
@@ -1705,6 +1706,7 @@ static struct bpf_blk *_gen_bpf_arch(struct bpf_state *state,
b_bintree->acc_start = _ACC_STATE_UNDEF;
b_bintree->acc_end = _ACC_STATE_OFFSET(_BPF_OFFSET_SYSCALL);
}
+#endif
/* additional ABI filtering */
if ((state->arch->token == SCMP_ARCH_X86_64 || ... no idea yet if it still works for the other cases. |
Random observation, it looks like our binary trees may not always be properly balanced. |
Ran out of time today, if no one else has time to look at it I'll try to take another go at it later this week (or next). |
Out of simplicity I designed it to fill up the left node before filling the right node. (Each node is 4 syscalls.) My rationale was that this optimization really only makes sense on really, really large filters. An imbalance of (up to) 4 syscalls would be small compared to walking the entire filter of 200+ syscalls. |
No pressure either way. I technically feel like I own it - since it was my crazy idea :). But having another person get somewhat familiar with the code wouldn't be a bad thing either. I should have time this week to check it out. |
Haven't had a chance to test it, but I believe this is the fix:
|
This made both of the above reproducers work properly for me. |
Handle the unlikely case where a user has chosen the binary tree optimization but has zero syscalls in their filter. Fixes: seccomp#370 Fixes: a3732b3 ("bpf:pfc: Add optimization option to use a binary tree") Signed-off-by: Tom Hromatka <tom.hromatka@oracle.com>
Add a test that exercises the binary tree optimization but the seccomp filter has zero syscalls in it. Related-bug: seccomp#370 Signed-off-by: Tom Hromatka <tom.hromatka@oracle.com>
Add a test that exercises the binary tree optimization but the seccomp filter has zero syscalls in it. Related-bug: seccomp#370 Signed-off-by: Tom Hromatka <tom.hromatka@oracle.com>
Sorry for the delay, but this looks good to me. Feel free to patch and merge. Thanks @drakenclimber.
|
Add a test that exercises the binary tree optimization but the seccomp filter has zero syscalls in it. Related-bug: #370 Signed-off-by: Tom Hromatka <tom.hromatka@oracle.com> Acked-by: Paul Moore <paul@paul-moore.com>
Handle the unlikely case where a user has chosen the binary tree optimization but has zero syscalls in their filter. Fixes: #370 Fixes: a3732b3 ("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 2de3b87)
Surely this is a corner case, and enabling binary tree optimization is obviously useless then there are no rules, but it still feels like a bug.
The text was updated successfully, but these errors were encountered: