From patchwork Mon Apr 23 06:59:25 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jiri Olsa X-Patchwork-Id: 902796 X-Patchwork-Delegate: bpf@iogearbox.net Return-Path: X-Original-To: patchwork-incoming-netdev@ozlabs.org Delivered-To: patchwork-incoming-netdev@ozlabs.org Authentication-Results: ozlabs.org; spf=none (mailfrom) smtp.mailfrom=vger.kernel.org (client-ip=209.132.180.67; helo=vger.kernel.org; envelope-from=netdev-owner@vger.kernel.org; receiver=) Authentication-Results: ozlabs.org; dmarc=none (p=none dis=none) header.from=kernel.org Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by ozlabs.org (Postfix) with ESMTP id 40Ty673WgWz9s0x for ; Mon, 23 Apr 2018 17:00:47 +1000 (AEST) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1754258AbeDWHAg (ORCPT ); Mon, 23 Apr 2018 03:00:36 -0400 Received: from mx3-rdu2.redhat.com ([66.187.233.73]:47168 "EHLO mx1.redhat.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1753263AbeDWG7a (ORCPT ); Mon, 23 Apr 2018 02:59:30 -0400 Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.rdu2.redhat.com [10.11.54.6]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id E87E3818AAE8; Mon, 23 Apr 2018 06:59:29 +0000 (UTC) Received: from krava.brq.redhat.com (unknown [10.43.17.247]) by smtp.corp.redhat.com (Postfix) with ESMTP id E8D4D2166BAE; Mon, 23 Apr 2018 06:59:28 +0000 (UTC) From: Jiri Olsa To: Alexei Starovoitov , Daniel Borkmann Cc: lkml , netdev@vger.kernel.org, Quentin Monnet Subject: [PATCH 1/3] bpf: Store license string for loaded program Date: Mon, 23 Apr 2018 08:59:25 +0200 Message-Id: <20180423065927.23127-2-jolsa@kernel.org> In-Reply-To: <20180423065927.23127-1-jolsa@kernel.org> References: <20180423065927.23127-1-jolsa@kernel.org> X-Scanned-By: MIMEDefang 2.78 on 10.11.54.6 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.8]); Mon, 23 Apr 2018 06:59:30 +0000 (UTC) X-Greylist: inspected by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.8]); Mon, 23 Apr 2018 06:59:30 +0000 (UTC) for IP:'10.11.54.6' DOMAIN:'int-mx06.intmail.prod.int.rdu2.redhat.com' HELO:'smtp.corp.redhat.com' FROM:'jolsa@kernel.org' RCPT:'' Sender: netdev-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org 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 --- 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; From patchwork Mon Apr 23 06:59:26 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jiri Olsa X-Patchwork-Id: 902793 X-Patchwork-Delegate: bpf@iogearbox.net Return-Path: X-Original-To: patchwork-incoming-netdev@ozlabs.org Delivered-To: patchwork-incoming-netdev@ozlabs.org Authentication-Results: ozlabs.org; spf=none (mailfrom) smtp.mailfrom=vger.kernel.org (client-ip=209.132.180.67; helo=vger.kernel.org; envelope-from=netdev-owner@vger.kernel.org; receiver=) Authentication-Results: ozlabs.org; dmarc=none (p=none dis=none) header.from=kernel.org Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by ozlabs.org (Postfix) with ESMTP id 40Ty4m4Pjsz9s16 for ; Mon, 23 Apr 2018 16:59:36 +1000 (AEST) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1754196AbeDWG7d (ORCPT ); Mon, 23 Apr 2018 02:59:33 -0400 Received: from mx3-rdu2.redhat.com ([66.187.233.73]:55530 "EHLO mx1.redhat.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1754162AbeDWG7b (ORCPT ); Mon, 23 Apr 2018 02:59:31 -0400 Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.rdu2.redhat.com [10.11.54.6]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 2F72A4270953; Mon, 23 Apr 2018 06:59:31 +0000 (UTC) Received: from krava.brq.redhat.com (unknown [10.43.17.247]) by smtp.corp.redhat.com (Postfix) with ESMTP id 2FCA92166BAE; Mon, 23 Apr 2018 06:59:30 +0000 (UTC) From: Jiri Olsa To: Alexei Starovoitov , Daniel Borkmann Cc: lkml , netdev@vger.kernel.org, Quentin Monnet Subject: [PATCH 2/3] tools bpf: Sync bpf.h uapi header Date: Mon, 23 Apr 2018 08:59:26 +0200 Message-Id: <20180423065927.23127-3-jolsa@kernel.org> In-Reply-To: <20180423065927.23127-1-jolsa@kernel.org> References: <20180423065927.23127-1-jolsa@kernel.org> X-Scanned-By: MIMEDefang 2.78 on 10.11.54.6 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.7]); Mon, 23 Apr 2018 06:59:31 +0000 (UTC) X-Greylist: inspected by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.7]); Mon, 23 Apr 2018 06:59:31 +0000 (UTC) for IP:'10.11.54.6' DOMAIN:'int-mx06.intmail.prod.int.rdu2.redhat.com' HELO:'smtp.corp.redhat.com' FROM:'jolsa@kernel.org' RCPT:'' Sender: netdev-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org Syncing the bpf.h uapi header with tools. Signed-off-by: Jiri Olsa --- 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 { From patchwork Mon Apr 23 06:59:27 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jiri Olsa X-Patchwork-Id: 902794 X-Patchwork-Delegate: bpf@iogearbox.net Return-Path: X-Original-To: patchwork-incoming-netdev@ozlabs.org Delivered-To: patchwork-incoming-netdev@ozlabs.org Authentication-Results: ozlabs.org; spf=none (mailfrom) smtp.mailfrom=vger.kernel.org (client-ip=209.132.180.67; helo=vger.kernel.org; envelope-from=netdev-owner@vger.kernel.org; receiver=) Authentication-Results: ozlabs.org; dmarc=none (p=none dis=none) header.from=kernel.org Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by ozlabs.org (Postfix) with ESMTP id 40Ty5X6bV8z9s0x for ; Mon, 23 Apr 2018 17:00:16 +1000 (AEST) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1754219AbeDWG7w (ORCPT ); Mon, 23 Apr 2018 02:59:52 -0400 Received: from mx3-rdu2.redhat.com ([66.187.233.73]:36092 "EHLO mx1.redhat.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1751535AbeDWG7c (ORCPT ); Mon, 23 Apr 2018 02:59:32 -0400 Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.rdu2.redhat.com [10.11.54.6]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 6B868F95CC; Mon, 23 Apr 2018 06:59:32 +0000 (UTC) Received: from krava.brq.redhat.com (unknown [10.43.17.247]) by smtp.corp.redhat.com (Postfix) with ESMTP id 6B6962166BAE; Mon, 23 Apr 2018 06:59:31 +0000 (UTC) From: Jiri Olsa To: Alexei Starovoitov , Daniel Borkmann Cc: lkml , netdev@vger.kernel.org, Quentin Monnet Subject: [PATCH 3/3] tools bpftool: Display license in prog show/list Date: Mon, 23 Apr 2018 08:59:27 +0200 Message-Id: <20180423065927.23127-4-jolsa@kernel.org> In-Reply-To: <20180423065927.23127-1-jolsa@kernel.org> References: <20180423065927.23127-1-jolsa@kernel.org> X-Scanned-By: MIMEDefang 2.78 on 10.11.54.6 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.1]); Mon, 23 Apr 2018 06:59:32 +0000 (UTC) X-Greylist: inspected by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.1]); Mon, 23 Apr 2018 06:59:32 +0000 (UTC) for IP:'10.11.54.6' DOMAIN:'int-mx06.intmail.prod.int.rdu2.redhat.com' HELO:'smtp.corp.redhat.com' FROM:'jolsa@kernel.org' RCPT:'' Sender: netdev-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org 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 --- 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];