Re: [PATCH bpf-next v6 4/8] bpf: lsm: Implement attach, detach and execution

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On 25-Mär 18:49, Andrii Nakryiko wrote:
> On Wed, Mar 25, 2020 at 8:27 AM KP Singh <kpsingh@xxxxxxxxxxxx> wrote:
> >
> > From: KP Singh <kpsingh@xxxxxxxxxx>
> >
> > JITed BPF programs are dynamically attached to the LSM hooks
> > using BPF trampolines. The trampoline prologue generates code to handle
> > conversion of the signature of the hook to the appropriate BPF context.
> >
> > The allocated trampoline programs are attached to the nop functions
> > initialized as LSM hooks.
> >
> > BPF_PROG_TYPE_LSM programs must have a GPL compatible license and
> > and need CAP_SYS_ADMIN (required for loading eBPF programs).
> >
> > Upon attachment:
> >
> > * A BPF fexit trampoline is used for LSM hooks with a void return type.
> > * A BPF fmod_ret trampoline is used for LSM hooks which return an
> >   int. The attached programs can override the return value of the
> >   bpf LSM hook to indicate a MAC Policy decision.
> >
> > Signed-off-by: KP Singh <kpsingh@xxxxxxxxxx>
> > Reviewed-by: Brendan Jackman <jackmanb@xxxxxxxxxx>
> > Reviewed-by: Florent Revest <revest@xxxxxxxxxx>
> > ---
> >  include/linux/bpf_lsm.h | 11 ++++++++
> >  kernel/bpf/bpf_lsm.c    | 28 +++++++++++++++++++++
> >  kernel/bpf/btf.c        |  9 ++++++-
> >  kernel/bpf/syscall.c    | 56 ++++++++++++++++++++++++++++-------------
> >  kernel/bpf/trampoline.c | 17 ++++++++++---
> >  kernel/bpf/verifier.c   | 19 +++++++++++---
> >  6 files changed, 113 insertions(+), 27 deletions(-)
> >
> 
> [...]
> 
> > diff --git a/kernel/bpf/syscall.c b/kernel/bpf/syscall.c
> > index 85567a6ea5f9..3ba30fd6101e 100644
> > --- a/kernel/bpf/syscall.c
> > +++ b/kernel/bpf/syscall.c
> > @@ -25,6 +25,7 @@
> >  #include <linux/nospec.h>
> >  #include <linux/audit.h>
> >  #include <uapi/linux/btf.h>
> > +#include <linux/bpf_lsm.h>

[...]

> > -               if (prog->expected_attach_type == BPF_TRACE_RAW_TP)
> > +               if (prog->expected_attach_type == BPF_TRACE_RAW_TP) {
> 
> this should probably also ensure prog->type == BPF_PROG_TYPE_TRACING ?
> Otherwise you can trick kernel with BPF_PROG_TYPE_LSM and
> expected_attach_type == BPF_TRACE_RAW_TP, no?

Indeed, fixed. Thanks!

- KP

> 
> >                         tp_name = prog->aux->attach_func_name;
> > -               else
> > -                       return bpf_tracing_prog_attach(prog);
> > -       } else {
> > +                       break;
> > +               }
> > +               return bpf_tracing_prog_attach(prog);
> > +       case BPF_PROG_TYPE_RAW_TRACEPOINT:
> > +       case BPF_PROG_TYPE_RAW_TRACEPOINT_WRITABLE:
> >                 if (strncpy_from_user(buf,
> >                                       u64_to_user_ptr(attr->raw_tracepoint.name),
> >                                       sizeof(buf) - 1) < 0) {
> > @@ -2479,6 +2495,10 @@ static int bpf_raw_tracepoint_open(const union bpf_attr *attr)
> >                }
> 
> [...]



[Index of Archives]     [Linux Samsung SoC]     [Linux Rockchip SoC]     [Linux Actions SoC]     [Linux for Synopsys ARC Processors]     [Linux NFS]     [Linux NILFS]     [Linux USB Devel]     [Video for Linux]     [Linux Audio Users]     [Yosemite News]     [Linux Kernel]     [Linux SCSI]


  Powered by Linux