lkml.org 
[lkml]   [2015]   [Apr]   [13]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
/
Date
SubjectRe: security problem with seccomp-filter
From
On Sun, Apr 12, 2015 at 2:33 PM, Felix von Leitner
<felix-linuxkernel@fefe.de> wrote:
>> What you're describing should work correctly (it's part of the
>> regression test suite we use). So, given that, I'd love to get to the
>> bottom of what you're seeing. Do you have a URL to your code? What
>> architecture are you running on?
>
> Well, I must be doing something wrong then.
> I extracted a test case from my program.
> I put it on http://ptrace.fefe.de/seccompfail.c
>
> It installs three seccomp filters, the last one containing this:
>
> DISALLOW_SYSCALL(prctl),
>
> with
>
> #define DISALLOW_SYSCALL(name) \
> BPF_JUMP(BPF_JMP+BPF_JEQ+BPF_K, __NR_##name, 0, 1), \
> BPF_STMT(BPF_RET+BPF_K, SECCOMP_RET_KILL)
>
> It is my understanding that that should then kill the process if the
> prctl syscall is called again.
>
> I test this by attempting to install the very same seccomp filter again,
> which calls prctl, but the process is not killed.
>
> What am I doing wrong?

Your filters don't load a syscall number, so the comparisons aren't
validating anything.

For example, from the working filter:

struct sock_filter filter[] = {
...
/* load the syscall number */
BPF_STMT(BPF_LD+BPF_W+BPF_ABS, offsetof(struct seccomp_data, nr)),
...
ALLOW_SYSCALL(close),
...
BPF_STMT(BPF_RET+BPF_K, SECCOMP_RET_KILL)
};

Where as yours from seccomp_denyfile and seccomp_denysocket don't load
the syscall number:

struct sock_filter filter[] = {
DISALLOW_SYSCALL(open),
...
BPF_STMT(BPF_RET+BPF_K, SECCOMP_RET_ALLOW),
};

When you add the load as the first statement in both filters:

struct sock_filter filter[] = {
BPF_STMT(BPF_LD+BPF_W+BPF_ABS, offsetof(struct seccomp_data, nr)),
DISALLOW_SYSCALL(open),
...
BPF_STMT(BPF_RET+BPF_K, SECCOMP_RET_ALLOW),
};

things work as expected:

$ ./seccompfail
Bad system call

I wonder if the validator could be improved to disallow comparisons
when the accumulator hasn't been written to. That might have helped
you find this mistake more quickly (i.e. getting EINVAL from your
filter install attempts).

-Kees

--
Kees Cook
Chrome OS Security


\
 
 \ /
  Last update: 2015-04-13 20:01    [W:0.064 / U:0.076 seconds]
©2003-2020 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site