diff options
| author | Andrii Nakryiko <[email protected]> | 2021-11-24 00:23:22 +0000 |
|---|---|---|
| committer | Daniel Borkmann <[email protected]> | 2021-11-25 23:15:03 +0000 |
| commit | e2e0d90c550a2588ebed7aa2753adaac0f633989 (patch) | |
| tree | 43764dd331642b2be4421090cfbb4db4d38247f2 /tools/testing/selftests/bpf/prog_tests/queue_stack_map.c | |
| parent | selftests/bpf: Prevent misaligned memory access in get_stack_raw_tp test (diff) | |
| download | kernel-e2e0d90c550a2588ebed7aa2753adaac0f633989.tar.gz kernel-e2e0d90c550a2588ebed7aa2753adaac0f633989.zip | |
selftests/bpf: Fix misaligned memory access in queue_stack_map test
Copy over iphdr into a local variable before accessing its fields.
Signed-off-by: Andrii Nakryiko <[email protected]>
Signed-off-by: Daniel Borkmann <[email protected]>
Link: https://lore.kernel.org/bpf/[email protected]
Diffstat (limited to 'tools/testing/selftests/bpf/prog_tests/queue_stack_map.c')
| -rw-r--r-- | tools/testing/selftests/bpf/prog_tests/queue_stack_map.c | 12 |
1 files changed, 7 insertions, 5 deletions
diff --git a/tools/testing/selftests/bpf/prog_tests/queue_stack_map.c b/tools/testing/selftests/bpf/prog_tests/queue_stack_map.c index 8ccba3ab70ee..b9822f914eeb 100644 --- a/tools/testing/selftests/bpf/prog_tests/queue_stack_map.c +++ b/tools/testing/selftests/bpf/prog_tests/queue_stack_map.c @@ -14,7 +14,7 @@ static void test_queue_stack_map_by_type(int type) int i, err, prog_fd, map_in_fd, map_out_fd; char file[32], buf[128]; struct bpf_object *obj; - struct iphdr *iph = (void *)buf + sizeof(struct ethhdr); + struct iphdr iph; /* Fill test values to be used */ for (i = 0; i < MAP_SIZE; i++) @@ -60,15 +60,17 @@ static void test_queue_stack_map_by_type(int type) err = bpf_prog_test_run(prog_fd, 1, &pkt_v4, sizeof(pkt_v4), buf, &size, &retval, &duration); - if (err || retval || size != sizeof(pkt_v4) || - iph->daddr != val) + if (err || retval || size != sizeof(pkt_v4)) + break; + memcpy(&iph, buf + sizeof(struct ethhdr), sizeof(iph)); + if (iph.daddr != val) break; } - CHECK(err || retval || size != sizeof(pkt_v4) || iph->daddr != val, + CHECK(err || retval || size != sizeof(pkt_v4) || iph.daddr != val, "bpf_map_pop_elem", "err %d errno %d retval %d size %d iph->daddr %u\n", - err, errno, retval, size, iph->daddr); + err, errno, retval, size, iph.daddr); /* Queue is empty, program should return TC_ACT_SHOT */ err = bpf_prog_test_run(prog_fd, 1, &pkt_v4, sizeof(pkt_v4), |
