2019-06-03 08:44:50 +03:00
|
|
|
// SPDX-License-Identifier: GPL-2.0-only
|
2012-03-05 15:49:31 +04:00
|
|
|
/*
|
|
|
|
* Based on arch/arm/kernel/signal.c
|
|
|
|
*
|
|
|
|
* Copyright (C) 1995-2009 Russell King
|
|
|
|
* Copyright (C) 2012 ARM Ltd.
|
|
|
|
*/
|
|
|
|
|
arm64: signal: Report signal frame size to userspace via auxv
Stateful CPU architecture extensions may require the signal frame
to grow to a size that exceeds the arch's MINSIGSTKSZ #define.
However, changing this #define is an ABI break.
To allow userspace the option of determining the signal frame size
in a more forwards-compatible way, this patch adds a new auxv entry
tagged with AT_MINSIGSTKSZ, which provides the maximum signal frame
size that the process can observe during its lifetime.
If AT_MINSIGSTKSZ is absent from the aux vector, the caller can
assume that the MINSIGSTKSZ #define is sufficient. This allows for
a consistent interface with older kernels that do not provide
AT_MINSIGSTKSZ.
The idea is that libc could expose this via sysconf() or some
similar mechanism.
There is deliberately no AT_SIGSTKSZ. The kernel knows nothing
about userspace's own stack overheads and should not pretend to
know.
For arm64:
The primary motivation for this interface is the Scalable Vector
Extension, which can require at least 4KB or so of extra space
in the signal frame for the largest hardware implementations.
To determine the correct value, a "Christmas tree" mode (via the
add_all argument) is added to setup_sigframe_layout(), to simulate
addition of all possible records to the signal frame at maximum
possible size.
If this procedure goes wrong somehow, resulting in a stupidly large
frame layout and hence failure of sigframe_alloc() to allocate a
record to the frame, then this is indicative of a kernel bug. In
this case, we WARN() and no attempt is made to populate
AT_MINSIGSTKSZ for userspace.
For arm64 SVE:
The SVE context block in the signal frame needs to be considered
too when computing the maximum possible signal frame size.
Because the size of this block depends on the vector length, this
patch computes the size based not on the thread's current vector
length but instead on the maximum possible vector length: this
determines the maximum size of SVE context block that can be
observed in any signal frame for the lifetime of the process.
Signed-off-by: Dave Martin <Dave.Martin@arm.com>
Acked-by: Will Deacon <will.deacon@arm.com>
Cc: Ard Biesheuvel <ard.biesheuvel@linaro.org>
Cc: Alex Bennée <alex.bennee@linaro.org>
Signed-off-by: Catalin Marinas <catalin.marinas@arm.com>
2018-06-01 13:10:14 +03:00
|
|
|
#include <linux/cache.h>
|
2014-04-30 13:51:32 +04:00
|
|
|
#include <linux/compat.h>
|
2012-03-05 15:49:31 +04:00
|
|
|
#include <linux/errno.h>
|
2017-06-15 17:03:38 +03:00
|
|
|
#include <linux/kernel.h>
|
2012-03-05 15:49:31 +04:00
|
|
|
#include <linux/signal.h>
|
|
|
|
#include <linux/personality.h>
|
|
|
|
#include <linux/freezer.h>
|
2017-06-15 17:03:39 +03:00
|
|
|
#include <linux/stddef.h>
|
2012-03-05 15:49:31 +04:00
|
|
|
#include <linux/uaccess.h>
|
2017-06-20 20:23:39 +03:00
|
|
|
#include <linux/sizes.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 17:03:40 +03:00
|
|
|
#include <linux/string.h>
|
2012-03-05 15:49:31 +04:00
|
|
|
#include <linux/tracehook.h>
|
|
|
|
#include <linux/ratelimit.h>
|
2017-06-15 04:12:03 +03:00
|
|
|
#include <linux/syscalls.h>
|
2012-03-05 15:49:31 +04:00
|
|
|
|
2017-11-02 15:12:37 +03:00
|
|
|
#include <asm/daifflags.h>
|
2012-03-05 15:49:31 +04:00
|
|
|
#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>
|
2017-08-01 17:35:54 +03:00
|
|
|
#include <asm/ptrace.h>
|
2012-03-05 15:49:31 +04:00
|
|
|
#include <asm/signal32.h>
|
2018-02-20 18:05:17 +03:00
|
|
|
#include <asm/traps.h>
|
2012-03-05 15:49:31 +04:00
|
|
|
#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 17:03:38 +03:00
|
|
|
};
|
|
|
|
|
|
|
|
struct frame_record {
|
2012-11-23 16:34:13 +04:00
|
|
|
u64 fp;
|
|
|
|
u64 lr;
|
2012-03-05 15:49:31 +04:00
|
|
|
};
|
|
|
|
|
2017-06-15 17:03:38 +03: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 17:03:40 +03:00
|
|
|
|
|
|
|
unsigned long size; /* size of allocated sigframe data */
|
|
|
|
unsigned long limit; /* largest allowed size */
|
|
|
|
|
|
|
|
unsigned long fpsimd_offset;
|
|
|
|
unsigned long esr_offset;
|
arm64/sve: Signal handling support
This patch implements support for saving and restoring the SVE
registers around signals.
A fixed-size header struct sve_context is always included in the
signal frame encoding the thread's vector length at the time of
signal delivery, optionally followed by a variable-layout structure
encoding the SVE registers.
Because of the need to preserve backwards compatibility, the FPSIMD
view of the SVE registers is always dumped as a struct
fpsimd_context in the usual way, in addition to any sve_context.
The SVE vector registers are dumped in full, including bits 127:0
of each register which alias the corresponding FPSIMD vector
registers in the hardware. To avoid any ambiguity about which
alias to restore during sigreturn, the kernel always restores bits
127:0 of each SVE vector register from the fpsimd_context in the
signal frame (which must be present): userspace needs to take this
into account if it wants to modify the SVE vector register contents
on return from a signal.
FPSR and FPCR, which are used by both FPSIMD and SVE, are not
included in sve_context because they are always present in
fpsimd_context anyway.
For signal delivery, a new helper
fpsimd_signal_preserve_current_state() is added to update _both_
the FPSIMD and SVE views in the task struct, to make it easier to
populate this information into the signal frame. Because of the
redundancy between the two views of the state, only one is updated
otherwise.
Reviewed-by: Catalin Marinas <catalin.marinas@arm.com>
Signed-off-by: Dave Martin <Dave.Martin@arm.com>
Cc: Alex Bennée <alex.bennee@linaro.org>
Cc: Ard Biesheuvel <ard.biesheuvel@linaro.org>
Cc: Will Deacon <will.deacon@arm.com>
Signed-off-by: Will Deacon <will.deacon@arm.com>
2017-10-31 18:51:07 +03:00
|
|
|
unsigned long sve_offset;
|
2017-06-20 20:23:39 +03:00
|
|
|
unsigned long extra_offset;
|
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 17:03:40 +03:00
|
|
|
unsigned long end_offset;
|
2017-06-15 17:03:38 +03:00
|
|
|
};
|
|
|
|
|
2017-06-20 20:23:39 +03:00
|
|
|
#define BASE_SIGFRAME_SIZE round_up(sizeof(struct rt_sigframe), 16)
|
|
|
|
#define TERMINATOR_SIZE round_up(sizeof(struct _aarch64_ctx), 16)
|
|
|
|
#define EXTRA_CONTEXT_SIZE round_up(sizeof(struct extra_context), 16)
|
|
|
|
|
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 17:03:40 +03:00
|
|
|
static void init_user_layout(struct rt_sigframe_user_layout *user)
|
|
|
|
{
|
2017-06-20 20:23:39 +03:00
|
|
|
const size_t reserved_size =
|
|
|
|
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 17:03:40 +03:00
|
|
|
memset(user, 0, sizeof(*user));
|
|
|
|
user->size = offsetof(struct rt_sigframe, uc.uc_mcontext.__reserved);
|
|
|
|
|
2017-06-20 20:23:39 +03:00
|
|
|
user->limit = user->size + reserved_size;
|
|
|
|
|
|
|
|
user->limit -= TERMINATOR_SIZE;
|
|
|
|
user->limit -= EXTRA_CONTEXT_SIZE;
|
|
|
|
/* Reserve space for extension and terminator ^ */
|
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 17:03:40 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
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-20 20:23:39 +03:00
|
|
|
/*
|
|
|
|
* Sanity limit on the approximate maximum size of signal frame we'll
|
|
|
|
* try to generate. Stack alignment padding and the frame record are
|
|
|
|
* not taken into account. This limit is not a guarantee and is
|
|
|
|
* NOT ABI.
|
|
|
|
*/
|
|
|
|
#define SIGFRAME_MAXSZ SZ_64K
|
|
|
|
|
|
|
|
static int __sigframe_alloc(struct rt_sigframe_user_layout *user,
|
|
|
|
unsigned long *offset, size_t size, bool extend)
|
|
|
|
{
|
|
|
|
size_t padded_size = round_up(size, 16);
|
|
|
|
|
|
|
|
if (padded_size > user->limit - user->size &&
|
|
|
|
!user->extra_offset &&
|
|
|
|
extend) {
|
|
|
|
int ret;
|
|
|
|
|
|
|
|
user->limit += EXTRA_CONTEXT_SIZE;
|
|
|
|
ret = __sigframe_alloc(user, &user->extra_offset,
|
|
|
|
sizeof(struct extra_context), false);
|
|
|
|
if (ret) {
|
|
|
|
user->limit -= EXTRA_CONTEXT_SIZE;
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Reserve space for the __reserved[] terminator */
|
|
|
|
user->size += TERMINATOR_SIZE;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Allow expansion up to SIGFRAME_MAXSZ, ensuring space for
|
|
|
|
* the terminator:
|
|
|
|
*/
|
|
|
|
user->limit = SIGFRAME_MAXSZ - TERMINATOR_SIZE;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Still not enough space? Bad luck! */
|
|
|
|
if (padded_size > user->limit - user->size)
|
|
|
|
return -ENOMEM;
|
|
|
|
|
|
|
|
*offset = user->size;
|
|
|
|
user->size += padded_size;
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2017-06-15 17:03:41 +03: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)
|
|
|
|
{
|
2017-06-20 20:23:39 +03:00
|
|
|
return __sigframe_alloc(user, offset, size, true);
|
|
|
|
}
|
2017-06-15 17:03:41 +03:00
|
|
|
|
2017-06-20 20:23:39 +03:00
|
|
|
/* Allocate the null terminator record and prevent further allocations */
|
|
|
|
static int sigframe_alloc_end(struct rt_sigframe_user_layout *user)
|
|
|
|
{
|
|
|
|
int ret;
|
2017-06-15 17:03:41 +03:00
|
|
|
|
2017-06-20 20:23:39 +03:00
|
|
|
/* Un-reserve the space reserved for the terminator: */
|
|
|
|
user->limit += TERMINATOR_SIZE;
|
|
|
|
|
|
|
|
ret = sigframe_alloc(user, &user->end_offset,
|
|
|
|
sizeof(struct _aarch64_ctx));
|
|
|
|
if (ret)
|
|
|
|
return ret;
|
|
|
|
|
|
|
|
/* Prevent further allocation: */
|
|
|
|
user->limit = user->size;
|
2017-06-15 17:03:41 +03:00
|
|
|
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 17:03:40 +03: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 15:49:31 +04:00
|
|
|
static int preserve_fpsimd_context(struct fpsimd_context __user *ctx)
|
|
|
|
{
|
2018-03-28 12:50:49 +03:00
|
|
|
struct user_fpsimd_state const *fpsimd =
|
|
|
|
¤t->thread.uw.fpsimd_state;
|
2012-03-05 15:49:31 +04:00
|
|
|
int err;
|
|
|
|
|
|
|
|
/* 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)
|
|
|
|
{
|
arm64: fpsimd: Fix state leakage when migrating after sigreturn
When refactoring the sigreturn code to handle SVE, I changed the
sigreturn implementation to store the new FPSIMD state from the
user sigframe into task_struct before reloading the state into the
CPU regs. This makes it easier to convert the data for SVE when
needed.
However, it turns out that the fpsimd_state structure passed into
fpsimd_update_current_state is not fully initialised, so assigning
the structure as a whole corrupts current->thread.fpsimd_state.cpu
with uninitialised data.
This means that if the garbage data written to .cpu happens to be a
valid cpu number, and the task is subsequently migrated to the cpu
identified by the that number, and then tries to enter userspace,
the CPU FPSIMD regs will be assumed to be correct for the task and
not reloaded as they should be. This can result in returning to
userspace with the FPSIMD registers containing data that is stale or
that belongs to another task or to the kernel.
Knowingly handing around a kernel structure that is incompletely
initialised with user data is a potential source of mistakes,
especially across source file boundaries. To help avoid a repeat
of this issue, this patch adapts the relevant internal API to hand
around the user-accessible subset only: struct user_fpsimd_state.
To avoid future surprises, this patch also converts all uses of
struct fpsimd_state that really only access the user subset, to use
struct user_fpsimd_state. A few missing consts are added to
function prototypes for good measure.
Thanks to Will for spotting the cause of the bug here.
Reported-by: Geert Uytterhoeven <geert@linux-m68k.org>
Signed-off-by: Dave Martin <Dave.Martin@arm.com>
Cc: Will Deacon <will.deacon@arm.com>
Cc: Ard Biesheuvel <ard.biesheuvel@linaro.org>
Signed-off-by: Catalin Marinas <catalin.marinas@arm.com>
2017-12-15 21:34:38 +03:00
|
|
|
struct user_fpsimd_state fpsimd;
|
2012-03-05 15:49:31 +04:00
|
|
|
__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);
|
|
|
|
|
arm64/sve: Signal handling support
This patch implements support for saving and restoring the SVE
registers around signals.
A fixed-size header struct sve_context is always included in the
signal frame encoding the thread's vector length at the time of
signal delivery, optionally followed by a variable-layout structure
encoding the SVE registers.
Because of the need to preserve backwards compatibility, the FPSIMD
view of the SVE registers is always dumped as a struct
fpsimd_context in the usual way, in addition to any sve_context.
The SVE vector registers are dumped in full, including bits 127:0
of each register which alias the corresponding FPSIMD vector
registers in the hardware. To avoid any ambiguity about which
alias to restore during sigreturn, the kernel always restores bits
127:0 of each SVE vector register from the fpsimd_context in the
signal frame (which must be present): userspace needs to take this
into account if it wants to modify the SVE vector register contents
on return from a signal.
FPSR and FPCR, which are used by both FPSIMD and SVE, are not
included in sve_context because they are always present in
fpsimd_context anyway.
For signal delivery, a new helper
fpsimd_signal_preserve_current_state() is added to update _both_
the FPSIMD and SVE views in the task struct, to make it easier to
populate this information into the signal frame. Because of the
redundancy between the two views of the state, only one is updated
otherwise.
Reviewed-by: Catalin Marinas <catalin.marinas@arm.com>
Signed-off-by: Dave Martin <Dave.Martin@arm.com>
Cc: Alex Bennée <alex.bennee@linaro.org>
Cc: Ard Biesheuvel <ard.biesheuvel@linaro.org>
Cc: Will Deacon <will.deacon@arm.com>
Signed-off-by: Will Deacon <will.deacon@arm.com>
2017-10-31 18:51:07 +03:00
|
|
|
clear_thread_flag(TIF_SVE);
|
|
|
|
|
2012-03-05 15:49:31 +04:00
|
|
|
/* load the hardware registers from the fpsimd_state structure */
|
2014-02-24 18:26:27 +04:00
|
|
|
if (!err)
|
|
|
|
fpsimd_update_current_state(&fpsimd);
|
2012-03-05 15:49:31 +04:00
|
|
|
|
|
|
|
return err ? -EFAULT : 0;
|
|
|
|
}
|
|
|
|
|
arm64/sve: Signal handling support
This patch implements support for saving and restoring the SVE
registers around signals.
A fixed-size header struct sve_context is always included in the
signal frame encoding the thread's vector length at the time of
signal delivery, optionally followed by a variable-layout structure
encoding the SVE registers.
Because of the need to preserve backwards compatibility, the FPSIMD
view of the SVE registers is always dumped as a struct
fpsimd_context in the usual way, in addition to any sve_context.
The SVE vector registers are dumped in full, including bits 127:0
of each register which alias the corresponding FPSIMD vector
registers in the hardware. To avoid any ambiguity about which
alias to restore during sigreturn, the kernel always restores bits
127:0 of each SVE vector register from the fpsimd_context in the
signal frame (which must be present): userspace needs to take this
into account if it wants to modify the SVE vector register contents
on return from a signal.
FPSR and FPCR, which are used by both FPSIMD and SVE, are not
included in sve_context because they are always present in
fpsimd_context anyway.
For signal delivery, a new helper
fpsimd_signal_preserve_current_state() is added to update _both_
the FPSIMD and SVE views in the task struct, to make it easier to
populate this information into the signal frame. Because of the
redundancy between the two views of the state, only one is updated
otherwise.
Reviewed-by: Catalin Marinas <catalin.marinas@arm.com>
Signed-off-by: Dave Martin <Dave.Martin@arm.com>
Cc: Alex Bennée <alex.bennee@linaro.org>
Cc: Ard Biesheuvel <ard.biesheuvel@linaro.org>
Cc: Will Deacon <will.deacon@arm.com>
Signed-off-by: Will Deacon <will.deacon@arm.com>
2017-10-31 18:51:07 +03:00
|
|
|
|
2017-06-15 17:03:39 +03:00
|
|
|
struct user_ctxs {
|
|
|
|
struct fpsimd_context __user *fpsimd;
|
arm64/sve: Signal handling support
This patch implements support for saving and restoring the SVE
registers around signals.
A fixed-size header struct sve_context is always included in the
signal frame encoding the thread's vector length at the time of
signal delivery, optionally followed by a variable-layout structure
encoding the SVE registers.
Because of the need to preserve backwards compatibility, the FPSIMD
view of the SVE registers is always dumped as a struct
fpsimd_context in the usual way, in addition to any sve_context.
The SVE vector registers are dumped in full, including bits 127:0
of each register which alias the corresponding FPSIMD vector
registers in the hardware. To avoid any ambiguity about which
alias to restore during sigreturn, the kernel always restores bits
127:0 of each SVE vector register from the fpsimd_context in the
signal frame (which must be present): userspace needs to take this
into account if it wants to modify the SVE vector register contents
on return from a signal.
FPSR and FPCR, which are used by both FPSIMD and SVE, are not
included in sve_context because they are always present in
fpsimd_context anyway.
For signal delivery, a new helper
fpsimd_signal_preserve_current_state() is added to update _both_
the FPSIMD and SVE views in the task struct, to make it easier to
populate this information into the signal frame. Because of the
redundancy between the two views of the state, only one is updated
otherwise.
Reviewed-by: Catalin Marinas <catalin.marinas@arm.com>
Signed-off-by: Dave Martin <Dave.Martin@arm.com>
Cc: Alex Bennée <alex.bennee@linaro.org>
Cc: Ard Biesheuvel <ard.biesheuvel@linaro.org>
Cc: Will Deacon <will.deacon@arm.com>
Signed-off-by: Will Deacon <will.deacon@arm.com>
2017-10-31 18:51:07 +03:00
|
|
|
struct sve_context __user *sve;
|
2017-06-15 17:03:39 +03:00
|
|
|
};
|
|
|
|
|
arm64/sve: Signal handling support
This patch implements support for saving and restoring the SVE
registers around signals.
A fixed-size header struct sve_context is always included in the
signal frame encoding the thread's vector length at the time of
signal delivery, optionally followed by a variable-layout structure
encoding the SVE registers.
Because of the need to preserve backwards compatibility, the FPSIMD
view of the SVE registers is always dumped as a struct
fpsimd_context in the usual way, in addition to any sve_context.
The SVE vector registers are dumped in full, including bits 127:0
of each register which alias the corresponding FPSIMD vector
registers in the hardware. To avoid any ambiguity about which
alias to restore during sigreturn, the kernel always restores bits
127:0 of each SVE vector register from the fpsimd_context in the
signal frame (which must be present): userspace needs to take this
into account if it wants to modify the SVE vector register contents
on return from a signal.
FPSR and FPCR, which are used by both FPSIMD and SVE, are not
included in sve_context because they are always present in
fpsimd_context anyway.
For signal delivery, a new helper
fpsimd_signal_preserve_current_state() is added to update _both_
the FPSIMD and SVE views in the task struct, to make it easier to
populate this information into the signal frame. Because of the
redundancy between the two views of the state, only one is updated
otherwise.
Reviewed-by: Catalin Marinas <catalin.marinas@arm.com>
Signed-off-by: Dave Martin <Dave.Martin@arm.com>
Cc: Alex Bennée <alex.bennee@linaro.org>
Cc: Ard Biesheuvel <ard.biesheuvel@linaro.org>
Cc: Will Deacon <will.deacon@arm.com>
Signed-off-by: Will Deacon <will.deacon@arm.com>
2017-10-31 18:51:07 +03:00
|
|
|
#ifdef CONFIG_ARM64_SVE
|
|
|
|
|
|
|
|
static int preserve_sve_context(struct sve_context __user *ctx)
|
|
|
|
{
|
|
|
|
int err = 0;
|
|
|
|
u16 reserved[ARRAY_SIZE(ctx->__reserved)];
|
|
|
|
unsigned int vl = current->thread.sve_vl;
|
|
|
|
unsigned int vq = 0;
|
|
|
|
|
|
|
|
if (test_thread_flag(TIF_SVE))
|
|
|
|
vq = sve_vq_from_vl(vl);
|
|
|
|
|
|
|
|
memset(reserved, 0, sizeof(reserved));
|
|
|
|
|
|
|
|
__put_user_error(SVE_MAGIC, &ctx->head.magic, err);
|
|
|
|
__put_user_error(round_up(SVE_SIG_CONTEXT_SIZE(vq), 16),
|
|
|
|
&ctx->head.size, err);
|
|
|
|
__put_user_error(vl, &ctx->vl, err);
|
|
|
|
BUILD_BUG_ON(sizeof(ctx->__reserved) != sizeof(reserved));
|
|
|
|
err |= __copy_to_user(&ctx->__reserved, reserved, sizeof(reserved));
|
|
|
|
|
|
|
|
if (vq) {
|
|
|
|
/*
|
|
|
|
* This assumes that the SVE state has already been saved to
|
|
|
|
* the task struct by calling preserve_fpsimd_context().
|
|
|
|
*/
|
|
|
|
err |= __copy_to_user((char __user *)ctx + SVE_SIG_REGS_OFFSET,
|
|
|
|
current->thread.sve_state,
|
|
|
|
SVE_SIG_REGS_SIZE(vq));
|
|
|
|
}
|
|
|
|
|
|
|
|
return err ? -EFAULT : 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int restore_sve_fpsimd_context(struct user_ctxs *user)
|
|
|
|
{
|
|
|
|
int err;
|
|
|
|
unsigned int vq;
|
arm64: fpsimd: Fix state leakage when migrating after sigreturn
When refactoring the sigreturn code to handle SVE, I changed the
sigreturn implementation to store the new FPSIMD state from the
user sigframe into task_struct before reloading the state into the
CPU regs. This makes it easier to convert the data for SVE when
needed.
However, it turns out that the fpsimd_state structure passed into
fpsimd_update_current_state is not fully initialised, so assigning
the structure as a whole corrupts current->thread.fpsimd_state.cpu
with uninitialised data.
This means that if the garbage data written to .cpu happens to be a
valid cpu number, and the task is subsequently migrated to the cpu
identified by the that number, and then tries to enter userspace,
the CPU FPSIMD regs will be assumed to be correct for the task and
not reloaded as they should be. This can result in returning to
userspace with the FPSIMD registers containing data that is stale or
that belongs to another task or to the kernel.
Knowingly handing around a kernel structure that is incompletely
initialised with user data is a potential source of mistakes,
especially across source file boundaries. To help avoid a repeat
of this issue, this patch adapts the relevant internal API to hand
around the user-accessible subset only: struct user_fpsimd_state.
To avoid future surprises, this patch also converts all uses of
struct fpsimd_state that really only access the user subset, to use
struct user_fpsimd_state. A few missing consts are added to
function prototypes for good measure.
Thanks to Will for spotting the cause of the bug here.
Reported-by: Geert Uytterhoeven <geert@linux-m68k.org>
Signed-off-by: Dave Martin <Dave.Martin@arm.com>
Cc: Will Deacon <will.deacon@arm.com>
Cc: Ard Biesheuvel <ard.biesheuvel@linaro.org>
Signed-off-by: Catalin Marinas <catalin.marinas@arm.com>
2017-12-15 21:34:38 +03:00
|
|
|
struct user_fpsimd_state fpsimd;
|
arm64/sve: Signal handling support
This patch implements support for saving and restoring the SVE
registers around signals.
A fixed-size header struct sve_context is always included in the
signal frame encoding the thread's vector length at the time of
signal delivery, optionally followed by a variable-layout structure
encoding the SVE registers.
Because of the need to preserve backwards compatibility, the FPSIMD
view of the SVE registers is always dumped as a struct
fpsimd_context in the usual way, in addition to any sve_context.
The SVE vector registers are dumped in full, including bits 127:0
of each register which alias the corresponding FPSIMD vector
registers in the hardware. To avoid any ambiguity about which
alias to restore during sigreturn, the kernel always restores bits
127:0 of each SVE vector register from the fpsimd_context in the
signal frame (which must be present): userspace needs to take this
into account if it wants to modify the SVE vector register contents
on return from a signal.
FPSR and FPCR, which are used by both FPSIMD and SVE, are not
included in sve_context because they are always present in
fpsimd_context anyway.
For signal delivery, a new helper
fpsimd_signal_preserve_current_state() is added to update _both_
the FPSIMD and SVE views in the task struct, to make it easier to
populate this information into the signal frame. Because of the
redundancy between the two views of the state, only one is updated
otherwise.
Reviewed-by: Catalin Marinas <catalin.marinas@arm.com>
Signed-off-by: Dave Martin <Dave.Martin@arm.com>
Cc: Alex Bennée <alex.bennee@linaro.org>
Cc: Ard Biesheuvel <ard.biesheuvel@linaro.org>
Cc: Will Deacon <will.deacon@arm.com>
Signed-off-by: Will Deacon <will.deacon@arm.com>
2017-10-31 18:51:07 +03:00
|
|
|
struct sve_context sve;
|
|
|
|
|
|
|
|
if (__copy_from_user(&sve, user->sve, sizeof(sve)))
|
|
|
|
return -EFAULT;
|
|
|
|
|
|
|
|
if (sve.vl != current->thread.sve_vl)
|
|
|
|
return -EINVAL;
|
|
|
|
|
|
|
|
if (sve.head.size <= sizeof(*user->sve)) {
|
|
|
|
clear_thread_flag(TIF_SVE);
|
|
|
|
goto fpsimd_only;
|
|
|
|
}
|
|
|
|
|
|
|
|
vq = sve_vq_from_vl(sve.vl);
|
|
|
|
|
|
|
|
if (sve.head.size < SVE_SIG_CONTEXT_SIZE(vq))
|
|
|
|
return -EINVAL;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Careful: we are about __copy_from_user() directly into
|
|
|
|
* thread.sve_state with preemption enabled, so protection is
|
|
|
|
* needed to prevent a racing context switch from writing stale
|
|
|
|
* registers back over the new data.
|
|
|
|
*/
|
|
|
|
|
|
|
|
fpsimd_flush_task_state(current);
|
|
|
|
/* From now, fpsimd_thread_switch() won't touch thread.sve_state */
|
|
|
|
|
|
|
|
sve_alloc(current);
|
|
|
|
err = __copy_from_user(current->thread.sve_state,
|
|
|
|
(char __user const *)user->sve +
|
|
|
|
SVE_SIG_REGS_OFFSET,
|
|
|
|
SVE_SIG_REGS_SIZE(vq));
|
|
|
|
if (err)
|
|
|
|
return -EFAULT;
|
|
|
|
|
|
|
|
set_thread_flag(TIF_SVE);
|
|
|
|
|
|
|
|
fpsimd_only:
|
|
|
|
/* copy the FP and status/control registers */
|
|
|
|
/* restore_sigframe() already checked that user->fpsimd != NULL. */
|
|
|
|
err = __copy_from_user(fpsimd.vregs, user->fpsimd->vregs,
|
|
|
|
sizeof(fpsimd.vregs));
|
|
|
|
__get_user_error(fpsimd.fpsr, &user->fpsimd->fpsr, err);
|
|
|
|
__get_user_error(fpsimd.fpcr, &user->fpsimd->fpcr, err);
|
|
|
|
|
|
|
|
/* load the hardware registers from the fpsimd_state structure */
|
|
|
|
if (!err)
|
|
|
|
fpsimd_update_current_state(&fpsimd);
|
|
|
|
|
|
|
|
return err ? -EFAULT : 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
#else /* ! CONFIG_ARM64_SVE */
|
|
|
|
|
|
|
|
/* Turn any non-optimised out attempts to use these into a link error: */
|
|
|
|
extern int preserve_sve_context(void __user *ctx);
|
|
|
|
extern int restore_sve_fpsimd_context(struct user_ctxs *user);
|
|
|
|
|
|
|
|
#endif /* ! CONFIG_ARM64_SVE */
|
|
|
|
|
|
|
|
|
2017-06-15 17:03:39 +03:00
|
|
|
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 17:03:40 +03:00
|
|
|
struct _aarch64_ctx __user *head;
|
|
|
|
char __user *base = (char __user *)&sc->__reserved;
|
2017-06-15 17:03:39 +03: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 17:03:40 +03:00
|
|
|
size_t limit = sizeof(sc->__reserved);
|
2017-06-20 20:23:39 +03:00
|
|
|
bool have_extra_context = false;
|
|
|
|
char const __user *const sfp = (char const __user *)sf;
|
2017-06-15 17:03:39 +03:00
|
|
|
|
|
|
|
user->fpsimd = NULL;
|
arm64/sve: Signal handling support
This patch implements support for saving and restoring the SVE
registers around signals.
A fixed-size header struct sve_context is always included in the
signal frame encoding the thread's vector length at the time of
signal delivery, optionally followed by a variable-layout structure
encoding the SVE registers.
Because of the need to preserve backwards compatibility, the FPSIMD
view of the SVE registers is always dumped as a struct
fpsimd_context in the usual way, in addition to any sve_context.
The SVE vector registers are dumped in full, including bits 127:0
of each register which alias the corresponding FPSIMD vector
registers in the hardware. To avoid any ambiguity about which
alias to restore during sigreturn, the kernel always restores bits
127:0 of each SVE vector register from the fpsimd_context in the
signal frame (which must be present): userspace needs to take this
into account if it wants to modify the SVE vector register contents
on return from a signal.
FPSR and FPCR, which are used by both FPSIMD and SVE, are not
included in sve_context because they are always present in
fpsimd_context anyway.
For signal delivery, a new helper
fpsimd_signal_preserve_current_state() is added to update _both_
the FPSIMD and SVE views in the task struct, to make it easier to
populate this information into the signal frame. Because of the
redundancy between the two views of the state, only one is updated
otherwise.
Reviewed-by: Catalin Marinas <catalin.marinas@arm.com>
Signed-off-by: Dave Martin <Dave.Martin@arm.com>
Cc: Alex Bennée <alex.bennee@linaro.org>
Cc: Ard Biesheuvel <ard.biesheuvel@linaro.org>
Cc: Will Deacon <will.deacon@arm.com>
Signed-off-by: Will Deacon <will.deacon@arm.com>
2017-10-31 18:51:07 +03:00
|
|
|
user->sve = NULL;
|
2017-06-15 17:03:39 +03: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 17:03:40 +03:00
|
|
|
if (!IS_ALIGNED((unsigned long)base, 16))
|
|
|
|
goto invalid;
|
|
|
|
|
2017-06-15 17:03:39 +03: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 17:03:40 +03:00
|
|
|
int err = 0;
|
2017-06-15 17:03:39 +03:00
|
|
|
u32 magic, size;
|
2017-06-20 20:23:39 +03:00
|
|
|
char const __user *userp;
|
|
|
|
struct extra_context const __user *extra;
|
|
|
|
u64 extra_datap;
|
|
|
|
u32 extra_size;
|
|
|
|
struct _aarch64_ctx const __user *end;
|
|
|
|
u32 end_magic, end_size;
|
2017-06-15 17:03:39 +03: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 17:03:40 +03:00
|
|
|
if (limit - offset < sizeof(*head))
|
2017-06-15 17:03:39 +03: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 17:03:40 +03:00
|
|
|
if (!IS_ALIGNED(offset, 16))
|
|
|
|
goto invalid;
|
|
|
|
|
|
|
|
head = (struct _aarch64_ctx __user *)(base + offset);
|
2017-06-15 17:03:39 +03: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 17:03:40 +03:00
|
|
|
if (limit - offset < size)
|
|
|
|
goto invalid;
|
|
|
|
|
2017-06-15 17:03:39 +03:00
|
|
|
switch (magic) {
|
|
|
|
case 0:
|
|
|
|
if (size)
|
|
|
|
goto invalid;
|
|
|
|
|
|
|
|
goto done;
|
|
|
|
|
|
|
|
case FPSIMD_MAGIC:
|
2020-01-14 02:30:22 +03:00
|
|
|
if (!system_supports_fpsimd())
|
|
|
|
goto invalid;
|
2017-06-15 17:03:39 +03:00
|
|
|
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 17:03:40 +03:00
|
|
|
if (size < sizeof(*user->fpsimd))
|
2017-06-15 17:03:39 +03:00
|
|
|
goto invalid;
|
|
|
|
|
|
|
|
user->fpsimd = (struct fpsimd_context __user *)head;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case ESR_MAGIC:
|
|
|
|
/* ignore */
|
|
|
|
break;
|
|
|
|
|
arm64/sve: Signal handling support
This patch implements support for saving and restoring the SVE
registers around signals.
A fixed-size header struct sve_context is always included in the
signal frame encoding the thread's vector length at the time of
signal delivery, optionally followed by a variable-layout structure
encoding the SVE registers.
Because of the need to preserve backwards compatibility, the FPSIMD
view of the SVE registers is always dumped as a struct
fpsimd_context in the usual way, in addition to any sve_context.
The SVE vector registers are dumped in full, including bits 127:0
of each register which alias the corresponding FPSIMD vector
registers in the hardware. To avoid any ambiguity about which
alias to restore during sigreturn, the kernel always restores bits
127:0 of each SVE vector register from the fpsimd_context in the
signal frame (which must be present): userspace needs to take this
into account if it wants to modify the SVE vector register contents
on return from a signal.
FPSR and FPCR, which are used by both FPSIMD and SVE, are not
included in sve_context because they are always present in
fpsimd_context anyway.
For signal delivery, a new helper
fpsimd_signal_preserve_current_state() is added to update _both_
the FPSIMD and SVE views in the task struct, to make it easier to
populate this information into the signal frame. Because of the
redundancy between the two views of the state, only one is updated
otherwise.
Reviewed-by: Catalin Marinas <catalin.marinas@arm.com>
Signed-off-by: Dave Martin <Dave.Martin@arm.com>
Cc: Alex Bennée <alex.bennee@linaro.org>
Cc: Ard Biesheuvel <ard.biesheuvel@linaro.org>
Cc: Will Deacon <will.deacon@arm.com>
Signed-off-by: Will Deacon <will.deacon@arm.com>
2017-10-31 18:51:07 +03:00
|
|
|
case SVE_MAGIC:
|
|
|
|
if (!system_supports_sve())
|
|
|
|
goto invalid;
|
|
|
|
|
|
|
|
if (user->sve)
|
|
|
|
goto invalid;
|
|
|
|
|
|
|
|
if (size < sizeof(*user->sve))
|
|
|
|
goto invalid;
|
|
|
|
|
|
|
|
user->sve = (struct sve_context __user *)head;
|
|
|
|
break;
|
|
|
|
|
2017-06-20 20:23:39 +03:00
|
|
|
case EXTRA_MAGIC:
|
|
|
|
if (have_extra_context)
|
|
|
|
goto invalid;
|
|
|
|
|
|
|
|
if (size < sizeof(*extra))
|
|
|
|
goto invalid;
|
|
|
|
|
|
|
|
userp = (char const __user *)head;
|
|
|
|
|
|
|
|
extra = (struct extra_context const __user *)userp;
|
|
|
|
userp += size;
|
|
|
|
|
|
|
|
__get_user_error(extra_datap, &extra->datap, err);
|
|
|
|
__get_user_error(extra_size, &extra->size, err);
|
|
|
|
if (err)
|
|
|
|
return err;
|
|
|
|
|
|
|
|
/* Check for the dummy terminator in __reserved[]: */
|
|
|
|
|
|
|
|
if (limit - offset - size < TERMINATOR_SIZE)
|
|
|
|
goto invalid;
|
|
|
|
|
|
|
|
end = (struct _aarch64_ctx const __user *)userp;
|
|
|
|
userp += TERMINATOR_SIZE;
|
|
|
|
|
|
|
|
__get_user_error(end_magic, &end->magic, err);
|
|
|
|
__get_user_error(end_size, &end->size, err);
|
|
|
|
if (err)
|
|
|
|
return err;
|
|
|
|
|
|
|
|
if (end_magic || end_size)
|
|
|
|
goto invalid;
|
|
|
|
|
|
|
|
/* Prevent looping/repeated parsing of extra_context */
|
|
|
|
have_extra_context = true;
|
|
|
|
|
|
|
|
base = (__force void __user *)extra_datap;
|
|
|
|
if (!IS_ALIGNED((unsigned long)base, 16))
|
|
|
|
goto invalid;
|
|
|
|
|
|
|
|
if (!IS_ALIGNED(extra_size, 16))
|
|
|
|
goto invalid;
|
|
|
|
|
|
|
|
if (base != userp)
|
|
|
|
goto invalid;
|
|
|
|
|
|
|
|
/* Reject "unreasonably large" frames: */
|
|
|
|
if (extra_size > sfp + SIGFRAME_MAXSZ - userp)
|
|
|
|
goto invalid;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Ignore trailing terminator in __reserved[]
|
|
|
|
* and start parsing extra data:
|
|
|
|
*/
|
|
|
|
offset = 0;
|
|
|
|
limit = extra_size;
|
2017-10-31 18:50:55 +03: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 05:57:57 +03:00
|
|
|
if (!access_ok(base, limit))
|
2017-10-31 18:50:55 +03:00
|
|
|
goto invalid;
|
|
|
|
|
2017-06-20 20:23:39 +03:00
|
|
|
continue;
|
|
|
|
|
2017-06-15 17:03:39 +03:00
|
|
|
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 17:03:40 +03:00
|
|
|
if (limit - offset < size)
|
2017-06-15 17:03:39 +03:00
|
|
|
goto invalid;
|
|
|
|
|
|
|
|
offset += size;
|
|
|
|
}
|
|
|
|
|
|
|
|
done:
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
invalid:
|
|
|
|
return -EINVAL;
|
|
|
|
}
|
|
|
|
|
2012-03-05 15:49:31 +04:00
|
|
|
static int restore_sigframe(struct pt_regs *regs,
|
|
|
|
struct rt_sigframe __user *sf)
|
|
|
|
{
|
|
|
|
sigset_t set;
|
|
|
|
int i, err;
|
2017-06-15 17:03:39 +03:00
|
|
|
struct user_ctxs user;
|
2012-03-05 15:49:31 +04: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.
|
|
|
|
*/
|
2017-08-01 17:35:54 +03:00
|
|
|
forget_syscall(regs);
|
2012-03-05 15:49:31 +04:00
|
|
|
|
2016-03-01 17:18:50 +03:00
|
|
|
err |= !valid_user_regs(®s->user_regs, current);
|
2017-06-15 17:03:39 +03:00
|
|
|
if (err == 0)
|
|
|
|
err = parse_user_sigframe(&user, sf);
|
2012-03-05 15:49:31 +04:00
|
|
|
|
2020-01-14 02:30:22 +03:00
|
|
|
if (err == 0 && system_supports_fpsimd()) {
|
arm64/sve: Signal handling support
This patch implements support for saving and restoring the SVE
registers around signals.
A fixed-size header struct sve_context is always included in the
signal frame encoding the thread's vector length at the time of
signal delivery, optionally followed by a variable-layout structure
encoding the SVE registers.
Because of the need to preserve backwards compatibility, the FPSIMD
view of the SVE registers is always dumped as a struct
fpsimd_context in the usual way, in addition to any sve_context.
The SVE vector registers are dumped in full, including bits 127:0
of each register which alias the corresponding FPSIMD vector
registers in the hardware. To avoid any ambiguity about which
alias to restore during sigreturn, the kernel always restores bits
127:0 of each SVE vector register from the fpsimd_context in the
signal frame (which must be present): userspace needs to take this
into account if it wants to modify the SVE vector register contents
on return from a signal.
FPSR and FPCR, which are used by both FPSIMD and SVE, are not
included in sve_context because they are always present in
fpsimd_context anyway.
For signal delivery, a new helper
fpsimd_signal_preserve_current_state() is added to update _both_
the FPSIMD and SVE views in the task struct, to make it easier to
populate this information into the signal frame. Because of the
redundancy between the two views of the state, only one is updated
otherwise.
Reviewed-by: Catalin Marinas <catalin.marinas@arm.com>
Signed-off-by: Dave Martin <Dave.Martin@arm.com>
Cc: Alex Bennée <alex.bennee@linaro.org>
Cc: Ard Biesheuvel <ard.biesheuvel@linaro.org>
Cc: Will Deacon <will.deacon@arm.com>
Signed-off-by: Will Deacon <will.deacon@arm.com>
2017-10-31 18:51:07 +03:00
|
|
|
if (!user.fpsimd)
|
|
|
|
return -EINVAL;
|
|
|
|
|
|
|
|
if (user.sve) {
|
|
|
|
if (!system_supports_sve())
|
|
|
|
return -EINVAL;
|
|
|
|
|
|
|
|
err = restore_sve_fpsimd_context(&user);
|
|
|
|
} else {
|
|
|
|
err = restore_fpsimd_context(user.fpsimd);
|
|
|
|
}
|
|
|
|
}
|
2012-03-05 15:49:31 +04:00
|
|
|
|
|
|
|
return err;
|
|
|
|
}
|
|
|
|
|
2018-07-11 16:56:53 +03:00
|
|
|
SYSCALL_DEFINE0(rt_sigreturn)
|
2012-03-05 15:49:31 +04:00
|
|
|
{
|
2018-07-11 16:56:41 +03:00
|
|
|
struct pt_regs *regs = current_pt_regs();
|
2012-03-05 15:49:31 +04:00
|
|
|
struct rt_sigframe __user *frame;
|
|
|
|
|
|
|
|
/* Always make any pending restarted system calls return -EINTR */
|
2015-02-13 02:01:14 +03:00
|
|
|
current->restart_block.fn = do_no_restart_syscall;
|
2012-03-05 15:49:31 +04: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;
|
|
|
|
|
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 05:57:57 +03:00
|
|
|
if (!access_ok(frame, sizeof (*frame)))
|
2012-03-05 15:49:31 +04:00
|
|
|
goto badframe;
|
|
|
|
|
|
|
|
if (restore_sigframe(regs, frame))
|
|
|
|
goto badframe;
|
|
|
|
|
2012-12-23 10:56:45 +04:00
|
|
|
if (restore_altstack(&frame->uc.uc_stack))
|
2012-03-05 15:49:31 +04:00
|
|
|
goto badframe;
|
|
|
|
|
|
|
|
return regs->regs[0];
|
|
|
|
|
|
|
|
badframe:
|
2018-02-20 18:05:17 +03:00
|
|
|
arm64_notify_segfault(regs->sp);
|
2012-03-05 15:49:31 +04:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
arm64: signal: Report signal frame size to userspace via auxv
Stateful CPU architecture extensions may require the signal frame
to grow to a size that exceeds the arch's MINSIGSTKSZ #define.
However, changing this #define is an ABI break.
To allow userspace the option of determining the signal frame size
in a more forwards-compatible way, this patch adds a new auxv entry
tagged with AT_MINSIGSTKSZ, which provides the maximum signal frame
size that the process can observe during its lifetime.
If AT_MINSIGSTKSZ is absent from the aux vector, the caller can
assume that the MINSIGSTKSZ #define is sufficient. This allows for
a consistent interface with older kernels that do not provide
AT_MINSIGSTKSZ.
The idea is that libc could expose this via sysconf() or some
similar mechanism.
There is deliberately no AT_SIGSTKSZ. The kernel knows nothing
about userspace's own stack overheads and should not pretend to
know.
For arm64:
The primary motivation for this interface is the Scalable Vector
Extension, which can require at least 4KB or so of extra space
in the signal frame for the largest hardware implementations.
To determine the correct value, a "Christmas tree" mode (via the
add_all argument) is added to setup_sigframe_layout(), to simulate
addition of all possible records to the signal frame at maximum
possible size.
If this procedure goes wrong somehow, resulting in a stupidly large
frame layout and hence failure of sigframe_alloc() to allocate a
record to the frame, then this is indicative of a kernel bug. In
this case, we WARN() and no attempt is made to populate
AT_MINSIGSTKSZ for userspace.
For arm64 SVE:
The SVE context block in the signal frame needs to be considered
too when computing the maximum possible signal frame size.
Because the size of this block depends on the vector length, this
patch computes the size based not on the thread's current vector
length but instead on the maximum possible vector length: this
determines the maximum size of SVE context block that can be
observed in any signal frame for the lifetime of the process.
Signed-off-by: Dave Martin <Dave.Martin@arm.com>
Acked-by: Will Deacon <will.deacon@arm.com>
Cc: Ard Biesheuvel <ard.biesheuvel@linaro.org>
Cc: Alex Bennée <alex.bennee@linaro.org>
Signed-off-by: Catalin Marinas <catalin.marinas@arm.com>
2018-06-01 13:10:14 +03:00
|
|
|
/*
|
|
|
|
* Determine the layout of optional records in the signal frame
|
|
|
|
*
|
|
|
|
* add_all: if true, lays out the biggest possible signal frame for
|
|
|
|
* this task; otherwise, generates a layout for the current state
|
|
|
|
* of the task.
|
|
|
|
*/
|
|
|
|
static int setup_sigframe_layout(struct rt_sigframe_user_layout *user,
|
|
|
|
bool add_all)
|
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 17:03:40 +03:00
|
|
|
{
|
2017-06-15 17:03:41 +03: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 17:03:40 +03:00
|
|
|
|
|
|
|
/* fault information, if valid */
|
arm64: signal: Report signal frame size to userspace via auxv
Stateful CPU architecture extensions may require the signal frame
to grow to a size that exceeds the arch's MINSIGSTKSZ #define.
However, changing this #define is an ABI break.
To allow userspace the option of determining the signal frame size
in a more forwards-compatible way, this patch adds a new auxv entry
tagged with AT_MINSIGSTKSZ, which provides the maximum signal frame
size that the process can observe during its lifetime.
If AT_MINSIGSTKSZ is absent from the aux vector, the caller can
assume that the MINSIGSTKSZ #define is sufficient. This allows for
a consistent interface with older kernels that do not provide
AT_MINSIGSTKSZ.
The idea is that libc could expose this via sysconf() or some
similar mechanism.
There is deliberately no AT_SIGSTKSZ. The kernel knows nothing
about userspace's own stack overheads and should not pretend to
know.
For arm64:
The primary motivation for this interface is the Scalable Vector
Extension, which can require at least 4KB or so of extra space
in the signal frame for the largest hardware implementations.
To determine the correct value, a "Christmas tree" mode (via the
add_all argument) is added to setup_sigframe_layout(), to simulate
addition of all possible records to the signal frame at maximum
possible size.
If this procedure goes wrong somehow, resulting in a stupidly large
frame layout and hence failure of sigframe_alloc() to allocate a
record to the frame, then this is indicative of a kernel bug. In
this case, we WARN() and no attempt is made to populate
AT_MINSIGSTKSZ for userspace.
For arm64 SVE:
The SVE context block in the signal frame needs to be considered
too when computing the maximum possible signal frame size.
Because the size of this block depends on the vector length, this
patch computes the size based not on the thread's current vector
length but instead on the maximum possible vector length: this
determines the maximum size of SVE context block that can be
observed in any signal frame for the lifetime of the process.
Signed-off-by: Dave Martin <Dave.Martin@arm.com>
Acked-by: Will Deacon <will.deacon@arm.com>
Cc: Ard Biesheuvel <ard.biesheuvel@linaro.org>
Cc: Alex Bennée <alex.bennee@linaro.org>
Signed-off-by: Catalin Marinas <catalin.marinas@arm.com>
2018-06-01 13:10:14 +03:00
|
|
|
if (add_all || current->thread.fault_code) {
|
2017-06-15 17:03:41 +03: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 17:03:40 +03:00
|
|
|
}
|
|
|
|
|
arm64/sve: Signal handling support
This patch implements support for saving and restoring the SVE
registers around signals.
A fixed-size header struct sve_context is always included in the
signal frame encoding the thread's vector length at the time of
signal delivery, optionally followed by a variable-layout structure
encoding the SVE registers.
Because of the need to preserve backwards compatibility, the FPSIMD
view of the SVE registers is always dumped as a struct
fpsimd_context in the usual way, in addition to any sve_context.
The SVE vector registers are dumped in full, including bits 127:0
of each register which alias the corresponding FPSIMD vector
registers in the hardware. To avoid any ambiguity about which
alias to restore during sigreturn, the kernel always restores bits
127:0 of each SVE vector register from the fpsimd_context in the
signal frame (which must be present): userspace needs to take this
into account if it wants to modify the SVE vector register contents
on return from a signal.
FPSR and FPCR, which are used by both FPSIMD and SVE, are not
included in sve_context because they are always present in
fpsimd_context anyway.
For signal delivery, a new helper
fpsimd_signal_preserve_current_state() is added to update _both_
the FPSIMD and SVE views in the task struct, to make it easier to
populate this information into the signal frame. Because of the
redundancy between the two views of the state, only one is updated
otherwise.
Reviewed-by: Catalin Marinas <catalin.marinas@arm.com>
Signed-off-by: Dave Martin <Dave.Martin@arm.com>
Cc: Alex Bennée <alex.bennee@linaro.org>
Cc: Ard Biesheuvel <ard.biesheuvel@linaro.org>
Cc: Will Deacon <will.deacon@arm.com>
Signed-off-by: Will Deacon <will.deacon@arm.com>
2017-10-31 18:51:07 +03:00
|
|
|
if (system_supports_sve()) {
|
|
|
|
unsigned int vq = 0;
|
|
|
|
|
arm64: signal: Report signal frame size to userspace via auxv
Stateful CPU architecture extensions may require the signal frame
to grow to a size that exceeds the arch's MINSIGSTKSZ #define.
However, changing this #define is an ABI break.
To allow userspace the option of determining the signal frame size
in a more forwards-compatible way, this patch adds a new auxv entry
tagged with AT_MINSIGSTKSZ, which provides the maximum signal frame
size that the process can observe during its lifetime.
If AT_MINSIGSTKSZ is absent from the aux vector, the caller can
assume that the MINSIGSTKSZ #define is sufficient. This allows for
a consistent interface with older kernels that do not provide
AT_MINSIGSTKSZ.
The idea is that libc could expose this via sysconf() or some
similar mechanism.
There is deliberately no AT_SIGSTKSZ. The kernel knows nothing
about userspace's own stack overheads and should not pretend to
know.
For arm64:
The primary motivation for this interface is the Scalable Vector
Extension, which can require at least 4KB or so of extra space
in the signal frame for the largest hardware implementations.
To determine the correct value, a "Christmas tree" mode (via the
add_all argument) is added to setup_sigframe_layout(), to simulate
addition of all possible records to the signal frame at maximum
possible size.
If this procedure goes wrong somehow, resulting in a stupidly large
frame layout and hence failure of sigframe_alloc() to allocate a
record to the frame, then this is indicative of a kernel bug. In
this case, we WARN() and no attempt is made to populate
AT_MINSIGSTKSZ for userspace.
For arm64 SVE:
The SVE context block in the signal frame needs to be considered
too when computing the maximum possible signal frame size.
Because the size of this block depends on the vector length, this
patch computes the size based not on the thread's current vector
length but instead on the maximum possible vector length: this
determines the maximum size of SVE context block that can be
observed in any signal frame for the lifetime of the process.
Signed-off-by: Dave Martin <Dave.Martin@arm.com>
Acked-by: Will Deacon <will.deacon@arm.com>
Cc: Ard Biesheuvel <ard.biesheuvel@linaro.org>
Cc: Alex Bennée <alex.bennee@linaro.org>
Signed-off-by: Catalin Marinas <catalin.marinas@arm.com>
2018-06-01 13:10:14 +03:00
|
|
|
if (add_all || test_thread_flag(TIF_SVE)) {
|
|
|
|
int vl = sve_max_vl;
|
|
|
|
|
|
|
|
if (!add_all)
|
|
|
|
vl = current->thread.sve_vl;
|
|
|
|
|
|
|
|
vq = sve_vq_from_vl(vl);
|
|
|
|
}
|
arm64/sve: Signal handling support
This patch implements support for saving and restoring the SVE
registers around signals.
A fixed-size header struct sve_context is always included in the
signal frame encoding the thread's vector length at the time of
signal delivery, optionally followed by a variable-layout structure
encoding the SVE registers.
Because of the need to preserve backwards compatibility, the FPSIMD
view of the SVE registers is always dumped as a struct
fpsimd_context in the usual way, in addition to any sve_context.
The SVE vector registers are dumped in full, including bits 127:0
of each register which alias the corresponding FPSIMD vector
registers in the hardware. To avoid any ambiguity about which
alias to restore during sigreturn, the kernel always restores bits
127:0 of each SVE vector register from the fpsimd_context in the
signal frame (which must be present): userspace needs to take this
into account if it wants to modify the SVE vector register contents
on return from a signal.
FPSR and FPCR, which are used by both FPSIMD and SVE, are not
included in sve_context because they are always present in
fpsimd_context anyway.
For signal delivery, a new helper
fpsimd_signal_preserve_current_state() is added to update _both_
the FPSIMD and SVE views in the task struct, to make it easier to
populate this information into the signal frame. Because of the
redundancy between the two views of the state, only one is updated
otherwise.
Reviewed-by: Catalin Marinas <catalin.marinas@arm.com>
Signed-off-by: Dave Martin <Dave.Martin@arm.com>
Cc: Alex Bennée <alex.bennee@linaro.org>
Cc: Ard Biesheuvel <ard.biesheuvel@linaro.org>
Cc: Will Deacon <will.deacon@arm.com>
Signed-off-by: Will Deacon <will.deacon@arm.com>
2017-10-31 18:51:07 +03:00
|
|
|
|
|
|
|
err = sigframe_alloc(user, &user->sve_offset,
|
|
|
|
SVE_SIG_CONTEXT_SIZE(vq));
|
|
|
|
if (err)
|
|
|
|
return err;
|
|
|
|
}
|
|
|
|
|
2017-06-20 20:23:39 +03:00
|
|
|
return sigframe_alloc_end(user);
|
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 17:03:40 +03:00
|
|
|
}
|
|
|
|
|
2017-06-15 17:03:38 +03:00
|
|
|
static int setup_sigframe(struct rt_sigframe_user_layout *user,
|
2012-03-05 15:49:31 +04:00
|
|
|
struct pt_regs *regs, sigset_t *set)
|
|
|
|
{
|
|
|
|
int i, err = 0;
|
2017-06-15 17:03:38 +03:00
|
|
|
struct rt_sigframe __user *sf = user->sigframe;
|
2012-03-05 15:49:31 +04:00
|
|
|
|
2012-11-23 16:34:13 +04:00
|
|
|
/* set up the stack frame for unwinding */
|
2017-06-15 17:03:38 +03: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 16:34:13 +04:00
|
|
|
|
2012-03-05 15:49:31 +04: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));
|
|
|
|
|
2020-01-14 02:30:22 +03:00
|
|
|
if (err == 0 && system_supports_fpsimd()) {
|
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 17:03:40 +03:00
|
|
|
struct fpsimd_context __user *fpsimd_ctx =
|
|
|
|
apply_user_offset(user, user->fpsimd_offset);
|
2014-04-04 18:42:16 +04:00
|
|
|
err |= preserve_fpsimd_context(fpsimd_ctx);
|
|
|
|
}
|
2012-03-05 15:49:31 +04:00
|
|
|
|
2013-09-16 18:19:27 +04: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 17:03:40 +03:00
|
|
|
if (err == 0 && user->esr_offset) {
|
|
|
|
struct esr_context __user *esr_ctx =
|
|
|
|
apply_user_offset(user, user->esr_offset);
|
|
|
|
|
2013-09-16 18:19:27 +04: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);
|
|
|
|
}
|
|
|
|
|
arm64/sve: Signal handling support
This patch implements support for saving and restoring the SVE
registers around signals.
A fixed-size header struct sve_context is always included in the
signal frame encoding the thread's vector length at the time of
signal delivery, optionally followed by a variable-layout structure
encoding the SVE registers.
Because of the need to preserve backwards compatibility, the FPSIMD
view of the SVE registers is always dumped as a struct
fpsimd_context in the usual way, in addition to any sve_context.
The SVE vector registers are dumped in full, including bits 127:0
of each register which alias the corresponding FPSIMD vector
registers in the hardware. To avoid any ambiguity about which
alias to restore during sigreturn, the kernel always restores bits
127:0 of each SVE vector register from the fpsimd_context in the
signal frame (which must be present): userspace needs to take this
into account if it wants to modify the SVE vector register contents
on return from a signal.
FPSR and FPCR, which are used by both FPSIMD and SVE, are not
included in sve_context because they are always present in
fpsimd_context anyway.
For signal delivery, a new helper
fpsimd_signal_preserve_current_state() is added to update _both_
the FPSIMD and SVE views in the task struct, to make it easier to
populate this information into the signal frame. Because of the
redundancy between the two views of the state, only one is updated
otherwise.
Reviewed-by: Catalin Marinas <catalin.marinas@arm.com>
Signed-off-by: Dave Martin <Dave.Martin@arm.com>
Cc: Alex Bennée <alex.bennee@linaro.org>
Cc: Ard Biesheuvel <ard.biesheuvel@linaro.org>
Cc: Will Deacon <will.deacon@arm.com>
Signed-off-by: Will Deacon <will.deacon@arm.com>
2017-10-31 18:51:07 +03:00
|
|
|
/* Scalable Vector Extension state, if present */
|
|
|
|
if (system_supports_sve() && err == 0 && user->sve_offset) {
|
|
|
|
struct sve_context __user *sve_ctx =
|
|
|
|
apply_user_offset(user, user->sve_offset);
|
|
|
|
err |= preserve_sve_context(sve_ctx);
|
|
|
|
}
|
|
|
|
|
2017-06-20 20:23:39 +03:00
|
|
|
if (err == 0 && user->extra_offset) {
|
|
|
|
char __user *sfp = (char __user *)user->sigframe;
|
|
|
|
char __user *userp =
|
|
|
|
apply_user_offset(user, user->extra_offset);
|
|
|
|
|
|
|
|
struct extra_context __user *extra;
|
|
|
|
struct _aarch64_ctx __user *end;
|
|
|
|
u64 extra_datap;
|
|
|
|
u32 extra_size;
|
|
|
|
|
|
|
|
extra = (struct extra_context __user *)userp;
|
|
|
|
userp += EXTRA_CONTEXT_SIZE;
|
|
|
|
|
|
|
|
end = (struct _aarch64_ctx __user *)userp;
|
|
|
|
userp += TERMINATOR_SIZE;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* extra_datap is just written to the signal frame.
|
|
|
|
* The value gets cast back to a void __user *
|
|
|
|
* during sigreturn.
|
|
|
|
*/
|
|
|
|
extra_datap = (__force u64)userp;
|
|
|
|
extra_size = sfp + round_up(user->size, 16) - userp;
|
|
|
|
|
|
|
|
__put_user_error(EXTRA_MAGIC, &extra->head.magic, err);
|
|
|
|
__put_user_error(EXTRA_CONTEXT_SIZE, &extra->head.size, err);
|
|
|
|
__put_user_error(extra_datap, &extra->datap, err);
|
|
|
|
__put_user_error(extra_size, &extra->size, err);
|
|
|
|
|
|
|
|
/* Add the terminator */
|
|
|
|
__put_user_error(0, &end->magic, err);
|
|
|
|
__put_user_error(0, &end->size, err);
|
|
|
|
}
|
|
|
|
|
2012-03-05 15:49:31 +04: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 17:03:40 +03: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 15:49:31 +04:00
|
|
|
|
|
|
|
return err;
|
|
|
|
}
|
|
|
|
|
2017-06-15 17:03:38 +03:00
|
|
|
static int get_sigframe(struct rt_sigframe_user_layout *user,
|
|
|
|
struct ksignal *ksig, struct pt_regs *regs)
|
2012-03-05 15:49:31 +04: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 17:03:40 +03:00
|
|
|
int err;
|
|
|
|
|
|
|
|
init_user_layout(user);
|
arm64: signal: Report signal frame size to userspace via auxv
Stateful CPU architecture extensions may require the signal frame
to grow to a size that exceeds the arch's MINSIGSTKSZ #define.
However, changing this #define is an ABI break.
To allow userspace the option of determining the signal frame size
in a more forwards-compatible way, this patch adds a new auxv entry
tagged with AT_MINSIGSTKSZ, which provides the maximum signal frame
size that the process can observe during its lifetime.
If AT_MINSIGSTKSZ is absent from the aux vector, the caller can
assume that the MINSIGSTKSZ #define is sufficient. This allows for
a consistent interface with older kernels that do not provide
AT_MINSIGSTKSZ.
The idea is that libc could expose this via sysconf() or some
similar mechanism.
There is deliberately no AT_SIGSTKSZ. The kernel knows nothing
about userspace's own stack overheads and should not pretend to
know.
For arm64:
The primary motivation for this interface is the Scalable Vector
Extension, which can require at least 4KB or so of extra space
in the signal frame for the largest hardware implementations.
To determine the correct value, a "Christmas tree" mode (via the
add_all argument) is added to setup_sigframe_layout(), to simulate
addition of all possible records to the signal frame at maximum
possible size.
If this procedure goes wrong somehow, resulting in a stupidly large
frame layout and hence failure of sigframe_alloc() to allocate a
record to the frame, then this is indicative of a kernel bug. In
this case, we WARN() and no attempt is made to populate
AT_MINSIGSTKSZ for userspace.
For arm64 SVE:
The SVE context block in the signal frame needs to be considered
too when computing the maximum possible signal frame size.
Because the size of this block depends on the vector length, this
patch computes the size based not on the thread's current vector
length but instead on the maximum possible vector length: this
determines the maximum size of SVE context block that can be
observed in any signal frame for the lifetime of the process.
Signed-off-by: Dave Martin <Dave.Martin@arm.com>
Acked-by: Will Deacon <will.deacon@arm.com>
Cc: Ard Biesheuvel <ard.biesheuvel@linaro.org>
Cc: Alex Bennée <alex.bennee@linaro.org>
Signed-off-by: Catalin Marinas <catalin.marinas@arm.com>
2018-06-01 13:10:14 +03:00
|
|
|
err = setup_sigframe_layout(user, false);
|
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 17:03:40 +03:00
|
|
|
if (err)
|
|
|
|
return err;
|
2012-03-05 15:49:31 +04:00
|
|
|
|
2014-03-05 16:31:20 +04:00
|
|
|
sp = sp_top = sigsp(regs->sp, ksig);
|
2012-03-05 15:49:31 +04:00
|
|
|
|
2017-06-15 17:03:38 +03: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 17:03:40 +03:00
|
|
|
sp = round_down(sp, 16) - sigframe_size(user);
|
2017-06-15 17:03:38 +03:00
|
|
|
user->sigframe = (struct rt_sigframe __user *)sp;
|
2012-03-05 15:49:31 +04:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Check that we can actually write to the signal frame.
|
|
|
|
*/
|
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 05:57:57 +03:00
|
|
|
if (!access_ok(user->sigframe, sp_top - sp))
|
2017-06-15 17:03:38 +03:00
|
|
|
return -EFAULT;
|
2012-03-05 15:49:31 +04:00
|
|
|
|
2017-06-15 17:03:38 +03:00
|
|
|
return 0;
|
2012-03-05 15:49:31 +04:00
|
|
|
}
|
|
|
|
|
2012-11-23 16:34:13 +04:00
|
|
|
static void setup_return(struct pt_regs *regs, struct k_sigaction *ka,
|
2017-06-15 17:03:38 +03:00
|
|
|
struct rt_sigframe_user_layout *user, int usig)
|
2012-03-05 15:49:31 +04:00
|
|
|
{
|
|
|
|
__sigrestore_t sigtramp;
|
|
|
|
|
|
|
|
regs->regs[0] = usig;
|
2017-06-15 17:03:38 +03:00
|
|
|
regs->sp = (unsigned long)user->sigframe;
|
|
|
|
regs->regs[29] = (unsigned long)&user->next_frame->fp;
|
2012-03-05 15:49:31 +04: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-07 00:52:44 +04:00
|
|
|
static int setup_rt_frame(int usig, struct ksignal *ksig, sigset_t *set,
|
|
|
|
struct pt_regs *regs)
|
2012-03-05 15:49:31 +04:00
|
|
|
{
|
2017-06-15 17:03:38 +03:00
|
|
|
struct rt_sigframe_user_layout user;
|
2012-03-05 15:49:31 +04:00
|
|
|
struct rt_sigframe __user *frame;
|
|
|
|
int err = 0;
|
|
|
|
|
arm64/sve: Signal handling support
This patch implements support for saving and restoring the SVE
registers around signals.
A fixed-size header struct sve_context is always included in the
signal frame encoding the thread's vector length at the time of
signal delivery, optionally followed by a variable-layout structure
encoding the SVE registers.
Because of the need to preserve backwards compatibility, the FPSIMD
view of the SVE registers is always dumped as a struct
fpsimd_context in the usual way, in addition to any sve_context.
The SVE vector registers are dumped in full, including bits 127:0
of each register which alias the corresponding FPSIMD vector
registers in the hardware. To avoid any ambiguity about which
alias to restore during sigreturn, the kernel always restores bits
127:0 of each SVE vector register from the fpsimd_context in the
signal frame (which must be present): userspace needs to take this
into account if it wants to modify the SVE vector register contents
on return from a signal.
FPSR and FPCR, which are used by both FPSIMD and SVE, are not
included in sve_context because they are always present in
fpsimd_context anyway.
For signal delivery, a new helper
fpsimd_signal_preserve_current_state() is added to update _both_
the FPSIMD and SVE views in the task struct, to make it easier to
populate this information into the signal frame. Because of the
redundancy between the two views of the state, only one is updated
otherwise.
Reviewed-by: Catalin Marinas <catalin.marinas@arm.com>
Signed-off-by: Dave Martin <Dave.Martin@arm.com>
Cc: Alex Bennée <alex.bennee@linaro.org>
Cc: Ard Biesheuvel <ard.biesheuvel@linaro.org>
Cc: Will Deacon <will.deacon@arm.com>
Signed-off-by: Will Deacon <will.deacon@arm.com>
2017-10-31 18:51:07 +03:00
|
|
|
fpsimd_signal_preserve_current_state();
|
|
|
|
|
2017-06-15 17:03:38 +03:00
|
|
|
if (get_sigframe(&user, ksig, regs))
|
2012-03-05 15:49:31 +04:00
|
|
|
return 1;
|
|
|
|
|
2017-06-15 17:03:38 +03:00
|
|
|
frame = user.sigframe;
|
|
|
|
|
2012-03-05 15:49:31 +04:00
|
|
|
__put_user_error(0, &frame->uc.uc_flags, err);
|
|
|
|
__put_user_error(NULL, &frame->uc.uc_link, err);
|
|
|
|
|
2012-12-23 10:56:45 +04:00
|
|
|
err |= __save_altstack(&frame->uc.uc_stack, regs->sp);
|
2017-06-15 17:03:38 +03:00
|
|
|
err |= setup_sigframe(&user, regs, set);
|
2012-11-23 16:34:13 +04:00
|
|
|
if (err == 0) {
|
2017-06-15 17:03:38 +03:00
|
|
|
setup_return(regs, &ksig->ka, &user, usig);
|
2013-10-07 00:52:44 +04:00
|
|
|
if (ksig->ka.sa.sa_flags & SA_SIGINFO) {
|
|
|
|
err |= copy_siginfo_to_user(&frame->info, &ksig->info);
|
2012-11-23 16:34:13 +04:00
|
|
|
regs->regs[1] = (unsigned long)&frame->info;
|
|
|
|
regs->regs[2] = (unsigned long)&frame->uc;
|
|
|
|
}
|
2012-03-05 15:49:31 +04: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-07 00:52:44 +04:00
|
|
|
static void handle_signal(struct ksignal *ksig, struct pt_regs *regs)
|
2012-03-05 15:49:31 +04:00
|
|
|
{
|
|
|
|
struct task_struct *tsk = current;
|
|
|
|
sigset_t *oldset = sigmask_to_save();
|
2013-10-07 00:52:44 +04:00
|
|
|
int usig = ksig->sig;
|
2012-03-05 15:49:31 +04:00
|
|
|
int ret;
|
|
|
|
|
2018-06-20 16:46:50 +03:00
|
|
|
rseq_signal_deliver(ksig, regs);
|
|
|
|
|
2012-03-05 15:49:31 +04:00
|
|
|
/*
|
|
|
|
* Set up the stack frame
|
|
|
|
*/
|
|
|
|
if (is_compat_task()) {
|
2013-10-07 00:52:44 +04:00
|
|
|
if (ksig->ka.sa.sa_flags & SA_SIGINFO)
|
|
|
|
ret = compat_setup_rt_frame(usig, ksig, oldset, regs);
|
2012-03-05 15:49:31 +04:00
|
|
|
else
|
2013-10-07 00:52:44 +04:00
|
|
|
ret = compat_setup_frame(usig, ksig, oldset, regs);
|
2012-03-05 15:49:31 +04:00
|
|
|
} else {
|
2013-10-07 00:52:44 +04:00
|
|
|
ret = setup_rt_frame(usig, ksig, oldset, regs);
|
2012-03-05 15:49:31 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Check that the resulting registers are actually sane.
|
|
|
|
*/
|
2016-03-01 17:18:50 +03:00
|
|
|
ret |= !valid_user_regs(®s->user_regs, current);
|
2012-03-05 15:49:31 +04:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Fast forward the stepping logic so we step into the signal
|
|
|
|
* handler.
|
|
|
|
*/
|
2013-10-07 00:52:44 +04:00
|
|
|
if (!ret)
|
|
|
|
user_fastforward_single_step(tsk);
|
2012-03-05 15:49:31 +04:00
|
|
|
|
2013-10-07 00:52:44 +04:00
|
|
|
signal_setup_done(ret, ksig, 0);
|
2012-03-05 15:49:31 +04: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-07 00:52:44 +04:00
|
|
|
int retval = 0;
|
|
|
|
struct ksignal ksig;
|
2018-06-07 14:32:05 +03:00
|
|
|
bool syscall = in_syscall(regs);
|
2012-03-05 15:49:31 +04:00
|
|
|
|
|
|
|
/*
|
|
|
|
* If we were from a system call, check for system call restarting...
|
|
|
|
*/
|
2018-06-07 14:32:05 +03:00
|
|
|
if (syscall) {
|
2012-03-05 15:49:31 +04:00
|
|
|
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.
|
|
|
|
*/
|
2017-08-01 17:35:54 +03:00
|
|
|
forget_syscall(regs);
|
2012-03-05 15:49:31 +04:00
|
|
|
|
|
|
|
/*
|
|
|
|
* 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-07 00:52:44 +04:00
|
|
|
if (get_signal(&ksig)) {
|
2012-03-05 15:49:31 +04: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-07 00:52:44 +04:00
|
|
|
!(ksig.ka.sa.sa_flags & SA_RESTART)))) {
|
2012-03-05 15:49:31 +04:00
|
|
|
regs->regs[0] = -EINTR;
|
|
|
|
regs->pc = continue_addr;
|
|
|
|
}
|
|
|
|
|
2013-10-07 00:52:44 +04:00
|
|
|
handle_signal(&ksig, regs);
|
2012-03-05 15:49:31 +04:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Handle restarting a different system call. As above, if a debugger
|
|
|
|
* has chosen to restart at a different PC, ignore the restart.
|
|
|
|
*/
|
2018-06-07 14:32:05 +03:00
|
|
|
if (syscall && regs->pc == restart_addr) {
|
2012-03-05 15:49:31 +04:00
|
|
|
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,
|
2018-07-11 16:56:36 +03:00
|
|
|
unsigned long thread_flags)
|
2012-03-05 15:49:31 +04:00
|
|
|
{
|
2016-07-14 23:48:14 +03: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();
|
2017-06-15 04:12:03 +03:00
|
|
|
|
2016-07-14 23:48:14 +03:00
|
|
|
do {
|
2017-09-07 18:30:47 +03:00
|
|
|
/* Check valid user FS if needed */
|
|
|
|
addr_limit_user_check();
|
|
|
|
|
2016-07-14 23:48:14 +03:00
|
|
|
if (thread_flags & _TIF_NEED_RESCHED) {
|
2017-11-02 15:12:37 +03:00
|
|
|
/* Unmask Debug and SError for the next task */
|
|
|
|
local_daif_restore(DAIF_PROCCTX_NOIRQ);
|
|
|
|
|
2016-07-14 23:48:14 +03:00
|
|
|
schedule();
|
|
|
|
} else {
|
2017-11-02 15:12:37 +03:00
|
|
|
local_daif_restore(DAIF_PROCCTX);
|
2016-07-14 23:48:14 +03:00
|
|
|
|
2016-11-02 12:10:46 +03:00
|
|
|
if (thread_flags & _TIF_UPROBE)
|
|
|
|
uprobe_notify_resume(regs);
|
|
|
|
|
2016-07-14 23:48:14 +03: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);
|
2018-06-20 16:46:50 +03:00
|
|
|
rseq_handle_notify_resume(NULL, regs);
|
2016-07-14 23:48:14 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
if (thread_flags & _TIF_FOREIGN_FPSTATE)
|
|
|
|
fpsimd_restore_current_state();
|
|
|
|
}
|
2014-05-08 13:20:23 +04:00
|
|
|
|
2017-11-02 15:12:37 +03:00
|
|
|
local_daif_mask();
|
2016-07-14 23:48:14 +03:00
|
|
|
thread_flags = READ_ONCE(current_thread_info()->flags);
|
|
|
|
} while (thread_flags & _TIF_WORK_MASK);
|
2012-03-05 15:49:31 +04:00
|
|
|
}
|
arm64: signal: Report signal frame size to userspace via auxv
Stateful CPU architecture extensions may require the signal frame
to grow to a size that exceeds the arch's MINSIGSTKSZ #define.
However, changing this #define is an ABI break.
To allow userspace the option of determining the signal frame size
in a more forwards-compatible way, this patch adds a new auxv entry
tagged with AT_MINSIGSTKSZ, which provides the maximum signal frame
size that the process can observe during its lifetime.
If AT_MINSIGSTKSZ is absent from the aux vector, the caller can
assume that the MINSIGSTKSZ #define is sufficient. This allows for
a consistent interface with older kernels that do not provide
AT_MINSIGSTKSZ.
The idea is that libc could expose this via sysconf() or some
similar mechanism.
There is deliberately no AT_SIGSTKSZ. The kernel knows nothing
about userspace's own stack overheads and should not pretend to
know.
For arm64:
The primary motivation for this interface is the Scalable Vector
Extension, which can require at least 4KB or so of extra space
in the signal frame for the largest hardware implementations.
To determine the correct value, a "Christmas tree" mode (via the
add_all argument) is added to setup_sigframe_layout(), to simulate
addition of all possible records to the signal frame at maximum
possible size.
If this procedure goes wrong somehow, resulting in a stupidly large
frame layout and hence failure of sigframe_alloc() to allocate a
record to the frame, then this is indicative of a kernel bug. In
this case, we WARN() and no attempt is made to populate
AT_MINSIGSTKSZ for userspace.
For arm64 SVE:
The SVE context block in the signal frame needs to be considered
too when computing the maximum possible signal frame size.
Because the size of this block depends on the vector length, this
patch computes the size based not on the thread's current vector
length but instead on the maximum possible vector length: this
determines the maximum size of SVE context block that can be
observed in any signal frame for the lifetime of the process.
Signed-off-by: Dave Martin <Dave.Martin@arm.com>
Acked-by: Will Deacon <will.deacon@arm.com>
Cc: Ard Biesheuvel <ard.biesheuvel@linaro.org>
Cc: Alex Bennée <alex.bennee@linaro.org>
Signed-off-by: Catalin Marinas <catalin.marinas@arm.com>
2018-06-01 13:10:14 +03:00
|
|
|
|
|
|
|
unsigned long __ro_after_init signal_minsigstksz;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Determine the stack space required for guaranteed signal devliery.
|
|
|
|
* This function is used to populate AT_MINSIGSTKSZ at process startup.
|
|
|
|
* cpufeatures setup is assumed to be complete.
|
|
|
|
*/
|
|
|
|
void __init minsigstksz_setup(void)
|
|
|
|
{
|
|
|
|
struct rt_sigframe_user_layout user;
|
|
|
|
|
|
|
|
init_user_layout(&user);
|
|
|
|
|
|
|
|
/*
|
|
|
|
* If this fails, SIGFRAME_MAXSZ needs to be enlarged. It won't
|
|
|
|
* be big enough, but it's our best guess:
|
|
|
|
*/
|
|
|
|
if (WARN_ON(setup_sigframe_layout(&user, true)))
|
|
|
|
return;
|
|
|
|
|
|
|
|
signal_minsigstksz = sigframe_size(&user) +
|
|
|
|
round_up(sizeof(struct frame_record), 16) +
|
|
|
|
16; /* max alignment padding */
|
|
|
|
}
|