On Tue, Feb 13, 2018 at 7:43 AM, Sargun Dhillon <sargun@xxxxxxxxx> 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 _______________________________________________ Containers mailing list Containers@xxxxxxxxxxxxxxxxxxxxxxxxxx https://lists.linuxfoundation.org/mailman/listinfo/containers