From nobody Sat Oct 4 22:34:43 2025 Received: from galois.linutronix.de (Galois.linutronix.de [193.142.43.55]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id CA57820C47C for ; Mon, 1 Sep 2025 12:34:37 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=193.142.43.55 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1756730079; cv=none; b=Ji1plFQS8oSt9zJ7aOpMbvTQ6cZdcnxP83hRFWgDX+ehtaonTH8aZnnlsvwxy337pa6RWpraS9IodesEOWcpp9FmVhSaLhX+j/lEA4f8AE6zr8bvjjY3ZwfEVQPaukZu9Tlylf9NueuYLzwGZKVgJP5M8SG2PLAzoDQupwUkg5U= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1756730079; c=relaxed/simple; bh=AktEwtLHe7dXjD3OqHqS0kggLfllnUbsXxMSxqdxwFQ=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=SJdRzw91r6j/pGEFhZ4O8GBENPxmgdYqZYEX67ymwAFIWR1yBPSTxs0Qg7TeplDcBB/Ugd2sQyb9xnyrDECcK/pOaWgTlX0nZKKY7DRMAx8wajPIELZeFe4Koy5xBDGy4xzfMviLYdnvAiAsG5Bl1zswESSGAHK+E2Ey6AQc0ps= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linutronix.de; spf=pass smtp.mailfrom=linutronix.de; dkim=pass (2048-bit key) header.d=linutronix.de header.i=@linutronix.de header.b=v3e2qEXa; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b=aqkk8AIM; arc=none smtp.client-ip=193.142.43.55 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linutronix.de Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linutronix.de Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=linutronix.de header.i=@linutronix.de header.b="v3e2qEXa"; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b="aqkk8AIM" From: =?utf-8?q?Thomas_Wei=C3=9Fschuh?= DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1756730075; 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=664gQerhLd5Hk2QfN13Hl9ZRcHstMZHAtXpxYIYNCU8=; b=v3e2qEXa1lHGp1FVvJ7lzZSRfX40e9VZ19xmBdk8pNuDcAWMX4JzQI1Tx0xhTahI3fyw6X IJ3Vrw6uPojNB03b0tqf0ibnwhOEkQ/Ydn2j9z/Xi0VXvlFo0yUSPiPvsq9jm1O7tjZLDD 7Kfhc4ivmywuPDqgJu/VEQa5UkRk6eCwztwBDsMb07nAUjDx/CuspcgwhPC11drtpjcQEB 6XrXWNzJbFSsgR0kIyLbNyQoh35VoBVDZDGNWO99QqBY98hBd/1TEDH62bDqoznqWfCGJZ 1NmPVMlinsN3fRYP9Dxc7K6BO52gx/MShKDb2cQeEGPBlOqOTf6SEvZ/ph9PQQ== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1756730075; 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=664gQerhLd5Hk2QfN13Hl9ZRcHstMZHAtXpxYIYNCU8=; b=aqkk8AIMjnLgGD8S2enri1xYtoNWzdmXV8J0RCEcvL+fJAyk3bBW2KXvhgC83n9o894jz6 3wjBuBX/SnYxUWCQ== Date: Mon, 01 Sep 2025 14:34:22 +0200 Subject: [PATCH v2 1/3] vdso/datastore: Explicitly prevent remote access to timens vvar page Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Message-Id: <20250901-vdso-mlockall-v2-1-68f5a6f03345@linutronix.de> References: <20250901-vdso-mlockall-v2-0-68f5a6f03345@linutronix.de> In-Reply-To: <20250901-vdso-mlockall-v2-0-68f5a6f03345@linutronix.de> To: Anna-Maria Behnsen , Frederic Weisbecker , Thomas Gleixner , Andy Lutomirski , Vincenzo Frascino Cc: Nam Cao , linux-kernel@vger.kernel.org, =?utf-8?q?Thomas_Wei=C3=9Fschuh?= X-Developer-Signature: v=1; a=ed25519-sha256; t=1756730069; l=2367; i=thomas.weissschuh@linutronix.de; s=20240209; h=from:subject:message-id; bh=AktEwtLHe7dXjD3OqHqS0kggLfllnUbsXxMSxqdxwFQ=; b=x2y56gEUObDsxYu00BLgFnfxcvV59AXLBIQ6P/kQPvBvH0fGjlWlsO6BWho/GgW6usS0QiXQV ouU8IVldediB1K75JFmpnd/7lcoOW1//gWLCHIVaPZ4IHfxRCLc5QrP X-Developer-Key: i=thomas.weissschuh@linutronix.de; a=ed25519; pk=pfvxvpFUDJV2h2nY0FidLUml22uGLSjByFbM6aqQQws= The fault handler for the timens page does not have access to the target task and therefore can not be invoked remotely. Currently the handler relies on the fact that the vvar mapping is marked as VM_IO and VM_PFNMAP for which the mm core always prevents remote access. However the VM_IO and VM_PFNMAP flags are going to be removed. Add an explicit check to prevent remote access to the mapping. Move the call to find_timens_vvar_page() after the check to avoid hitting the WARN() in that function. Signed-off-by: Thomas Wei=C3=9Fschuh --- kernel/time/namespace.c | 7 ++----- lib/vdso/datastore.c | 7 ++++++- 2 files changed, 8 insertions(+), 6 deletions(-) diff --git a/kernel/time/namespace.c b/kernel/time/namespace.c index 667452768ed3b50e48e3cfb70f8ef68e4bed9e0b..e225547021b73230e3c820cd916= 35e0483821c49 100644 --- a/kernel/time/namespace.c +++ b/kernel/time/namespace.c @@ -198,11 +198,8 @@ struct page *find_timens_vvar_page(struct vm_area_stru= ct *vma) return current->nsproxy->time_ns->vvar_page; =20 /* - * VM_PFNMAP | VM_IO protect .fault() handler from being called - * through interfaces like /proc/$pid/mem or - * process_vm_{readv,writev}() as long as there's no .access() - * in special_mapping_vmops(). - * For more details check_vma_flags() and __access_remote_vm() + * vvar_fault() protects this from being called through remote interfaces= like + * /proc/$pid/mem or process_vm_{readv,writev}(). */ =20 WARN(1, "vvar_page accessed remotely"); diff --git a/lib/vdso/datastore.c b/lib/vdso/datastore.c index 3693c6caf2c4d41a526613d5fb746cb3a981ea2e..ed1aa3e27b13f8b48d18dad9488= e0798f49cb338 100644 --- a/lib/vdso/datastore.c +++ b/lib/vdso/datastore.c @@ -40,10 +40,15 @@ struct vdso_arch_data *vdso_k_arch_data =3D &vdso_arch_= data_store.data; static vm_fault_t vvar_fault(const struct vm_special_mapping *sm, struct vm_area_struct *vma, struct vm_fault *vmf) { - struct page *timens_page =3D find_timens_vvar_page(vma); + struct page *timens_page; unsigned long addr, pfn; vm_fault_t err; =20 + if (unlikely(vmf->flags & FAULT_FLAG_REMOTE)) + return VM_FAULT_SIGBUS; + + timens_page =3D find_timens_vvar_page(vma); + switch (vmf->pgoff) { case VDSO_TIME_PAGE_OFFSET: if (!IS_ENABLED(CONFIG_HAVE_GENERIC_VDSO)) --=20 2.51.0 From nobody Sat Oct 4 22:34:43 2025 Received: from galois.linutronix.de (Galois.linutronix.de [193.142.43.55]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id CA5EA26CE21 for ; Mon, 1 Sep 2025 12:34:37 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=193.142.43.55 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1756730079; cv=none; b=EF8rd+eqqSXbO6kteQDj8Ym8+qW+1PkiCV88HLCMEk6OBwF2qctICheJ+Ke1GJO4fLUSdH5tqn5pjGOMWIfr8N8TAJ2NElZxv5MkB0Tx7P9A4nEFTQQJhDi2xW2Ps4Eq7oTKFqjpceAd27IY5VBpUynMOESfO0uy0aKjGNvNpH4= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1756730079; c=relaxed/simple; bh=2Z2Yf2jDLYoL0s7wWG7QZHD1EkbeUblgxlFw9/asD14=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=clTvlKEWJcajQ0jYu+dSBDgbwEECv5MiMlDYSnwiEfclIlcrDpZ3q9c9np6Z9DD9hh+XEAqDouo23V1ln81VYf3FdFe3ONFAQ19PO6vtFdE6Fl1BlgA3/f+k8o0syrw4kkl4PqvdWudqcKuj3RAgGEQWGWGh+MMUdUOQAUGmUJo= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linutronix.de; spf=pass smtp.mailfrom=linutronix.de; dkim=pass (2048-bit key) header.d=linutronix.de header.i=@linutronix.de header.b=p2Dn6AZV; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b=f6wmqjIh; arc=none smtp.client-ip=193.142.43.55 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linutronix.de Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linutronix.de Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=linutronix.de header.i=@linutronix.de header.b="p2Dn6AZV"; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b="f6wmqjIh" From: =?utf-8?q?Thomas_Wei=C3=9Fschuh?= DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1756730076; 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=jvnBFUYJVcZhyzM1/4HJ06q2UGLo2W1V/cNJfNZMj1A=; b=p2Dn6AZV60rxrMSrLO0RRHHMoRZONaaRuJvv4ivlSZz1FADREzFYlwjvnSbwpXml2bjs0p veADOOORfNIkyvl/8e+9yqHE4X2n11Gihj2e0efLYaV5Y1/zi0sVYn34GewIW5C3HbbF/1 Zr6z6Y91FxGdeSEMlJ8ZnCrCriDc37xlDefip/S4luR1VwjjDU1rPOcodO1qHbJc5Zk2oh rKnMsVf2yiOCdb4CmQEQUkWeWnzsT7h/KgeWh1CY4bOsDnVREmjKSfRE7wYyHjpYXqlnZY OGLv3GivA654utie9rz8U8dChzWT6k49QnToUq3wfui4GPYlmG00oIcggflnkA== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1756730076; 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=jvnBFUYJVcZhyzM1/4HJ06q2UGLo2W1V/cNJfNZMj1A=; b=f6wmqjIhGy98adGOvFfTCJnRt4YLGyXAZa4zGGlt6WUGuzWGHGrHpupQ9CirE4gQn4ct/n 5Y0S/f09hdrFpDCg== Date: Mon, 01 Sep 2025 14:34:23 +0200 Subject: [PATCH v2 2/3] vdso/datastore: Allow prefaulting by mlockall() Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Message-Id: <20250901-vdso-mlockall-v2-2-68f5a6f03345@linutronix.de> References: <20250901-vdso-mlockall-v2-0-68f5a6f03345@linutronix.de> In-Reply-To: <20250901-vdso-mlockall-v2-0-68f5a6f03345@linutronix.de> To: Anna-Maria Behnsen , Frederic Weisbecker , Thomas Gleixner , Andy Lutomirski , Vincenzo Frascino Cc: Nam Cao , linux-kernel@vger.kernel.org, =?utf-8?q?Thomas_Wei=C3=9Fschuh?= X-Developer-Signature: v=1; a=ed25519-sha256; t=1756730069; l=4112; i=thomas.weissschuh@linutronix.de; s=20240209; h=from:subject:message-id; bh=2Z2Yf2jDLYoL0s7wWG7QZHD1EkbeUblgxlFw9/asD14=; b=gX/BDPsYpmhqdLCoF4/B8x+IbRsqmpIKwvKEsT0SBsMCwe3+Oi2W0Tnsy+QSIfb66b5Cg9sXl bkjcsjC9+SbDpk7JB/08o/UgJA7obSZ/2NB5L+lVFb+2yaVWwk7QXYk X-Developer-Key: i=thomas.weissschuh@linutronix.de; a=ed25519; pk=pfvxvpFUDJV2h2nY0FidLUml22uGLSjByFbM6aqQQws= Latency-sensitive applications expect not to experience any pagefaults after calling mlockall(). However mlockall() ignores VM_PFNMAP and VM_IO mappings, both of which are used by the generic vDSO datastore. While the fault handler itself is very fast, going through the full pagefault exception handling is much slower, on the order of 20us in a test machine. Since the memory behind the datastore mappings is always present and accessible it is not necessary to use VM_IO for them. VM_PFNMAP can be removed by mapping the pages through 'struct page' instead of PFNs. VM_MIXEDMAP is necessary to call vmf_insert_page() in the timens optimization path. The data page mapping is now also aligned with the architecture-specific code pages. Some architecture-specific data pages, like the x86 VCLOCK pages, continue to use VM_IO as they are not always mappable. Regular mlock() would also work, but userspace does not know the boundaries of the vDSO. Reported-by: Nam Cao Signed-off-by: Thomas Wei=C3=9Fschuh Tested-by: Nam Cao --- lib/vdso/datastore.c | 25 +++++++++++++------------ 1 file changed, 13 insertions(+), 12 deletions(-) diff --git a/lib/vdso/datastore.c b/lib/vdso/datastore.c index ed1aa3e27b13f8b48d18dad9488e0798f49cb338..00714c0cf0b24b813bf5b28ff8a= 19e5f246fce45 100644 --- a/lib/vdso/datastore.c +++ b/lib/vdso/datastore.c @@ -40,8 +40,8 @@ struct vdso_arch_data *vdso_k_arch_data =3D &vdso_arch_da= ta_store.data; static vm_fault_t vvar_fault(const struct vm_special_mapping *sm, struct vm_area_struct *vma, struct vm_fault *vmf) { - struct page *timens_page; - unsigned long addr, pfn; + struct page *page, *timens_page; + unsigned long addr; vm_fault_t err; =20 if (unlikely(vmf->flags & FAULT_FLAG_REMOTE)) @@ -53,17 +53,17 @@ static vm_fault_t vvar_fault(const struct vm_special_ma= pping *sm, case VDSO_TIME_PAGE_OFFSET: if (!IS_ENABLED(CONFIG_HAVE_GENERIC_VDSO)) return VM_FAULT_SIGBUS; - pfn =3D __phys_to_pfn(__pa_symbol(vdso_k_time_data)); + page =3D virt_to_page(vdso_k_time_data); if (timens_page) { /* * Fault in VVAR page too, since it will be accessed * to get clock data anyway. */ addr =3D vmf->address + VDSO_TIMENS_PAGE_OFFSET * PAGE_SIZE; - err =3D vmf_insert_pfn(vma, addr, pfn); + err =3D vmf_insert_page(vma, addr, page); if (unlikely(err & VM_FAULT_ERROR)) return err; - pfn =3D page_to_pfn(timens_page); + page =3D timens_page; } break; case VDSO_TIMENS_PAGE_OFFSET: @@ -76,24 +76,25 @@ static vm_fault_t vvar_fault(const struct vm_special_ma= pping *sm, */ if (!IS_ENABLED(CONFIG_TIME_NS) || !timens_page) return VM_FAULT_SIGBUS; - pfn =3D __phys_to_pfn(__pa_symbol(vdso_k_time_data)); + page =3D virt_to_page(vdso_k_time_data); break; case VDSO_RNG_PAGE_OFFSET: if (!IS_ENABLED(CONFIG_VDSO_GETRANDOM)) return VM_FAULT_SIGBUS; - pfn =3D __phys_to_pfn(__pa_symbol(vdso_k_rng_data)); + page =3D virt_to_page(vdso_k_rng_data); break; case VDSO_ARCH_PAGES_START ... VDSO_ARCH_PAGES_END: if (!IS_ENABLED(CONFIG_ARCH_HAS_VDSO_ARCH_DATA)) return VM_FAULT_SIGBUS; - pfn =3D __phys_to_pfn(__pa_symbol(vdso_k_arch_data)) + - vmf->pgoff - VDSO_ARCH_PAGES_START; + page =3D virt_to_page(vdso_k_arch_data) + vmf->pgoff - VDSO_ARCH_PAGES_S= TART; break; default: return VM_FAULT_SIGBUS; } =20 - return vmf_insert_pfn(vma, vmf->address, pfn); + get_page(page); + vmf->page =3D page; + return 0; } =20 const struct vm_special_mapping vdso_vvar_mapping =3D { @@ -104,8 +105,8 @@ const struct vm_special_mapping vdso_vvar_mapping =3D { struct vm_area_struct *vdso_install_vvar_mapping(struct mm_struct *mm, uns= igned long addr) { return _install_special_mapping(mm, addr, VDSO_NR_PAGES * PAGE_SIZE, - VM_READ | VM_MAYREAD | VM_IO | VM_DONTDUMP | - VM_PFNMAP | VM_SEALED_SYSMAP, + VM_READ | VM_MAYREAD | VM_DONTDUMP | + VM_MIXEDMAP | VM_SEALED_SYSMAP, &vdso_vvar_mapping); } =20 --=20 2.51.0 From nobody Sat Oct 4 22:34:43 2025 Received: from galois.linutronix.de (Galois.linutronix.de [193.142.43.55]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 805BE2EE60A for ; Mon, 1 Sep 2025 12:34:38 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=193.142.43.55 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1756730080; cv=none; b=tFUTanxIMl1LwgK7jkBXoOWDakrYz5DADldNJduiM2w3dx6b7V9MspmdwIc9yqm/r4GFk8Zsh1/souI67m/GmcFPOywhdMl9k7hN+Z+ndM41Dufpa0FXVEwLE8birGsH2xS0dKU52f0ymis13+A+wlCOcbCJucl2eeWFLVzI1+8= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1756730080; c=relaxed/simple; bh=KgmRXr8eTNBbNSGItv2vwvS8zIsxpkPNuXrWN6GBfPg=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=J8IcV1NTzYb/3RfHFzBUSbdTW7+iR/WAN6Eejor1pz8iafqg6TjvgOC+1sg3GqnStMm1YDn6L0G8ht1jAUIJ7aFEnIJno9gwbN62hIpIYOCNZxXc6RjSdTNj62hSJXTXJjgn7Lf6hLKutfessXy4+0qHSGyONVxBUAkBdhAkKDk= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linutronix.de; spf=pass smtp.mailfrom=linutronix.de; dkim=pass (2048-bit key) header.d=linutronix.de header.i=@linutronix.de header.b=L4820MGb; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b=Jwtr5WD/; arc=none smtp.client-ip=193.142.43.55 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linutronix.de Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linutronix.de Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=linutronix.de header.i=@linutronix.de header.b="L4820MGb"; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b="Jwtr5WD/" From: =?utf-8?q?Thomas_Wei=C3=9Fschuh?= DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1756730076; 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=sLXN0Ug7/Fbpvs+OH36pHZYk1tM/rWA4HaY8KaBRXA8=; b=L4820MGbboZjRU7p5VYVDVF0M3YNMBEmjlHtLCd33rAnEgEtIfQNzeAEDV9XlEjUPSkUo4 hnKY4lcXU5Xz6vyYPW3RupltKJ/HwOMft58youefOWuozV4UyNfciKjisgvgUQj4F8cR8B +Fv4+5GMpRCWCIwzexKRym5sbBhJ7MBI857Mlt7giy1/SaqDzqkq+A36eSn31JmYIeEzwL Su3mhuJyBmdH+O3j3eNGFGFGWXlHIWAmkeI+uimmoTdxJ7sekG4FA34IOdwV5zyL4rQbW5 7oapP9PjQ53N+ZZbmBjgL+dGVVHW8/c7Lzd34vr3TS64xNyR1nqEI93ieBR5fQ== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1756730076; 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=sLXN0Ug7/Fbpvs+OH36pHZYk1tM/rWA4HaY8KaBRXA8=; b=Jwtr5WD/oeLTg+IBGHvZZZgHKjU/aUeOoZcdRpF+bYyTkPNCDmHzK2YapEm2nnLNFDy6ds Ic+idPRkW9V4Q8Ag== Date: Mon, 01 Sep 2025 14:34:24 +0200 Subject: [PATCH v2 3/3] vdso/datastore: Map zero page for unavailable data Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Message-Id: <20250901-vdso-mlockall-v2-3-68f5a6f03345@linutronix.de> References: <20250901-vdso-mlockall-v2-0-68f5a6f03345@linutronix.de> In-Reply-To: <20250901-vdso-mlockall-v2-0-68f5a6f03345@linutronix.de> To: Anna-Maria Behnsen , Frederic Weisbecker , Thomas Gleixner , Andy Lutomirski , Vincenzo Frascino Cc: Nam Cao , linux-kernel@vger.kernel.org, =?utf-8?q?Thomas_Wei=C3=9Fschuh?= X-Developer-Signature: v=1; a=ed25519-sha256; t=1756730069; l=2172; i=thomas.weissschuh@linutronix.de; s=20240209; h=from:subject:message-id; bh=KgmRXr8eTNBbNSGItv2vwvS8zIsxpkPNuXrWN6GBfPg=; b=ChEMS7suOrbGHjxdsNd1FrdITfrSRcpc6sQTgufN1Pd/3HiYd7dlaLzUcQBraq4yah+Z8Vf6R sX56GXwwlu6C8PTDlwMt7TONJ0xsDoHo1kL8+iyB5LQ9tsoU2EevJKW X-Developer-Key: i=thomas.weissschuh@linutronix.de; a=ed25519; pk=pfvxvpFUDJV2h2nY0FidLUml22uGLSjByFbM6aqQQws= mlockall() stops if a page in a VMA is unmappable. As the datastore VMA can contain holes, mlockall() does not process all data pages correctly. Replace the mapping error VM_FAULT_SIGBUS with a mapping of the zero page. The vDSO will not access these pages in any case and for other userspace these pages have undefined contents. This will allow mlockall() to process all pages within the VMA. Signed-off-by: Thomas Wei=C3=9Fschuh --- lib/vdso/datastore.c | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/lib/vdso/datastore.c b/lib/vdso/datastore.c index 00714c0cf0b24b813bf5b28ff8a19e5f246fce45..f9e37195c2af43c7b2c4b02d01b= e492d84223ecd 100644 --- a/lib/vdso/datastore.c +++ b/lib/vdso/datastore.c @@ -40,7 +40,7 @@ struct vdso_arch_data *vdso_k_arch_data =3D &vdso_arch_da= ta_store.data; static vm_fault_t vvar_fault(const struct vm_special_mapping *sm, struct vm_area_struct *vma, struct vm_fault *vmf) { - struct page *page, *timens_page; + struct page *page =3D ZERO_PAGE(0), *timens_page; unsigned long addr; vm_fault_t err; =20 @@ -52,7 +52,7 @@ static vm_fault_t vvar_fault(const struct vm_special_mapp= ing *sm, switch (vmf->pgoff) { case VDSO_TIME_PAGE_OFFSET: if (!IS_ENABLED(CONFIG_HAVE_GENERIC_VDSO)) - return VM_FAULT_SIGBUS; + break; page =3D virt_to_page(vdso_k_time_data); if (timens_page) { /* @@ -75,17 +75,17 @@ static vm_fault_t vvar_fault(const struct vm_special_ma= pping *sm, * See also the comment near timens_setup_vdso_data(). */ if (!IS_ENABLED(CONFIG_TIME_NS) || !timens_page) - return VM_FAULT_SIGBUS; + break; page =3D virt_to_page(vdso_k_time_data); break; case VDSO_RNG_PAGE_OFFSET: if (!IS_ENABLED(CONFIG_VDSO_GETRANDOM)) - return VM_FAULT_SIGBUS; + break; page =3D virt_to_page(vdso_k_rng_data); break; case VDSO_ARCH_PAGES_START ... VDSO_ARCH_PAGES_END: if (!IS_ENABLED(CONFIG_ARCH_HAS_VDSO_ARCH_DATA)) - return VM_FAULT_SIGBUS; + break; page =3D virt_to_page(vdso_k_arch_data) + vmf->pgoff - VDSO_ARCH_PAGES_S= TART; break; default: --=20 2.51.0