arm64: mte: Do not allow PROT_MTE on MAP_HUGETLB user mappings
PATCH 1/1 arm64: mte: Do not allow PROT_MTE on MAP_HUGETLB user mappings
PROT_MTE (memory tagging extensions) is not supported on all user mmap() types for various reasons (memory attributes, backing storage, CoW handling). The arm64 arch_validate_flags() function checks whether the VM_MTE_ALLOWED flag has been set for a vma during mmap(), usually by arch_calc_vm_flag_bits().
Linux prior to 6.13 does not support PROT_MTE hugetlb mappings. This was added by commit 25c17c4b55de ("hugetlb: arm64: add mte support"). However, earlier kernels inadvertently set VM_MTE_ALLOWED on (MAP_ANONYMOUS | MAP_HUGETLB) mappings by only checking for MAP_ANONYMOUS.
Explicitly check MAP_HUGETLB in arch_calc_vm_flag_bits() and avoid setting VM_MTE_ALLOWED for such mappings.
---
Hi Greg,
This patch applies cleanly on top of the stable-rc/linux-6.12.y to 5.10.y LTS, so I'm only sending it once. It's not for 6.13 onwards since those kernels support hugetlbfs with MTE.
Thanks,
Catalin
arch/arm64/include/asm/mman.h | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-)
arch/arm64/include/asm/mman.h +6 -3
@@ -41,9 +41,12 @@ static inline unsigned long arch_calc_vm_flag_bits(struct file *file,* backed by tags-capable memory. The vm_flags may be overridden by a * filesystem supporting MTE (RAM-based). */ -if (system_supports_mte () && - ((flags &MAP_ANONYMOUS ) ||shmem_file (file))) -return VM_MTE_ALLOWED ; +if (system_supports_mte ()) { +if ((flags &MAP_ANONYMOUS ) && !(flags &MAP_HUGETLB )) +return VM_MTE_ALLOWED ; +if (shmem_file (file)) +return VM_MTE_ALLOWED ; + }return 0 ; }
Greg Kroah-Hartman
maintainerQuoted 19 lines · Catalin Marinas
PROT_MTE(memory tagging extensions) is not supported on all usermmap()types for various reasons (memory attributes, backing storage, CoW handling). The arm64arch_validate_flags()function checks whether theVM_MTE_ALLOWEDflag has been set for a vma duringmmap(), usually byarch_calc_vm_flag_bits().Linux prior to 6.13 does not support
PROT_MTEhugetlb mappings. This was added by commit25c17c4b55de("hugetlb: arm64: add mte support"). However, earlier kernels inadvertently setVM_MTE_ALLOWEDon (MAP_ANONYMOUS|MAP_HUGETLB) mappings by only checking forMAP_ANONYMOUS.Explicitly check
MAP_HUGETLBinarch_calc_vm_flag_bits()and avoid settingVM_MTE_ALLOWEDfor such mappings.Fixes 9f3419315f3c ("arm64: mte: Add PROT_MTE support to mmap() and mprotect()")Cc <[email protected]> # 5.10.x-6.12.xReported-by Naresh Kamboju <[email protected]>Signed-off-by Catalin Marinas <[email protected]>
Quoted 7 lines
---
Hi Greg,
This patch applies cleanly on top of the stable-rc/linux-6.12.y to 5.10.y LTS, so I'm only sending it once. It's not for 6.13 onwards since those kernels support hugetlbfs with MTE.
Thanks for this, I'll queue it up after the next round of releases.
greg k-h
Sasha Levin
maintainer[ Sasha's backport helper bot ]
Hi,
Summary of potential issues:
⚠️ Could not find matching upstream commit
No upstream commit was identified. Using temporary commit for testing.
Results of testing on various branches:
| Branch | Patch Apply | Build Test | |---------------------------|-------------|------------| | stable/linux-6.12.y | Success | Success | | stable/linux-5.10.y | Success | Success |
Greg Kroah-Hartman
maintainerQuoted 19 lines · Catalin Marinas
PROT_MTE(memory tagging extensions) is not supported on all usermmap()types for various reasons (memory attributes, backing storage, CoW handling). The arm64arch_validate_flags()function checks whether theVM_MTE_ALLOWEDflag has been set for a vma duringmmap(), usually byarch_calc_vm_flag_bits().Linux prior to 6.13 does not support
PROT_MTEhugetlb mappings. This was added by commit25c17c4b55de("hugetlb: arm64: add mte support"). However, earlier kernels inadvertently setVM_MTE_ALLOWEDon (MAP_ANONYMOUS|MAP_HUGETLB) mappings by only checking forMAP_ANONYMOUS.Explicitly check
MAP_HUGETLBinarch_calc_vm_flag_bits()and avoid settingVM_MTE_ALLOWEDfor such mappings.Fixes 9f3419315f3c ("arm64: mte: Add PROT_MTE support to mmap() and mprotect()")Cc <[email protected]> # 5.10.x-6.12.xReported-by Naresh Kamboju <[email protected]>Signed-off-by Catalin Marinas <[email protected]>
Quoted 7 lines
---
Hi Greg,
This patch applies cleanly on top of the stable-rc/linux-6.12.y to 5.10.y LTS, so I'm only sending it once. It's not for 6.13 onwards since those kernels support hugetlbfs with MTE.
Now queued up,t hanks.
greg k-h
Quoted 22 lines · Greg Kroah-Hartman
Quoted 21 lines · Catalin Marinas
PROT_MTE(memory tagging extensions) is not supported on all usermmap()types for various reasons (memory attributes, backing storage, CoW handling). The arm64arch_validate_flags()function checks whether theVM_MTE_ALLOWEDflag has been set for a vma duringmmap(), usually byarch_calc_vm_flag_bits().Linux prior to 6.13 does not support
PROT_MTEhugetlb mappings. This was added by commit25c17c4b55de("hugetlb: arm64: add mte support"). However, earlier kernels inadvertently setVM_MTE_ALLOWEDon (MAP_ANONYMOUS|MAP_HUGETLB) mappings by only checking forMAP_ANONYMOUS.Explicitly check
MAP_HUGETLBinarch_calc_vm_flag_bits()and avoid settingVM_MTE_ALLOWEDfor such mappings.Fixes 9f3419315f3c ("arm64: mte: Add PROT_MTE support to mmap() and mprotect()")Cc <[email protected]> # 5.10.x-6.12.xReported-by Naresh Kamboju <[email protected]>Signed-off-by Catalin Marinas <[email protected]>---
Quoted 7 lines
Quoted 5 lines
Hi Greg,
This patch applies cleanly on top of the stable-rc/linux-6.12.y to 5.10.y LTS, so I'm only sending it once. It's not for 6.13 onwards since those kernels support hugetlbfs with MTE.
Now queued up, thanks.
Thanks Greg.
Signature · 1 line
Catalin