mirror of
https://git.kernel.org/pub/scm/linux/kernel/git/stable/linux.git
synced 2024-12-29 09:16:33 +00:00
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: ebafc1e535
("selftests/bpf: Add three test cases for bits_iter")
Reported-by: Byeonguk Jeong <jungbu2855@gmail.com>
Closes: https://lore.kernel.org/bpf/ZycSXwjH4UTvx-Cn@ub22/
Signed-off-by: Hou Tao <houtao1@huawei.com>
Acked-by: Ilya Leoshkevich <iii@linux.ibm.com>
Link: https://lore.kernel.org/r/20241105043057.3371482-1-houtao@huaweicloud.com
Signed-off-by: Alexei Starovoitov <ast@kernel.org>
This commit is contained in:
parent
2e1b3cc9d7
commit
6801cf7890
@ -57,9 +57,15 @@ __description("null pointer")
|
|||||||
__success __retval(0)
|
__success __retval(0)
|
||||||
int null_pointer(void)
|
int null_pointer(void)
|
||||||
{
|
{
|
||||||
int nr = 0;
|
struct bpf_iter_bits iter;
|
||||||
|
int err, nr = 0;
|
||||||
int *bit;
|
int *bit;
|
||||||
|
|
||||||
|
err = bpf_iter_bits_new(&iter, NULL, 1);
|
||||||
|
bpf_iter_bits_destroy(&iter);
|
||||||
|
if (err != -EINVAL)
|
||||||
|
return 1;
|
||||||
|
|
||||||
bpf_for_each(bits, bit, NULL, 1)
|
bpf_for_each(bits, bit, NULL, 1)
|
||||||
nr++;
|
nr++;
|
||||||
return nr;
|
return nr;
|
||||||
@ -194,15 +200,33 @@ __description("bad words")
|
|||||||
__success __retval(0)
|
__success __retval(0)
|
||||||
int bad_words(void)
|
int bad_words(void)
|
||||||
{
|
{
|
||||||
void *bad_addr = (void *)(3UL << 30);
|
void *bad_addr = (void *)-4095;
|
||||||
int nr = 0;
|
struct bpf_iter_bits iter;
|
||||||
|
volatile int nr;
|
||||||
int *bit;
|
int *bit;
|
||||||
|
int err;
|
||||||
|
|
||||||
|
err = bpf_iter_bits_new(&iter, bad_addr, 1);
|
||||||
|
bpf_iter_bits_destroy(&iter);
|
||||||
|
if (err != -EFAULT)
|
||||||
|
return 1;
|
||||||
|
|
||||||
|
nr = 0;
|
||||||
bpf_for_each(bits, bit, bad_addr, 1)
|
bpf_for_each(bits, bit, bad_addr, 1)
|
||||||
nr++;
|
nr++;
|
||||||
|
if (nr != 0)
|
||||||
|
return 2;
|
||||||
|
|
||||||
|
err = bpf_iter_bits_new(&iter, bad_addr, 4);
|
||||||
|
bpf_iter_bits_destroy(&iter);
|
||||||
|
if (err != -EFAULT)
|
||||||
|
return 3;
|
||||||
|
|
||||||
|
nr = 0;
|
||||||
bpf_for_each(bits, bit, bad_addr, 4)
|
bpf_for_each(bits, bit, bad_addr, 4)
|
||||||
nr++;
|
nr++;
|
||||||
|
if (nr != 0)
|
||||||
|
return 4;
|
||||||
|
|
||||||
return nr;
|
return 0;
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user