selftests/bpf: Use the last page in test_snprintf_btf on s390
Subsystems (3)
PATCH v3 1/1 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 0000000000000000 should generate error, got (361)
---
v1: https://lore.kernel.org/bpf/[email protected]/
v1 -> v2: Yonghong suggested to add the pointer value to the error
message.
I've noticed that I've been passing BADPTR as flags, therefore the fix worked only by accident. Put it into p.ptr where it belongs.
v2: https://lore.kernel.org/bpf/[email protected]/
v2 -> v3: Heiko mentioned that using _REGION1_SIZE is not future-proof.
We had a private discussion and came to the conclusion that the the last page is good enough.
.../testing/selftests/bpf/progs/netif_receive_skb.c | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-)
tools/testing/selftests/bpf/progs/netif_receive_skb.c +10 -3
@@ -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
@@ -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 %p should generate error, got (%d)" , +BADPTR , __ret); ret = -ERANGE ; }
Signature · 1 line
2.29.2
Quoted 17 lines · Ilya Leoshkevich
test_snprintf_btffails on s390, because NULL points to a readable struct lowcore there. Fix by using the last page instead.Error message example:
printing 0000000000000000 should generate error, got (361)Signed-off-by Ilya Leoshkevich <[email protected]>---
v1: https://lore.kernel.org/bpf/[email protected]/
v1 -> v2: Yonghong suggested to add the pointer value to the error
message.
I've noticed that I've been passing BADPTR as flags, therefore the fix worked only by accident. Put it into p.ptr where it belongs.
Quoted 4 lines
v2: https://lore.kernel.org/bpf/[email protected]/
v2 -> v3: Heiko mentioned that using_REGION1_SIZEis not future-proof.
We had a private discussion and came to the conclusion that the the last page is good enough.
Heiko, could you ack the patch if it is okay? Thanks!
Quoted 24 lines
.../testing/selftests/bpf/progs/netif_receive_skb.c | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-)tools/testing/selftests/bpf/progs/netif_receive_skb.c +7
-0@@ -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 @@ -113,11 +120,11 @@ int BPF_PROG(trace_netif_receive_skb, struct sk_buff *skb) }
tools/testing/selftests/bpf/progs/netif_receive_skb.c int BPF_PROG(trace_netif_receive_skb, struct sk_buff *skb) · line 127
Quoted 10 lines
tools/testing/selftests/bpf/progs/netif_receive_skb.c +3
-3/* 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 %p should generate error, got (%d)" , +BADPTR , __ret);
From https://www.kernel.org/doc/Documentation/printk-formats.txt:
Pointers printed without a specifier extension (i.e unadorned %p) are hashed to give a unique identifier without leaking kernel addresses to user space. On 64 bit machines the first 32 bits are zeroed. If you _really_ want the address see %px below.
I think it is okay to use %px here.
Quoted 4 lines
tools/testing/selftests/bpf/progs/netif_receive_skb.c +0
-0ret = -ERANGE ; }
Quoted 76 lines · Yonghong Song
Quoted 20 lines · Ilya Leoshkevich
test_snprintf_btffails on s390, because NULL points to a readable struct lowcore there. Fix by using the last page instead.Error message example:
printing 0000000000000000 should generate error, got (361)
Signed-off-by Ilya Leoshkevich <[email protected]>---
v1:
https://lore.kernel.org/bpf/[email protected]/
v1 -> v2: Yonghong suggested to add the pointer value to the error message.
I've noticed that I've been passing BADPTR as flags, therefore
the fix worked only by accident. Put it into p.ptr where it
belongs.Quoted 7 lines
v2:
https://lore.kernel.org/bpf/[email protected]/
v2 -> v3: Heiko mentioned that using_REGION1_SIZEis not future- proof.
We had a private discussion and came to the conclusion that
the the last page is good enough.Heiko, could you ack the patch if it is okay? Thanks!
Quoted 32 lines
.../testing/selftests/bpf/progs/netif_receive_skb.c| 13
++++++++++---1 file changed, 10 insertions(+), 3 deletions(-)tools/testing/selftests/bpf/progs/netif_receive_skb.c +0
-0@@ -16,6 +16,13 @@ bool skip = false; #define STRSIZE 2048 #define EXPECTED_STRSIZE 256tools/testing/selftests/bpf/progs/netif_receive_skb.c +2
-0+#if defined(bpf_target_s390) +/* NULL points to a readable struct lowcore on s390, so take the last page */
tools/testing/selftests/bpf/progs/netif_receive_skb.c +5
-0+#define BADPTR ((void *)0xFFFFFFFFFFFFF000ULL) +#else +#define BADPTR 0 +#endif +#ifndef
ARRAY_SIZE
#define ARRAY_SIZE(x) (sizeof(x) / sizeof((x)[0])) #endiftools/testing/selftests/bpf/progs/netif_receive_skb.c +0
-0@@ -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;Quoted 8 lines
__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 %p should generate error, got (%d)",
+ BADPTR,__ret);From https://www.kernel.org/doc/Documentation/printk-formats.txt:
Quoted 8 lines
Pointers printed without a specifier extension (i.e unadorned %p) are hashed to give a unique identifier without leaking kernel addresses to user
space. On 64 bit machines the first 32 bits are zeroed. If you _really_
want the address see %px below.I think it is okay to use %px here.
I don't think bpf_trace_printk supports it, but I'll use %llx instead.
[...]
Heiko Carstens
Acked-byQuoted 7 lines · Yonghong Song
Quoted 7 lines
test_snprintf_btffails on s390, because NULL points to a readable struct lowcore there. Fix by using the last page instead.Error message example:
printing 0000000000000000 should generate error, got (361)
Quoted 7 lines
Quoted 5 lines
Signed-off-by Ilya Leoshkevich <[email protected]>---
v2 -> v3: Heiko mentioned that using_REGION1_SIZEis not future-proof.
We had a private discussion and came to the conclusion that the the last page is good enough.Heiko, could you ack the patch if it is okay? Thanks!
Yes, sure.