diff --git a/include/linux/bpf.h b/include/linux/bpf.h index 2265a4411198cce4950df0b8a9eab8b26b4e168c..a75abe99491899b91f5e2b30fade7bc32b8e8ba5 100644 --- a/include/linux/bpf.h +++ b/include/linux/bpf.h @@ -1537,9 +1537,6 @@ int bpf_prog_test_run_flow_dissector(struct bpf_prog *prog, int bpf_prog_test_run_raw_tp(struct bpf_prog *prog, const union bpf_attr *kattr, union bpf_attr __user *uattr); -int bpf_prog_test_run_sk_lookup(struct bpf_prog *prog, - const union bpf_attr *kattr, - union bpf_attr __user *uattr); bool btf_ctx_access(int off, int size, enum bpf_access_type type, const struct bpf_prog *prog, struct bpf_insn_access_aux *info); @@ -1754,13 +1751,6 @@ static inline int bpf_prog_test_run_flow_dissector(struct bpf_prog *prog, return -ENOTSUPP; } -static inline int bpf_prog_test_run_sk_lookup(struct bpf_prog *prog, - const union bpf_attr *kattr, - union bpf_attr __user *uattr) -{ - return -ENOTSUPP; -} - static inline void bpf_map_put(struct bpf_map *map) { } diff --git a/include/uapi/linux/bpf.h b/include/uapi/linux/bpf.h index 2a234023821e387f2d07ec95756671721260b619..0f39fdcb2273c4ca42c7a00a88ec2a34e3faa886 100644 --- a/include/uapi/linux/bpf.h +++ b/include/uapi/linux/bpf.h @@ -5007,10 +5007,7 @@ struct bpf_pidns_info { /* User accessible data for SK_LOOKUP programs. Add new fields at the end. */ struct bpf_sk_lookup { - union { - __bpf_md_ptr(struct bpf_sock *, sk); /* Selected socket */ - __u64 cookie; /* Non-zero if socket was selected in PROG_TEST_RUN */ - }; + __bpf_md_ptr(struct bpf_sock *, sk); /* Selected socket */ __u32 family; /* Protocol family (AF_INET, AF_INET6) */ __u32 protocol; /* IP protocol (IPPROTO_TCP, IPPROTO_UDP) */ diff --git a/net/bpf/test_run.c b/net/bpf/test_run.c index 07e64bbe7a4fd3e3ace85fc6825017548c15cb26..99712d35e5351e72f5e46caac6ba141a9d16221d 100644 --- a/net/bpf/test_run.c +++ b/net/bpf/test_run.c @@ -10,10 +10,8 @@ #include #include #include -#include #include #include -#include #define CREATE_TRACE_POINTS #include @@ -782,106 +780,3 @@ int bpf_prog_test_run_flow_dissector(struct bpf_prog *prog, kfree(data); return ret; } - -int bpf_prog_test_run_sk_lookup(struct bpf_prog *prog, const union bpf_attr *kattr, - union bpf_attr __user *uattr) -{ - struct bpf_test_timer t = { NO_PREEMPT }; - struct bpf_prog_array *progs = NULL; - struct bpf_sk_lookup_kern ctx = {}; - u32 repeat = kattr->test.repeat; - struct bpf_sk_lookup *user_ctx; - u32 retval, duration; - int ret = -EINVAL; - - if (prog->type != BPF_PROG_TYPE_SK_LOOKUP) - return -EINVAL; - - if (kattr->test.flags || kattr->test.cpu) - return -EINVAL; - - if (kattr->test.data_in || kattr->test.data_size_in || kattr->test.data_out || - kattr->test.data_size_out) - return -EINVAL; - - if (!repeat) - repeat = 1; - - user_ctx = bpf_ctx_init(kattr, sizeof(*user_ctx)); - if (IS_ERR(user_ctx)) - return PTR_ERR(user_ctx); - - if (!user_ctx) - return -EINVAL; - - if (user_ctx->sk) - goto out; - - if (!range_is_zero(user_ctx, offsetofend(typeof(*user_ctx), local_port), sizeof(*user_ctx))) - goto out; - - if (user_ctx->local_port > U16_MAX || user_ctx->remote_port > U16_MAX) { - ret = -ERANGE; - goto out; - } - - ctx.family = (u16)user_ctx->family; - ctx.protocol = (u16)user_ctx->protocol; - ctx.dport = (u16)user_ctx->local_port; - ctx.sport = (__force __be16)user_ctx->remote_port; - - switch (ctx.family) { - case AF_INET: - ctx.v4.daddr = (__force __be32)user_ctx->local_ip4; - ctx.v4.saddr = (__force __be32)user_ctx->remote_ip4; - break; - -#if IS_ENABLED(CONFIG_IPV6) - case AF_INET6: - ctx.v6.daddr = (struct in6_addr *)user_ctx->local_ip6; - ctx.v6.saddr = (struct in6_addr *)user_ctx->remote_ip6; - break; -#endif - - default: - ret = -EAFNOSUPPORT; - goto out; - } - - progs = bpf_prog_array_alloc(1, GFP_KERNEL); - if (!progs) { - ret = -ENOMEM; - goto out; - } - - progs->items[0].prog = prog; - - bpf_test_timer_enter(&t); - do { - ctx.selected_sk = NULL; - retval = BPF_PROG_SK_LOOKUP_RUN_ARRAY(progs, ctx, BPF_PROG_RUN); - } while (bpf_test_timer_continue(&t, repeat, &ret, &duration)); - bpf_test_timer_leave(&t); - - if (ret < 0) - goto out; - - user_ctx->cookie = 0; - if (ctx.selected_sk) { - if (ctx.selected_sk->sk_reuseport && !ctx.no_reuseport) { - ret = -EOPNOTSUPP; - goto out; - } - - user_ctx->cookie = sock_gen_cookie(ctx.selected_sk); - } - - ret = bpf_test_finish(kattr, uattr, NULL, 0, retval, duration); - if (!ret) - ret = bpf_ctx_finish(kattr, uattr, user_ctx, sizeof(*user_ctx)); - -out: - bpf_prog_array_free(progs); - kfree(user_ctx); - return ret; -} diff --git a/net/core/filter.c b/net/core/filter.c index e3e28b12ccc51ccf3d18c8e2113e4ab1d18584cd..eca1c19ff6c5a530c856dd90f9ed9e98a07da4e8 100644 --- a/net/core/filter.c +++ b/net/core/filter.c @@ -10334,7 +10334,6 @@ static u32 sk_lookup_convert_ctx_access(enum bpf_access_type type, } const struct bpf_prog_ops sk_lookup_prog_ops = { - .test_run = bpf_prog_test_run_sk_lookup, }; const struct bpf_verifier_ops sk_lookup_verifier_ops = { diff --git a/tools/include/uapi/linux/bpf.h b/tools/include/uapi/linux/bpf.h index 7943e748916d4c71836acb51239553ded0bcfe1c..1dd4b1acbcb07f815f9e3ca1f344c4df35b3077c 100644 --- a/tools/include/uapi/linux/bpf.h +++ b/tools/include/uapi/linux/bpf.h @@ -5007,10 +5007,7 @@ struct bpf_pidns_info { /* User accessible data for SK_LOOKUP programs. Add new fields at the end. */ struct bpf_sk_lookup { - union { - __bpf_md_ptr(struct bpf_sock *, sk); /* Selected socket */ - __u64 cookie; /* Non-zero if socket was selected in PROG_TEST_RUN */ - }; + __bpf_md_ptr(struct bpf_sock *, sk); /* Selected socket */ __u32 family; /* Protocol family (AF_INET, AF_INET6) */ __u32 protocol; /* IP protocol (IPPROTO_TCP, IPPROTO_UDP) */ diff --git a/tools/testing/selftests/bpf/test_verifier.c b/tools/testing/selftests/bpf/test_verifier.c index 961c17b4681e5f22c38f195c536590aeba9b9078..0fc813235575de01020ae623c9d6b25ac06ba5dc 100644 --- a/tools/testing/selftests/bpf/test_verifier.c +++ b/tools/testing/selftests/bpf/test_verifier.c @@ -101,7 +101,7 @@ struct bpf_test { enum bpf_prog_type prog_type; uint8_t flags; void (*fill_helper)(struct bpf_test *self); - int runs; + uint8_t runs; #define bpf_testdata_struct_t \ struct { \ uint32_t retval, retval_unpriv; \ @@ -1064,7 +1064,7 @@ static void do_test_single(struct bpf_test *test, bool unpriv, run_errs = 0; run_successes = 0; - if (!alignment_prevented_execution && fd_prog >= 0 && test->runs >= 0) { + if (!alignment_prevented_execution && fd_prog >= 0) { uint32_t expected_val; int i; diff --git a/tools/testing/selftests/bpf/verifier/ctx_sk_lookup.c b/tools/testing/selftests/bpf/verifier/ctx_sk_lookup.c index fd3b62a084b9f2181886e97af1f7d1bc486c7813..2ad5f974451c3ffe265c940b7d850d2787539253 100644 --- a/tools/testing/selftests/bpf/verifier/ctx_sk_lookup.c +++ b/tools/testing/selftests/bpf/verifier/ctx_sk_lookup.c @@ -239,7 +239,6 @@ .result = ACCEPT, .prog_type = BPF_PROG_TYPE_SK_LOOKUP, .expected_attach_type = BPF_SK_LOOKUP, - .runs = -1, }, /* invalid 8-byte reads from a 4-byte fields in bpf_sk_lookup */ {