Skip to content

Commit 6801cf7

Browse files
Hou TaoAlexei Starovoitov
authored andcommitted
selftests/bpf: Use -4095 as the bad address for bits iterator
As reported by Byeonguk, the bad_words test in verifier_bits_iter.c occasionally fails on s390 host. Quoting Ilya's explanation: s390 kernel runs in a completely separate address space, there is no user/kernel split at TASK_SIZE. The same address may be valid in both the kernel and the user address spaces, there is no way to tell by looking at it. The config option related to this property is ARCH_HAS_NON_OVERLAPPING_ADDRESS_SPACE. Also, unfortunately, 0 is a valid address in the s390 kernel address space. Fix the issue by using -4095 as the bad address for bits iterator, as suggested by Ilya. Verify that bpf_iter_bits_new() returns -EINVAL for NULL address and -EFAULT for bad address. Fixes: ebafc1e ("selftests/bpf: Add three test cases for bits_iter") Reported-by: Byeonguk Jeong <[email protected]> Closes: https://lore.kernel.org/bpf/ZycSXwjH4UTvx-Cn@ub22/ Signed-off-by: Hou Tao <[email protected]> Acked-by: Ilya Leoshkevich <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Alexei Starovoitov <[email protected]>
1 parent 2e1b3cc commit 6801cf7

File tree

1 file changed

+28
-4
lines changed

1 file changed

+28
-4
lines changed

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

Lines changed: 28 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -57,9 +57,15 @@ __description("null pointer")
5757
__success __retval(0)
5858
int null_pointer(void)
5959
{
60-
int nr = 0;
60+
struct bpf_iter_bits iter;
61+
int err, nr = 0;
6162
int *bit;
6263

64+
err = bpf_iter_bits_new(&iter, NULL, 1);
65+
bpf_iter_bits_destroy(&iter);
66+
if (err != -EINVAL)
67+
return 1;
68+
6369
bpf_for_each(bits, bit, NULL, 1)
6470
nr++;
6571
return nr;
@@ -194,15 +200,33 @@ __description("bad words")
194200
__success __retval(0)
195201
int bad_words(void)
196202
{
197-
void *bad_addr = (void *)(3UL << 30);
198-
int nr = 0;
203+
void *bad_addr = (void *)-4095;
204+
struct bpf_iter_bits iter;
205+
volatile int nr;
199206
int *bit;
207+
int err;
208+
209+
err = bpf_iter_bits_new(&iter, bad_addr, 1);
210+
bpf_iter_bits_destroy(&iter);
211+
if (err != -EFAULT)
212+
return 1;
200213

214+
nr = 0;
201215
bpf_for_each(bits, bit, bad_addr, 1)
202216
nr++;
217+
if (nr != 0)
218+
return 2;
203219

220+
err = bpf_iter_bits_new(&iter, bad_addr, 4);
221+
bpf_iter_bits_destroy(&iter);
222+
if (err != -EFAULT)
223+
return 3;
224+
225+
nr = 0;
204226
bpf_for_each(bits, bit, bad_addr, 4)
205227
nr++;
228+
if (nr != 0)
229+
return 4;
206230

207-
return nr;
231+
return 0;
208232
}

0 commit comments

Comments
 (0)