STRICT_KERNEL_RWX weakened on ARM by CONFIG_ARM_LPAE=y
Subsystems (2)
cover STRICT_KERNEL_RWX weakened on ARM by CONFIG_ARM_LPAE=y
Hi,
This patch series fixes a bug which makes CONFIG_STRICT_KERNEL_RWX ineffective when CONFIG_ARM_LPAE is enabled. Specifically, the kernel text and rodata are mapped writeable. This has been the case since DEBUG_RODATA for ARM was first merged in 3.19.
The cause was an incorrect conflict resolution in 1e3479225acb ("ARM: 8275/1:
mm: fix PMD_SECT_RDONLY undeclared compile error") between the commit that implemented DEBUG_RODATA, 80d6b0c2eed2 ("ARM: mm: allow text and rodata sections to be read-only"), and another that moved the LPAE read-only bit into a software bit, ded947798469 ("ARM: 8109/1: mm: Modify pte_write and pmd_write logic for LPAE").
The incorrect mappings were not apparent in the debugfs kernel_page_tables dump because that was checking only the software RO bit, not the hardware RO bit.
Regards,
Philip
Philip Derrin (2):
ARM: mm: make STRICT_KERNEL_RWX effective for LPAE
ARM: mm: dump: check hardware RO bit for LPAE
arch/arm/mm/dump.c | 4 ++-- arch/arm/mm/init.c | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-)
Signature · 1 line
2.15.0
PATCH 1/2 ARM: mm: make STRICT_KERNEL_RWX effective for LPAE
Currently, for ARM kernels with CONFIG_ARM_LPAE and CONFIG_STRICT_KERNEL_RWX enabled, the 2MiB pages mapping the kernel code and rodata are writable. They are marked read-only in a software bit (L_PMD_SECT_RDONLY) but the hardware read-only bit is not set (PMD_SECT_AP2).
For user mappings, the logic that propagates the software bit to the hardware bit is in set_pmd_at(); but for the kernel, section_update() writes the PMDs directly, skipping this logic.
The fix is to set PMD_SECT_AP2 for read-only sections in section_update(), at the same time as L_PMD_SECT_RDONLY.
--- arch/arm/mm/init.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
arch/arm/mm/init.c +2 -2
@@ -639,8 +639,8 @@ static struct section_perm ro_perms[] = { .start = (unsigned long)_stext, .end = (unsigned long )__init_begin, #ifdef CONFIG_ARM_LPAE - .mask = ~L_PMD_SECT_RDONLY , - .prot = L_PMD_SECT_RDONLY, + .mask = ~(L_PMD_SECT_RDONLY |PMD_SECT_AP2 ), + .prot = L_PMD_SECT_RDONLY | PMD_SECT_AP2, #else .mask = ~(PMD_SECT_APX |PMD_SECT_AP_WRITE ), .prot = PMD_SECT_APX | PMD_SECT_AP_WRITE,
Signature · 1 line
2.15.0
PATCH 2/2 ARM: mm: dump: check hardware RO bit for LPAE
In reply to Philip DerrinWhen CONFIG_ARM_LPAE is set, the PMD dump relies on the software read-only bit to determine whether a page is writable. This concealed a bug which left the kernel text section writable (AP2=0) while marked read-only in the software bit.
In a kernel with the AP2 bug, the dump looks like this:
---[ Kernel Mapping ]---
0xc0000000-0xc0200000 2M RW NX SHD
0xc0200000-0xc0600000 4M ro x SHD
0xc0600000-0xc0800000 2M ro NX SHD
0xc0800000-0xc4800000 64M RW NX SHDThe fix is to check that the software and hardware bits are both set before displaying "ro". The dump then shows the true perms:
---[ Kernel Mapping ]---
0xc0000000-0xc0200000 2M RW NX SHD
0xc0200000-0xc0600000 4M RW x SHD
0xc0600000-0xc0800000 2M RW NX SHD
0xc0800000-0xc4800000 64M RW NX SHD--- arch/arm/mm/dump.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
arch/arm/mm/dump.c +2 -2
@@ -129,8 +129,8 @@ static const struct prot_bits section_bits[] = { .val = PMD_SECT_USER, .set = "USR", }, { - .mask = L_PMD_SECT_RDONLY, - .val = L_PMD_SECT_RDONLY, + .mask = L_PMD_SECT_RDONLY | PMD_SECT_AP2, + .val = L_PMD_SECT_RDONLY | PMD_SECT_AP2, .set = "ro", .clear = "RW",#elif __LINUX_ARM_ARCH__ >= 6
Signature · 1 line
2.15.0
cover STRICT_KERNEL_RWX weakened on ARM by CONFIG_ARM_LPAE=y
In reply to Philip DerrinQuoted 14 lines · Philip Derrin
Hi,
This patch series fixes a bug which makes
CONFIG_STRICT_KERNEL_RWXineffective whenCONFIG_ARM_LPAEis enabled. Specifically, the kernel text and rodata are mapped writeable. This has been the case sinceDEBUG_RODATAfor ARM was first merged in 3.19.The cause was an incorrect conflict resolution in
1e3479225acb("ARM: 8275/1:
mm: fixPMD_SECT_RDONLYundeclared compile error") between the commit that implementedDEBUG_RODATA,80d6b0c2eed2("ARM: mm: allow text and rodata sections to be read-only"), and another that moved the LPAE read-only bit into a software bit,ded947798469("ARM: 8109/1: mm: Modifypte_writeandpmd_writelogic for LPAE").
Quoted 3 lines
The incorrect mappings were not apparent in the debugfs
kernel_page_tablesdump because that was checking only the software RO bit, not the hardware RO bit.
Thanks for catching this! Please consider both patches:
-Kees
Quoted 16 lines
Regards,
PhilipPhilip Derrin (2):
ARM: mm: makeSTRICT_KERNEL_RWXeffective for LPAE
ARM: mm: dump: check hardware RO bit for LPAEarch/arm/mm/dump.c | 4 ++-- arch/arm/mm/init.c | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-)--
2.15.0
Signature · 2 lines
Kees Cook Pixel Security
Russell King - ARM Linux
maintainercover STRICT_KERNEL_RWX weakened on ARM by CONFIG_ARM_LPAE=y
Quoted 15 lines · Kees Cook
Quoted 14 lines · Philip Derrin
Hi,
This patch series fixes a bug which makes
CONFIG_STRICT_KERNEL_RWXineffective whenCONFIG_ARM_LPAEis enabled. Specifically, the kernel text and rodata are mapped writeable. This has been the case sinceDEBUG_RODATAfor ARM was first merged in 3.19.The cause was an incorrect conflict resolution in
1e3479225acb("ARM: 8275/1:
mm: fixPMD_SECT_RDONLYundeclared compile error") between the commit that implementedDEBUG_RODATA,80d6b0c2eed2("ARM: mm: allow text and rodata sections to be read-only"), and another that moved the LPAE read-only bit into a software bit,ded947798469("ARM: 8109/1: mm: Modifypte_writeandpmd_writelogic for LPAE").
Quoted 7 lines
Quoted 3 lines
The incorrect mappings were not apparent in the debugfs
kernel_page_tablesdump because that was checking only the software RO bit, not the hardware RO bit.Thanks for catching this! Please consider both patches:
Reviewed-by Kees Cook <[email protected]>
Where are these patches, and why weren't they copied to the arm kernel list?
Signature · 3 lines
RMK's Patch system: http://www.armlinux.org.uk/developer/patches/ FTTC broadband for 0.8mile line in suburbia: sync at 8.8Mbps down 630kbps up According to speedtest.net: 8.21Mbps down 510kbps up
cover STRICT_KERNEL_RWX weakened on ARM by CONFIG_ARM_LPAE=y
Hi Russell,
Quoted 20 lines · Russell King - ARM Linux
Quoted 19 lines · Kees Cook
Quoted 17 lines · Philip Derrin
Hi,
This patch series fixes a bug which makes
CONFIG_STRICT_KERNEL_RWXineffective whenCONFIG_ARM_LPAEis enabled. Specifically, the kernel text and rodata are mapped writeable. This has been the case sinceDEBUG_RODATAfor ARM was first merged in 3.19.The cause was an incorrect conflict resolution in
1e3479225acb("ARM: 8275/1:
mm: fixPMD_SECT_RDONLYundeclared compile error") between the commit that implementedDEBUG_RODATA,80d6b0c2eed2("ARM: mm: allow text and rodata sections to be read-only"), and another that moved the LPAE read-only bit into a software bit,ded947798469("ARM: 8109/1: mm: Modifypte_writeandpmd_writelogic for LPAE").The incorrect mappings were not apparent in the debugfs
kernel_page_tablesdump because that was checking only the software RO bit, not the hardware RO bit.
Quoted 6 lines
Quoted 3 lines
Thanks for catching this! Please consider both patches:
Reviewed-by Kees Cook <[email protected]>Where are these patches, and why weren't they copied to the arm kernel list?
I got the patches from the list.
Cover:
http://lists.infradead.org/pipermail/linux-arm-kernel/2017-November/541532.html
1/2:
http://lists.infradead.org/pipermail/linux-arm-kernel/2017-November/541531.html
2/2:
http://lists.infradead.org/pipermail/linux-arm-kernel/2017-November/541533.html
baruch
Signature · 3 lines
http://baruch.siach.name/blog/ ~. .~ Tk Open Systems
=}------------------------------------------------ooO--U--Ooo------------{=
- baruch at tkos.co.il - tel: +972.52.368.4656, http://www.tkos.co.il -Russell King - ARM Linux
maintainercover STRICT_KERNEL_RWX weakened on ARM by CONFIG_ARM_LPAE=y
Quoted 30 lines · Baruch Siach
Hi Russell,
Quoted 20 lines · Russell King - ARM Linux
Quoted 19 lines · Kees Cook
Quoted 17 lines · Philip Derrin
Hi,
This patch series fixes a bug which makes
CONFIG_STRICT_KERNEL_RWXineffective whenCONFIG_ARM_LPAEis enabled. Specifically, the kernel text and rodata are mapped writeable. This has been the case sinceDEBUG_RODATAfor ARM was first merged in 3.19.The cause was an incorrect conflict resolution in
1e3479225acb("ARM: 8275/1:
mm: fixPMD_SECT_RDONLYundeclared compile error") between the commit that implementedDEBUG_RODATA,80d6b0c2eed2("ARM: mm: allow text and rodata sections to be read-only"), and another that moved the LPAE read-only bit into a software bit,ded947798469("ARM: 8109/1: mm: Modifypte_writeandpmd_writelogic for LPAE").The incorrect mappings were not apparent in the debugfs
kernel_page_tablesdump because that was checking only the software RO bit, not the hardware RO bit.Quoted 6 lines
Quoted 3 lines
Thanks for catching this! Please consider both patches:
Reviewed-by Kees Cook <[email protected]>Where are these patches, and why weren't they copied to the arm kernel list?
Quoted 8 lines
I got the patches from the list.
Cover:
http://lists.infradead.org/pipermail/linux-arm-kernel/2017-November/541532.html
1/2:
http://lists.infradead.org/pipermail/linux-arm-kernel/2017-November/541531.html
2/2:
http://lists.infradead.org/pipermail/linux-arm-kernel/2017-November/541533.html
Ah, dspam decided they were spam, so they ended up in one of my junk mailboxes.
Signature · 3 lines
RMK's Patch system: http://www.armlinux.org.uk/developer/patches/ FTTC broadband for 0.8mile line in suburbia: sync at 8.8Mbps down 630kbps up According to speedtest.net: 8.21Mbps down 510kbps up
cover STRICT_KERNEL_RWX weakened on ARM by CONFIG_ARM_LPAE=y
In reply to Russell King - ARM LinuxQuoted 16 lines · Russell King - ARM Linux
Quoted 15 lines · Kees Cook
Quoted 14 lines · Philip Derrin
Hi,
This patch series fixes a bug which makes
CONFIG_STRICT_KERNEL_RWXineffective whenCONFIG_ARM_LPAEis enabled. Specifically, the kernel text and rodata are mapped writeable. This has been the case sinceDEBUG_RODATAfor ARM was first merged in 3.19.The cause was an incorrect conflict resolution in
1e3479225acb("ARM: 8275/1:
mm: fixPMD_SECT_RDONLYundeclared compile error") between the commit that implementedDEBUG_RODATA,80d6b0c2eed2("ARM: mm: allow text and rodata sections to be read-only"), and another that moved the LPAE read-only bit into a software bit,ded947798469("ARM: 8109/1: mm: Modifypte_writeandpmd_writelogic for LPAE").
Quoted 8 lines
Quoted 6 lines
Quoted 3 lines
The incorrect mappings were not apparent in the debugfs
kernel_page_tablesdump because that was checking only the software RO bit, not the hardware RO bit.Thanks for catching this! Please consider both patches:
Reviewed-by Kees Cook <[email protected]>Where are these patches, and why weren't they copied to the arm kernel list?
I've added these to the patch tracker, as 8721/1 and 8722/1.
Thanks,
Philip
cover STRICT_KERNEL_RWX weakened on ARM by CONFIG_ARM_LPAE=y
In reply to Philip DerrinQuoted 14 lines · Philip Derrin
Hi,
This patch series fixes a bug which makes
CONFIG_STRICT_KERNEL_RWXineffective whenCONFIG_ARM_LPAEis enabled. Specifically, the kernel text and rodata are mapped writeable. This has been the case sinceDEBUG_RODATAfor ARM was first merged in 3.19.The cause was an incorrect conflict resolution in
1e3479225acb("ARM: 8275/1:
mm: fixPMD_SECT_RDONLYundeclared compile error") between the commit that implementedDEBUG_RODATA,80d6b0c2eed2("ARM: mm: allow text and rodata sections to be read-only"), and another that moved the LPAE read-only bit into a software bit,ded947798469("ARM: 8109/1: mm: Modifypte_writeandpmd_writelogic for LPAE").
Quoted 3 lines
The incorrect mappings were not apparent in the debugfs
kernel_page_tablesdump because that was checking only the software RO bit, not the hardware RO bit.
FWIW, on an ARCH_BRCMSTB system with ARM_LPAE=y:
Signature · 1 line
Florian
cover STRICT_KERNEL_RWX weakened on ARM by CONFIG_ARM_LPAE=y
Quoted 15 lines · Florian Fainelli
Quoted 14 lines · Philip Derrin
Hi,
This patch series fixes a bug which makes
CONFIG_STRICT_KERNEL_RWXineffective whenCONFIG_ARM_LPAEis enabled. Specifically, the kernel text and rodata are mapped writeable. This has been the case sinceDEBUG_RODATAfor ARM was first merged in 3.19.The cause was an incorrect conflict resolution in
1e3479225acb("ARM: 8275/1:
mm: fixPMD_SECT_RDONLYundeclared compile error") between the commit that implementedDEBUG_RODATA,80d6b0c2eed2("ARM: mm: allow text and rodata sections to be read-only"), and another that moved the LPAE read-only bit into a software bit,ded947798469("ARM: 8109/1: mm: Modifypte_writeandpmd_writelogic for LPAE").
Quoted 7 lines
Quoted 3 lines
The incorrect mappings were not apparent in the debugfs
kernel_page_tablesdump because that was checking only the software RO bit, not the hardware RO bit.FWIW, on an
ARCH_BRCMSTBsystem with ARM_LPAE=y:Tested-by Florian Fainelli <[email protected]>
Russell, given this fixes an accidentally broken feature, is there any hope for this series to land in v4.15?
Thanks!
-Kees
Signature · 2 lines
Kees Cook Pixel Security