Skip to content

Commit ee3392e

Browse files
committed
Alexei Starovoitov says: ==================== pull-request: bpf-next 2023-04-24 We've added 5 non-merge commits during the last 3 day(s) which contain a total of 7 files changed, 87 insertions(+), 44 deletions(-). The main changes are: 1) Workaround for bpf iter selftest due to lack of subprog support in precision tracking, from Andrii. 2) Disable bpf_refcount_acquire kfunc until races are fixed, from Dave. 3) One more test_verifier test converted from asm macro to asm in C, from Eduard. 4) Fix build with NETFILTER=y INET=n config, from Florian. 5) Add __rcu_read_{lock,unlock} into deny list, from Yafang. * tag 'for-netdev' of https://git.kernel.org/pub/scm/linux/kernel/git/bpf/bpf-next: selftests/bpf: avoid mark_all_scalars_precise() trigger in one of iter tests bpf: Add __rcu_read_{lock,unlock} into btf id deny list bpf: Disable bpf_refcount_acquire kfunc calls until race conditions are fixed selftests/bpf: verifier/prevent_map_lookup converted to inline assembly bpf: fix link failure with NETFILTER=y INET=n ==================== Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Jakub Kicinski <[email protected]>
2 parents 9610a8d + be7dbd2 commit ee3392e

File tree

7 files changed

+87
-44
lines changed

7 files changed

+87
-44
lines changed

include/linux/bpf_types.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ BPF_PROG_TYPE(BPF_PROG_TYPE_LSM, lsm,
7979
#endif
8080
BPF_PROG_TYPE(BPF_PROG_TYPE_SYSCALL, bpf_syscall,
8181
void *, void *)
82-
#ifdef CONFIG_NETFILTER
82+
#ifdef CONFIG_NETFILTER_BPF_LINK
8383
BPF_PROG_TYPE(BPF_PROG_TYPE_NETFILTER, netfilter,
8484
struct bpf_nf_ctx, struct bpf_nf_ctx)
8585
#endif

kernel/bpf/verifier.c

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10509,7 +10509,10 @@ static int check_kfunc_args(struct bpf_verifier_env *env, struct bpf_kfunc_call_
1050910509
verbose(env, "arg#%d doesn't point to a type with bpf_refcount field\n", i);
1051010510
return -EINVAL;
1051110511
}
10512-
10512+
if (rec->refcount_off >= 0) {
10513+
verbose(env, "bpf_refcount_acquire calls are disabled for now\n");
10514+
return -EINVAL;
10515+
}
1051310516
meta->arg_refcount_acquire.btf = reg->btf;
1051410517
meta->arg_refcount_acquire.btf_id = reg->btf_id;
1051510518
break;
@@ -18668,6 +18671,10 @@ BTF_ID(func, rcu_read_unlock_strict)
1866818671
BTF_ID(func, preempt_count_add)
1866918672
BTF_ID(func, preempt_count_sub)
1867018673
#endif
18674+
#ifdef CONFIG_PREEMPT_RCU
18675+
BTF_ID(func, __rcu_read_lock)
18676+
BTF_ID(func, __rcu_read_unlock)
18677+
#endif
1867118678
BTF_SET_END(btf_id_deny)
1867218679

1867318680
static bool can_be_sleepable(struct bpf_prog *prog)

tools/testing/selftests/bpf/prog_tests/refcounted_kptr.c

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,8 @@
99

1010
void test_refcounted_kptr(void)
1111
{
12-
RUN_TESTS(refcounted_kptr);
1312
}
1413

1514
void test_refcounted_kptr_fail(void)
1615
{
17-
RUN_TESTS(refcounted_kptr_fail);
1816
}

tools/testing/selftests/bpf/prog_tests/verifier.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@
4242
#include "verifier_meta_access.skel.h"
4343
#include "verifier_netfilter_ctx.skel.h"
4444
#include "verifier_netfilter_retcode.skel.h"
45+
#include "verifier_prevent_map_lookup.skel.h"
4546
#include "verifier_raw_stack.skel.h"
4647
#include "verifier_raw_tp_writable.skel.h"
4748
#include "verifier_reg_equal.skel.h"
@@ -140,6 +141,7 @@ void test_verifier_masking(void) { RUN(verifier_masking); }
140141
void test_verifier_meta_access(void) { RUN(verifier_meta_access); }
141142
void test_verifier_netfilter_ctx(void) { RUN(verifier_netfilter_ctx); }
142143
void test_verifier_netfilter_retcode(void) { RUN(verifier_netfilter_retcode); }
144+
void test_verifier_prevent_map_lookup(void) { RUN(verifier_prevent_map_lookup); }
143145
void test_verifier_raw_stack(void) { RUN(verifier_raw_stack); }
144146
void test_verifier_raw_tp_writable(void) { RUN(verifier_raw_tp_writable); }
145147
void test_verifier_reg_equal(void) { RUN(verifier_reg_equal); }

tools/testing/selftests/bpf/progs/iters.c

Lines changed: 15 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -651,25 +651,29 @@ int iter_stack_array_loop(const void *ctx)
651651
return sum;
652652
}
653653

