2019-05-27 14:55:01 +08:00
|
|
|
// SPDX-License-Identifier: GPL-2.0-or-later
|
2006-03-27 08:57:01 +08:00
|
|
|
/**
|
|
|
|
* Copyright (C) 2005 Brian Rogan <bcr6@cornell.edu>, IBM
|
|
|
|
*
|
|
|
|
**/
|
|
|
|
|
y2038: globally rename compat_time to old_time32
Christoph Hellwig suggested a slightly different path for handling
backwards compatibility with the 32-bit time_t based system calls:
Rather than simply reusing the compat_sys_* entry points on 32-bit
architectures unchanged, we get rid of those entry points and the
compat_time types by renaming them to something that makes more sense
on 32-bit architectures (which don't have a compat mode otherwise),
and then share the entry points under the new name with the 64-bit
architectures that use them for implementing the compatibility.
The following types and interfaces are renamed here, and moved
from linux/compat_time.h to linux/time32.h:
old new
--- ---
compat_time_t old_time32_t
struct compat_timeval struct old_timeval32
struct compat_timespec struct old_timespec32
struct compat_itimerspec struct old_itimerspec32
ns_to_compat_timeval() ns_to_old_timeval32()
get_compat_itimerspec64() get_old_itimerspec32()
put_compat_itimerspec64() put_old_itimerspec32()
compat_get_timespec64() get_old_timespec32()
compat_put_timespec64() put_old_timespec32()
As we already have aliases in place, this patch addresses only the
instances that are relevant to the system call interface in particular,
not those that occur in device drivers and other modules. Those
will get handled separately, while providing the 64-bit version
of the respective interfaces.
I'm not renaming the timex, rusage and itimerval structures, as we are
still debating what the new interface will look like, and whether we
will need a replacement at all.
This also doesn't change the names of the syscall entry points, which can
be done more easily when we actually switch over the 32-bit architectures
to use them, at that point we need to change COMPAT_SYSCALL_DEFINEx to
SYSCALL_DEFINEx with a new name, e.g. with a _time32 suffix.
Suggested-by: Christoph Hellwig <hch@infradead.org>
Link: https://lore.kernel.org/lkml/20180705222110.GA5698@infradead.org/
Signed-off-by: Arnd Bergmann <arnd@arndb.de>
2018-07-13 18:52:28 +08:00
|
|
|
#include <linux/time.h>
|
2006-03-27 08:57:01 +08:00
|
|
|
#include <linux/oprofile.h>
|
|
|
|
#include <linux/sched.h>
|
|
|
|
#include <asm/processor.h>
|
2014-11-21 11:23:19 +08:00
|
|
|
#include <linux/uaccess.h>
|
2006-09-23 08:37:41 +08:00
|
|
|
#include <asm/compat.h>
|
2014-08-20 06:55:19 +08:00
|
|
|
#include <asm/oprofile_impl.h>
|
2006-03-27 08:57:01 +08:00
|
|
|
|
|
|
|
#define STACK_SP(STACK) *(STACK)
|
|
|
|
|
|
|
|
#define STACK_LR64(STACK) *((unsigned long *)(STACK) + 2)
|
|
|
|
#define STACK_LR32(STACK) *((unsigned int *)(STACK) + 1)
|
|
|
|
|
|
|
|
#ifdef CONFIG_PPC64
|
|
|
|
#define STACK_LR(STACK) STACK_LR64(STACK)
|
|
|
|
#else
|
|
|
|
#define STACK_LR(STACK) STACK_LR32(STACK)
|
|
|
|
#endif
|
|
|
|
|
|
|
|
static unsigned int user_getsp32(unsigned int sp, int is_first)
|
|
|
|
{
|
|
|
|
unsigned int stack_frame[2];
|
2006-09-23 08:37:41 +08:00
|
|
|
void __user *p = compat_ptr(sp);
|
2006-03-27 08:57:01 +08:00
|
|
|
|
Remove 'type' argument from access_ok() function
Nobody has actually used the type (VERIFY_READ vs VERIFY_WRITE) argument
of the user address range verification function since we got rid of the
old racy i386-only code to walk page tables by hand.
It existed because the original 80386 would not honor the write protect
bit when in kernel mode, so you had to do COW by hand before doing any
user access. But we haven't supported that in a long time, and these
days the 'type' argument is a purely historical artifact.
A discussion about extending 'user_access_begin()' to do the range
checking resulted this patch, because there is no way we're going to
move the old VERIFY_xyz interface to that model. And it's best done at
the end of the merge window when I've done most of my merges, so let's
just get this done once and for all.
This patch was mostly done with a sed-script, with manual fix-ups for
the cases that weren't of the trivial 'access_ok(VERIFY_xyz' form.
There were a couple of notable cases:
- csky still had the old "verify_area()" name as an alias.
- the iter_iov code had magical hardcoded knowledge of the actual
values of VERIFY_{READ,WRITE} (not that they mattered, since nothing
really used it)
- microblaze used the type argument for a debug printout
but other than those oddities this should be a total no-op patch.
I tried to fix up all architectures, did fairly extensive grepping for
access_ok() uses, and the changes are trivial, but I may have missed
something. Any missed conversion should be trivially fixable, though.
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
2019-01-04 10:57:57 +08:00
|
|
|
if (!access_ok(p, sizeof(stack_frame)))
|
2006-03-27 08:57:01 +08:00
|
|
|
return 0;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* The most likely reason for this is that we returned -EFAULT,
|
|
|
|
* which means that we've done all that we can do from
|
|
|
|
* interrupt context.
|
|
|
|
*/
|
2006-09-23 08:37:41 +08:00
|
|
|
if (__copy_from_user_inatomic(stack_frame, p, sizeof(stack_frame)))
|
2006-03-27 08:57:01 +08:00
|
|
|
return 0;
|
|
|
|
|
|
|
|
if (!is_first)
|
|
|
|
oprofile_add_trace(STACK_LR32(stack_frame));
|
|
|
|
|
|
|
|
/*
|
|
|
|
* We do not enforce increasing stack addresses here because
|
|
|
|
* we may transition to a different stack, eg a signal handler.
|
|
|
|
*/
|
|
|
|
return STACK_SP(stack_frame);
|
|
|
|
}
|
|
|
|
|
|
|
|
#ifdef CONFIG_PPC64
|
|
|
|
static unsigned long user_getsp64(unsigned long sp, int is_first)
|
|
|
|
{
|
|
|
|
unsigned long stack_frame[3];
|
|
|
|
|
Remove 'type' argument from access_ok() function
Nobody has actually used the type (VERIFY_READ vs VERIFY_WRITE) argument
of the user address range verification function since we got rid of the
old racy i386-only code to walk page tables by hand.
It existed because the original 80386 would not honor the write protect
bit when in kernel mode, so you had to do COW by hand before doing any
user access. But we haven't supported that in a long time, and these
days the 'type' argument is a purely historical artifact.
A discussion about extending 'user_access_begin()' to do the range
checking resulted this patch, because there is no way we're going to
move the old VERIFY_xyz interface to that model. And it's best done at
the end of the merge window when I've done most of my merges, so let's
just get this done once and for all.
This patch was mostly done with a sed-script, with manual fix-ups for
the cases that weren't of the trivial 'access_ok(VERIFY_xyz' form.
There were a couple of notable cases:
- csky still had the old "verify_area()" name as an alias.
- the iter_iov code had magical hardcoded knowledge of the actual
values of VERIFY_{READ,WRITE} (not that they mattered, since nothing
really used it)
- microblaze used the type argument for a debug printout
but other than those oddities this should be a total no-op patch.
I tried to fix up all architectures, did fairly extensive grepping for
access_ok() uses, and the changes are trivial, but I may have missed
something. Any missed conversion should be trivially fixable, though.
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
2019-01-04 10:57:57 +08:00
|
|
|
if (!access_ok((void __user *)sp, sizeof(stack_frame)))
|
2006-03-27 08:57:01 +08:00
|
|
|
return 0;
|
|
|
|
|
2006-09-23 08:37:41 +08:00
|
|
|
if (__copy_from_user_inatomic(stack_frame, (void __user *)sp,
|
2006-03-27 08:57:01 +08:00
|
|
|
sizeof(stack_frame)))
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
if (!is_first)
|
|
|
|
oprofile_add_trace(STACK_LR64(stack_frame));
|
|
|
|
|
|
|
|
return STACK_SP(stack_frame);
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
static unsigned long kernel_getsp(unsigned long sp, int is_first)
|
|
|
|
{
|
|
|
|
unsigned long *stack_frame = (unsigned long *)sp;
|
|
|
|
|
|
|
|
if (!validate_sp(sp, current, STACK_FRAME_OVERHEAD))
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
if (!is_first)
|
|
|
|
oprofile_add_trace(STACK_LR(stack_frame));
|
|
|
|
|
|
|
|
/*
|
|
|
|
* We do not enforce increasing stack addresses here because
|
|
|
|
* we might be transitioning from an interrupt stack to a kernel
|
|
|
|
* stack. validate_sp() is designed to understand this, so just
|
|
|
|
* use it.
|
|
|
|
*/
|
|
|
|
return STACK_SP(stack_frame);
|
|
|
|
}
|
|
|
|
|
|
|
|
void op_powerpc_backtrace(struct pt_regs * const regs, unsigned int depth)
|
|
|
|
{
|
|
|
|
unsigned long sp = regs->gpr[1];
|
|
|
|
int first_frame = 1;
|
|
|
|
|
|
|
|
/* We ditch the top stackframe so need to loop through an extra time */
|
|
|
|
depth += 1;
|
|
|
|
|
|
|
|
if (!user_mode(regs)) {
|
|
|
|
while (depth--) {
|
|
|
|
sp = kernel_getsp(sp, first_frame);
|
|
|
|
if (!sp)
|
|
|
|
break;
|
|
|
|
first_frame = 0;
|
|
|
|
}
|
|
|
|
} else {
|
2014-11-21 11:23:19 +08:00
|
|
|
pagefault_disable();
|
2006-03-27 08:57:01 +08:00
|
|
|
#ifdef CONFIG_PPC64
|
2010-08-27 11:49:11 +08:00
|
|
|
if (!is_32bit_task()) {
|
2006-03-27 08:57:01 +08:00
|
|
|
while (depth--) {
|
|
|
|
sp = user_getsp64(sp, first_frame);
|
|
|
|
if (!sp)
|
|
|
|
break;
|
|
|
|
first_frame = 0;
|
|
|
|
}
|
2014-11-21 11:23:19 +08:00
|
|
|
pagefault_enable();
|
2006-03-27 08:57:01 +08:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
while (depth--) {
|
|
|
|
sp = user_getsp32(sp, first_frame);
|
|
|
|
if (!sp)
|
|
|
|
break;
|
|
|
|
first_frame = 0;
|
|
|
|
}
|
2014-11-21 11:23:19 +08:00
|
|
|
pagefault_enable();
|
2006-03-27 08:57:01 +08:00
|
|
|
}
|
|
|
|
}
|