All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH 0/3] bpf: Store/dump license string for loaded program
@ 2018-04-23  6:59 Jiri Olsa
  2018-04-23  6:59 ` [PATCH 1/3] bpf: Store " Jiri Olsa
                   ` (3 more replies)
  0 siblings, 4 replies; 8+ messages in thread
From: Jiri Olsa @ 2018-04-23  6:59 UTC (permalink / raw)
  To: Alexei Starovoitov, Daniel Borkmann; +Cc: lkml, netdev, Quentin Monnet

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(-)

^ permalink raw reply	[flat|nested] 8+ messages in thread

* [PATCH 1/3] bpf: Store license string for loaded program
  2018-04-23  6:59 [PATCH 0/3] bpf: Store/dump license string for loaded program Jiri Olsa
@ 2018-04-23  6:59 ` Jiri Olsa
  2018-04-23  6:59 ` [PATCH 2/3] tools bpf: Sync bpf.h uapi header Jiri Olsa
                   ` (2 subsequent siblings)
  3 siblings, 0 replies; 8+ messages in thread
From: Jiri Olsa @ 2018-04-23  6:59 UTC (permalink / raw)
  To: Alexei Starovoitov, Daniel Borkmann; +Cc: lkml, netdev, Quentin Monnet

Storing the license string provided loaded program,
so it can be provided back when dumping the loaded
programs info (added in following change).

Signed-off-by: Jiri Olsa <jolsa@kernel.org>
---
 include/linux/bpf.h      | 1 +
 include/uapi/linux/bpf.h | 3 +++
 kernel/bpf/core.c        | 1 +
 kernel/bpf/syscall.c     | 7 ++++++-
 4 files changed, 11 insertions(+), 1 deletion(-)

diff --git a/include/linux/bpf.h b/include/linux/bpf.h
index ee5275e7d4df..8530b791c1b0 100644
--- a/include/linux/bpf.h
+++ b/include/linux/bpf.h
@@ -274,6 +274,7 @@ struct bpf_prog_aux {
 	struct user_struct *user;
 	u64 load_time; /* ns since boottime */
 	char name[BPF_OBJ_NAME_LEN];
+	char *license;
 #ifdef CONFIG_SECURITY
 	void *security;
 #endif
diff --git a/include/uapi/linux/bpf.h b/include/uapi/linux/bpf.h
index c8383a289f7b..b7298ee177e7 100644
--- a/include/uapi/linux/bpf.h
+++ b/include/uapi/linux/bpf.h
@@ -239,6 +239,8 @@ enum bpf_attach_type {
 
 #define BPF_OBJ_NAME_LEN 16U
 
+#define BPF_OBJ_LICENSE_LEN 128U
+
 /* Flags for accessing BPF object */
 #define BPF_F_RDONLY		(1U << 3)
 #define BPF_F_WRONLY		(1U << 4)
@@ -1039,6 +1041,7 @@ struct bpf_prog_info {
 	__u32 ifindex;
 	__u64 netns_dev;
 	__u64 netns_ino;
+	char license[BPF_OBJ_LICENSE_LEN];
 } __attribute__((aligned(8)));
 
 struct bpf_map_info {
diff --git a/kernel/bpf/core.c b/kernel/bpf/core.c
index d315b393abdd..05352a928917 100644
--- a/kernel/bpf/core.c
+++ b/kernel/bpf/core.c
@@ -142,6 +142,7 @@ struct bpf_prog *bpf_prog_realloc(struct bpf_prog *fp_old, unsigned int size,
 
 void __bpf_prog_free(struct bpf_prog *fp)
 {
+	kfree(fp->aux->license);
 	kfree(fp->aux);
 	vfree(fp);
 }
diff --git a/kernel/bpf/syscall.c b/kernel/bpf/syscall.c
index fe23dc5a3ec4..a876af93147f 100644
--- a/kernel/bpf/syscall.c
+++ b/kernel/bpf/syscall.c
@@ -1265,7 +1265,7 @@ static int bpf_prog_load(union bpf_attr *attr)
 	enum bpf_prog_type type = attr->prog_type;
 	struct bpf_prog *prog;
 	int err;
-	char license[128];
+	char license[BPF_OBJ_LICENSE_LEN];
 	bool is_gpl;
 
 	if (CHECK_ATTR(BPF_PROG_LOAD))
@@ -1345,6 +1345,10 @@ static int bpf_prog_load(union bpf_attr *attr)
 	if (err)
 		goto free_prog;
 
+	prog->aux->license = kstrdup(license, GFP_KERNEL);
+	if (!prog->aux->license)
+		goto free_prog;
+
 	/* run eBPF verifier */
 	err = bpf_check(&prog, attr);
 	if (err < 0)
@@ -1917,6 +1921,7 @@ static int bpf_prog_get_info_by_fd(struct bpf_prog *prog,
 
 	memcpy(info.tag, prog->tag, sizeof(prog->tag));
 	memcpy(info.name, prog->aux->name, sizeof(prog->aux->name));
+	strncpy(info.license, prog->aux->license, BPF_OBJ_LICENSE_LEN);
 
 	ulen = info.nr_map_ids;
 	info.nr_map_ids = prog->aux->used_map_cnt;
-- 
2.13.6

^ permalink raw reply related	[flat|nested] 8+ messages in thread

* [PATCH 2/3] tools bpf: Sync bpf.h uapi header
  2018-04-23  6:59 [PATCH 0/3] bpf: Store/dump license string for loaded program Jiri Olsa
  2018-04-23  6:59 ` [PATCH 1/3] bpf: Store " Jiri Olsa
