linux/arch/parisc
John David Anglin 9b2f4e7385 parisc: Update comments in make_insert_tlb
commit cb22f247f3 upstream.

The following testcase exposed a problem with our read access checks
in get_user() and raw_copy_from_user():

#include <stdint.h>
#include <stddef.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
#include <errno.h>
#include <sys/mman.h>
#include <sys/types.h>

int main(int argc, char **argv)
{
  unsigned long page_size = sysconf(_SC_PAGESIZE);
  char *p = malloc(3 * page_size);
  char *p_aligned;

  /* initialize memory region. If not initialized, write syscall below will correctly return EFAULT. */
  if (1)
	memset(p, 'X', 3 * page_size);

  p_aligned = (char *) ((((uintptr_t) p) + (2*page_size - 1)) & ~(page_size - 1));
  /* Drop PROT_READ protection. Kernel and userspace should fault when accessing that memory region */
  mprotect(p_aligned, page_size, PROT_NONE);

  /* the following write() should return EFAULT, since PROT_READ was dropped by previous mprotect() */
  int ret = write(2, p_aligned, 1);
  if (!ret || errno != EFAULT)
	printf("\n FAILURE: write() did not returned expected EFAULT value\n");

  return 0;
}

Because of the way _PAGE_READ is handled, kernel code never generates
a read access fault when it access a page as the kernel privilege level
is always less than PL1 in the PTE.

This patch reworks the comments in the make_insert_tlb macro to try
to make this clearer.

Signed-off-by: John David Anglin <dave.anglin@bell.net>
Signed-off-by: Helge Deller <deller@gmx.de>
Cc: stable@vger.kernel.org # v5.12+
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
History 2025-08-28 16:26:08 +02:00
..
boot parisc: fix building with gcc-15 2025-06-27 11:07:29 +01:00
configs parisc: Update 32- and 64-bit defconfigs 2022-05-08 20:01:11 +02:00
include parisc: Revise __get_user() to probe user read access 2025-08-28 16:26:08 +02:00
kernel parisc: Update comments in make_insert_tlb 2025-08-28 16:26:08 +02:00
lib parisc: Check region is readable by user in raw_copy_from_user() 2025-08-28 16:26:08 +02:00
math-emu parisc: Fix double SIGFPE crash 2025-05-09 09:41:34 +02:00
mm parisc: Try to fixup kernel exception in bad_area_nosemaphore path of do_page_fault() 2025-08-28 16:26:08 +02:00
defpalo.conf parisc: switch to gzip-compressed vmlinuz kernel 2013-07-09 22:09:20 +02:00
install.sh kbuild: factor out the common installation code into scripts/install.sh 2022-05-11 21:45:53 +09:00
Kbuild kbuild: use more subdir- for visiting subdirectories while cleaning 2021-10-24 13:49:46 +09:00
Kconfig parisc: fix a possible DMA corruption 2024-11-22 15:37:35 +01:00
Kconfig.debug tracing: Refactor TRACE_IRQFLAGS_SUPPORT in Kconfig 2021-08-16 11:37:21 -04:00
Makefile parisc: Makefile: explain that 64BIT requires both 32-bit and 64-bit compilers 2025-08-28 16:26:08 +02:00