2012-03-05 11:49:31 +00:00
|
|
|
/*
|
|
|
|
* Based on arch/arm/kernel/signal.c
|
|
|
|
*
|
|
|
|
* Copyright (C) 1995-2009 Russell King
|
|
|
|
* Copyright (C) 2012 ARM Ltd.
|
|
|
|
*
|
|
|
|
* This program is free software; you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU General Public License version 2 as
|
|
|
|
* published by the Free Software Foundation.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
*/
|
|
|
|
|
2014-04-30 09:51:32 +00:00
|
|
|
#include <linux/compat.h>
|
2012-03-05 11:49:31 +00:00
|
|
|
#include <linux/errno.h>
|
2017-06-15 14:03:38 +00:00
|
|
|
#include <linux/kernel.h>
|
2012-03-05 11:49:31 +00:00
|
|
|
#include <linux/signal.h>
|
|
|
|
#include <linux/personality.h>
|
|
|
|
#include <linux/freezer.h>
|
2017-06-15 14:03:39 +00:00
|
|
|
#include <linux/stddef.h>
|
2012-03-05 11:49:31 +00:00
|
|
|
#include <linux/uaccess.h>
|
arm64: signal: factor frame layout and population into separate passes
In preparation for expanding the signal frame, this patch refactors
the signal frame setup code in setup_sigframe() into two separate
passes.
The first pass, setup_sigframe_layout(), determines the size of the
signal frame and its internal layout, including the presence and
location of optional records. The resulting knowledge is used to
allocate and locate the user stack space required for the signal
frame and to determine which optional records to include.
The second pass, setup_sigframe(), is called once the stack frame
is allocated in order to populate it with the necessary context
information.
As a result of these changes, it becomes more natural to represent
locations in the signal frame by a base pointer and an offset,
since the absolute address of each location is not known during the
layout pass. To be more consistent with this logic,
parse_user_sigframe() is refactored to describe signal frame
locations in a similar way.
This change has no effect on the signal ABI, but will make it
easier to expand the signal frame in future patches.
Reviewed-by: Catalin Marinas <catalin.marinas@arm.com>
Signed-off-by: Dave Martin <Dave.Martin@arm.com>
Signed-off-by: Will Deacon <will.deacon@arm.com>
2017-06-15 14:03:40 +00:00
|
|
|
#include <linux/string.h>
|
2012-03-05 11:49:31 +00:00
|
|
|
#include <linux/tracehook.h>
|
|
|
|
#include <linux/ratelimit.h>
|
|
|
|
|
|
|
|
#include <asm/debug-monitors.h>
|
|
|
|
#include <asm/elf.h>
|
|
|
|
#include <asm/cacheflush.h>
|
|
|
|
#include <asm/ucontext.h>
|
|
|
|
#include <asm/unistd.h>
|
|
|
|
#include <asm/fpsimd.h>
|
|
|
|
#include <asm/signal32.h>
|
|
|
|
#include <asm/vdso.h>
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Do a signal return; undo the signal stack. These are aligned to 128-bit.
|
|
|
|
*/
|
|
|
|
struct rt_sigframe {
|
|
|
|
struct siginfo info;
|
|
|
|
struct ucontext uc;
|
2017-06-15 14:03:38 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
struct frame_record {
|
2012-11-23 12:34:13 +00:00
|
|
|
u64 fp;
|
|
|
|
u64 lr;
|
2012-03-05 11:49:31 +00:00
|
|
|
};
|
|
|
|
|
2017-06-15 14:03:38 +00:00
|
|
|
struct rt_sigframe_user_layout {
|
|
|
|
struct rt_sigframe __user *sigframe;
|
|
|
|
struct frame_record __user *next_frame;
|
arm64: signal: factor frame layout and population into separate passes
In preparation for expanding the signal frame, this patch refactors
the signal frame setup code in setup_sigframe() into two separate
passes.
The first pass, setup_sigframe_layout(), determines the size of the
signal frame and its internal layout, including the presence and
location of optional records. The resulting knowledge is used to
allocate and locate the user stack space required for the signal
frame and to determine which optional records to include.
The second pass, setup_sigframe(), is called once the stack frame
is allocated in order to populate it with the necessary context
information.
As a result of these changes, it becomes more natural to represent
locations in the signal frame by a base pointer and an offset,
since the absolute address of each location is not known during the
layout pass. To be more consistent with this logic,
parse_user_sigframe() is refactored to describe signal frame
locations in a similar way.
This change has no effect on the signal ABI, but will make it
easier to expand the signal frame in future patches.
Reviewed-by: Catalin Marinas <catalin.marinas@arm.com>
Signed-off-by: Dave Martin <Dave.Martin@arm.com>
Signed-off-by: Will Deacon <will.deacon@arm.com>
2017-06-15 14:03:40 +00:00
|
|
|
|
|
|
|
unsigned long size; /* size of allocated sigframe data */
|
|
|
|
unsigned long limit; /* largest allowed size */
|
|
|
|
|
|
|
|
unsigned long fpsimd_offset;
|
|
|
|
unsigned long esr_offset;
|
|
|
|
unsigned long end_offset;
|
2017-06-15 14:03:38 +00:00
|
|
|
};
|
|
|
|
|
arm64: signal: factor frame layout and population into separate passes
In preparation for expanding the signal frame, this patch refactors
the signal frame setup code in setup_sigframe() into two separate
passes.
The first pass, setup_sigframe_layout(), determines the size of the
signal frame and its internal layout, including the presence and
location of optional records. The resulting knowledge is used to
allocate and locate the user stack space required for the signal
frame and to determine which optional records to include.
The second pass, setup_sigframe(), is called once the stack frame
is allocated in order to populate it with the necessary context
information.
As a result of these changes, it becomes more natural to represent
locations in the signal frame by a base pointer and an offset,
since the absolute address of each location is not known during the
layout pass. To be more consistent with this logic,
parse_user_sigframe() is refactored to describe signal frame
locations in a similar way.
This change has no effect on the signal ABI, but will make it
easier to expand the signal frame in future patches.
Reviewed-by: Catalin Marinas <catalin.marinas@arm.com>
Signed-off-by: Dave Martin <Dave.Martin@arm.com>
Signed-off-by: Will Deacon <will.deacon@arm.com>
2017-06-15 14:03:40 +00:00
|
|
|
static void init_user_layout(struct rt_sigframe_user_layout *user)
|
|
|
|
{
|
|
|
|
memset(user, 0, sizeof(*user));
|
|
|
|
user->size = offsetof(struct rt_sigframe, uc.uc_mcontext.__reserved);
|
|
|
|
|
|
|
|
user->limit = user->size +
|
|
|
|
sizeof(user->sigframe->uc.uc_mcontext.__reserved) -
|
|
|
|
round_up(sizeof(struct _aarch64_ctx), 16);
|
|
|
|
/* ^ reserve space for terminator */
|
|
|
|
}
|
|
|
|
|
|
|
|
static size_t sigframe_size(struct rt_sigframe_user_layout const *user)
|
|
|
|
{
|
|
|
|
return round_up(max(user->size, sizeof(struct rt_sigframe)), 16);
|
|
|
|
}
|
|
|
|
|
2017-06-15 14:03:41 +00:00
|
|
|
/*
|
|
|
|
* Allocate space for an optional record of <size> bytes in the user
|
|
|
|
* signal frame. The offset from the signal frame base address to the
|
|
|
|
* allocated block is assigned to *offset.
|
|
|
|
*/
|
|
|
|
static int sigframe_alloc(struct rt_sigframe_user_layout *user,
|
|
|
|
unsigned long *offset, size_t size)
|
|
|
|
{
|
|
|
|
size_t padded_size = round_up(size, 16);
|
|
|
|
|
|
|
|
*offset = user->size;
|
|
|
|
user->size += padded_size;
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
arm64: signal: factor frame layout and population into separate passes
In preparation for expanding the signal frame, this patch refactors
the signal frame setup code in setup_sigframe() into two separate
passes.
The first pass, setup_sigframe_layout(), determines the size of the
signal frame and its internal layout, including the presence and
location of optional records. The resulting knowledge is used to
allocate and locate the user stack space required for the signal
frame and to determine which optional records to include.
The second pass, setup_sigframe(), is called once the stack frame
is allocated in order to populate it with the necessary context
information.
As a result of these changes, it becomes more natural to represent
locations in the signal frame by a base pointer and an offset,
since the absolute address of each location is not known during the
layout pass. To be more consistent with this logic,
parse_user_sigframe() is refactored to describe signal frame
locations in a similar way.
This change has no effect on the signal ABI, but will make it
easier to expand the signal frame in future patches.
Reviewed-by: Catalin Marinas <catalin.marinas@arm.com>
Signed-off-by: Dave Martin <Dave.Martin@arm.com>
Signed-off-by: Will Deacon <will.deacon@arm.com>
2017-06-15 14:03:40 +00:00
|
|
|
static void __user *apply_user_offset(
|
|
|
|
struct rt_sigframe_user_layout const *user, unsigned long offset)
|
|
|
|
{
|
|
|
|
char __user *base = (char __user *)user->sigframe;
|
|
|
|
|
|
|
|
return base + offset;
|
|
|
|
}
|
|
|
|
|
2012-03-05 11:49:31 +00:00
|
|
|
static int preserve_fpsimd_context(struct fpsimd_context __user *ctx)
|
|
|
|
{
|
|
|
|
struct fpsimd_state *fpsimd = ¤t->thread.fpsimd_state;
|
|
|
|
int err;
|
|
|
|
|
|
|
|
/* dump the hardware registers to the fpsimd_state structure */
|
2014-02-24 14:26:27 +00:00
|
|
|
fpsimd_preserve_current_state();
|
2012-03-05 11:49:31 +00:00
|
|
|
|
|
|
|
/* copy the FP and status/control registers */
|
|
|
|
err = __copy_to_user(ctx->vregs, fpsimd->vregs, sizeof(fpsimd->vregs));
|
|
|
|
__put_user_error(fpsimd->fpsr, &ctx->fpsr, err);
|
|
|
|
__put_user_error(fpsimd->fpcr, &ctx->fpcr, err);
|
|
|
|
|
|
|
|
/* copy the magic/size information */
|
|
|
|
__put_user_error(FPSIMD_MAGIC, &ctx->head.magic, err);
|
|
|
|
__put_user_error(sizeof(struct fpsimd_context), &ctx->head.size, err);
|
|
|
|
|
|
|
|
return err ? -EFAULT : 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int restore_fpsimd_context(struct fpsimd_context __user *ctx)
|
|
|
|
{
|
|
|
|
struct fpsimd_state fpsimd;
|
|
|
|
__u32 magic, size;
|
|
|
|
int err = 0;
|
|
|
|
|
|
|
|
/* check the magic/size information */
|
|
|
|
__get_user_error(magic, &ctx->head.magic, err);
|
|
|
|
__get_user_error(size, &ctx->head.size, err);
|
|
|
|
if (err)
|
|
|
|
return -EFAULT;
|
|
|
|
if (magic != FPSIMD_MAGIC || size != sizeof(struct fpsimd_context))
|
|
|
|
return -EINVAL;
|
|
|
|
|
|
|
|
/* copy the FP and status/control registers */
|
|
|
|
err = __copy_from_user(fpsimd.vregs, ctx->vregs,
|
|
|
|
sizeof(fpsimd.vregs));
|
|
|
|
__get_user_error(fpsimd.fpsr, &ctx->fpsr, err);
|
|
|
|
__get_user_error(fpsimd.fpcr, &ctx->fpcr, err);
|
|
|
|
|
|
|
|
/* load the hardware registers from the fpsimd_state structure */
|
2014-02-24 14:26:27 +00:00
|
|
|
if (!err)
|
|
|
|
fpsimd_update_current_state(&fpsimd);
|
2012-03-05 11:49:31 +00:00
|
|
|
|
|
|
|
return err ? -EFAULT : 0;
|
|
|
|
}
|
|
|
|
|
2017-06-15 14:03:39 +00:00
|
|
|
struct user_ctxs {
|
|
|
|
struct fpsimd_context __user *fpsimd;
|
|
|
|
};
|
|
|
|
|
|
|
|
static int parse_user_sigframe(struct user_ctxs *user,
|
|
|
|
struct rt_sigframe __user *sf)
|
|
|
|
{
|
|
|
|
struct sigcontext __user *const sc = &sf->uc.uc_mcontext;
|
arm64: signal: factor frame layout and population into separate passes
In preparation for expanding the signal frame, this patch refactors
the signal frame setup code in setup_sigframe() into two separate
passes.
The first pass, setup_sigframe_layout(), determines the size of the
signal frame and its internal layout, including the presence and
location of optional records. The resulting knowledge is used to
allocate and locate the user stack space required for the signal
frame and to determine which optional records to include.
The second pass, setup_sigframe(), is called once the stack frame
is allocated in order to populate it with the necessary context
information.
As a result of these changes, it becomes more natural to represent
locations in the signal frame by a base pointer and an offset,
since the absolute address of each location is not known during the
layout pass. To be more consistent with this logic,
parse_user_sigframe() is refactored to describe signal frame
locations in a similar way.
This change has no effect on the signal ABI, but will make it
easier to expand the signal frame in future patches.
Reviewed-by: Catalin Marinas <catalin.marinas@arm.com>
Signed-off-by: Dave Martin <Dave.Martin@arm.com>
Signed-off-by: Will Deacon <will.deacon@arm.com>
2017-06-15 14:03:40 +00:00
|
|
|
struct _aarch64_ctx __user *head;
|
|
|
|
char __user *base = (char __user *)&sc->__reserved;
|
2017-06-15 14:03:39 +00:00
|
|
|
size_t offset = 0;
|
arm64: signal: factor frame layout and population into separate passes
In preparation for expanding the signal frame, this patch refactors
the signal frame setup code in setup_sigframe() into two separate
passes.
The first pass, setup_sigframe_layout(), determines the size of the
signal frame and its internal layout, including the presence and
location of optional records. The resulting knowledge is used to
allocate and locate the user stack space required for the signal
frame and to determine which optional records to include.
The second pass, setup_sigframe(), is called once the stack frame
is allocated in order to populate it with the necessary context
information.
As a result of these changes, it becomes more natural to represent
locations in the signal frame by a base pointer and an offset,
since the absolute address of each location is not known during the
layout pass. To be more consistent with this logic,
parse_user_sigframe() is refactored to describe signal frame
locations in a similar way.
This change has no effect on the signal ABI, but will make it
easier to expand the signal frame in future patches.
Reviewed-by: Catalin Marinas <catalin.marinas@arm.com>
Signed-off-by: Dave Martin <Dave.Martin@arm.com>
Signed-off-by: Will Deacon <will.deacon@arm.com>
2017-06-15 14:03:40 +00:00
|
|
|
size_t limit = sizeof(sc->__reserved);
|
2017-06-15 14:03:39 +00:00
|
|
|
|
|
|
|
user->fpsimd = NULL;
|
|
|
|
|
arm64: signal: factor frame layout and population into separate passes
In preparation for expanding the signal frame, this patch refactors
the signal frame setup code in setup_sigframe() into two separate
passes.
The first pass, setup_sigframe_layout(), determines the size of the
signal frame and its internal layout, including the presence and
location of optional records. The resulting knowledge is used to
allocate and locate the user stack space required for the signal
frame and to determine which optional records to include.
The second pass, setup_sigframe(), is called once the stack frame
is allocated in order to populate it with the necessary context
information.
As a result of these changes, it becomes more natural to represent
locations in the signal frame by a base pointer and an offset,
since the absolute address of each location is not known during the
layout pass. To be more consistent with this logic,
parse_user_sigframe() is refactored to describe signal frame
locations in a similar way.
This change has no effect on the signal ABI, but will make it
easier to expand the signal frame in future patches.
Reviewed-by: Catalin Marinas <catalin.marinas@arm.com>
Signed-off-by: Dave Martin <Dave.Martin@arm.com>
Signed-off-by: Will Deacon <will.deacon@arm.com>
2017-06-15 14:03:40 +00:00
|
|
|
if (!IS_ALIGNED((unsigned long)base, 16))
|
|
|
|
goto invalid;
|
|
|
|
|
2017-06-15 14:03:39 +00:00
|
|
|
while (1) {
|
arm64: signal: factor frame layout and population into separate passes
In preparation for expanding the signal frame, this patch refactors
the signal frame setup code in setup_sigframe() into two separate
passes.
The first pass, setup_sigframe_layout(), determines the size of the
signal frame and its internal layout, including the presence and
location of optional records. The resulting knowledge is used to
allocate and locate the user stack space required for the signal
frame and to determine which optional records to include.
The second pass, setup_sigframe(), is called once the stack frame
is allocated in order to populate it with the necessary context
information.
As a result of these changes, it becomes more natural to represent
locations in the signal frame by a base pointer and an offset,
since the absolute address of each location is not known during the
layout pass. To be more consistent with this logic,
parse_user_sigframe() is refactored to describe signal frame
locations in a similar way.
This change has no effect on the signal ABI, but will make it
easier to expand the signal frame in future patches.
Reviewed-by: Catalin Marinas <catalin.marinas@arm.com>
Signed-off-by: Dave Martin <Dave.Martin@arm.com>
Signed-off-by: Will Deacon <will.deacon@arm.com>
2017-06-15 14:03:40 +00:00
|
|
|
int err = 0;
|
2017-06-15 14:03:39 +00:00
|
|
|
u32 magic, size;
|
|
|
|
|
arm64: signal: factor frame layout and population into separate passes
In preparation for expanding the signal frame, this patch refactors
the signal frame setup code in setup_sigframe() into two separate
passes.
The first pass, setup_sigframe_layout(), determines the size of the
signal frame and its internal layout, including the presence and
location of optional records. The resulting knowledge is used to
allocate and locate the user stack space required for the signal
frame and to determine which optional records to include.
The second pass, setup_sigframe(), is called once the stack frame
is allocated in order to populate it with the necessary context
information.
As a result of these changes, it becomes more natural to represent
locations in the signal frame by a base pointer and an offset,
since the absolute address of each location is not known during the
layout pass. To be more consistent with this logic,
parse_user_sigframe() is refactored to describe signal frame
locations in a similar way.
This change has no effect on the signal ABI, but will make it
easier to expand the signal frame in future patches.
Reviewed-by: Catalin Marinas <catalin.marinas@arm.com>
Signed-off-by: Dave Martin <Dave.Martin@arm.com>
Signed-off-by: Will Deacon <will.deacon@arm.com>
2017-06-15 14:03:40 +00:00
|
|
|
if (limit - offset < sizeof(*head))
|
2017-06-15 14:03:39 +00:00
|
|
|
goto invalid;
|
|
|
|
|
arm64: signal: factor frame layout and population into separate passes
In preparation for expanding the signal frame, this patch refactors
the signal frame setup code in setup_sigframe() into two separate
passes.
The first pass, setup_sigframe_layout(), determines the size of the
signal frame and its internal layout, including the presence and
location of optional records. The resulting knowledge is used to
allocate and locate the user stack space required for the signal
frame and to determine which optional records to include.
The second pass, setup_sigframe(), is called once the stack frame
is allocated in order to populate it with the necessary context
information.
As a result of these changes, it becomes more natural to represent
locations in the signal frame by a base pointer and an offset,
since the absolute address of each location is not known during the
layout pass. To be more consistent with this logic,
parse_user_sigframe() is refactored to describe signal frame
locations in a similar way.
This change has no effect on the signal ABI, but will make it
easier to expand the signal frame in future patches.
Reviewed-by: Catalin Marinas <catalin.marinas@arm.com>
Signed-off-by: Dave Martin <Dave.Martin@arm.com>
Signed-off-by: Will Deacon <will.deacon@arm.com>
2017-06-15 14:03:40 +00:00
|
|
|
if (!IS_ALIGNED(offset, 16))
|
|
|
|
goto invalid;
|
|
|
|
|
|
|
|
head = (struct _aarch64_ctx __user *)(base + offset);
|
2017-06-15 14:03:39 +00:00
|
|
|
__get_user_error(magic, &head->magic, err);
|
|
|
|
__get_user_error(size, &head->size, err);
|
|
|
|
if (err)
|
|
|
|
return err;
|
|
|
|
|
arm64: signal: factor frame layout and population into separate passes
In preparation for expanding the signal frame, this patch refactors
the signal frame setup code in setup_sigframe() into two separate
passes.
The first pass, setup_sigframe_layout(), determines the size of the
signal frame and its internal layout, including the presence and
location of optional records. The resulting knowledge is used to
allocate and locate the user stack space required for the signal
frame and to determine which optional records to include.
The second pass, setup_sigframe(), is called once the stack frame
is allocated in order to populate it with the necessary context
information.
As a result of these changes, it becomes more natural to represent
locations in the signal frame by a base pointer and an offset,
since the absolute address of each location is not known during the
layout pass. To be more consistent with this logic,
parse_user_sigframe() is refactored to describe signal frame
locations in a similar way.
This change has no effect on the signal ABI, but will make it
easier to expand the signal frame in future patches.
Reviewed-by: Catalin Marinas <catalin.marinas@arm.com>
Signed-off-by: Dave Martin <Dave.Martin@arm.com>
Signed-off-by: Will Deacon <will.deacon@arm.com>
2017-06-15 14:03:40 +00:00
|
|
|
if (limit - offset < size)
|
|
|
|
goto invalid;
|
|
|
|
|
2017-06-15 14:03:39 +00:00
|
|
|
switch (magic) {
|
|
|
|
case 0:
|
|
|
|
if (size)
|
|
|
|
goto invalid;
|
|
|
|
|
|
|
|
goto done;
|
|
|
|
|
|
|
|
case FPSIMD_MAGIC:
|
|
|
|
if (user->fpsimd)
|
|
|
|
goto invalid;
|
|
|
|
|
arm64: signal: factor frame layout and population into separate passes
In preparation for expanding the signal frame, this patch refactors
the signal frame setup code in setup_sigframe() into two separate
passes.
The first pass, setup_sigframe_layout(), determines the size of the
signal frame and its internal layout, including the presence and
location of optional records. The resulting knowledge is used to
allocate and locate the user stack space required for the signal
frame and to determine which optional records to include.
The second pass, setup_sigframe(), is called once the stack frame
is allocated in order to populate it with the necessary context
information.
As a result of these changes, it becomes more natural to represent
locations in the signal frame by a base pointer and an offset,
since the absolute address of each location is not known during the
layout pass. To be more consistent with this logic,
parse_user_sigframe() is refactored to describe signal frame
locations in a similar way.
This change has no effect on the signal ABI, but will make it
easier to expand the signal frame in future patches.
Reviewed-by: Catalin Marinas <catalin.marinas@arm.com>
Signed-off-by: Dave Martin <Dave.Martin@arm.com>
Signed-off-by: Will Deacon <will.deacon@arm.com>
2017-06-15 14:03:40 +00:00
|
|
|
if (size < sizeof(*user->fpsimd))
|
2017-06-15 14:03:39 +00:00
|
|
|
goto invalid;
|
|
|
|
|
|
|
|
user->fpsimd = (struct fpsimd_context __user *)head;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case ESR_MAGIC:
|
|
|
|
/* ignore */
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
goto invalid;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (size < sizeof(*head))
|
|
|
|
goto invalid;
|
|
|
|
|
arm64: signal: factor frame layout and population into separate passes
In preparation for expanding the signal frame, this patch refactors
the signal frame setup code in setup_sigframe() into two separate
passes.
The first pass, setup_sigframe_layout(), determines the size of the
signal frame and its internal layout, including the presence and
location of optional records. The resulting knowledge is used to
allocate and locate the user stack space required for the signal
frame and to determine which optional records to include.
The second pass, setup_sigframe(), is called once the stack frame
is allocated in order to populate it with the necessary context
information.
As a result of these changes, it becomes more natural to represent
locations in the signal frame by a base pointer and an offset,
since the absolute address of each location is not known during the
layout pass. To be more consistent with this logic,
parse_user_sigframe() is refactored to describe signal frame
locations in a similar way.
This change has no effect on the signal ABI, but will make it
easier to expand the signal frame in future patches.
Reviewed-by: Catalin Marinas <catalin.marinas@arm.com>
Signed-off-by: Dave Martin <Dave.Martin@arm.com>
Signed-off-by: Will Deacon <will.deacon@arm.com>
2017-06-15 14:03:40 +00:00
|
|
|
if (limit - offset < size)
|
2017-06-15 14:03:39 +00:00
|
|
|
goto invalid;
|
|
|
|
|
|
|
|
offset += size;
|
|
|
|
}
|
|
|
|
|
|
|
|
done:
|
|
|
|
if (!user->fpsimd)
|
|
|
|
goto invalid;
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
invalid:
|
|
|
|
return -EINVAL;
|
|
|
|
}
|
|
|
|
|
2012-03-05 11:49:31 +00:00
|
|
|
static int restore_sigframe(struct pt_regs *regs,
|
|
|
|
struct rt_sigframe __user *sf)
|
|
|
|
{
|
|
|
|
sigset_t set;
|
|
|
|
int i, err;
|
2017-06-15 14:03:39 +00:00
|
|
|
struct user_ctxs user;
|
2012-03-05 11:49:31 +00:00
|
|
|
|
|
|
|
err = __copy_from_user(&set, &sf->uc.uc_sigmask, sizeof(set));
|
|
|
|
if (err == 0)
|
|
|
|
set_current_blocked(&set);
|
|
|
|
|
|
|
|
for (i = 0; i < 31; i++)
|
|
|
|
__get_user_error(regs->regs[i], &sf->uc.uc_mcontext.regs[i],
|
|
|
|
err);
|
|
|
|
__get_user_error(regs->sp, &sf->uc.uc_mcontext.sp, err);
|
|
|
|
__get_user_error(regs->pc, &sf->uc.uc_mcontext.pc, err);
|
|
|
|
__get_user_error(regs->pstate, &sf->uc.uc_mcontext.pstate, err);
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Avoid sys_rt_sigreturn() restarting.
|
|
|
|
*/
|
|
|
|
regs->syscallno = ~0UL;
|
|
|
|
|
2016-03-01 14:18:50 +00:00
|
|
|
err |= !valid_user_regs(®s->user_regs, current);
|
2017-06-15 14:03:39 +00:00
|
|
|
if (err == 0)
|
|
|
|
err = parse_user_sigframe(&user, sf);
|
2012-03-05 11:49:31 +00:00
|
|
|
|
2017-06-15 14:03:39 +00:00
|
|
|
if (err == 0)
|
|
|
|
err = restore_fpsimd_context(user.fpsimd);
|
2012-03-05 11:49:31 +00:00
|
|
|
|
|
|
|
return err;
|
|
|
|
}
|
|
|
|
|
|
|
|
asmlinkage long sys_rt_sigreturn(struct pt_regs *regs)
|
|
|
|
{
|
|
|
|
struct rt_sigframe __user *frame;
|
|
|
|
|
|
|
|
/* Always make any pending restarted system calls return -EINTR */
|
2015-02-12 23:01:14 +00:00
|
|
|
current->restart_block.fn = do_no_restart_syscall;
|
2012-03-05 11:49:31 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Since we stacked the signal on a 128-bit boundary, then 'sp' should
|
|
|
|
* be word aligned here.
|
|
|
|
*/
|
|
|
|
if (regs->sp & 15)
|
|
|
|
goto badframe;
|
|
|
|
|
|
|
|
frame = (struct rt_sigframe __user *)regs->sp;
|
|
|
|
|
|
|
|
if (!access_ok(VERIFY_READ, frame, sizeof (*frame)))
|
|
|
|
goto badframe;
|
|
|
|
|
|
|
|
if (restore_sigframe(regs, frame))
|
|
|
|
goto badframe;
|
|
|
|
|
2012-12-23 06:56:45 +00:00
|
|
|
if (restore_altstack(&frame->uc.uc_stack))
|
2012-03-05 11:49:31 +00:00
|
|
|
goto badframe;
|
|
|
|
|
|
|
|
return regs->regs[0];
|
|
|
|
|
|
|
|
badframe:
|
|
|
|
if (show_unhandled_signals)
|
|
|
|
pr_info_ratelimited("%s[%d]: bad frame in %s: pc=%08llx sp=%08llx\n",
|
|
|
|
current->comm, task_pid_nr(current), __func__,
|
|
|
|
regs->pc, regs->sp);
|
|
|
|
force_sig(SIGSEGV, current);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
arm64: signal: factor frame layout and population into separate passes
In preparation for expanding the signal frame, this patch refactors
the signal frame setup code in setup_sigframe() into two separate
passes.
The first pass, setup_sigframe_layout(), determines the size of the
signal frame and its internal layout, including the presence and
location of optional records. The resulting knowledge is used to
allocate and locate the user stack space required for the signal
frame and to determine which optional records to include.
The second pass, setup_sigframe(), is called once the stack frame
is allocated in order to populate it with the necessary context
information.
As a result of these changes, it becomes more natural to represent
locations in the signal frame by a base pointer and an offset,
since the absolute address of each location is not known during the
layout pass. To be more consistent with this logic,
parse_user_sigframe() is refactored to describe signal frame
locations in a similar way.
This change has no effect on the signal ABI, but will make it
easier to expand the signal frame in future patches.
Reviewed-by: Catalin Marinas <catalin.marinas@arm.com>
Signed-off-by: Dave Martin <Dave.Martin@arm.com>
Signed-off-by: Will Deacon <will.deacon@arm.com>
2017-06-15 14:03:40 +00:00
|
|
|
/* Determine the layout of optional records in the signal frame */
|
|
|
|
static int setup_sigframe_layout(struct rt_sigframe_user_layout *user)
|
|
|
|
{
|
2017-06-15 14:03:41 +00:00
|
|
|
int err;
|
|
|
|
|
|
|
|
err = sigframe_alloc(user, &user->fpsimd_offset,
|
|
|
|
sizeof(struct fpsimd_context));
|
|
|
|
if (err)
|
|
|
|
return err;
|
arm64: signal: factor frame layout and population into separate passes
In preparation for expanding the signal frame, this patch refactors
the signal frame setup code in setup_sigframe() into two separate
passes.
The first pass, setup_sigframe_layout(), determines the size of the
signal frame and its internal layout, including the presence and
location of optional records. The resulting knowledge is used to
allocate and locate the user stack space required for the signal
frame and to determine which optional records to include.
The second pass, setup_sigframe(), is called once the stack frame
is allocated in order to populate it with the necessary context
information.
As a result of these changes, it becomes more natural to represent
locations in the signal frame by a base pointer and an offset,
since the absolute address of each location is not known during the
layout pass. To be more consistent with this logic,
parse_user_sigframe() is refactored to describe signal frame
locations in a similar way.
This change has no effect on the signal ABI, but will make it
easier to expand the signal frame in future patches.
Reviewed-by: Catalin Marinas <catalin.marinas@arm.com>
Signed-off-by: Dave Martin <Dave.Martin@arm.com>
Signed-off-by: Will Deacon <will.deacon@arm.com>
2017-06-15 14:03:40 +00:00
|
|
|
|
|
|
|
/* fault information, if valid */
|
|
|
|
if (current->thread.fault_code) {
|
2017-06-15 14:03:41 +00:00
|
|
|
err = sigframe_alloc(user, &user->esr_offset,
|
|
|
|
sizeof(struct esr_context));
|
|
|
|
if (err)
|
|
|
|
return err;
|
arm64: signal: factor frame layout and population into separate passes
In preparation for expanding the signal frame, this patch refactors
the signal frame setup code in setup_sigframe() into two separate
passes.
The first pass, setup_sigframe_layout(), determines the size of the
signal frame and its internal layout, including the presence and
location of optional records. The resulting knowledge is used to
allocate and locate the user stack space required for the signal
frame and to determine which optional records to include.
The second pass, setup_sigframe(), is called once the stack frame
is allocated in order to populate it with the necessary context
information.
As a result of these changes, it becomes more natural to represent
locations in the signal frame by a base pointer and an offset,
since the absolute address of each location is not known during the
layout pass. To be more consistent with this logic,
parse_user_sigframe() is refactored to describe signal frame
locations in a similar way.
This change has no effect on the signal ABI, but will make it
easier to expand the signal frame in future patches.
Reviewed-by: Catalin Marinas <catalin.marinas@arm.com>
Signed-off-by: Dave Martin <Dave.Martin@arm.com>
Signed-off-by: Will Deacon <will.deacon@arm.com>
2017-06-15 14:03:40 +00:00
|
|
|
}
|
|
|
|
|
2017-06-15 14:03:41 +00:00
|
|
|
/*
|
|
|
|
* Allocate space for the terminator record.
|
|
|
|
* HACK: here we undo the reservation of space for the end record.
|
|
|
|
* This bodge should be replaced with a cleaner approach later on.
|
|
|
|
*/
|
|
|
|
user->limit = offsetof(struct rt_sigframe, uc.uc_mcontext.__reserved) +
|
|
|
|
sizeof(user->sigframe->uc.uc_mcontext.__reserved);
|
arm64: signal: factor frame layout and population into separate passes
In preparation for expanding the signal frame, this patch refactors
the signal frame setup code in setup_sigframe() into two separate
passes.
The first pass, setup_sigframe_layout(), determines the size of the
signal frame and its internal layout, including the presence and
location of optional records. The resulting knowledge is used to
allocate and locate the user stack space required for the signal
frame and to determine which optional records to include.
The second pass, setup_sigframe(), is called once the stack frame
is allocated in order to populate it with the necessary context
information.
As a result of these changes, it becomes more natural to represent
locations in the signal frame by a base pointer and an offset,
since the absolute address of each location is not known during the
layout pass. To be more consistent with this logic,
parse_user_sigframe() is refactored to describe signal frame
locations in a similar way.
This change has no effect on the signal ABI, but will make it
easier to expand the signal frame in future patches.
Reviewed-by: Catalin Marinas <catalin.marinas@arm.com>
Signed-off-by: Dave Martin <Dave.Martin@arm.com>
Signed-off-by: Will Deacon <will.deacon@arm.com>
2017-06-15 14:03:40 +00:00
|
|
|
|
2017-06-15 14:03:41 +00:00
|
|
|
err = sigframe_alloc(user, &user->end_offset,
|
|
|
|
sizeof(struct _aarch64_ctx));
|
|
|
|
return err;
|
arm64: signal: factor frame layout and population into separate passes
In preparation for expanding the signal frame, this patch refactors
the signal frame setup code in setup_sigframe() into two separate
passes.
The first pass, setup_sigframe_layout(), determines the size of the
signal frame and its internal layout, including the presence and
location of optional records. The resulting knowledge is used to
allocate and locate the user stack space required for the signal
frame and to determine which optional records to include.
The second pass, setup_sigframe(), is called once the stack frame
is allocated in order to populate it with the necessary context
information.
As a result of these changes, it becomes more natural to represent
locations in the signal frame by a base pointer and an offset,
since the absolute address of each location is not known during the
layout pass. To be more consistent with this logic,
parse_user_sigframe() is refactored to describe signal frame
locations in a similar way.
This change has no effect on the signal ABI, but will make it
easier to expand the signal frame in future patches.
Reviewed-by: Catalin Marinas <catalin.marinas@arm.com>
Signed-off-by: Dave Martin <Dave.Martin@arm.com>
Signed-off-by: Will Deacon <will.deacon@arm.com>
2017-06-15 14:03:40 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2017-06-15 14:03:38 +00:00
|
|
|
static int setup_sigframe(struct rt_sigframe_user_layout *user,
|
2012-03-05 11:49:31 +00:00
|
|
|
struct pt_regs *regs, sigset_t *set)
|
|
|
|
{
|
|
|
|
int i, err = 0;
|
2017-06-15 14:03:38 +00:00
|
|
|
struct rt_sigframe __user *sf = user->sigframe;
|
2012-03-05 11:49:31 +00:00
|
|
|
|
2012-11-23 12:34:13 +00:00
|
|
|
/* set up the stack frame for unwinding */
|
2017-06-15 14:03:38 +00:00
|
|
|
__put_user_error(regs->regs[29], &user->next_frame->fp, err);
|
|
|
|
__put_user_error(regs->regs[30], &user->next_frame->lr, err);
|
2012-11-23 12:34:13 +00:00
|
|
|
|
2012-03-05 11:49:31 +00:00
|
|
|
for (i = 0; i < 31; i++)
|
|
|
|
__put_user_error(regs->regs[i], &sf->uc.uc_mcontext.regs[i],
|
|
|
|
err);
|
|
|
|
__put_user_error(regs->sp, &sf->uc.uc_mcontext.sp, err);
|
|
|
|
__put_user_error(regs->pc, &sf->uc.uc_mcontext.pc, err);
|
|
|
|
__put_user_error(regs->pstate, &sf->uc.uc_mcontext.pstate, err);
|
|
|
|
|
|
|
|
__put_user_error(current->thread.fault_address, &sf->uc.uc_mcontext.fault_address, err);
|
|
|
|
|
|
|
|
err |= __copy_to_user(&sf->uc.uc_sigmask, set, sizeof(*set));
|
|
|
|
|
2014-04-04 14:42:16 +00:00
|
|
|
if (err == 0) {
|
arm64: signal: factor frame layout and population into separate passes
In preparation for expanding the signal frame, this patch refactors
the signal frame setup code in setup_sigframe() into two separate
passes.
The first pass, setup_sigframe_layout(), determines the size of the
signal frame and its internal layout, including the presence and
location of optional records. The resulting knowledge is used to
allocate and locate the user stack space required for the signal
frame and to determine which optional records to include.
The second pass, setup_sigframe(), is called once the stack frame
is allocated in order to populate it with the necessary context
information.
As a result of these changes, it becomes more natural to represent
locations in the signal frame by a base pointer and an offset,
since the absolute address of each location is not known during the
layout pass. To be more consistent with this logic,
parse_user_sigframe() is refactored to describe signal frame
locations in a similar way.
This change has no effect on the signal ABI, but will make it
easier to expand the signal frame in future patches.
Reviewed-by: Catalin Marinas <catalin.marinas@arm.com>
Signed-off-by: Dave Martin <Dave.Martin@arm.com>
Signed-off-by: Will Deacon <will.deacon@arm.com>
2017-06-15 14:03:40 +00:00
|
|
|
struct fpsimd_context __user *fpsimd_ctx =
|
|
|
|
apply_user_offset(user, user->fpsimd_offset);
|
2014-04-04 14:42:16 +00:00
|
|
|
err |= preserve_fpsimd_context(fpsimd_ctx);
|
|
|
|
}
|
2012-03-05 11:49:31 +00:00
|
|
|
|
2013-09-16 14:19:27 +00:00
|
|
|
/* fault information, if valid */
|
arm64: signal: factor frame layout and population into separate passes
In preparation for expanding the signal frame, this patch refactors
the signal frame setup code in setup_sigframe() into two separate
passes.
The first pass, setup_sigframe_layout(), determines the size of the
signal frame and its internal layout, including the presence and
location of optional records. The resulting knowledge is used to
allocate and locate the user stack space required for the signal
frame and to determine which optional records to include.
The second pass, setup_sigframe(), is called once the stack frame
is allocated in order to populate it with the necessary context
information.
As a result of these changes, it becomes more natural to represent
locations in the signal frame by a base pointer and an offset,
since the absolute address of each location is not known during the
layout pass. To be more consistent with this logic,
parse_user_sigframe() is refactored to describe signal frame
locations in a similar way.
This change has no effect on the signal ABI, but will make it
easier to expand the signal frame in future patches.
Reviewed-by: Catalin Marinas <catalin.marinas@arm.com>
Signed-off-by: Dave Martin <Dave.Martin@arm.com>
Signed-off-by: Will Deacon <will.deacon@arm.com>
2017-06-15 14:03:40 +00:00
|
|
|
if (err == 0 && user->esr_offset) {
|
|
|
|
struct esr_context __user *esr_ctx =
|
|
|
|
apply_user_offset(user, user->esr_offset);
|
|
|
|
|
2013-09-16 14:19:27 +00:00
|
|
|
__put_user_error(ESR_MAGIC, &esr_ctx->head.magic, err);
|
|
|
|
__put_user_error(sizeof(*esr_ctx), &esr_ctx->head.size, err);
|
|
|
|
__put_user_error(current->thread.fault_code, &esr_ctx->esr, err);
|
|
|
|
}
|
|
|
|
|
2012-03-05 11:49:31 +00:00
|
|
|
/* set the "end" magic */
|
arm64: signal: factor frame layout and population into separate passes
In preparation for expanding the signal frame, this patch refactors
the signal frame setup code in setup_sigframe() into two separate
passes.
The first pass, setup_sigframe_layout(), determines the size of the
signal frame and its internal layout, including the presence and
location of optional records. The resulting knowledge is used to
allocate and locate the user stack space required for the signal
frame and to determine which optional records to include.
The second pass, setup_sigframe(), is called once the stack frame
is allocated in order to populate it with the necessary context
information.
As a result of these changes, it becomes more natural to represent
locations in the signal frame by a base pointer and an offset,
since the absolute address of each location is not known during the
layout pass. To be more consistent with this logic,
parse_user_sigframe() is refactored to describe signal frame
locations in a similar way.
This change has no effect on the signal ABI, but will make it
easier to expand the signal frame in future patches.
Reviewed-by: Catalin Marinas <catalin.marinas@arm.com>
Signed-off-by: Dave Martin <Dave.Martin@arm.com>
Signed-off-by: Will Deacon <will.deacon@arm.com>
2017-06-15 14:03:40 +00:00
|
|
|
if (err == 0) {
|
|
|
|
struct _aarch64_ctx __user *end =
|
|
|
|
apply_user_offset(user, user->end_offset);
|
|
|
|
|
|
|
|
__put_user_error(0, &end->magic, err);
|
|
|
|
__put_user_error(0, &end->size, err);
|
|
|
|
}
|
2012-03-05 11:49:31 +00:00
|
|
|
|
|
|
|
return err;
|
|
|
|
}
|
|
|
|
|
2017-06-15 14:03:38 +00:00
|
|
|
static int get_sigframe(struct rt_sigframe_user_layout *user,
|
|
|
|
struct ksignal *ksig, struct pt_regs *regs)
|
2012-03-05 11:49:31 +00:00
|
|
|
{
|
|
|
|
unsigned long sp, sp_top;
|
arm64: signal: factor frame layout and population into separate passes
In preparation for expanding the signal frame, this patch refactors
the signal frame setup code in setup_sigframe() into two separate
passes.
The first pass, setup_sigframe_layout(), determines the size of the
signal frame and its internal layout, including the presence and
location of optional records. The resulting knowledge is used to
allocate and locate the user stack space required for the signal
frame and to determine which optional records to include.
The second pass, setup_sigframe(), is called once the stack frame
is allocated in order to populate it with the necessary context
information.
As a result of these changes, it becomes more natural to represent
locations in the signal frame by a base pointer and an offset,
since the absolute address of each location is not known during the
layout pass. To be more consistent with this logic,
parse_user_sigframe() is refactored to describe signal frame
locations in a similar way.
This change has no effect on the signal ABI, but will make it
easier to expand the signal frame in future patches.
Reviewed-by: Catalin Marinas <catalin.marinas@arm.com>
Signed-off-by: Dave Martin <Dave.Martin@arm.com>
Signed-off-by: Will Deacon <will.deacon@arm.com>
2017-06-15 14:03:40 +00:00
|
|
|
int err;
|
|
|
|
|
|
|
|
init_user_layout(user);
|
|
|
|
err = setup_sigframe_layout(user);
|
|
|
|
if (err)
|
|
|
|
return err;
|
2012-03-05 11:49:31 +00:00
|
|
|
|
2014-03-05 12:31:20 +00:00
|
|
|
sp = sp_top = sigsp(regs->sp, ksig);
|
2012-03-05 11:49:31 +00:00
|
|
|
|
2017-06-15 14:03:38 +00:00
|
|
|
sp = round_down(sp - sizeof(struct frame_record), 16);
|
|
|
|
user->next_frame = (struct frame_record __user *)sp;
|
|
|
|
|
arm64: signal: factor frame layout and population into separate passes
In preparation for expanding the signal frame, this patch refactors
the signal frame setup code in setup_sigframe() into two separate
passes.
The first pass, setup_sigframe_layout(), determines the size of the
signal frame and its internal layout, including the presence and
location of optional records. The resulting knowledge is used to
allocate and locate the user stack space required for the signal
frame and to determine which optional records to include.
The second pass, setup_sigframe(), is called once the stack frame
is allocated in order to populate it with the necessary context
information.
As a result of these changes, it becomes more natural to represent
locations in the signal frame by a base pointer and an offset,
since the absolute address of each location is not known during the
layout pass. To be more consistent with this logic,
parse_user_sigframe() is refactored to describe signal frame
locations in a similar way.
This change has no effect on the signal ABI, but will make it
easier to expand the signal frame in future patches.
Reviewed-by: Catalin Marinas <catalin.marinas@arm.com>
Signed-off-by: Dave Martin <Dave.Martin@arm.com>
Signed-off-by: Will Deacon <will.deacon@arm.com>
2017-06-15 14:03:40 +00:00
|
|
|
sp = round_down(sp, 16) - sigframe_size(user);
|
2017-06-15 14:03:38 +00:00
|
|
|
user->sigframe = (struct rt_sigframe __user *)sp;
|
2012-03-05 11:49:31 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Check that we can actually write to the signal frame.
|
|
|
|
*/
|
2017-06-15 14:03:38 +00:00
|
|
|
if (!access_ok(VERIFY_WRITE, user->sigframe, sp_top - sp))
|
|
|
|
return -EFAULT;
|
2012-03-05 11:49:31 +00:00
|
|
|
|
2017-06-15 14:03:38 +00:00
|
|
|
return 0;
|
2012-03-05 11:49:31 +00:00
|
|
|
}
|
|
|
|
|
2012-11-23 12:34:13 +00:00
|
|
|
static void setup_return(struct pt_regs *regs, struct k_sigaction *ka,
|
2017-06-15 14:03:38 +00:00
|
|
|
struct rt_sigframe_user_layout *user, int usig)
|
2012-03-05 11:49:31 +00:00
|
|
|
{
|
|
|
|
__sigrestore_t sigtramp;
|
|
|
|
|
|
|
|
regs->regs[0] = usig;
|
2017-06-15 14:03:38 +00:00
|
|
|
regs->sp = (unsigned long)user->sigframe;
|
|
|
|
regs->regs[29] = (unsigned long)&user->next_frame->fp;
|
2012-03-05 11:49:31 +00:00
|
|
|
regs->pc = (unsigned long)ka->sa.sa_handler;
|
|
|
|
|
|
|
|
if (ka->sa.sa_flags & SA_RESTORER)
|
|
|
|
sigtramp = ka->sa.sa_restorer;
|
|
|
|
else
|
|
|
|
sigtramp = VDSO_SYMBOL(current->mm->context.vdso, sigtramp);
|
|
|
|
|
|
|
|
regs->regs[30] = (unsigned long)sigtramp;
|
|
|
|
}
|
|
|
|
|
2013-10-06 20:52:44 +00:00
|
|
|
static int setup_rt_frame(int usig, struct ksignal *ksig, sigset_t *set,
|
|
|
|
struct pt_regs *regs)
|
2012-03-05 11:49:31 +00:00
|
|
|
{
|
2017-06-15 14:03:38 +00:00
|
|
|
struct rt_sigframe_user_layout user;
|
2012-03-05 11:49:31 +00:00
|
|
|
struct rt_sigframe __user *frame;
|
|
|
|
int err = 0;
|
|
|
|
|
2017-06-15 14:03:38 +00:00
|
|
|
if (get_sigframe(&user, ksig, regs))
|
2012-03-05 11:49:31 +00:00
|
|
|
return 1;
|
|
|
|
|
2017-06-15 14:03:38 +00:00
|
|
|
frame = user.sigframe;
|
|
|
|
|
2012-03-05 11:49:31 +00:00
|
|
|
__put_user_error(0, &frame->uc.uc_flags, err);
|
|
|
|
__put_user_error(NULL, &frame->uc.uc_link, err);
|
|
|
|
|
2012-12-23 06:56:45 +00:00
|
|
|
err |= __save_altstack(&frame->uc.uc_stack, regs->sp);
|
2017-06-15 14:03:38 +00:00
|
|
|
err |= setup_sigframe(&user, regs, set);
|
2012-11-23 12:34:13 +00:00
|
|
|
if (err == 0) {
|
2017-06-15 14:03:38 +00:00
|
|
|
setup_return(regs, &ksig->ka, &user, usig);
|
2013-10-06 20:52:44 +00:00
|
|
|
if (ksig->ka.sa.sa_flags & SA_SIGINFO) {
|
|
|
|
err |= copy_siginfo_to_user(&frame->info, &ksig->info);
|
2012-11-23 12:34:13 +00:00
|
|
|
regs->regs[1] = (unsigned long)&frame->info;
|
|
|
|
regs->regs[2] = (unsigned long)&frame->uc;
|
|
|
|
}
|
2012-03-05 11:49:31 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return err;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void setup_restart_syscall(struct pt_regs *regs)
|
|
|
|
{
|
|
|
|
if (is_compat_task())
|
|
|
|
compat_setup_restart_syscall(regs);
|
|
|
|
else
|
|
|
|
regs->regs[8] = __NR_restart_syscall;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* OK, we're invoking a handler
|
|
|
|
*/
|
2013-10-06 20:52:44 +00:00
|
|
|
static void handle_signal(struct ksignal *ksig, struct pt_regs *regs)
|
2012-03-05 11:49:31 +00:00
|
|
|
{
|
|
|
|
struct task_struct *tsk = current;
|
|
|
|
sigset_t *oldset = sigmask_to_save();
|
2013-10-06 20:52:44 +00:00
|
|
|
int usig = ksig->sig;
|
2012-03-05 11:49:31 +00:00
|
|
|
int ret;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Set up the stack frame
|
|
|
|
*/
|
|
|
|
if (is_compat_task()) {
|
2013-10-06 20:52:44 +00:00
|
|
|
if (ksig->ka.sa.sa_flags & SA_SIGINFO)
|
|
|
|
ret = compat_setup_rt_frame(usig, ksig, oldset, regs);
|
2012-03-05 11:49:31 +00:00
|
|
|
else
|
2013-10-06 20:52:44 +00:00
|
|
|
ret = compat_setup_frame(usig, ksig, oldset, regs);
|
2012-03-05 11:49:31 +00:00
|
|
|
} else {
|
2013-10-06 20:52:44 +00:00
|
|
|
ret = setup_rt_frame(usig, ksig, oldset, regs);
|
2012-03-05 11:49:31 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Check that the resulting registers are actually sane.
|
|
|
|
*/
|
2016-03-01 14:18:50 +00:00
|
|
|
ret |= !valid_user_regs(®s->user_regs, current);
|
2012-03-05 11:49:31 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Fast forward the stepping logic so we step into the signal
|
|
|
|
* handler.
|
|
|
|
*/
|
2013-10-06 20:52:44 +00:00
|
|
|
if (!ret)
|
|
|
|
user_fastforward_single_step(tsk);
|
2012-03-05 11:49:31 +00:00
|
|
|
|
2013-10-06 20:52:44 +00:00
|
|
|
signal_setup_done(ret, ksig, 0);
|
2012-03-05 11:49:31 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Note that 'init' is a special process: it doesn't get signals it doesn't
|
|
|
|
* want to handle. Thus you cannot kill init even with a SIGKILL even by
|
|
|
|
* mistake.
|
|
|
|
*
|
|
|
|
* Note that we go through the signals twice: once to check the signals that
|
|
|
|
* the kernel can handle, and then we build all the user-level signal handling
|
|
|
|
* stack-frames in one go after that.
|
|
|
|
*/
|
|
|
|
static void do_signal(struct pt_regs *regs)
|
|
|
|
{
|
|
|
|
unsigned long continue_addr = 0, restart_addr = 0;
|
2013-10-06 20:52:44 +00:00
|
|
|
int retval = 0;
|
2012-03-05 11:49:31 +00:00
|
|
|
int syscall = (int)regs->syscallno;
|
2013-10-06 20:52:44 +00:00
|
|
|
struct ksignal ksig;
|
2012-03-05 11:49:31 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* If we were from a system call, check for system call restarting...
|
|
|
|
*/
|
|
|
|
if (syscall >= 0) {
|
|
|
|
continue_addr = regs->pc;
|
|
|
|
restart_addr = continue_addr - (compat_thumb_mode(regs) ? 2 : 4);
|
|
|
|
retval = regs->regs[0];
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Avoid additional syscall restarting via ret_to_user.
|
|
|
|
*/
|
|
|
|
regs->syscallno = ~0UL;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Prepare for system call restart. We do this here so that a
|
|
|
|
* debugger will see the already changed PC.
|
|
|
|
*/
|
|
|
|
switch (retval) {
|
|
|
|
case -ERESTARTNOHAND:
|
|
|
|
case -ERESTARTSYS:
|
|
|
|
case -ERESTARTNOINTR:
|
|
|
|
case -ERESTART_RESTARTBLOCK:
|
|
|
|
regs->regs[0] = regs->orig_x0;
|
|
|
|
regs->pc = restart_addr;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Get the signal to deliver. When running under ptrace, at this point
|
|
|
|
* the debugger may change all of our registers.
|
|
|
|
*/
|
2013-10-06 20:52:44 +00:00
|
|
|
if (get_signal(&ksig)) {
|
2012-03-05 11:49:31 +00:00
|
|
|
/*
|
|
|
|
* Depending on the signal settings, we may need to revert the
|
|
|
|
* decision to restart the system call, but skip this if a
|
|
|
|
* debugger has chosen to restart at a different PC.
|
|
|
|
*/
|
|
|
|
if (regs->pc == restart_addr &&
|
|
|
|
(retval == -ERESTARTNOHAND ||
|
|
|
|
retval == -ERESTART_RESTARTBLOCK ||
|
|
|
|
(retval == -ERESTARTSYS &&
|
2013-10-06 20:52:44 +00:00
|
|
|
!(ksig.ka.sa.sa_flags & SA_RESTART)))) {
|
2012-03-05 11:49:31 +00:00
|
|
|
regs->regs[0] = -EINTR;
|
|
|
|
regs->pc = continue_addr;
|
|
|
|
}
|
|
|
|
|
2013-10-06 20:52:44 +00:00
|
|
|
handle_signal(&ksig, regs);
|
2012-03-05 11:49:31 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Handle restarting a different system call. As above, if a debugger
|
|
|
|
* has chosen to restart at a different PC, ignore the restart.
|
|
|
|
*/
|
|
|
|
if (syscall >= 0 && regs->pc == restart_addr) {
|
|
|
|
if (retval == -ERESTART_RESTARTBLOCK)
|
|
|
|
setup_restart_syscall(regs);
|
|
|
|
user_rewind_single_step(current);
|
|
|
|
}
|
|
|
|
|
|
|
|
restore_saved_sigmask();
|
|
|
|
}
|
|
|
|
|
|
|
|
asmlinkage void do_notify_resume(struct pt_regs *regs,
|
|
|
|
unsigned int thread_flags)
|
|
|
|
{
|
2016-07-14 20:48:14 +00:00
|
|
|
/*
|
|
|
|
* The assembly code enters us with IRQs off, but it hasn't
|
|
|
|
* informed the tracing code of that for efficiency reasons.
|
|
|
|
* Update the trace code with the current status.
|
|
|
|
*/
|
|
|
|
trace_hardirqs_off();
|
|
|
|
do {
|
|
|
|
if (thread_flags & _TIF_NEED_RESCHED) {
|
|
|
|
schedule();
|
|
|
|
} else {
|
|
|
|
local_irq_enable();
|
|
|
|
|
2016-11-02 09:10:46 +00:00
|
|
|
if (thread_flags & _TIF_UPROBE)
|
|
|
|
uprobe_notify_resume(regs);
|
|
|
|
|
2016-07-14 20:48:14 +00:00
|
|
|
if (thread_flags & _TIF_SIGPENDING)
|
|
|
|
do_signal(regs);
|
|
|
|
|
|
|
|
if (thread_flags & _TIF_NOTIFY_RESUME) {
|
|
|
|
clear_thread_flag(TIF_NOTIFY_RESUME);
|
|
|
|
tracehook_notify_resume(regs);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (thread_flags & _TIF_FOREIGN_FPSTATE)
|
|
|
|
fpsimd_restore_current_state();
|
|
|
|
}
|
2014-05-08 09:20:23 +00:00
|
|
|
|
2016-07-14 20:48:14 +00:00
|
|
|
local_irq_disable();
|
|
|
|
thread_flags = READ_ONCE(current_thread_info()->flags);
|
|
|
|
} while (thread_flags & _TIF_WORK_MASK);
|
2012-03-05 11:49:31 +00:00
|
|
|
}
|