@ 2018-04-23  6:59 ` Jiri Olsa
  2018-04-23  6:59 ` [PATCH 3/3] tools bpftool: Display license in prog show/list Jiri Olsa
  2018-04-23 20:11 ` [PATCH 0/3] bpf: Store/dump license string for loaded program Alexei Starovoitov
  3 siblings, 0 replies; 8+ messages in thread
From: Jiri Olsa @ 2018-04-23  6:59 UTC (permalink / raw)
  To: Alexei Starovoitov, Daniel Borkmann; +Cc: lkml, netdev, Quentin Monnet

Syncing the bpf.h uapi header with tools.

Signed-off-by: Jiri Olsa <jolsa@kernel.org>
---
 tools/include/uapi/linux/bpf.h | 4 ++++
 1 file changed, 4 insertions(+)

diff --git a/tools/include/uapi/linux/bpf.h b/tools/include/uapi/linux/bpf.h
index 7f7fbb9d0253..b7298ee177e7 100644
--- a/tools/include/uapi/linux/bpf.h
+++ b/tools/include/uapi/linux/bpf.h
@@ -239,6 +239,8 @@ enum bpf_attach_type {
 
 #define BPF_OBJ_NAME_LEN 16U
 
+#define BPF_OBJ_LICENSE_LEN 128U
+
 /* Flags for accessing BPF object */
 #define BPF_F_RDONLY		(1U << 3)
 #define BPF_F_WRONLY		(1U << 4)
@@ -884,6 +886,7 @@ enum bpf_func_id {
 /* BPF_FUNC_skb_set_tunnel_key flags. */
 #define BPF_F_ZERO_CSUM_TX		(1ULL << 1)
 #define BPF_F_DONT_FRAGMENT		(1ULL << 2)
+#define BPF_F_SEQ_NUMBER		(1ULL << 3)
 
 /* BPF_FUNC_perf_event_output, BPF_FUNC_perf_event_read and
  * BPF_FUNC_perf_event_read_value flags.
@@ -1038,6 +1041,7 @@ struct bpf_prog_info {
 	__u32 ifindex;
 	__u64 netns_dev;
 	__u64 netns_ino;
+	char license[BPF_OBJ_LICENSE_LEN];
 } __attribute__((aligned(8)));
 
 struct bpf_map_info {
-- 
2.13.6

^ permalink raw reply related	[flat|nested] 8+ messages in thread

* [PATCH 3/3] tools bpftool: Display license in prog show/list
  2018-04-23  6:59 [PATCH 0/3] bpf: Store/dump license string for loaded program Jiri Olsa
  2018-04-23  6:59 ` [PATCH 1/3] bpf: Store " Jiri Olsa
  2018-04-23  6:59 ` [PATCH 2/3] tools bpf: Sync bpf.h uapi header Jiri Olsa
@ 2018-04-23  6:59 ` Jiri Olsa
  2018-04-23 20:11 ` [PATCH 0/3] bpf: Store/dump license string for loaded program Alexei Starovoitov
  3 siblings, 0 replies; 8+ messages in thread
From: Jiri Olsa @ 2018-04-23  6:59 UTC (permalink / raw)
  To: Alexei Starovoitov, Daniel Borkmann; +Cc: lkml, netdev, Quentin Monnet

Display the license string in bpftool prog command, like:

  # 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", ... ]

Signed-off-by: Jiri Olsa <jolsa@kernel.org>
---
 tools/bpf/bpftool/prog.c | 4 ++++
 1 file changed, 4 insertions(+)

diff --git a/tools/bpf/bpftool/prog.c b/tools/bpf/bpftool/prog.c
index 548adb9b7317..ea5ede899cf7 100644
--- a/tools/bpf/bpftool/prog.c
+++ b/tools/bpf/bpftool/prog.c
@@ -235,6 +235,8 @@ static void print_prog_json(struct bpf_prog_info *info, int fd)
 		     info->tag[0], info->tag[1], info->tag[2], info->tag[3],
 		     info->tag[4], info->tag[5], info->tag[6], info->tag[7]);
 
+	jsonw_string_field(json_wtr, "license", info->license);
+
 	print_dev_json(info->ifindex, info->netns_dev, info->netns_ino);
 
 	if (info->load_time) {
@@ -295,8 +297,10 @@ static void print_prog_plain(struct bpf_prog_info *info, int fd)
 	printf("tag ");
 	fprint_hex(stdout, info->tag, BPF_TAG_SIZE, "");
 	print_dev_plain(info->ifindex, info->netns_dev, info->netns_ino);
+	printf(" license %s", info->license);
 	printf("\n");
 
+
 	if (info->load_time) {
 		char buf[32];
 
-- 
2.13.6

^ permalink raw reply related	[flat|nested] 8+ messages in thread

* Re: [PATCH 0/3] bpf: Store/dump license string for loaded program
  2018-04-23  6:59 [PATCH 0/3] bpf: Store/dump license string for loaded program Jiri Olsa
                   ` (2 preceding siblings ...)
  2018-04-23  6:59 ` [PATCH 3/3] tools bpftool: Display license in prog show/list Jiri Olsa
@ 2018-04-23 20:11 ` Alexei Starovoitov
  2018-04-25 10:17   ` Jiri Olsa
  3 siblings, 1 reply; 8+ messages in thread
From: Alexei Starovoitov @ 2018-04-23 20:11 UTC (permalink / raw)
  To: Jiri Olsa
  Cc: Alexei Starovoitov, Daniel Borkmann, lkml, netdev, Quentin Monnet

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.

^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: [PATCH 0/3] bpf: Store/dump license string for loaded program
  2018-04-23 20:11 ` [PATCH 0/3] bpf: Store/dump license string for loaded program Alexei Starovoitov
