From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by smtp.subspace.kernel.org (Postfix) with ESMTP id BA8D22EEE7C for ; Fri, 3 Jul 2026 11:43:24 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=217.140.110.172 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1783079006; cv=none; b=VOjnFg6ZApMGo5xpCVxaLyo5yE7gRQCj6vKlPeJCxJuSME831FLgrZ6iy5UnHf5UQTBjZF2wd0c64QmhuX5SdBjgkHQlDl+hUW2N/rGRi0QVgtj+l5rnngn8zNBItyjCNDodW3PAnPIql00MuevRdclr9obQpRYt7Ez8Ll/z0v4= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1783079006; c=relaxed/simple; bh=9JD/rGnP4z6sxKxaETbXjsBJM6V+qvu6dbKpCu5ZUWA=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=fghUiHvA7TfYAXe0tbku+AkJNbexjAvBEHkoSdpi2+O3Jqkmzl9/OeK+DI5LpK/kEyqDONRwIv0L1x0zw8YJYC8cgW1uV4X3kjT2HvNg+ixHK2I8DExIwz9FdIkYbIJwN6ygbIGRQCFYCIuO/hwhIq3Mf3yP6ze14oGd8Mb1rsw= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=arm.com; spf=pass smtp.mailfrom=arm.com; dkim=pass (1024-bit key) header.d=arm.com header.i=@arm.com header.b=tVEge0Bj; arc=none smtp.client-ip=217.140.110.172 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=arm.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=arm.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=arm.com header.i=@arm.com header.b="tVEge0Bj" Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.121.207.14]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id A3DF41E2F; Fri, 3 Jul 2026 04:43:19 -0700 (PDT) Received: from cesw-amp-gbt-1s-m12830-01.blr.arm.com (cesw-amp-gbt-1s-m12830-01.blr.arm.com [10.164.195.31]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPA id BC5943FAA1; Fri, 3 Jul 2026 04:43:14 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=arm.com; s=foss; t=1783079004; bh=9JD/rGnP4z6sxKxaETbXjsBJM6V+qvu6dbKpCu5ZUWA=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=tVEge0BjP5FjjmbkU4psRvLiJd6bT9jhj1hm1Pa4vOf3rdbXx6C7YaGHpoigAPzqO vKdTkxgcIiMBdS93gKBCSr4GR2SegSbmQlxjG4YynzgaC0GjPSQiSEhJAQWBhw6M0z NnXaV/42Hn1Ubhy+dmLVElzAxQsZflcB0qbag9k0= From: Dev Jain To: muchun.song@linux.dev, osalvador@suse.de, akpm@linux-foundation.org, ljs@kernel.org, david@kernel.org, liam@infradead.org Cc: Dev Jain , riel@surriel.com, vbabka@kernel.org, harry@kernel.org, jannh@google.com, lance.yang@linux.dev, kas@kernel.org, linux-mm@kvack.org, linux-kernel@vger.kernel.org, apopple@nvidia.com, rcampbell@nvidia.com, ziy@nvidia.com, matthew.brost@intel.com, joshua.hahnjy@gmail.com, rakie.kim@sk.com, byungchul@sk.com, gourry@gourry.net, ying.huang@linux.alibaba.com, ak@linux.intel.com, nao.horiguchi@gmail.com, mel@csn.ul.ie, j-nomura@ce.jp.nec.com, pfalcato@suse.de, tglx@kernel.org, dave.hansen@intel.com, jpoimboe@kernel.org, catalin.marinas@arm.com, will@kernel.org, linux-arm-kernel@lists.infradead.org, ryan.roberts@arm.com, anshuman.khandual@arm.com Subject: [PATCH v3 6/6] mm/mprotect: use huge_ptep_get() for hugetlb Date: Fri, 3 Jul 2026 11:41:59 +0000 Message-ID: <20260703114202.365553-7-dev.jain@arm.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20260703114202.365553-1-dev.jain@arm.com> References: <20260703114202.365553-1-dev.jain@arm.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit prot_none_hugetlb_entry() is the hugetlb callback for the early mprotect(PROT_NONE) PFN permission walk on x86. The callback passes the decoded PFN to pfn_modify_allowed(). For a hugetlb callback, the pte pointer refers to a hugetlb entry. On architectures where hugetlb entries need huge_ptep_get(), reading that entry with ptep_get() can make the permission check use the wrong PFN. Use huge_ptep_get() before decoding the hugetlb PFN. Currently there is no path which can trigger a bug: huge_ptep_get() is a simple ptep_get() for x86, and the prot_none walk occurs only for x86. So no need to backport - use the correct helper anyways. Fixes: 42e4089c7890 ("x86/speculation/l1tf: Disallow non privileged high MMIO PROT_NONE mappings") Reviewed-by: Muchun Song Signed-off-by: Dev Jain --- mm/mprotect.c | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/mm/mprotect.c b/mm/mprotect.c index 9cbf932b028cf..6360d8a378023 100644 --- a/mm/mprotect.c +++ b/mm/mprotect.c @@ -699,14 +699,20 @@ static int prot_none_pte_entry(pte_t *pte, unsigned long addr, 0 : -EACCES; } +#ifdef CONFIG_HUGETLB_PAGE static int prot_none_hugetlb_entry(pte_t *pte, unsigned long hmask, unsigned long addr, unsigned long next, struct mm_walk *walk) { - return pfn_modify_allowed(pte_pfn(ptep_get(pte)), - *(pgprot_t *)(walk->private)) ? - 0 : -EACCES; + const pte_t entry = huge_ptep_get(walk->mm, addr, pte); + + if (pfn_modify_allowed(pte_pfn(entry), *(pgprot_t *)(walk->private))) + return 0; + return -EACCESS; } +#else +#define prot_none_hugetlb_entry NULL +#endif static int prot_none_test(unsigned long addr, unsigned long next, struct mm_walk *walk) -- 2.43.0