* [PATCH net-next v2 1/3] tools: Sync {,tools/}include/uapi/linux/bpf.h
@ 2017-02-06 20:52 Mickaël Salaün
2017-02-06 20:52 ` [PATCH net-next v2 2/3] bpf: Change the include directory for selftest Mickaël Salaün
` (2 more replies)
0 siblings, 3 replies; 6+ messages in thread
From: Mickaël Salaün @ 2017-02-06 20:52 UTC (permalink / raw)
To: linux-kernel
Cc: Mickaël Salaün, Alexei Starovoitov,
Arnaldo Carvalho de Melo, Daniel Borkmann, David S . Miller,
netdev, Daniel Mack, Gianluca Borello
The tools version of this header is out of date; update it to the latest
version from kernel header.
Synchronize with the following commits:
* b95a5c4db09b ("bpf: add a longest prefix match trie map implementation")
* a5e8c07059d0 ("bpf: add bpf_probe_read_str helper")
* d1b662adcdb8 ("bpf: allow option for setting bpf_l4_csum_replace from scratch")
Signed-off-by: Mickaël Salaün <mic@digikod.net>
Cc: Alexei Starovoitov <ast@fb.com>
Cc: Arnaldo Carvalho de Melo <acme@redhat.com>
Cc: Daniel Borkmann <daniel@iogearbox.net>
Cc: Daniel Mack <daniel@zonque.org>
Cc: David S. Miller <davem@davemloft.net>
Cc: Gianluca Borello <g.borello@gmail.com>
---
tools/include/uapi/linux/bpf.h | 23 ++++++++++++++++++++++-
1 file changed, 22 insertions(+), 1 deletion(-)
diff --git a/tools/include/uapi/linux/bpf.h b/tools/include/uapi/linux/bpf.h
index 0eb0e87dbe9f..e07fd5a324e6 100644
--- a/tools/include/uapi/linux/bpf.h
+++ b/tools/include/uapi/linux/bpf.h
@@ -63,6 +63,12 @@ struct bpf_insn {
__s32 imm; /* signed immediate constant */
};
+/* Key of an a BPF_MAP_TYPE_LPM_TRIE entry */
+struct bpf_lpm_trie_key {
+ __u32 prefixlen; /* up to 32 for AF_INET, 128 for AF_INET6 */
+ __u8 data[0]; /* Arbitrary size */
+};
+
/* BPF syscall commands, see bpf(2) man-page for details. */
enum bpf_cmd {
BPF_MAP_CREATE,
@@ -89,6 +95,7 @@ enum bpf_map_type {
BPF_MAP_TYPE_CGROUP_ARRAY,
BPF_MAP_TYPE_LRU_HASH,
BPF_MAP_TYPE_LRU_PERCPU_HASH,
+ BPF_MAP_TYPE_LPM_TRIE,
};
enum bpf_prog_type {
@@ -430,6 +437,18 @@ union bpf_attr {
* @xdp_md: pointer to xdp_md
* @delta: An positive/negative integer to be added to xdp_md.data
* Return: 0 on success or negative on error
+ *
+ * int bpf_probe_read_str(void *dst, int size, const void *unsafe_ptr)
+ * Copy a NUL terminated string from unsafe address. In case the string
+ * length is smaller than size, the target is not padded with further NUL
+ * bytes. In case the string length is larger than size, just count-1
+ * bytes are copied and the last byte is set to NUL.
+ * @dst: destination address
+ * @size: maximum number of bytes to copy, including the trailing NUL
+ * @unsafe_ptr: unsafe address
+ * Return:
+ * > 0 length of the string including the trailing NUL on success
+ * < 0 error
*/
#define __BPF_FUNC_MAPPER(FN) \
FN(unspec), \
@@ -476,7 +495,8 @@ union bpf_attr {
FN(set_hash_invalid), \
FN(get_numa_node_id), \
FN(skb_change_head), \
- FN(xdp_adjust_head),
+ FN(xdp_adjust_head), \
+ FN(probe_read_str),
/* integer value in 'imm' field of BPF_CALL instruction selects which helper
* function eBPF program intends to call
@@ -502,6 +522,7 @@ enum bpf_func_id {
/* BPF_FUNC_l4_csum_replace flags. */
#define BPF_F_PSEUDO_HDR (1ULL << 4)
#define BPF_F_MARK_MANGLED_0 (1ULL << 5)
+#define BPF_F_MARK_ENFORCE (1ULL << 6)
/* BPF_FUNC_clone_redirect and BPF_FUNC_redirect flags. */
#define BPF_F_INGRESS (1ULL << 0)
--
2.11.0
^ permalink raw reply related [flat|nested] 6+ messages in thread
* [PATCH net-next v2 2/3] bpf: Change the include directory for selftest
2017-02-06 20:52 [PATCH net-next v2 1/3] tools: Sync {,tools/}include/uapi/linux/bpf.h Mickaël Salaün
@ 2017-02-06 20:52 ` Mickaël Salaün
2017-02-06 20:52 ` [PATCH net-next v2 3/3] bpf: Always test unprivileged programs Mickaël Salaün
2017-02-07 18:01 ` [PATCH net-next v2 1/3] tools: Sync {,tools/}include/uapi/linux/bpf.h David Miller
2 siblings, 0 replies; 6+ messages in thread
From: Mickaël Salaün @ 2017-02-06 20:52 UTC (permalink / raw)
To: linux-kernel
Cc: Mickaël Salaün, Alexei Starovoitov,
Arnaldo Carvalho de Melo, Daniel Borkmann, David S . Miller,
netdev
Use the tools include directory instead of the installed one to allow
builds from other kernels.
Signed-off-by: Mickaël Salaün <mic@digikod.net>
Cc: Alexei Starovoitov <ast@fb.com>
Cc: Arnaldo Carvalho de Melo <acme@redhat.com>
Cc: Daniel Borkmann <daniel@iogearbox.net>
Cc: David S. Miller <davem@davemloft.net>
---
tools/testing/selftests/bpf/Makefile | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/tools/testing/selftests/bpf/Makefile b/tools/testing/selftests/bpf/Makefile
index 769a6cb42b4b..c470c7301636 100644
--- a/tools/testing/selftests/bpf/Makefile
+++ b/tools/testing/selftests/bpf/Makefile
@@ -1,4 +1,4 @@
-CFLAGS += -Wall -O2 -I../../../../usr/include
+CFLAGS += -Wall -O2 -I../../../include/uapi
test_objs = test_verifier test_tag test_maps test_lru_map test_lpm_map
--
2.11.0
^ permalink raw reply related [flat|nested] 6+ messages in thread
* [PATCH net-next v2 3/3] bpf: Always test unprivileged programs
2017-02-06 20:52 [PATCH net-next v2 1/3] tools: Sync {,tools/}include/uapi/linux/bpf.h Mickaël Salaün
2017-02-06 20:52 ` [PATCH net-next v2 2/3] bpf: Change the include directory for selftest Mickaël Salaün
@ 2017-02-06 20:52 ` Mickaël Salaün
2017-02-06 21:19 ` Alexei Starovoitov
2017-02-06 22:44 ` Daniel Borkmann
2017-02-07 18:01 ` [PATCH net-next v2 1/3] tools: Sync {,tools/}include/uapi/linux/bpf.h David Miller
2 siblings, 2 replies; 6+ messages in thread
From: Mickaël Salaün @ 2017-02-06 20:52 UTC (permalink / raw)
To: linux-kernel
Cc: Mickaël Salaün, Alexei Starovoitov,
Arnaldo Carvalho de Melo, Daniel Borkmann, David S . Miller,
netdev, Shuah Khan
If selftests are run as root, then execute the unprivileged checks as
well. This switch from 240 to 364 tests.
The test numbers are suffixed with "/u" when executed as unprivileged or
with "/p" when executed as privileged.
The geteuid() check is replaced with a capability check.
Handling capabilities requires the libcap dependency.
Signed-off-by: Mickaël Salaün <mic@digikod.net>
Cc: Alexei Starovoitov <ast@fb.com>
Cc: Daniel Borkmann <daniel@iogearbox.net>
Cc: Shuah Khan <shuah@kernel.org>
---
tools/testing/selftests/bpf/Makefile | 2 +-
tools/testing/selftests/bpf/test_verifier.c | 68 ++++++++++++++++++++++++++---
2 files changed, 64 insertions(+), 6 deletions(-)
diff --git a/tools/testing/selftests/bpf/Makefile b/tools/testing/selftests/bpf/Makefile
index c470c7301636..f3d65ad53494 100644
--- a/tools/testing/selftests/bpf/Makefile
+++ b/tools/testing/selftests/bpf/Makefile
@@ -1,4 +1,4 @@
-CFLAGS += -Wall -O2 -I../../../include/uapi
+CFLAGS += -Wall -O2 -lcap -I../../../include/uapi
test_objs = test_verifier test_tag test_maps test_lru_map test_lpm_map
diff --git a/tools/testing/selftests/bpf/test_verifier.c b/tools/testing/selftests/bpf/test_verifier.c
index 0d0912c7f03c..6a82e7db2c20 100644
--- a/tools/testing/selftests/bpf/test_verifier.c
+++ b/tools/testing/selftests/bpf/test_verifier.c
@@ -16,6 +16,7 @@
#include <stdbool.h>
#include <sched.h>
+#include <sys/capability.h>
#include <sys/resource.h>
#include <linux/unistd.h>
@@ -4496,6 +4497,55 @@ static void do_test_single(struct bpf_test *test, bool unpriv,
goto close_fds;
}
+static bool is_admin(void)
+{
+ cap_t caps;
+ cap_flag_value_t sysadmin = CAP_CLEAR;
+ const cap_value_t cap_val = CAP_SYS_ADMIN;
+
+ if (!CAP_IS_SUPPORTED(CAP_SETFCAP)) {
+ perror("cap_get_flag");
+ return false;
+ }
+ caps = cap_get_proc();
+ if (!caps) {
+ perror("cap_get_proc");
+ return false;
+ }
+ if (cap_get_flag(caps, cap_val, CAP_EFFECTIVE, &sysadmin))
+ perror("cap_get_flag");
+ if (cap_free(caps))
+ perror("cap_free");
+ return (sysadmin == CAP_SET);
+}
+
+static int set_admin(bool admin)
+{
+ cap_t caps;
+ const cap_value_t cap_val = CAP_SYS_ADMIN;
+ int ret = -1;
+
+ caps = cap_get_proc();
+ if (!caps) {
+ perror("cap_get_proc");
+ return -1;
+ }
+ if (cap_set_flag(caps, CAP_EFFECTIVE, 1, &cap_val,
+ admin ? CAP_SET : CAP_CLEAR)) {
+ perror("cap_set_flag");
+ goto out;
+ }
+ if (cap_set_proc(caps)) {
+ perror("cap_set_proc");
+ goto out;
+ }
+ ret = 0;
+out:
+ if (cap_free(caps))
+ perror("cap_free");
+ return ret;
+}
+
static int do_test(bool unpriv, unsigned int from, unsigned int to)
{
int i, passes = 0, errors = 0;
@@ -4506,11 +4556,19 @@ static int do_test(bool unpriv, unsigned int from, unsigned int to)
/* Program types that are not supported by non-root we
* skip right away.
*/
- if (unpriv && test->prog_type)
- continue;
+ if (!test->prog_type) {
+ if (!unpriv)
+ set_admin(false);
+ printf("#%d/u %s ", i, test->descr);
+ do_test_single(test, true, &passes, &errors);
+ if (!unpriv)
+ set_admin(true);
+ }
- printf("#%d %s ", i, test->descr);
- do_test_single(test, unpriv, &passes, &errors);
+ if (!unpriv) {
+ printf("#%d/p %s ", i, test->descr);
+ do_test_single(test, false, &passes, &errors);
+ }
}
printf("Summary: %d PASSED, %d FAILED\n", passes, errors);
@@ -4522,7 +4580,7 @@ int main(int argc, char **argv)
struct rlimit rinf = { RLIM_INFINITY, RLIM_INFINITY };
struct rlimit rlim = { 1 << 20, 1 << 20 };
unsigned int from = 0, to = ARRAY_SIZE(tests);
- bool unpriv = geteuid() != 0;
+ bool unpriv = !is_admin();
if (argc == 3) {
unsigned int l = atoi(argv[argc - 2]);
--
2.11.0
^ permalink raw reply related [flat|nested] 6+ messages in thread
* Re: [PATCH net-next v2 3/3] bpf: Always test unprivileged programs
2017-02-06 20:52 ` [PATCH net-next v2 3/3] bpf: Always test unprivileged programs Mickaël Salaün
@ 2017-02-06 21:19 ` Alexei Starovoitov
2017-02-06 22:44 ` Daniel Borkmann
1 sibling, 0 replies; 6+ messages in thread
From: Alexei Starovoitov @ 2017-02-06 21:19 UTC (permalink / raw)
To: Mickaël Salaün, linux-kernel
Cc: Arnaldo Carvalho de Melo, Daniel Borkmann, David S . Miller,
netdev, Shuah Khan
On 2/6/17 12:52 PM, Mickaël Salaün wrote:
> If selftests are run as root, then execute the unprivileged checks as
> well. This switch from 240 to 364 tests.
>
> The test numbers are suffixed with "/u" when executed as unprivileged or
> with "/p" when executed as privileged.
>
> The geteuid() check is replaced with a capability check.
>
> Handling capabilities requires the libcap dependency.
>
> Signed-off-by: Mickaël Salaün <mic@digikod.net>
> Cc: Alexei Starovoitov <ast@fb.com>
> Cc: Daniel Borkmann <daniel@iogearbox.net>
> Cc: Shuah Khan <shuah@kernel.org>
Acked-by: Alexei Starovoitov <ast@kernel.org>
you can keep acks when there are no changes to the patch.
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [PATCH net-next v2 3/3] bpf: Always test unprivileged programs
2017-02-06 20:52 ` [PATCH net-next v2 3/3] bpf: Always test unprivileged programs Mickaël Salaün
2017-02-06 21:19 ` Alexei Starovoitov
@ 2017-02-06 22:44 ` Daniel Borkmann
1 sibling, 0 replies; 6+ messages in thread
From: Daniel Borkmann @ 2017-02-06 22:44 UTC (permalink / raw)
To: Mickaël Salaün, linux-kernel
Cc: Alexei Starovoitov, Arnaldo Carvalho de Melo, David S . Miller,
netdev, Shuah Khan
On 02/06/2017 09:52 PM, Mickaël Salaün wrote:
> If selftests are run as root, then execute the unprivileged checks as
> well. This switch from 240 to 364 tests.
>
> The test numbers are suffixed with "/u" when executed as unprivileged or
> with "/p" when executed as privileged.
>
> The geteuid() check is replaced with a capability check.
>
> Handling capabilities requires the libcap dependency.
>
> Signed-off-by: Mickaël Salaün <mic@digikod.net>
> Cc: Alexei Starovoitov <ast@fb.com>
> Cc: Daniel Borkmann <daniel@iogearbox.net>
> Cc: Shuah Khan <shuah@kernel.org>
Acked-by: Daniel Borkmann <daniel@iogearbox.net>
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [PATCH net-next v2 1/3] tools: Sync {,tools/}include/uapi/linux/bpf.h
2017-02-06 20:52 [PATCH net-next v2 1/3] tools: Sync {,tools/}include/uapi/linux/bpf.h Mickaël Salaün
2017-02-06 20:52 ` [PATCH net-next v2 2/3] bpf: Change the include directory for selftest Mickaël Salaün
2017-02-06 20:52 ` [PATCH net-next v2 3/3] bpf: Always test unprivileged programs Mickaël Salaün
@ 2017-02-07 18:01 ` David Miller
2 siblings, 0 replies; 6+ messages in thread
From: David Miller @ 2017-02-07 18:01 UTC (permalink / raw)
To: mic; +Cc: linux-kernel, ast, acme, daniel, netdev, daniel, g.borello
Again, I need to see a proper "[PATCH net-next v2 0/3]" header posting
explaining this series.
Thanks.
^ permalink raw reply [flat|nested] 6+ messages in thread
end of thread, other threads:[~2017-02-07 18:01 UTC | newest]
Thread overview: 6+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2017-02-06 20:52 [PATCH net-next v2 1/3] tools: Sync {,tools/}include/uapi/linux/bpf.h Mickaël Salaün
2017-02-06 20:52 ` [PATCH net-next v2 2/3] bpf: Change the include directory for selftest Mickaël Salaün
2017-02-06 20:52 ` [PATCH net-next v2 3/3] bpf: Always test unprivileged programs Mickaël Salaün
2017-02-06 21:19 ` Alexei Starovoitov
2017-02-06 22:44 ` Daniel Borkmann
2017-02-07 18:01 ` [PATCH net-next v2 1/3] tools: Sync {,tools/}include/uapi/linux/bpf.h David Miller
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).