Re: [PATCH v3 4/4] selftests/mm: virtual_address_range: Avoid reading from VM_IO mappings

From: Andrew Morton
Date: Mon Jan 13 2025 - 20:25:30 EST


On Mon, 13 Jan 2025 14:15:38 +0100 Thomas Weißschuh <thomas.weissschuh@xxxxxxxxxxxxx> wrote:

> 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 e93d2521b27f ("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.
>
> Reported-by: kernel test robot <oliver.sang@xxxxxxxxx>
> Closes: https://lore.kernel.org/oe-lkp/202412271148.2656e485-lkp@xxxxxxxxx
> Fixes: e93d2521b27f ("x86/vdso: Split virtual clock pages into dedicated mapping")
> Fixes: 010409649885 ("selftests/mm: confirm VA exhaustion without reliance on correctness of mmap()")
> Suggested-by: David Hildenbrand <david@xxxxxxxxxx>
> Link: https://lore.kernel.org/lkml/e97c2a5d-c815-4936-a767-ac42a3220a90@xxxxxxxxxx/
> Signed-off-by: Thomas Weißschuh <thomas.weissschuh@xxxxxxxxxxxxx>
>
> Revert "selftests/mm: virtual_address_range: Avoid reading VVAR mappings"
>
> This reverts commit 05cc5d292ac4238684b59922aecf59c932edefa0.

I'm assuming that the above two lines simply shouldn't be here?