History

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. ====================

David S. Miller committed 6 years ago

Commit 167ff132 parents 3554e54 e1cebd819 files · +203 −85Browse files

Unified · Split

19 files
  1. arch/x86/net/bpf_jit_comp.c +15 −3
  2. arch/x86/net/bpf_jit_comp32.c +22 −6
  3. include/uapi/linux/bpf.h +1 −1
  4. kernel/bpf/cpumap.c +1 −1
  5. kernel/bpf/syscall.c +10 −3
  6. kernel/bpf/verifier.c +28 −10
  7. tools/bpf/bpftool/struct_ops.c +7 −1
  8. tools/bpf/runqslower/Makefile +1 −1
  9. tools/include/uapi/linux/bpf.h +1 −1
  10. tools/lib/bpf/netlink.c +2 −0
  11. tools/testing/selftests/bpf/prog_tests/fexit_bpf2bpf.c +24 −6
  12. tools/testing/selftests/bpf/progs/connect4_prog.c +16 −12
  13. tools/testing/selftests/bpf/progs/freplace_connect4.c +18 −0
  14. tools/testing/selftests/bpf/progs/test_btf_haskv.c +5 −13
  15. tools/testing/selftests/bpf/progs/test_btf_newkv.c +5 −13
  16. tools/testing/selftests/bpf/progs/test_btf_nokv.c +5 −13
  17. tools/testing/selftests/bpf/test_btf.c +1 −1
  18. tools/testing/selftests/bpf/verifier/stack_ptr.c +40 −0
  19. tools/testing/selftests/bpf/verifier/value_illegal_alu.c +1 −0
