Skip to content

Commit f069b72

Browse files
jsitnickigregkh
authored andcommitted
selftests/bpf: Fix u8 narrow load checks for bpf_sk_lookup remote_port
commit 3c69611 upstream. In commit 9a69e2b ("bpf: Make remote_port field in struct bpf_sk_lookup 16-bit wide") ->remote_port field changed from __u32 to __be16. However, narrow load tests which exercise 1-byte sized loads from offsetof(struct bpf_sk_lookup, remote_port) were not adopted to reflect the change. As a result, on little-endian we continue testing loads from addresses: - (__u8 *)&ctx->remote_port + 3 - (__u8 *)&ctx->remote_port + 4 which map to the zero padding following the remote_port field, and don't break the tests because there is no observable change. While on big-endian, we observe breakage because tests expect to see zeros for values loaded from: - (__u8 *)&ctx->remote_port - 1 - (__u8 *)&ctx->remote_port - 2 Above addresses map to ->remote_ip6 field, which precedes ->remote_port, and are populated during the bpf_sk_lookup IPv6 tests. Unsurprisingly, on s390x we observe: #136/38 sk_lookup/narrow access to ctx v4:OK #136/39 sk_lookup/narrow access to ctx v6:FAIL Fix it by removing the checks for 1-byte loads from offsets outside of the ->remote_port field. Fixes: 9a69e2b ("bpf: Make remote_port field in struct bpf_sk_lookup 16-bit wide") Suggested-by: Ilya Leoshkevich <[email protected]> Signed-off-by: Jakub Sitnicki <[email protected]> Signed-off-by: Alexei Starovoitov <[email protected]> Acked-by: Martin KaFai Lau <[email protected]> Link: https://lore.kernel.org/bpf/[email protected] Signed-off-by: Greg Kroah-Hartman <[email protected]>
1 parent 349fc7d commit f069b72

File tree

1 file changed

+1
-2
lines changed

1 file changed

+1
-2
lines changed

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

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -404,8 +404,7 @@ int ctx_narrow_access(struct bpf_sk_lookup *ctx)
404404

405405
/* Narrow loads from remote_port field. Expect SRC_PORT. */
406406
if (LSB(ctx->remote_port, 0) != ((SRC_PORT >> 0) & 0xff) ||
407-
LSB(ctx->remote_port, 1) != ((SRC_PORT >> 8) & 0xff) ||
408-
LSB(ctx->remote_port, 2) != 0 || LSB(ctx->remote_port, 3) != 0)
407+
LSB(ctx->remote_port, 1) != ((SRC_PORT >> 8) & 0xff))
409408
return SK_DROP;
410409
if (LSW(ctx->remote_port, 0) != SRC_PORT)
411410
return SK_DROP;

0 commit comments

Comments
 (0)