Skip to contentSkip to conversation

ARM: 8235/1: Support for the PXN CPU feature on ARMv7

PATCH New Jungseung Lee 2 participants 2 messages Dec 24, 2014 1 message not in the archive

lore
Share & tools
lore

A message that is not in the archive (sent off-list or not yet received): [email protected]

#1 lore raw

PATCH 1/1 ARM: 8235/1: Support for the PXN CPU feature on ARMv7

Hi Ben,

2014-12-24 7:42 GMT+09:00 Ben Hutchings <[email protected]>:

Quoted 6 lines

I think that if a non-LPAE kernel runs on a processor that supports LPAE, it should use PXN in short descriptors. In that case, this test should be changed to match a value of 5 as well. Maybe it should be simply be read_cpuid_ext(CPUID_EXT_MMFR0) & 4, but as I said I can't check this against the ARM ARM.

Yes, you are right.
The case of a non-LPAE kernel running on a processor that supports LPAE has been missed.
It is good to be read_cpuid_ext(CPUID_EXT_MMFR0) & 4.
Thanks for your reporting.

Quoted 7 lines

Ben.

--
Ben Hutchings
Editing code like this is akin to sticking plasters on the bleeding stump of a severed limb. - me, 29 June 1999

#2 lore raw

PATCH 1/1 ARM: 8235/1: Support for the PXN CPU feature on ARMv7

In reply to a message not in the archive
Quoted 34 lines · Ben Hutchings
Quoted 12 lines · Jungseung Lee

Modern ARMv7-A/R cores optionally implement below new hardware feature:

- PXN:
Privileged execute-never(PXN) is a security feature. PXN bit determines whether the processor can execute software from the region. This is effective solution against ret2usr attack. On an implementation that does not include the LPAE, PXN is optionally supported.

This patch set PXN bit on user page table for preventing user code execution with privilege mode.

[...]

Review

Quoted 9 lines
(quoted diff) +9 -0
+
+	/*
+	 * Check is it with support for the PXN bit
+	 * in the Short-descriptor translation table format descriptors.
+	 */
+	if (cpu_arch == CPU_ARCH_ARMv7 &&
+		(read_cpuid_ext(CPUID_EXT_MMFR0) & 0xF) == 4) {
+		user_pmd_table |= PMD_PXNTABLE;
+	}

[...]

I thought it was odd that this checks for a specific value of 4 bits, not just 1. Unfortunately I don't have access to the ARM Architecture Reference Manual, but I reviewed the public documentation to find the value of MMFR0 in current Cortex-A and -R cores.

So far as I can see, these 4 bits are equal to 5 on the Cortex cores that support LPAE (A7, A15, A53, A57), 3 on other v7-A cores and 0 on v7-R cores.

Quoted 5 lines

I think that if a non-LPAE kernel runs on a processor that supports LPAE, it should use PXN in short descriptors. In that case, this test should be changed to match a value of 5 as well. Maybe it should be simply be read_cpuid_ext(CPUID_EXT_MMFR0) & 4, but as I said I can't check this against the ARM ARM.

The MMFR0.VMSA field is 4 bits wide. The individual bits don't have a meaning, it's just a counter as follows:

0b0000 Not supported.
0b0001 Support for IMPLEMENTATION DEFINED VMSA.
0b0010 Support for VMSAv6, with Cache and TLB Type Registers
implemented.
0b0011 Support for VMSAv7, with support for remapping and the Access
flag. ARMv7-A profile.
0b0100 As for 0b0011, and adds support for the PXN bit in the
Short-descriptor translation table format descriptors.
0b0101 As for 0b0100, and adds support for the Long-descriptor
translation table format.

So I agree that we should not just check for 4 since 5 has the PXN feature (they are incremental, so it would be safe for 6/7/8 etc). But I would use ">= 4" rather than just checking a bit in case we ever get to 8.

Signature · 1 line
Catalin