Skip to contentSkip to conversation

x86/mm: Disable W^X detection and enforcement on 32-bit

PATCH In review Dave Hansen 7 participants 8 messages Sep 23, 2022 – Oct 2, 2022

Subsystems (3)
lore
Share & tools
lore

Dave Hansen

author maintainer
#0 lore raw

PATCH 1/1 x86/mm: Disable W^X detection and enforcement on 32-bit

The 32-bit code is in a weird spot. Some 32-bit builds (non-PAE) do not even have NX support. Even PAE builds that support NX have to contend with things like EFI data and code mixed in the same pages where W+X is unavoidable.

The folks still running X86_32=y kernels are unlikely to care much about NX. That combined with the fundamental inability fix _all_ of the W+X things means this code had little value on X86_32=y. Disable the checks.

---
 arch/x86/mm/pat/set_memory.c | 8 ++++++++
 1 file changed, 8 insertions(+)
arch/x86/mm/pat/set_memory.c +8 -0
index 20b1e24baa85..efe882c753ca 100644
@@ -587,6 +587,14 @@ static inline pgprot_t verify_rwx(pgprot_t old, pgprot_t new, unsigned long star
 {
 	unsigned long end;
 
+	/*
+	 * 32-bit has some unfixable W+X issues, like EFI code
+	 * and writeable data being in the same page.  Disable
+	 * detection and enforcement there.
+	 */
+	if (IS_ENABLED(CONFIG_X86_32))
+		return new;
+
 	/* Only enforce when NX is supported: */
 	if (!(__supported_pte_mask & _PAGE_NX))
 		return new;
Signature · 1 line
2.34.1
#1 lore raw
Quoted 8 lines · Dave Hansen

The 32-bit code is in a weird spot. Some 32-bit builds (non-PAE) do not even have NX support. Even PAE builds that support NX have to contend with things like EFI data and code mixed in the same pages where W+X is unavoidable.

The folks still running X86_32=y kernels are unlikely to care much about NX. That combined with the fundamental inability fix _all_ of the W+X things means this code had little value on X86_32=y. Disable the checks.

Maybe downgrade the check to a warning for X86_32=y?

Signature · 1 line
  Kiryl Shutsemau / Kirill A. Shutemov
#2 lore raw
Quoted 10 lines · Kirill A. Shutemov
Quoted 8 lines · Dave Hansen

The 32-bit code is in a weird spot. Some 32-bit builds (non-PAE) do not even have NX support. Even PAE builds that support NX have to contend with things like EFI data and code mixed in the same pages where W+X is unavoidable.

The folks still running X86_32=y kernels are unlikely to care much about NX. That combined with the fundamental inability fix _all_ of the W+X things means this code had little value on X86_32=y. Disable the checks.

Maybe downgrade the check to a warning for X86_32=y?

But for this EFI case, we really don't want the warning. It's unfixable.

I'm also not sure we want to go to the trouble to properly silence the warning in these unfixable cases. There was an argument elsewhere in the thread that we really shouldn't be warning on things that we don't have full intentions to fix. I buy that argument.

#3 lore raw
Quoted 10 lines · Dave Hansen
Quoted 9 lines · Kirill A. Shutemov
Quoted 8 lines · Dave Hansen

The 32-bit code is in a weird spot. Some 32-bit builds (non-PAE) do not even have NX support. Even PAE builds that support NX have to contend with things like EFI data and code mixed in the same pages where W+X is unavoidable.

The folks still running X86_32=y kernels are unlikely to care much about NX. That combined with the fundamental inability fix _all_ of the W+X things means this code had little value on X86_32=y. Disable the checks.

Quoted 8 lines
Quoted 1 line

Maybe downgrade the check to a warning for X86_32=y?

But for this EFI case, we really don't want the warning. It's unfixable.

I'm also not sure we want to go to the trouble to properly silence the warning in these unfixable cases. There was an argument elsewhere in the thread that we really shouldn't be warning on things that we don't have full intentions to fix. I buy that argument.

Yes, there are already way too many such useless warnings around. Please don't add more of them.

Guenter

Reviewed-by on v1 1/1
#4 lore raw
In reply to Dave Hansen
Quoted 11 lines · Dave Hansen

The 32-bit code is in a weird spot. Some 32-bit builds (non-PAE) do not even have NX support. Even PAE builds that support NX have to contend with things like EFI data and code mixed in the same pages where W+X is unavoidable.

The folks still running X86_32=y kernels are unlikely to care much about NX. That combined with the fundamental inability fix _all_ of the W+X things means this code had little value on X86_32=y. Disable the checks.

Signature · 1 line
Kees Cook
Tested-by on v1 1/1
#5 lore raw
In reply to Dave Hansen
Quoted 9 lines · Dave Hansen

The 32-bit code is in a weird spot. Some 32-bit builds (non-PAE) do not even have NX support. Even PAE builds that support NX have to contend with things like EFI data and code mixed in the same pages where W+X is unavoidable.

The folks still running X86_32=y kernels are unlikely to care much about NX. That combined with the fundamental inability fix _all_ of the W+X things means this code had little value on X86_32=y. Disable the checks.

Quoted 13 lines

Guenter

Quoted 26 lines
---
 arch/x86/mm/pat/set_memory.c | 8 ++++++++
 1 file changed, 8 insertions(+)
arch/x86/mm/pat/set_memory.c +8 -0
index 20b1e24baa85..efe882c753ca 100644
@@ -587,6 +587,14 @@ static inline pgprot_t verify_rwx(pgprot_t old, pgprot_t new, unsigned long star
 {
 	unsigned long end;
 
+	/*
+	 * 32-bit has some unfixable W+X issues, like EFI code
+	 * and writeable data being in the same page.  Disable
+	 * detection and enforcement there.
+	 */
+	if (IS_ENABLED(CONFIG_X86_32))
+		return new;
+
 	/* Only enforce when NX is supported: */
 	if (!(__supported_pte_mask & _PAGE_NX))
 		return new;
Signature · 1 line
2.34.1
maintainer Acked-by on v1 1/1
#6 lore raw
In reply to Dave Hansen
Quoted 10 lines · Dave Hansen

The 32-bit code is in a weird spot. Some 32-bit builds (non-PAE) do not even have NX support. Even PAE builds that support NX have to contend with things like EFI data and code mixed in the same pages where W+X is unavoidable.

The folks still running X86_32=y kernels are unlikely to care much about NX. That combined with the fundamental inability fix _all_ of the W+X things means this code had little value on X86_32=y. Disable the checks.

Quoted 13 lines
Quoted 26 lines
---
 arch/x86/mm/pat/set_memory.c | 8 ++++++++
 1 file changed, 8 insertions(+)
arch/x86/mm/pat/set_memory.c +8 -1
index 20b1e24baa85..efe882c753ca 100644
@@ -587,6 +587,14 @@ static inline pgprot_t verify_rwx(pgprot_t old, pgprot_t new, unsigned long star
 {
        unsigned long end;
 
+       /*
+        * 32-bit has some unfixable W+X issues, like EFI code
+        * and writeable data being in the same page.  Disable
+        * detection and enforcement there.
+        */
+       if (IS_ENABLED(CONFIG_X86_32))
+               return new;
+
        /* Only enforce when NX is supported: */
        if (!(__supported_pte_mask & _PAGE_NX))
                return new;
--

2.34.1

#7 lore raw
In reply to Dave Hansen

Hi!

Quoted 19 lines

The 32-bit code is in a weird spot. Some 32-bit builds (non-PAE) do not even have NX support. Even PAE builds that support NX have to contend with things like EFI data and code mixed in the same pages where W+X is unavoidable.

The folks still running X86_32=y kernels are unlikely to care much about NX. That combined with the fundamental inability fix _all_ of the W+X things means this code had little value on X86_32=y. Disable the checks.

---
 arch/x86/mm/pat/set_memory.c | 8 ++++++++
 1 file changed, 8 insertions(+)
arch/x86/mm/pat/set_memory.c +0 -0
index 20b1e24baa85..efe882c753ca 100644
@@ -587,6 +587,14 @@ static inline pgprot_t verify_rwx(pgprot_t old, pgprot_t new, unsigned long star
 {

arch/x86/mm/pat/set_memory.c static inline pgprot_t verify_rwx(pgprot_t old, pgprot_t new, unsigned long star · line 597

Quoted 10 lines
arch/x86/mm/pat/set_memory.c +8 -0
 	unsigned long end;
 
+	/*
+	 * 32-bit has some unfixable W+X issues, like EFI code
+	 * and writeable data being in the same page.  Disable
+	 * detection and enforcement there.
+	 */
+	if (IS_ENABLED(CONFIG_X86_32))
+		return new;
+

You are going from extreme to extreme. W^X is useful on x86-32 at least in some configs, so it would make sense to detect and inform about the issues (perhaps with something like KERN_INFO).

Best regards,
Pavel

Signature · 1 line
People of Russia, stop Putin before his war on Ukraine escalates.