Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

um: Fix pte_read() and pte_exec() for kernel mappings

The pte_read() and pte_exec() helpers are only used during the TLB
sync to determine the read/exec permissions for mmap. However, for
kernel mappings, they will always return 0. This leads to kern_map()
having to unconditionally set the exec flag to 1 and the read flag
unexpectedly always being 0. Remove the unnecessary check for the
_PAGE_USER bit in these helpers to ensure that the kernel mapping
permissions can be correctly determined.

Signed-off-by: Tiwei Bie <tiwei.btw@antgroup.com>
Link: https://patch.msgid.link/20260302235224.1915380-3-tiwei.btw@antgroup.com
Signed-off-by: Johannes Berg <johannes.berg@intel.com>

authored by

Tiwei Bie and committed by
Johannes Berg
cd4126d4 102331b6

+5 -7
+4 -5
arch/um/include/asm/pgtable.h
··· 121 121 */ 122 122 static inline int pte_read(pte_t pte) 123 123 { 124 - return((pte_get_bits(pte, _PAGE_USER)) && 125 - !(pte_get_bits(pte, _PAGE_PROTNONE))); 124 + return !pte_get_bits(pte, _PAGE_PROTNONE); 126 125 } 127 126 128 - static inline int pte_exec(pte_t pte){ 129 - return((pte_get_bits(pte, _PAGE_USER)) && 130 - !(pte_get_bits(pte, _PAGE_PROTNONE))); 127 + static inline int pte_exec(pte_t pte) 128 + { 129 + return !pte_get_bits(pte, _PAGE_PROTNONE); 131 130 } 132 131 133 132 static inline int pte_write(pte_t pte)
+1 -2
arch/um/kernel/tlb.c
··· 29 29 unsigned long virt, unsigned long len, int prot, 30 30 int phys_fd, unsigned long long offset) 31 31 { 32 - /* TODO: Why is executable needed to be always set in the kernel? */ 33 32 return os_map_memory((void *)virt, phys_fd, offset, len, 34 33 prot & UM_PROT_READ, prot & UM_PROT_WRITE, 35 - 1); 34 + prot & UM_PROT_EXEC); 36 35 } 37 36 38 37 static int kern_unmap(struct mm_id *mm_idp,