lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  linux-cve-announce  PHC 
Open Source and information security mailing list archives
 
Hash Suite: Windows password security audit tool. GUI, reports in PDF.
[<prev] [next>] [<thread-prev] [day] [month] [year] [list]
Date:   Tue, 13 Feb 2018 12:18:18 -0800
From:   Kees Cook <keescook@...omium.org>
To:     Sargun Dhillon <sargun@...gun.me>
Cc:     Network Development <netdev@...r.kernel.org>,
        Alexei Starovoitov <ast@...nel.org>,
        Daniel Borkmann <daniel@...earbox.net>,
        Linux Containers <containers@...ts.linux-foundation.org>,
        Andy Lutomirski <luto@...capital.net>,
        Will Drewry <wad@...omium.org>
Subject: Re: [PATCH net-next 3/3] bpf: Add eBPF seccomp sample programs

On Tue, Feb 13, 2018 at 7:43 AM, Sargun Dhillon <sargun@...gun.me> wrote:
> +++ b/samples/bpf/seccomp1_kern.c
> @@ -0,0 +1,17 @@
> +#include <uapi/linux/seccomp.h>
> +#include <uapi/linux/bpf.h>
> +#include <uapi/linux/unistd.h>
> +#include "bpf_helpers.h"
> +#include <uapi/linux/errno.h>
> +
> +/* Returns EPERM when trying to close fd 999 */
> +SEC("seccomp")
> +int bpf_prog1(struct seccomp_data *ctx)
> +{
> +       if (ctx->nr == __NR_close && ctx->args[0] == 999)
> +               return SECCOMP_RET_ERRNO | EPERM;
> +
> +       return SECCOMP_RET_ALLOW;
> +}
> +
> +char _license[] SEC("license") = "GPL";
> [...]
> +++ b/samples/bpf/seccomp2_kern.c
> @@ -0,0 +1,24 @@
> +#include <uapi/linux/seccomp.h>
> +#include <uapi/linux/bpf.h>
> +#include <uapi/linux/unistd.h>
> +#include "bpf_helpers.h"
> +#include <uapi/linux/errno.h>
> +
> +static inline int unknown(struct seccomp_data *ctx)
> +{
> +       if (ctx->args[0] % 2 == 0)
> +               return SECCOMP_RET_KILL;
> +       return SECCOMP_RET_LOG;
> +}
> +
> +/* Returns errno on sched_yield syscall */
> +SEC("seccomp")
> +int bpf_prog1(struct seccomp_data *ctx)
> +{
> +       if (ctx->nr == __NR_sched_yield)
> +               return SECCOMP_RET_ERRNO | EPERM;
> +
> +       return SECCOMP_RET_ALLOW;
> +}
> +
> +char _license[] SEC("license") = "aGPL";

Nit: these should check architecture before syscall number. Since
they're samples, people look at them for and copy them regularly, they
should be as safe/correct as possible.

-Kees

-- 
Kees Cook
Pixel Security

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