From patchwork Tue Jan 14 16:06:48 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Thomas_Wei=C3=9Fschuh?= X-Patchwork-Id: 13938949 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id 7D66EC02183 for ; Tue, 14 Jan 2025 16:07:23 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 6B2D3280004; Tue, 14 Jan 2025 11:07:15 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 63CB1280001; Tue, 14 Jan 2025 11:07:15 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 4B6C2280004; Tue, 14 Jan 2025 11:07:15 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0011.hostedemail.com [216.40.44.11]) by kanga.kvack.org (Postfix) with ESMTP id 2C07E280001 for ; Tue, 14 Jan 2025 11:07:15 -0500 (EST) Received: from smtpin18.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay06.hostedemail.com (Postfix) with ESMTP id DE39EAFA60 for ; Tue, 14 Jan 2025 16:07:14 +0000 (UTC) X-FDA: 83006536788.18.CA72D90 Received: from galois.linutronix.de (Galois.linutronix.de [193.142.43.55]) by imf22.hostedemail.com (Postfix) with ESMTP id F22E7C0012 for ; Tue, 14 Jan 2025 16:07:12 +0000 (UTC) Authentication-Results: imf22.hostedemail.com; dkim=pass header.d=linutronix.de header.s=2020 header.b=cnFtEm18; dkim=pass header.d=linutronix.de header.s=2020e header.b=KnaL0Bqp; dmarc=pass (policy=none) header.from=linutronix.de; spf=pass (imf22.hostedemail.com: domain of t-8ch@linutronix.de designates 193.142.43.55 as permitted sender) smtp.mailfrom=t-8ch@linutronix.de ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1736870833; a=rsa-sha256; cv=none; b=s41cQTFo28E01XELdAVvq+KstX7TgfAYtqWc0rJgnPcte1u1OfDsoxYOZJI7O9PhbD2QB6 tOVrwYlRDKYqL4swlcsMt1KsyVkcVjMAGgbpNE7+cRze0SdAh03vbiloYimlYRdCIxl0eU kT0RGoxQEH6Mr9U8O+EBxvqF3HfeM7s= ARC-Authentication-Results: i=1; imf22.hostedemail.com; dkim=pass header.d=linutronix.de header.s=2020 header.b=cnFtEm18; dkim=pass header.d=linutronix.de header.s=2020e header.b=KnaL0Bqp; dmarc=pass (policy=none) header.from=linutronix.de; spf=pass (imf22.hostedemail.com: domain of t-8ch@linutronix.de designates 193.142.43.55 as permitted sender) smtp.mailfrom=t-8ch@linutronix.de ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1736870833; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=8RpmujbkErM0AyBS/jsicWpVLkLAFbMaYP9rwEqJEd4=; b=RN2QLwQHqsKYNE1ZxiISrQwtJ/dVBOPy6yk+lbo3CD/CkxkwI4ipdr5BsYmOQbGSIJ48kz oun1Y/ZdAT28pM3L1z22EnuCwjpfrtaZTQEl4oUwd9DvflfHgBhPWWiTMvDKQtLJ45vL+S lUjF447aX0oPpT57B/xiWeEyhDlUoqM= From: =?utf-8?q?Thomas_Wei=C3=9Fschuh?= DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1736870831; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=8RpmujbkErM0AyBS/jsicWpVLkLAFbMaYP9rwEqJEd4=; b=cnFtEm18MbrSTZZNuEaTkbh1BCcJt6ODsBTtckfbbeBTuMwWvfgoDH3wreQrDdYd1I0hw8 97ExHGFWJLfiU6XcyeJtpAwoC0Qz1BIovPU4xCrc8zfK7umEq2FCW1b9xv3S92UJChPxeI tKtUWD1C7mvfBy86MAPmtENlpMqANSi8EfbAps+ZDGu9SEPH548AoatKNvljt7zOw90zTk oTEyluL2uULENRWrH4iVCaTTYUj05nGT4qftjRCQp0nC+/v0mveb4TPDoLF3HpAt3N8xVE QXHaHQqJ10QuHj+hBWYkwwD9Srq37GiphfOKHOOYwuSSW0V8RyGLEC17HbnREA== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1736870831; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=8RpmujbkErM0AyBS/jsicWpVLkLAFbMaYP9rwEqJEd4=; b=KnaL0Bqp9VgUi6gfGyMii2Jd+8VSJEQIwpet4OdI32Z/16BYWMCnsNmSsVtWJTtQZh+xOC Zg4dYFNssdyZ38Ag== Date: Tue, 14 Jan 2025 17:06:48 +0100 Subject: [PATCH v4 4/4] selftests/mm: virtual_address_range: Avoid reading from VM_IO mappings MIME-Version: 1.0 Message-Id: <20250114-virtual_address_range-tests-v4-4-6fd7269934a5@linutronix.de> References: <20250114-virtual_address_range-tests-v4-0-6fd7269934a5@linutronix.de> In-Reply-To: <20250114-virtual_address_range-tests-v4-0-6fd7269934a5@linutronix.de> To: Andrew Morton , Shuah Khan , Dev Jain , Thomas Gleixner , David Hildenbrand , Anshuman Khandual Cc: linux-mm@kvack.org, linux-kselftest@vger.kernel.org, linux-kernel@vger.kernel.org, =?utf-8?q?Thomas_Wei=C3=9Fschuh?= , kernel test robot X-Developer-Signature: v=1; a=ed25519-sha256; t=1736870827; l=4152; i=thomas.weissschuh@linutronix.de; s=20240209; h=from:subject:message-id; bh=dH3RzX1kWHmc070i/rqPW6ADGmajD2eJb8ZOtqkz4DI=; b=xQ+14+XJAZIgmtLRSLuvQ0RJRXCT1ZR5pG5JrfZEm4tjhZLiKT2rLZ0+9AZVNI24R/g7D4PPN oQPBYszSdrkDyMlNo2pPeLn+tt9sG8qIS0glZuGpfXKUlxWf9D0u92u X-Developer-Key: i=thomas.weissschuh@linutronix.de; a=ed25519; pk=pfvxvpFUDJV2h2nY0FidLUml22uGLSjByFbM6aqQQws= X-Rspam-User: X-Rspamd-Server: rspam03 X-Rspamd-Queue-Id: F22E7C0012 X-Stat-Signature: rdxkspgamzgwzjs4awxup1ydquz4fiaq X-HE-Tag: 1736870832-804041 X-HE-Meta: U2FsdGVkX1/1Q+y7G+5nBwLXfCBg0ylbA6pjyVYqDdsZUZvhWkn0OxsH5U/HGhaK/Bo07xeQzGapYewHopoDvSdy4p5zWJOLgKPUchyf7t6L0vfXTSTWfWkMlCKjEoTQZe2iGICEE6kEVnoLOOPN71IB6oAyiskCm5Q8dFbR2aQJNDmUR7iC2slKVkYR0cghURCOWihvKfT+UwQsfl9tuvhQ7qxYqJwGyt9Vgs21PMVCT2wuAd/uUg95Wp8DtHEPAyEzcg2ZPh5Goybrb9X1oosdTun2OUwatqpN5cdY3oNob1HFeUzqFRKsQG2dD7l7DNdDBqG5EAqED7tUioAozxxwu6fPyLcvy0fPjOTbDed/mUbzY2+++StW4zuEzpWHx8IGZRwbt11lp0FnVGFMKSz7X6dH39ZILOI/bUXDoSOc8mPpxuHBOU9zcgAI1hNOTxHz+7njmk+jM2sdhFpIcNayF1FiQ1dt8DiVvEueyHVtIEaVXqxjVIfwOSf54Fe1cdLLzlvVf54k05ff2H3nbxIy/82DvqBhdHFBE//1k8xB7GqoR2nOgoD0iMMp2QOHXMsEVf8QBWNhFwQEeJ9OStjvNUGWh45enHNHFE88vK85j0j4mpd2y97etowkxuXaREP10FJ80FQ4nnsCKFVUlf1iCITstof+CEEX37N3gBPTj9y/aa4hfQmMEZAb+p6RheGth9znI98AjF3sq8RvkV02GC/MvR9Q7qTkiqnOci78j3e8afmX0H685Jgc10YHVC/kD202bUOUOQcf6kzmJR+qiiA3xwLMgOJ8iby09Ls8JVsm5kCgTc7mmtMXdmtjpetNybQLeaAUHk0HwUmgzRim5K94Xh5gphKuUfQXBsNswM3ZmCUhNVrkRsxGwWTVFh8019dgG7iQQIH5qqxP5+Eye4dlHvCFLDH49UP4fv1VACPMMqgDscx1c71OL2qY0QvNZDw+M3/ccek7RSC ri/kM86O LgJabdVNmg460ZzkLGhpdh9zHdcpy6bVjhW16GbsfhWSDmbEYKBQnHTpUL2Skqp3lIWYRpJpaVgQVv+upR/vUp2ORJ1V+6ApGG7DIXVhDc49W9KMwuecNtJWOmz644H5nVXzZ0b2jviVDTRPA9hiSffu0Ae1hVv6WCtEJFW4/ZE0EnNh2DvwUTQn1gsFXzz5Vh4DA2Tkw7wGFhBbiv/K8phipJsyQy+WhX+MXzqMF5h8PKAYfSDL60svr2xE9t3uDEdVkwb6k87U8+qtr9fe47NawZ0sKcPdRHbhsC6sHosym+krZYAVCM1hfonB+/X+5sLtBw3+WCsEWHnwUlZ4oYUmJp/2kLxtp1LagTZWFwWUgbmiH3a8nFVirqg2nSLCDv1f0XfZcQ/HUWXoI0EbeUf8CsB5nYeiXueQMludU9cnF3HTM39R794nOrh6pUxNmoqzf04y+2KTUccKK6hW1fsjEcZrb35kuZHlCmzGla92I1Rbq2Irv8bJDwrQ/UvbQNTpQ2+3DkJ5yTMU= X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: List-Subscribe: List-Unsubscribe: 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 Closes: https://lore.kernel.org/oe-lkp/202412271148.2656e485-lkp@intel.com 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 Link: https://lore.kernel.org/lkml/e97c2a5d-c815-4936-a767-ac42a3220a90@redhat.com/ Signed-off-by: Thomas Weißschuh Acked-by: David Hildenbrand --- I left out the comment about the requirement for check_vmflag_io() to be called with the start address of a mapping. It's the same for the check_huge_*() functions and there it's not documented either. Also there is only a single, correct user and any misuse will instantly result in visible breakage. --- tools/testing/selftests/mm/virtual_address_range.c | 4 ++++ tools/testing/selftests/mm/vm_util.c | 24 ++++++++++++++++++++++ tools/testing/selftests/mm/vm_util.h | 1 + 3 files changed, 29 insertions(+) diff --git a/tools/testing/selftests/mm/virtual_address_range.c b/tools/testing/selftests/mm/virtual_address_range.c index 386e4e46fa65b98af78dee4bb30144eb2b51f528..b380e102b22f0a44654ab046f257e8c35e8d90e9 100644 --- a/tools/testing/selftests/mm/virtual_address_range.c +++ b/tools/testing/selftests/mm/virtual_address_range.c @@ -15,6 +15,7 @@ #include #include +#include "vm_util.h" #include "../kselftest.h" /* @@ -159,6 +160,9 @@ static int validate_complete_va_space(void) if (prot[0] != 'r') continue; + if (check_vmflag_io((void *)start_addr)) + continue; + /* * Confirm whether MAP_CHUNK_SIZE chunk can be found or not. * If write succeeds, no need to check MAP_CHUNK_SIZE - 1 diff --git a/tools/testing/selftests/mm/vm_util.c b/tools/testing/selftests/mm/vm_util.c index a450ab353f8e710a6bfce347bc3a7309920c70f5..8bd2c5e59bc73bdfa617d4b11b448da84e2a3daf 100644 --- a/tools/testing/selftests/mm/vm_util.c +++ b/tools/testing/selftests/mm/vm_util.c @@ -400,3 +400,27 @@ unsigned long get_free_hugepages(void) fclose(f); return fhp; } + +bool check_vmflag_io(void *addr) +{ + char buffer[MAX_LINE_LENGTH]; + const char *flags; + size_t flaglen; + + flags = __get_smap_entry(addr, "VmFlags:", buffer, sizeof(buffer)); + if (!flags) + ksft_exit_fail_msg("%s: No VmFlags for %p\n", __func__, addr); + + while (true) { + flags += strspn(flags, " "); + + flaglen = strcspn(flags, " "); + if (!flaglen) + return false; + + if (flaglen == strlen("io") && !memcmp(flags, "io", flaglen)) + return true; + + flags += flaglen; + } +} diff --git a/tools/testing/selftests/mm/vm_util.h b/tools/testing/selftests/mm/vm_util.h index 2eaed82099255e09ffd38ad9714994397f304685..b60ac68a9dc8893895f49946b258260f7a82218a 100644 --- a/tools/testing/selftests/mm/vm_util.h +++ b/tools/testing/selftests/mm/vm_util.h @@ -53,6 +53,7 @@ int uffd_unregister(int uffd, void *addr, uint64_t len); int uffd_register_with_ioctls(int uffd, void *addr, uint64_t len, bool miss, bool wp, bool minor, uint64_t *ioctls); unsigned long get_free_hugepages(void); +bool check_vmflag_io(void *addr); /* * On ppc64 this will only work with radix 2M hugepage size