arch/x86/net/bpf_jit_comp.c+15−3
@@ -158,6 +158,19 @@ static bool is_ereg(u32 reg) · 157 unmodified lines
158158 BIT(BPF_REG_AX));
159159 }
160160
161+/*
162+ * is_ereg_8l() == true if BPF register 'reg' is mapped to access x86-64
163+ * lower 8-bit registers dil,sil,bpl,spl,r8b..r15b, which need extra byte
164+ * of encoding. al,cl,dl,bl have simpler encoding.
165+ */
166+static bool is_ereg_8l(u32 reg)
167+{
168+ return is_ereg(reg) ||
169+ (1 << reg) & (BIT(BPF_REG_1) |
170+ BIT(BPF_REG_2) |
171+ BIT(BPF_REG_FP));
172+}
173+
161174 static bool is_axreg(u32 reg)
162175 {
163176 return reg == BPF_REG_0;
@@ -598,9 +611,8 @@ static void emit_stx(u8 **pprog, u32 size, u32 dst_reg, u32 src_reg, int off) · 434 unmodified lines
598611 switch (size) {
599612 case BPF_B:
600613 /* Emit 'mov byte ptr [rax + off], al' */
601− if (is_ereg(dst_reg) || is_ereg(src_reg) ||
602− /* We have to add extra byte for x86 SIL, DIL regs */
603− src_reg == BPF_REG_1 || src_reg == BPF_REG_2)
614+ if (is_ereg(dst_reg) || is_ereg_8l(src_reg))
615+ /* Add extra byte for eregs or SIL,DIL,BPL in src_reg */
604616 EMIT2(add_2mod(0x40, dst_reg, src_reg), 0x88);
605617 else
606618 EMIT1(0x88);
arch/x86/net/bpf_jit_comp32.c+22−6
@@ -1847,14 +1847,16 @@ static int do_jit(struct bpf_prog *bpf_prog, int *addrs, u8 *image, · 1846 unmodified lines
18471847 case BPF_B:
18481848 case BPF_H:
18491849 case BPF_W:
1850− if (!bpf_prog->aux->verifier_zext)
1850+ if (bpf_prog->aux->verifier_zext)
18511851 break;
18521852 if (dstk) {
18531853 EMIT3(0xC7, add_1reg(0x40, IA32_EBP),
18541854 STACK_VAR(dst_hi));
18551855 EMIT(0x0, 4);
18561856 } else {
1857− EMIT3(0xC7, add_1reg(0xC0, dst_hi), 0);
1857+ /* xor dst_hi,dst_hi */
1858+ EMIT2(0x33,
1859+ add_2reg(0xC0, dst_hi, dst_hi));
18581860 }
18591861 break;
18601862 case BPF_DW:
@@ -2013,8 +2015,8 @@ static int do_jit(struct bpf_prog *bpf_prog, int *addrs, u8 *image, · 152 unmodified lines
20132015 case BPF_JMP | BPF_JSET | BPF_X:
20142016 case BPF_JMP32 | BPF_JSET | BPF_X: {
20152017 bool is_jmp64 = BPF_CLASS(insn->code) == BPF_JMP;
2016− u8 dreg_lo = dstk ? IA32_EAX : dst_lo;
2017− u8 dreg_hi = dstk ? IA32_EDX : dst_hi;
2018+ u8 dreg_lo = IA32_EAX;
2019+ u8 dreg_hi = IA32_EDX;
20182020 u8 sreg_lo = sstk ? IA32_ECX : src_lo;
20192021 u8 sreg_hi = sstk ? IA32_EBX : src_hi;
20202022
@@ -2026,6 +2028,13 @@ static int do_jit(struct bpf_prog *bpf_prog, int *addrs, u8 *image, · 5 unmodified lines
20262028 add_2reg(0x40, IA32_EBP,
20272029 IA32_EDX),
20282030 STACK_VAR(dst_hi));
2031+ } else {
2032+ /* mov dreg_lo,dst_lo */
2033+ EMIT2(0x89, add_2reg(0xC0, dreg_lo, dst_lo));
2034+ if (is_jmp64)
2035+ /* mov dreg_hi,dst_hi */
2036+ EMIT2(0x89,
2037+ add_2reg(0xC0, dreg_hi, dst_hi));
20292038 }
20302039
20312040 if (sstk) {
@@ -2050,8 +2059,8 @@ static int do_jit(struct bpf_prog *bpf_prog, int *addrs, u8 *image, · 18 unmodified lines
20502059 case BPF_JMP | BPF_JSET | BPF_K:
20512060 case BPF_JMP32 | BPF_JSET | BPF_K: {
20522061 bool is_jmp64 = BPF_CLASS(insn->code) == BPF_JMP;
2053− u8 dreg_lo = dstk ? IA32_EAX : dst_lo;
2054− u8 dreg_hi = dstk ? IA32_EDX : dst_hi;
2062+ u8 dreg_lo = IA32_EAX;
2063+ u8 dreg_hi = IA32_EDX;
20552064 u8 sreg_lo = IA32_ECX;
20562065 u8 sreg_hi = IA32_EBX;
20572066 u32 hi;
@@ -2064,6 +2073,13 @@ static int do_jit(struct bpf_prog *bpf_prog, int *addrs, u8 *image, · 6 unmodified lines
20642073 add_2reg(0x40, IA32_EBP,
20652074 IA32_EDX),
20662075 STACK_VAR(dst_hi));
2076+ } else {
2077+ /* mov dreg_lo,dst_lo */
2078+ EMIT2(0x89, add_2reg(0xC0, dreg_lo, dst_lo));
2079+ if (is_jmp64)
2080+ /* mov dreg_hi,dst_hi */
2081+ EMIT2(0x89,
2082+ add_2reg(0xC0, dreg_hi, dst_hi));
20672083 }
20682084
20692085 /* mov ecx,imm32 */
include/uapi/linux/bpf.h+1−1
@@ -1642,7 +1642,7 @@ union bpf_attr { · 1641 unmodified lines
16421642 * ifindex, but doesn't require a map to do so.
16431643 * Return
16441644 * **XDP_REDIRECT** on success, or the value of the two lower bits
1645− * of the **flags* argument on error.
1645+ * of the *flags* argument on error.
16461646 *
16471647 * int bpf_sk_redirect_map(struct sk_buff *skb, struct bpf_map *map, u32 key, u64 flags)
16481648 * Description
kernel/bpf/cpumap.c+1−1
@@ -469,7 +469,7 @@ static int cpu_map_update_elem(struct bpf_map *map, void *key, void *value, · 468 unmodified lines
469469 return -EOVERFLOW;
470470
471471 /* Make sure CPU is a valid possible cpu */
472− if (!cpu_possible(key_cpu))
472+ if (key_cpu >= nr_cpumask_bits || !cpu_possible(key_cpu))
473473 return -ENODEV;
474474
475475 if (qsize == 0) {
kernel/bpf/syscall.c+10−3
@@ -2283,7 +2283,7 @@ static void bpf_link_show_fdinfo(struct seq_file *m, struct file *filp) · 2282 unmodified lines
22832283 }
22842284 #endif
22852285
2286−const struct file_operations bpf_link_fops = {
2286+static const struct file_operations bpf_link_fops = {
22872287 #ifdef CONFIG_PROC_FS
22882288 .show_fdinfo = bpf_link_show_fdinfo,
22892289 #endif
@@ -3628,8 +3628,10 @@ static int link_update(union bpf_attr *attr) · 1338 unmodified lines
36283628 return PTR_ERR(link);
36293629
36303630 new_prog = bpf_prog_get(attr->link_update.new_prog_fd);
3631− if (IS_ERR(new_prog))
3632− return PTR_ERR(new_prog);
3631+ if (IS_ERR(new_prog)) {
3632+ ret = PTR_ERR(new_prog);
3633+ goto out_put_link;
3634+ }
36333635
36343636 if (flags & BPF_F_REPLACE) {
36353637 old_prog = bpf_prog_get(attr->link_update.old_prog_fd);
@@ -3638,6 +3640,9 @@ static int link_update(union bpf_attr *attr) · 2 unmodified lines
36383640 old_prog = NULL;
36393641 goto out_put_progs;
36403642 }
3643+ } else if (attr->link_update.old_prog_fd) {
3644+ ret = -EINVAL;
3645+ goto out_put_progs;
36413646 }
36423647
36433648 #ifdef CONFIG_CGROUP_BPF
@@ -3653,6 +3658,8 @@ out_put_progs: · 9 unmodified lines
36533658 bpf_prog_put(old_prog);
36543659 if (ret)
36553660 bpf_prog_put(new_prog);
3661+out_put_link:
3662+ bpf_link_put(link);
36563663 return ret;
36573664 }
36583665
kernel/bpf/verifier.c+28−10
@@ -2118,6 +2118,15 @@ static bool register_is_const(struct bpf_reg_state *reg) · 2117 unmodified lines
21182118 return reg->type == SCALAR_VALUE && tnum_is_const(reg->var_off);
21192119 }
21202120
2121+static bool __is_pointer_value(bool allow_ptr_leaks,
2122+ const struct bpf_reg_state *reg)
2123+{
2124+ if (allow_ptr_leaks)
2125+ return false;
2126+
2127+ return reg->type != SCALAR_VALUE;
2128+}
2129+
21212130 static void save_register_state(struct bpf_func_state *state,
21222131 int spi, struct bpf_reg_state *reg)
21232132 {
@@ -2308,6 +2317,16 @@ static int check_stack_read(struct bpf_verifier_env *env, · 184 unmodified lines
23082317 * which resets stack/reg liveness for state transitions
23092318 */
23102319 state->regs[value_regno].live |= REG_LIVE_WRITTEN;
2320+ } else if (__is_pointer_value(env->allow_ptr_leaks, reg)) {
2321+ /* If value_regno==-1, the caller is asking us whether
2322+ * it is acceptable to use this value as a SCALAR_VALUE
2323+ * (e.g. for XADD).
2324+ * We must not allow unprivileged callers to do that
2325+ * with spilled pointers.
2326+ */
2327+ verbose(env, "leaking pointer from stack off %d\n",
2328+ off);
2329+ return -EACCES;
23112330 }
23122331 mark_reg_read(env, reg, reg->parent, REG_LIVE_READ64);
23132332 } else {
@@ -2673,15 +2692,6 @@ static int check_sock_access(struct bpf_verifier_env *env, int insn_idx, · 359 unmodified lines
26732692 return -EACCES;
26742693 }
26752694
2676−static bool __is_pointer_value(bool allow_ptr_leaks,
2677− const struct bpf_reg_state *reg)
2678−{
2679− if (allow_ptr_leaks)
2680− return false;
2681−
2682− return reg->type != SCALAR_VALUE;
2683−}
2684−
26852695 static struct bpf_reg_state *reg_state(struct bpf_verifier_env *env, int regno)
26862696 {
26872697 return cur_regs(env) + regno;
@@ -3089,7 +3099,7 @@ static int check_ptr_to_btf_access(struct bpf_verifier_env *env, · 401 unmodified lines
30893099 if (ret < 0)
30903100 return ret;
30913101
3092− if (atype == BPF_READ) {
3102+ if (atype == BPF_READ && value_regno >= 0) {
30933103 if (ret == SCALAR_VALUE) {
30943104 mark_reg_unknown(env, regs, value_regno);
30953105 return 0;
@@ -10487,6 +10497,7 @@ static int check_attach_btf_id(struct bpf_verifier_env *env) · 7391 unmodified lines
1048710497 return -EINVAL;
1048810498 }
1048910499 env->ops = bpf_verifier_ops[tgt_prog->type];
10500+ prog->expected_attach_type = tgt_prog->expected_attach_type;
1049010501 }
1049110502 if (!tgt_prog->jited) {
1049210503 verbose(env, "Can attach to only JITed progs\n");
@@ -10831,6 +10842,13 @@ err_release_maps: · 338 unmodified lines
1083110842 * them now. Otherwise free_used_maps() will release them.
1083210843 */
1083310844 release_maps(env);
10845+
10846+ /* extension progs temporarily inherit the attach_type of their targets
10847+ for verification purposes, so set it back to zero before returning
10848+ */
10849+ if (env->prog->type == BPF_PROG_TYPE_EXT)
10850+ env->prog->expected_attach_type = 0;
10851+
1083410852 *prog = env->prog;
1083510853 err_unlock:
1083610854 if (!is_priv)
tools/bpf/bpftool/struct_ops.c+7−1
@@ -479,6 +479,7 @@ static int do_unregister(int argc, char **argv) · 478 unmodified lines
479479
480480 static int do_register(int argc, char **argv)
481481 {
482+ struct bpf_object_load_attr load_attr = {};
482483 const struct bpf_map_def *def;
483484 struct bpf_map_info info = {};
484485 __u32 info_len = sizeof(info);
@@ -499,7 +500,12 @@ static int do_register(int argc, char **argv) · 14 unmodified lines
499500
500501 set_max_rlimit();
501502
502− if (bpf_object__load(obj)) {
503+ load_attr.obj = obj;
504+ if (verifier_logs)
505+ /* log_level1 + log_level2 + stats, but not stable UAPI */
506+ load_attr.log_level = 1 + 2 + 4;
507+
508+ if (bpf_object__load_xattr(&load_attr)) {
503509 bpf_object__close(obj);
504510 return -1;
505511 }
tools/bpf/runqslower/Makefile+1−1
@@ -8,7 +8,7 @@ BPFTOOL ?= $(DEFAULT_BPFTOOL) · 7 unmodified lines
88 LIBBPF_SRC := $(abspath ../../lib/bpf)
99 BPFOBJ := $(OUTPUT)/libbpf.a
1010 BPF_INCLUDE := $(OUTPUT)
11−INCLUDES := -I$(BPF_INCLUDE) -I$(OUTPUT) -I$(abspath ../../lib)
11+INCLUDES := -I$(OUTPUT) -I$(BPF_INCLUDE) -I$(abspath ../../lib)
1212 CFLAGS := -g -Wall
1313
1414 # Try to detect best kernel BTF source
tools/include/uapi/linux/bpf.h+1−1
@@ -1642,7 +1642,7 @@ union bpf_attr { · 1641 unmodified lines
16421642 * ifindex, but doesn't require a map to do so.
16431643 * Return
16441644 * **XDP_REDIRECT** on success, or the value of the two lower bits
1645− * of the **flags* argument on error.
1645+ * of the *flags* argument on error.
16461646 *
16471647 * int bpf_sk_redirect_map(struct sk_buff *skb, struct bpf_map *map, u32 key, u64 flags)
16481648 * Description
tools/lib/bpf/netlink.c+2−0
@@ -321,6 +321,8 @@ int bpf_get_link_xdp_info(int ifindex, struct xdp_link_info *info, · 320 unmodified lines
321321
322322 static __u32 get_xdp_id(struct xdp_link_info *info, __u32 flags)
323323 {
324+ flags &= XDP_FLAGS_MODES;
325+
324326 if (info->attach_mode != XDP_ATTACHED_MULTI && !flags)
325327 return info->prog_id;
326328 if (flags & XDP_FLAGS_DRV_MODE)
tools/testing/selftests/bpf/prog_tests/fexit_bpf2bpf.c+24−6
@@ -5,7 +5,8 @@ · 4 unmodified lines
55 static void test_fexit_bpf2bpf_common(const char *obj_file,
66 const char *target_obj_file,
77 int prog_cnt,
8− const char **prog_name)
8+ const char **prog_name,
9+ bool run_prog)
910 {
1011 struct bpf_object *obj = NULL, *pkt_obj;
1112 int err, pkt_fd, i;
@@ -18,7 +19,8 @@ static void test_fexit_bpf2bpf_common(const char *obj_file, · 6 unmodified lines
1819
1920 err = bpf_prog_load(target_obj_file, BPF_PROG_TYPE_UNSPEC,
2021 &pkt_obj, &pkt_fd);
21− if (CHECK(err, "prog_load sched cls", "err %d errno %d\n", err, errno))
22+ if (CHECK(err, "tgt_prog_load", "file %s err %d errno %d\n",
23+ target_obj_file, err, errno))
2224 return;
2325 DECLARE_LIBBPF_OPTS(bpf_object_open_opts, opts,
2426 .attach_prog_fd = pkt_fd,
@@ -33,7 +35,7 @@ static void test_fexit_bpf2bpf_common(const char *obj_file, · 8 unmodified lines
3335
3436 obj = bpf_object__open_file(obj_file, &opts);
3537 if (CHECK(IS_ERR_OR_NULL(obj), "obj_open",
36− "failed to open fexit_bpf2bpf: %ld\n",
38+ "failed to open %s: %ld\n", obj_file,
3739 PTR_ERR(obj)))
3840 goto close_prog;
3941
@@ -49,6 +51,10 @@ static void test_fexit_bpf2bpf_common(const char *obj_file, · 9 unmodified lines
4951 if (CHECK(IS_ERR(link[i]), "attach_trace", "failed to link\n"))
5052 goto close_prog;
5153 }
54+
55+ if (!run_prog)
56+ goto close_prog;
57+
5258 data_map = bpf_object__find_map_by_name(obj, "fexit_bp.bss");
5359 if (CHECK(!data_map, "find_data_map", "data map not found\n"))
5460 goto close_prog;
@@ -89,7 +95,7 @@ static void test_target_no_callees(void) · 34 unmodified lines
8995 test_fexit_bpf2bpf_common("./fexit_bpf2bpf_simple.o",
9096 "./test_pkt_md_access.o",
9197 ARRAY_SIZE(prog_name),
92− prog_name);
98+ prog_name, true);
9399 }
94100
95101 static void test_target_yes_callees(void)
@@ -103,7 +109,7 @@ static void test_target_yes_callees(void) · 7 unmodified lines
103109 test_fexit_bpf2bpf_common("./fexit_bpf2bpf.o",
104110 "./test_pkt_access.o",
105111 ARRAY_SIZE(prog_name),
106− prog_name);
112+ prog_name, true);
107113 }
108114
109115 static void test_func_replace(void)
@@ -120,7 +126,18 @@ static void test_func_replace(void) · 10 unmodified lines
120126 test_fexit_bpf2bpf_common("./fexit_bpf2bpf.o",
121127 "./test_pkt_access.o",
122128 ARRAY_SIZE(prog_name),
123− prog_name);
129+ prog_name, true);
130+}
131+
132+static void test_func_replace_verify(void)
133+{
134+ const char *prog_name[] = {
135+ "freplace/do_bind",
136+ };
137+ test_fexit_bpf2bpf_common("./freplace_connect4.o",
138+ "./connect4_prog.o",
139+ ARRAY_SIZE(prog_name),
140+ prog_name, false);
124141 }
125142
126143 void test_fexit_bpf2bpf(void)
@@ -128,4 +145,5 @@ void test_fexit_bpf2bpf(void) · 1 unmodified line
128145 test_target_no_callees();
129146 test_target_yes_callees();
130147 test_func_replace();
148+ test_func_replace_verify();
131149 }
tools/testing/selftests/bpf/progs/connect4_prog.c+16−12
@@ -18,11 +18,25 @@ · 17 unmodified lines
1818
1919 int _version SEC("version") = 1;
2020
21+__attribute__ ((noinline))
22+int do_bind(struct bpf_sock_addr *ctx)
23+{
24+ struct sockaddr_in sa = {};
25+
26+ sa.sin_family = AF_INET;
27+ sa.sin_port = bpf_htons(0);
28+ sa.sin_addr.s_addr = bpf_htonl(SRC_REWRITE_IP4);
29+
30+ if (bpf_bind(ctx, (struct sockaddr *)&sa, sizeof(sa)) != 0)
31+ return 0;
32+
33+ return 1;
34+}
35+
2136 SEC("cgroup/connect4")
2237 int connect_v4_prog(struct bpf_sock_addr *ctx)
2338 {
2439 struct bpf_sock_tuple tuple = {};
25− struct sockaddr_in sa;
2640 struct bpf_sock *sk;
2741
2842 /* Verify that new destination is available. */
@@ -56,17 +70,7 @@ int connect_v4_prog(struct bpf_sock_addr *ctx) · 27 unmodified lines
5670 ctx->user_ip4 = bpf_htonl(DST_REWRITE_IP4);
5771 ctx->user_port = bpf_htons(DST_REWRITE_PORT4);
5872
59− /* Rewrite source. */
60− memset(&sa, 0, sizeof(sa));
61−
62− sa.sin_family = AF_INET;
63− sa.sin_port = bpf_htons(0);
64− sa.sin_addr.s_addr = bpf_htonl(SRC_REWRITE_IP4);
65−
66− if (bpf_bind(ctx, (struct sockaddr *)&sa, sizeof(sa)) != 0)
67− return 0;
68−
69− return 1;
73+ return do_bind(ctx) ? 1 : 0;
7074 }
7175
7276 char _license[] SEC("license") = "GPL";
tools/testing/selftests/bpf/progs/freplace_connect4.c+18−0
@@ -0,0 +1,18 @@
1+#include <linux/stddef.h>
2+#include <linux/ipv6.h>
3+#include <linux/bpf.h>
4+#include <linux/in.h>
5+#include <sys/socket.h>
6+#include <bpf/bpf_helpers.h>
7+#include <bpf/bpf_endian.h>
8+
9+SEC("freplace/do_bind")
10+int new_do_bind(struct bpf_sock_addr *ctx)
11+{
12+ struct sockaddr_in sa = {};
13+
14+ bpf_bind(ctx, (struct sockaddr *)&sa, sizeof(sa));
15+ return 0;
16+}
17+
18+char _license[] SEC("license") = "GPL";
tools/testing/selftests/bpf/progs/test_btf_haskv.c+5−13
@@ -20,20 +20,12 @@ struct bpf_map_def SEC("maps") btf_map = { · 19 unmodified lines
2020
2121 BPF_ANNOTATE_KV_PAIR(btf_map, int, struct ipv_counts);
2222
23−struct dummy_tracepoint_args {
24− unsigned long long pad;
25− struct sock *sock;
26−};
27−
2823 __attribute__((noinline))
29−int test_long_fname_2(struct dummy_tracepoint_args *arg)
24+int test_long_fname_2(void)
3025 {
3126 struct ipv_counts *counts;
3227 int key = 0;
3328
34− if (!arg->sock)
35− return 0;
36−
3729 counts = bpf_map_lookup_elem(&btf_map, &key);
3830 if (!counts)
3931 return 0;
@@ -44,15 +36,15 @@ int test_long_fname_2(struct dummy_tracepoint_args *arg) · 4 unmodified lines
4436 }
4537
4638 __attribute__((noinline))
47−int test_long_fname_1(struct dummy_tracepoint_args *arg)
39+int test_long_fname_1(void)
4840 {
49− return test_long_fname_2(arg);
41+ return test_long_fname_2();
5042 }
5143
5244 SEC("dummy_tracepoint")
53−int _dummy_tracepoint(struct dummy_tracepoint_args *arg)
45+int _dummy_tracepoint(void *arg)
5446 {
55− return test_long_fname_1(arg);
47+ return test_long_fname_1();
5648 }
5749
5850 char _license[] SEC("license") = "GPL";
tools/testing/selftests/bpf/progs/test_btf_newkv.c+5−13
@@ -28,20 +28,12 @@ struct { · 27 unmodified lines
2828 __type(value, struct ipv_counts);
2929 } btf_map SEC(".maps");
3030
31−struct dummy_tracepoint_args {
32− unsigned long long pad;
33− struct sock *sock;
34−};
35−
3631 __attribute__((noinline))
37−int test_long_fname_2(struct dummy_tracepoint_args *arg)
32+int test_long_fname_2(void)
3833 {
3934 struct ipv_counts *counts;
4035 int key = 0;
4136
42− if (!arg->sock)
43− return 0;
44−
4537 counts = bpf_map_lookup_elem(&btf_map, &key);
4638 if (!counts)
4739 return 0;
@@ -57,15 +49,15 @@ int test_long_fname_2(struct dummy_tracepoint_args *arg) · 9 unmodified lines
5749 }
5850
5951 __attribute__((noinline))
60−int test_long_fname_1(struct dummy_tracepoint_args *arg)
52+int test_long_fname_1(void)
6153 {
62− return test_long_fname_2(arg);
54+ return test_long_fname_2();
6355 }
6456
6557 SEC("dummy_tracepoint")
66−int _dummy_tracepoint(struct dummy_tracepoint_args *arg)
58+int _dummy_tracepoint(void *arg)
6759 {
68− return test_long_fname_1(arg);
60+ return test_long_fname_1();
6961 }
7062
7163 char _license[] SEC("license") = "GPL";
tools/testing/selftests/bpf/progs/test_btf_nokv.c+5−13
@@ -17,20 +17,12 @@ struct bpf_map_def SEC("maps") btf_map = { · 16 unmodified lines
1717 .max_entries = 4,
1818 };
1919
20−struct dummy_tracepoint_args {
21− unsigned long long pad;
22− struct sock *sock;
23−};
24−
2520 __attribute__((noinline))
26−int test_long_fname_2(struct dummy_tracepoint_args *arg)
21+int test_long_fname_2(void)
2722 {
2823 struct ipv_counts *counts;
2924 int key = 0;
3025
31− if (!arg->sock)
32− return 0;
33−
3426 counts = bpf_map_lookup_elem(&btf_map, &key);
3527 if (!counts)
3628 return 0;
@@ -41,15 +33,15 @@ int test_long_fname_2(struct dummy_tracepoint_args *arg) · 4 unmodified lines
4133 }
4234
4335 __attribute__((noinline))
44−int test_long_fname_1(struct dummy_tracepoint_args *arg)
36+int test_long_fname_1(void)
4537 {
46− return test_long_fname_2(arg);
38+ return test_long_fname_2();
4739 }
4840
4941 SEC("dummy_tracepoint")
50−int _dummy_tracepoint(struct dummy_tracepoint_args *arg)
42+int _dummy_tracepoint(void *arg)
5143 {
52− return test_long_fname_1(arg);
44+ return test_long_fname_1();
5345 }
5446
5547 char _license[] SEC("license") = "GPL";
tools/testing/selftests/bpf/test_btf.c+1−1
@@ -2854,7 +2854,7 @@ static struct btf_raw_test raw_tests[] = { · 2853 unmodified lines
28542854 .value_type_id = 1,
28552855 .max_entries = 4,
28562856 .btf_load_err = true,
2857− .err_str = "vlen != 0",
2857+ .err_str = "Invalid func linkage",
28582858 },
28592859
28602860 {
tools/testing/selftests/bpf/verifier/stack_ptr.c+40−0
@@ -315,3 +315,43 @@ · 314 unmodified lines
315315 },
316316 .result = ACCEPT,
317317 },
318+{
319+ "store PTR_TO_STACK in R10 to array map using BPF_B",
320+ .insns = {
321+ /* Load pointer to map. */
322+ BPF_MOV64_REG(BPF_REG_2, BPF_REG_10),
323+ BPF_ALU64_IMM(BPF_ADD, BPF_REG_2, -8),
324+ BPF_ST_MEM(BPF_DW, BPF_REG_2, 0, 0),
325+ BPF_LD_MAP_FD(BPF_REG_1, 0),
326+ BPF_EMIT_CALL(BPF_FUNC_map_lookup_elem),
327+ BPF_JMP_IMM(BPF_JNE, BPF_REG_0, 0, 2),
328+ BPF_MOV64_IMM(BPF_REG_0, 2),
329+ BPF_EXIT_INSN(),
330+ BPF_MOV64_REG(BPF_REG_1, BPF_REG_0),
331+ /* Copy R10 to R9. */
332+ BPF_MOV64_REG(BPF_REG_9, BPF_REG_10),
333+ /* Pollute other registers with unaligned values. */
334+ BPF_MOV64_IMM(BPF_REG_2, -1),
335+ BPF_MOV64_IMM(BPF_REG_3, -1),
336+ BPF_MOV64_IMM(BPF_REG_4, -1),
337+ BPF_MOV64_IMM(BPF_REG_5, -1),
338+ BPF_MOV64_IMM(BPF_REG_6, -1),
339+ BPF_MOV64_IMM(BPF_REG_7, -1),
340+ BPF_MOV64_IMM(BPF_REG_8, -1),
341+ /* Store both R9 and R10 with BPF_B and read back. */
342+ BPF_STX_MEM(BPF_B, BPF_REG_1, BPF_REG_10, 0),
343+ BPF_LDX_MEM(BPF_B, BPF_REG_2, BPF_REG_1, 0),
344+ BPF_STX_MEM(BPF_B, BPF_REG_1, BPF_REG_9, 0),
345+ BPF_LDX_MEM(BPF_B, BPF_REG_3, BPF_REG_1, 0),
346+ /* Should read back as same value. */
347+ BPF_JMP_REG(BPF_JEQ, BPF_REG_2, BPF_REG_3, 2),
348+ BPF_MOV64_IMM(BPF_REG_0, 1),
349+ BPF_EXIT_INSN(),
350+ BPF_MOV64_IMM(BPF_REG_0, 42),
351+ BPF_EXIT_INSN(),
352+ },
353+ .fixup_map_array_48b = { 3 },
354+ .result = ACCEPT,
355+ .retval = 42,
356+ .prog_type = BPF_PROG_TYPE_SCHED_CLS,
357+},
tools/testing/selftests/bpf/verifier/value_illegal_alu.c+1−0
@@ -88,6 +88,7 @@ · 87 unmodified lines
8888 BPF_EXIT_INSN(),
8989 },
9090 .fixup_map_hash_48b = { 3 },
91+ .errstr_unpriv = "leaking pointer from stack off -8",
9192 .errstr = "R0 invalid mem access 'inv'",
9293 .result = REJECT,
9394 .flags = F_NEEDS_EFFICIENT_UNALIGNED_ACCESS,