ptrace: add PTRACE_GET_SYSCALL_INFO request
Subsystems (28)
v6 cover ptrace: add PTRACE_GET_SYSCALL_INFO request
PTRACE_GET_SYSCALL_INFO is a generic ptrace API that lets ptracer obtain details of the syscall the tracee is blocked in.
There are two reasons for a special syscall-related ptrace request.
Firstly, with the current ptrace API there are cases when ptracer cannot retrieve necessary information about syscalls. Some examples include:
* The notorious int-0x80-from-64-bit-task issue. See [1] for details. In short, if a 64-bit task performs a syscall through int 0x80, its tracer has no reliable means to find out that the syscall was, in fact, a compat syscall, and misidentifies it.
* Syscall-enter-stop and syscall-exit-stop look the same for the tracer. Common practice is to keep track of the sequence of ptrace-stops in order not to mix the two syscall-stops up. But it is not as simple as it looks; for example, strace had a (just recently fixed) long-standing bug where attaching strace to a tracee that is performing the execve system call led to the tracer identifying the following syscall-exit-stop as syscall-enter-stop, which messed up all the state tracking.
* Since the introduction of commit 84d77d3f06e7e8dea057d10e8ec77ad71f721be3 ("ptrace: Don't allow accessing an undumpable mm"), both PTRACE_PEEKDATA and process_vm_readv become unavailable when the process dumpable flag is cleared. On such architectures as ia64 this results in all syscall arguments being unavailable for the tracer.
Secondly, ptracers also have to support a lot of arch-specific code for obtaining information about the tracee. For some architectures, this requires a ptrace(PTRACE_PEEKUSER, ...) invocation for every syscall argument and return value.
PTRACE_GET_SYSCALL_INFO returns the following structure:
struct ptrace_syscall_info {
__u8 op; /* PTRACE_SYSCALL_INFO_* */
__u32 arch __attribute__((__aligned__(sizeof(__u32))));
__u64 instruction_pointer;
__u64 stack_pointer;
union {
struct {
__u64 nr;
__u64 args[6];
} entry;
struct {
__s64 rval;
__u8 is_error;
} exit;
struct {
__u64 nr;
__u64 args[6];
__u32 ret_data;
} seccomp;
};
};The structure was chosen according to [2], except for the following changes:
* seccomp substructure was added as a superset of entry substructure;
* the type of nr field was changed from int to __u64 because syscall numbers are, as a practical matter, 64 bits;
* stack_pointer field was added along with instruction_pointer field since it is readily available and can save the tracer from extra PTRACE_GETREGS/PTRACE_GETREGSET calls;
* arch is always initialized to aid with tracing system calls
* such as execve();
* instruction_pointer and stack_pointer are always initialized so they could be easily obtained for non-syscall stops;
* a boolean is_error field was added along with rval field, this way the tracer can more reliably distinguish a return value from an error value.
strace has been ported to PTRACE_GET_SYSCALL_INFO, you can find it in [3] and [4].
[1] https://lore.kernel.org/lkml/CA+55aFzcSVmdDj9Lh_gdbz1OzHyEm6ZrGPBDAJnywm2LF_eVyg@mail.gmail.com/
[2] https://lore.kernel.org/lkml/CAObL_7GM0n80N7J_DFw_eQyfLyzq+sf4y2AvsCCV88Tb3AwEHA@mail.gmail.com/
[3] https://github.com/strace/strace/commits/ldv/PTRACE_GET_SYSCALL_INFO
[4] https://gitlab.com/strace/strace/commits/ldv/PTRACE_GET_SYSCALL_INFO
---
Notes:
v6:
* Add syscall_get_arguments and syscall_set_arguments wrappers to asm-generic/syscall.h, requested by Geert.
* Change PTRACE_GET_SYSCALL_INFO return code: do not take trailing paddings into account, use the end of the last field of the structure being written.
* Change struct ptrace_syscall_info:
* remove .frame_pointer field, is is not needed and not portable;
* make .arch field explicitly aligned, remove no longer needed padding before .arch field;
* remove trailing pads, they are no longer needed.
v5:
* Merge separate series and patches into the single series.
* Change PTRACE_EVENTMSG_SYSCALL_{ENTRY,EXIT} values as requested by Oleg.
* Change struct ptrace_syscall_info: generalize instruction_pointer, stack_pointer, and frame_pointer fields by moving them from ptrace_syscall_info.{entry,seccomp} substructures to ptrace_syscall_info and initializing them for all stops.
* Add PTRACE_SYSCALL_INFO_NONE, set it when not in a syscall stop, so e.g. "strace -i" could use PTRACE_SYSCALL_INFO_SECCOMP to obtain instruction_pointer when the tracee is in a signal stop.
* Patch all remaining architectures to provide all necessary syscall_get_* functions.
* Make available for all architectures: do not conditionalize on CONFIG_HAVE_ARCH_TRACEHOOK since all syscall_get_* functions are implemented on all architectures.
* Add a test for PTRACE_GET_SYSCALL_INFO to selftests/ptrace.
v4:
* Do not introduce task_struct.ptrace_event,
use child->last_siginfo->si_code instead.
* Implement PTRACE_SYSCALL_INFO_SECCOMP and ptrace_syscall_info.seccomp support along with PTRACE_SYSCALL_INFO_{ENTRY,EXIT} and ptrace_syscall_info.{entry,exit}.
v3:
* Change struct ptrace_syscall_info.
* Support PTRACE_EVENT_SECCOMP by adding ptrace_event to task_struct.
* Add proper defines for ptrace_syscall_info.op values.
* Rename PT_SYSCALL_IS_ENTERING and PT_SYSCALL_IS_EXITING to PTRACE_EVENTMSG_SYSCALL_ENTRY and PTRACE_EVENTMSG_SYSCALL_EXIT
* and move them to uapi.
v2:
* Do not use task->ptrace.
* Replace entry_info.is_compat with entry_info.arch, use syscall_get_arch().
* Use addr argument of sys_ptrace to get expected size of the struct; return full size of the struct.
Dmitry V. Levin (25):
asm-generic/syscall.h: prepare for inclusion by other files asm-generic/syscall.h: turn syscall_[gs]et_arguments into wrappers
alpha: define remaining syscall_get_* functions
Move EM_ARCOMPACT and EM_ARCV2 to uapi/linux/elf-em.h
arc: define syscall_get_arch()
c6x: define syscall_get_arch()
elf-em.h: add EM_CSKY
csky: define syscall_get_arch()
h8300: define remaining syscall_get_* functions
Move EM_HEXAGON to uapi/linux/elf-em.h
hexagon: define remaining syscall_get_* functions
Move EM_NDS32 to uapi/linux/elf-em.h
nds32: define syscall_get_arch()
nios2: define syscall_get_arch()
m68k: add asm/syscall.h
mips: define syscall_get_error()
parisc: define syscall_get_error()
powerpc: define syscall_get_error()
riscv: define syscall_get_arch()
Move EM_XTENSA to uapi/linux/elf-em.h
xtensa: define syscall_get_* functions
Move EM_UNICORE to uapi/linux/elf-em.h
unicore32: add asm/syscall.h
syscall_get_arch: add "struct task_struct *" argument selftests/ptrace: add a test case for PTRACE_GET_SYSCALL_INFO
Elvira Khabirova (2):
powerpc/ptrace: replace ptrace_report_syscall() with a tracehook call
ptrace: add PTRACE_GET_SYSCALL_INFO request
arch/alpha/include/asm/syscall.h | 31 +- arch/arc/include/asm/elf.h | 6 +- arch/arc/include/asm/syscall.h | 11 + arch/arm/include/asm/syscall.h | 2 +- arch/arm64/include/asm/syscall.h | 4 +- arch/c6x/include/asm/syscall.h | 7 + arch/csky/include/asm/syscall.h | 7 + arch/h8300/include/asm/syscall.h | 19 ++ arch/hexagon/include/asm/elf.h | 6 +- arch/hexagon/include/asm/syscall.h | 22 ++ arch/ia64/include/asm/syscall.h | 2 +- arch/m68k/include/asm/syscall.h | 42 +++ arch/microblaze/include/asm/syscall.h | 2 +- arch/mips/include/asm/syscall.h | 12 +- arch/mips/kernel/ptrace.c | 2 +- arch/nds32/include/asm/elf.h | 3 +- arch/nds32/include/asm/syscall.h | 8 + arch/nios2/include/asm/syscall.h | 6 + arch/openrisc/include/asm/syscall.h | 2 +- arch/parisc/include/asm/syscall.h | 11 +- arch/powerpc/include/asm/syscall.h | 20 +- arch/powerpc/kernel/ptrace.c | 7 +- arch/riscv/include/asm/syscall.h | 10 + arch/s390/include/asm/syscall.h | 4 +- arch/sh/include/asm/syscall_32.h | 2 +- arch/sh/include/asm/syscall_64.h | 2 +- arch/sparc/include/asm/syscall.h | 5 +- arch/unicore32/include/asm/elf.h | 3 +- arch/unicore32/include/asm/syscall.h | 46 +++ arch/x86/include/asm/syscall.h | 8 +- arch/x86/um/asm/syscall.h | 2 +- arch/xtensa/include/asm/elf.h | 2 +- arch/xtensa/include/asm/syscall.h | 65 +++++ include/asm-generic/syscall.h | 85 ++++-- include/linux/tracehook.h | 9 +- include/uapi/linux/audit.h | 16 ++ include/uapi/linux/elf-em.h | 8 + include/uapi/linux/ptrace.h | 35 +++ kernel/auditsc.c | 4 +- kernel/ptrace.c | 101 ++++++- kernel/seccomp.c | 4 +- tools/testing/selftests/ptrace/.gitignore | 1 + tools/testing/selftests/ptrace/Makefile | 2 +- .../selftests/ptrace/get_syscall_info.c | 271 ++++++++++++++++++ 44 files changed, 851 insertions(+), 66 deletions(-) create mode 100644 arch/m68k/include/asm/syscall.h create mode 100644 arch/unicore32/include/asm/syscall.h create mode 100644 tools/testing/selftests/ptrace/get_syscall_info.c
Signature · 1 line
ldv
PATCH v6 1/27 asm-generic/syscall.h: prepare for inclusion by other files
From the very beginning and up to now asm-generic/syscall.h is used for documentation purposes only, it could not be included by arch-specific asm/syscall.h files due to static/non-static conflict of function prototypes.
---
Notes:
v6: initial revision
include/asm-generic/syscall.h | 39 +++++++++++++++++++++-------------- 1 file changed, 24 insertions(+), 15 deletions(-)
include/asm-generic/syscall.h +24 -15
@@ -16,8 +16,8 @@* cannot return to user mode while we are looking at it. */ -#ifndef _ASM_SYSCALL_H -#define _ASM_SYSCALL_H 1 +#ifndef _ASM_GENERIC_SYSCALL_H +#define _ASM_GENERIC_SYSCALL_H 1struct task_struct ;struct pt_regs ;
@@ -38,7 +38,8 @@ struct pt_regs;* * It's only valid to call this when @task is known to be blocked. */ -int syscall_get_nr (struct task_struct *task,struct pt_regs *regs); +static int +syscall_get_nr (struct task_struct *task,struct pt_regs *regs);/** * syscall_rollback - roll back registers after an aborted system call
@@ -56,7 +57,8 @@ int syscall_get_nr(struct task_struct *task, struct pt_regs *regs);* system call instruction. This may not be the same as what the * register state looked like at system call entry tracing. */ -void syscall_rollback (struct task_struct *task,struct pt_regs *regs); +static void +syscall_rollback (struct task_struct *task,struct pt_regs *regs);/** * syscall_get_error - check result of traced system call
@@ -68,7 +70,8 @@ void syscall_rollback(struct task_struct *task, struct pt_regs *regs);* It's only valid to call this when @task is stopped for tracing on exit * from a system call, due to %TIF_SYSCALL_TRACE or %TIF_SYSCALL_AUDIT. */ -long syscall_get_error (struct task_struct *task,struct pt_regs *regs); +static long +syscall_get_error (struct task_struct *task,struct pt_regs *regs);/** * syscall_get_return_value - get the return value of a traced system call
@@ -81,7 +84,8 @@ long syscall_get_error(struct task_struct *task, struct pt_regs *regs);* It's only valid to call this when @task is stopped for tracing on exit * from a system call, due to %TIF_SYSCALL_TRACE or %TIF_SYSCALL_AUDIT. */ -long syscall_get_return_value (struct task_struct *task,struct pt_regs *regs); +static long +syscall_get_return_value (struct task_struct *task,struct pt_regs *regs);/** * syscall_set_return_value - change the return value of a traced system call
@@ -98,8 +102,9 @@ long syscall_get_return_value(struct task_struct *task, struct pt_regs *regs);* It's only valid to call this when @task is stopped for tracing on exit * from a system call, due to %TIF_SYSCALL_TRACE or %TIF_SYSCALL_AUDIT. */ -void syscall_set_return_value (struct task_struct *task,struct pt_regs *regs, -int error,long val); +static void +syscall_set_return_value (struct task_struct *task,struct pt_regs *regs, +int error,long val);/** * syscall_get_arguments - extract system call parameter values
@@ -118,8 +123,9 @@ void syscall_set_return_value(struct task_struct *task, struct pt_regs *regs,* It's invalid to call this with @i + @n > 6; we only support system calls * taking up to 6 arguments. */ -void syscall_get_arguments (struct task_struct *task,struct pt_regs *regs, -unsigned int i,unsigned int n,unsigned long *args); +static void +syscall_get_arguments (struct task_struct *task,struct pt_regs *regs, +unsigned int i,unsigned int n,unsigned long *args);/** * syscall_set_arguments - change system call parameter value
@@ -138,9 +144,10 @@ void syscall_get_arguments(struct task_struct *task, struct pt_regs *regs,* It's invalid to call this with @i + @n > 6; we only support system calls * taking up to 6 arguments. */ -void syscall_set_arguments (struct task_struct *task,struct pt_regs *regs, -unsigned int i,unsigned int n, -const unsigned long *args); +static void +syscall_set_arguments (struct task_struct *task,struct pt_regs *regs, +unsigned int i,unsigned int n, +const unsigned long *args);/** * syscall_get_arch - return the AUDIT_ARCH for the current system call
@@ -153,5 +160,7 @@ void syscall_set_arguments(struct task_struct *task, struct pt_regs *regs,* Architectures which permit CONFIG_HAVE_ARCH_SECCOMP_FILTER must * provide an implementation of this. */ -int syscall_get_arch (void ); -#endif /* _ASM_SYSCALL_H */ +static int +syscall_get_arch (void ); + +#endif /* _ASM_GENERIC_SYSCALL_H */
Signature · 1 line
ldv
PATCH v6 2/27 asm-generic/syscall.h: turn syscall_[gs]et_arguments into wrappers
In reply to Dmitry V. LevinAdd a generic wrapper syscall_get_arguments() that checks its arguments and calls arch-specific __syscall_get_arguments().
Likewise, add a generic wrapper syscall_set_arguments() that checks its arguments and calls arch-specific __syscall_set_arguments().
This is the first step on the way of getting rid of BUGs, BUG_ONs, and replicated error checks in arch-specific asm/syscall.h files.
---
Notes:
v6: initial revision
include/asm-generic/syscall.h | 47 +++++++++++++++++++++++++++++++++-- 1 file changed, 45 insertions(+), 2 deletions(-)
include/asm-generic/syscall.h +45 -2
@@ -122,10 +122,34 @@ syscall_set_return_value(struct task_struct *task, struct pt_regs *regs,* entry to a system call, due to %TIF_SYSCALL_TRACE or %TIF_SYSCALL_AUDIT. * It's invalid to call this with @i + @n > 6; we only support system calls * taking up to 6 arguments. +* +* This function is a wrapper around arch-specific __syscall_get_arguments. */ static void +__syscall_get_arguments (struct task_struct *task,struct pt_regs *regs, +unsigned int i,unsigned int n,unsigned long *args); + +static inline void syscall_get_arguments (struct task_struct *task,struct pt_regs *regs, -unsigned int i,unsigned int n,unsigned long *args); +unsigned int i,unsigned int n,unsigned long *args) +{ +/* +* Ideally there should have been a BUILD_BUG_ON(i + n > 6) +* instead of these checks because it is a "cannot happen" +* kind of assertion. +*/ +if (WARN_ON_ONCE (i >6 )) { +memset (args,0 , n *sizeof (args[0 ])); +return ; + } +if (WARN_ON_ONCE (n >6 - i)) { +unsigned int extra = n - (6 - i); + + n =6 - i; +memset (&args[n],0 , extra *sizeof (args[0 ])); + } +__syscall_get_arguments (task, regs, i, n, args); +}/** * syscall_set_arguments - change system call parameter value
@@ -143,11 +167,30 @@ syscall_get_arguments(struct task_struct *task, struct pt_regs *regs,* entry to a system call, due to %TIF_SYSCALL_TRACE or %TIF_SYSCALL_AUDIT. * It's invalid to call this with @i + @n > 6; we only support system calls * taking up to 6 arguments. +* +* This function is a wrapper around arch-specific __syscall_set_arguments. */ static void +__syscall_set_arguments (struct task_struct *task,struct pt_regs *regs, +unsigned int i,unsigned int n, +const unsigned long *args); + +static inline void syscall_set_arguments (struct task_struct *task,struct pt_regs *regs,unsigned int i,unsigned int n, -const unsigned long *args); +const unsigned long *args) +{ +/* +* Ideally there should have been a BUILD_BUG_ON(i + n > 6) +* instead of these checks because it is a "cannot happen" +* kind of assertion. +*/ +if (WARN_ON_ONCE (i >6 )) +return ; +if (WARN_ON_ONCE (n >6 - i)) + n =6 - i; +__syscall_set_arguments (task, regs, i, n, args); +}/** * syscall_get_arch - return the AUDIT_ARCH for the current system call
Signature · 1 line
ldv
PATCH v6 3/27 alpha: define remaining syscall_get_* functions
In reply to Dmitry V. Levinsyscall_get_* functions are required to be implemented on all architectures in order to extend the generic ptrace API with PTRACE_GET_SYSCALL_INFO request.
This adds remaining 4 syscall_get_* functions as documented in asm-generic/syscall.h: syscall_get_nr, syscall_get_arguments, syscall_get_error, and syscall_get_return_value.
---
Notes:
v6: use asm-generic/syscall.h
arch/alpha/include/asm/syscall.h | 31 ++++++++++++++++++++++++++++++- 1 file changed, 30 insertions(+), 1 deletion(-)
arch/alpha/include/asm/syscall.h +30 -1
@@ -2,9 +2,38 @@#ifndef _ASM_ALPHA_SYSCALL_H#define _ASM_ALPHA_SYSCALL_H +#include <asm/ptrace.h> +#include <asm-generic/syscall.h> #include <uapi/linux/audit.h> -static inline int syscall_get_arch (void ) +static inline int +syscall_get_nr (struct task_struct *task,struct pt_regs *regs) +{ +return regs->r0; +} + +static inline void +__syscall_get_arguments (struct task_struct *task,struct pt_regs *regs, +unsigned int i,unsigned int n,unsigned long *args) +{ +BUILD_BUG_ON (sizeof (regs->r16) !=sizeof (args[0 ])); +memcpy (args, ®s->r16 + i, n *sizeof (args[0 ])); +} + +static inline long +syscall_get_error (struct task_struct *task,struct pt_regs *regs) +{ +return regs->r19 ? -regs->r0 :0 ; +} + +static inline long +syscall_get_return_value (struct task_struct *task,struct pt_regs *regs) +{ +return regs->r0; +} + +static inline int +syscall_get_arch (void ) {return AUDIT_ARCH_ALPHA ; }
Signature · 1 line
ldv
PATCH v6 4/27 Move EM_ARCOMPACT and EM_ARCV2 to uapi/linux/elf-em.h
In reply to Dmitry V. LevinThese should never have been defined in the arch tree to begin with, and now uapi/linux/audit.h header is going to use EM_ARCOMPACT and EM_ARCV2 in order to define AUDIT_ARCH_ARCOMPACT and AUDIT_ARCH_ARCV2 which are needed to implement syscall_get_arch() which in turn is required to extend the generic ptrace API with PTRACE_GET_SYSCALL_INFO request.
---
Notes:
v6: unchanged
v5: added Cc
v2: added Acked-by
arch/arc/include/asm/elf.h | 6 +----- include/uapi/linux/elf-em.h | 2 ++ 2 files changed, 3 insertions(+), 5 deletions(-)
arch/arc/include/asm/elf.h +1 -5
@@ -10,13 +10,9 @@#define __ASM_ARC_ELF_H#include <linux/types.h> +#include <linux/elf-em.h> #include <uapi/asm/elf.h> -/* These ELF defines belong to uapi but libc elf.h already defines them */ -#define EM_ARCOMPACT 93 - -#define EM_ARCV2 195/* ARCv2 Cores */ -#define EM_ARC_INUSE (IS_ENABLED(CONFIG_ISA_ARCOMPACT) ? \ EM_ARCOMPACT : EM_ARCV2)
include/uapi/linux/elf-em.h +2 -0
@@ -34,6 +34,7 @@#define EM_M32R 88/* Renesas M32R */ #define EM_MN10300 89/* Panasonic/MEI MN10300, AM33 */ #define EM_OPENRISC 92/* OpenRISC 32-bit embedded processor */ +#define EM_ARCOMPACT 93/* ARCompact processor */ #define EM_BLACKFIN 106/* ADI Blackfin Processor */ #define EM_ALTERA_NIOS2 113/* Altera Nios II soft-core processor */ #define EM_TI_C6000 140/* TI C6X DSPs */
@@ -41,6 +42,7 @@#define EM_TILEPRO 188/* Tilera TILEPro */ #define EM_MICROBLAZE 189/* Xilinx MicroBlaze */ #define EM_TILEGX 191/* Tilera TILE-Gx */ +#define EM_ARCV2 195/* ARCv2 Cores */ #define EM_RISCV 243/* RISC-V */ #define EM_BPF 247/* Linux BPF - in-kernel virtual machine */ #define EM_FRV 0x5441/* Fujitsu FR-V */
Signature · 1 line
ldv
Re: [PATCH v6 04/27] Move EM_ARCOMPACT and EM_ARCV2 to uapi/linux/elf-em.h
Hi,
Quoted 14 lines · Dmitry V. Levin
These should never have been defined in the arch tree to begin with, and now
uapi/linux/audit.hheader is going to useEM_ARCOMPACTandEM_ARCV2in order to defineAUDIT_ARCH_ARCOMPACTandAUDIT_ARCH_ARCV2which are needed to implementsyscall_get_arch()which in turn is required to extend the generic ptrace API withPTRACE_GET_SYSCALL_INFOrequest.Acked-by Vineet Gupta <vgupta at synopsys.com>Cc Elvira Khabirova <lineprinter at altlinux.org>Cc Eugene Syromyatnikov <esyr at redhat.com>Cc Oleg Nesterov <oleg at redhat.com>Cc Andy Lutomirski <luto at kernel.org>Cc Alexey Brodkin <alexey.brodkin at synopsys.com>Cc linux-snps-arc at lists.infradead.orgSigned-off-by Dmitry V. Levin <ldv at altlinux.org>
Quoted 1 line
---
Looks like the whole series is going to be pinged for quite some time yet, so would you mind taking this patch into your arc tree, please?
Thanks.
Quoted 50 lines
Notes:
v6: unchanged
v5: added Cc
v2: added Acked-byarch/arc/include/asm/elf.h | 6 +----- include/uapi/linux/elf-em.h | 2 ++ 2 files changed, 3 insertions(+), 5 deletions(-)arch/arc/include/asm/elf.h +1
-5@@ -10,13 +10,9 @@#define __ASM_ARC_ELF_H#include <linux/types.h> +#include <linux/elf-em.h> #include <uapi/asm/elf.h> -/* These ELF defines belong to uapi but libc elf.h already defines them */ -#define EM_ARCOMPACT 93 - -#define EM_ARCV2 195/* ARCv2 Cores */ -#define EM_ARC_INUSE (IS_ENABLED(CONFIG_ISA_ARCOMPACT) ? \ EM_ARCOMPACT : EM_ARCV2)include/uapi/linux/elf-em.h +2
-0@@ -34,6 +34,7 @@#define EM_M32R 88/* Renesas M32R */ #define EM_MN10300 89/* Panasonic/MEI MN10300, AM33 */ #define EM_OPENRISC 92/* OpenRISC 32-bit embedded processor */ +#define EM_ARCOMPACT 93/* ARCompact processor */ #define EM_BLACKFIN 106/* ADI Blackfin Processor */ #define EM_ALTERA_NIOS2 113/* Altera Nios II soft-core processor */ #define EM_TI_C6000 140/* TI C6X DSPs */ @@ -41,6 +42,7 @@#define EM_TILEPRO 188/* Tilera TILEPro */ #define EM_MICROBLAZE 189/* Xilinx MicroBlaze */ #define EM_TILEGX 191/* Tilera TILE-Gx */ +#define EM_ARCV2 195/* ARCv2 Cores */ #define EM_RISCV 243/* RISC-V */ #define EM_BPF 247/* Linux BPF - in-kernel virtual machine */ #define EM_FRV 0x5441/* Fujitsu FR-V */ Signature · 1 line
ldv
Signature · 8 lines
ldv -------------- next part -------------- A non-text attachment was scrubbed... Name: signature.asc Type: application/pgp-signature Size: 801 bytes Desc: not available URL: <http://lists.infradead.org/pipermail/linux-snps-arc/attachments/20181221/54a761eb/attachment-0001.sig>
PATCH v6 5/27 arc: define syscall_get_arch()
In reply to Dmitry V. Levinsyscall_get_arch() is required to be implemented on all architectures in addition to already implemented syscall_get_nr(), syscall_get_arguments(), syscall_get_error(), and syscall_get_return_value() functions in order to extend the generic ptrace API with PTRACE_GET_SYSCALL_INFO request.
---
Notes:
v6: unchanged
v5: added Cc
v2: added Acked-by
arch/arc/include/asm/syscall.h | 11 +++++++++++ include/uapi/linux/audit.h | 4 ++++ 2 files changed, 15 insertions(+)
arch/arc/include/asm/syscall.h +11 -0
@@ -9,6 +9,7 @@#ifndef _ASM_ARC_SYSCALL_H#define _ASM_ARC_SYSCALL_H 1 +#include <uapi/linux/audit.h> #include <linux/err.h> #include <linux/sched.h> #include <asm/unistd.h>
@@ -68,4 +69,14 @@ syscall_get_arguments(struct task_struct *task, struct pt_regs *regs, } } +static inline int +syscall_get_arch (void ) +{ +return IS_ENABLED (CONFIG_ISA_ARCOMPACT ) + ? (IS_ENABLED (CONFIG_CPU_BIG_ENDIAN ) + ?AUDIT_ARCH_ARCOMPACTBE :AUDIT_ARCH_ARCOMPACT ) + : (IS_ENABLED (CONFIG_CPU_BIG_ENDIAN ) + ?AUDIT_ARCH_ARCV2BE :AUDIT_ARCH_ARCV2 ); +} +#endif
include/uapi/linux/audit.h +4 -0
@@ -375,6 +375,10 @@ enum {#define AUDIT_ARCH_AARCH64 (EM_AARCH64|__AUDIT_ARCH_64BIT|__AUDIT_ARCH_LE)#define AUDIT_ARCH_ALPHA (EM_ALPHA|__AUDIT_ARCH_64BIT|__AUDIT_ARCH_LE) +#define AUDIT_ARCH_ARCOMPACT (EM_ARCOMPACT|__AUDIT_ARCH_LE) +#define AUDIT_ARCH_ARCOMPACTBE (EM_ARCOMPACT) +#define AUDIT_ARCH_ARCV2 (EM_ARCV2|__AUDIT_ARCH_LE) +#define AUDIT_ARCH_ARCV2BE (EM_ARCV2)#define AUDIT_ARCH_ARM (EM_ARM|__AUDIT_ARCH_LE)#define AUDIT_ARCH_ARMEB (EM_ARM)#define AUDIT_ARCH_CRIS (EM_CRIS|__AUDIT_ARCH_LE)
Signature · 1 line
ldv
Re: [PATCH v6 05/27] arc: define syscall_get_arch()
Hi,
Quoted 17 lines · Dmitry V. Levin
syscall_get_arch()is required to be implemented on all architectures in addition to already implementedsyscall_get_nr(),syscall_get_arguments(),syscall_get_error(), andsyscall_get_return_value()functions in order to extend the generic ptrace API withPTRACE_GET_SYSCALL_INFOrequest.Acked-by Vineet Gupta <vgupta at synopsys.com>Cc Elvira Khabirova <lineprinter at altlinux.org>Cc Eugene Syromyatnikov <esyr at redhat.com>Cc Oleg Nesterov <oleg at redhat.com>Cc Andy Lutomirski <luto at kernel.org>Cc Alexey Brodkin <alexey.brodkin at synopsys.com>Cc Paul Moore <paul at paul-moore.com>Cc Eric Paris <eparis at redhat.com>Cc linux-snps-arc at lists.infradead.orgCc linux-audit at redhat.comSigned-off-by Dmitry V. Levin <ldv at altlinux.org>
Quoted 1 line
---
Looks like the whole series is going to be pinged for quite some time yet, so would you mind taking this patch into your arc tree, please?
Thanks.
Quoted 53 lines
Notes:
v6: unchanged
v5: added Cc
v2: added Acked-byarch/arc/include/asm/syscall.h | 11 +++++++++++ include/uapi/linux/audit.h | 4 ++++ 2 files changed, 15 insertions(+)arch/arc/include/asm/syscall.h +11
-0@@ -9,6 +9,7 @@#ifndef _ASM_ARC_SYSCALL_H#define _ASM_ARC_SYSCALL_H 1 +#include <uapi/linux/audit.h> #include <linux/err.h> #include <linux/sched.h> #include <asm/unistd.h> @@ -68,4 +69,14 @@ syscall_get_arguments(struct task_struct *task, struct pt_regs *regs, } } +static inline int +syscall_get_arch (void ) +{ +return IS_ENABLED (CONFIG_ISA_ARCOMPACT ) + ? (IS_ENABLED (CONFIG_CPU_BIG_ENDIAN ) + ?AUDIT_ARCH_ARCOMPACTBE :AUDIT_ARCH_ARCOMPACT ) + : (IS_ENABLED (CONFIG_CPU_BIG_ENDIAN ) + ?AUDIT_ARCH_ARCV2BE :AUDIT_ARCH_ARCV2 ); +} +#endif include/uapi/linux/audit.h +4
-0@@ -375,6 +375,10 @@ enum {#define AUDIT_ARCH_AARCH64 (EM_AARCH64|__AUDIT_ARCH_64BIT|__AUDIT_ARCH_LE)#define AUDIT_ARCH_ALPHA (EM_ALPHA|__AUDIT_ARCH_64BIT|__AUDIT_ARCH_LE) +#define AUDIT_ARCH_ARCOMPACT (EM_ARCOMPACT|__AUDIT_ARCH_LE) +#define AUDIT_ARCH_ARCOMPACTBE (EM_ARCOMPACT) +#define AUDIT_ARCH_ARCV2 (EM_ARCV2|__AUDIT_ARCH_LE) +#define AUDIT_ARCH_ARCV2BE (EM_ARCV2)#define AUDIT_ARCH_ARM (EM_ARM|__AUDIT_ARCH_LE)#define AUDIT_ARCH_ARMEB (EM_ARM)#define AUDIT_ARCH_CRIS (EM_CRIS|__AUDIT_ARCH_LE)Signature · 1 line
ldv
Signature · 8 lines
ldv -------------- next part -------------- A non-text attachment was scrubbed... Name: signature.asc Type: application/pgp-signature Size: 801 bytes Desc: not available URL: <http://lists.infradead.org/pipermail/linux-snps-arc/attachments/20181221/fc930f01/attachment.sig>
PATCH v6 6/27 c6x: define syscall_get_arch()
In reply to Dmitry V. Levinsyscall_get_arch() is required to be implemented on all architectures in addition to already implemented syscall_get_nr(), syscall_get_arguments(), syscall_get_error(), and syscall_get_return_value() functions in order to extend the generic ptrace API with PTRACE_GET_SYSCALL_INFO request.
---
Notes:
v6: added Acked-by
v5: added Cc
arch/c6x/include/asm/syscall.h | 7 +++++++ include/uapi/linux/audit.h | 2 ++ 2 files changed, 9 insertions(+)
arch/c6x/include/asm/syscall.h +7 -0
@@ -11,6 +11,7 @@#ifndef __ASM_C6X_SYSCALL_H#define __ASM_C6X_SYSCALL_H +#include <uapi/linux/audit.h> #include <linux/err.h> #include <linux/sched.h>
@@ -120,4 +121,10 @@ static inline void syscall_set_arguments(struct task_struct *task, } } +static inline int syscall_get_arch (void ) +{ +return IS_ENABLED (CONFIG_CPU_BIG_ENDIAN ) + ?AUDIT_ARCH_C6XBE :AUDIT_ARCH_C6X ; +} +#endif /* __ASM_C6X_SYSCALLS_H */
include/uapi/linux/audit.h +2 -0
@@ -381,6 +381,8 @@ enum {#define AUDIT_ARCH_ARCV2BE (EM_ARCV2)#define AUDIT_ARCH_ARM (EM_ARM|__AUDIT_ARCH_LE)#define AUDIT_ARCH_ARMEB (EM_ARM) +#define AUDIT_ARCH_C6X (EM_TI_C6000|__AUDIT_ARCH_LE) +#define AUDIT_ARCH_C6XBE (EM_TI_C6000)#define AUDIT_ARCH_CRIS (EM_CRIS|__AUDIT_ARCH_LE)#define AUDIT_ARCH_FRV (EM_FRV)#define AUDIT_ARCH_I386 (EM_386|__AUDIT_ARCH_LE)
Signature · 1 line
ldv
PATCH v6 7/27 elf-em.h: add EM_CSKY
In reply to Dmitry V. LevinThe uapi/linux/audit.h header is going to use EM_CSKY in order to define AUDIT_ARCH_CSKY which is needed to implement syscall_get_arch() which in turn is required to extend the generic ptrace API with PTRACE_GET_SYSCALL_INFO request.
The value for EM_CSKY has been taken from arch/csky/include/asm/elf.h and confirmed by binutils:include/elf/common.h
---
Notes:
v6: unchanged
include/uapi/linux/elf-em.h | 1 + 1 file changed, 1 insertion(+)
include/uapi/linux/elf-em.h +1 -0
@@ -45,6 +45,7 @@#define EM_ARCV2 195/* ARCv2 Cores */ #define EM_RISCV 243/* RISC-V */ #define EM_BPF 247/* Linux BPF - in-kernel virtual machine */ +#define EM_CSKY 252/* C-SKY processor family */ #define EM_FRV 0x5441/* Fujitsu FR-V */ /*
Signature · 1 line
ldv
Re: [PATCH v6 07/27] elf-em.h: add EM_CSKY
Quoted 36 lines · Dmitry V. Levin
The
uapi/linux/audit.hheader is going to useEM_CSKYin order to defineAUDIT_ARCH_CSKYwhich is needed to implementsyscall_get_arch()which in turn is required to extend the generic ptrace API withPTRACE_GET_SYSCALL_INFOrequest.The value for
EM_CSKYhas been taken fromarch/csky/include/asm/elf.hand confirmed by binutils:include/elf/common.hCc Guo Ren <[email protected]>Cc Oleg Nesterov <[email protected]>Cc Andy Lutomirski <[email protected]>Cc Elvira Khabirova <[email protected]>Cc Eugene Syromyatnikov <[email protected]>Signed-off-by Dmitry V. Levin <[email protected]>---
Notes:
v6: unchangedinclude/uapi/linux/elf-em.h | 1 + 1 file changed, 1 insertion(+)include/uapi/linux/elf-em.h +1
-0@@ -45,6 +45,7 @@#define EM_ARCV2 195/* ARCv2 Cores */ #define EM_RISCV 243/* RISC-V */ #define EM_BPF 247/* Linux BPF - in-kernel virtual machine */ +#define EM_CSKY 252/* C-SKY processor family */ #define EM_FRV 0x5441/* Fujitsu FR-V */ /* Signature · 1 line
ldv
Re: [PATCH v6 07/27] elf-em.h: add EM_CSKY
Hi,
Quoted 1 line · Guo Ren
Reviewed-by Guo Ren <[email protected]>
Given that the whole series is going to be pinged for quite some time yet, would you mind taking this patch into the csky tree?
Thanks.
Quoted 37 lines · Dmitry V. Levin
Quoted 36 lines
The
uapi/linux/audit.hheader is going to useEM_CSKYin order to defineAUDIT_ARCH_CSKYwhich is needed to implementsyscall_get_arch()which in turn is required to extend the generic ptrace API withPTRACE_GET_SYSCALL_INFOrequest.The value for
EM_CSKYhas been taken fromarch/csky/include/asm/elf.hand confirmed by binutils:include/elf/common.hCc Guo Ren <[email protected]>Cc Oleg Nesterov <[email protected]>Cc Andy Lutomirski <[email protected]>Cc Elvira Khabirova <[email protected]>Cc Eugene Syromyatnikov <[email protected]>Signed-off-by Dmitry V. Levin <[email protected]>---
Notes:
v6: unchangedinclude/uapi/linux/elf-em.h | 1 + 1 file changed, 1 insertion(+)include/uapi/linux/elf-em.h +1
-0@@ -45,6 +45,7 @@#define EM_ARCV2 195/* ARCv2 Cores */ #define EM_RISCV 243/* RISC-V */ #define EM_BPF 247/* Linux BPF - in-kernel virtual machine */ +#define EM_CSKY 252/* C-SKY processor family */ #define EM_FRV 0x5441/* Fujitsu FR-V */ /* Signature · 1 line
ldv
Signature · 1 line
ldv
Guo Ren
maintainerRe: [PATCH v6 07/27] elf-em.h: add EM_CSKY
Quoted 7 lines · Dmitry V. Levin
Hi,
Quoted 1 line · Guo Ren
Reviewed-by Guo Ren <[email protected]>Given that the whole series is going to be pinged for quite some time yet, would you mind taking this patch into the csky tree?
Ok
Best Regards
Guo Ren
Quoted 43 lines
Thanks.
Quoted 37 lines · Dmitry V. Levin
Quoted 36 lines
The
uapi/linux/audit.hheader is going to useEM_CSKYin order to defineAUDIT_ARCH_CSKYwhich is needed to implementsyscall_get_arch()which in turn is required to extend the generic ptrace API withPTRACE_GET_SYSCALL_INFOrequest.The value for
EM_CSKYhas been taken fromarch/csky/include/asm/elf.hand confirmed by binutils:include/elf/common.hCc Guo Ren <[email protected]>Cc Oleg Nesterov <[email protected]>Cc Andy Lutomirski <[email protected]>Cc Elvira Khabirova <[email protected]>Cc Eugene Syromyatnikov <[email protected]>Signed-off-by Dmitry V. Levin <[email protected]>---
Notes:
v6: unchangedinclude/uapi/linux/elf-em.h | 1 + 1 file changed, 1 insertion(+)include/uapi/linux/elf-em.h +1
-0@@ -45,6 +45,7 @@#define EM_ARCV2 195/* ARCv2 Cores */ #define EM_RISCV 243/* RISC-V */ #define EM_BPF 247/* Linux BPF - in-kernel virtual machine */ +#define EM_CSKY 252/* C-SKY processor family */ #define EM_FRV 0x5441/* Fujitsu FR-V */ /* Signature · 1 line
ldvSignature · 1 line
ldv
PATCH v6 8/27 csky: define syscall_get_arch()
In reply to Dmitry V. Levinsyscall_get_arch() is required to be implemented on all architectures in order to extend the generic ptrace API with PTRACE_GET_SYSCALL_INFO request.
---
Notes:
v6: unchanged
arch/csky/include/asm/syscall.h | 7 +++++++ include/uapi/linux/audit.h | 1 + 2 files changed, 8 insertions(+)
arch/csky/include/asm/syscall.h +7 -0
@@ -6,6 +6,7 @@#include <linux/sched.h> #include <linux/err.h> #include <abi/regdef.h> +#include <uapi/linux/audit.h> static inline int syscall_get_nr (struct task_struct *task,struct pt_regs *regs)
@@ -68,4 +69,10 @@ syscall_set_arguments(struct task_struct *task, struct pt_regs *regs, memcpy(®s->a1 + i * sizeof(regs->a1), args, n * sizeof(regs->a0)); } +static inline int +syscall_get_arch (void ) +{ +return AUDIT_ARCH_CSKY ; +} +#endif /* __ASM_SYSCALL_H */
include/uapi/linux/audit.h +1 -0
@@ -384,6 +384,7 @@ enum {#define AUDIT_ARCH_C6X (EM_TI_C6000|__AUDIT_ARCH_LE)#define AUDIT_ARCH_C6XBE (EM_TI_C6000)#define AUDIT_ARCH_CRIS (EM_CRIS|__AUDIT_ARCH_LE) +#define AUDIT_ARCH_CSKY (EM_CSKY|__AUDIT_ARCH_LE)#define AUDIT_ARCH_FRV (EM_FRV)#define AUDIT_ARCH_I386 (EM_386|__AUDIT_ARCH_LE)#define AUDIT_ARCH_IA64 (EM_IA_64|__AUDIT_ARCH_64BIT|__AUDIT_ARCH_LE)
Signature · 1 line
ldv
Re: [PATCH v6 08/27] csky: define syscall_get_arch()
Thx Dmitry,
Quoted 59 lines · Dmitry V. Levin
syscall_get_arch()is required to be implemented on all architectures in order to extend the generic ptrace API withPTRACE_GET_SYSCALL_INFOrequest.Cc Guo Ren <[email protected]>Cc Paul Moore <[email protected]>Cc Eric Paris <[email protected]>Cc Oleg Nesterov <[email protected]>Cc Andy Lutomirski <[email protected]>Cc Elvira Khabirova <[email protected]>Cc Eugene Syromyatnikov <[email protected]>Signed-off-by Dmitry V. Levin <[email protected]>---
Notes:
v6: unchangedarch/csky/include/asm/syscall.h | 7 +++++++ include/uapi/linux/audit.h | 1 + 2 files changed, 8 insertions(+)arch/csky/include/asm/syscall.h +7
-0@@ -6,6 +6,7 @@#include <linux/sched.h> #include <linux/err.h> #include <abi/regdef.h> +#include <uapi/linux/audit.h> static inline int syscall_get_nr (struct task_struct *task,struct pt_regs *regs)@@ -68,4 +69,10 @@ syscall_set_arguments(struct task_struct *task, struct pt_regs *regs, memcpy(®s->a1 + i * sizeof(regs->a1), args, n * sizeof(regs->a0)); } +static inline int +syscall_get_arch (void ) +{ +return AUDIT_ARCH_CSKY ; +} +#endif /* __ASM_SYSCALL_H */ include/uapi/linux/audit.h +1
-0@@ -384,6 +384,7 @@ enum {#define AUDIT_ARCH_C6X (EM_TI_C6000|__AUDIT_ARCH_LE)#define AUDIT_ARCH_C6XBE (EM_TI_C6000)#define AUDIT_ARCH_CRIS (EM_CRIS|__AUDIT_ARCH_LE) +#define AUDIT_ARCH_CSKY (EM_CSKY|__AUDIT_ARCH_LE)#define AUDIT_ARCH_FRV (EM_FRV)#define AUDIT_ARCH_I386 (EM_386|__AUDIT_ARCH_LE)#define AUDIT_ARCH_IA64 (EM_IA_64|__AUDIT_ARCH_64BIT|__AUDIT_ARCH_LE)Signature · 1 line
ldv
Re: [PATCH v6 08/27] csky: define syscall_get_arch()
Hi,
Quoted 3 lines · Guo Ren
Thx Dmitry,
Reviewed-by Guo Ren <[email protected]>
Given that the whole series is going to be pinged for quite some time yet, would you mind taking this patch into the csky tree?
Thanks.
Quoted 60 lines · Dmitry V. Levin
Quoted 59 lines
syscall_get_arch()is required to be implemented on all architectures in order to extend the generic ptrace API withPTRACE_GET_SYSCALL_INFOrequest.Cc Guo Ren <[email protected]>Cc Paul Moore <[email protected]>Cc Eric Paris <[email protected]>Cc Oleg Nesterov <[email protected]>Cc Andy Lutomirski <[email protected]>Cc Elvira Khabirova <[email protected]>Cc Eugene Syromyatnikov <[email protected]>Signed-off-by Dmitry V. Levin <[email protected]>---
Notes:
v6: unchangedarch/csky/include/asm/syscall.h | 7 +++++++ include/uapi/linux/audit.h | 1 + 2 files changed, 8 insertions(+)arch/csky/include/asm/syscall.h +7
-0@@ -6,6 +6,7 @@#include <linux/sched.h> #include <linux/err.h> #include <abi/regdef.h> +#include <uapi/linux/audit.h> static inline int syscall_get_nr (struct task_struct *task,struct pt_regs *regs)@@ -68,4 +69,10 @@ syscall_set_arguments(struct task_struct *task, struct pt_regs *regs, memcpy(®s->a1 + i * sizeof(regs->a1), args, n * sizeof(regs->a0)); } +static inline int +syscall_get_arch (void ) +{ +return AUDIT_ARCH_CSKY ; +} +#endif /* __ASM_SYSCALL_H */ include/uapi/linux/audit.h +1
-0@@ -384,6 +384,7 @@ enum {#define AUDIT_ARCH_C6X (EM_TI_C6000|__AUDIT_ARCH_LE)#define AUDIT_ARCH_C6XBE (EM_TI_C6000)#define AUDIT_ARCH_CRIS (EM_CRIS|__AUDIT_ARCH_LE) +#define AUDIT_ARCH_CSKY (EM_CSKY|__AUDIT_ARCH_LE)#define AUDIT_ARCH_FRV (EM_FRV)#define AUDIT_ARCH_I386 (EM_386|__AUDIT_ARCH_LE)#define AUDIT_ARCH_IA64 (EM_IA_64|__AUDIT_ARCH_64BIT|__AUDIT_ARCH_LE)Signature · 1 line
ldv
Signature · 1 line
ldv
Guo Ren
maintainerRe: [PATCH v6 08/27] csky: define syscall_get_arch()
Quoted 9 lines · Dmitry V. Levin
Hi,
Quoted 3 lines · Guo Ren
Thx Dmitry,
Reviewed-by Guo Ren <[email protected]>Given that the whole series is going to be pinged for quite some time yet, would you mind taking this patch into the csky tree?
OK.
Best Regards
Guo Ren
Quoted 66 lines
Thanks.
Quoted 60 lines · Dmitry V. Levin
Quoted 59 lines
syscall_get_arch()is required to be implemented on all architectures in order to extend the generic ptrace API withPTRACE_GET_SYSCALL_INFOrequest.Cc Guo Ren <[email protected]>Cc Paul Moore <[email protected]>Cc Eric Paris <[email protected]>Cc Oleg Nesterov <[email protected]>Cc Andy Lutomirski <[email protected]>Cc Elvira Khabirova <[email protected]>Cc Eugene Syromyatnikov <[email protected]>Signed-off-by Dmitry V. Levin <[email protected]>---
Notes:
v6: unchangedarch/csky/include/asm/syscall.h | 7 +++++++ include/uapi/linux/audit.h | 1 + 2 files changed, 8 insertions(+)arch/csky/include/asm/syscall.h +7
-0@@ -6,6 +6,7 @@#include <linux/sched.h> #include <linux/err.h> #include <abi/regdef.h> +#include <uapi/linux/audit.h> static inline int syscall_get_nr (struct task_struct *task,struct pt_regs *regs)@@ -68,4 +69,10 @@ syscall_set_arguments(struct task_struct *task, struct pt_regs *regs, memcpy(®s->a1 + i * sizeof(regs->a1), args, n * sizeof(regs->a0)); } +static inline int +syscall_get_arch (void ) +{ +return AUDIT_ARCH_CSKY ; +} +#endif /* __ASM_SYSCALL_H */ include/uapi/linux/audit.h +1
-0@@ -384,6 +384,7 @@ enum {#define AUDIT_ARCH_C6X (EM_TI_C6000|__AUDIT_ARCH_LE)#define AUDIT_ARCH_C6XBE (EM_TI_C6000)#define AUDIT_ARCH_CRIS (EM_CRIS|__AUDIT_ARCH_LE) +#define AUDIT_ARCH_CSKY (EM_CSKY|__AUDIT_ARCH_LE)#define AUDIT_ARCH_FRV (EM_FRV)#define AUDIT_ARCH_I386 (EM_386|__AUDIT_ARCH_LE)#define AUDIT_ARCH_IA64 (EM_IA_64|__AUDIT_ARCH_64BIT|__AUDIT_ARCH_LE)Signature · 1 line
ldvSignature · 1 line
ldv
PATCH v6 9/27 h8300: define remaining syscall_get_* functions
In reply to Dmitry V. Levinsyscall_get_* functions are required to be implemented on all architectures in order to extend the generic ptrace API with PTRACE_GET_SYSCALL_INFO request.
This adds remaining 3 syscall_get_* functions as documented in asm-generic/syscall.h: syscall_get_error, syscall_get_return_value, and syscall_get_arch.
---
Notes:
v6: added missing includes
v5: added syscall_get_error and syscall_get_return_value
arch/h8300/include/asm/syscall.h | 19 +++++++++++++++++++ include/uapi/linux/audit.h | 1 + 2 files changed, 20 insertions(+)
arch/h8300/include/asm/syscall.h +19 -0
@@ -8,6 +8,8 @@#include <linux/linkage.h> #include <linux/types.h> #include <linux/ptrace.h> +#include <linux/err.h> +#include <uapi/linux/audit.h> static inline int syscall_get_nr (struct task_struct *task,struct pt_regs *regs)
@@ -47,6 +49,23 @@ syscall_get_arguments(struct task_struct *task, struct pt_regs *regs, } } +static inline long +syscall_get_error (struct task_struct *task,struct pt_regs *regs) +{ +return IS_ERR_VALUE (regs->er0) ? regs->er0 :0 ; +} + +static inline long +syscall_get_return_value (struct task_struct *task,struct pt_regs *regs) +{ +return regs->er0; +} + +static inline int +syscall_get_arch (void ) +{ +return AUDIT_ARCH_H8300 ; +}/* Misc syscall related bits */
include/uapi/linux/audit.h +1 -0
@@ -386,6 +386,7 @@ enum {#define AUDIT_ARCH_CRIS (EM_CRIS|__AUDIT_ARCH_LE)#define AUDIT_ARCH_CSKY (EM_CSKY|__AUDIT_ARCH_LE)#define AUDIT_ARCH_FRV (EM_FRV) +#define AUDIT_ARCH_H8300 (EM_H8_300)#define AUDIT_ARCH_I386 (EM_386|__AUDIT_ARCH_LE)#define AUDIT_ARCH_IA64 (EM_IA_64|__AUDIT_ARCH_64BIT|__AUDIT_ARCH_LE)#define AUDIT_ARCH_M32R (EM_M32R)
Signature · 1 line
ldv
PATCH v6 10/27 Move EM_HEXAGON to uapi/linux/elf-em.h
In reply to Dmitry V. LevinThis should never have been defined in the arch tree to begin with, and now uapi/linux/audit.h header is going to use EM_HEXAGON in order to define AUDIT_ARCH_HEXAGON which is needed to implement syscall_get_arch() which in turn is required to extend the generic ptrace API with PTRACE_GET_SYSCALL_INFO request.
---
Notes:
v6: unchanged
v5: added Cc
arch/hexagon/include/asm/elf.h | 6 +----- include/uapi/linux/elf-em.h | 1 + 2 files changed, 2 insertions(+), 5 deletions(-)
arch/hexagon/include/asm/elf.h +1 -5
@@ -23,11 +23,7 @@#include <asm/ptrace.h> #include <asm/user.h> - -/* -* This should really be in linux/elf-em.h. -*/ -#define EM_HEXAGON 164/* QUALCOMM Hexagon */ +#include <linux/elf-em.h> struct elf32_hdr ;
include/uapi/linux/elf-em.h +1 -0
@@ -38,6 +38,7 @@#define EM_BLACKFIN 106/* ADI Blackfin Processor */ #define EM_ALTERA_NIOS2 113/* Altera Nios II soft-core processor */ #define EM_TI_C6000 140/* TI C6X DSPs */ +#define EM_HEXAGON 164/* QUALCOMM Hexagon */ #define EM_AARCH64 183/* ARM 64 bit */ #define EM_TILEPRO 188/* Tilera TILEPro */ #define EM_MICROBLAZE 189/* Xilinx MicroBlaze */
Signature · 1 line
ldv
PATCH v6 11/27 hexagon: define remaining syscall_get_* functions
In reply to Dmitry V. Levinsyscall_get_* functions are required to be implemented on all architectures in order to extend the generic ptrace API with PTRACE_GET_SYSCALL_INFO request.
This adds remaining 3 syscall_get_* functions as documented in asm-generic/syscall.h: syscall_get_error, syscall_get_return_value, and syscall_get_arch.
---
Notes:
v6: added missing includes
v5: added syscall_get_error and syscall_get_return_value
arch/hexagon/include/asm/syscall.h | 22 ++++++++++++++++++++++ include/uapi/linux/audit.h | 1 + 2 files changed, 23 insertions(+)
arch/hexagon/include/asm/syscall.h +22 -0
@@ -21,6 +21,10 @@#ifndef _ASM_HEXAGON_SYSCALL_H#define _ASM_HEXAGON_SYSCALL_H +#include <linux/err.h> +#include <asm/ptrace.h> +#include <uapi/linux/audit.h> +typedef long (*syscall_fn )(unsigned long ,unsigned long ,unsigned long ,unsigned long ,unsigned long ,unsigned long );
@@ -43,4 +47,22 @@ static inline void syscall_get_arguments(struct task_struct *task,BUG_ON (i + n >6 ); memcpy(args, &(®s->r00)[i], n * sizeof(args[0])); } + +static inline long syscall_get_error (struct task_struct *task, +struct pt_regs *regs) +{ +return IS_ERR_VALUE (regs->r00) ? regs->r00 :0 ; +} + +static inline long syscall_get_return_value (struct task_struct *task, +struct pt_regs *regs) +{ +return regs->r00; +} + +static inline int syscall_get_arch (void ) +{ +return AUDIT_ARCH_HEXAGON ; +} +#endif
include/uapi/linux/audit.h +1 -0
@@ -387,6 +387,7 @@ enum {#define AUDIT_ARCH_CSKY (EM_CSKY|__AUDIT_ARCH_LE)#define AUDIT_ARCH_FRV (EM_FRV)#define AUDIT_ARCH_H8300 (EM_H8_300) +#define AUDIT_ARCH_HEXAGON (EM_HEXAGON)#define AUDIT_ARCH_I386 (EM_386|__AUDIT_ARCH_LE)#define AUDIT_ARCH_IA64 (EM_IA_64|__AUDIT_ARCH_64BIT|__AUDIT_ARCH_LE)#define AUDIT_ARCH_M32R (EM_M32R)
Signature · 1 line
ldv
PATCH v6 12/27 Move EM_NDS32 to uapi/linux/elf-em.h
In reply to Dmitry V. LevinThis should never have been defined in the arch tree to begin with, and now uapi/linux/audit.h header is going to use EM_NDS32 in order to define AUDIT_ARCH_NDS32 which is needed to implement syscall_get_arch() which in turn is required to extend the generic ptrace API with PTRACE_GET_SYSCALL_INFO request.
---
Notes:
v6: unchanged
v5: added Cc
arch/nds32/include/asm/elf.h | 3 +-- include/uapi/linux/elf-em.h | 2 ++ 2 files changed, 3 insertions(+), 2 deletions(-)
arch/nds32/include/asm/elf.h +1 -2
@@ -9,14 +9,13 @@*/ #include <asm/ptrace.h> +#include <linux/elf-em.h> typedef unsigned long elf_greg_t ;typedef unsigned long elf_freg_t [3 ];extern unsigned int elf_hwcap; -#define EM_NDS32 167 -#define R_NDS32_NONE 0#define R_NDS32_16_RELA 19#define R_NDS32_32_RELA 20
include/uapi/linux/elf-em.h +2 -0
@@ -39,6 +39,8 @@#define EM_ALTERA_NIOS2 113/* Altera Nios II soft-core processor */ #define EM_TI_C6000 140/* TI C6X DSPs */ #define EM_HEXAGON 164/* QUALCOMM Hexagon */ +#define EM_NDS32 167/* Andes Technology compact code size +embedded RISC processor family */ #define EM_AARCH64 183/* ARM 64 bit */ #define EM_TILEPRO 188/* Tilera TILEPro */ #define EM_MICROBLAZE 189/* Xilinx MicroBlaze */
Signature · 1 line
ldv
PATCH v6 13/27 nds32: define syscall_get_arch()
In reply to Dmitry V. Levinsyscall_get_arch() is required to be implemented on all architectures in addition to already implemented syscall_get_nr(), syscall_get_arguments(), syscall_get_error(), and syscall_get_return_value() functions in order to extend the generic ptrace API with PTRACE_GET_SYSCALL_INFO request.
---
Notes:
v6: unchanged
v5: added Cc
v2: apparently, this architecture can be configured as big-endian,
so changed AUDIT_ARCH_NDS32 to be little-endian, and added AUDIT_ARCH_NDS32BE.
arch/nds32/include/asm/syscall.h | 8 ++++++++ include/uapi/linux/audit.h | 2 ++ 2 files changed, 10 insertions(+)
arch/nds32/include/asm/syscall.h +8 -0
@@ -5,6 +5,7 @@#ifndef _ASM_NDS32_SYSCALL_H#define _ASM_NDS32_SYSCALL_H 1 +#include <uapi/linux/audit.h> #include <linux/err.h> struct task_struct ;struct pt_regs ;
@@ -185,4 +186,11 @@ void syscall_set_arguments(struct task_struct *task, struct pt_regs *regs, memcpy(®s->uregs[0] + i, args, n * sizeof(args[0])); } + +static inline int syscall_get_arch (void ) +{ +return IS_ENABLED (CONFIG_CPU_BIG_ENDIAN ) + ?AUDIT_ARCH_NDS32BE :AUDIT_ARCH_NDS32 ; +} +#endif /* _ASM_NDS32_SYSCALL_H */
include/uapi/linux/audit.h +2 -0
@@ -401,6 +401,8 @@ enum {#define AUDIT_ARCH_MIPSEL64 (EM_MIPS|__AUDIT_ARCH_64BIT|__AUDIT_ARCH_LE)#define AUDIT_ARCH_MIPSEL64N32 (EM_MIPS|__AUDIT_ARCH_64BIT|__AUDIT_ARCH_LE|\ __AUDIT_ARCH_CONVENTION_MIPS64_N32) +#define AUDIT_ARCH_NDS32 (EM_NDS32|__AUDIT_ARCH_LE) +#define AUDIT_ARCH_NDS32BE (EM_NDS32)#define AUDIT_ARCH_OPENRISC (EM_OPENRISC)#define AUDIT_ARCH_PARISC (EM_PARISC)#define AUDIT_ARCH_PARISC64 (EM_PARISC|__AUDIT_ARCH_64BIT)
Signature · 1 line
ldv
PATCH v6 14/27 nios2: define syscall_get_arch()
In reply to Dmitry V. Levinsyscall_get_arch() is required to be implemented on all architectures in addition to already implemented syscall_get_nr(), syscall_get_arguments(), syscall_get_error(), and syscall_get_return_value() functions in order to extend the generic ptrace API with PTRACE_GET_SYSCALL_INFO request.
---
Notes:
v6: unchanged
v5: added Cc
arch/nios2/include/asm/syscall.h | 6 ++++++ include/uapi/linux/audit.h | 1 + 2 files changed, 7 insertions(+)
arch/nios2/include/asm/syscall.h +6 -0
@@ -17,6 +17,7 @@#ifndef __ASM_NIOS2_SYSCALL_H__#define __ASM_NIOS2_SYSCALL_H__ +#include <uapi/linux/audit.h> #include <linux/err.h> #include <linux/sched.h>
@@ -135,4 +136,9 @@ static inline void syscall_set_arguments(struct task_struct *task, } } +static inline int syscall_get_arch (void ) +{ +return AUDIT_ARCH_NIOS2 ; +} +#endif
include/uapi/linux/audit.h +1 -0
@@ -403,6 +403,7 @@ enum { __AUDIT_ARCH_CONVENTION_MIPS64_N32)#define AUDIT_ARCH_NDS32 (EM_NDS32|__AUDIT_ARCH_LE)#define AUDIT_ARCH_NDS32BE (EM_NDS32) +#define AUDIT_ARCH_NIOS2 (EM_ALTERA_NIOS2|__AUDIT_ARCH_LE)#define AUDIT_ARCH_OPENRISC (EM_OPENRISC)#define AUDIT_ARCH_PARISC (EM_PARISC)#define AUDIT_ARCH_PARISC64 (EM_PARISC|__AUDIT_ARCH_64BIT)
Signature · 1 line
ldv
PATCH v6 15/27 m68k: add asm/syscall.h
In reply to Dmitry V. Levinsyscall_get_* functions are required to be implemented on all architectures in order to extend the generic ptrace API with PTRACE_GET_SYSCALL_INFO request.
This introduces asm/syscall.h on m68k implementing all 5 syscall_get_* functions as documented in asm-generic/syscall.h: syscall_get_nr, syscall_get_arguments, syscall_get_error, syscall_get_return_value, and syscall_get_arch.
---
Notes:
v6: added missing includes, use asm-generic/syscall.h
v5: added syscall_get_nr, syscall_get_arguments, syscall_get_error,
and syscall_get_return_value
v1: added syscall_get_arch
arch/m68k/include/asm/syscall.h | 42 +++++++++++++++++++++++++++++++++ 1 file changed, 42 insertions(+) create mode 100644 arch/m68k/include/asm/syscall.h
arch/m68k/include/asm/syscall.h new file +42 -0
@@ -0,0 +1,42 @@ +/* SPDX-License-Identifier: GPL-2.0 */ +#ifndef _ASM_M68K_SYSCALL_H +#define _ASM_M68K_SYSCALL_H + +#include <asm/ptrace.h> +#include <asm-generic/syscall.h> +#include <linux/err.h> +#include <uapi/linux/audit.h> + +static inline int +syscall_get_nr (struct task_struct *task,struct pt_regs *regs) +{ +return regs->orig_d0; +} + +static inline void +__syscall_get_arguments (struct task_struct *task,struct pt_regs *regs, +unsigned int i,unsigned int n,unsigned long *args) +{ +BUILD_BUG_ON (sizeof (regs->d1) !=sizeof (args[0 ])); +memcpy (args, ®s->d1 + i, n *sizeof (args[0 ])); +} + +static inline long +syscall_get_error (struct task_struct *task,struct pt_regs *regs) +{ +return IS_ERR_VALUE (regs->d0) ? regs->d0 :0 ; +} + +static inline long +syscall_get_return_value (struct task_struct *task,struct pt_regs *regs) +{ +return regs->d0; +} + +static inline int +syscall_get_arch (void ) +{ +return AUDIT_ARCH_M68K ; +} + +#endif /* _ASM_M68K_SYSCALL_H */
Signature · 1 line
ldv
PATCH v6 16/27 mips: define syscall_get_error()
In reply to Dmitry V. Levinsyscall_get_error() is required to be implemented on all architectures in addition to already implemented syscall_get_nr(), syscall_get_arguments(), syscall_get_return_value(), and syscall_get_arch() functions in order to extend the generic ptrace API with PTRACE_GET_SYSCALL_INFO request.
---
Notes:
v6: unchanged
v5: initial revision
arch/mips/include/asm/syscall.h | 6 ++++++ 1 file changed, 6 insertions(+)
arch/mips/include/asm/syscall.h +6 -0
@@ -89,6 +89,12 @@ static inline unsigned long mips_get_syscall_arg(unsigned long *arg,unreachable (); } +static inline long syscall_get_error (struct task_struct *task, +struct pt_regs *regs) +{ +return regs->regs[7 ] ? -regs->regs[2 ] :0 ; +} +static inline long syscall_get_return_value (struct task_struct *task,struct pt_regs *regs) {
Signature · 1 line
ldv
Re: [PATCH v6 16/27] mips: define syscall_get_error()
Hi Dmitry,
Quoted 6 lines · Dmitry V. Levin
syscall_get_error()is required to be implemented on all architectures in addition to already implementedsyscall_get_nr(),syscall_get_arguments(),syscall_get_return_value(), andsyscall_get_arch()functions in order to extend the generic ptrace API withPTRACE_GET_SYSCALL_INFOrequest.
Quoted 9 lines
Cc Paul Burton <[email protected]>Cc Ralf Baechle <[email protected]>Cc James Hogan <[email protected]>Cc Oleg Nesterov <[email protected]>Cc Andy Lutomirski <[email protected]>Cc Elvira Khabirova <[email protected]>Cc Eugene Syromyatnikov <[email protected]>Signed-off-by Dmitry V. Levin <[email protected]>
Thanks,
Paul
Re: [PATCH v6 16/27] mips: define syscall_get_error()
Hi Paul,
Quoted 19 lines · Paul Burton
Hi Dmitry,
Quoted 6 lines · Dmitry V. Levin
syscall_get_error()is required to be implemented on all architectures in addition to already implementedsyscall_get_nr(),syscall_get_arguments(),syscall_get_return_value(), andsyscall_get_arch()functions in order to extend the generic ptrace API withPTRACE_GET_SYSCALL_INFOrequest.Quoted 9 lines
Cc Paul Burton <[email protected]>Cc Ralf Baechle <[email protected]>Cc James Hogan <[email protected]>Cc Oleg Nesterov <[email protected]>Cc Andy Lutomirski <[email protected]>Cc Elvira Khabirova <[email protected]>Cc Eugene Syromyatnikov <[email protected]>Signed-off-by Dmitry V. Levin <[email protected]>
Quoted 1 line
Acked-by Paul Burton <[email protected]>
As it looks like the whole series is going to be pinged for quite some time yet, would you mind taking this patch into the mips tree?
Thanks,
Signature · 1 line
ldv
PATCH v6 17/27 parisc: define syscall_get_error()
In reply to Dmitry V. Levinsyscall_get_error() is required to be implemented on all architectures in addition to already implemented syscall_get_nr(), syscall_get_arguments(), syscall_get_return_value(), and syscall_get_arch() functions in order to extend the generic ptrace API with PTRACE_GET_SYSCALL_INFO request.
---
Notes:
v6: unchanged
v5: initial revision
arch/parisc/include/asm/syscall.h | 7 +++++++ 1 file changed, 7 insertions(+)
arch/parisc/include/asm/syscall.h +7 -0
@@ -43,6 +43,13 @@ static inline void syscall_get_arguments(struct task_struct *tsk, } } +static inline long syscall_get_error (struct task_struct *task, +struct pt_regs *regs) +{ +unsigned long error = regs->gr[28 ]; +return IS_ERR_VALUE (error) ? error :0 ; +} +static inline long syscall_get_return_value (struct task_struct *task,struct pt_regs *regs) {
Signature · 1 line
ldv
PATCH v6 18/27 powerpc: define syscall_get_error()
In reply to Dmitry V. Levinsyscall_get_error() is required to be implemented on this architecture in addition to already implemented syscall_get_nr(), syscall_get_arguments(), syscall_get_return_value(), and syscall_get_arch() functions in order to extend the generic ptrace API with PTRACE_GET_SYSCALL_INFO request.
---
Notes:
v6: unchanged
v5:
This change has been tested with tools/testing/selftests/ptrace/get_syscall_info.c and strace, so it's correct from PTRACE_GET_SYSCALL_INFO point of view.
This cast doubts on commit v4.3-rc1~86^2~81 that changed syscall_set_return_value() in a way that doesn't quite match syscall_get_error(), but syscall_set_return_value() is out of scope of this series, so I'll just let you know my concerns.
arch/powerpc/include/asm/syscall.h | 10 ++++++++++ 1 file changed, 10 insertions(+)
arch/powerpc/include/asm/syscall.h +10 -0
@@ -39,6 +39,16 @@ static inline void syscall_rollback(struct task_struct *task, regs->gpr[3 ] = regs->orig_gpr3; } +static inline long syscall_get_error (struct task_struct *task, +struct pt_regs *regs) +{ +/* +* If the system call failed, +* regs->gpr[3] contains a positive ERRORCODE. +*/ +return (regs->ccr &0x10000000UL ) ? -regs->gpr[3 ] :0 ; +} +static inline long syscall_get_return_value (struct task_struct *task,struct pt_regs *regs) {
Signature · 1 line
ldv
Michael Ellerman
reviewerpowerpc syscall_set_return_value() is confused (was Re: [PATCH v6 18/27] powerpc: define syscall_get_error())
Hi Dmitry,
Quoted 25 lines · Dmitry V. Levin
syscall_get_error()is required to be implemented on this architecture in addition to already implementedsyscall_get_nr(),syscall_get_arguments(),syscall_get_return_value(), andsyscall_get_arch()functions in order to extend the generic ptrace API withPTRACE_GET_SYSCALL_INFOrequest.Cc Michael Ellerman <[email protected]>Cc Benjamin Herrenschmidt <[email protected]>Cc Paul Mackerras <[email protected]>Cc Oleg Nesterov <[email protected]>Cc Andy Lutomirski <[email protected]>Cc Elvira Khabirova <[email protected]>Cc Eugene Syromyatnikov <[email protected]>Signed-off-by Dmitry V. Levin <[email protected]>---
Notes:
v6: unchangedv5:
This change has been tested withtools/testing/selftests/ptrace/get_syscall_info.cand strace, so it's correct fromPTRACE_GET_SYSCALL_INFOpoint of view.
Quoted 4 lines
This cast doubts on commit v4.3-rc1~86^2~81 that changed
syscall_set_return_value()in a way that doesn't quite matchsyscall_get_error(), butsyscall_set_return_value()is out of scope of this series, so I'll just let you know my concerns.
Sorry I only just saw this comment.
It's going to take me a while to page this stuff back into my brain, but I think you may have a point.
I think the way it's written now *works* but only because it's only used by seccomp, and we rely on the fact that the syscall exit path will negate the value before returning to userspace or calling ptrace etc.
eg. we do:
syscall_set_return_value()
if (error) {
regs->ccr |= 0x10000000L;
regs->gpr[3] = error;then the asm does:
/* Return code is already in r3 thanks to do_syscall_trace_enter() */ b .Lsyscall_exit ...
.Lsyscall_exit:
std r3,RESULT(r1) ...
3: cmpld r3,r11
ld r5,_CCR(r1) bge- .Lsyscall_error ...
.Lsyscall_error:
oris r5,r5,0x1000 /* Set SO bit in CR */ neg r3,r3 std r5,_CCR(r1)
And we do the same before calling do_syscall_trace_leave().
Still it's a bit confused, because in the C code we're setting r3 and CCR in the C code, but we're not negating the value in r3, and we're not setting result at all.
I'll test a patch to fix it up.
cheers
PATCH v6 19/27 riscv: define syscall_get_arch()
In reply to Dmitry V. Levinsyscall_get_arch() is required to be implemented on all architectures in addition to already implemented syscall_get_nr(), syscall_get_arguments(), syscall_get_error(), and syscall_get_return_value() functions in order to extend the generic ptrace API with PTRACE_GET_SYSCALL_INFO request.
---
Notes:
v6: unchanged
v5: added Cc
v2: added Reviewed-by
arch/riscv/include/asm/syscall.h | 10 ++++++++++ include/uapi/linux/audit.h | 2 ++ 2 files changed, 12 insertions(+)
arch/riscv/include/asm/syscall.h +10 -0
@@ -18,6 +18,7 @@#ifndef _ASM_RISCV_SYSCALL_H#define _ASM_RISCV_SYSCALL_H +#include <uapi/linux/audit.h> #include <linux/sched.h> #include <linux/err.h>
@@ -99,4 +100,13 @@ static inline void syscall_set_arguments(struct task_struct *task, memcpy(®s->a1 + i * sizeof(regs->a1), args, n * sizeof(regs->a0)); } +static inline int syscall_get_arch (void ) +{ +#ifdef CONFIG_64BIT +return AUDIT_ARCH_RISCV64 ; +#else +return AUDIT_ARCH_RISCV32 ; +#endif +} +#endif /* _ASM_RISCV_SYSCALL_H */
include/uapi/linux/audit.h +2 -0
@@ -411,6 +411,8 @@ enum {/* do not define AUDIT_ARCH_PPCLE since it is not supported by audit */ #define AUDIT_ARCH_PPC64 (EM_PPC64|__AUDIT_ARCH_64BIT)#define AUDIT_ARCH_PPC64LE (EM_PPC64|__AUDIT_ARCH_64BIT|__AUDIT_ARCH_LE) +#define AUDIT_ARCH_RISCV32 (EM_RISCV|__AUDIT_ARCH_LE) +#define AUDIT_ARCH_RISCV64 (EM_RISCV|__AUDIT_ARCH_64BIT|__AUDIT_ARCH_LE)#define AUDIT_ARCH_S390 (EM_S390)#define AUDIT_ARCH_S390X (EM_S390|__AUDIT_ARCH_64BIT)#define AUDIT_ARCH_SH (EM_SH)
Signature · 1 line
ldv
PATCH v6 20/27 Move EM_XTENSA to uapi/linux/elf-em.h
In reply to Dmitry V. LevinThis should never have been defined in the arch tree to begin with, and now uapi/linux/audit.h header is going to use EM_XTENSA in order to define AUDIT_ARCH_XTENSA which is needed to implement syscall_get_arch() which in turn is required to extend the generic ptrace API with PTRACE_GET_SYSCALL_INFO request.
---
Notes:
v6: there is an earlier revision of this patch in xtensa tree where
EM_XTENSA is added to uapi/linux/elf-em.h but arch/xtensa/include/asm/elf.h remains unchanged
v5: move EM_XTENSA to elf-em.h instead of adding,
I didn't realize it was already defined in the arch tree
v2: added Reviewed-by
arch/xtensa/include/asm/elf.h | 2 +- include/uapi/linux/elf-em.h | 1 + 2 files changed, 2 insertions(+), 1 deletion(-)
arch/xtensa/include/asm/elf.h +1 -1
@@ -15,10 +15,10 @@#include <asm/ptrace.h> #include <asm/coprocessor.h> +#include <linux/elf-em.h> /* Xtensa processor ELF architecture-magic number */ -#define EM_XTENSA 94#define EM_XTENSA_OLD 0xABC7/* Xtensa relocations defined by the ABIs */
include/uapi/linux/elf-em.h +1 -0
@@ -35,6 +35,7 @@#define EM_MN10300 89/* Panasonic/MEI MN10300, AM33 */ #define EM_OPENRISC 92/* OpenRISC 32-bit embedded processor */ #define EM_ARCOMPACT 93/* ARCompact processor */ +#define EM_XTENSA 94/* Tensilica Xtensa Architecture */ #define EM_BLACKFIN 106/* ADI Blackfin Processor */ #define EM_ALTERA_NIOS2 113/* Altera Nios II soft-core processor */ #define EM_TI_C6000 140/* TI C6X DSPs */
Signature · 1 line
ldv
PATCH v6 21/27 xtensa: define syscall_get_* functions
In reply to Dmitry V. Levinsyscall_get_* functions are required to be implemented on all architectures in order to extend the generic ptrace API with PTRACE_GET_SYSCALL_INFO request.
This adds all 5 syscall_get_* functions on xtensa as documented in asm-generic/syscall.h: syscall_get_nr, syscall_get_arguments, syscall_get_error, syscall_get_return_value, and syscall_get_arch.
---
Notes:
v6: there is a tracehook support in xtensa tree where all syscall_get_*
functions are implemented already, no need to pay attention at this patch
v5: added syscall_get_nr, syscall_get_arguments, syscall_get_error,
and syscall_get_return_value
v2: added Acked-by
v1: added syscall_get_arch
arch/xtensa/include/asm/syscall.h | 65 +++++++++++++++++++++++++++++++ include/uapi/linux/audit.h | 1 + 2 files changed, 66 insertions(+)
arch/xtensa/include/asm/syscall.h +65 -0
@@ -8,6 +8,71 @@* Copyright (C) 2001 - 2007 Tensilica Inc. */ +#include <linux/err.h> +#include <uapi/linux/audit.h> +#include <asm/ptrace.h> +#include <asm-generic/syscall.h> + +static inline int +syscall_get_nr (struct task_struct *task,struct pt_regs *regs) +{ +return regs->syscall; +} + +static inline void +__syscall_get_arguments (struct task_struct *task,struct pt_regs *regs, +unsigned int i,unsigned int n,unsigned long *args) +{ +switch (i) { +case 0 : +if (!n--) +break ; + *args++ = regs->areg[6 ]; +/* fall through */ +case 1 : +if (!n--) +break ; + *args++ = regs->areg[3 ]; +/* fall through */ +case 2 : +if (!n--) +break ; + *args++ = regs->areg[4 ]; +/* fall through */ +case 3 : +if (!n--) +break ; + *args++ = regs->areg[5 ]; +/* fall through */ +case 4 : +if (!n--) +break ; + *args++ = regs->areg[8 ]; +/* fall through */ +case 5 : +if (!n--) +break ; + *args++ = regs->areg[9 ]; + } +} + +static inline long +syscall_get_error (struct task_struct *task,struct pt_regs *regs) +{ +return IS_ERR_VALUE (regs->areg[2 ]) ? regs->areg[2 ] :0 ; + +static inline long +syscall_get_return_value (struct task_struct *task,struct pt_regs *regs) +{ +return regs->areg[2 ]; +} + +static inline int +syscall_get_arch (void ) +{ +return AUDIT_ARCH_XTENSA ; +} +struct pt_regs ;asmlinkage long xtensa_ptrace (long ,long ,long ,long );asmlinkage long xtensa_sigreturn (struct pt_regs *);
include/uapi/linux/audit.h +1 -0
@@ -425,6 +425,7 @@ enum {#define AUDIT_ARCH_TILEGX32 (EM_TILEGX|__AUDIT_ARCH_LE)#define AUDIT_ARCH_TILEPRO (EM_TILEPRO|__AUDIT_ARCH_LE)#define AUDIT_ARCH_X86_64 (EM_X86_64|__AUDIT_ARCH_64BIT|__AUDIT_ARCH_LE) +#define AUDIT_ARCH_XTENSA (EM_XTENSA)#define AUDIT_PERM_EXEC 1#define AUDIT_PERM_WRITE 2
Signature · 1 line
ldv
PATCH v6 22/27 Move EM_UNICORE to uapi/linux/elf-em.h
In reply to Dmitry V. LevinThis should never have been defined in the arch tree to begin with, and now uapi/linux/audit.h header is going to use EM_UNICORE in order to define AUDIT_ARCH_UNICORE which is needed to implement syscall_get_arch() which in turn is required to extend the generic ptrace API with PTRACE_GET_SYSCALL_INFO request.
---
Notes:
v6: unchanged
v5: added Cc
arch/unicore32/include/asm/elf.h | 3 +-- include/uapi/linux/elf-em.h | 1 + 2 files changed, 2 insertions(+), 2 deletions(-)
arch/unicore32/include/asm/elf.h +1 -2
@@ -19,6 +19,7 @@* ELF register definitions.. */ #include <asm/ptrace.h> +#include <linux/elf-em.h> typedef unsigned long elf_greg_t ;typedef unsigned long elf_freg_t [3 ];
@@ -28,8 +29,6 @@ typedef elf_greg_t elf_gregset_t[ELF_NGREG];typedef struct fp_state elf_fpregset_t ; -#define EM_UNICORE 110 -#define R_UNICORE_NONE 0#define R_UNICORE_PC24 1#define R_UNICORE_ABS32 2
include/uapi/linux/elf-em.h +1 -0
@@ -37,6 +37,7 @@#define EM_ARCOMPACT 93/* ARCompact processor */ #define EM_XTENSA 94/* Tensilica Xtensa Architecture */ #define EM_BLACKFIN 106/* ADI Blackfin Processor */ +#define EM_UNICORE 110/* UniCore-32 */ #define EM_ALTERA_NIOS2 113/* Altera Nios II soft-core processor */ #define EM_TI_C6000 140/* TI C6X DSPs */ #define EM_HEXAGON 164/* QUALCOMM Hexagon */
Signature · 1 line
ldv
PATCH v6 23/27 unicore32: add asm/syscall.h
In reply to Dmitry V. Levinsyscall_get_* functions are required to be implemented on all architectures in order to extend the generic ptrace API with PTRACE_GET_SYSCALL_INFO request.
This introduces asm/syscall.h on unicore32 implementing all 5 syscall_get_* functions as documented in asm-generic/syscall.h:syscall_get_nr, syscall_get_arguments, syscall_get_error, syscall_get_return_value, and syscall_get_arch.
A note for the unicore32 architecture maintainer: I have no idea about the syscall semantics on this architecture, and the code is of little help here. All I could infer from the code is that it looks very similar to ARM, so the implementation of syscall_get_* functions is also similar to ARM.
---
Notes:
v6: made use of asm-generic/syscall.h
v5: added syscall_get_nr, syscall_get_arguments, syscall_get_error,
and syscall_get_return_value
v1: added syscall_get_arch
arch/unicore32/include/asm/syscall.h | 46 ++++++++++++++++++++++++++++ include/uapi/linux/audit.h | 1 + 2 files changed, 47 insertions(+) create mode 100644 arch/unicore32/include/asm/syscall.h
arch/unicore32/include/asm/syscall.h new file +47 -0
@@ -0,0 +1,47 @@ +/* SPDX-License-Identifier: GPL-2.0 */ +#ifndef _ASM_UNICORE_SYSCALL_H +#define _ASM_UNICORE_SYSCALL_H + +#include <linux/err.h> +#include <asm/ptrace.h> +#include <asm-generic/syscall.h> +#include <uapi/linux/audit.h> + +static inline int +syscall_get_nr (struct task_struct *task,struct pt_regs *regs) +{ +return task_thread_info (task)->syscall; +} + +static inline void +__syscall_get_arguments (struct task_struct *task,struct pt_regs *regs, +unsigned int i,unsigned int n,unsigned long *args) +{ +if (i ==0 ) { + args[0 ] = regs->UCreg_ORIG_00; + args++; + i++; + n--; + } +memcpy (args, ®s->UCreg_00 + i, n *sizeof (args[0 ])); +} + +static inline long +syscall_get_error (struct task_struct *task,struct pt_regs *regs) +{ +return IS_ERR_VALUE (regs->UCreg_00) ? regs->UCreg_00 :0 ; +} + +static inline long +syscall_get_return_value (struct task_struct *task,struct pt_regs *regs) +{ +return regs->UCreg_00; +} + +static inline int +syscall_get_arch (void ) +{ +return AUDIT_ARCH_UNICORE ; +} + +#endif /* _ASM_UNICORE_SYSCALL_H */
include/uapi/linux/audit.h +1 -0
@@ -424,6 +424,7 @@ enum {#define AUDIT_ARCH_TILEGX (EM_TILEGX|__AUDIT_ARCH_64BIT|__AUDIT_ARCH_LE)#define AUDIT_ARCH_TILEGX32 (EM_TILEGX|__AUDIT_ARCH_LE)#define AUDIT_ARCH_TILEPRO (EM_TILEPRO|__AUDIT_ARCH_LE) +#define AUDIT_ARCH_UNICORE (EM_UNICORE|__AUDIT_ARCH_LE)#define AUDIT_ARCH_X86_64 (EM_X86_64|__AUDIT_ARCH_64BIT|__AUDIT_ARCH_LE)#define AUDIT_ARCH_XTENSA (EM_XTENSA)
Signature · 1 line
ldv
PATCH v6 24/27 syscall_get_arch: add "struct task_struct *" argument
In reply to Dmitry V. LevinThis argument is required to extend the generic ptrace API with PTRACE_GET_SYSCALL_INFO request: syscall_get_arch() is going to be called from ptrace_request() along with syscall_get_nr(), syscall_get_arguments(), syscall_get_error(), and syscall_get_return_value() functions with a tracee as their argument.
Reverts: 5e937a9ae913 ("syscall_get_arch: remove useless function arguments")
Reverts: 1002d94d3076 ("syscall.h: fix doc text for syscall_get_arch()")
---
Notes:
v6: added more Acked-by
v5: added Cc
v2: cleaned up mips part, added Reviewed-by
arch/alpha/include/asm/syscall.h | 2 +- arch/arc/include/asm/syscall.h | 2 +- arch/arm/include/asm/syscall.h | 2 +- arch/arm64/include/asm/syscall.h | 4 ++-- arch/c6x/include/asm/syscall.h | 2 +- arch/csky/include/asm/syscall.h | 2 +- arch/h8300/include/asm/syscall.h | 2 +- arch/hexagon/include/asm/syscall.h | 2 +- arch/ia64/include/asm/syscall.h | 2 +- arch/m68k/include/asm/syscall.h | 2 +- arch/microblaze/include/asm/syscall.h | 2 +- arch/mips/include/asm/syscall.h | 6 +++--- arch/mips/kernel/ptrace.c | 2 +- arch/nds32/include/asm/syscall.h | 2 +- arch/nios2/include/asm/syscall.h | 2 +- arch/openrisc/include/asm/syscall.h | 2 +- arch/parisc/include/asm/syscall.h | 4 ++-- arch/powerpc/include/asm/syscall.h | 10 ++++++++-- arch/riscv/include/asm/syscall.h | 2 +- arch/s390/include/asm/syscall.h | 4 ++-- arch/sh/include/asm/syscall_32.h | 2 +- arch/sh/include/asm/syscall_64.h | 2 +- arch/sparc/include/asm/syscall.h | 5 +++-- arch/unicore32/include/asm/syscall.h | 2 +- arch/x86/include/asm/syscall.h | 8 +++++--- arch/x86/um/asm/syscall.h | 2 +- arch/xtensa/include/asm/syscall.h | 2 +- include/asm-generic/syscall.h | 5 +++-- kernel/auditsc.c | 4 ++-- kernel/seccomp.c | 4 ++-- 30 files changed, 52 insertions(+), 42 deletions(-)
arch/alpha/include/asm/syscall.h +1 -1
@@ -33,7 +33,7 @@ syscall_get_return_value(struct task_struct *task, struct pt_regs *regs) }static inline int -syscall_get_arch (void ) +syscall_get_arch (struct task_struct *task) {return AUDIT_ARCH_ALPHA ; }
arch/arc/include/asm/syscall.h +1 -1
@@ -70,7 +70,7 @@ syscall_get_arguments(struct task_struct *task, struct pt_regs *regs, }static inline int -syscall_get_arch (void ) +syscall_get_arch (struct task_struct *task) {return IS_ENABLED (CONFIG_ISA_ARCOMPACT ) ? (IS_ENABLED(CONFIG_CPU_BIG_ENDIAN)
arch/arm/include/asm/syscall.h +1 -1
@@ -104,7 +104,7 @@ static inline void syscall_set_arguments(struct task_struct *task,memcpy (®s->ARM_r0 + i, args, n *sizeof (args[0 ])); } -static inline int syscall_get_arch (void ) +static inline int syscall_get_arch (struct task_struct *task) {/* ARM tasks don't change audit architectures on the fly. */ return AUDIT_ARCH_ARM ;
arch/arm64/include/asm/syscall.h +2 -2
@@ -117,9 +117,9 @@ static inline void syscall_set_arguments(struct task_struct *task,* We don't care about endianness (__AUDIT_ARCH_LE bit) here because * AArch64 has the same system calls both on little- and big- endian. */ -static inline int syscall_get_arch (void ) +static inline int syscall_get_arch (struct task_struct *task) { -if (is_compat_task ()) +if (is_compat_thread (task_thread_info (task)))return AUDIT_ARCH_ARM ;return AUDIT_ARCH_AARCH64 ;
arch/c6x/include/asm/syscall.h +1 -1
@@ -121,7 +121,7 @@ static inline void syscall_set_arguments(struct task_struct *task, } } -static inline int syscall_get_arch (void ) +static inline int syscall_get_arch (struct task_struct *task) {return IS_ENABLED (CONFIG_CPU_BIG_ENDIAN ) ?AUDIT_ARCH_C6XBE :AUDIT_ARCH_C6X ;
arch/csky/include/asm/syscall.h +1 -1
@@ -70,7 +70,7 @@ syscall_set_arguments(struct task_struct *task, struct pt_regs *regs, }static inline int -syscall_get_arch (void ) +syscall_get_arch (struct task_struct *task) {return AUDIT_ARCH_CSKY ; }
arch/h8300/include/asm/syscall.h +1 -1
@@ -62,7 +62,7 @@ syscall_get_return_value(struct task_struct *task, struct pt_regs *regs) }static inline int -syscall_get_arch (void ) +syscall_get_arch (struct task_struct *task) {return AUDIT_ARCH_H8300 ; }
arch/hexagon/include/asm/syscall.h +1 -1
@@ -60,7 +60,7 @@ static inline long syscall_get_return_value(struct task_struct *task,return regs->r00; } -static inline int syscall_get_arch (void ) +static inline int syscall_get_arch (struct task_struct *task) {return AUDIT_ARCH_HEXAGON ; }
arch/ia64/include/asm/syscall.h +1 -1
@@ -81,7 +81,7 @@ static inline void syscall_set_arguments(struct task_struct *task,ia64_syscall_get_set_arguments (task, regs, i, n, args,1 ); } -static inline int syscall_get_arch (void ) +static inline int syscall_get_arch (struct task_struct *task) {return AUDIT_ARCH_IA64 ; }
arch/m68k/include/asm/syscall.h +1 -1
@@ -34,7 +34,7 @@ syscall_get_return_value(struct task_struct *task, struct pt_regs *regs) }static inline int -syscall_get_arch (void ) +syscall_get_arch (struct task_struct *task) {return AUDIT_ARCH_M68K ; }
arch/microblaze/include/asm/syscall.h +1 -1
@@ -101,7 +101,7 @@ static inline void syscall_set_arguments(struct task_struct *task,asmlinkage unsigned long do_syscall_trace_enter (struct pt_regs *regs); asmlinkage void do_syscall_trace_leave(struct pt_regs *regs); -static inline int syscall_get_arch (void ) +static inline int syscall_get_arch (struct task_struct *task) {return AUDIT_ARCH_MICROBLAZE ; }
arch/mips/include/asm/syscall.h +3 -3
@@ -146,14 +146,14 @@ extern const unsigned long sys_call_table[];extern const unsigned long sys32_call_table[];extern const unsigned long sysn32_call_table[]; -static inline int syscall_get_arch (void ) +static inline int syscall_get_arch (struct task_struct *task) {int arch =AUDIT_ARCH_MIPS ;#ifdef CONFIG_64BIT -if (!test_thread_flag (TIF_32BIT_REGS )) { +if (!test_tsk_thread_flag (task,TIF_32BIT_REGS )) { arch |= __AUDIT_ARCH_64BIT;/* N32 sets only TIF_32BIT_ADDR */ -if (test_thread_flag (TIF_32BIT_ADDR )) +if (test_tsk_thread_flag (task,TIF_32BIT_ADDR )) arch |= __AUDIT_ARCH_CONVENTION_MIPS64_N32; }#endif
arch/mips/kernel/ptrace.c +1 -1
@@ -1272,7 +1272,7 @@ asmlinkage long syscall_trace_enter(struct pt_regs *regs, long syscall)unsigned long args[6 ]; sd.nr = syscall; - sd.arch =syscall_get_arch (); + sd.arch =syscall_get_arch (current);syscall_get_arguments (current, regs,0 ,6 , args);for (i =0 ; i <6 ; i++) sd.args[i] = args[i];
arch/nds32/include/asm/syscall.h +1 -1
@@ -187,7 +187,7 @@ void syscall_set_arguments(struct task_struct *task, struct pt_regs *regs,memcpy (®s->uregs[0 ] + i, args, n *sizeof (args[0 ])); } -static inline int syscall_get_arch (void ) +static inline int syscall_get_arch (struct task_struct *task) {return IS_ENABLED (CONFIG_CPU_BIG_ENDIAN ) ?AUDIT_ARCH_NDS32BE :AUDIT_ARCH_NDS32 ;
arch/nios2/include/asm/syscall.h +1 -1
@@ -136,7 +136,7 @@ static inline void syscall_set_arguments(struct task_struct *task, } } -static inline int syscall_get_arch (void ) +static inline int syscall_get_arch (struct task_struct *task) {return AUDIT_ARCH_NIOS2 ; }
arch/openrisc/include/asm/syscall.h +1 -1
@@ -72,7 +72,7 @@ syscall_set_arguments(struct task_struct *task, struct pt_regs *regs,memcpy (®s->gpr[3 + i], args, n *sizeof (args[0 ])); } -static inline int syscall_get_arch (void ) +static inline int syscall_get_arch (struct task_struct *task) {return AUDIT_ARCH_OPENRISC ; }
arch/parisc/include/asm/syscall.h +2 -2
@@ -69,11 +69,11 @@ static inline void syscall_rollback(struct task_struct *task,/* do nothing */ } -static inline int syscall_get_arch (void ) +static inline int syscall_get_arch (struct task_struct *task) {int arch =AUDIT_ARCH_PARISC ;#ifdef CONFIG_64BIT -if (!is_compat_task ()) +if (!__is_compat_task (task)) arch =AUDIT_ARCH_PARISC64 ;#endif return arch;
arch/powerpc/include/asm/syscall.h +8 -2
@@ -110,9 +110,15 @@ static inline void syscall_set_arguments(struct task_struct *task, regs->orig_gpr3 = args[0 ]; } -static inline int syscall_get_arch (void ) +static inline int syscall_get_arch (struct task_struct *task) { -int arch =is_32bit_task () ?AUDIT_ARCH_PPC :AUDIT_ARCH_PPC64 ; +int arch; + +if (IS_ENABLED (CONFIG_PPC64 ) && !test_tsk_thread_flag (task,TIF_32BIT )) + arch =AUDIT_ARCH_PPC64 ; +else + arch =AUDIT_ARCH_PPC ; +#ifdef __LITTLE_ENDIAN__ arch |= __AUDIT_ARCH_LE;#endif
arch/riscv/include/asm/syscall.h +1 -1
@@ -100,7 +100,7 @@ static inline void syscall_set_arguments(struct task_struct *task,memcpy (®s->a1 + i *sizeof (regs->a1), args, n *sizeof (regs->a0)); } -static inline int syscall_get_arch (void ) +static inline int syscall_get_arch (struct task_struct *task) {#ifdef CONFIG_64BIT return AUDIT_ARCH_RISCV64 ;
arch/s390/include/asm/syscall.h +2 -2
@@ -92,10 +92,10 @@ static inline void syscall_set_arguments(struct task_struct *task, regs->orig_gpr2 = args[0 ]; } -static inline int syscall_get_arch (void ) +static inline int syscall_get_arch (struct task_struct *task) {#ifdef CONFIG_COMPAT -if (test_tsk_thread_flag (current,TIF_31BIT )) +if (test_tsk_thread_flag (task,TIF_31BIT ))return AUDIT_ARCH_S390 ;#endif return AUDIT_ARCH_S390X ;
arch/sh/include/asm/syscall_32.h +1 -1
@@ -95,7 +95,7 @@ static inline void syscall_set_arguments(struct task_struct *task, } } -static inline int syscall_get_arch (void ) +static inline int syscall_get_arch (struct task_struct *task) {int arch =AUDIT_ARCH_SH ;
arch/sh/include/asm/syscall_64.h +1 -1
@@ -63,7 +63,7 @@ static inline void syscall_set_arguments(struct task_struct *task,memcpy (®s->regs[2 + i], args, n *sizeof (args[0 ])); } -static inline int syscall_get_arch (void ) +static inline int syscall_get_arch (struct task_struct *task) {int arch =AUDIT_ARCH_SH ;
arch/sparc/include/asm/syscall.h +3 -2
@@ -128,10 +128,11 @@ static inline void syscall_set_arguments(struct task_struct *task, regs->u_regs[UREG_I0 + i + j] = args[j]; } -static inline int syscall_get_arch (void ) +static inline int syscall_get_arch (struct task_struct *task) {#if defined(CONFIG_SPARC64 ) && defined(CONFIG_COMPAT ) -return in_compat_syscall () ?AUDIT_ARCH_SPARC :AUDIT_ARCH_SPARC64 ; +return test_tsk_thread_flag (task,TIF_32BIT ) + ?AUDIT_ARCH_SPARC :AUDIT_ARCH_SPARC64 ;#elif defined(CONFIG_SPARC64 )return AUDIT_ARCH_SPARC64 ;#else
arch/unicore32/include/asm/syscall.h +1 -1
@@ -38,7 +38,7 @@ syscall_get_return_value(struct task_struct *task, struct pt_regs *regs) }static inline int -syscall_get_arch (void ) +syscall_get_arch (struct task_struct *task) {return AUDIT_ARCH_UNICORE ; }
arch/x86/include/asm/syscall.h +5 -3
@@ -107,7 +107,7 @@ static inline void syscall_set_arguments(struct task_struct *task,memcpy (®s->bx + i, args, n *sizeof (args[0 ])); } -static inline int syscall_get_arch (void ) +static inline int syscall_get_arch (struct task_struct *task) {return AUDIT_ARCH_I386 ; }
@@ -236,10 +236,12 @@ static inline void syscall_set_arguments(struct task_struct *task, } } -static inline int syscall_get_arch (void ) +static inline int syscall_get_arch (struct task_struct *task) {/* x32 tasks should be considered AUDIT_ARCH_X86_64. */ -return in_ia32_syscall () ?AUDIT_ARCH_I386 :AUDIT_ARCH_X86_64 ; +return (IS_ENABLED (CONFIG_IA32_EMULATION ) && + task->thread_info.status &TS_COMPAT ) + ?AUDIT_ARCH_I386 :AUDIT_ARCH_X86_64 ; }#endif /* CONFIG_X86_32 */
arch/x86/um/asm/syscall.h +1 -1
@@ -9,7 +9,7 @@ typedef asmlinkage long (*sys_call_ptr_t)(unsigned long, unsigned long, unsigned long, unsigned long, unsigned long, unsigned long); -static inline int syscall_get_arch (void ) +static inline int syscall_get_arch (struct task_struct *task) {#ifdef CONFIG_X86_32 return AUDIT_ARCH_I386 ;
arch/xtensa/include/asm/syscall.h +1 -1
@@ -68,7 +68,7 @@ syscall_get_return_value(struct task_struct *task, struct pt_regs *regs) }static inline int -syscall_get_arch (void ) +syscall_get_arch (struct task_struct *task) {return AUDIT_ARCH_XTENSA ; }
include/asm-generic/syscall.h +3 -2
@@ -194,16 +194,17 @@ syscall_set_arguments(struct task_struct *task, struct pt_regs *regs,/** * syscall_get_arch - return the AUDIT_ARCH for the current system call +* @task: task of interest, must be blocked * * Returns the AUDIT_ARCH_* based on the system call convention in use. * -* It's only valid to call this when current is stopped on entry to a system +* It's only valid to call this when @task is stopped on entry to a system * call, due to %TIF_SYSCALL_TRACE, %TIF_SYSCALL_AUDIT, or %TIF_SECCOMP. * * Architectures which permit CONFIG_HAVE_ARCH_SECCOMP_FILTER must * provide an implementation of this. */ static int -syscall_get_arch (void ); +syscall_get_arch (struct task_struct *task);#endif /* _ASM_GENERIC_SYSCALL_H */
kernel/auditsc.c +2 -2
@@ -1537,7 +1537,7 @@ void __audit_syscall_entry(int major, unsigned long a1, unsigned long a2,return ; } - context->arch =syscall_get_arch (); + context->arch =syscall_get_arch (current); context->major = major; context->argv[0 ] = a1; context->argv[1 ] = a2;
@@ -2495,7 +2495,7 @@ void audit_seccomp(unsigned long syscall, long signr, int code)return ;audit_log_task (ab);audit_log_format (ab," sig=%ld arch=%x syscall=%ld compat=%d ip=0x%lx code=0x%x" , - signr,syscall_get_arch (), syscall, + signr,syscall_get_arch (current), syscall,in_compat_syscall (),KSTK_EIP (current), code);audit_log_end (ab); }
kernel/seccomp.c +2 -2
@@ -82,7 +82,7 @@ static void populate_seccomp_data(struct seccomp_data *sd)unsigned long args[6 ]; sd->nr =syscall_get_nr (task, regs); - sd->arch =syscall_get_arch (); + sd->arch =syscall_get_arch (task);syscall_get_arguments (task, regs,0 ,6 , args); sd->args[0 ] = args[0 ]; sd->args[1 ] = args[1 ];
@@ -529,7 +529,7 @@ static void seccomp_init_siginfo(kernel_siginfo_t *info, int syscall, int reason info->si_code =SYS_SECCOMP ; info->si_call_addr = (void __user *)KSTK_EIP (current); info->si_errno = reason; - info->si_arch =syscall_get_arch (); + info->si_arch =syscall_get_arch (current); info->si_syscall = syscall; }
Signature · 1 line
ldv
PATCH v6 25/27 powerpc/ptrace: replace ptrace_report_syscall() with a tracehook call
In reply to Dmitry V. LevinFrom: Elvira Khabirova <[email protected]>
Arch code should use tracehook_*() helpers, as documented in include/linux/tracehook.h, ptrace_report_syscall() is not expected to be used outside that file.
The patch does not look very nice, but at least it is correct and opens the way for PTRACE_GET_SYSCALL_INFO API.
---
Notes:
v6: this is the fix that was taken into powerpc tree
v5: reverted to a simple approach, compile- and run-tested
v4: rewritten to call tracehook_report_syscall_entry() once, compile-tested
v3: add a descriptive comment
v2: explicitly ignore tracehook_report_syscall_entry() return code
arch/powerpc/kernel/ptrace.c | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-)
arch/powerpc/kernel/ptrace.c +6 -1
@@ -3266,12 +3266,17 @@ long do_syscall_trace_enter(struct pt_regs *regs)user_exit ();if (test_thread_flag (TIF_SYSCALL_EMU )) { -ptrace_report_syscall (regs);/* +* A nonzero return code from tracehook_report_syscall_entry() +* tells us to prevent the syscall execution, but we are not +* going to execute it anyway. +* * Returning -1 will skip the syscall execution. We want to * avoid clobbering any register also, thus, not 'gotoing' * skip label. */ +if (tracehook_report_syscall_entry (regs)) + ;return -1 ; }
Signature · 1 line
ldv
PATCH v6 26/27 ptrace: add PTRACE_GET_SYSCALL_INFO request
In reply to Dmitry V. LevinFrom: Elvira Khabirova <[email protected]>
PTRACE_GET_SYSCALL_INFO is a generic ptrace API that lets ptracer obtain details of the syscall the tracee is blocked in.
There are two reasons for a special syscall-related ptrace request.
Firstly, with the current ptrace API there are cases when ptracer cannot retrieve necessary information about syscalls. Some examples include:
* The notorious int-0x80-from-64-bit-task issue. See [1] for details. In short, if a 64-bit task performs a syscall through int 0x80, its tracer has no reliable means to find out that the syscall was, in fact, a compat syscall, and misidentifies it.
* Syscall-enter-stop and syscall-exit-stop look the same for the tracer. Common practice is to keep track of the sequence of ptrace-stops in order not to mix the two syscall-stops up. But it is not as simple as it looks; for example, strace had a (just recently fixed) long-standing bug where attaching strace to a tracee that is performing the execve system call led to the tracer identifying the following syscall-exit-stop as syscall-enter-stop, which messed up all the state tracking.
* Since the introduction of commit 84d77d3f06e7e8dea057d10e8ec77ad71f721be3 ("ptrace: Don't allow accessing an undumpable mm"), both PTRACE_PEEKDATA and process_vm_readv become unavailable when the process dumpable flag is cleared. On such architectures as ia64 this results in all syscall arguments being unavailable for the tracer.
Secondly, ptracers also have to support a lot of arch-specific code for obtaining information about the tracee. For some architectures, this requires a ptrace(PTRACE_PEEKUSER, ...) invocation for every syscall argument and return value.
ptrace(2) man page:
long ptrace(enum __ptrace_request request, pid_t pid,
void *addr, void *data);
...PTRACE_GET_SYSCALL_INFO
Retrieve information about the syscall that caused the stop. The information is placed into the buffer pointed by "data" argument, which should be a pointer to a buffer of type "struct ptrace_syscall_info".
The "addr" argument contains the size of the buffer pointed to by "data" argument (i.e., sizeof(struct ptrace_syscall_info)). The return value contains the number of bytes available to be written by the kernel.
If the size of data to be written by the kernel exceeds the size specified by "addr" argument, the output is truncated.
---
Notes:
v6:
* Change PTRACE_GET_SYSCALL_INFO return code: do not take trailing paddings into account, use the end of the last field of the structure being written.
* Change struct ptrace_syscall_info:
* remove .frame_pointer field, is is not needed and not portable;
* make .arch field explicitly aligned, remove no longer needed padding before .arch field;
* remove trailing pads, they are no longer needed.
v5:
* Change PTRACE_EVENTMSG_SYSCALL_{ENTRY,EXIT} values as requested by Oleg.
* Change struct ptrace_syscall_info: generalize instruction_pointer, stack_pointer, and frame_pointer fields by moving them from ptrace_syscall_info.{entry,seccomp} substructures to ptrace_syscall_info and initializing them for all stops.
* Add PTRACE_SYSCALL_INFO_NONE, set it when not in a syscall stop, so e.g. "strace -i" could use PTRACE_SYSCALL_INFO_SECCOMP to obtain instruction_pointer when the tracee is in a signal stop.
* Make available for all architectures: do not conditionalize on CONFIG_HAVE_ARCH_TRACEHOOK since all syscall_get_* functions are implemented on all architectures.
v4:
* Do not introduce task_struct.ptrace_event,
use child->last_siginfo->si_code instead.
* Implement PTRACE_SYSCALL_INFO_SECCOMP and ptrace_syscall_info.seccomp support along with PTRACE_SYSCALL_INFO_{ENTRY,EXIT} and ptrace_syscall_info.{entry,exit}.
v3:
* Change struct ptrace_syscall_info.
* Support PTRACE_EVENT_SECCOMP by adding ptrace_event to task_struct.
* Add proper defines for ptrace_syscall_info.op values.
* Rename PT_SYSCALL_IS_ENTERING and PT_SYSCALL_IS_EXITING to PTRACE_EVENTMSG_SYSCALL_ENTRY and PTRACE_EVENTMSG_SYSCALL_EXIT
* and move them to uapi.
v2:
* Do not use task->ptrace.
* Replace entry_info.is_compat with entry_info.arch, use syscall_get_arch().
* Use addr argument of sys_ptrace to get expected size of the struct; return full size of the struct.
include/linux/tracehook.h | 9 ++-- include/uapi/linux/ptrace.h | 35 +++++++++++++ kernel/ptrace.c | 101 +++++++++++++++++++++++++++++++++++- 3 files changed, 141 insertions(+), 4 deletions(-)
include/linux/tracehook.h +6 -3
@@ -57,13 +57,15 @@ struct linux_binprm;/* * ptrace report for syscall entry and exit looks identical. */ -static inline int ptrace_report_syscall (struct pt_regs *regs) +static inline int ptrace_report_syscall (struct pt_regs *regs, +unsigned long message) {int ptrace = current->ptrace;if (!(ptrace &PT_PTRACED ))return 0 ; + current->ptrace_message = message;ptrace_notify (SIGTRAP | ((ptrace &PT_TRACESYSGOOD ) ?0x80 :0 ));/*
@@ -76,6 +78,7 @@ static inline int ptrace_report_syscall(struct pt_regs *regs) current->exit_code =0 ; } + current->ptrace_message =0 ;return fatal_signal_pending (current); }
@@ -101,7 +104,7 @@ static inline int ptrace_report_syscall(struct pt_regs *regs)static inline __must_check int tracehook_report_syscall_entry (struct pt_regs *regs) { -return ptrace_report_syscall (regs); +return ptrace_report_syscall (regs,PTRACE_EVENTMSG_SYSCALL_ENTRY ); }/**
@@ -126,7 +129,7 @@ static inline void tracehook_report_syscall_exit(struct pt_regs *regs, int step)if (step)user_single_step_report (regs);else -ptrace_report_syscall (regs); +ptrace_report_syscall (regs,PTRACE_EVENTMSG_SYSCALL_EXIT ); }/**
include/uapi/linux/ptrace.h +35 -0
@@ -73,6 +73,41 @@ struct seccomp_metadata {__u64 flags;/* Output: filter's flags */ }; +#define PTRACE_GET_SYSCALL_INFO 0x420e +#define PTRACE_SYSCALL_INFO_NONE 0 +#define PTRACE_SYSCALL_INFO_ENTRY 1 +#define PTRACE_SYSCALL_INFO_EXIT 2 +#define PTRACE_SYSCALL_INFO_SECCOMP 3 + +struct ptrace_syscall_info { +__u8 op;/* PTRACE_SYSCALL_INFO_* */ +__u32 arch __attribute__((__aligned__ (sizeof (__u32)))); +__u64 instruction_pointer; +__u64 stack_pointer; +union { +struct { +__u64 nr; +__u64 args[6 ]; + } entry; +struct { +__s64 rval; +__u8 is_error; + } exit; +struct { +__u64 nr; +__u64 args[6 ]; +__u32 ret_data; + } seccomp; + }; +}; + +/* +* These values are stored in task->ptrace_message +* by tracehook_report_syscall_* to describe the current syscall-stop. +*/ +#define PTRACE_EVENTMSG_SYSCALL_ENTRY 1 +#define PTRACE_EVENTMSG_SYSCALL_EXIT 2 +/* Read signals from a shared (process wide) queue */ #define PTRACE_PEEKSIGINFO_SHARED (1 << 0)
kernel/ptrace.c +100 -1
119 lines not on this page · raw message
Signature · 1 line
ldv
PATCH v6 27/27 selftests/ptrace: add a test case for PTRACE_GET_SYSCALL_INFO
In reply to Dmitry V. LevinCheck whether PTRACE_GET_SYSCALL_INFO semantics implemented in the kernel matches userspace expectations.
---
Notes:
v6: made PTRACE_GET_SYSCALL_INFO return value checks strict
tools/testing/selftests/ptrace/.gitignore | 1 + tools/testing/selftests/ptrace/Makefile | 2 +- .../selftests/ptrace/get_syscall_info.c | 271 ++++++++++++++++++ 3 files changed, 273 insertions(+), 1 deletion(-) create mode 100644 tools/testing/selftests/ptrace/get_syscall_info.c
tools/testing/selftests/ptrace/.gitignore +1 -0
@@ -1 +1,2 @@ +get_syscall_info peeksiginfo
tools/testing/selftests/ptrace/Makefile +1 -1
@@ -1,5 +1,5 @@ CFLAGS += -iquote../../../../include/uapi -Wall -TEST_GEN_PROGS := peeksiginfo +TEST_GEN_PROGS := get_syscall_info peeksiginfo include ../lib.mk
tools/testing/selftests/ptrace/get_syscall_info.c new file +271 -0
271 lines not on this page · raw message
Signature · 1 line
ldv
Quoted 156 lines · Dmitry V. Levin
PTRACE_GET_SYSCALL_INFOis a generic ptrace API that lets ptracer obtain details of the syscall the tracee is blocked in.There are two reasons for a special syscall-related ptrace request.
Firstly, with the current ptrace API there are cases when ptracer cannot retrieve necessary information about syscalls. Some examples include:
* The notorious int-0x80-from-64-bit-task issue. See [1] for details. In short, if a 64-bit task performs a syscall through int0x80, its tracer has no reliable means to find out that the syscall was, in fact, a compat syscall, and misidentifies it.
* Syscall-enter-stop and syscall-exit-stop look the same for the tracer. Common practice is to keep track of the sequence of ptrace-stops in order not to mix the two syscall-stops up. But it is not as simple as it looks; for example, strace had a (just recently fixed) long-standing bug where attaching strace to a tracee that is performing the execve system call led to the tracer identifying the following syscall-exit-stop as syscall-enter-stop, which messed up all the state tracking.
* Since the introduction of commit84d77d3f06e7e8dea057d10e8ec77ad71f721be3("ptrace: Don't allow accessing an undumpable mm"), bothPTRACE_PEEKDATAandprocess_vm_readvbecome unavailable when the process dumpable flag is cleared. On such architectures as ia64 this results in all syscall arguments being unavailable for the tracer.Secondly, ptracers also have to support a lot of arch-specific code for obtaining information about the tracee. For some architectures, this requires a
ptrace(PTRACE_PEEKUSER, ...)invocation for every syscall argument and return value.
PTRACE_GET_SYSCALL_INFOreturns the following structure:struct ptrace_syscall_info { __u8 op; /* PTRACE_SYSCALL_INFO_* */ __u32 arch __attribute__((__aligned__(sizeof(__u32)))); __u64 instruction_pointer; __u64 stack_pointer; union { struct { __u64 nr; __u64 args[6]; } entry; struct { __s64 rval; __u8 is_error; } exit; struct { __u64 nr; __u64 args[6]; __u32 ret_data; } seccomp; }; };The structure was chosen according to [2], except for the following changes:
* seccomp substructure was added as a superset of entry substructure;
* the type of nr field was changed from int to__u64because syscall numbers are, as a practical matter, 64 bits;
*stack_pointerfield was added along withinstruction_pointerfield since it is readily available and can save the tracer from extra PTRACE_GETREGS/PTRACE_GETREGSET calls;
* arch is always initialized to aid with tracing system calls
* such asexecve();
*instruction_pointerandstack_pointerare always initialized so they could be easily obtained for non-syscall stops;
* a booleanis_errorfield was added along with rval field, this way the tracer can more reliably distinguish a return value from an error value.strace has been ported to
PTRACE_GET_SYSCALL_INFO, you can find it in [3] and [4].[1] https://lore.kernel.org/lkml/CA+55aFzcSVmdDj9Lh_gdbz1OzHyEm6ZrGPBDAJnywm2LF_eVyg@mail.gmail.com/
[2] https://lore.kernel.org/lkml/CAObL_7GM0n80N7J_DFw_eQyfLyzq+sf4y2AvsCCV88Tb3AwEHA@mail.gmail.com/
[3] https://github.com/strace/strace/commits/ldv/PTRACE_GET_SYSCALL_INFO
[4] https://gitlab.com/strace/strace/commits/ldv/PTRACE_GET_SYSCALL_INFO---
Notes:
v6:
* Addsyscall_get_argumentsandsyscall_set_argumentswrappers toasm-generic/syscall.h, requested by Geert.
* ChangePTRACE_GET_SYSCALL_INFOreturn code: do not take trailing paddings into account, use the end of the last field of the structure being written.
* Change structptrace_syscall_info:
* remove .frame_pointer field, is is not needed and not portable;
* make .arch field explicitly aligned, remove no longer needed padding before .arch field;
* remove trailing pads, they are no longer needed.v5:
* Merge separate series and patches into the single series.
* Change PTRACE_EVENTMSG_SYSCALL_{ENTRY,EXIT} values as requested by Oleg.
* Change structptrace_syscall_info: generalizeinstruction_pointer,stack_pointer, andframe_pointerfields by moving them from ptrace_syscall_info.{entry,seccomp} substructures toptrace_syscall_infoand initializing them for all stops.
* AddPTRACE_SYSCALL_INFO_NONE, set it when not in a syscall stop, so e.g. "strace -i" could usePTRACE_SYSCALL_INFO_SECCOMPto obtaininstruction_pointerwhen the tracee is in a signal stop.
* Patch all remaining architectures to provide all necessary syscall_get_* functions.
* Make available for all architectures: do not conditionalize onCONFIG_HAVE_ARCH_TRACEHOOKsince all syscall_get_* functions are implemented on all architectures.
* Add a test forPTRACE_GET_SYSCALL_INFOto selftests/ptrace.v4:
* Do not introduce task_struct.ptrace_event,
usechild->last_siginfo->si_codeinstead.
* ImplementPTRACE_SYSCALL_INFO_SECCOMPand ptrace_syscall_info.seccomp support along with PTRACE_SYSCALL_INFO_{ENTRY,EXIT} and ptrace_syscall_info.{entry,exit}.v3:
* Change structptrace_syscall_info.
* SupportPTRACE_EVENT_SECCOMPby addingptrace_eventtotask_struct.
* Add proper defines for ptrace_syscall_info.op values.
* RenamePT_SYSCALL_IS_ENTERINGandPT_SYSCALL_IS_EXITINGtoPTRACE_EVENTMSG_SYSCALL_ENTRYandPTRACE_EVENTMSG_SYSCALL_EXIT
* and move them to uapi.v2:
* Do not usetask->ptrace.
* Replace entry_info.is_compat with entry_info.arch, usesyscall_get_arch().
* Use addr argument ofsys_ptraceto get expected size of the struct; return full size of the struct.Dmitry V. Levin (25):
asm-generic/syscall.h: prepare for inclusion by other filesasm-generic/syscall.h: turn syscall_[gs]et_arguments into wrappers
alpha: define remaining syscall_get_* functions
MoveEM_ARCOMPACTandEM_ARCV2touapi/linux/elf-em.h
arc: definesyscall_get_arch()
c6x: definesyscall_get_arch()
elf-em.h: addEM_CSKY
csky: definesyscall_get_arch()
h8300: define remaining syscall_get_* functions
MoveEM_HEXAGONtouapi/linux/elf-em.h
hexagon: define remaining syscall_get_* functions
MoveEM_NDS32touapi/linux/elf-em.h
nds32: definesyscall_get_arch()
nios2: definesyscall_get_arch()
m68k: addasm/syscall.h
mips: definesyscall_get_error()
parisc: definesyscall_get_error()
powerpc: definesyscall_get_error()
riscv: definesyscall_get_arch()
MoveEM_XTENSAtouapi/linux/elf-em.h
xtensa: define syscall_get_* functions
MoveEM_UNICOREtouapi/linux/elf-em.h
unicore32: addasm/syscall.h
syscall_get_arch: add "structtask_struct*" argument selftests/ptrace: add a test case forPTRACE_GET_SYSCALL_INFO
Quoted 3 lines
Elvira Khabirova (2):
powerpc/ptrace: replaceptrace_report_syscall()with a tracehook call
ptrace: addPTRACE_GET_SYSCALL_INFOrequest
As mentioned in the previous patchsets, this all looks fine to me from an audit perspective (although there is not much audit code to really comment on). Feel free to add my ACK to the audit related patches.
Quoted 49 lines
arch/alpha/include/asm/syscall.h | 31 +- arch/arc/include/asm/elf.h | 6 +- arch/arc/include/asm/syscall.h | 11 + arch/arm/include/asm/syscall.h | 2 +- arch/arm64/include/asm/syscall.h | 4 +- arch/c6x/include/asm/syscall.h | 7 + arch/csky/include/asm/syscall.h | 7 + arch/h8300/include/asm/syscall.h | 19 ++ arch/hexagon/include/asm/elf.h | 6 +- arch/hexagon/include/asm/syscall.h | 22 ++ arch/ia64/include/asm/syscall.h | 2 +- arch/m68k/include/asm/syscall.h | 42 +++ arch/microblaze/include/asm/syscall.h | 2 +- arch/mips/include/asm/syscall.h | 12 +- arch/mips/kernel/ptrace.c | 2 +- arch/nds32/include/asm/elf.h | 3 +- arch/nds32/include/asm/syscall.h | 8 + arch/nios2/include/asm/syscall.h | 6 + arch/openrisc/include/asm/syscall.h | 2 +- arch/parisc/include/asm/syscall.h | 11 +- arch/powerpc/include/asm/syscall.h | 20 +- arch/powerpc/kernel/ptrace.c | 7 +- arch/riscv/include/asm/syscall.h | 10 + arch/s390/include/asm/syscall.h | 4 +- arch/sh/include/asm/syscall_32.h | 2 +- arch/sh/include/asm/syscall_64.h | 2 +- arch/sparc/include/asm/syscall.h | 5 +- arch/unicore32/include/asm/elf.h | 3 +- arch/unicore32/include/asm/syscall.h | 46 +++ arch/x86/include/asm/syscall.h | 8 +- arch/x86/um/asm/syscall.h | 2 +- arch/xtensa/include/asm/elf.h | 2 +- arch/xtensa/include/asm/syscall.h | 65 +++++ include/asm-generic/syscall.h | 85 ++++-- include/linux/tracehook.h | 9 +- include/uapi/linux/audit.h | 16 ++ include/uapi/linux/elf-em.h | 8 + include/uapi/linux/ptrace.h | 35 +++ kernel/auditsc.c | 4 +- kernel/ptrace.c | 101 ++++++- kernel/seccomp.c | 4 +- tools/testing/selftests/ptrace/.gitignore | 1 + tools/testing/selftests/ptrace/Makefile | 2 +- .../selftests/ptrace/get_syscall_info.c | 271 ++++++++++++++++++ 44 files changed, 851 insertions(+), 66 deletions(-) create mode 100644 arch/m68k/include/asm/syscall.h create mode 100644 arch/unicore32/include/asm/syscall.h create mode 100644 tools/testing/selftests/ptrace/get_syscall_info.c
Quoted 2 lines
--
ldv
--
paul moore
www.paul-moore.com