Skip to content

Commit 3bd6137

Browse files
t-8chakpm00
authored andcommitted
selftests/mm: virtual_address_range: avoid reading from VM_IO mappings
The virtual_address_range selftest reads from the start of each mapping listed in /proc/self/maps. However not all mappings are valid to be arbitrarily accessed. For example the vvar data used for virtual clocks on x86 [vvar_vclock] can only be accessed if 1) the kernel configuration enables virtual clocks and 2) the hypervisor provided the data for it. Only the VDSO itself has the necessary information to know this. Since commit e93d252 ("x86/vdso: Split virtual clock pages into dedicated mapping") the virtual clock data was split out into its own mapping, leading to EFAULT from read() during the validation. Check for the VM_IO flag as a proxy. It is present for the VVAR mappings and MMIO ranges can be dangerous to access arbitrarily. Link: https://lkml.kernel.org/r/20250114-virtual_address_range-tests-v4-4-6fd7269934a5@linutronix.de Reported-by: kernel test robot <oliver.sang@intel.com> Closes: https://lore.kernel.org/oe-lkp/202412271148.2656e485-lkp@intel.com Fixes: e93d252 ("x86/vdso: Split virtual clock pages into dedicated mapping") Fixes: 0104096 ("selftests/mm: confirm VA exhaustion without reliance on correctness of mmap()") Signed-off-by: Thomas Weißschuh <thomas.weissschuh@linutronix.de> Suggested-by: David Hildenbrand <david@redhat.com> Link: https://lore.kernel.org/lkml/e97c2a5d-c815-4936-a767-ac42a3220a90@redhat.com/ Acked-by: David Hildenbrand <david@redhat.com> Cc: Anshuman Khandual <khandual@linux.vnet.ibm.com> Cc: Dev Jain <dev.jain@arm.com> Cc: Shuah Khan (Samsung OSG) <shuah@kernel.org> Cc: Thomas Gleixner <tglx@linutronix.de> Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
1 parent 3c479b5 commit 3bd6137

File tree

3 files changed

+29
-0
lines changed

3 files changed

+29
-0
lines changed

tools/testing/selftests/mm/virtual_address_range.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
#include <sys/time.h>
1616
#include <fcntl.h>
1717

18+
#include "vm_util.h"
1819
#include "../kselftest.h"
1920

2021
/*
@@ -159,6 +160,9 @@ static int validate_complete_va_space(void)
159160
if (prot[0] != 'r')
160161
continue;
161162

163+
if (check_vmflag_io((void *)start_addr))
164+
continue;
165+
162166
/*
163167
* Confirm whether MAP_CHUNK_SIZE chunk can be found or not.
164168
* If write succeeds, no need to check MAP_CHUNK_SIZE - 1

tools/testing/selftests/mm/vm_util.c

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -400,3 +400,27 @@ unsigned long get_free_hugepages(void)
400400
fclose(f);
401401
return fhp;
402402
}
403+
404+
bool check_vmflag_io(void *addr)
405+
{
406+
char buffer[MAX_LINE_LENGTH];
407+
const char *flags;
408+
size_t flaglen;
409+
410+
flags = __get_smap_entry(addr, "VmFlags:", buffer, sizeof(buffer));
411+
if (!flags)
412+
ksft_exit_fail_msg("%s: No VmFlags for %p\n", __func__, addr);
413+
414+
while (true) {
415+
flags += strspn(flags, " ");
416+
417+
flaglen = strcspn(flags, " ");
418+
if (!flaglen)
419+
return false;
420+
421+
if (flaglen == strlen("io") && !memcmp(flags, "io", flaglen))
422+
return true;
423+
424+
flags += flaglen;
425+
}
426+
}

tools/testing/selftests/mm/vm_util.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,7 @@ int uffd_unregister(int uffd, void *addr, uint64_t len);
5353
int uffd_register_with_ioctls(int uffd, void *addr, uint64_t len,
5454
bool miss, bool wp, bool minor, uint64_t *ioctls);
5555
unsigned long get_free_hugepages(void);
56+
bool check_vmflag_io(void *addr);
5657

5758
/*
5859
* On ppc64 this will only work with radix 2M hugepage size

0 commit comments

Comments
 (0)