mirror of
git://git.kernel.org/pub/scm/linux/kernel/git/xiang/erofs.git
synced 2026-10-29 13:23:23 +01:00
Patch series "mm: Care about shadow stack guard gap when getting an unmapped area", v2. As covered in the commit log forc44357c2e7("x86/mm: care about shadow stack guard gap during placement") our current mmap() implementation does not take care to ensure that a new mapping isn't placed with existing mappings inside it's own guard gaps. This is particularly important for shadow stacks since if two shadow stacks end up getting placed adjacent to each other then they can overflow into each other which weakens the protection offered by the feature. On x86 there is a custom arch_get_unmapped_area() which was updated by the above commit to cover this case by specifying a start_gap for allocations with VM_SHADOW_STACK. Both arm64 and RISC-V have equivalent features and use the generic implementation of arch_get_unmapped_area() so let's make the equivalent change there so they also don't get shadow stack pages placed without guard pages. The arm64 and RISC-V shadow stack implementations are currently on the list: https://lore.kernel.org/r/20240829-arm64-gcs-v12-0-42fec94743 https://lore.kernel.org/lkml/[email protected]/ Given the addition of the use of vm_flags in the generic implementation we also simplify the set of possibilities that have to be dealt with in the core code by making arch_get_unmapped_area() take vm_flags as standard. This is a bit invasive since the prototype change touches quite a few architectures but since the parameter is ignored the change is straightforward, the simplification for the generic code seems worth it. This patch (of 3): When we introduced arch_get_unmapped_area_vmflags() in961148704a("mm: introduce arch_get_unmapped_area_vmflags()") we did so as part of properly supporting guard pages for shadow stacks on x86_64, which uses a custom arch_get_unmapped_area(). Equivalent features are also present on both arm64 and RISC-V, both of which use the generic implementation of arch_get_unmapped_area() and will require equivalent modification there. Rather than continue to deal with having two versions of the functions let's bite the bullet and have all implementations of arch_get_unmapped_area() take vm_flags as a parameter. The new parameter is currently ignored by all implementations other than x86. The only caller that doesn't have a vm_flags available is mm_get_unmapped_area(), as for the x86 implementation and the wrapper used on other architectures this is modified to supply no flags. No functional changes. Link: https://lkml.kernel.org/r/20240904-mm-generic-shadow-stack-guard-v2-0-a46b8b6dc0ed@kernel.org Link: https://lkml.kernel.org/r/20240904-mm-generic-shadow-stack-guard-v2-1-a46b8b6dc0ed@kernel.org Signed-off-by: Mark Brown <[email protected]> Acked-by: Lorenzo Stoakes <[email protected]> Reviewed-by: Liam R. Howlett <[email protected]> Acked-by: Helge Deller <[email protected]> [parisc] Cc: Alexander Gordeev <[email protected]> Cc: Andreas Larsson <[email protected]> Cc: Borislav Petkov <[email protected]> Cc: Christian Borntraeger <[email protected]> Cc: Christophe Leroy <[email protected]> Cc: Chris Zankel <[email protected]> Cc: Dave Hansen <[email protected]> Cc: David S. Miller <[email protected]> Cc: "Edgecombe, Rick P" <[email protected]> Cc: Gerald Schaefer <[email protected]> Cc: Guo Ren <[email protected]> Cc: Heiko Carstens <[email protected]> Cc: "H. Peter Anvin" <[email protected]> Cc: Huacai Chen <[email protected]> Cc: Ingo Molnar <[email protected]> Cc: Ivan Kokshaysky <[email protected]> Cc: James Bottomley <[email protected]> Cc: John Paul Adrian Glaubitz <[email protected]> Cc: Matt Turner <[email protected]> Cc: Max Filippov <[email protected]> Cc: Michael Ellerman <[email protected]> Cc: Naveen N Rao <[email protected]> Cc: Nicholas Piggin <[email protected]> Cc: Richard Henderson <[email protected]> Cc: Rich Felker <[email protected]> Cc: Russell King <[email protected]> Cc: Sven Schnelle <[email protected]> Cc: Thomas Bogendoerfer <[email protected]> Cc: Thomas Gleixner <[email protected]> Cc: Vasily Gorbik <[email protected]> Cc: Vineet Gupta <[email protected]> Cc: Vlastimil Babka <[email protected]> Cc: WANG Xuerui <[email protected]> Cc: Yoshinori Sato <[email protected]> Signed-off-by: Andrew Morton <[email protected]>
101 lines
2.4 KiB
C
101 lines
2.4 KiB
C
/*
|
|
* arch/xtensa/kernel/syscall.c
|
|
*
|
|
* This file is subject to the terms and conditions of the GNU General Public
|
|
* License. See the file "COPYING" in the main directory of this archive
|
|
* for more details.
|
|
*
|
|
* Copyright (C) 2001 - 2005 Tensilica Inc.
|
|
* Copyright (C) 2000 Silicon Graphics, Inc.
|
|
* Copyright (C) 1995 - 2000 by Ralf Baechle
|
|
*
|
|
* Joe Taylor <[email protected], [email protected]>
|
|
* Marc Gauthier <[email protected], [email protected]>
|
|
* Chris Zankel <[email protected]>
|
|
* Kevin Chea
|
|
*
|
|
*/
|
|
#include <linux/uaccess.h>
|
|
#include <asm/syscall.h>
|
|
#include <linux/linkage.h>
|
|
#include <linux/stringify.h>
|
|
#include <linux/errno.h>
|
|
#include <linux/syscalls.h>
|
|
#include <linux/file.h>
|
|
#include <linux/fs.h>
|
|
#include <linux/mman.h>
|
|
#include <linux/sched/mm.h>
|
|
#include <linux/shm.h>
|
|
|
|
syscall_t sys_call_table[] /* FIXME __cacheline_aligned */= {
|
|
#define __SYSCALL(nr, entry) (syscall_t)entry,
|
|
#include <asm/syscall_table.h>
|
|
};
|
|
|
|
#define COLOUR_ALIGN(addr, pgoff) \
|
|
((((addr) + SHMLBA - 1) & ~(SHMLBA - 1)) + \
|
|
(((pgoff) << PAGE_SHIFT) & (SHMLBA - 1)))
|
|
|
|
asmlinkage long xtensa_shmat(int shmid, char __user *shmaddr, int shmflg)
|
|
{
|
|
unsigned long ret;
|
|
long err;
|
|
|
|
err = do_shmat(shmid, shmaddr, shmflg, &ret, SHMLBA);
|
|
if (err)
|
|
return err;
|
|
return (long)ret;
|
|
}
|
|
|
|
asmlinkage long xtensa_fadvise64_64(int fd, int advice,
|
|
unsigned long long offset, unsigned long long len)
|
|
{
|
|
return ksys_fadvise64_64(fd, offset, len, advice);
|
|
}
|
|
|
|
#ifdef CONFIG_MMU
|
|
unsigned long arch_get_unmapped_area(struct file *filp, unsigned long addr,
|
|
unsigned long len, unsigned long pgoff, unsigned long flags,
|
|
vm_flags_t vm_flags)
|
|
{
|
|
struct vm_area_struct *vmm;
|
|
struct vma_iterator vmi;
|
|
|
|
if (flags & MAP_FIXED) {
|
|
/* We do not accept a shared mapping if it would violate
|
|
* cache aliasing constraints.
|
|
*/
|
|
if ((flags & MAP_SHARED) &&
|
|
((addr - (pgoff << PAGE_SHIFT)) & (SHMLBA - 1)))
|
|
return -EINVAL;
|
|
return addr;
|
|
}
|
|
|
|
if (len > TASK_SIZE)
|
|
return -ENOMEM;
|
|
if (!addr)
|
|
addr = TASK_UNMAPPED_BASE;
|
|
|
|
if (flags & MAP_SHARED)
|
|
addr = COLOUR_ALIGN(addr, pgoff);
|
|
else
|
|
addr = PAGE_ALIGN(addr);
|
|
|
|
vma_iter_init(&vmi, current->mm, addr);
|
|
for_each_vma(vmi, vmm) {
|
|
/* At this point: (addr < vmm->vm_end). */
|
|
if (addr + len <= vm_start_gap(vmm))
|
|
break;
|
|
|
|
addr = vmm->vm_end;
|
|
if (flags & MAP_SHARED)
|
|
addr = COLOUR_ALIGN(addr, pgoff);
|
|
}
|
|
|
|
if (TASK_SIZE - len < addr)
|
|
return -ENOMEM;
|
|
|
|
return addr;
|
|
}
|
|
#endif
|