@ 2018-04-25 10:17   ` Jiri Olsa
  2018-04-25 16:15     ` Alexei Starovoitov
  0 siblings, 1 reply; 8+ messages in thread
From: Jiri Olsa @ 2018-04-25 10:17 UTC (permalink / raw)
  To: Alexei Starovoitov
  Cc: Jiri Olsa, Alexei Starovoitov, Daniel Borkmann, lkml, netdev,
	Quentin Monnet

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));

^ permalink raw reply related	[flat|nested] 8+ messages in thread

* Re: [PATCH 0/3] bpf: Store/dump license string for loaded program
  2018-04-25 10:17   ` Jiri Olsa
@ 2018-04-25 16:15     ` Alexei Starovoitov
  2018-04-25 16:20       ` Jiri Olsa
  0 siblings, 1 reply; 8+ messages in thread
From: Alexei Starovoitov @ 2018-04-25 16:15 UTC (permalink / raw)
  To: Jiri Olsa
  Cc: Jiri Olsa, Alexei Starovoitov, Daniel Borkmann, lkml, netdev,
	Quentin Monnet

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.

^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: [PATCH 0/3] bpf: Store/dump license string for loaded program
  2018-04-25 16:15     ` Alexei Starovoitov
@ 2018-04-25 16:20       ` Jiri Olsa
  0 siblings, 0 replies; 8+ messages in thread
From: Jiri Olsa @ 2018-04-25 16:20 UTC (permalink / raw)
  To: Alexei Starovoitov
  Cc: Jiri Olsa, Alexei Starovoitov, Daniel Borkmann, lkml, netdev,
	Quentin Monnet

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

^ permalink raw reply	[flat|nested] 8+ messages in thread

end of thread, other threads:[~2018-04-25 16:23 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2018-04-23  6:59 [PATCH 0/3] bpf: Store/dump license string for loaded program Jiri Olsa
2018-04-23  6:59 ` [PATCH 1/3] bpf: Store " Jiri Olsa
2018-04-23  6:59 ` [PATCH 2/3] tools bpf: Sync bpf.h uapi header Jiri Olsa
2018-04-23  6:59 ` [PATCH 3/3] tools bpftool: Display license in prog show/list Jiri Olsa
2018-04-23 20:11 ` [PATCH 0/3] bpf: Store/dump license string for loaded program Alexei Starovoitov
2018-04-25 10:17   ` Jiri Olsa
2018-04-25 16:15     ` Alexei Starovoitov
2018-04-25 16:20       ` Jiri Olsa

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.