Skip to content

Commit

Permalink
selftests/bpf: Use the last page in test_snprintf_btf on s390
Browse files Browse the repository at this point in the history
commit 42a382a upstream.

test_snprintf_btf fails on s390, because NULL points to a readable
struct lowcore there. Fix by using the last page instead.

Error message example:

    printing fffffffffffff000 should generate error, got (361)

Fixes: 076a95f ("selftests/bpf: Add bpf_snprintf_btf helper tests")
Signed-off-by: Ilya Leoshkevich <iii@linux.ibm.com>
Signed-off-by: Daniel Borkmann <daniel@iogearbox.net>
Acked-by: Heiko Carstens <hca@linux.ibm.com>
Acked-by: Yonghong Song <yhs@fb.com>
Link: https://lore.kernel.org/bpf/20210227051726.121256-1-iii@linux.ibm.com
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
  • Loading branch information
iii-i authored and gregkh committed Mar 17, 2021
1 parent 3e14c42 commit 2073eca
Showing 1 changed file with 10 additions and 3 deletions.
13 changes: 10 additions & 3 deletions tools/testing/selftests/bpf/progs/netif_receive_skb.c
Expand Up @@ -16,6 +16,13 @@ bool skip = false;
#define STRSIZE 2048
#define EXPECTED_STRSIZE 256

#if defined(bpf_target_s390)
/* NULL points to a readable struct lowcore on s390, so take the last page */
#define BADPTR ((void *)0xFFFFFFFFFFFFF000ULL)
#else
#define BADPTR 0
#endif

#ifndef ARRAY_SIZE
#define ARRAY_SIZE(x) (sizeof(x) / sizeof((x)[0]))
#endif
Expand Down Expand Up @@ -113,11 +120,11 @@ int BPF_PROG(trace_netif_receive_skb, struct sk_buff *skb)
}

/* Check invalid ptr value */
p.ptr = 0;
p.ptr = BADPTR;
__ret = bpf_snprintf_btf(str, STRSIZE, &p, sizeof(p), 0);
if (__ret >= 0) {
bpf_printk("printing NULL should generate error, got (%d)",
__ret);
bpf_printk("printing %llx should generate error, got (%d)",
(unsigned long long)BADPTR, __ret);
ret = -ERANGE;
}

Expand Down

0 comments on commit 2073eca

Please sign in to comment.