mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: "tip-bot2 for Mike Rapoport (Microsoft)" <tip-bot2@linutronix.de>
To: linux-tip-commits@vger.kernel.org
Cc: "Mike Rapoport (Microsoft)" <rppt@kernel.org>,
	Dave Hansen <dave.hansen@linux.intel.com>,
	Juergen Gross <jgross@suse.com>,
	"Lorenzo Stoakes (ARM)" <ljs@kernel.org>,
	syzbot@syzkaller.appspotmail.com, Atish Patra <atishp@meta.com>,
	Nikunj A Dadhania <nikunj@amd.com>,
	stable@vger.kernel.org, x86@kernel.org,
	linux-kernel@vger.kernel.org
Subject: [tip: x86/urgent] x86/mm/pat: Fix effective RW computation in lookup_address_in_pgd_attr()
Date: Mon, 31 Aug 2026 22:27:22 -0000	[thread overview]
Message-ID: <178821524253.3717435.263421019019349643.tip-bot2@tip-bot2> (raw)
In-Reply-To: <20260813-cpa-fixes-v2-5-39b4ff90f91d@kernel.org>

The following commit has been merged into the x86/urgent branch of tip:

Commit-ID:     34cd1c931a365a6b81e00e743f9f260050104ff6
Gitweb:        https://git.kernel.org/tip/34cd1c931a365a6b81e00e743f9f260050104ff6
Author:        Mike Rapoport (Microsoft) <rppt@kernel.org>
AuthorDate:    Thu, 13 Aug 2026 12:01:28 +03:00
Committer:     Dave Hansen <dave.hansen@linux.intel.com>
CommitterDate: Mon, 31 Aug 2026 15:20:52 -07:00

x86/mm/pat: Fix effective RW computation in lookup_address_in_pgd_attr()

lookup_address_in_pgd_attr() accumulates the effective NX and RW bits of
the walked page table levels so that verify_rwx() can detect mappings that
are both writable and executable.

The RW bits are folded into a bool with

	rw &= pXd_flags(*pXd) & _PAGE_RW;

but _PAGE_RW is 0x2. So consider the accumulation line:

        rw &= pXd_flags(*pXd) & _PAGE_RW;

where rw=0x1 and the right side evaluates down to 0x2. It'll end up doing:

        rw = 0x1 & 0x2

and rw always ends up 0.

This way rw becomes false at the first level walked, regardless of the
actual permissions, and verify_rwx() treats every mapping as non-writable
and never reports a W^X violation.

Add double negation to the right side to normalize the _PAGE_RW flag to
0 or 1.

Assisted-by: Copilot:claude-opus-4.8
Fixes: ceb647b4b529 ("x86/pat: Introduce lookup_address_in_pgd_attr()")
Signed-off-by: Mike Rapoport (Microsoft) <rppt@kernel.org>
Signed-off-by: Dave Hansen <dave.hansen@linux.intel.com>
Reviewed-by: Juergen Gross <jgross@suse.com>
Reviewed-by: Lorenzo Stoakes (ARM) <ljs@kernel.org>
Tested-by: syzbot@syzkaller.appspotmail.com
Tested-by: Atish Patra <atishp@meta.com>
Tested-by: Nikunj A Dadhania <nikunj@amd.com>
Cc: stable@vger.kernel.org
Link: https://patch.msgid.link/20260813-cpa-fixes-v2-5-39b4ff90f91d@kernel.org
---
 arch/x86/mm/pat/set_memory.c | 8 ++++----
 1 file changed, 4 insertions(+), 4 deletions(-)

