2019-05-27 14:55:05 +08:00
|
|
|
// SPDX-License-Identifier: GPL-2.0-or-later
|
2005-04-17 06:20:36 +08:00
|
|
|
|
|
|
|
/*
|
|
|
|
* PARISC specific syscalls
|
|
|
|
*
|
|
|
|
* Copyright (C) 1999-2003 Matthew Wilcox <willy at parisc-linux.org>
|
|
|
|
* Copyright (C) 2000-2003 Paul Bame <bame at parisc-linux.org>
|
|
|
|
* Copyright (C) 2001 Thomas Bogendoerfer <tsbogend at parisc-linux.org>
|
2020-10-23 00:40:07 +08:00
|
|
|
* Copyright (C) 1999-2020 Helge Deller <deller@gmx.de>
|
2005-04-17 06:20:36 +08:00
|
|
|
*/
|
|
|
|
|
2016-12-25 03:46:01 +08:00
|
|
|
#include <linux/uaccess.h>
|
2014-02-01 05:19:52 +08:00
|
|
|
#include <asm/elf.h>
|
2005-04-17 06:20:36 +08:00
|
|
|
#include <linux/file.h>
|
|
|
|
#include <linux/fs.h>
|
|
|
|
#include <linux/linkage.h>
|
|
|
|
#include <linux/mm.h>
|
|
|
|
#include <linux/mman.h>
|
2017-02-09 01:51:30 +08:00
|
|
|
#include <linux/sched/signal.h>
|
2017-02-09 01:51:31 +08:00
|
|
|
#include <linux/sched/mm.h>
|
2005-04-17 06:20:36 +08:00
|
|
|
#include <linux/shm.h>
|
|
|
|
#include <linux/syscalls.h>
|
2006-08-27 23:12:13 +08:00
|
|
|
#include <linux/utsname.h>
|
|
|
|
#include <linux/personality.h>
|
2014-02-01 05:19:52 +08:00
|
|
|
#include <linux/random.h>
|
2020-10-23 00:40:07 +08:00
|
|
|
#include <linux/compat.h>
|
2023-06-30 18:36:09 +08:00
|
|
|
#include <linux/elf-randomize.h>
|
2005-04-17 06:20:36 +08:00
|
|
|
|
2023-02-27 02:03:33 +08:00
|
|
|
/*
|
2023-07-21 23:24:31 +08:00
|
|
|
* Construct an artificial page offset for the mapping based on the virtual
|
2023-02-27 02:03:33 +08:00
|
|
|
* address of the kernel file mapping variable.
|
2023-07-21 23:24:31 +08:00
|
|
|
* If filp is zero the calculated pgoff value aliases the memory of the given
|
|
|
|
* address. This is useful for io_uring where the mapping shall alias a kernel
|
|
|
|
* address and a userspace adress where both the kernel and the userspace
|
|
|
|
* access the same memory region.
|
2023-02-27 02:03:33 +08:00
|
|
|
*/
|
2023-07-21 23:24:31 +08:00
|
|
|
#define GET_FILP_PGOFF(filp, addr) \
|
|
|
|
((filp ? (((unsigned long) filp->f_mapping) >> 8) \
|
|
|
|
& ((SHM_COLOUR-1) >> PAGE_SHIFT) : 0UL) \
|
|
|
|
+ (addr >> PAGE_SHIFT))
|
2005-04-17 06:20:36 +08:00
|
|
|
|
2023-02-27 02:03:33 +08:00
|
|
|
static unsigned long shared_align_offset(unsigned long filp_pgoff,
|
2014-02-01 05:19:52 +08:00
|
|
|
unsigned long pgoff)
|
|
|
|
{
|
2023-02-27 02:03:33 +08:00
|
|
|
return (filp_pgoff + pgoff) << PAGE_SHIFT;
|
2005-04-17 06:20:36 +08:00
|
|
|
}
|
|
|
|
|
2014-02-01 05:19:52 +08:00
|
|
|
static inline unsigned long COLOR_ALIGN(unsigned long addr,
|
2023-02-27 02:03:33 +08:00
|
|
|
unsigned long filp_pgoff, unsigned long pgoff)
|
2005-04-17 06:20:36 +08:00
|
|
|
{
|
2014-04-10 01:49:28 +08:00
|
|
|
unsigned long base = (addr+SHM_COLOUR-1) & ~(SHM_COLOUR-1);
|
|
|
|
unsigned long off = (SHM_COLOUR-1) &
|
2023-02-27 02:03:33 +08:00
|
|
|
shared_align_offset(filp_pgoff, pgoff);
|
2014-02-01 05:19:52 +08:00
|
|
|
return base + off;
|
2005-04-17 06:20:36 +08:00
|
|
|
}
|
|
|
|
|
2020-11-07 02:41:36 +08:00
|
|
|
|
|
|
|
#define STACK_SIZE_DEFAULT (USER_WIDE_MODE \
|
|
|
|
? (1 << 30) /* 1 GB */ \
|
|
|
|
: (CONFIG_STACK_MAX_DEFAULT_SIZE_MB*1024*1024))
|
|
|
|
|
|
|
|
unsigned long calc_max_stack_size(unsigned long stack_max)
|
|
|
|
{
|
|
|
|
#ifdef CONFIG_COMPAT
|
|
|
|
if (!USER_WIDE_MODE && (stack_max == COMPAT_RLIM_INFINITY))
|
|
|
|
stack_max = STACK_SIZE_DEFAULT;
|
|
|
|
else
|
|
|
|
#endif
|
|
|
|
if (stack_max == RLIM_INFINITY)
|
|
|
|
stack_max = STACK_SIZE_DEFAULT;
|
|
|
|
|
|
|
|
return stack_max;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2014-02-01 05:19:52 +08:00
|
|
|
/*
|
|
|
|
* Top of mmap area (just below the process stack).
|
|
|
|
*/
|
|
|
|
|
2018-04-11 07:34:53 +08:00
|
|
|
/*
|
|
|
|
* When called from arch_get_unmapped_area(), rlim_stack will be NULL,
|
|
|
|
* indicating that "current" should be used instead of a passed-in
|
|
|
|
* value from the exec bprm as done with arch_pick_mmap_layout().
|
|
|
|
*/
|
|
|
|
static unsigned long mmap_upper_limit(struct rlimit *rlim_stack)
|
parisc: fix mmap(MAP_FIXED|MAP_SHARED) to already mmapped address
locale-gen on Debian showed a strange problem on parisc:
mmap2(NULL, 536870912, PROT_NONE, MAP_SHARED, 3, 0) = 0x42a54000
mmap2(0x42a54000, 103860, PROT_READ|PROT_WRITE, MAP_SHARED|MAP_FIXED, 3, 0) = -1 EINVAL (Invalid argument)
Basically it was just trying to re-mmap() a file at the same address
which it was given by a previous mmap() call. But this remapping failed
with EINVAL.
The problem is, that when MAP_FIXED and MAP_SHARED flags were used, we didn't
included the mapping-based offset when we verified the alignment of the given
fixed address against the offset which we calculated it in the previous call.
Signed-off-by: Helge Deller <deller@gmx.de>
Cc: <stable@vger.kernel.org> # 3.10+
2013-11-21 06:07:42 +08:00
|
|
|
{
|
2014-02-01 05:19:52 +08:00
|
|
|
unsigned long stack_base;
|
parisc: fix mmap(MAP_FIXED|MAP_SHARED) to already mmapped address
locale-gen on Debian showed a strange problem on parisc:
mmap2(NULL, 536870912, PROT_NONE, MAP_SHARED, 3, 0) = 0x42a54000
mmap2(0x42a54000, 103860, PROT_READ|PROT_WRITE, MAP_SHARED|MAP_FIXED, 3, 0) = -1 EINVAL (Invalid argument)
Basically it was just trying to re-mmap() a file at the same address
which it was given by a previous mmap() call. But this remapping failed
with EINVAL.
The problem is, that when MAP_FIXED and MAP_SHARED flags were used, we didn't
included the mapping-based offset when we verified the alignment of the given
fixed address against the offset which we calculated it in the previous call.
Signed-off-by: Helge Deller <deller@gmx.de>
Cc: <stable@vger.kernel.org> # 3.10+
2013-11-21 06:07:42 +08:00
|
|
|
|
2014-05-01 05:26:02 +08:00
|
|
|
/* Limit stack size - see setup_arg_pages() in fs/exec.c */
|
2018-04-11 07:34:53 +08:00
|
|
|
stack_base = rlim_stack ? rlim_stack->rlim_max
|
|
|
|
: rlimit_max(RLIMIT_STACK);
|
2020-11-07 02:41:36 +08:00
|
|
|
|
|
|
|
stack_base = calc_max_stack_size(stack_base);
|
2014-02-01 05:19:52 +08:00
|
|
|
|
2015-05-12 04:01:27 +08:00
|
|
|
/* Add space for stack randomization. */
|
2019-04-04 14:26:22 +08:00
|
|
|
if (current->flags & PF_RANDOMIZE)
|
|
|
|
stack_base += (STACK_RND_MASK << PAGE_SHIFT);
|
2015-05-12 04:01:27 +08:00
|
|
|
|
2014-02-01 05:19:52 +08:00
|
|
|
return PAGE_ALIGN(STACK_TOP - stack_base);
|
parisc: fix mmap(MAP_FIXED|MAP_SHARED) to already mmapped address
locale-gen on Debian showed a strange problem on parisc:
mmap2(NULL, 536870912, PROT_NONE, MAP_SHARED, 3, 0) = 0x42a54000
mmap2(0x42a54000, 103860, PROT_READ|PROT_WRITE, MAP_SHARED|MAP_FIXED, 3, 0) = -1 EINVAL (Invalid argument)
Basically it was just trying to re-mmap() a file at the same address
which it was given by a previous mmap() call. But this remapping failed
with EINVAL.
The problem is, that when MAP_FIXED and MAP_SHARED flags were used, we didn't
included the mapping-based offset when we verified the alignment of the given
fixed address against the offset which we calculated it in the previous call.
Signed-off-by: Helge Deller <deller@gmx.de>
Cc: <stable@vger.kernel.org> # 3.10+
2013-11-21 06:07:42 +08:00
|
|
|
}
|
|
|
|
|
2023-02-27 02:03:33 +08:00
|
|
|
enum mmap_allocation_direction {UP, DOWN};
|
2014-02-01 05:19:52 +08:00
|
|
|
|
2023-02-27 02:03:33 +08:00
|
|
|
static unsigned long arch_get_unmapped_area_common(struct file *filp,
|
|
|
|
unsigned long addr, unsigned long len, unsigned long pgoff,
|
|
|
|
unsigned long flags, enum mmap_allocation_direction dir)
|
2005-04-17 06:20:36 +08:00
|
|
|
{
|
2014-02-01 05:19:52 +08:00
|
|
|
struct mm_struct *mm = current->mm;
|
mm: larger stack guard gap, between vmas
Stack guard page is a useful feature to reduce a risk of stack smashing
into a different mapping. We have been using a single page gap which
is sufficient to prevent having stack adjacent to a different mapping.
But this seems to be insufficient in the light of the stack usage in
userspace. E.g. glibc uses as large as 64kB alloca() in many commonly
used functions. Others use constructs liks gid_t buffer[NGROUPS_MAX]
which is 256kB or stack strings with MAX_ARG_STRLEN.
This will become especially dangerous for suid binaries and the default
no limit for the stack size limit because those applications can be
tricked to consume a large portion of the stack and a single glibc call
could jump over the guard page. These attacks are not theoretical,
unfortunatelly.
Make those attacks less probable by increasing the stack guard gap
to 1MB (on systems with 4k pages; but make it depend on the page size
because systems with larger base pages might cap stack allocations in
the PAGE_SIZE units) which should cover larger alloca() and VLA stack
allocations. It is obviously not a full fix because the problem is
somehow inherent, but it should reduce attack space a lot.
One could argue that the gap size should be configurable from userspace,
but that can be done later when somebody finds that the new 1MB is wrong
for some special case applications. For now, add a kernel command line
option (stack_guard_gap) to specify the stack gap size (in page units).
Implementation wise, first delete all the old code for stack guard page:
because although we could get away with accounting one extra page in a
stack vma, accounting a larger gap can break userspace - case in point,
a program run with "ulimit -S -v 20000" failed when the 1MB gap was
counted for RLIMIT_AS; similar problems could come with RLIMIT_MLOCK
and strict non-overcommit mode.
Instead of keeping gap inside the stack vma, maintain the stack guard
gap as a gap between vmas: using vm_start_gap() in place of vm_start
(or vm_end_gap() in place of vm_end if VM_GROWSUP) in just those few
places which need to respect the gap - mainly arch_get_unmapped_area(),
and and the vma tree's subtree_gap support for that.
Original-patch-by: Oleg Nesterov <oleg@redhat.com>
Original-patch-by: Michal Hocko <mhocko@suse.com>
Signed-off-by: Hugh Dickins <hughd@google.com>
Acked-by: Michal Hocko <mhocko@suse.com>
Tested-by: Helge Deller <deller@gmx.de> # parisc
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
2017-06-19 19:03:24 +08:00
|
|
|
struct vm_area_struct *vma, *prev;
|
2023-02-27 02:03:33 +08:00
|
|
|
unsigned long filp_pgoff;
|
|
|
|
int do_color_align;
|
2013-02-28 09:02:40 +08:00
|
|
|
struct vm_unmapped_area_info info;
|
2005-04-17 06:20:36 +08:00
|
|
|
|
2023-02-27 02:03:33 +08:00
|
|
|
if (unlikely(len > TASK_SIZE))
|
2014-02-01 05:19:52 +08:00
|
|
|
return -ENOMEM;
|
|
|
|
|
|
|
|
do_color_align = 0;
|
|
|
|
if (filp || (flags & MAP_SHARED))
|
|
|
|
do_color_align = 1;
|
2023-07-21 23:24:31 +08:00
|
|
|
filp_pgoff = GET_FILP_PGOFF(filp, addr);
|
2014-02-01 05:19:52 +08:00
|
|
|
|
|
|
|
if (flags & MAP_FIXED) {
|
2023-02-27 02:03:33 +08:00
|
|
|
/* Even MAP_FIXED mappings must reside within TASK_SIZE */
|
|
|
|
if (TASK_SIZE - len < addr)
|
|
|
|
return -EINVAL;
|
|
|
|
|
|
|
|
if ((flags & MAP_SHARED) && filp &&
|
|
|
|
(addr - shared_align_offset(filp_pgoff, pgoff))
|
2014-04-10 01:49:28 +08:00
|
|
|
& (SHM_COLOUR - 1))
|
2014-02-01 05:19:52 +08:00
|
|
|
return -EINVAL;
|
2023-02-27 02:03:33 +08:00
|
|
|
return addr;
|
2014-02-01 05:19:52 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
if (addr) {
|
2023-02-27 02:03:33 +08:00
|
|
|
if (do_color_align)
|
|
|
|
addr = COLOR_ALIGN(addr, filp_pgoff, pgoff);
|
2014-02-01 05:19:52 +08:00
|
|
|
else
|
|
|
|
addr = PAGE_ALIGN(addr);
|
|
|
|
|
mm: larger stack guard gap, between vmas
Stack guard page is a useful feature to reduce a risk of stack smashing
into a different mapping. We have been using a single page gap which
is sufficient to prevent having stack adjacent to a different mapping.
But this seems to be insufficient in the light of the stack usage in
userspace. E.g. glibc uses as large as 64kB alloca() in many commonly
used functions. Others use constructs liks gid_t buffer[NGROUPS_MAX]
which is 256kB or stack strings with MAX_ARG_STRLEN.
This will become especially dangerous for suid binaries and the default
no limit for the stack size limit because those applications can be
tricked to consume a large portion of the stack and a single glibc call
could jump over the guard page. These attacks are not theoretical,
unfortunatelly.
Make those attacks less probable by increasing the stack guard gap
to 1MB (on systems with 4k pages; but make it depend on the page size
because systems with larger base pages might cap stack allocations in
the PAGE_SIZE units) which should cover larger alloca() and VLA stack
allocations. It is obviously not a full fix because the problem is
somehow inherent, but it should reduce attack space a lot.
One could argue that the gap size should be configurable from userspace,
but that can be done later when somebody finds that the new 1MB is wrong
for some special case applications. For now, add a kernel command line
option (stack_guard_gap) to specify the stack gap size (in page units).
Implementation wise, first delete all the old code for stack guard page:
because although we could get away with accounting one extra page in a
stack vma, accounting a larger gap can break userspace - case in point,
a program run with "ulimit -S -v 20000" failed when the 1MB gap was
counted for RLIMIT_AS; similar problems could come with RLIMIT_MLOCK
and strict non-overcommit mode.
Instead of keeping gap inside the stack vma, maintain the stack guard
gap as a gap between vmas: using vm_start_gap() in place of vm_start
(or vm_end_gap() in place of vm_end if VM_GROWSUP) in just those few
places which need to respect the gap - mainly arch_get_unmapped_area(),
and and the vma tree's subtree_gap support for that.
Original-patch-by: Oleg Nesterov <oleg@redhat.com>
Original-patch-by: Michal Hocko <mhocko@suse.com>
Signed-off-by: Hugh Dickins <hughd@google.com>
Acked-by: Michal Hocko <mhocko@suse.com>
Tested-by: Helge Deller <deller@gmx.de> # parisc
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
2017-06-19 19:03:24 +08:00
|
|
|
vma = find_vma_prev(mm, addr, &prev);
|
2023-02-27 02:03:33 +08:00
|
|
|
if (TASK_SIZE - len >= addr &&
|
mm: larger stack guard gap, between vmas
Stack guard page is a useful feature to reduce a risk of stack smashing
into a different mapping. We have been using a single page gap which
is sufficient to prevent having stack adjacent to a different mapping.
But this seems to be insufficient in the light of the stack usage in
userspace. E.g. glibc uses as large as 64kB alloca() in many commonly
used functions. Others use constructs liks gid_t buffer[NGROUPS_MAX]
which is 256kB or stack strings with MAX_ARG_STRLEN.
This will become especially dangerous for suid binaries and the default
no limit for the stack size limit because those applications can be
tricked to consume a large portion of the stack and a single glibc call
could jump over the guard page. These attacks are not theoretical,
unfortunatelly.
Make those attacks less probable by increasing the stack guard gap
to 1MB (on systems with 4k pages; but make it depend on the page size
because systems with larger base pages might cap stack allocations in
the PAGE_SIZE units) which should cover larger alloca() and VLA stack
allocations. It is obviously not a full fix because the problem is
somehow inherent, but it should reduce attack space a lot.
One could argue that the gap size should be configurable from userspace,
but that can be done later when somebody finds that the new 1MB is wrong
for some special case applications. For now, add a kernel command line
option (stack_guard_gap) to specify the stack gap size (in page units).
Implementation wise, first delete all the old code for stack guard page:
because although we could get away with accounting one extra page in a
stack vma, accounting a larger gap can break userspace - case in point,
a program run with "ulimit -S -v 20000" failed when the 1MB gap was
counted for RLIMIT_AS; similar problems could come with RLIMIT_MLOCK
and strict non-overcommit mode.
Instead of keeping gap inside the stack vma, maintain the stack guard
gap as a gap between vmas: using vm_start_gap() in place of vm_start
(or vm_end_gap() in place of vm_end if VM_GROWSUP) in just those few
places which need to respect the gap - mainly arch_get_unmapped_area(),
and and the vma tree's subtree_gap support for that.
Original-patch-by: Oleg Nesterov <oleg@redhat.com>
Original-patch-by: Michal Hocko <mhocko@suse.com>
Signed-off-by: Hugh Dickins <hughd@google.com>
Acked-by: Michal Hocko <mhocko@suse.com>
Tested-by: Helge Deller <deller@gmx.de> # parisc
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
2017-06-19 19:03:24 +08:00
|
|
|
(!vma || addr + len <= vm_start_gap(vma)) &&
|
|
|
|
(!prev || addr >= vm_end_gap(prev)))
|
2023-02-27 02:03:33 +08:00
|
|
|
return addr;
|
2014-02-01 05:19:52 +08:00
|
|
|
}
|
|
|
|
|
2013-02-28 09:02:40 +08:00
|
|
|
info.length = len;
|
2023-02-27 02:03:33 +08:00
|
|
|
info.align_mask = do_color_align ? (PAGE_MASK & (SHM_COLOUR - 1)) : 0;
|
|
|
|
info.align_offset = shared_align_offset(filp_pgoff, pgoff);
|
|
|
|
|
|
|
|
if (dir == DOWN) {
|
|
|
|
info.flags = VM_UNMAPPED_AREA_TOPDOWN;
|
|
|
|
info.low_limit = PAGE_SIZE;
|
|
|
|
info.high_limit = mm->mmap_base;
|
|
|
|
addr = vm_unmapped_area(&info);
|
|
|
|
if (!(addr & ~PAGE_MASK))
|
|
|
|
return addr;
|
|
|
|
VM_BUG_ON(addr != -ENOMEM);
|
|
|
|
|
|
|
|
/*
|
|
|
|
* A failed mmap() very likely causes application failure,
|
|
|
|
* so fall back to the bottom-up function here. This scenario
|
|
|
|
* can happen with large stack limits and large mmap()
|
|
|
|
* allocations.
|
|
|
|
*/
|
|
|
|
}
|
|
|
|
|
|
|
|
info.flags = 0;
|
2014-02-01 05:19:52 +08:00
|
|
|
info.low_limit = mm->mmap_legacy_base;
|
2018-04-11 07:34:53 +08:00
|
|
|
info.high_limit = mmap_upper_limit(NULL);
|
2023-02-27 02:03:33 +08:00
|
|
|
return vm_unmapped_area(&info);
|
2005-04-17 06:20:36 +08:00
|
|
|
}
|
|
|
|
|
2023-02-27 02:03:33 +08:00
|
|
|
unsigned long arch_get_unmapped_area(struct file *filp, unsigned long addr,
|
|
|
|
unsigned long len, unsigned long pgoff, unsigned long flags)
|
2005-04-17 06:20:36 +08:00
|
|
|
{
|
2023-02-27 02:03:33 +08:00
|
|
|
return arch_get_unmapped_area_common(filp,
|
|
|
|
addr, len, pgoff, flags, UP);
|
|
|
|
}
|
2014-02-01 05:19:52 +08:00
|
|
|
|
2023-02-27 02:03:33 +08:00
|
|
|
unsigned long arch_get_unmapped_area_topdown(struct file *filp,
|
|
|
|
unsigned long addr, unsigned long len, unsigned long pgoff,
|
|
|
|
unsigned long flags)
|
|
|
|
{
|
|
|
|
return arch_get_unmapped_area_common(filp,
|
|
|
|
addr, len, pgoff, flags, DOWN);
|
2005-04-17 06:20:36 +08:00
|
|
|
}
|
|
|
|
|
2014-02-01 05:19:52 +08:00
|
|
|
static int mmap_is_legacy(void)
|
|
|
|
{
|
|
|
|
if (current->personality & ADDR_COMPAT_LAYOUT)
|
|
|
|
return 1;
|
|
|
|
|
|
|
|
/* parisc stack always grows up - so a unlimited stack should
|
|
|
|
* not be an indicator to use the legacy memory layout.
|
|
|
|
* if (rlimit(RLIMIT_STACK) == RLIM_INFINITY)
|
|
|
|
* return 1;
|
|
|
|
*/
|
|
|
|
|
|
|
|
return sysctl_legacy_va_layout;
|
|
|
|
}
|
|
|
|
|
|
|
|
static unsigned long mmap_rnd(void)
|
|
|
|
{
|
|
|
|
unsigned long rnd = 0;
|
|
|
|
|
2016-10-16 06:02:27 +08:00
|
|
|
if (current->flags & PF_RANDOMIZE)
|
2022-10-05 23:43:22 +08:00
|
|
|
rnd = get_random_u32() & MMAP_RND_MASK;
|
2016-10-16 06:02:27 +08:00
|
|
|
|
2014-02-01 05:19:52 +08:00
|
|
|
return rnd << PAGE_SHIFT;
|
|
|
|
}
|
|
|
|
|
2016-10-16 06:02:27 +08:00
|
|
|
unsigned long arch_mmap_rnd(void)
|
|
|
|
{
|
2022-10-05 23:43:22 +08:00
|
|
|
return (get_random_u32() & MMAP_RND_MASK) << PAGE_SHIFT;
|
2016-10-16 06:02:27 +08:00
|
|
|
}
|
|
|
|
|
2014-02-01 05:19:52 +08:00
|
|
|
static unsigned long mmap_legacy_base(void)
|
|
|
|
{
|
|
|
|
return TASK_UNMAPPED_BASE + mmap_rnd();
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* This function, called very early during the creation of a new
|
|
|
|
* process VM image, sets up which VM layout function to use:
|
|
|
|
*/
|
2018-04-11 07:34:53 +08:00
|
|
|
void arch_pick_mmap_layout(struct mm_struct *mm, struct rlimit *rlim_stack)
|
2014-02-01 05:19:52 +08:00
|
|
|
{
|
|
|
|
mm->mmap_legacy_base = mmap_legacy_base();
|
2018-04-11 07:34:53 +08:00
|
|
|
mm->mmap_base = mmap_upper_limit(rlim_stack);
|
2014-02-01 05:19:52 +08:00
|
|
|
|
|
|
|
if (mmap_is_legacy()) {
|
|
|
|
mm->mmap_base = mm->mmap_legacy_base;
|
|
|
|
mm->get_unmapped_area = arch_get_unmapped_area;
|
|
|
|
} else {
|
|
|
|
mm->get_unmapped_area = arch_get_unmapped_area_topdown;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2005-04-17 06:20:36 +08:00
|
|
|
asmlinkage unsigned long sys_mmap2(unsigned long addr, unsigned long len,
|
|
|
|
unsigned long prot, unsigned long flags, unsigned long fd,
|
|
|
|
unsigned long pgoff)
|
|
|
|
{
|
|
|
|
/* Make sure the shift for mmap2 is constant (12), no matter what PAGE_SIZE
|
|
|
|
we have. */
|
2018-03-11 18:34:46 +08:00
|
|
|
return ksys_mmap_pgoff(addr, len, prot, flags, fd,
|
|
|
|
pgoff >> (PAGE_SHIFT - 12));
|
2005-04-17 06:20:36 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
asmlinkage unsigned long sys_mmap(unsigned long addr, unsigned long len,
|
|
|
|
unsigned long prot, unsigned long flags, unsigned long fd,
|
|
|
|
unsigned long offset)
|
|
|
|
{
|
|
|
|
if (!(offset & ~PAGE_MASK)) {
|
2018-03-11 18:34:46 +08:00
|
|
|
return ksys_mmap_pgoff(addr, len, prot, flags, fd,
|
2009-12-01 06:37:04 +08:00
|
|
|
offset >> PAGE_SHIFT);
|
2005-04-17 06:20:36 +08:00
|
|
|
} else {
|
|
|
|
return -EINVAL;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Fucking broken ABI */
|
|
|
|
|
|
|
|
#ifdef CONFIG_64BIT
|
|
|
|
asmlinkage long parisc_truncate64(const char __user * path,
|
|
|
|
unsigned int high, unsigned int low)
|
|
|
|
{
|
2018-03-20 00:32:11 +08:00
|
|
|
return ksys_truncate(path, (long)high << 32 | low);
|
2005-04-17 06:20:36 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
asmlinkage long parisc_ftruncate64(unsigned int fd,
|
|
|
|
unsigned int high, unsigned int low)
|
|
|
|
{
|
2018-03-11 18:34:54 +08:00
|
|
|
return ksys_ftruncate(fd, (long)high << 32 | low);
|
2005-04-17 06:20:36 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
/* stubs for the benefit of the syscall_table since truncate64 and truncate
|
|
|
|
* are identical on LP64 */
|
|
|
|
asmlinkage long sys_truncate64(const char __user * path, unsigned long length)
|
|
|
|
{
|
2018-03-20 00:32:11 +08:00
|
|
|
return ksys_truncate(path, length);
|
2005-04-17 06:20:36 +08:00
|
|
|
}
|
|
|
|
asmlinkage long sys_ftruncate64(unsigned int fd, unsigned long length)
|
|
|
|
{
|
2018-03-11 18:34:54 +08:00
|
|
|
return ksys_ftruncate(fd, length);
|
2005-04-17 06:20:36 +08:00
|
|
|
}
|
|
|
|
asmlinkage long sys_fcntl64(unsigned int fd, unsigned int cmd, unsigned long arg)
|
|
|
|
{
|
|
|
|
return sys_fcntl(fd, cmd, arg);
|
|
|
|
}
|
|
|
|
#else
|
|
|
|
|
|
|
|
asmlinkage long parisc_truncate64(const char __user * path,
|
|
|
|
unsigned int high, unsigned int low)
|
|
|
|
{
|
2018-03-20 00:32:11 +08:00
|
|
|
return ksys_truncate(path, (loff_t)high << 32 | low);
|
2005-04-17 06:20:36 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
asmlinkage long parisc_ftruncate64(unsigned int fd,
|
|
|
|
unsigned int high, unsigned int low)
|
|
|
|
{
|
|
|
|
return sys_ftruncate64(fd, (loff_t)high << 32 | low);
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
asmlinkage ssize_t parisc_pread64(unsigned int fd, char __user *buf, size_t count,
|
|
|
|
unsigned int high, unsigned int low)
|
|
|
|
{
|
2018-03-20 00:38:31 +08:00
|
|
|
return ksys_pread64(fd, buf, count, (loff_t)high << 32 | low);
|
2005-04-17 06:20:36 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
asmlinkage ssize_t parisc_pwrite64(unsigned int fd, const char __user *buf,
|
|
|
|
size_t count, unsigned int high, unsigned int low)
|
|
|
|
{
|
2018-03-20 00:38:31 +08:00
|
|
|
return ksys_pwrite64(fd, buf, count, (loff_t)high << 32 | low);
|
2005-04-17 06:20:36 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
asmlinkage ssize_t parisc_readahead(int fd, unsigned int high, unsigned int low,
|
|
|
|
size_t count)
|
|
|
|
{
|
2018-03-20 00:51:36 +08:00
|
|
|
return ksys_readahead(fd, (loff_t)high << 32 | low, count);
|
2005-04-17 06:20:36 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
asmlinkage long parisc_fadvise64_64(int fd,
|
|
|
|
unsigned int high_off, unsigned int low_off,
|
|
|
|
unsigned int high_len, unsigned int low_len, int advice)
|
|
|
|
{
|
2018-03-11 18:34:45 +08:00
|
|
|
return ksys_fadvise64_64(fd, (loff_t)high_off << 32 | low_off,
|
2005-04-17 06:20:36 +08:00
|
|
|
(loff_t)high_len << 32 | low_len, advice);
|
|
|
|
}
|
|
|
|
|
2006-04-20 12:44:07 +08:00
|
|
|
asmlinkage long parisc_sync_file_range(int fd,
|
|
|
|
u32 hi_off, u32 lo_off, u32 hi_nbytes, u32 lo_nbytes,
|
|
|
|
unsigned int flags)
|
|
|
|
{
|
2018-03-11 18:34:47 +08:00
|
|
|
return ksys_sync_file_range(fd, (loff_t)hi_off << 32 | lo_off,
|
2006-04-20 12:44:07 +08:00
|
|
|
(loff_t)hi_nbytes << 32 | lo_nbytes, flags);
|
|
|
|
}
|
|
|
|
|
2013-02-20 04:23:59 +08:00
|
|
|
asmlinkage long parisc_fallocate(int fd, int mode, u32 offhi, u32 offlo,
|
|
|
|
u32 lenhi, u32 lenlo)
|
|
|
|
{
|
2018-03-20 00:46:32 +08:00
|
|
|
return ksys_fallocate(fd, mode, ((u64)offhi << 32) | offlo,
|
|
|
|
((u64)lenhi << 32) | lenlo);
|
2013-02-20 04:23:59 +08:00
|
|
|
}
|
|
|
|
|
2023-06-30 18:36:09 +08:00
|
|
|
asmlinkage long parisc_personality(unsigned long personality)
|
2006-08-27 23:12:13 +08:00
|
|
|
{
|
|
|
|
long err;
|
|
|
|
|
|
|
|
if (personality(current->personality) == PER_LINUX32
|
2012-08-02 21:33:59 +08:00
|
|
|
&& personality(personality) == PER_LINUX)
|
|
|
|
personality = (personality & ~PER_MASK) | PER_LINUX32;
|
2006-08-27 23:12:13 +08:00
|
|
|
|
|
|
|
err = sys_personality(personality);
|
2012-08-02 21:33:59 +08:00
|
|
|
if (personality(err) == PER_LINUX32)
|
|
|
|
err = (err & ~PER_MASK) | PER_LINUX;
|
2006-08-27 23:12:13 +08:00
|
|
|
|
|
|
|
return err;
|
|
|
|
}
|
2020-10-23 00:40:07 +08:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Up to kernel v5.9 we defined O_NONBLOCK as 000200004,
|
|
|
|
* since then O_NONBLOCK is defined as 000200000.
|
|
|
|
*
|
|
|
|
* The following wrapper functions mask out the old
|
|
|
|
* O_NDELAY bit from calls which use O_NONBLOCK.
|
|
|
|
*
|
|
|
|
* XXX: Remove those in year 2022 (or later)?
|
|
|
|
*/
|
|
|
|
|
|
|
|
#define O_NONBLOCK_OLD 000200004
|
|
|
|
#define O_NONBLOCK_MASK_OUT (O_NONBLOCK_OLD & ~O_NONBLOCK)
|
|
|
|
|
|
|
|
static int FIX_O_NONBLOCK(int flags)
|
|
|
|
{
|
2021-10-18 00:53:31 +08:00
|
|
|
if ((flags & O_NONBLOCK_MASK_OUT) &&
|
|
|
|
!test_thread_flag(TIF_NONBLOCK_WARNING)) {
|
|
|
|
set_thread_flag(TIF_NONBLOCK_WARNING);
|
|
|
|
pr_warn("%s(%d) uses a deprecated O_NONBLOCK value."
|
|
|
|
" Please recompile with newer glibc.\n",
|
|
|
|
current->comm, current->pid);
|
2020-10-23 00:40:07 +08:00
|
|
|
}
|
|
|
|
return flags & ~O_NONBLOCK_MASK_OUT;
|
|
|
|
}
|
|
|
|
|
|
|
|
asmlinkage long parisc_timerfd_create(int clockid, int flags)
|
|
|
|
{
|
|
|
|
flags = FIX_O_NONBLOCK(flags);
|
|
|
|
return sys_timerfd_create(clockid, flags);
|
|
|
|
}
|
|
|
|
|
|
|
|
asmlinkage long parisc_signalfd4(int ufd, sigset_t __user *user_mask,
|
|
|
|
size_t sizemask, int flags)
|
|
|
|
{
|
|
|
|
flags = FIX_O_NONBLOCK(flags);
|
|
|
|
return sys_signalfd4(ufd, user_mask, sizemask, flags);
|
|
|
|
}
|
|
|
|
|
|
|
|
#ifdef CONFIG_COMPAT
|
|
|
|
asmlinkage long parisc_compat_signalfd4(int ufd,
|
|
|
|
compat_sigset_t __user *user_mask,
|
|
|
|
compat_size_t sizemask, int flags)
|
|
|
|
{
|
|
|
|
flags = FIX_O_NONBLOCK(flags);
|
|
|
|
return compat_sys_signalfd4(ufd, user_mask, sizemask, flags);
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
asmlinkage long parisc_eventfd2(unsigned int count, int flags)
|
|
|
|
{
|
|
|
|
flags = FIX_O_NONBLOCK(flags);
|
|
|
|
return sys_eventfd2(count, flags);
|
|
|
|
}
|
|
|
|
|
|
|
|
asmlinkage long parisc_userfaultfd(int flags)
|
|
|
|
{
|
|
|
|
flags = FIX_O_NONBLOCK(flags);
|
|
|
|
return sys_userfaultfd(flags);
|
|
|
|
}
|
|
|
|
|
|
|
|
asmlinkage long parisc_pipe2(int __user *fildes, int flags)
|
|
|
|
{
|
|
|
|
flags = FIX_O_NONBLOCK(flags);
|
|
|
|
return sys_pipe2(fildes, flags);
|
|
|
|
}
|
|
|
|
|
|
|
|
asmlinkage long parisc_inotify_init1(int flags)
|
|
|
|
{
|
|
|
|
flags = FIX_O_NONBLOCK(flags);
|
|
|
|
return sys_inotify_init1(flags);
|
|
|
|
}
|
2022-12-12 02:50:20 +08:00
|
|
|
|
|
|
|
/*
|
|
|
|
* madvise() wrapper
|
|
|
|
*
|
|
|
|
* Up to kernel v6.1 parisc has different values than all other
|
|
|
|
* platforms for the MADV_xxx flags listed below.
|
|
|
|
* To keep binary compatibility with existing userspace programs
|
|
|
|
* translate the former values to the new values.
|
|
|
|
*
|
|
|
|
* XXX: Remove this wrapper in year 2025 (or later)
|
|
|
|
*/
|
|
|
|
|
|
|
|
asmlinkage notrace long parisc_madvise(unsigned long start, size_t len_in, int behavior)
|
|
|
|
{
|
|
|
|
switch (behavior) {
|
|
|
|
case 65: behavior = MADV_MERGEABLE; break;
|
|
|
|
case 66: behavior = MADV_UNMERGEABLE; break;
|
|
|
|
case 67: behavior = MADV_HUGEPAGE; break;
|
|
|
|
case 68: behavior = MADV_NOHUGEPAGE; break;
|
|
|
|
case 69: behavior = MADV_DONTDUMP; break;
|
|
|
|
case 70: behavior = MADV_DODUMP; break;
|
|
|
|
case 71: behavior = MADV_WIPEONFORK; break;
|
|
|
|
case 72: behavior = MADV_KEEPONFORK; break;
|
|
|
|
case 73: behavior = MADV_COLLAPSE; break;
|
|
|
|
}
|
|
|
|
|
|
|
|
return sys_madvise(start, len_in, behavior);
|
|
|
|
}
|