mbox series

[0/3] bpf: Store/dump license string for loaded program

Message ID 20180423065927.23127-1-jolsa@kernel.org
Headers show
Series bpf: Store/dump license string for loaded program | expand

Message

Jiri Olsa April 23, 2018, 6:59 a.m. UTC
hi,
sending the change to store and dump the license
info for loaded BPF programs. It's important for
us get the license info, when investigating on
screwed up machine.

Adding change to bpftool to dump the license via:

  # bpftool prog list
  1: kprobe  name func_begin  tag 59bef35a42fda602 license GPL
          loaded_at Apr 22/15:46  uid 0
          xlated 272B  not jited  memlock 4096B  map_ids 1

  # bpftool prog show --json
  [{"id":1,"type":"kprobe","name":"fun ... ,"license":"GPL", ... ]

Also available at:
  https://git.kernel.org/pub/scm/linux/kernel/git/jolsa/perf.git
  bpf/license

thanks,
jirka


---
Jiri Olsa (3):
      bpf: Store license string for loaded program
      tools bpf: Sync bpf.h uapi header
      tools bpftool: Display license in prog show/list

 include/linux/bpf.h            | 1 +
 include/uapi/linux/bpf.h       | 3 +++
 kernel/bpf/core.c              | 1 +
 kernel/bpf/syscall.c           | 7 ++++++-
 tools/bpf/bpftool/prog.c       | 4 ++++
 tools/include/uapi/linux/bpf.h | 4 ++++
 6 files changed, 19 insertions(+), 1 deletion(-)

Comments

Alexei Starovoitov April 23, 2018, 8:11 p.m. UTC | #1
On Mon, Apr 23, 2018 at 08:59:24AM +0200, Jiri Olsa wrote:
> hi,
> sending the change to store and dump the license
> info for loaded BPF programs. It's important for
> us get the license info, when investigating on
> screwed up machine.

hmm. boolean flag whether bpf prog is gpl or not
is already exposed via bpf_prog_info.
I see no point of wasting extra 128 bytes of kernel memory.
Jiri Olsa April 25, 2018, 10:17 a.m. UTC | #2
On Mon, Apr 23, 2018 at 02:11:36PM -0600, Alexei Starovoitov wrote:
> On Mon, Apr 23, 2018 at 08:59:24AM +0200, Jiri Olsa wrote:
> > hi,
> > sending the change to store and dump the license
> > info for loaded BPF programs. It's important for
> > us get the license info, when investigating on
> > screwed up machine.
> 
> hmm. boolean flag whether bpf prog is gpl or not
> is already exposed via bpf_prog_info.

hum, I can't see that (on bpf-next/master)
would the attached change be ok with you?

jirka


---
diff --git a/include/uapi/linux/bpf.h b/include/uapi/linux/bpf.h
index e6679393b687..2ce9c9d41c2b 100644
--- a/include/uapi/linux/bpf.h
+++ b/include/uapi/linux/bpf.h
@@ -1062,6 +1062,7 @@ struct bpf_prog_info {
 	__u32 ifindex;
 	__u64 netns_dev;
 	__u64 netns_ino;
+	__u16 gpl_compatible:1;
 } __attribute__((aligned(8)));
 
 struct bpf_map_info {
diff --git a/kernel/bpf/syscall.c b/kernel/bpf/syscall.c
index fe23dc5a3ec4..7bb4ff1c770a 100644
--- a/kernel/bpf/syscall.c
+++ b/kernel/bpf/syscall.c
@@ -1914,6 +1914,7 @@ static int bpf_prog_get_info_by_fd(struct bpf_prog *prog,
 	info.load_time = prog->aux->load_time;
 	info.created_by_uid = from_kuid_munged(current_user_ns(),
 					       prog->aux->user->uid);
+	info.gpl_compatible = prog->gpl_compatible;
 
 	memcpy(info.tag, prog->tag, sizeof(prog->tag));
 	memcpy(info.name, prog->aux->name, sizeof(prog->aux->name));
Alexei Starovoitov April 25, 2018, 4:15 p.m. UTC | #3
On Wed, Apr 25, 2018 at 12:17:13PM +0200, Jiri Olsa wrote:
> On Mon, Apr 23, 2018 at 02:11:36PM -0600, Alexei Starovoitov wrote:
> > On Mon, Apr 23, 2018 at 08:59:24AM +0200, Jiri Olsa wrote:
> > > hi,
> > > sending the change to store and dump the license
> > > info for loaded BPF programs. It's important for
> > > us get the license info, when investigating on
> > > screwed up machine.
> > 
> > hmm. boolean flag whether bpf prog is gpl or not
> > is already exposed via bpf_prog_info.
> 
> hum, I can't see that (on bpf-next/master)
> would the attached change be ok with you?
> 
> jirka
> 
> 
> ---
> diff --git a/include/uapi/linux/bpf.h b/include/uapi/linux/bpf.h
> index e6679393b687..2ce9c9d41c2b 100644
> --- a/include/uapi/linux/bpf.h
> +++ b/include/uapi/linux/bpf.h
> @@ -1062,6 +1062,7 @@ struct bpf_prog_info {
>  	__u32 ifindex;
>  	__u64 netns_dev;
>  	__u64 netns_ino;
> +	__u16 gpl_compatible:1;
>  } __attribute__((aligned(8)));

ahh. I swear there were patches to add it and I thought we accepted them.
Also just noticed that commit 675fc275a3a2d added 4-byte hole in there.
So I'm thinking we can fill the hole with 
 	__u32 ifindex;
+	__u32 gpl_compatible:1;
 	__u64 netns_dev;
 	__u64 netns_ino;

and keep adding bit fields in there without breaking user space.
Such patch would need to go to bpf tree.
Jiri Olsa April 25, 2018, 4:20 p.m. UTC | #4
On Wed, Apr 25, 2018 at 10:15:29AM -0600, Alexei Starovoitov wrote:
> On Wed, Apr 25, 2018 at 12:17:13PM +0200, Jiri Olsa wrote:
> > On Mon, Apr 23, 2018 at 02:11:36PM -0600, Alexei Starovoitov wrote:
> > > On Mon, Apr 23, 2018 at 08:59:24AM +0200, Jiri Olsa wrote:
> > > > hi,
> > > > sending the change to store and dump the license
> > > > info for loaded BPF programs. It's important for
> > > > us get the license info, when investigating on
> > > > screwed up machine.
> > > 
> > > hmm. boolean flag whether bpf prog is gpl or not
> > > is already exposed via bpf_prog_info.
> > 
> > hum, I can't see that (on bpf-next/master)
> > would the attached change be ok with you?
> > 
> > jirka
> > 
> > 
> > ---
> > diff --git a/include/uapi/linux/bpf.h b/include/uapi/linux/bpf.h
> > index e6679393b687..2ce9c9d41c2b 100644
> > --- a/include/uapi/linux/bpf.h
> > +++ b/include/uapi/linux/bpf.h
> > @@ -1062,6 +1062,7 @@ struct bpf_prog_info {
> >  	__u32 ifindex;
> >  	__u64 netns_dev;
> >  	__u64 netns_ino;
> > +	__u16 gpl_compatible:1;
> >  } __attribute__((aligned(8)));
> 
> ahh. I swear there were patches to add it and I thought we accepted them.
> Also just noticed that commit 675fc275a3a2d added 4-byte hole in there.
> So I'm thinking we can fill the hole with 
>  	__u32 ifindex;
> +	__u32 gpl_compatible:1;
>  	__u64 netns_dev;
>  	__u64 netns_ino;
> 
> and keep adding bit fields in there without breaking user space.
> Such patch would need to go to bpf tree.
> 

ok, will post v2 with that

thanks,
jirka