diff --git a/arch/x86/mm/pat/set_memory.c b/arch/x86/mm/pat/set_memory.c
index 4652487..2266609 100644
--- a/arch/x86/mm/pat/set_memory.c
+++ b/arch/x86/mm/pat/set_memory.c
@@ -754,7 +754,7 @@ pte_t *lookup_address_in_pgd_attr(pgd_t *pgd, unsigned long address,
 
 	*level = PG_LEVEL_512G;
 	*nx |= pgd_flags(*pgd) & _PAGE_NX;
-	*rw &= pgd_flags(*pgd) & _PAGE_RW;
+	*rw &= !!(pgd_flags(*pgd) & _PAGE_RW);
 
 	p4d = p4d_offset(pgd, address);
 	if (p4d_none(*p4d))
@@ -765,7 +765,7 @@ pte_t *lookup_address_in_pgd_attr(pgd_t *pgd, unsigned long address,
 
 	*level = PG_LEVEL_1G;
 	*nx |= p4d_flags(*p4d) & _PAGE_NX;
-	*rw &= p4d_flags(*p4d) & _PAGE_RW;
+	*rw &= !!(p4d_flags(*p4d) & _PAGE_RW);
 
 	pud = pud_offset(p4d, address);
 	if (pud_none(*pud))
@@ -776,7 +776,7 @@ pte_t *lookup_address_in_pgd_attr(pgd_t *pgd, unsigned long address,
 
 	*level = PG_LEVEL_2M;
 	*nx |= pud_flags(*pud) & _PAGE_NX;
-	*rw &= pud_flags(*pud) & _PAGE_RW;
+	*rw &= !!(pud_flags(*pud) & _PAGE_RW);
 
 	pmd = pmd_offset(pud, address);
 	if (pmd_none(*pmd))
@@ -787,7 +787,7 @@ pte_t *lookup_address_in_pgd_attr(pgd_t *pgd, unsigned long address,
 
 	*level = PG_LEVEL_4K;
 	*nx |= pmd_flags(*pmd) & _PAGE_NX;
-	*rw &= pmd_flags(*pmd) & _PAGE_RW;
+	*rw &= !!(pmd_flags(*pmd) & _PAGE_RW);
 
 	return pte_offset_kernel(pmd, address);
 }

  parent reply	other threads:[~2026-08-31 22:27 UTC|newest]

Thread overview: 66+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-08-13  9:01 [PATCH v2 0/5] x86/mm/pat: CPA fixes Mike Rapoport
2026-08-13  9:01 ` [PATCH v2 1/5] x86/mm/pat: acquire init_mm write lock on collapse to avoid UAF Mike Rapoport
2026-08-31 22:27   ` [tip: x86/urgent] x86/mm/pat: Acquire " tip-bot2 for Lorenzo Stoakes (ARM)
2026-09-01  6:03     ` Jiri Slaby
2026-09-01  7:10       ` Lorenzo Stoakes (ARM)
2026-09-01 23:36         ` Dave Hansen
2026-09-02  6:53           ` Lorenzo Stoakes (ARM)
2026-09-08  9:32           ` Mike Rapoport
2026-09-08 10:12             ` Lorenzo Stoakes (ARM)
2026-09-08 13:58             ` Dave Hansen
2026-09-08 15:14               ` Dave Hansen
2026-09-08 15:17               ` Vlastimil Babka (SUSE)
2026-09-08 19:59                 ` Dave Hansen
2026-09-08 23:00                   ` Update on CPA fixes, x86/urgent and x86/mm Dave Hansen
2026-09-09  6:40                     ` Ingo Molnar
2026-09-09  6:45                       ` Ingo Molnar
2026-09-02 18:33   ` [tip: x86/urgent] x86/mm/pat: Acquire init_mm write lock on collapse to avoid UAF tip-bot2 for Lorenzo Stoakes (ARM)
2026-09-08  7:21   ` [tip: x86/mm] " tip-bot2 for Lorenzo Stoakes (ARM)
2026-09-08 22:51   ` [tip: x86/urgent] " tip-bot2 for Lorenzo Stoakes (ARM)
2026-09-09  6:44   ` tip-bot2 for Lorenzo Stoakes (ARM)
2026-08-13  9:01 ` [PATCH v2 2/5] x86/mm/pat: acquire init_mm read lock on attribute change " Mike Rapoport
2026-08-31 22:27   ` [tip: x86/urgent] x86/mm/pat: Acquire " tip-bot2 for Lorenzo Stoakes (ARM)
2026-09-01  6:05     ` Jiri Slaby
2026-09-01  7:20       ` Lorenzo Stoakes (ARM)
2026-09-01 13:46       ` Dave Hansen
2026-09-02 18:33   ` tip-bot2 for Lorenzo Stoakes (ARM)
2026-09-08  7:21   ` [tip: x86/mm] x86/mm/pat: Acquire init_mm read lock on attribute changes " tip-bot2 for Lorenzo Stoakes (ARM)
2026-09-08 22:51   ` [tip: x86/urgent] " tip-bot2 for Lorenzo Stoakes (ARM)
2026-09-09  6:44   ` tip-bot2 for Lorenzo Stoakes (ARM)
2026-08-13  9:01 ` [PATCH v2 3/5] x86/alternative: exclude text poking against change_page_attr() Mike Rapoport
2026-08-25  9:37   ` Jiri Slaby
2026-08-31 22:27   ` [tip: x86/urgent] x86/alternative: Exclude " tip-bot2 for Pedro Falcato
2026-09-01  6:16     ` Jiri Slaby
2026-09-01  7:18       ` Lorenzo Stoakes (ARM)
2026-09-01  7:22         ` Jiri Slaby
2026-09-01  7:24           ` Lorenzo Stoakes (ARM)
2026-09-02 18:33   ` tip-bot2 for Pedro Falcato
2026-09-08  7:21   ` [tip: x86/mm] x86/alternatives: " tip-bot2 for Pedro Falcato
2026-09-08 22:51   ` [tip: x86/urgent] " tip-bot2 for Pedro Falcato
2026-09-09  6:44   ` tip-bot2 for Pedro Falcato
2026-08-13  9:01 ` [PATCH v2 4/5] x86/mm/pat: allocate split page tables as kernel page tables Mike Rapoport
2026-08-31 22:27   ` [tip: x86/urgent] x86/mm/pat: Allocate " tip-bot2 for Lorenzo Stoakes (ARM)
2026-09-02 18:33   ` tip-bot2 for Lorenzo Stoakes (ARM)
2026-09-08  7:21   ` [tip: x86/mm] " tip-bot2 for Lorenzo Stoakes (ARM)
2026-09-08 22:51   ` [tip: x86/urgent] " tip-bot2 for Lorenzo Stoakes (ARM)
2026-09-09  6:44   ` tip-bot2 for Lorenzo Stoakes (ARM)
2026-08-13  9:01 ` [PATCH v2 5/5] x86/mm/pat: fix effective RW computation in lookup_address_in_pgd_attr() Mike Rapoport (Microsoft)
2026-08-13  9:45   ` Lorenzo Stoakes (ARM)
2026-08-31 22:27   ` tip-bot2 for Mike Rapoport (Microsoft) [this message]
2026-09-02 18:33   ` [tip: x86/urgent] x86/mm/pat: Fix " tip-bot2 for Mike Rapoport (Microsoft)
2026-09-05  4:42     ` Nathan Chancellor
2026-09-06 14:50       ` Dave Hansen
2026-09-06 18:12         ` Nathan Chancellor
2026-09-06 19:12           ` Dave Hansen
2026-09-06 19:52             ` Mike Rapoport
2026-09-07  6:46               ` Mike Rapoport
2026-09-07 22:28             ` Nathan Chancellor
2026-09-08  9:29               ` Mike Rapoport
2026-09-08 22:52   ` [tip: x86/mm] " tip-bot2 for Mike Rapoport (Microsoft)
2026-08-13 15:05 ` [PATCH v2 0/5] x86/mm/pat: CPA fixes Nikunj A. Dadhania
2026-08-13 15:07   ` Lorenzo Stoakes (ARM)
2026-08-13 15:23     ` Pedro Falcato
2026-08-13 17:13 ` Andrew Morton
2026-08-25  7:12 ` Atish Patra
2026-08-25  7:31   ` Lorenzo Stoakes (ARM)
2026-08-25 20:05     ` Atish Patra

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=178821524253.3717435.263421019019349643.tip-bot2@tip-bot2 \
    --to=tip-bot2@linutronix.de \
    --cc=atishp@meta.com \
    --cc=dave.hansen@linux.intel.com \
    --cc=jgross@suse.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-tip-commits@vger.kernel.org \
    --cc=ljs@kernel.org \
    --cc=nikunj@amd.com \
    --cc=rppt@kernel.org \
    --cc=stable@vger.kernel.org \
    --cc=syzbot@syzkaller.appspotmail.com \
    --cc=x86@kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®