654-
static __noinline void fill(struct bpf_iter_num *it, int *arr, __u32 n, int mul)
654+
#define ARR_SZ 16
655+
656+
static __noinline void fill(struct bpf_iter_num *it, int *arr, int mul)
655657
{
656-
int *t, i;
658+
int *t;
659+
__u64 i;
657660

658661
while ((t = bpf_iter_num_next(it))) {
659662
i = *t;
660-
if (i >= n)
663+
if (i >= ARR_SZ)
661664
break;
662665
arr[i] = i * mul;
663666
}
664667
}
665668

666-
static __noinline int sum(struct bpf_iter_num *it, int *arr, __u32 n)
669+
static __noinline int sum(struct bpf_iter_num *it, int *arr)
667670
{
668-
int *t, i, sum = 0;;
671+
int *t, sum = 0;;
672+
__u64 i;
669673

670674
while ((t = bpf_iter_num_next(it))) {
671675
i = *t;
672-
if (i >= n)
676+
if (i >= ARR_SZ)
673677
break;
674678
sum += arr[i];
675679
}
@@ -681,7 +685,7 @@ SEC("raw_tp")
681685
__success
682686
int iter_pass_iter_ptr_to_subprog(const void *ctx)
683687
{
684-
int arr1[16], arr2[32];
688+
int arr1[ARR_SZ], arr2[ARR_SZ];
685689
struct bpf_iter_num it;
686690
int n, sum1, sum2;
687691

@@ -690,25 +694,25 @@ int iter_pass_iter_ptr_to_subprog(const void *ctx)
690694
/* fill arr1 */
691695
n = ARRAY_SIZE(arr1);
692696
bpf_iter_num_new(&it, 0, n);
693-
fill(&it, arr1, n, 2);
697+
fill(&it, arr1, 2);
694698
bpf_iter_num_destroy(&it);
695699

696700
/* fill arr2 */
697701
n = ARRAY_SIZE(arr2);
698702
bpf_iter_num_new(&it, 0, n);
699-
fill(&it, arr2, n, 10);
703+
fill(&it, arr2, 10);
700704
bpf_iter_num_destroy(&it);
701705

702706
/* sum arr1 */
703707
n = ARRAY_SIZE(arr1);
704708
bpf_iter_num_new(&it, 0, n);
705-
sum1 = sum(&it, arr1, n);
709+
sum1 = sum(&it, arr1);
706710
bpf_iter_num_destroy(&it);
707711

708712
/* sum arr2 */
709713
n = ARRAY_SIZE(arr2);
710714
bpf_iter_num_new(&it, 0, n);
711-
sum2 = sum(&it, arr2, n);
715+
sum2 = sum(&it, arr2);
712716
bpf_iter_num_destroy(&it);
713717

714718
bpf_printk("sum1=%d, sum2=%d", sum1, sum2);
Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
// SPDX-License-Identifier: GPL-2.0
2+
/* Converted from tools/testing/selftests/bpf/verifier/prevent_map_lookup.c */
3+
4+
#include <linux/bpf.h>
5+
#include <bpf/bpf_helpers.h>
6+
#include "bpf_misc.h"
7+
8+
struct {
9+
__uint(type, BPF_MAP_TYPE_STACK_TRACE);
10+
__uint(max_entries, 1);
11+
__type(key, __u32);
12+
__type(value, __u64);
13+
} map_stacktrace SEC(".maps");
14+
15+
struct {
16+
__uint(type, BPF_MAP_TYPE_PROG_ARRAY);
17+
__uint(max_entries, 8);
18+
__uint(key_size, sizeof(int));
19+
__array(values, void (void));
20+
} map_prog2_socket SEC(".maps");
21+
22+
SEC("perf_event")
23+
__description("prevent map lookup in stack trace")
24+
__failure __msg("cannot pass map_type 7 into func bpf_map_lookup_elem")
25+
__naked void map_lookup_in_stack_trace(void)
26+
{
27+
asm volatile (" \
28+
r1 = 0; \
29+
*(u64*)(r10 - 8) = r1; \
30+
r2 = r10; \
31+
r2 += -8; \
32+
r1 = %[map_stacktrace] ll; \
33+
call %[bpf_map_lookup_elem]; \
34+
exit; \
35+
" :
36+
: __imm(bpf_map_lookup_elem),
37+
__imm_addr(map_stacktrace)
38+
: __clobber_all);
39+
}
40+
41+
SEC("socket")
42+
__description("prevent map lookup in prog array")
43+
__failure __msg("cannot pass map_type 3 into func bpf_map_lookup_elem")
44+
__failure_unpriv
45+
__naked void map_lookup_in_prog_array(void)
46+
{
47+
asm volatile (" \
48+
r1 = 0; \
49+
*(u64*)(r10 - 8) = r1; \
50+
r2 = r10; \
51+
r2 += -8; \
52+
r1 = %[map_prog2_socket] ll; \
53+
call %[bpf_map_lookup_elem]; \
54+
exit; \
55+
" :
56+
: __imm(bpf_map_lookup_elem),
57+
__imm_addr(map_prog2_socket)
58+
: __clobber_all);
59+
}
60+
61+
char _license[] SEC("license") = "GPL";

tools/testing/selftests/bpf/verifier/prevent_map_lookup.c

Lines changed: 0 additions & 29 deletions
This file was deleted.

0 commit comments

Comments
 (0)