Revert "selftests/bpf: extend changes_pkt_data with cases w/o subprograms"
This reverts commit 04789af756a4a43e72986185f66f148e65b32fed which is commit 04789af756a4a43e72986185f66f148e65b32fed upstream. It breaks the Android kernel abi and can be brought back in the future in an abi-safe way if it is really needed. Bug: 161946584 Change-Id: I454badded1d44b44beded5b1382c581caf57fc03 Signed-off-by: Greg Kroah-Hartman <gregkh@google.com>
This commit is contained in:
@@ -10,14 +10,10 @@ static void print_verifier_log(const char *log)
|
|||||||
fprintf(stdout, "VERIFIER LOG:\n=============\n%s=============\n", log);
|
fprintf(stdout, "VERIFIER LOG:\n=============\n%s=============\n", log);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void test_aux(const char *main_prog_name,
|
static void test_aux(const char *main_prog_name, const char *freplace_prog_name, bool expect_load)
|
||||||
const char *to_be_replaced,
|
|
||||||
const char *replacement,
|
|
||||||
bool expect_load)
|
|
||||||
{
|
{
|
||||||
struct changes_pkt_data_freplace *freplace = NULL;
|
struct changes_pkt_data_freplace *freplace = NULL;
|
||||||
struct bpf_program *freplace_prog = NULL;
|
struct bpf_program *freplace_prog = NULL;
|
||||||
struct bpf_program *main_prog = NULL;
|
|
||||||
LIBBPF_OPTS(bpf_object_open_opts, opts);
|
LIBBPF_OPTS(bpf_object_open_opts, opts);
|
||||||
struct changes_pkt_data *main = NULL;
|
struct changes_pkt_data *main = NULL;
|
||||||
char log[16*1024];
|
char log[16*1024];
|
||||||
@@ -30,10 +26,6 @@ static void test_aux(const char *main_prog_name,
|
|||||||
main = changes_pkt_data__open_opts(&opts);
|
main = changes_pkt_data__open_opts(&opts);
|
||||||
if (!ASSERT_OK_PTR(main, "changes_pkt_data__open"))
|
if (!ASSERT_OK_PTR(main, "changes_pkt_data__open"))
|
||||||
goto out;
|
goto out;
|
||||||
main_prog = bpf_object__find_program_by_name(main->obj, main_prog_name);
|
|
||||||
if (!ASSERT_OK_PTR(main_prog, "main_prog"))
|
|
||||||
goto out;
|
|
||||||
bpf_program__set_autoload(main_prog, true);
|
|
||||||
err = changes_pkt_data__load(main);
|
err = changes_pkt_data__load(main);
|
||||||
print_verifier_log(log);
|
print_verifier_log(log);
|
||||||
if (!ASSERT_OK(err, "changes_pkt_data__load"))
|
if (!ASSERT_OK(err, "changes_pkt_data__load"))
|
||||||
@@ -41,14 +33,14 @@ static void test_aux(const char *main_prog_name,
|
|||||||
freplace = changes_pkt_data_freplace__open_opts(&opts);
|
freplace = changes_pkt_data_freplace__open_opts(&opts);
|
||||||
if (!ASSERT_OK_PTR(freplace, "changes_pkt_data_freplace__open"))
|
if (!ASSERT_OK_PTR(freplace, "changes_pkt_data_freplace__open"))
|
||||||
goto out;
|
goto out;
|
||||||
freplace_prog = bpf_object__find_program_by_name(freplace->obj, replacement);
|
freplace_prog = bpf_object__find_program_by_name(freplace->obj, freplace_prog_name);
|
||||||
if (!ASSERT_OK_PTR(freplace_prog, "freplace_prog"))
|
if (!ASSERT_OK_PTR(freplace_prog, "freplace_prog"))
|
||||||
goto out;
|
goto out;
|
||||||
bpf_program__set_autoload(freplace_prog, true);
|
bpf_program__set_autoload(freplace_prog, true);
|
||||||
bpf_program__set_autoattach(freplace_prog, true);
|
bpf_program__set_autoattach(freplace_prog, true);
|
||||||
bpf_program__set_attach_target(freplace_prog,
|
bpf_program__set_attach_target(freplace_prog,
|
||||||
bpf_program__fd(main_prog),
|
bpf_program__fd(main->progs.dummy),
|
||||||
to_be_replaced);
|
main_prog_name);
|
||||||
err = changes_pkt_data_freplace__load(freplace);
|
err = changes_pkt_data_freplace__load(freplace);
|
||||||
print_verifier_log(log);
|
print_verifier_log(log);
|
||||||
if (expect_load) {
|
if (expect_load) {
|
||||||
@@ -70,38 +62,15 @@ out:
|
|||||||
* that either do or do not. It is only ok to freplace subprograms
|
* that either do or do not. It is only ok to freplace subprograms
|
||||||
* that do not change packet data with those that do not as well.
|
* that do not change packet data with those that do not as well.
|
||||||
* The below tests check outcomes for each combination of such freplace.
|
* The below tests check outcomes for each combination of such freplace.
|
||||||
* Also test a case when main subprogram itself is replaced and is a single
|
|
||||||
* subprogram in a program.
|
|
||||||
*/
|
*/
|
||||||
void test_changes_pkt_data_freplace(void)
|
void test_changes_pkt_data_freplace(void)
|
||||||
{
|
{
|
||||||
struct {
|
if (test__start_subtest("changes_with_changes"))
|
||||||
const char *main;
|
test_aux("changes_pkt_data", "changes_pkt_data", true);
|
||||||
const char *to_be_replaced;
|
if (test__start_subtest("changes_with_doesnt_change"))
|
||||||
bool changes;
|
test_aux("changes_pkt_data", "does_not_change_pkt_data", true);
|
||||||
} mains[] = {
|
if (test__start_subtest("doesnt_change_with_changes"))
|
||||||
{ "main_with_subprogs", "changes_pkt_data", true },
|
test_aux("does_not_change_pkt_data", "changes_pkt_data", false);
|
||||||
{ "main_with_subprogs", "does_not_change_pkt_data", false },
|
if (test__start_subtest("doesnt_change_with_doesnt_change"))
|
||||||
{ "main_changes", "main_changes", true },
|
test_aux("does_not_change_pkt_data", "does_not_change_pkt_data", true);
|
||||||
{ "main_does_not_change", "main_does_not_change", false },
|
|
||||||
};
|
|
||||||
struct {
|
|
||||||
const char *func;
|
|
||||||
bool changes;
|
|
||||||
} replacements[] = {
|
|
||||||
{ "changes_pkt_data", true },
|
|
||||||
{ "does_not_change_pkt_data", false }
|
|
||||||
};
|
|
||||||
char buf[64];
|
|
||||||
|
|
||||||
for (int i = 0; i < ARRAY_SIZE(mains); ++i) {
|
|
||||||
for (int j = 0; j < ARRAY_SIZE(replacements); ++j) {
|
|
||||||
snprintf(buf, sizeof(buf), "%s_with_%s",
|
|
||||||
mains[i].to_be_replaced, replacements[j].func);
|
|
||||||
if (!test__start_subtest(buf))
|
|
||||||
continue;
|
|
||||||
test_aux(mains[i].main, mains[i].to_be_replaced, replacements[j].func,
|
|
||||||
mains[i].changes || !replacements[j].changes);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
@@ -4,35 +4,22 @@
|
|||||||
#include <bpf/bpf_helpers.h>
|
#include <bpf/bpf_helpers.h>
|
||||||
|
|
||||||
__noinline
|
__noinline
|
||||||
long changes_pkt_data(struct __sk_buff *sk)
|
long changes_pkt_data(struct __sk_buff *sk, __u32 len)
|
||||||
{
|
{
|
||||||
return bpf_skb_pull_data(sk, 0);
|
return bpf_skb_pull_data(sk, len);
|
||||||
}
|
}
|
||||||
|
|
||||||
__noinline __weak
|
__noinline __weak
|
||||||
long does_not_change_pkt_data(struct __sk_buff *sk)
|
long does_not_change_pkt_data(struct __sk_buff *sk, __u32 len)
|
||||||
{
|
{
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
SEC("?tc")
|
SEC("tc")
|
||||||
int main_with_subprogs(struct __sk_buff *sk)
|
int dummy(struct __sk_buff *sk)
|
||||||
{
|
|
||||||
changes_pkt_data(sk);
|
|
||||||
does_not_change_pkt_data(sk);
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
SEC("?tc")
|
|
||||||
int main_changes(struct __sk_buff *sk)
|
|
||||||
{
|
|
||||||
bpf_skb_pull_data(sk, 0);
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
SEC("?tc")
|
|
||||||
int main_does_not_change(struct __sk_buff *sk)
|
|
||||||
{
|
{
|
||||||
|
changes_pkt_data(sk, 0);
|
||||||
|
does_not_change_pkt_data(sk, 0);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -4,13 +4,13 @@
|
|||||||
#include <bpf/bpf_helpers.h>
|
#include <bpf/bpf_helpers.h>
|
||||||
|
|
||||||
SEC("?freplace")
|
SEC("?freplace")
|
||||||
long changes_pkt_data(struct __sk_buff *sk)
|
long changes_pkt_data(struct __sk_buff *sk, __u32 len)
|
||||||
{
|
{
|
||||||
return bpf_skb_pull_data(sk, 0);
|
return bpf_skb_pull_data(sk, len);
|
||||||
}
|
}
|
||||||
|
|
||||||
SEC("?freplace")
|
SEC("?freplace")
|
||||||
long does_not_change_pkt_data(struct __sk_buff *sk)
|
long does_not_change_pkt_data(struct __sk_buff *sk, __u32 len)
|
||||||
{
|
{
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user