Merge git://git.kernel.org/pub/scm/linux/kernel/git/bpf/bpf
Alexei Starovoitov says: ==================== pull-request: bpf 2020-04-24 The following pull-request contains BPF updates for your *net* tree. We've added 17 non-merge commits during the last 5 day(s) which contain a total of 19 files changed, 203 insertions(+), 85 deletions(-). The main changes are: 1) link_update fix, from Andrii. 2) libbpf get_xdp_id fix, from David. 3) xadd verifier fix, from Jann. 4) x86-32 JIT fixes, from Luke and Wang. 5) test_btf fix, from Stanislav. 6) freplace verifier fix, from Toke. ==================== Signed-off-by: David S. Miller <davem@davemloft.net>
This commit is contained in:
@@ -5,7 +5,8 @@
|
||||
static void test_fexit_bpf2bpf_common(const char *obj_file,
|
||||
const char *target_obj_file,
|
||||
int prog_cnt,
|
||||
const char **prog_name)
|
||||
const char **prog_name,
|
||||
bool run_prog)
|
||||
{
|
||||
struct bpf_object *obj = NULL, *pkt_obj;
|
||||
int err, pkt_fd, i;
|
||||
@@ -18,7 +19,8 @@ static void test_fexit_bpf2bpf_common(const char *obj_file,
|
||||
|
||||
err = bpf_prog_load(target_obj_file, BPF_PROG_TYPE_UNSPEC,
|
||||
&pkt_obj, &pkt_fd);
|
||||
if (CHECK(err, "prog_load sched cls", "err %d errno %d\n", err, errno))
|
||||
if (CHECK(err, "tgt_prog_load", "file %s err %d errno %d\n",
|
||||
target_obj_file, err, errno))
|
||||
return;
|
||||
DECLARE_LIBBPF_OPTS(bpf_object_open_opts, opts,
|
||||
.attach_prog_fd = pkt_fd,
|
||||
@@ -33,7 +35,7 @@ static void test_fexit_bpf2bpf_common(const char *obj_file,
|
||||
|
||||
obj = bpf_object__open_file(obj_file, &opts);
|
||||
if (CHECK(IS_ERR_OR_NULL(obj), "obj_open",
|
||||
"failed to open fexit_bpf2bpf: %ld\n",
|
||||
"failed to open %s: %ld\n", obj_file,
|
||||
PTR_ERR(obj)))
|
||||
goto close_prog;
|
||||
|
||||
@@ -49,6 +51,10 @@ static void test_fexit_bpf2bpf_common(const char *obj_file,
|
||||
if (CHECK(IS_ERR(link[i]), "attach_trace", "failed to link\n"))
|
||||
goto close_prog;
|
||||
}
|
||||
|
||||
if (!run_prog)
|
||||
goto close_prog;
|
||||
|
||||
data_map = bpf_object__find_map_by_name(obj, "fexit_bp.bss");
|
||||
if (CHECK(!data_map, "find_data_map", "data map not found\n"))
|
||||
goto close_prog;
|
||||
@@ -89,7 +95,7 @@ static void test_target_no_callees(void)
|
||||
test_fexit_bpf2bpf_common("./fexit_bpf2bpf_simple.o",
|
||||
"./test_pkt_md_access.o",
|
||||
ARRAY_SIZE(prog_name),
|
||||
prog_name);
|
||||
prog_name, true);
|
||||
}
|
||||
|
||||
static void test_target_yes_callees(void)
|
||||
@@ -103,7 +109,7 @@ static void test_target_yes_callees(void)
|
||||
test_fexit_bpf2bpf_common("./fexit_bpf2bpf.o",
|
||||
"./test_pkt_access.o",
|
||||
ARRAY_SIZE(prog_name),
|
||||
prog_name);
|
||||
prog_name, true);
|
||||
}
|
||||
|
||||
static void test_func_replace(void)
|
||||
@@ -120,7 +126,18 @@ static void test_func_replace(void)
|
||||
test_fexit_bpf2bpf_common("./fexit_bpf2bpf.o",
|
||||
"./test_pkt_access.o",
|
||||
ARRAY_SIZE(prog_name),
|
||||
prog_name);
|
||||
prog_name, true);
|
||||
}
|
||||
|
||||
static void test_func_replace_verify(void)
|
||||
{
|
||||
const char *prog_name[] = {
|
||||
"freplace/do_bind",
|
||||
};
|
||||
test_fexit_bpf2bpf_common("./freplace_connect4.o",
|
||||
"./connect4_prog.o",
|
||||
ARRAY_SIZE(prog_name),
|
||||
prog_name, false);
|
||||
}
|
||||
|
||||
void test_fexit_bpf2bpf(void)
|
||||
@@ -128,4 +145,5 @@ void test_fexit_bpf2bpf(void)
|
||||
test_target_no_callees();
|
||||
test_target_yes_callees();
|
||||
test_func_replace();
|
||||
test_func_replace_verify();
|
||||
}
|
||||
|
||||
@@ -18,11 +18,25 @@
|
||||
|
||||
int _version SEC("version") = 1;
|
||||
|
||||
__attribute__ ((noinline))
|
||||
int do_bind(struct bpf_sock_addr *ctx)
|
||||
{
|
||||
struct sockaddr_in sa = {};
|
||||
|
||||
sa.sin_family = AF_INET;
|
||||
sa.sin_port = bpf_htons(0);
|
||||
sa.sin_addr.s_addr = bpf_htonl(SRC_REWRITE_IP4);
|
||||
|
||||
if (bpf_bind(ctx, (struct sockaddr *)&sa, sizeof(sa)) != 0)
|
||||
return 0;
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
SEC("cgroup/connect4")
|
||||
int connect_v4_prog(struct bpf_sock_addr *ctx)
|
||||
{
|
||||
struct bpf_sock_tuple tuple = {};
|
||||
struct sockaddr_in sa;
|
||||
struct bpf_sock *sk;
|
||||
|
||||
/* Verify that new destination is available. */
|
||||
@@ -56,17 +70,7 @@ int connect_v4_prog(struct bpf_sock_addr *ctx)
|
||||
ctx->user_ip4 = bpf_htonl(DST_REWRITE_IP4);
|
||||
ctx->user_port = bpf_htons(DST_REWRITE_PORT4);
|
||||
|
||||
/* Rewrite source. */
|
||||
memset(&sa, 0, sizeof(sa));
|
||||
|
||||
sa.sin_family = AF_INET;
|
||||
sa.sin_port = bpf_htons(0);
|
||||
sa.sin_addr.s_addr = bpf_htonl(SRC_REWRITE_IP4);
|
||||
|
||||
if (bpf_bind(ctx, (struct sockaddr *)&sa, sizeof(sa)) != 0)
|
||||
return 0;
|
||||
|
||||
return 1;
|
||||
return do_bind(ctx) ? 1 : 0;
|
||||
}
|
||||
|
||||
char _license[] SEC("license") = "GPL";
|
||||
|
||||
@@ -0,0 +1,18 @@
|
||||
#include <linux/stddef.h>
|
||||
#include <linux/ipv6.h>
|
||||
#include <linux/bpf.h>
|
||||
#include <linux/in.h>
|
||||
#include <sys/socket.h>
|
||||
#include <bpf/bpf_helpers.h>
|
||||
#include <bpf/bpf_endian.h>
|
||||
|
||||
SEC("freplace/do_bind")
|
||||
int new_do_bind(struct bpf_sock_addr *ctx)
|
||||
{
|
||||
struct sockaddr_in sa = {};
|
||||
|
||||
bpf_bind(ctx, (struct sockaddr *)&sa, sizeof(sa));
|
||||
return 0;
|
||||
}
|
||||
|
||||
char _license[] SEC("license") = "GPL";
|
||||
@@ -20,20 +20,12 @@ struct bpf_map_def SEC("maps") btf_map = {
|
||||
|
||||
BPF_ANNOTATE_KV_PAIR(btf_map, int, struct ipv_counts);
|
||||
|
||||
struct dummy_tracepoint_args {
|
||||
unsigned long long pad;
|
||||
struct sock *sock;
|
||||
};
|
||||
|
||||
__attribute__((noinline))
|
||||
int test_long_fname_2(struct dummy_tracepoint_args *arg)
|
||||
int test_long_fname_2(void)
|
||||
{
|
||||
struct ipv_counts *counts;
|
||||
int key = 0;
|
||||
|
||||
if (!arg->sock)
|
||||
return 0;
|
||||
|
||||
counts = bpf_map_lookup_elem(&btf_map, &key);
|
||||
if (!counts)
|
||||
return 0;
|
||||
@@ -44,15 +36,15 @@ int test_long_fname_2(struct dummy_tracepoint_args *arg)
|
||||
}
|
||||
|
||||
__attribute__((noinline))
|
||||
int test_long_fname_1(struct dummy_tracepoint_args *arg)
|
||||
int test_long_fname_1(void)
|
||||
{
|
||||
return test_long_fname_2(arg);
|
||||
return test_long_fname_2();
|
||||
}
|
||||
|
||||
SEC("dummy_tracepoint")
|
||||
int _dummy_tracepoint(struct dummy_tracepoint_args *arg)
|
||||
int _dummy_tracepoint(void *arg)
|
||||
{
|
||||
return test_long_fname_1(arg);
|
||||
return test_long_fname_1();
|
||||
}
|
||||
|
||||
char _license[] SEC("license") = "GPL";
|
||||
|
||||
@@ -28,20 +28,12 @@ struct {
|
||||
__type(value, struct ipv_counts);
|
||||
} btf_map SEC(".maps");
|
||||
|
||||
struct dummy_tracepoint_args {
|
||||
unsigned long long pad;
|
||||
struct sock *sock;
|
||||
};
|
||||
|
||||
__attribute__((noinline))
|
||||
int test_long_fname_2(struct dummy_tracepoint_args *arg)
|
||||
int test_long_fname_2(void)
|
||||
{
|
||||
struct ipv_counts *counts;
|
||||
int key = 0;
|
||||
|
||||
if (!arg->sock)
|
||||
return 0;
|
||||
|
||||
counts = bpf_map_lookup_elem(&btf_map, &key);
|
||||
if (!counts)
|
||||
return 0;
|
||||
@@ -57,15 +49,15 @@ int test_long_fname_2(struct dummy_tracepoint_args *arg)
|
||||
}
|
||||
|
||||
__attribute__((noinline))
|
||||
int test_long_fname_1(struct dummy_tracepoint_args *arg)
|
||||
int test_long_fname_1(void)
|
||||
{
|
||||
return test_long_fname_2(arg);
|
||||
return test_long_fname_2();
|
||||
}
|
||||
|
||||
SEC("dummy_tracepoint")
|
||||
int _dummy_tracepoint(struct dummy_tracepoint_args *arg)
|
||||
int _dummy_tracepoint(void *arg)
|
||||
{
|
||||
return test_long_fname_1(arg);
|
||||
return test_long_fname_1();
|
||||
}
|
||||
|
||||
char _license[] SEC("license") = "GPL";
|
||||
|
||||
@@ -17,20 +17,12 @@ struct bpf_map_def SEC("maps") btf_map = {
|
||||
.max_entries = 4,
|
||||
};
|
||||
|
||||
struct dummy_tracepoint_args {
|
||||
unsigned long long pad;
|
||||
struct sock *sock;
|
||||
};
|
||||
|
||||
__attribute__((noinline))
|
||||
int test_long_fname_2(struct dummy_tracepoint_args *arg)
|
||||
int test_long_fname_2(void)
|
||||
{
|
||||
struct ipv_counts *counts;
|
||||
int key = 0;
|
||||
|
||||
if (!arg->sock)
|
||||
return 0;
|
||||
|
||||
counts = bpf_map_lookup_elem(&btf_map, &key);
|
||||
if (!counts)
|
||||
return 0;
|
||||
@@ -41,15 +33,15 @@ int test_long_fname_2(struct dummy_tracepoint_args *arg)
|
||||
}
|
||||
|
||||
__attribute__((noinline))
|
||||
int test_long_fname_1(struct dummy_tracepoint_args *arg)
|
||||
int test_long_fname_1(void)
|
||||
{
|
||||
return test_long_fname_2(arg);
|
||||
return test_long_fname_2();
|
||||
}
|
||||
|
||||
SEC("dummy_tracepoint")
|
||||
int _dummy_tracepoint(struct dummy_tracepoint_args *arg)
|
||||
int _dummy_tracepoint(void *arg)
|
||||
{
|
||||
return test_long_fname_1(arg);
|
||||
return test_long_fname_1();
|
||||
}
|
||||
|
||||
char _license[] SEC("license") = "GPL";
|
||||
|
||||
@@ -2854,7 +2854,7 @@ static struct btf_raw_test raw_tests[] = {
|
||||
.value_type_id = 1,
|
||||
.max_entries = 4,
|
||||
.btf_load_err = true,
|
||||
.err_str = "vlen != 0",
|
||||
.err_str = "Invalid func linkage",
|
||||
},
|
||||
|
||||
{
|
||||
|
||||
@@ -315,3 +315,43 @@
|
||||
},
|
||||
.result = ACCEPT,
|
||||
},
|
||||
{
|
||||
"store PTR_TO_STACK in R10 to array map using BPF_B",
|
||||
.insns = {
|
||||
/* Load pointer to map. */
|
||||
BPF_MOV64_REG(BPF_REG_2, BPF_REG_10),
|
||||
BPF_ALU64_IMM(BPF_ADD, BPF_REG_2, -8),
|
||||
BPF_ST_MEM(BPF_DW, BPF_REG_2, 0, 0),
|
||||
BPF_LD_MAP_FD(BPF_REG_1, 0),
|
||||
BPF_EMIT_CALL(BPF_FUNC_map_lookup_elem),
|
||||
BPF_JMP_IMM(BPF_JNE, BPF_REG_0, 0, 2),
|
||||
BPF_MOV64_IMM(BPF_REG_0, 2),
|
||||
BPF_EXIT_INSN(),
|
||||
BPF_MOV64_REG(BPF_REG_1, BPF_REG_0),
|
||||
/* Copy R10 to R9. */
|
||||
BPF_MOV64_REG(BPF_REG_9, BPF_REG_10),
|
||||
/* Pollute other registers with unaligned values. */
|
||||
BPF_MOV64_IMM(BPF_REG_2, -1),
|
||||
BPF_MOV64_IMM(BPF_REG_3, -1),
|
||||
BPF_MOV64_IMM(BPF_REG_4, -1),
|
||||
BPF_MOV64_IMM(BPF_REG_5, -1),
|
||||
BPF_MOV64_IMM(BPF_REG_6, -1),
|
||||
BPF_MOV64_IMM(BPF_REG_7, -1),
|
||||
BPF_MOV64_IMM(BPF_REG_8, -1),
|
||||
/* Store both R9 and R10 with BPF_B and read back. */
|
||||
BPF_STX_MEM(BPF_B, BPF_REG_1, BPF_REG_10, 0),
|
||||
BPF_LDX_MEM(BPF_B, BPF_REG_2, BPF_REG_1, 0),
|
||||
BPF_STX_MEM(BPF_B, BPF_REG_1, BPF_REG_9, 0),
|
||||
BPF_LDX_MEM(BPF_B, BPF_REG_3, BPF_REG_1, 0),
|
||||
/* Should read back as same value. */
|
||||
BPF_JMP_REG(BPF_JEQ, BPF_REG_2, BPF_REG_3, 2),
|
||||
BPF_MOV64_IMM(BPF_REG_0, 1),
|
||||
BPF_EXIT_INSN(),
|
||||
BPF_MOV64_IMM(BPF_REG_0, 42),
|
||||
BPF_EXIT_INSN(),
|
||||
},
|
||||
.fixup_map_array_48b = { 3 },
|
||||
.result = ACCEPT,
|
||||
.retval = 42,
|
||||
.prog_type = BPF_PROG_TYPE_SCHED_CLS,
|
||||
},
|
||||
|
||||
@@ -88,6 +88,7 @@
|
||||
BPF_EXIT_INSN(),
|
||||
},
|
||||
.fixup_map_hash_48b = { 3 },
|
||||
.errstr_unpriv = "leaking pointer from stack off -8",
|
||||
.errstr = "R0 invalid mem access 'inv'",
|
||||
.result = REJECT,
|
||||
.flags = F_NEEDS_EFFICIENT_UNALIGNED_ACCESS,
|
||||
|
||||
Reference in New Issue
Block a user