Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

selftests/bpf: Use the last page in test_snprintf_btf on s390

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: 076a95f5aff2 ("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

authored by

Ilya Leoshkevich and committed by
Daniel Borkmann
42a382a4 8811f4a9

+10 -3
+10 -3
tools/testing/selftests/bpf/progs/netif_receive_skb.c
··· 16 16 #define STRSIZE 2048 17 17 #define EXPECTED_STRSIZE 256 18 18 19 + #if defined(bpf_target_s390) 20 + /* NULL points to a readable struct lowcore on s390, so take the last page */ 21 + #define BADPTR ((void *)0xFFFFFFFFFFFFF000ULL) 22 + #else 23 + #define BADPTR 0 24 + #endif 25 + 19 26 #ifndef ARRAY_SIZE 20 27 #define ARRAY_SIZE(x) (sizeof(x) / sizeof((x)[0])) 21 28 #endif ··· 120 113 } 121 114 122 115 /* Check invalid ptr value */ 123 - p.ptr = 0; 116 + p.ptr = BADPTR; 124 117 __ret = bpf_snprintf_btf(str, STRSIZE, &p, sizeof(p), 0); 125 118 if (__ret >= 0) { 126 - bpf_printk("printing NULL should generate error, got (%d)", 127 - __ret); 119 + bpf_printk("printing %llx should generate error, got (%d)", 120 + (unsigned long long)BADPTR, __ret); 128 121 ret = -ERANGE; 129 122 } 130 123