[PATCH v6 01/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. Cc: Arnd Bergmann Cc: Oleg Nesterov Cc: Geert Uytterhoeven Cc: Elvira Khabirova Cc: Eugene Syromyatnikov Cc: linux-a...@vger.kernel.org Signed-off-by: Dmitry V. Levin --- Notes: v6: initial revision include/asm-generic/syscall.h | 39 +-- 1 file changed, 24 insertions(+), 15 deletions(-) diff --git a/include/asm-generic/syscall.h b/include/asm-generic/syscall.h index 0c938a4354f6..9863a5f8fbe8 100644 --- a/include/asm-generic/syscall.h +++ b/include/asm-generic/syscall.h @@ -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 1 struct 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 */ -- ldv
[PATCH v6 07/27] elf-em.h: add EM_CSKY
The 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 Cc: Guo Ren Cc: Oleg Nesterov Cc: Andy Lutomirski Cc: Elvira Khabirova Cc: Eugene Syromyatnikov Signed-off-by: Dmitry V. Levin --- Notes: v6: unchanged include/uapi/linux/elf-em.h | 1 + 1 file changed, 1 insertion(+) diff --git a/include/uapi/linux/elf-em.h b/include/uapi/linux/elf-em.h index 42b7546352a6..ee0b26ab92b0 100644 --- a/include/uapi/linux/elf-em.h +++ b/include/uapi/linux/elf-em.h @@ -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_CSKY252 /* C-SKY processor family */ #define EM_FRV 0x5441 /* Fujitsu FR-V */ /* -- ldv
[PATCH v6 03/27] alpha: define remaining syscall_get_* functions
syscall_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. Cc: Richard Henderson Cc: Ivan Kokshaysky Cc: Matt Turner Cc: Oleg Nesterov Cc: Andy Lutomirski Cc: Elvira Khabirova Cc: Eugene Syromyatnikov Cc: linux-al...@vger.kernel.org Signed-off-by: Dmitry V. Levin --- Notes: v6: use asm-generic/syscall.h arch/alpha/include/asm/syscall.h | 31 ++- 1 file changed, 30 insertions(+), 1 deletion(-) diff --git a/arch/alpha/include/asm/syscall.h b/arch/alpha/include/asm/syscall.h index d73a6fcb519c..c67d6a69d7c8 100644 --- a/arch/alpha/include/asm/syscall.h +++ b/arch/alpha/include/asm/syscall.h @@ -2,9 +2,38 @@ #ifndef _ASM_ALPHA_SYSCALL_H #define _ASM_ALPHA_SYSCALL_H +#include +#include #include -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; } -- ldv
[PATCH v6 05/27] arc: define syscall_get_arch()
syscall_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. Acked-by: Vineet Gupta Cc: Elvira Khabirova Cc: Eugene Syromyatnikov Cc: Oleg Nesterov Cc: Andy Lutomirski Cc: Alexey Brodkin Cc: Paul Moore Cc: Eric Paris Cc: linux-snps-...@lists.infradead.org Cc: linux-au...@redhat.com Signed-off-by: Dmitry V. Levin --- 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(+) diff --git a/arch/arc/include/asm/syscall.h b/arch/arc/include/asm/syscall.h index 29de09804306..c7fc4c0c3bcb 100644 --- a/arch/arc/include/asm/syscall.h +++ b/arch/arc/include/asm/syscall.h @@ -9,6 +9,7 @@ #ifndef _ASM_ARC_SYSCALL_H #define _ASM_ARC_SYSCALL_H 1 +#include #include #include #include @@ -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 diff --git a/include/uapi/linux/audit.h b/include/uapi/linux/audit.h index 818ae690ab79..bedf3bf54c3a 100644 --- a/include/uapi/linux/audit.h +++ b/include/uapi/linux/audit.h @@ -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) -- ldv
[PATCH v6 02/27] asm-generic/syscall.h: turn syscall_[gs]et_arguments into wrappers
Add 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. Cc: Arnd Bergmann Cc: Oleg Nesterov Cc: Geert Uytterhoeven Cc: Elvira Khabirova Cc: Eugene Syromyatnikov Cc: linux-a...@vger.kernel.org Signed-off-by: Dmitry V. Levin --- Notes: v6: initial revision include/asm-generic/syscall.h | 47 +-- 1 file changed, 45 insertions(+), 2 deletions(-) diff --git a/include/asm-generic/syscall.h b/include/asm-generic/syscall.h index 9863a5f8fbe8..fdefe27fa63f 100644 --- a/include/asm-generic/syscall.h +++ b/include/asm-generic/syscall.h @@ -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 -- ldv
[PATCH v6 10/27] Move EM_HEXAGON to uapi/linux/elf-em.h
This 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. Cc: Richard Kuo Cc: Oleg Nesterov Cc: Andy Lutomirski Cc: Elvira Khabirova Cc: Eugene Syromyatnikov Cc: linux-hexa...@vger.kernel.org Signed-off-by: Dmitry V. Levin --- 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(-) diff --git a/arch/hexagon/include/asm/elf.h b/arch/hexagon/include/asm/elf.h index 80311e7b8ca6..d10fbd54ae51 100644 --- a/arch/hexagon/include/asm/elf.h +++ b/arch/hexagon/include/asm/elf.h @@ -23,11 +23,7 @@ #include #include - -/* - * This should really be in linux/elf-em.h. - */ -#define EM_HEXAGON 164 /* QUALCOMM Hexagon */ +#include struct elf32_hdr; diff --git a/include/uapi/linux/elf-em.h b/include/uapi/linux/elf-em.h index ee0b26ab92b0..e0fb2794bbad 100644 --- a/include/uapi/linux/elf-em.h +++ b/include/uapi/linux/elf-em.h @@ -38,6 +38,7 @@ #define EM_BLACKFIN 106 /* ADI Blackfin Processor */ #define EM_ALTERA_NIOS2113 /* Altera Nios II soft-core processor */ #define EM_TI_C6000140 /* 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 */ -- ldv
[PATCH v6 09/27] h8300: define remaining syscall_get_* functions
syscall_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. Cc: Yoshinori Sato Cc: Paul Moore Cc: Eric Paris Cc: Oleg Nesterov Cc: Andy Lutomirski Cc: Elvira Khabirova Cc: Eugene Syromyatnikov Cc: uclinux-h8-de...@lists.sourceforge.jp Cc: linux-au...@redhat.com Signed-off-by: Dmitry V. Levin --- 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(+) diff --git a/arch/h8300/include/asm/syscall.h b/arch/h8300/include/asm/syscall.h index 924990401237..0a6565d12836 100644 --- a/arch/h8300/include/asm/syscall.h +++ b/arch/h8300/include/asm/syscall.h @@ -8,6 +8,8 @@ #include #include #include +#include +#include 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 */ diff --git a/include/uapi/linux/audit.h b/include/uapi/linux/audit.h index 55904a40d768..672c6d9d7577 100644 --- a/include/uapi/linux/audit.h +++ b/include/uapi/linux/audit.h @@ -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) -- ldv
[PATCH v6 11/27] hexagon: define remaining syscall_get_* functions
syscall_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. Cc: Richard Kuo Cc: Paul Moore Cc: Eric Paris Cc: Oleg Nesterov Cc: Andy Lutomirski Cc: Elvira Khabirova Cc: Eugene Syromyatnikov Cc: linux-hexa...@vger.kernel.org Cc: linux-au...@redhat.com Signed-off-by: Dmitry V. Levin --- 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(+) diff --git a/arch/hexagon/include/asm/syscall.h b/arch/hexagon/include/asm/syscall.h index 4af9c7b6f13a..c3290c0bc458 100644 --- a/arch/hexagon/include/asm/syscall.h +++ b/arch/hexagon/include/asm/syscall.h @@ -21,6 +21,10 @@ #ifndef _ASM_HEXAGON_SYSCALL_H #define _ASM_HEXAGON_SYSCALL_H +#include +#include +#include + 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 diff --git a/include/uapi/linux/audit.h b/include/uapi/linux/audit.h index 672c6d9d7577..b8e848736031 100644 --- a/include/uapi/linux/audit.h +++ b/include/uapi/linux/audit.h @@ -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) -- ldv
[PATCH v6 06/27] c6x: define syscall_get_arch()
syscall_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. Acked-by: Mark Salter Cc: Aurelien Jacquiot Cc: Paul Moore Cc: Eric Paris Cc: Oleg Nesterov Cc: Andy Lutomirski Cc: Elvira Khabirova Cc: Eugene Syromyatnikov Cc: linux-c6x-...@linux-c6x.org Cc: linux-au...@redhat.com Signed-off-by: Dmitry V. Levin --- 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(+) diff --git a/arch/c6x/include/asm/syscall.h b/arch/c6x/include/asm/syscall.h index ae2be315ee9c..39dbd1ef994c 100644 --- a/arch/c6x/include/asm/syscall.h +++ b/arch/c6x/include/asm/syscall.h @@ -11,6 +11,7 @@ #ifndef __ASM_C6X_SYSCALL_H #define __ASM_C6X_SYSCALL_H +#include #include #include @@ -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 */ diff --git a/include/uapi/linux/audit.h b/include/uapi/linux/audit.h index bedf3bf54c3a..72aeea0a740d 100644 --- a/include/uapi/linux/audit.h +++ b/include/uapi/linux/audit.h @@ -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) -- ldv
[PATCH v6 04/27] Move EM_ARCOMPACT and EM_ARCV2 to uapi/linux/elf-em.h
These 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. Acked-by: Vineet Gupta Cc: Elvira Khabirova Cc: Eugene Syromyatnikov Cc: Oleg Nesterov Cc: Andy Lutomirski Cc: Alexey Brodkin Cc: linux-snps-...@lists.infradead.org Signed-off-by: Dmitry V. Levin --- 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(-) diff --git a/arch/arc/include/asm/elf.h b/arch/arc/include/asm/elf.h index aa2d6da9d187..2b80c184c9c8 100644 --- a/arch/arc/include/asm/elf.h +++ b/arch/arc/include/asm/elf.h @@ -10,13 +10,9 @@ #define __ASM_ARC_ELF_H #include +#include #include -/* 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) diff --git a/include/uapi/linux/elf-em.h b/include/uapi/linux/elf-em.h index 93722e60204c..42b7546352a6 100644 --- a/include/uapi/linux/elf-em.h +++ b/include/uapi/linux/elf-em.h @@ -34,6 +34,7 @@ #define EM_M32R88 /* 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_NIOS2113 /* Altera Nios II soft-core processor */ #define EM_TI_C6000140 /* 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 */ -- ldv
[PATCH v6 08/27] csky: define syscall_get_arch()
syscall_get_arch() is required to be implemented on all architectures in order to extend the generic ptrace API with PTRACE_GET_SYSCALL_INFO request. Cc: Guo Ren Cc: Paul Moore Cc: Eric Paris Cc: Oleg Nesterov Cc: Andy Lutomirski Cc: Elvira Khabirova Cc: Eugene Syromyatnikov Cc: linux-au...@redhat.com Signed-off-by: Dmitry V. Levin --- Notes: v6: unchanged arch/csky/include/asm/syscall.h | 7 +++ include/uapi/linux/audit.h | 1 + 2 files changed, 8 insertions(+) diff --git a/arch/csky/include/asm/syscall.h b/arch/csky/include/asm/syscall.h index 926a64a8b4ee..d637445737b7 100644 --- a/arch/csky/include/asm/syscall.h +++ b/arch/csky/include/asm/syscall.h @@ -6,6 +6,7 @@ #include #include #include +#include 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 */ diff --git a/include/uapi/linux/audit.h b/include/uapi/linux/audit.h index 72aeea0a740d..55904a40d768 100644 --- a/include/uapi/linux/audit.h +++ b/include/uapi/linux/audit.h @@ -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) -- ldv
[PATCH v6 15/27] m68k: add asm/syscall.h
syscall_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. Cc: Geert Uytterhoeven Cc: Oleg Nesterov Cc: Andy Lutomirski Cc: Elvira Khabirova Cc: Eugene Syromyatnikov Cc: linux-m...@lists.linux-m68k.org Signed-off-by: Dmitry V. Levin --- 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 diff --git a/arch/m68k/include/asm/syscall.h b/arch/m68k/include/asm/syscall.h new file mode 100644 index ..c87b14417753 --- /dev/null +++ b/arch/m68k/include/asm/syscall.h @@ -0,0 +1,42 @@ +/* SPDX-License-Identifier: GPL-2.0 */ +#ifndef _ASM_M68K_SYSCALL_H +#define _ASM_M68K_SYSCALL_H + +#include +#include +#include +#include + +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 */ -- ldv
[PATCH v6 14/27] nios2: define syscall_get_arch()
syscall_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. Cc: Ley Foon Tan Cc: Paul Moore Cc: Eric Paris Cc: Oleg Nesterov Cc: Andy Lutomirski Cc: Elvira Khabirova Cc: Eugene Syromyatnikov Cc: nios2-...@lists.rocketboards.org Cc: linux-au...@redhat.com Signed-off-by: Dmitry V. Levin --- Notes: v6: unchanged v5: added Cc arch/nios2/include/asm/syscall.h | 6 ++ include/uapi/linux/audit.h | 1 + 2 files changed, 7 insertions(+) diff --git a/arch/nios2/include/asm/syscall.h b/arch/nios2/include/asm/syscall.h index 9de220854c4a..cf35e210fc4d 100644 --- a/arch/nios2/include/asm/syscall.h +++ b/arch/nios2/include/asm/syscall.h @@ -17,6 +17,7 @@ #ifndef __ASM_NIOS2_SYSCALL_H__ #define __ASM_NIOS2_SYSCALL_H__ +#include #include #include @@ -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 diff --git a/include/uapi/linux/audit.h b/include/uapi/linux/audit.h index 54551adb3d5d..883c5f56be9c 100644 --- a/include/uapi/linux/audit.h +++ b/include/uapi/linux/audit.h @@ -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) -- ldv
[PATCH v6 12/27] Move EM_NDS32 to uapi/linux/elf-em.h
This 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. Cc: Greentime Hu Cc: Vincent Chen Cc: Oleg Nesterov Cc: Andy Lutomirski Cc: Elvira Khabirova Cc: Eugene Syromyatnikov Signed-off-by: Dmitry V. Levin --- 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(-) diff --git a/arch/nds32/include/asm/elf.h b/arch/nds32/include/asm/elf.h index f5f9cf7e0544..71f9d51481a2 100644 --- a/arch/nds32/include/asm/elf.h +++ b/arch/nds32/include/asm/elf.h @@ -9,14 +9,13 @@ */ #include +#include 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_RELA19 #define R_NDS32_32_RELA20 diff --git a/include/uapi/linux/elf-em.h b/include/uapi/linux/elf-em.h index e0fb2794bbad..d8695ad90f6b 100644 --- a/include/uapi/linux/elf-em.h +++ b/include/uapi/linux/elf-em.h @@ -39,6 +39,8 @@ #define EM_ALTERA_NIOS2113 /* Altera Nios II soft-core processor */ #define EM_TI_C6000140 /* 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 */ -- ldv
[PATCH v6 16/27] mips: define syscall_get_error()
syscall_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. Cc: Paul Burton Cc: Ralf Baechle Cc: James Hogan Cc: Oleg Nesterov Cc: Andy Lutomirski Cc: Elvira Khabirova Cc: Eugene Syromyatnikov Cc: linux-m...@vger.kernel.org Signed-off-by: Dmitry V. Levin --- Notes: v6: unchanged v5: initial revision arch/mips/include/asm/syscall.h | 6 ++ 1 file changed, 6 insertions(+) diff --git a/arch/mips/include/asm/syscall.h b/arch/mips/include/asm/syscall.h index 6cf8ffb5367e..04ab927ff47d 100644 --- a/arch/mips/include/asm/syscall.h +++ b/arch/mips/include/asm/syscall.h @@ -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) { -- ldv
[PATCH v6 13/27] nds32: define syscall_get_arch()
syscall_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. Cc: Greentime Hu Cc: Vincent Chen Cc: Paul Moore Cc: Eric Paris Cc: Oleg Nesterov Cc: Andy Lutomirski Cc: Elvira Khabirova Cc: Eugene Syromyatnikov Cc: linux-au...@redhat.com Signed-off-by: Dmitry V. Levin --- 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(+) diff --git a/arch/nds32/include/asm/syscall.h b/arch/nds32/include/asm/syscall.h index f7e5e86765fe..569149ca25da 100644 --- a/arch/nds32/include/asm/syscall.h +++ b/arch/nds32/include/asm/syscall.h @@ -5,6 +5,7 @@ #ifndef _ASM_NDS32_SYSCALL_H #define _ASM_NDS32_SYSCALL_H 1 +#include #include 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 */ diff --git a/include/uapi/linux/audit.h b/include/uapi/linux/audit.h index b8e848736031..54551adb3d5d 100644 --- a/include/uapi/linux/audit.h +++ b/include/uapi/linux/audit.h @@ -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) -- ldv
[PATCH v6 17/27] parisc: define syscall_get_error()
syscall_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. Cc: James E.J. Bottomley Cc: Helge Deller Cc: Oleg Nesterov Cc: Andy Lutomirski Cc: Elvira Khabirova Cc: Eugene Syromyatnikov Cc: linux-par...@vger.kernel.org Signed-off-by: Dmitry V. Levin --- Notes: v6: unchanged v5: initial revision arch/parisc/include/asm/syscall.h | 7 +++ 1 file changed, 7 insertions(+) diff --git a/arch/parisc/include/asm/syscall.h b/arch/parisc/include/asm/syscall.h index 8bff1a58c97f..477511ff7546 100644 --- a/arch/parisc/include/asm/syscall.h +++ b/arch/parisc/include/asm/syscall.h @@ -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) { -- ldv
[PATCH v6 19/27] riscv: define syscall_get_arch()
syscall_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. Based-on-patch-by: David Abdurachmanov Reviewed-by: Palmer Dabbelt Cc: Elvira Khabirova Cc: Eugene Syromyatnikov Cc: Oleg Nesterov Cc: Andy Lutomirski Cc: Albert Ou Cc: Paul Moore Cc: Eric Paris Cc: linux-ri...@lists.infradead.org Cc: linux-au...@redhat.com Signed-off-by: Dmitry V. Levin --- 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(+) diff --git a/arch/riscv/include/asm/syscall.h b/arch/riscv/include/asm/syscall.h index 8d25f8904c00..bba3da6ef157 100644 --- a/arch/riscv/include/asm/syscall.h +++ b/arch/riscv/include/asm/syscall.h @@ -18,6 +18,7 @@ #ifndef _ASM_RISCV_SYSCALL_H #define _ASM_RISCV_SYSCALL_H +#include #include #include @@ -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 */ diff --git a/include/uapi/linux/audit.h b/include/uapi/linux/audit.h index 883c5f56be9c..1e9808f3a240 100644 --- a/include/uapi/linux/audit.h +++ b/include/uapi/linux/audit.h @@ -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) -- ldv
[PATCH v6 18/27] powerpc: define syscall_get_error()
syscall_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. Cc: Michael Ellerman Cc: Benjamin Herrenschmidt Cc: Paul Mackerras Cc: Oleg Nesterov Cc: Andy Lutomirski Cc: Elvira Khabirova Cc: Eugene Syromyatnikov Cc: linuxppc-...@lists.ozlabs.org Signed-off-by: Dmitry V. Levin --- 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(+) diff --git a/arch/powerpc/include/asm/syscall.h b/arch/powerpc/include/asm/syscall.h index ab9f3f0a8637..1d03e753391d 100644 --- a/arch/powerpc/include/asm/syscall.h +++ b/arch/powerpc/include/asm/syscall.h @@ -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 & 0x1000UL) ? -regs->gpr[3] : 0; +} + static inline long syscall_get_return_value(struct task_struct *task, struct pt_regs *regs) { -- ldv
[PATCH v6 22/27] Move EM_UNICORE to uapi/linux/elf-em.h
This 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. Cc: Guan Xuetao Cc: Oleg Nesterov Cc: Andy Lutomirski Cc: Elvira Khabirova Cc: Eugene Syromyatnikov Signed-off-by: Dmitry V. Levin --- 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(-) diff --git a/arch/unicore32/include/asm/elf.h b/arch/unicore32/include/asm/elf.h index 829042d07722..ae66dc1be49e 100644 --- a/arch/unicore32/include/asm/elf.h +++ b/arch/unicore32/include/asm/elf.h @@ -19,6 +19,7 @@ * ELF register definitions.. */ #include +#include 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_ABS322 diff --git a/include/uapi/linux/elf-em.h b/include/uapi/linux/elf-em.h index f392dd9d07f7..2533bb1db3ef 100644 --- a/include/uapi/linux/elf-em.h +++ b/include/uapi/linux/elf-em.h @@ -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_NIOS2113 /* Altera Nios II soft-core processor */ #define EM_TI_C6000140 /* TI C6X DSPs */ #define EM_HEXAGON 164 /* QUALCOMM Hexagon */ -- ldv
[PATCH v6 23/27] unicore32: add asm/syscall.h
syscall_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. Cc: Guan Xuetao Cc: Paul Moore Cc: Eric Paris Cc: Oleg Nesterov Cc: Andy Lutomirski Cc: Elvira Khabirova Cc: Eugene Syromyatnikov Cc: linux-au...@redhat.com Signed-off-by: Dmitry V. Levin --- 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 diff --git a/arch/unicore32/include/asm/syscall.h b/arch/unicore32/include/asm/syscall.h new file mode 100644 index ..267e97e256bd --- /dev/null +++ b/arch/unicore32/include/asm/syscall.h @@ -0,0 +1,47 @@ +/* SPDX-License-Identifier: GPL-2.0 */ +#ifndef _ASM_UNICORE_SYSCALL_H +#define _ASM_UNICORE_SYSCALL_H + +#include +#include +#include +#include + +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 */ diff --git a/include/uapi/linux/audit.h b/include/uapi/linux/audit.h index bcc0619b046f..3901c51c0b93 100644 --- a/include/uapi/linux/audit.h +++ b/include/uapi/linux/audit.h @@ -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) -- ldv
[PATCH v6 20/27] Move EM_XTENSA to uapi/linux/elf-em.h
This 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. Cc: Max Filippov Cc: Oleg Nesterov Cc: Andy Lutomirski Cc: Elvira Khabirova Cc: Eugene Syromyatnikov Cc: Chris Zankel Cc: linux-xte...@linux-xtensa.org Signed-off-by: Dmitry V. Levin --- 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(-) diff --git a/arch/xtensa/include/asm/elf.h b/arch/xtensa/include/asm/elf.h index eacb25a41718..344f1c6a546e 100644 --- a/arch/xtensa/include/asm/elf.h +++ b/arch/xtensa/include/asm/elf.h @@ -15,10 +15,10 @@ #include #include +#include /* Xtensa processor ELF architecture-magic number */ -#define EM_XTENSA 94 #define EM_XTENSA_OLD 0xABC7 /* Xtensa relocations defined by the ABIs */ diff --git a/include/uapi/linux/elf-em.h b/include/uapi/linux/elf-em.h index d8695ad90f6b..f392dd9d07f7 100644 --- a/include/uapi/linux/elf-em.h +++ b/include/uapi/linux/elf-em.h @@ -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_NIOS2113 /* Altera Nios II soft-core processor */ #define EM_TI_C6000140 /* TI C6X DSPs */ -- ldv
[PATCH v6 21/27] xtensa: define syscall_get_* functions
syscall_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. Cc: Max Filippov Cc: Oleg Nesterov Cc: Andy Lutomirski Cc: Elvira Khabirova Cc: Eugene Syromyatnikov Cc: Chris Zankel Cc: Paul Moore Cc: Eric Paris Cc: linux-xte...@linux-xtensa.org Cc: linux-au...@redhat.com Signed-off-by: Dmitry V. Levin --- 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(+) diff --git a/arch/xtensa/include/asm/syscall.h b/arch/xtensa/include/asm/syscall.h index 3673ff1f1bc5..40c6de062ac8 100644 --- a/arch/xtensa/include/asm/syscall.h +++ b/arch/xtensa/include/asm/syscall.h @@ -8,6 +8,71 @@ * Copyright (C) 2001 - 2007 Tensilica Inc. */ +#include +#include +#include +#include + +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*); diff --git a/include/uapi/linux/audit.h b/include/uapi/linux/audit.h index 1e9808f3a240..bcc0619b046f 100644 --- a/include/uapi/linux/audit.h +++ b/include/uapi/linux/audit.h @@ -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_EXEC1 #define AUDIT_PERM_WRITE 2 -- ldv
[PATCH v6 27/27] selftests/ptrace: add a test case for PTRACE_GET_SYSCALL_INFO
Check whether PTRACE_GET_SYSCALL_INFO semantics implemented in the kernel matches userspace expectations. Cc: Oleg Nesterov Cc: Andy Lutomirski Cc: Shuah Khan Cc: Elvira Khabirova Cc: Eugene Syromyatnikov Cc: linux-kselft...@vger.kernel.org Signed-off-by: Dmitry V. Levin --- 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 diff --git a/tools/testing/selftests/ptrace/.gitignore b/tools/testing/selftests/ptrace/.gitignore index b3e59d41fd82..cfcc49a7def7 100644 --- a/tools/testing/selftests/ptrace/.gitignore +++ b/tools/testing/selftests/ptrace/.gitignore @@ -1 +1,2 @@ +get_syscall_info peeksiginfo diff --git a/tools/testing/selftests/ptrace/Makefile b/tools/testing/selftests/ptrace/Makefile index 8a2bc5562179..4bc550b6b845 100644 --- a/tools/testing/selftests/ptrace/Makefile +++ b/tools/testing/selftests/ptrace/Makefile @@ -1,5 +1,5 @@ CFLAGS += -iquote../../../../include/uapi -Wall -TEST_GEN_PROGS := peeksiginfo +TEST_GEN_PROGS := get_syscall_info peeksiginfo include ../lib.mk diff --git a/tools/testing/selftests/ptrace/get_syscall_info.c b/tools/testing/selftests/ptrace/get_syscall_info.c new file mode 100644 index ..28e972825b74 --- /dev/null +++ b/tools/testing/selftests/ptrace/get_syscall_info.c @@ -0,0 +1,271 @@ +/* SPDX-License-Identifier: GPL-2.0-or-later + * + * Copyright (c) 2018 Dmitry V. Levin + * All rights reserved. + * + * Check whether PTRACE_GET_SYSCALL_INFO semantics implemented in the kernel + * matches userspace expectations. + */ + +#include "../kselftest_harness.h" +#include +#include +#include +#include "linux/ptrace.h" + +static int +kill_tracee(pid_t pid) +{ + if (!pid) + return 0; + + int saved_errno = errno; + + int rc = kill(pid, SIGKILL); + + errno = saved_errno; + return rc; +} + +static long +sys_ptrace(int request, pid_t pid, unsigned long addr, unsigned long data) +{ + return syscall(__NR_ptrace, request, pid, addr, data); +} + +#define LOG_KILL_TRACEE(fmt, ...) \ + do {\ + kill_tracee(pid); \ + TH_LOG("wait #%d: " fmt,\ + ptrace_stop, ##__VA_ARGS__); \ + } while (0) + +TEST(get_syscall_info) +{ + static const unsigned long args[][7] = { + /* a sequence of architecture-agnostic syscalls */ + { + __NR_chdir, + (unsigned long) "", + 0xbad1fed1, + 0xbad2fed2, + 0xbad3fed3, + 0xbad4fed4, + 0xbad5fed5 + }, + { + __NR_gettid, + 0xcaf0bea0, + 0xcaf1bea1, + 0xcaf2bea2, + 0xcaf3bea3, + 0xcaf4bea4, + 0xcaf5bea5 + }, + { + __NR_exit_group, + 0, + 0xfac1c0d1, + 0xfac2c0d2, + 0xfac3c0d3, + 0xfac4c0d4, + 0xfac5c0d5 + } + }; + const unsigned long *exp_args; + + pid_t pid = fork(); + + ASSERT_LE(0, pid) { + TH_LOG("fork: %m"); + } + + if (pid == 0) { + /* get the pid before PTRACE_TRACEME */ + pid = getpid(); + ASSERT_EQ(0, sys_ptrace(PTRACE_TRACEME, 0, 0, 0)) { + TH_LOG("PTRACE_TRACEME: %m"); + } + ASSERT_EQ(0, kill(pid, SIGSTOP)) { + /* cannot happen */ + TH_LOG("kill SIGSTOP: %m"); + } + for (unsigned int i = 0; i < ARRAY_SIZE(args); ++i) { + syscall(args[i][0], + args[i][1], args[i][2], args[i][3], + args[i][4], args[i][5], args[i][6]); + } + /* unreachable */ + _exit(1); + } + + const struct { + unsigned int is_error; + int rval; + } *exp_param, exit_param[] = { + { 1, -ENOENT }, /* chdir */ + { 0, pid } /* gettid */ + }; + + unsigned int ptrace_stop; + + for (ptrace_stop = 0; ; ++ptrace_stop) { +
[PATCH v6 25/27] powerpc/ptrace: replace ptrace_report_syscall() with a tracehook call
From: Elvira Khabirova 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. Co-authored-by: Dmitry V. Levin Fixes: 5521eb4bca2d ("powerpc/ptrace: Add support for PTRACE_SYSEMU") Signed-off-by: Elvira Khabirova Signed-off-by: Dmitry V. Levin [mpe: Take this as a minimal fix for 4.20, we'll rework it later] Signed-off-by: Michael Ellerman --- 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(-) diff --git a/arch/powerpc/kernel/ptrace.c b/arch/powerpc/kernel/ptrace.c index afb819f4ca68..714c3480c52d 100644 --- a/arch/powerpc/kernel/ptrace.c +++ b/arch/powerpc/kernel/ptrace.c @@ -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; } -- ldv
[PATCH v6 26/27] ptrace: add PTRACE_GET_SYSCALL_INFO request
From: Elvira Khabirova 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. Co-authored-by: Dmitry V. Levin Reviewed-by: Oleg Nesterov Reviewed-by: Kees Cook Cc: Andy Lutomirski Cc: Eugene Syromyatnikov Cc: Jann Horn Cc: linux-...@vger.kernel.org Cc: strace-de...@lists.strace.io Signed-off-by: Elvira Khabirova Signed-off-by: Dmitry V. Levin --- 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 ++
[PATCH v6 24/27] syscall_get_arch: add "struct task_struct *" argument
This 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()") Reviewed-by: Andy Lutomirski # for x86 Reviewed-by: Palmer Dabbelt Acked-by: Paul Burton # MIPS parts Acked-by: Michael Ellerman (powerpc) Acked-by: Kees Cook # seccomp parts Acked-by: Mark Salter # for the c6x bit Cc: Eric Paris Cc: Paul Moore Cc: Richard Henderson Cc: Ivan Kokshaysky Cc: Matt Turner Cc: Vineet Gupta Cc: Russell King Cc: Catalin Marinas Cc: Will Deacon Cc: Aurelien Jacquiot Cc: Yoshinori Sato Cc: Richard Kuo Cc: Tony Luck Cc: Fenghua Yu Cc: Geert Uytterhoeven Cc: Michal Simek Cc: Greentime Hu Cc: Vincent Chen Cc: Ley Foon Tan Cc: Jonas Bonn Cc: Stefan Kristiansson Cc: Stafford Horne Cc: James E.J. Bottomley Cc: Helge Deller Cc: Albert Ou Cc: Martin Schwidefsky Cc: Heiko Carstens Cc: Rich Felker Cc: David S. Miller Cc: Guan Xuetao Cc: Jeff Dike Cc: Richard Weinberger Cc: Chris Zankel Cc: Max Filippov Cc: Arnd Bergmann Cc: Will Drewry Cc: Oleg Nesterov Cc: Elvira Khabirova Cc: Eugene Syromyatnikov Cc: Ralf Baechle Cc: James Hogan Cc: Benjamin Herrenschmidt Cc: Paul Mackerras Cc: Thomas Gleixner Cc: Ingo Molnar Cc: Borislav Petkov Cc: H. Peter Anvin Cc: x...@kernel.org Cc: linux-al...@vger.kernel.org Cc: linux-snps-...@lists.infradead.org Cc: linux-arm-ker...@lists.infradead.org Cc: linux-c6x-...@linux-c6x.org Cc: uclinux-h8-de...@lists.sourceforge.jp Cc: linux-hexa...@vger.kernel.org Cc: linux-i...@vger.kernel.org Cc: linux-m...@lists.linux-m68k.org Cc: linux-m...@vger.kernel.org Cc: nios2-...@lists.rocketboards.org Cc: openr...@lists.librecores.org Cc: linux-par...@vger.kernel.org Cc: linuxppc-...@lists.ozlabs.org Cc: linux-ri...@lists.infradead.org Cc: linux-s...@vger.kernel.org Cc: linux...@vger.kernel.org Cc: sparcli...@vger.kernel.org Cc: linux...@lists.infradead.org Cc: linux-xte...@linux-xtensa.org Cc: linux-a...@vger.kernel.org Cc: linux-au...@redhat.com Signed-off-by: Dmitry V. Levin --- 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(-) diff --git a/arch/alpha/include/asm/syscall.h b/arch/alpha/include/asm/syscall.h index c67d6a69d7c8..20078aef0922 100644 --- a/arch/alpha/include/asm/syscall.h +++ b/arch/alpha/include/asm/syscall.h @@ -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; } diff --git a/arch/arc/include/asm/syscall.h b/arch/arc/include/asm/syscall.h index c7fc4c0c3bcb..caf2697ef5b7 100644 --- a/arch/arc/include/asm/syscall.h +++ b/arch/arc/include/asm/syscall.h @@ -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) diff --git a/arch/arm/include/asm/syscall.h b/arch/arm/include/asm/syscall.h index 06dea6bce293..3940ceac0bdc 100644 --
[PATCH] uapi: linux/blkzoned.h: fix BLKGETZONESZ and BLKGETNRZONES definitions
According to the documentation in include/uapi/asm-generic/ioctl.h, _IOW means userspace is writing and kernel is reading, and _IOR means userspace is reading and kernel is writing. In case of these two ioctls, kernel is writing and userspace is reading, so they have to be _IOR instead of _IOW. Fixes: 72cd87576d1d8 ("block: Introduce BLKGETZONESZ ioctl") Fixes: 65e4e3eee83d7 ("block: Introduce BLKGETNRZONES ioctl") Signed-off-by: Dmitry V. Levin --- Since both ioctls were introduced after 4.19, please make sure they are fixed in 4.20. Thanks. include/uapi/linux/blkzoned.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/include/uapi/linux/blkzoned.h b/include/uapi/linux/blkzoned.h index 8f08ff9bdea0..6fa38d001d84 100644 --- a/include/uapi/linux/blkzoned.h +++ b/include/uapi/linux/blkzoned.h @@ -141,7 +141,7 @@ struct blk_zone_range { */ #define BLKREPORTZONE _IOWR(0x12, 130, struct blk_zone_report) #define BLKRESETZONE _IOW(0x12, 131, struct blk_zone_range) -#define BLKGETZONESZ _IOW(0x12, 132, __u32) -#define BLKGETNRZONES _IOW(0x12, 133, __u32) +#define BLKGETZONESZ _IOR(0x12, 132, __u32) +#define BLKGETNRZONES _IOR(0x12, 133, __u32) #endif /* _UAPI_BLKZONED_H */ -- ldv
[PATCH] uapi: linux/fs.h: update comment about reserved ioctl numbers
As commit 72cd87576d1d8 ("block: Introduce BLKGETZONESZ ioctl") and commit 65e4e3eee83d7 ("block: Introduce BLKGETNRZONES ioctl") added two more ioctls of type 0x12, update the comment about ioctl numbers reserved for zoned block devices. Signed-off-by: Dmitry V. Levin --- include/uapi/linux/fs.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/include/uapi/linux/fs.h b/include/uapi/linux/fs.h index a441ea1bfe6d..2af9da218c33 100644 --- a/include/uapi/linux/fs.h +++ b/include/uapi/linux/fs.h @@ -228,7 +228,7 @@ struct fsxattr { #define BLKROTATIONAL _IO(0x12,126) #define BLKZEROOUT _IO(0x12,127) /* - * A jump here: 130-131 are reserved for zoned block devices + * A jump here: 130-133 are reserved for zoned block devices * (see uapi/linux/blkzoned.h) */ -- ldv
[PATCH] powerpc/ptrace: cleanup do_syscall_trace_enter
Invoke tracehook_report_syscall_entry once. Signed-off-by: Dmitry V. Levin --- arch/powerpc/kernel/ptrace.c | 54 +--- 1 file changed, 31 insertions(+), 23 deletions(-) diff --git a/arch/powerpc/kernel/ptrace.c b/arch/powerpc/kernel/ptrace.c index 714c3480c52d..8794d32c2d9e 100644 --- a/arch/powerpc/kernel/ptrace.c +++ b/arch/powerpc/kernel/ptrace.c @@ -3263,32 +3263,40 @@ static inline int do_seccomp(struct pt_regs *regs) { return 0; } */ long do_syscall_trace_enter(struct pt_regs *regs) { + u32 cached_flags; + user_exit(); - if (test_thread_flag(TIF_SYSCALL_EMU)) { - /* -* 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; - } + cached_flags = READ_ONCE(current_thread_info()->flags) & + (_TIF_SYSCALL_EMU | _TIF_SYSCALL_TRACE); - /* -* The tracer may decide to abort the syscall, if so tracehook -* will return !0. Note that the tracer may also just change -* regs->gpr[0] to an invalid syscall number, that is handled -* below on the exit path. -*/ - if (test_thread_flag(TIF_SYSCALL_TRACE) && - tracehook_report_syscall_entry(regs)) - goto skip; + if (cached_flags) { + int rc = tracehook_report_syscall_entry(regs); + + if (unlikely(cached_flags & _TIF_SYSCALL_EMU)) { + /* +* 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. +*/ + return -1; + } + + if (rc) { + /* +* The tracer decided to abort the syscall. +* Note that the tracer may also just change +* regs->gpr[0] to an invalid syscall number, +* that is handled below on the exit path. +*/ + goto skip; + } + } /* Run seccomp after ptrace; allow it to set gpr[3]. */ if (do_seccomp(regs)) -- ldv
Re: [PATCH] powerpc/ptrace: cleanup do_syscall_trace_enter
Hi, On Mon, Dec 17, 2018 at 10:20:26PM +1100, Michael Ellerman wrote: > "Dmitry V. Levin" writes: > > Invoke tracehook_report_syscall_entry once. > > Thanks. > > > Signed-off-by: Dmitry V. Levin > > --- > > arch/powerpc/kernel/ptrace.c | 54 +--- > > 1 file changed, 31 insertions(+), 23 deletions(-) > > > > diff --git a/arch/powerpc/kernel/ptrace.c b/arch/powerpc/kernel/ptrace.c > > index 714c3480c52d..8794d32c2d9e 100644 > > --- a/arch/powerpc/kernel/ptrace.c > > +++ b/arch/powerpc/kernel/ptrace.c > > @@ -3263,32 +3263,40 @@ static inline int do_seccomp(struct pt_regs *regs) > > { return 0; } > > */ > > long do_syscall_trace_enter(struct pt_regs *regs) > > { > > + u32 cached_flags; > > + > > Do you mind if I just call it "flags", I find "cached_flags" a bit > unwieldy for some reason. > > I'm happy to fix it up when applying. No problem, feel free to call it whatever you like. Thanks, -- ldv signature.asc Description: PGP signature
Re: [PATCH v5 13/25] m68k: add asm/syscall.h
Hi Geert, On Mon, Dec 10, 2018 at 09:45:42AM +0100, Geert Uytterhoeven wrote: > Hi Dmitry, > > On Mon, Dec 10, 2018 at 5:30 AM Dmitry V. Levin wrote: > > syscall_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. > > > > Cc: Geert Uytterhoeven > > Cc: Oleg Nesterov > > Cc: Andy Lutomirski > > Cc: Elvira Khabirova > > Cc: Eugene Syromyatnikov > > Cc: linux-m...@lists.linux-m68k.org > > Signed-off-by: Dmitry V. Levin > > --- > > > > Notes: > > v5: added syscall_get_nr, syscall_get_arguments, syscall_get_error, > > and syscall_get_return_value > > v1: added syscall_get_arch > > > --- /dev/null > > +++ b/arch/m68k/include/asm/syscall.h > > @@ -0,0 +1,39 @@ > > > +static inline void > > +syscall_get_arguments(struct task_struct *task, struct pt_regs *regs, > > + unsigned int i, unsigned int n, unsigned long *args) > > +{ > > + BUG_ON(i + n > 6); > > Does this have to crash the kernel? This is what most of other architectures do, but we could choose a softer approach, e.g. use WARN_ON_ONCE instead. > Perhaps you can return an error code instead? That would be problematic given the signature of this function and the nature of the potential bug which would most likely be a usage error. -- ldv signature.asc Description: PGP signature
Re: [PATCH v5 19/25] xtensa: define syscall_get_* functions
Hi, On Sun, Dec 09, 2018 at 09:02:50PM -0800, Max Filippov wrote: > Hello, > > On Sun, Dec 9, 2018 at 8:30 PM Dmitry V. Levin wrote: > > syscall_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. > > I have this set of functions plus syscall_set_arguments implemented > for syscall tracing here: > > https://github.com/jcmvbkbc/linux-xtensa/commit/0023f56298cc92ce47e61b1b5dd1038f7be4f826 Good, but we also need syscall_get_arch for PTRACE_GET_SYSCALL_INFO. > How should we synchronize our changes? No problem, I can revert to the previous edition of this patch that just adds syscall_get_arch. Alternatively, you can just take that couple of patches (v5 18/25 and v2 15/15) into your tree. > > diff --git a/arch/xtensa/include/asm/syscall.h > > b/arch/xtensa/include/asm/syscall.h > > index 3673ff1f1bc5..d529c855a144 100644 > > --- a/arch/xtensa/include/asm/syscall.h > > +++ b/arch/xtensa/include/asm/syscall.h > > [...] > > > +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]; > > + /* fall through */ > > + case 6: > > + if (!n--) > > + break; > > + /* fall through */ > > + default: > > + BUG(); > > A WARN should be enough. This is what most of other architectures do in syscall_get_arguments, but I agree that a WARN_ON_ONCE should be enough. -- ldv signature.asc Description: PGP signature
Re: [PATCH v5 13/25] m68k: add asm/syscall.h
Hi Geert, On Mon, Dec 10, 2018 at 02:06:28PM +0100, Geert Uytterhoeven wrote: > On Mon, Dec 10, 2018 at 1:41 PM Dmitry V. Levin wrote: > > On Mon, Dec 10, 2018 at 09:45:42AM +0100, Geert Uytterhoeven wrote: > > > On Mon, Dec 10, 2018 at 5:30 AM Dmitry V. Levin wrote: > > > > syscall_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. > > > > > > > > Cc: Geert Uytterhoeven > > > > Cc: Oleg Nesterov > > > > Cc: Andy Lutomirski > > > > Cc: Elvira Khabirova > > > > Cc: Eugene Syromyatnikov > > > > Cc: linux-m...@lists.linux-m68k.org > > > > Signed-off-by: Dmitry V. Levin > > > > --- > > > > > > > > Notes: > > > > v5: added syscall_get_nr, syscall_get_arguments, syscall_get_error, > > > > and syscall_get_return_value > > > > v1: added syscall_get_arch > > > > > > > --- /dev/null > > > > +++ b/arch/m68k/include/asm/syscall.h > > > > @@ -0,0 +1,39 @@ > > > > > > > +static inline void > > > > +syscall_get_arguments(struct task_struct *task, struct pt_regs *regs, > > > > + unsigned int i, unsigned int n, unsigned long > > > > *args) > > > > +{ > > > > + BUG_ON(i + n > 6); > > > > > > Does this have to crash the kernel? > > > > This is what most of other architectures do, but we could choose > > a softer approach, e.g. use WARN_ON_ONCE instead. > > > > > Perhaps you can return an error code instead? > > > > That would be problematic given the signature of this function > > and the nature of the potential bug which would most likely be a usage > > error. > > Of course to handle that, the function's signature need to be changed. > Changing it has the advantage that the error handling can be done at the > caller, in common code, instead of duplicating it for all > architectures, possibly > leading to different semantics. Given that *all* current users of syscall_get_arguments specify i == 0 (and there is an architecture that has BUG_ON(i)), it should be really a usage error to get into situation where i + n > 6, I wish a BUILD_BUG_ON could be used here instead. I don't think it worths pushing the change of API just to convert a "cannot happen" assertion into an error that would have to be dealt with on the caller side. -- ldv signature.asc Description: PGP signature
Re: [PATCH v6] powerpc/ptrace: replace ptrace_report_syscall() with a tracehook call
On Mon, Dec 10, 2018 at 02:28:07PM +0100, Oleg Nesterov wrote: > On 12/07, Dmitry V. Levin wrote: > > > > Please make either v5 or v6 edition of this fix, or any similar fix, > > into v4.20. > > IIUC, v5 above means > > [PATCH v5 23/25] powerpc/ptrace: replace ptrace_report_syscall() with a > tracehook call > > you sent in another series... They just happen to have the same v5 here and there. In that series I included the most trivial variant of the change. > > long do_syscall_trace_enter(struct pt_regs *regs) > > { > > + struct thread_info *ti; > > + u32 cached_flags; > > + > > user_exit(); > > > > - if (test_thread_flag(TIF_SYSCALL_EMU)) { > > - ptrace_report_syscall(regs); > > - /* > > -* Returning -1 will skip the syscall execution. We want to > > -* avoid clobbering any register also, thus, not 'gotoing' > > -* skip label. > > -*/ > > - return -1; > > - } > > + ti = current_thread_info(); > > + cached_flags = READ_ONCE(ti->flags) & > > + (_TIF_SYSCALL_EMU | _TIF_SYSCALL_TRACE | > > + _TIF_SYSCALL_TRACEPOINT); > > > > - /* > > -* The tracer may decide to abort the syscall, if so tracehook > > -* will return !0. Note that the tracer may also just change > > -* regs->gpr[0] to an invalid syscall number, that is handled > > -* below on the exit path. > > -*/ > > - if (test_thread_flag(TIF_SYSCALL_TRACE) && > > - tracehook_report_syscall_entry(regs)) > > - goto skip; > > + if (cached_flags & (_TIF_SYSCALL_EMU | _TIF_SYSCALL_TRACE)) { > > + int rc = tracehook_report_syscall_entry(regs); > > + > > + if (unlikely(cached_flags & _TIF_SYSCALL_EMU)) { > > + /* > > +* 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. > > +*/ > > + return -1; > > + } > > + > > + if (rc) { > > + /* > > +* The tracer decided to abort the syscall. > > +* Note that the tracer may also just change > > +* regs->gpr[0] to an invalid syscall number, > > +* that is handled below on the exit path. > > +*/ > > + goto skip; > > + } > > + } > > > > /* Run seccomp after ptrace; allow it to set gpr[3]. */ > > if (do_seccomp(regs)) > > @@ -3293,7 +3309,7 @@ long do_syscall_trace_enter(struct pt_regs *regs) > > if (regs->gpr[0] >= NR_syscalls) > > goto skip; > > > > - if (unlikely(test_thread_flag(TIF_SYSCALL_TRACEPOINT))) > > + if (unlikely(cached_flags & _TIF_SYSCALL_TRACEPOINT)) > > I will leave this to maintainers, but to me this change looks good and imo it > also cleanups the code. > > However I am not sure cached_flags should include _TIF_SYSCALL_TRACEPOINT. If > nothing else, the caller can sleep in ptrace_stop() unpredictably long and > TIF_SYSCALL_TRACEPOINT can be set/cleared meanwhile. I agree, we shouldn't cache _TIF_SYSCALL_TRACEPOINT. -- ldv signature.asc Description: PGP signature
Re: [PATCH v5 24/25] ptrace: add PTRACE_GET_SYSCALL_INFO request
Hi, things are getting too complicated and we need some advice how to deal with this frame_pointer issue. On Mon, Dec 10, 2018 at 10:26:50PM +0800, kbuild test robot wrote: > Hi Elvira, > > Thank you for the patch! Yet something to improve: > > [auto build test ERROR on linus/master] > [also build test ERROR on v4.20-rc6] > [cannot apply to next-20181207] > [if your patch is applied to the wrong git tree, please drop us a note to > help improve the system] > > url: > https://github.com/0day-ci/linux/commits/Dmitry-V-Levin/ptrace-add-PTRACE_GET_SYSCALL_INFO-request/20181210-174745 > config: mips-malta_kvm_defconfig (attached as .config) > compiler: mipsel-linux-gnu-gcc (Debian 7.2.0-11) 7.2.0 > reproduce: > wget > https://raw.githubusercontent.com/intel/lkp-tests/master/sbin/make.cross -O > ~/bin/make.cross > chmod +x ~/bin/make.cross > # save the attached .config to linux build tree > GCC_VERSION=7.2.0 make.cross ARCH=mips > > All errors (new ones prefixed by >>): > >kernel/ptrace.c: In function 'ptrace_get_syscall_info': > >> kernel/ptrace.c:942:20: error: implicit declaration of function > >> 'frame_pointer'; did you mean 'trace_printk'? > >> [-Werror=implicit-function-declaration] > .frame_pointer = frame_pointer(regs) >^ >trace_printk >cc1: some warnings being treated as errors > > vim +942 kernel/ptrace.c > >931 >932static int >933ptrace_get_syscall_info(struct task_struct *child, unsigned > long user_size, >934void __user *datavp) >935{ >936struct pt_regs *regs = task_pt_regs(child); >937struct ptrace_syscall_info info = { >938.op = PTRACE_SYSCALL_INFO_NONE, >939.arch = syscall_get_arch(child), >940.instruction_pointer = > instruction_pointer(regs), >941.stack_pointer = user_stack_pointer(regs), > > 942.frame_pointer = frame_pointer(regs) >943}; >944unsigned long actual_size = offsetof(struct > ptrace_syscall_info, entry); >945unsigned long write_size; >946 >947/* >948 * This does not need lock_task_sighand() to access >949 * child->last_siginfo because ptrace_freeze_traced() >950 * called earlier by ptrace_check_attach() ensures that >951 * the tracee cannot go away and clear its last_siginfo. >952 */ >953switch (child->last_siginfo ? > child->last_siginfo->si_code : 0) { >954case SIGTRAP | 0x80: >955switch (child->ptrace_message) { >956case PTRACE_EVENTMSG_SYSCALL_ENTRY: >957actual_size = > ptrace_get_syscall_info_entry(child, regs, >958 > &info); >959break; >960case PTRACE_EVENTMSG_SYSCALL_EXIT: >961actual_size = > ptrace_get_syscall_info_exit(child, regs, >962 >&info); >963break; >964} >965break; >966case SIGTRAP | (PTRACE_EVENT_SECCOMP << 8): >967actual_size = > ptrace_get_syscall_info_seccomp(child, regs, >968 > &info); >969break; >970} >971 >972write_size = min(actual_size, user_size); >973return copy_to_user(datavp, &info, write_size) ? > -EFAULT : actual_size; >974} >975 We decided to add .frame_pointer to struct ptrace_syscall_info just for consistency with .instruction_pointer and .stack_pointer; I must have been misled by comments in asm-generic/ptrace.h into thinking that frame_pointer() is universally available across architectures. Unlike .instruction_pointer and .stack_pointer that are actually needed in strace, .frame_pointer is not used, so from strace PoV we don't really need it. So the question is, does anybody need a struct ptrace_syscall_info.frame_pointer? If yes, how can frame_pointer() be defined on MIPS? Or should we just forget about making sense of frame_pointer() and remove struct ptrace_syscall_info.frame_pointer from the proposed API? -- ldv signature.asc Description: PGP signature
Re: [PATCH v5 24/25] ptrace: add PTRACE_GET_SYSCALL_INFO request
On Mon, Dec 10, 2018 at 03:11:07PM +0100, Oleg Nesterov wrote: > On 12/10, Dmitry V. Levin wrote: > > > > +struct ptrace_syscall_info { > > + __u8 op;/* PTRACE_SYSCALL_INFO_* */ > > + __u8 __pad0[3]; > > + __u32 arch; > > + __u64 instruction_pointer; > > + __u64 stack_pointer; > > + __u64 frame_pointer; > > + union { > > + struct { > > + __u64 nr; > > + __u64 args[6]; > > + } entry; > > + struct { > > + __s64 rval; > > + __u8 is_error; > > + __u8 __pad1[7]; > > + } exit; > > + struct { > > + __u64 nr; > > + __u64 args[6]; > > + __u32 ret_data; > > + __u8 __pad2[4]; > > + } seccomp; > > + }; > > +}; > > Could you explain why ptrace_syscall_info needs __pad{0,1,2} ? I simply can't > understand why... I suppose the idea behind the use of these pads was to make the structure arch-independent. I don't think we really need to keep it exactly the same on all architectures - the only practical requirement is to avoid any compat issues, but I don't mind keeping the structure arch-independent. -- ldv signature.asc Description: PGP signature
Re: [PATCH v5 19/25] xtensa: define syscall_get_* functions
On Mon, Dec 10, 2018 at 12:14:37PM -0800, Max Filippov wrote: > On Mon, Dec 10, 2018 at 4:53 AM Dmitry V. Levin wrote: > > On Sun, Dec 09, 2018 at 09:02:50PM -0800, Max Filippov wrote: > > > How should we synchronize our changes? > > > > No problem, I can revert to the previous edition of this patch > > that just adds syscall_get_arch. > > Alternatively, you can just take that couple of patches (v5 18/25 > > and v2 15/15) into your tree. > > Sure I can do the second. Will it work for v2 16/15 that changes > syscall_get_arch adding an argument to it? No, I'm afraid it won't work for v2 16/15 (aka v5 22/25), which means I'd have to keep them in the series. -- ldv signature.asc Description: PGP signature
Re: [PATCH v5 19/25] xtensa: define syscall_get_* functions
On Mon, Dec 10, 2018 at 11:24:02PM +0300, Dmitry V. Levin wrote: > On Mon, Dec 10, 2018 at 12:14:37PM -0800, Max Filippov wrote: > > On Mon, Dec 10, 2018 at 4:53 AM Dmitry V. Levin wrote: > > > On Sun, Dec 09, 2018 at 09:02:50PM -0800, Max Filippov wrote: > > > > How should we synchronize our changes? > > > > > > No problem, I can revert to the previous edition of this patch > > > that just adds syscall_get_arch. > > > Alternatively, you can just take that couple of patches (v5 18/25 > > > and v2 15/15) into your tree. > > > > Sure I can do the second. Will it work for v2 16/15 that changes > > syscall_get_arch adding an argument to it? > > No, I'm afraid it won't work for v2 16/15 (aka v5 22/25), which means > I'd have to keep them in the series. You can surely take them into your tree, but I'll have to keep them in the series because of that change of syscall_get_arch signature. Sorry for confusion. -- ldv signature.asc Description: PGP signature
[PATCH] asm-generic/ptrace.h: add a comment about frame_pointer
I have been misled by comments in asm-generic/ptrace.h into thinking that frame_pointer() is universally available across architectures, which resulted in a wrong design decision. Add a comment about frame_pointer in a hope that it will help others to avoid this mistake in the future. Cc: Oleg Nesterov Cc: Arnd Bergmann Cc: linux-a...@vger.kernel.org Signed-off-by: Dmitry V. Levin --- include/asm-generic/ptrace.h | 4 1 file changed, 4 insertions(+) diff --git a/include/asm-generic/ptrace.h b/include/asm-generic/ptrace.h index 82e674f6b337..3186c30bd50d 100644 --- a/include/asm-generic/ptrace.h +++ b/include/asm-generic/ptrace.h @@ -59,6 +59,10 @@ static inline void user_stack_pointer_set(struct pt_regs *regs, #define SET_FP(regs, val) (GET_FP(regs) = (val)) #endif +/* + * Unlike instruction_pointer and user_stack_pointer, + * frame_pointer is not universally available across architectures. + */ static inline unsigned long frame_pointer(struct pt_regs *regs) { return GET_FP(regs); -- ldv
Re: [PATCH v5 24/25] ptrace: add PTRACE_GET_SYSCALL_INFO request
On Tue, Dec 11, 2018 at 04:29:54PM +0100, Oleg Nesterov wrote: > On 12/10, Dmitry V. Levin wrote: > > On Mon, Dec 10, 2018 at 03:11:07PM +0100, Oleg Nesterov wrote: > > > On 12/10, Dmitry V. Levin wrote: > > > > > > > > +struct ptrace_syscall_info { > > > > + __u8 op;/* PTRACE_SYSCALL_INFO_* */ > > > > + __u8 __pad0[3]; > > > > + __u32 arch; > > > > + __u64 instruction_pointer; > > > > + __u64 stack_pointer; > > > > + __u64 frame_pointer; > > > > + union { > > > > + struct { > > > > + __u64 nr; > > > > + __u64 args[6]; > > > > + } entry; > > > > + struct { > > > > + __s64 rval; > > > > + __u8 is_error; > > > > + __u8 __pad1[7]; > > > > + } exit; > > > > + struct { > > > > + __u64 nr; > > > > + __u64 args[6]; > > > > + __u32 ret_data; > > > > + __u8 __pad2[4]; > > > > + } seccomp; > > > > + }; > > > > +}; > > > > > > Could you explain why ptrace_syscall_info needs __pad{0,1,2} ? I simply > > > can't > > > understand why... > > > > I suppose the idea behind the use of these pads was to make the structure > > arch-independent. > > Still can't understand... are you saying that without (say) __pad2[4] > sizeof(ptrace_syscall_info) or offsetofend(ptrace_syscall_info, seccomp) > will depend on arch? Or what? I am just curious. Yes, without padding these sizes will depend on architecture: $ cat t.c #include int main() { struct s { __u64 nr; __u64 args[6]; __u32 ret_data; }; return sizeof(struct s); } $ gcc -m64 -Wall -O2 t.c && ./a.out; echo $? 64 $ gcc -m32 -Wall -O2 t.c && ./a.out; echo $? 60 This happens because __u64 has 32-bit alignment on some 32-bit architectures like x86. There is also m68k where __u32 has 16-bit alignment. > > I don't think we really need to keep it exactly the same on all > > architectures - the only practical requirement is to avoid any compat > > issues, but I don't mind keeping the structure arch-independent. > > OK, but may be you can add a short comment to explain these pads. Alternatively, we could use __attribute__((aligned(N))), e.g. struct ptrace_syscall_info { __u8 op;/* PTRACE_SYSCALL_INFO_* */ __u32 arch __attribute__((aligned(4))); __u64 instruction_pointer; __u64 stack_pointer; union { struct { __u64 nr __attribute__((aligned(8))); __u64 args[6]; } entry; struct { __s64 rval __attribute__((aligned(8))); __u8 is_error; } exit; struct { __u64 nr __attribute__((aligned(8))); __u64 args[6]; __u32 ret_data; } seccomp; }; }; Do you prefer __attribute__((aligned(N))) to padding? -- ldv signature.asc Description: PGP signature
Re: [PATCH v5 24/25] ptrace: add PTRACE_GET_SYSCALL_INFO request
On Tue, Dec 11, 2018 at 07:23:05PM +0300, Dmitry V. Levin wrote: > On Tue, Dec 11, 2018 at 04:29:54PM +0100, Oleg Nesterov wrote: > > On 12/10, Dmitry V. Levin wrote: > > > On Mon, Dec 10, 2018 at 03:11:07PM +0100, Oleg Nesterov wrote: > > > > On 12/10, Dmitry V. Levin wrote: > > > > > > > > > > +struct ptrace_syscall_info { > > > > > + __u8 op;/* PTRACE_SYSCALL_INFO_* */ > > > > > + __u8 __pad0[3]; > > > > > + __u32 arch; > > > > > + __u64 instruction_pointer; > > > > > + __u64 stack_pointer; > > > > > + __u64 frame_pointer; > > > > > + union { > > > > > + struct { > > > > > + __u64 nr; > > > > > + __u64 args[6]; > > > > > + } entry; > > > > > + struct { > > > > > + __s64 rval; > > > > > + __u8 is_error; > > > > > + __u8 __pad1[7]; > > > > > + } exit; > > > > > + struct { > > > > > + __u64 nr; > > > > > + __u64 args[6]; > > > > > + __u32 ret_data; > > > > > + __u8 __pad2[4]; > > > > > + } seccomp; > > > > > + }; > > > > > +}; > > > > > > > > Could you explain why ptrace_syscall_info needs __pad{0,1,2} ? I simply > > > > can't > > > > understand why... > > > > > > I suppose the idea behind the use of these pads was to make the structure > > > arch-independent. > > > > Still can't understand... are you saying that without (say) __pad2[4] > > sizeof(ptrace_syscall_info) or offsetofend(ptrace_syscall_info, seccomp) > > will depend on arch? Or what? I am just curious. > > Yes, without padding these sizes will depend on architecture: > > $ cat t.c > #include > int main() { > struct s { > __u64 nr; > __u64 args[6]; > __u32 ret_data; > }; > return sizeof(struct s); > } > > $ gcc -m64 -Wall -O2 t.c && ./a.out; echo $? > 64 > $ gcc -m32 -Wall -O2 t.c && ./a.out; echo $? > 60 > > This happens because __u64 has 32-bit alignment on some 32-bit > architectures like x86. > > There is also m68k where __u32 has 16-bit alignment. Said that, I think it would be better if PTRACE_GET_SYSCALL_INFO did not take these trailing pads into account, e.g. - return offsetofend(struct ptrace_syscall_info, seccomp); + return offsetofend(struct ptrace_syscall_info, seccomp.ret_data); ... - return offsetofend(struct ptrace_syscall_info, exit); + return offsetofend(struct ptrace_syscall_info, exit.is_error); The reason is that it would allow to fill these trailing pads with something useful in the future. -- ldv signature.asc Description: PGP signature
Re: [PATCH v6 04/27] Move EM_ARCOMPACT and EM_ARCV2 to uapi/linux/elf-em.h
Hi, On Thu, Dec 13, 2018 at 08:21:42PM +0300, Dmitry V. Levin wrote: > These 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. > > Acked-by: Vineet Gupta > Cc: Elvira Khabirova > Cc: Eugene Syromyatnikov > Cc: Oleg Nesterov > Cc: Andy Lutomirski > Cc: Alexey Brodkin > Cc: linux-snps-...@lists.infradead.org > Signed-off-by: Dmitry V. Levin > --- 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. > 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(-) > > diff --git a/arch/arc/include/asm/elf.h b/arch/arc/include/asm/elf.h > index aa2d6da9d187..2b80c184c9c8 100644 > --- a/arch/arc/include/asm/elf.h > +++ b/arch/arc/include/asm/elf.h > @@ -10,13 +10,9 @@ > #define __ASM_ARC_ELF_H > > #include > +#include > #include > > -/* 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) > > diff --git a/include/uapi/linux/elf-em.h b/include/uapi/linux/elf-em.h > index 93722e60204c..42b7546352a6 100644 > --- a/include/uapi/linux/elf-em.h > +++ b/include/uapi/linux/elf-em.h > @@ -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_MICROBLAZE189 /* Xilinx MicroBlaze */ > #define EM_TILEGX191 /* 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 */ > -- > ldv -- ldv signature.asc Description: PGP signature
Re: [PATCH v6 05/27] arc: define syscall_get_arch()
Hi, On Thu, Dec 13, 2018 at 08:21:46PM +0300, Dmitry V. Levin wrote: > syscall_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. > > Acked-by: Vineet Gupta > Cc: Elvira Khabirova > Cc: Eugene Syromyatnikov > Cc: Oleg Nesterov > Cc: Andy Lutomirski > Cc: Alexey Brodkin > Cc: Paul Moore > Cc: Eric Paris > Cc: linux-snps-...@lists.infradead.org > Cc: linux-au...@redhat.com > Signed-off-by: Dmitry V. Levin > --- 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. > 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(+) > > diff --git a/arch/arc/include/asm/syscall.h b/arch/arc/include/asm/syscall.h > index 29de09804306..c7fc4c0c3bcb 100644 > --- a/arch/arc/include/asm/syscall.h > +++ b/arch/arc/include/asm/syscall.h > @@ -9,6 +9,7 @@ > #ifndef _ASM_ARC_SYSCALL_H > #define _ASM_ARC_SYSCALL_H 1 > > +#include > #include > #include > #include > @@ -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 > diff --git a/include/uapi/linux/audit.h b/include/uapi/linux/audit.h > index 818ae690ab79..bedf3bf54c3a 100644 > --- a/include/uapi/linux/audit.h > +++ b/include/uapi/linux/audit.h > @@ -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) > -- > ldv -- ldv signature.asc Description: PGP signature
Re: [PATCH v6 16/27] mips: define syscall_get_error()
Hi Paul, On Thu, Dec 13, 2018 at 07:00:16PM +, Paul Burton wrote: > Hi Dmitry, > > On Thu, Dec 13, 2018 at 08:23:02PM +0300, Dmitry V. Levin wrote: > > syscall_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. > > > > Cc: Paul Burton > > Cc: Ralf Baechle > > Cc: James Hogan > > Cc: Oleg Nesterov > > Cc: Andy Lutomirski > > Cc: Elvira Khabirova > > Cc: Eugene Syromyatnikov > > Cc: linux-m...@vger.kernel.org > > Signed-off-by: Dmitry V. Levin > > Acked-by: Paul Burton 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, -- ldv signature.asc Description: PGP signature
Re: [PATCH v6 07/27] elf-em.h: add EM_CSKY
Hi, On Fri, Dec 14, 2018 at 12:43:08PM +0800, Guo Ren wrote: > Reviewed-by: Guo Ren 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. > On Thu, Dec 13, 2018 at 08:22:00PM +0300, Dmitry V. Levin wrote: > > The 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 > > > > Cc: Guo Ren > > Cc: Oleg Nesterov > > Cc: Andy Lutomirski > > Cc: Elvira Khabirova > > Cc: Eugene Syromyatnikov > > Signed-off-by: Dmitry V. Levin > > --- > > > > Notes: > > v6: unchanged > > > > include/uapi/linux/elf-em.h | 1 + > > 1 file changed, 1 insertion(+) > > > > diff --git a/include/uapi/linux/elf-em.h b/include/uapi/linux/elf-em.h > > index 42b7546352a6..ee0b26ab92b0 100644 > > --- a/include/uapi/linux/elf-em.h > > +++ b/include/uapi/linux/elf-em.h > > @@ -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_CSKY252 /* C-SKY processor family */ > > #define EM_FRV 0x5441 /* Fujitsu FR-V */ > > > > /* > > -- > > ldv -- ldv signature.asc Description: PGP signature
Re: [PATCH v6 08/27] csky: define syscall_get_arch()
Hi, On Fri, Dec 14, 2018 at 12:44:12PM +0800, Guo Ren wrote: > Thx Dmitry, > > Reviewed-by: Guo Ren 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. > On Thu, Dec 13, 2018 at 08:22:07PM +0300, Dmitry V. Levin wrote: > > syscall_get_arch() is required to be implemented on all architectures > > in order to extend the generic ptrace API with PTRACE_GET_SYSCALL_INFO > > request. > > > > Cc: Guo Ren > > Cc: Paul Moore > > Cc: Eric Paris > > Cc: Oleg Nesterov > > Cc: Andy Lutomirski > > Cc: Elvira Khabirova > > Cc: Eugene Syromyatnikov > > Cc: linux-au...@redhat.com > > Signed-off-by: Dmitry V. Levin > > --- > > > > Notes: > > v6: unchanged > > > > arch/csky/include/asm/syscall.h | 7 +++ > > include/uapi/linux/audit.h | 1 + > > 2 files changed, 8 insertions(+) > > > > diff --git a/arch/csky/include/asm/syscall.h > > b/arch/csky/include/asm/syscall.h > > index 926a64a8b4ee..d637445737b7 100644 > > --- a/arch/csky/include/asm/syscall.h > > +++ b/arch/csky/include/asm/syscall.h > > @@ -6,6 +6,7 @@ > > #include > > #include > > #include > > +#include > > > > 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 */ > > diff --git a/include/uapi/linux/audit.h b/include/uapi/linux/audit.h > > index 72aeea0a740d..55904a40d768 100644 > > --- a/include/uapi/linux/audit.h > > +++ b/include/uapi/linux/audit.h > > @@ -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) > > -- > > ldv -- ldv signature.asc Description: PGP signature
Re: "bpf: Improve the info.func_info and info.func_info_rec_size behavior" breaks strace self tests
On Fri, Jan 04, 2019 at 10:25:24AM +0100, Heiko Carstens wrote: > On Thu, Jan 03, 2019 at 11:52:51PM +, Martin Lau wrote: > > On Thu, Jan 03, 2019 at 11:41:18PM +0100, Heiko Carstens wrote: > > > On Thu, Jan 03, 2019 at 07:12:05PM +, Martin Lau wrote: > > > > On Thu, Jan 03, 2019 at 12:46:13PM +0100, Heiko Carstens wrote: > > > > > Hello, > > > > > > > > > > the kernel commit 7337224fc150 ("bpf: Improve the info.func_info and > > > > > info.func_info_rec_size behavior") breaks one of strace's self tests: > > > > > > > > > > FAIL: bpf-obj_get_info_by_fd-prog-v.gen > ... > > I am running against linux-next. I don't see how root and non-root affect > > thing here. I guess the test has been running without jit so far? > > Yes, it was disabled. Enabling jit and adding your memset fix leads to > what you report with 2) below. > > > 1) root or not, if jit is enabled, > >without the memset() fix in the bpf-obj_get_info_by_fd.c in my last > > email, > >they all failed: > >[root@arch-fb-vm1 tests]# ./bpf-obj_get_info_by_fd-prog-v.gen.test > >BPF_OBJ_GET_INFO_BY_FD prog 2 failed: Bad address > >bpf-obj_get_info_by_fd-prog-v.gen.test: skipped test: > > ../bpf-obj_get_info_by_fd-prog-v exited with code 77 > > > >Please fix this first. > > > > 2) After having the memset fix: > >Root or not, for jited program, if I run > >./bpf-obj_get_info_by_fd-prog-v.gen.test, they failed. If I read the > >init.sh correclty, it fails because there is a diff between the > >./bpf-obj_get_info_by_fd-prog-v stdout and the "strace -o log". I think > >"strace -o log" only has the /* bytes 104..151 */ part if some bytes > >are non-zero? > > > >Regardless, the test program "bpf-obj_get_info_by_fd.c" is telling > >the kernel that the userspace "info" is in size 168 bytes. > >The kernel then tells as much details as possible about > >a bpf prog in "info". I don't see a ABI breakage here. > > > >I believe the test just happens to work so far because it has been > > running > >without jit? > > > >If I run it with jit enabled: > > -bpf(BPF_OBJ_GET_INFO_BY_FD, {info={bpf_fd=4, > > info_len=168, info={type=BPF_PROG_TYPE_SOCKET_FILTER, id=35, > > tag="\xda\xbf\x02\x07\xd1\x99\x24\x86", jited_prog_len=0 => 110, > > jited_prog_insns=NULL, xlated_prog_len=0 => 120, xlated_prog_insns=[], > > load_time=2476906063975, created_by_uid=0, nr_map_ids=0 => 1, map_ids=[], > > name="test_prog", ifindex=0, netns_dev=makedev(0, 0), netns_ino=0}}}, 16) = > > 0 > > -bpf(BPF_OBJ_GET_INFO_BY_FD, {info={bpf_fd=4, > > info_len=168, info={type=BPF_PROG_TYPE_SOCKET_FILTER, id=35, > > tag="\xda\xbf\x02\x07\xd1\x99\x24\x86", jited_prog_len=0 => 110, > > jited_prog_insns=NULL, xlated_prog_len=0 => 120, xlated_prog_insns=[], > > load_time=2476906063975, created_by_uid=0, nr_map_ids=2 => 1, map_ids=[36], > > name="test_prog", ifindex=0, netns_dev=makedev(0, 0), netns_ino=0}}}, 16) = > > 0 > > +bpf(BPF_OBJ_GET_INFO_BY_FD, {info={bpf_fd=4, > > info_len=168, info={type=BPF_PROG_TYPE_SOCKET_FILTER, id=35, > > tag="\xda\xbf\x02\x07\xd1\x99\x24\x86", jited_prog_len=0 => 110, > > jited_prog_insns=NULL, xlated_prog_len=0 => 120, xlated_prog_insns=[], > > load_time=2476906063975, created_by_uid=0, nr_map_ids=0 => 1, map_ids=[], > > name="test_prog", ifindex=0, netns_dev=makedev(0, 0), netns_ino=0, /* bytes > > 104..167 */ > > "\x01\x00\x00\x00\x01\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x08\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"}}}, > > 16) = 0 > > +bpf(BPF_OBJ_GET_INFO_BY_FD, {info={bpf_fd=4, > > info_len=168, info={type=BPF_PROG_TYPE_SOCKET_FILTER, id=35, > > tag="\xda\xbf\x02\x07\xd1\x99\x24\x86", jited_prog_len=0 => 110, > > jited_prog_insns=NULL, xlated_prog_len=0 => 120, xlated_prog_insns=[], > > load_time=2476906063975, created_by_uid=0, nr_map_ids=2 => 1, map_ids=[36], > > name="test_prog", ifindex=0, netns_dev=makedev(0, 0), netns_ino=0, /* bytes > > 104..167 */ > > "\x01\x00\x00\x00\x01\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x08\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"}}}, > > 16) = 0 > > > > The diff comes in as early as byte 104-th which is the nr_jited_ksyms == > > 1. > > > > Please fix the test program. A protential fix is in > > bpf-obj_get_info_by_fd.c > > to printf the non-zero "/* bytes 104..1xx */..." the same way as the > > "strace -o log" does. > > Thanks a lot for looking into this! > Eugene, Dmitry will you take care of fixing this? Thanks for reporting this! AFAICT, the test in question was specifically designed to check whether the strace printer of BPF_OBJ_GET_INFO_BY_FD command is up to date with the kernel, and this f
[PATCH v7 01/22] 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. Cc: Arnd Bergmann Cc: Oleg Nesterov Cc: Geert Uytterhoeven Cc: Elvira Khabirova Cc: Eugene Syromyatnikov Cc: linux-a...@vger.kernel.org Signed-off-by: Dmitry V. Levin --- Notes: v7: unchanged v6: initial revision include/asm-generic/syscall.h | 39 +-- 1 file changed, 24 insertions(+), 15 deletions(-) diff --git a/include/asm-generic/syscall.h b/include/asm-generic/syscall.h index 0c938a4354f6..9863a5f8fbe8 100644 --- a/include/asm-generic/syscall.h +++ b/include/asm-generic/syscall.h @@ -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 1 struct 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 */ -- ldv
[PATCH v7 02/22] asm-generic/syscall.h: turn syscall_[gs]et_arguments into wrappers
Add 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. Cc: Arnd Bergmann Cc: Oleg Nesterov Cc: Geert Uytterhoeven Cc: Elvira Khabirova Cc: Eugene Syromyatnikov Cc: linux-a...@vger.kernel.org Signed-off-by: Dmitry V. Levin --- Notes: v7: unchanged v6: initial revision include/asm-generic/syscall.h | 47 +-- 1 file changed, 45 insertions(+), 2 deletions(-) diff --git a/include/asm-generic/syscall.h b/include/asm-generic/syscall.h index 9863a5f8fbe8..fdefe27fa63f 100644 --- a/include/asm-generic/syscall.h +++ b/include/asm-generic/syscall.h @@ -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 -- ldv
[PATCH v7 04/22] Move EM_ARCOMPACT and EM_ARCV2 to uapi/linux/elf-em.h
These 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. Acked-by: Vineet Gupta Cc: Elvira Khabirova Cc: Eugene Syromyatnikov Cc: Oleg Nesterov Cc: Andy Lutomirski Cc: Alexey Brodkin Cc: linux-snps-...@lists.infradead.org Signed-off-by: Dmitry V. Levin --- Notes: v7: unchanged 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(-) diff --git a/arch/arc/include/asm/elf.h b/arch/arc/include/asm/elf.h index aa2d6da9d187..2b80c184c9c8 100644 --- a/arch/arc/include/asm/elf.h +++ b/arch/arc/include/asm/elf.h @@ -10,13 +10,9 @@ #define __ASM_ARC_ELF_H #include +#include #include -/* 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) diff --git a/include/uapi/linux/elf-em.h b/include/uapi/linux/elf-em.h index 0c3000faedba..081675ed89cb 100644 --- a/include/uapi/linux/elf-em.h +++ b/include/uapi/linux/elf-em.h @@ -34,6 +34,7 @@ #define EM_M32R88 /* 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_XTENSA 94 /* Tensilica Xtensa Architecture */ #define EM_BLACKFIN 106 /* ADI Blackfin Processor */ #define EM_ALTERA_NIOS2113 /* Altera Nios II soft-core processor */ @@ -42,6 +43,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_CSKY252 /* C-SKY */ -- ldv
[PATCH v7 03/22] alpha: define remaining syscall_get_* functions
syscall_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. Cc: Richard Henderson Cc: Ivan Kokshaysky Cc: Matt Turner Cc: Oleg Nesterov Cc: Andy Lutomirski Cc: Elvira Khabirova Cc: Eugene Syromyatnikov Cc: linux-al...@vger.kernel.org Signed-off-by: Dmitry V. Levin --- Notes: v7: unchanged v6: use asm-generic/syscall.h v5: initial revision arch/alpha/include/asm/syscall.h | 31 ++- 1 file changed, 30 insertions(+), 1 deletion(-) diff --git a/arch/alpha/include/asm/syscall.h b/arch/alpha/include/asm/syscall.h index d73a6fcb519c..c67d6a69d7c8 100644 --- a/arch/alpha/include/asm/syscall.h +++ b/arch/alpha/include/asm/syscall.h @@ -2,9 +2,38 @@ #ifndef _ASM_ALPHA_SYSCALL_H #define _ASM_ALPHA_SYSCALL_H +#include +#include #include -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; } -- ldv
[PATCH v7 07/22] h8300: define remaining syscall_get_* functions
syscall_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. Acked-by: Paul Moore # audit related parts Cc: Yoshinori Sato Cc: Eric Paris Cc: Oleg Nesterov Cc: Andy Lutomirski Cc: Elvira Khabirova Cc: Eugene Syromyatnikov Cc: uclinux-h8-de...@lists.sourceforge.jp Cc: linux-au...@redhat.com Signed-off-by: Dmitry V. Levin --- Notes: v7: added Acked-by 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(+) diff --git a/arch/h8300/include/asm/syscall.h b/arch/h8300/include/asm/syscall.h index 924990401237..0a6565d12836 100644 --- a/arch/h8300/include/asm/syscall.h +++ b/arch/h8300/include/asm/syscall.h @@ -8,6 +8,8 @@ #include #include #include +#include +#include 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 */ diff --git a/include/uapi/linux/audit.h b/include/uapi/linux/audit.h index e3d0255b4fc2..c6a6e3a9ec9a 100644 --- a/include/uapi/linux/audit.h +++ b/include/uapi/linux/audit.h @@ -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) -- ldv
[PATCH v7 05/22] arc: define syscall_get_arch()
syscall_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. Acked-by: Vineet Gupta Acked-by: Paul Moore Cc: Elvira Khabirova Cc: Eugene Syromyatnikov Cc: Oleg Nesterov Cc: Andy Lutomirski Cc: Alexey Brodkin Cc: Eric Paris Cc: linux-snps-...@lists.infradead.org Cc: linux-au...@redhat.com Signed-off-by: Dmitry V. Levin --- Notes: v7: added Acked-by 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(+) diff --git a/arch/arc/include/asm/syscall.h b/arch/arc/include/asm/syscall.h index 29de09804306..c7fc4c0c3bcb 100644 --- a/arch/arc/include/asm/syscall.h +++ b/arch/arc/include/asm/syscall.h @@ -9,6 +9,7 @@ #ifndef _ASM_ARC_SYSCALL_H #define _ASM_ARC_SYSCALL_H 1 +#include #include #include #include @@ -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 diff --git a/include/uapi/linux/audit.h b/include/uapi/linux/audit.h index 36a7e3f18e69..41d8fa80ebad 100644 --- a/include/uapi/linux/audit.h +++ b/include/uapi/linux/audit.h @@ -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) -- ldv
[PATCH v7 09/22] hexagon: define remaining syscall_get_* functions
syscall_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. Acked-by: Paul Moore # audit related parts Cc: Richard Kuo Cc: Eric Paris Cc: Oleg Nesterov Cc: Andy Lutomirski Cc: Elvira Khabirova Cc: Eugene Syromyatnikov Cc: linux-hexa...@vger.kernel.org Cc: linux-au...@redhat.com Signed-off-by: Dmitry V. Levin --- Notes: v7: added Acked-by 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(+) diff --git a/arch/hexagon/include/asm/syscall.h b/arch/hexagon/include/asm/syscall.h index 4af9c7b6f13a..c3290c0bc458 100644 --- a/arch/hexagon/include/asm/syscall.h +++ b/arch/hexagon/include/asm/syscall.h @@ -21,6 +21,10 @@ #ifndef _ASM_HEXAGON_SYSCALL_H #define _ASM_HEXAGON_SYSCALL_H +#include +#include +#include + 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 diff --git a/include/uapi/linux/audit.h b/include/uapi/linux/audit.h index c6a6e3a9ec9a..b1602dcc13bc 100644 --- a/include/uapi/linux/audit.h +++ b/include/uapi/linux/audit.h @@ -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) -- ldv
[PATCH v7 06/22] c6x: define syscall_get_arch()
syscall_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. Acked-by: Mark Salter Acked-by: Paul Moore Cc: Aurelien Jacquiot Cc: Eric Paris Cc: Oleg Nesterov Cc: Andy Lutomirski Cc: Elvira Khabirova Cc: Eugene Syromyatnikov Cc: linux-c6x-...@linux-c6x.org Cc: linux-au...@redhat.com Signed-off-by: Dmitry V. Levin --- Notes: v7: added Acked-by 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(+) diff --git a/arch/c6x/include/asm/syscall.h b/arch/c6x/include/asm/syscall.h index ae2be315ee9c..39dbd1ef994c 100644 --- a/arch/c6x/include/asm/syscall.h +++ b/arch/c6x/include/asm/syscall.h @@ -11,6 +11,7 @@ #ifndef __ASM_C6X_SYSCALL_H #define __ASM_C6X_SYSCALL_H +#include #include #include @@ -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 */ diff --git a/include/uapi/linux/audit.h b/include/uapi/linux/audit.h index 41d8fa80ebad..e3d0255b4fc2 100644 --- a/include/uapi/linux/audit.h +++ b/include/uapi/linux/audit.h @@ -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_CSKY(EM_CSKY|__AUDIT_ARCH_LE) #define AUDIT_ARCH_FRV (EM_FRV) -- ldv
[PATCH v7 08/22] Move EM_HEXAGON to uapi/linux/elf-em.h
This 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. Cc: Richard Kuo Cc: Oleg Nesterov Cc: Andy Lutomirski Cc: Elvira Khabirova Cc: Eugene Syromyatnikov Cc: linux-hexa...@vger.kernel.org Signed-off-by: Dmitry V. Levin --- Notes: v7: unchanged 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(-) diff --git a/arch/hexagon/include/asm/elf.h b/arch/hexagon/include/asm/elf.h index 80311e7b8ca6..d10fbd54ae51 100644 --- a/arch/hexagon/include/asm/elf.h +++ b/arch/hexagon/include/asm/elf.h @@ -23,11 +23,7 @@ #include #include - -/* - * This should really be in linux/elf-em.h. - */ -#define EM_HEXAGON 164 /* QUALCOMM Hexagon */ +#include struct elf32_hdr; diff --git a/include/uapi/linux/elf-em.h b/include/uapi/linux/elf-em.h index 081675ed89cb..bd02325028d8 100644 --- a/include/uapi/linux/elf-em.h +++ b/include/uapi/linux/elf-em.h @@ -39,6 +39,7 @@ #define EM_BLACKFIN 106 /* ADI Blackfin Processor */ #define EM_ALTERA_NIOS2113 /* Altera Nios II soft-core processor */ #define EM_TI_C6000140 /* 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 */ -- ldv
[PATCH v7 12/22] nios2: define syscall_get_arch()
syscall_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. Acked-by: Paul Moore Cc: Ley Foon Tan Cc: Eric Paris Cc: Oleg Nesterov Cc: Andy Lutomirski Cc: Elvira Khabirova Cc: Eugene Syromyatnikov Cc: nios2-...@lists.rocketboards.org Cc: linux-au...@redhat.com Signed-off-by: Dmitry V. Levin --- Notes: v7: added Acked-by v6: unchanged v5: added Cc arch/nios2/include/asm/syscall.h | 6 ++ include/uapi/linux/audit.h | 1 + 2 files changed, 7 insertions(+) diff --git a/arch/nios2/include/asm/syscall.h b/arch/nios2/include/asm/syscall.h index 9de220854c4a..cf35e210fc4d 100644 --- a/arch/nios2/include/asm/syscall.h +++ b/arch/nios2/include/asm/syscall.h @@ -17,6 +17,7 @@ #ifndef __ASM_NIOS2_SYSCALL_H__ #define __ASM_NIOS2_SYSCALL_H__ +#include #include #include @@ -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 diff --git a/include/uapi/linux/audit.h b/include/uapi/linux/audit.h index 1568ddc1c945..efeb0bbd6c4d 100644 --- a/include/uapi/linux/audit.h +++ b/include/uapi/linux/audit.h @@ -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) -- ldv
[PATCH v7 10/22] Move EM_NDS32 to uapi/linux/elf-em.h
This 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. Cc: Greentime Hu Cc: Vincent Chen Cc: Oleg Nesterov Cc: Andy Lutomirski Cc: Elvira Khabirova Cc: Eugene Syromyatnikov Signed-off-by: Dmitry V. Levin --- Notes: v7: unchanged 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(-) diff --git a/arch/nds32/include/asm/elf.h b/arch/nds32/include/asm/elf.h index 95f3ea253e4c..02250626b9f0 100644 --- a/arch/nds32/include/asm/elf.h +++ b/arch/nds32/include/asm/elf.h @@ -10,14 +10,13 @@ #include #include +#include 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_RELA19 #define R_NDS32_32_RELA20 diff --git a/include/uapi/linux/elf-em.h b/include/uapi/linux/elf-em.h index bd02325028d8..4b8df722330e 100644 --- a/include/uapi/linux/elf-em.h +++ b/include/uapi/linux/elf-em.h @@ -40,6 +40,8 @@ #define EM_ALTERA_NIOS2113 /* Altera Nios II soft-core processor */ #define EM_TI_C6000140 /* 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 */ -- ldv
[PATCH v7 13/22] m68k: add asm/syscall.h
syscall_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. Acked-by: Paul Moore # audit related parts Cc: Geert Uytterhoeven Cc: Oleg Nesterov Cc: Andy Lutomirski Cc: Elvira Khabirova Cc: Eugene Syromyatnikov Cc: linux-m...@lists.linux-m68k.org Signed-off-by: Dmitry V. Levin --- Notes: v7: added Acked-by 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 diff --git a/arch/m68k/include/asm/syscall.h b/arch/m68k/include/asm/syscall.h new file mode 100644 index ..c87b14417753 --- /dev/null +++ b/arch/m68k/include/asm/syscall.h @@ -0,0 +1,42 @@ +/* SPDX-License-Identifier: GPL-2.0 */ +#ifndef _ASM_M68K_SYSCALL_H +#define _ASM_M68K_SYSCALL_H + +#include +#include +#include +#include + +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 */ -- ldv
[PATCH v7 15/22] parisc: define syscall_get_error()
syscall_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. Cc: James E.J. Bottomley Cc: Helge Deller Cc: Oleg Nesterov Cc: Andy Lutomirski Cc: Elvira Khabirova Cc: Eugene Syromyatnikov Cc: linux-par...@vger.kernel.org Signed-off-by: Dmitry V. Levin --- Notes: v7: unchanged v6: unchanged v5: initial revision arch/parisc/include/asm/syscall.h | 7 +++ 1 file changed, 7 insertions(+) diff --git a/arch/parisc/include/asm/syscall.h b/arch/parisc/include/asm/syscall.h index 8bff1a58c97f..477511ff7546 100644 --- a/arch/parisc/include/asm/syscall.h +++ b/arch/parisc/include/asm/syscall.h @@ -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) { -- ldv
[PATCH v7 11/22] nds32: define syscall_get_arch()
syscall_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. Acked-by: Paul Moore Cc: Greentime Hu Cc: Vincent Chen Cc: Eric Paris Cc: Oleg Nesterov Cc: Andy Lutomirski Cc: Elvira Khabirova Cc: Eugene Syromyatnikov Cc: linux-au...@redhat.com Signed-off-by: Dmitry V. Levin --- Notes: v7: added Acked-by 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(+) diff --git a/arch/nds32/include/asm/syscall.h b/arch/nds32/include/asm/syscall.h index f7e5e86765fe..569149ca25da 100644 --- a/arch/nds32/include/asm/syscall.h +++ b/arch/nds32/include/asm/syscall.h @@ -5,6 +5,7 @@ #ifndef _ASM_NDS32_SYSCALL_H #define _ASM_NDS32_SYSCALL_H 1 +#include #include 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 */ diff --git a/include/uapi/linux/audit.h b/include/uapi/linux/audit.h index b1602dcc13bc..1568ddc1c945 100644 --- a/include/uapi/linux/audit.h +++ b/include/uapi/linux/audit.h @@ -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) -- ldv
[PATCH v7 17/22] riscv: define syscall_get_arch()
syscall_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. Based-on-patch-by: David Abdurachmanov Reviewed-by: Palmer Dabbelt Acked-by: Paul Moore Cc: Elvira Khabirova Cc: Eugene Syromyatnikov Cc: Oleg Nesterov Cc: Andy Lutomirski Cc: Albert Ou Cc: Eric Paris Cc: linux-ri...@lists.infradead.org Cc: linux-au...@redhat.com Signed-off-by: Dmitry V. Levin --- Notes: v7: added Acked-by 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(+) diff --git a/arch/riscv/include/asm/syscall.h b/arch/riscv/include/asm/syscall.h index 8d25f8904c00..bba3da6ef157 100644 --- a/arch/riscv/include/asm/syscall.h +++ b/arch/riscv/include/asm/syscall.h @@ -18,6 +18,7 @@ #ifndef _ASM_RISCV_SYSCALL_H #define _ASM_RISCV_SYSCALL_H +#include #include #include @@ -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 */ diff --git a/include/uapi/linux/audit.h b/include/uapi/linux/audit.h index efeb0bbd6c4d..bcc0619b046f 100644 --- a/include/uapi/linux/audit.h +++ b/include/uapi/linux/audit.h @@ -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) -- ldv
[PATCH v7 18/22] Move EM_UNICORE to uapi/linux/elf-em.h
This 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. Cc: Guan Xuetao Cc: Oleg Nesterov Cc: Andy Lutomirski Cc: Elvira Khabirova Cc: Eugene Syromyatnikov Signed-off-by: Dmitry V. Levin --- Notes: v7: unchanged 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(-) diff --git a/arch/unicore32/include/asm/elf.h b/arch/unicore32/include/asm/elf.h index 829042d07722..ae66dc1be49e 100644 --- a/arch/unicore32/include/asm/elf.h +++ b/arch/unicore32/include/asm/elf.h @@ -19,6 +19,7 @@ * ELF register definitions.. */ #include +#include 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_ABS322 diff --git a/include/uapi/linux/elf-em.h b/include/uapi/linux/elf-em.h index 4b8df722330e..f47e853546fa 100644 --- a/include/uapi/linux/elf-em.h +++ b/include/uapi/linux/elf-em.h @@ -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_NIOS2113 /* Altera Nios II soft-core processor */ #define EM_TI_C6000140 /* TI C6X DSPs */ #define EM_HEXAGON 164 /* QUALCOMM Hexagon */ -- ldv
[PATCH v7 19/22] unicore32: add asm/syscall.h
syscall_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. Acked-by: Paul Moore # audit related parts Cc: Guan Xuetao Cc: Eric Paris Cc: Oleg Nesterov Cc: Andy Lutomirski Cc: Elvira Khabirova Cc: Eugene Syromyatnikov Cc: linux-au...@redhat.com Signed-off-by: Dmitry V. Levin --- Notes: v7: added Acked-by 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 | 47 include/uapi/linux/audit.h | 1 + 2 files changed, 48 insertions(+) create mode 100644 arch/unicore32/include/asm/syscall.h diff --git a/arch/unicore32/include/asm/syscall.h b/arch/unicore32/include/asm/syscall.h new file mode 100644 index ..267e97e256bd --- /dev/null +++ b/arch/unicore32/include/asm/syscall.h @@ -0,0 +1,47 @@ +/* SPDX-License-Identifier: GPL-2.0 */ +#ifndef _ASM_UNICORE_SYSCALL_H +#define _ASM_UNICORE_SYSCALL_H + +#include +#include +#include +#include + +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 */ diff --git a/include/uapi/linux/audit.h b/include/uapi/linux/audit.h index bcc0619b046f..3901c51c0b93 100644 --- a/include/uapi/linux/audit.h +++ b/include/uapi/linux/audit.h @@ -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) -- ldv
[PATCH v7 14/22] mips: define syscall_get_error()
syscall_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. Acked-by: Paul Burton Cc: Ralf Baechle Cc: James Hogan Cc: Oleg Nesterov Cc: Andy Lutomirski Cc: Elvira Khabirova Cc: Eugene Syromyatnikov Cc: linux-m...@vger.kernel.org Signed-off-by: Dmitry V. Levin --- Notes: v7: added Acked-by v6: unchanged v5: initial revision arch/mips/include/asm/syscall.h | 6 ++ 1 file changed, 6 insertions(+) diff --git a/arch/mips/include/asm/syscall.h b/arch/mips/include/asm/syscall.h index 6cf8ffb5367e..04ab927ff47d 100644 --- a/arch/mips/include/asm/syscall.h +++ b/arch/mips/include/asm/syscall.h @@ -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) { -- ldv
[PATCH v7 16/22] powerpc: define syscall_get_error()
syscall_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. Cc: Michael Ellerman Cc: Benjamin Herrenschmidt Cc: Paul Mackerras Cc: Oleg Nesterov Cc: Andy Lutomirski Cc: Elvira Khabirova Cc: Eugene Syromyatnikov Cc: linuxppc-...@lists.ozlabs.org Signed-off-by: Dmitry V. Levin --- Notes: v7: unchanged 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(+) diff --git a/arch/powerpc/include/asm/syscall.h b/arch/powerpc/include/asm/syscall.h index 1a0e7a8b1c81..b522781ad7c0 100644 --- a/arch/powerpc/include/asm/syscall.h +++ b/arch/powerpc/include/asm/syscall.h @@ -38,6 +38,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 & 0x1000UL) ? -regs->gpr[3] : 0; +} + static inline long syscall_get_return_value(struct task_struct *task, struct pt_regs *regs) { -- ldv
[PATCH v7 22/22] selftests/ptrace: add a test case for PTRACE_GET_SYSCALL_INFO
Check whether PTRACE_GET_SYSCALL_INFO semantics implemented in the kernel matches userspace expectations. Cc: Oleg Nesterov Cc: Andy Lutomirski Cc: Shuah Khan Cc: Elvira Khabirova Cc: Eugene Syromyatnikov Cc: linux-kselft...@vger.kernel.org Signed-off-by: Dmitry V. Levin --- Notes: v7: unchanged 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 diff --git a/tools/testing/selftests/ptrace/.gitignore b/tools/testing/selftests/ptrace/.gitignore index b3e59d41fd82..cfcc49a7def7 100644 --- a/tools/testing/selftests/ptrace/.gitignore +++ b/tools/testing/selftests/ptrace/.gitignore @@ -1 +1,2 @@ +get_syscall_info peeksiginfo diff --git a/tools/testing/selftests/ptrace/Makefile b/tools/testing/selftests/ptrace/Makefile index 8a2bc5562179..4bc550b6b845 100644 --- a/tools/testing/selftests/ptrace/Makefile +++ b/tools/testing/selftests/ptrace/Makefile @@ -1,5 +1,5 @@ CFLAGS += -iquote../../../../include/uapi -Wall -TEST_GEN_PROGS := peeksiginfo +TEST_GEN_PROGS := get_syscall_info peeksiginfo include ../lib.mk diff --git a/tools/testing/selftests/ptrace/get_syscall_info.c b/tools/testing/selftests/ptrace/get_syscall_info.c new file mode 100644 index ..28e972825b74 --- /dev/null +++ b/tools/testing/selftests/ptrace/get_syscall_info.c @@ -0,0 +1,271 @@ +/* SPDX-License-Identifier: GPL-2.0-or-later + * + * Copyright (c) 2018 Dmitry V. Levin + * All rights reserved. + * + * Check whether PTRACE_GET_SYSCALL_INFO semantics implemented in the kernel + * matches userspace expectations. + */ + +#include "../kselftest_harness.h" +#include +#include +#include +#include "linux/ptrace.h" + +static int +kill_tracee(pid_t pid) +{ + if (!pid) + return 0; + + int saved_errno = errno; + + int rc = kill(pid, SIGKILL); + + errno = saved_errno; + return rc; +} + +static long +sys_ptrace(int request, pid_t pid, unsigned long addr, unsigned long data) +{ + return syscall(__NR_ptrace, request, pid, addr, data); +} + +#define LOG_KILL_TRACEE(fmt, ...) \ + do {\ + kill_tracee(pid); \ + TH_LOG("wait #%d: " fmt,\ + ptrace_stop, ##__VA_ARGS__); \ + } while (0) + +TEST(get_syscall_info) +{ + static const unsigned long args[][7] = { + /* a sequence of architecture-agnostic syscalls */ + { + __NR_chdir, + (unsigned long) "", + 0xbad1fed1, + 0xbad2fed2, + 0xbad3fed3, + 0xbad4fed4, + 0xbad5fed5 + }, + { + __NR_gettid, + 0xcaf0bea0, + 0xcaf1bea1, + 0xcaf2bea2, + 0xcaf3bea3, + 0xcaf4bea4, + 0xcaf5bea5 + }, + { + __NR_exit_group, + 0, + 0xfac1c0d1, + 0xfac2c0d2, + 0xfac3c0d3, + 0xfac4c0d4, + 0xfac5c0d5 + } + }; + const unsigned long *exp_args; + + pid_t pid = fork(); + + ASSERT_LE(0, pid) { + TH_LOG("fork: %m"); + } + + if (pid == 0) { + /* get the pid before PTRACE_TRACEME */ + pid = getpid(); + ASSERT_EQ(0, sys_ptrace(PTRACE_TRACEME, 0, 0, 0)) { + TH_LOG("PTRACE_TRACEME: %m"); + } + ASSERT_EQ(0, kill(pid, SIGSTOP)) { + /* cannot happen */ + TH_LOG("kill SIGSTOP: %m"); + } + for (unsigned int i = 0; i < ARRAY_SIZE(args); ++i) { + syscall(args[i][0], + args[i][1], args[i][2], args[i][3], + args[i][4], args[i][5], args[i][6]); + } + /* unreachable */ + _exit(1); + } + + const struct { + unsigned int is_error; + int rval; + } *exp_param, exit_param[] = { + { 1, -ENOENT }, /* chdir */ + { 0, pid } /* gettid */ + }; + + unsigned int ptrace_stop; + + for (ptrace_stop = 0; ; ++ptrace_stop) { +
[PATCH v7 20/22] syscall_get_arch: add "struct task_struct *" argument
This 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()") Reviewed-by: Andy Lutomirski # for x86 Reviewed-by: Palmer Dabbelt Acked-by: Paul Burton # MIPS parts Acked-by: Michael Ellerman (powerpc) Acked-by: Kees Cook # seccomp parts Acked-by: Mark Salter # for the c6x bit Acked-by: Paul Moore # audit related parts Cc: Eric Paris Cc: Richard Henderson Cc: Ivan Kokshaysky Cc: Matt Turner Cc: Vineet Gupta Cc: Russell King Cc: Catalin Marinas Cc: Will Deacon Cc: Aurelien Jacquiot Cc: Yoshinori Sato Cc: Richard Kuo Cc: Tony Luck Cc: Fenghua Yu Cc: Geert Uytterhoeven Cc: Michal Simek Cc: Greentime Hu Cc: Vincent Chen Cc: Ley Foon Tan Cc: Jonas Bonn Cc: Stefan Kristiansson Cc: Stafford Horne Cc: James E.J. Bottomley Cc: Helge Deller Cc: Albert Ou Cc: Martin Schwidefsky Cc: Heiko Carstens Cc: Rich Felker Cc: David S. Miller Cc: Guan Xuetao Cc: Jeff Dike Cc: Richard Weinberger Cc: Chris Zankel Cc: Max Filippov Cc: Arnd Bergmann Cc: Will Drewry Cc: Oleg Nesterov Cc: Elvira Khabirova Cc: Eugene Syromyatnikov Cc: Ralf Baechle Cc: James Hogan Cc: Benjamin Herrenschmidt Cc: Paul Mackerras Cc: Thomas Gleixner Cc: Ingo Molnar Cc: Borislav Petkov Cc: H. Peter Anvin Cc: x...@kernel.org Cc: linux-al...@vger.kernel.org Cc: linux-snps-...@lists.infradead.org Cc: linux-arm-ker...@lists.infradead.org Cc: linux-c6x-...@linux-c6x.org Cc: uclinux-h8-de...@lists.sourceforge.jp Cc: linux-hexa...@vger.kernel.org Cc: linux-i...@vger.kernel.org Cc: linux-m...@lists.linux-m68k.org Cc: linux-m...@vger.kernel.org Cc: nios2-...@lists.rocketboards.org Cc: openr...@lists.librecores.org Cc: linux-par...@vger.kernel.org Cc: linuxppc-...@lists.ozlabs.org Cc: linux-ri...@lists.infradead.org Cc: linux-s...@vger.kernel.org Cc: linux...@vger.kernel.org Cc: sparcli...@vger.kernel.org Cc: linux...@lists.infradead.org Cc: linux-xte...@linux-xtensa.org Cc: linux-a...@vger.kernel.org Cc: linux-au...@redhat.com Signed-off-by: Dmitry V. Levin --- Notes: v7: added more Acked-by 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(-) diff --git a/arch/alpha/include/asm/syscall.h b/arch/alpha/include/asm/syscall.h index c67d6a69d7c8..20078aef0922 100644 --- a/arch/alpha/include/asm/syscall.h +++ b/arch/alpha/include/asm/syscall.h @@ -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; } diff --git a/arch/arc/include/asm/syscall.h b/arch/arc/include/asm/syscall.h index c7fc4c0c3bcb..caf2697ef5b7 100644 --- a/arch/arc/include/asm/syscall.h +++ b/arch/arc/include/asm/syscall.h @@ -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) diff --git a/arch/arm/include/asm/syscall.h b/arch/arm/include
[PATCH v7 21/22] ptrace: add PTRACE_GET_SYSCALL_INFO request
From: Elvira Khabirova 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. Co-authored-by: Dmitry V. Levin Reviewed-by: Oleg Nesterov Reviewed-by: Kees Cook Cc: Andy Lutomirski Cc: Eugene Syromyatnikov Cc: Jann Horn Cc: linux-...@vger.kernel.org Cc: strace-de...@lists.strace.io Signed-off-by: Elvira Khabirova Signed-off-by: Dmitry V. Levin --- Notes: v7: unchanged 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
[PATCH] nds32: fix asm/syscall.h
All syscall_get_* and syscall_set_* functions must be defined as static inline. Reported-by: kbuild test robot Fixes: 1932fbe36e02 ("nds32: System calls handling") Cc: Greentime Hu Cc: Vincent Chen Cc: Elvira Khabirova Cc: Eugene Syromyatnikov Cc: sta...@vger.kernel.org # v4.17+ Signed-off-by: Dmitry V. Levin --- arch/nds32/include/asm/syscall.h | 29 ++--- 1 file changed, 18 insertions(+), 11 deletions(-) diff --git a/arch/nds32/include/asm/syscall.h b/arch/nds32/include/asm/syscall.h index f7e5e86765fe..6b131202d0e9 100644 --- a/arch/nds32/include/asm/syscall.h +++ b/arch/nds32/include/asm/syscall.h @@ -25,7 +25,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 inline int +syscall_get_nr(struct task_struct *task, struct pt_regs *regs) { return regs->syscallno; } @@ -46,7 +47,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 inline void +syscall_rollback(struct task_struct *task, struct pt_regs *regs) { regs->uregs[0] = regs->orig_r0; } @@ -61,7 +63,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 inline long +syscall_get_error(struct task_struct *task, struct pt_regs *regs) { unsigned long error = regs->uregs[0]; return IS_ERR_VALUE(error) ? error : 0; @@ -78,7 +81,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 inline long +syscall_get_return_value(struct task_struct *task, struct pt_regs *regs) { return regs->uregs[0]; } @@ -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 inline void +syscall_set_return_value(struct task_struct *task, struct pt_regs *regs, +int error, long val) { regs->uregs[0] = (long)error ? error : val; } @@ -122,8 +127,9 @@ void syscall_set_return_value(struct task_struct *task, struct pt_regs *regs, * taking up to 6 arguments. */ #define SYSCALL_MAX_ARGS 6 -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) { if (n == 0) return; @@ -163,9 +169,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 inline void +syscall_set_arguments(struct task_struct *task, struct pt_regs *regs, + unsigned int i, unsigned int n, + const unsigned long *args) { if (n == 0) return; -- ldv
Re: [PATCH v7 21/22] ptrace: add PTRACE_GET_SYSCALL_INFO request
Hi, Looks like we need help to overcome this alpha specific issue: On Mon, Jan 07, 2019 at 03:05:23PM +0800, kbuild test robot wrote: > Hi Elvira, > > Thank you for the patch! Yet something to improve: > > [auto build test ERROR on linus/master] > [also build test ERROR on v5.0-rc1] > [cannot apply to next-20190103] > [if your patch is applied to the wrong git tree, please drop us a note to > help improve the system] > > url: > https://github.com/0day-ci/linux/commits/Dmitry-V-Levin/asm-generic-syscall-h-prepare-for-inclusion-by-other-files/20190107-115241 > config: alpha-allmodconfig (attached as .config) > compiler: alpha-linux-gnu-gcc (Debian 7.2.0-11) 7.2.0 > reproduce: > wget > https://raw.githubusercontent.com/intel/lkp-tests/master/sbin/make.cross -O > ~/bin/make.cross > chmod +x ~/bin/make.cross > # save the attached .config to linux build tree > GCC_VERSION=7.2.0 make.cross ARCH=alpha > > All errors (new ones prefixed by >>): > >kernel/ptrace.c: In function 'ptrace_get_syscall_info': > >> kernel/ptrace.c:944:20: error: implicit declaration of function > >> 'user_stack_pointer'; did you mean 'xa_tag_pointer'? > >> [-Werror=implicit-function-declaration] > .stack_pointer = user_stack_pointer(regs), >^~ >xa_tag_pointer >In file included from arch/alpha/include/asm/syscall.h:6:0, > from include/linux/audit.h:214, > from kernel/ptrace.c:24: The mandatory function static inline unsigned long user_stack_pointer(struct pt_regs *regs) is not implemented on alpha, and I don't know how to implement it because the relevant information is not available via struct pt_regs. On alpha task_thread_info(task)->pcb.usp is used to obtain the user stack pointer. -- ldv signature.asc Description: PGP signature
Re: d_off field in struct dirent and 32-on-64 emulation
On Thu, Dec 27, 2018 at 06:18:19PM +0100, Florian Weimer wrote: > We have a bit of an interesting problem with respect to the d_off > field in struct dirent. > > When running a 64-bit kernel on certain file systems, notably ext4, > this field uses the full 63 bits even for small directories (strace -v > output, wrapped here for readability): > > getdents(3, [ > {d_ino=1494304, d_off=3901177228673045825, d_reclen=40, > d_name="authorized_keys", d_type=DT_REG}, > {d_ino=1494277, d_off=7491915799041650922, d_reclen=24, d_name=".", > d_type=DT_DIR}, > {d_ino=1314655, d_off=9223372036854775807, d_reclen=24, d_name="..", > d_type=DT_DIR} > ], 32768) = 88 > > When running in 32-bit compat mode, this value is somehow truncated to > 31 bits, for both the getdents and the getdents64 (!) system call (at > least on i386). Why getdents64 system call is affected by this truncation, isn't it a kernel bug that has to be fixed in the kernel instead? -- ldv signature.asc Description: PGP signature
Re: [PATCH] alpha: fix page fault handling for r16-r18 targets
Hi, On Sun, Dec 30, 2018 at 08:23:12PM +, Sergei Trofimovich wrote: > Fix page fault handling code to fixup r16-r18 registers. > Before the patch code had off-by-two registers bug. > This bug caused overwriting of ps,pc,gp registers instead > of fixing intended r16,r17,r18 (see `struct pt_regs`). > > More details: > > Initially Dmitry noticed a kernel bug as a failure > on strace test suite. Test passes unmapped userspace > pointer to io_submit: > > ```c > #include > #include > #include > #include > int main(void) > { > unsigned long ctx = 0; > if (syscall(__NR_io_setup, 1, &ctx)) > err(1, "io_setup"); > const size_t page_size = sysconf(_SC_PAGESIZE); > const size_t size = page_size * 2; > void *ptr = mmap(NULL, size, PROT_READ | PROT_WRITE, > MAP_PRIVATE | MAP_ANONYMOUS, -1, 0); > if (MAP_FAILED == ptr) > err(1, "mmap(%zu)", size); > if (munmap(ptr, size)) > err(1, "munmap"); > syscall(__NR_io_submit, ctx, 1, ptr + page_size); > syscall(__NR_io_destroy, ctx); > return 0; > } > ``` > > Running this test causes kernel to crash when handling page fault: > > ``` > Unable to handle kernel paging request at virtual address 9468 > CPU 3 > aio(26027): Oops 0 > pc = [] ra = [] ps = Not > tainted > pc is at sys_io_submit+0x108/0x200 > ra is at sys_io_submit+0x6c/0x200 > v0 = fc00c58e6300 t0 = fff2 t1 = 0225e000 > t2 = fc01f159fef8 t3 = fc0001009640 t4 = fce0f6e0 > t5 = 020001002e9e t6 = 4c41564e49452031 t7 = fc01f159c000 > s0 = 0002 s1 = 0225e000 s2 = > s3 = s4 = s5 = fff2 > s6 = fc00c58e6300 > a0 = fc00c58e6300 a1 = a2 = 0225e000 > a3 = 021ac260 a4 = 021ac1e8 a5 = 0001 > t8 = 0008 t9 = 00011f8bce30 t10= 021ac440 > t11= pv = fc6fd320 at = > gp = sp = 265fd174 > Disabling lock debugging due to kernel taint > Trace: > [] entSys+0xa4/0xc0 > ``` > > Here `gp` has invalid value. `gp is s overwritten by a fixup for the > following page fault handler in `io_submit` syscall handler: > > ``` > __se_sys_io_submit > ... > ldq a1,0(t1) > bne t0,4280 <__se_sys_io_submit+0x180> > ``` > > After a page fault `t0` should contain -EFALUT and `a1` is 0. > Instead `gp` was overwritten in place of `a1`. > > This happens due to a off-by-two bug in `dpf_reg()` for `r16-r18` > (aka `a0-a2`). > > I think the bug went unnoticed for a long time as `gp` is one > of scratch registers. Any kernel function call would re-calculate `gp`. Thanks, that's impressive! According to the history git, the off-by-two bug was introduced in linux 2.1.32 when trap_a{0,1,2} fields were inserted into struct pt_regs on alpha without an appropriate dpf_reg() update. Before 2.1.32 (back to 2.1.7 when dpf_reg() was introduced) there was another off-by-one bug in dpf_reg(): r16 was written into struct pt_regs.r17. In other words, the bug is quite old indeed. You can add Reported-and-reviewed-by: "Dmitry V. Levin" Cc: sta...@vger.kernel.org # v2.1.32+ > CC: Dmitry V. Levin This is a technical address, please remove it. > CC: Richard Henderson > CC: Ivan Kokshaysky > CC: Matt Turner > CC: linux-al...@vger.kernel.org > CC: linux-kernel@vger.kernel.org > Reported-by: Dmitry V. Levin > Bug: https://bugs.gentoo.org/672040 > Signed-off-by: Sergei Trofimovich > --- > arch/alpha/mm/fault.c | 2 +- > 1 file changed, 1 insertion(+), 1 deletion(-) > > diff --git a/arch/alpha/mm/fault.c b/arch/alpha/mm/fault.c > index d73dc473fbb9..188fc9256baf 100644 > --- a/arch/alpha/mm/fault.c > +++ b/arch/alpha/mm/fault.c > @@ -78,7 +78,7 @@ __load_new_mm_context(struct mm_struct *next_mm) > /* Macro for exception fixup code to access integer registers. */ > #define dpf_reg(r) \ > (((unsigned long *)regs)[(r) <= 8 ? (r) : (r) <= 15 ? (r)-16 : \ > - (r) <= 18 ? (r)+8 : (r)-10]) > + (r) <= 18 ? (r)+10 : (r)-10]) > > asmlinkage void > do_page_fault(unsigned long address, unsigned long mmcsr, > -- > 2.20.1 -- ldv signature.asc Description: PGP signature
Re: [RFC PATCH] ptrace: add PTRACE_GET_SYSCALL_INFO request
On Wed, Nov 07, 2018 at 04:27:51AM +0100, Elvira Khabirova wrote: [...] > The structure was chosen according to [2], except for two changes. > First: instead of an arch field with a value of AUDIT_ARCH_*, a boolean > is_compat value is returned, because a) not all arches have an AUDIT_ARCH_* > defined for them, To be more specific, here is the list of arch subtrees in v4.20-rc1 that invoke tracehook_report_syscall_entry() but do not provide syscall_get_arch(): arch/arc arch/c6x arch/h8300 arch/hexagon arch/m68k arch/nds32 arch/nios2 arch/riscv arch/um arch/xtensa Among these trees only m68k has its AUDIT_ARCH_M68K constant defined. -- ldv
Re: [RFC PATCH] ptrace: add PTRACE_GET_SYSCALL_INFO request
On Wed, Nov 07, 2018 at 12:21:01PM +0100, Oleg Nesterov wrote: > On 11/07, Elvira Khabirova wrote: > > > > 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. > > Yes, this was discussed many times... > > So perhaps it makes sense to encode compat/is_enter in ->ptrace_message, > debugger can use PTRACE_GETEVENTMSG to get this info. This would mean for the debugger an extra syscall invocation for each syscall stop. When strace doesn't have to fetch memory, it invokes three syscalls per syscall stop (wait4, PTRACE_GETREGSET, and PTRACE_SYSCALL). We definitely want to avoid adding PTRACE_GETEVENTMSG on top of that. -- ldv
Re: [PATCH v23 3/5] tracing: Allow user-space mapping of the ring-buffer
On Fri, May 10, 2024 at 03:04:32PM +0100, Vincent Donnefort wrote: [...] > diff --git a/include/uapi/linux/trace_mmap.h b/include/uapi/linux/trace_mmap.h > index b682e9925539..bd1066754220 100644 > --- a/include/uapi/linux/trace_mmap.h > +++ b/include/uapi/linux/trace_mmap.h > @@ -43,4 +43,6 @@ struct trace_buffer_meta { > __u64 Reserved2; > }; > > +#define TRACE_MMAP_IOCTL_GET_READER _IO('T', 0x1) > + I'm sorry but among all the numbers this one was probably the least fortunate choice because it collides with TCGETS on most of architectures. For example, this is how strace output would look like when TRACE_MMAP_IOCTL_GET_READER support is added: $ strace -e ioctl stty ioctl(0, TCGETS or TRACE_MMAP_IOCTL_GET_READER, {c_iflag=ICRNL|IXON, c_oflag=NL0|CR0|TAB0|BS0|VT0|FF0|OPOST|ONLCR, c_cflag=B38400|CS8|CREAD, c_lflag=ISIG|ICANON|ECHO|ECHOE|ECHOK|IEXTEN|ECHOCTL|ECHOKE, ...}) = 0 Even though ioctl numbers are inherently not unique, TCGETS is a very traditional one, so it would be great if you could change TRACE_MMAP_IOCTL_GET_READER to avoid this collision. Given that _IO('T', 0x1) is _IOC(_IOC_NONE, 'T', 0x1, 0), something like _IOC(_IOC_NONE, 'T', 0x1, 0x1) should be OK. -- ldv
[PATCH] uapi: change TRACE_MMAP_IOCTL_GET_READER to avoid collision with TCGETS
The number that was initially chosen for TRACE_MMAP_IOCTL_GET_READER, unfortunately, collides with TCGETS on most of architectures. For example, this is how strace output would look like when support for this value of TRACE_MMAP_IOCTL_GET_READER is added: $ strace -e ioctl stty ioctl(0, TCGETS or TRACE_MMAP_IOCTL_GET_READER, {c_iflag=ICRNL|IXON, c_oflag=NL0|CR0|TAB0|BS0|VT0|FF0|OPOST|ONLCR, +c_cflag=B38400|CS8|CREAD, c_lflag=ISIG|ICANON|ECHO|ECHOE|ECHOK|IEXTEN|ECHOCTL|ECHOKE, ...}) = 0 Even though ioctl numbers are inherently not unique, TCGETS is a very traditional one, so let's change the value of TRACE_MMAP_IOCTL_GET_READER a bit to avoid this collision. Given that _IO('T', 0x1) is _IOC(_IOC_NONE, 'T', 0x1, 0), something like _IOC(_IOC_NONE, 'T', 0x1, 0x1) should be OK. Fixes: cf9f0f7c4c5bb ("tracing: Allow user-space mapping of the ring-buffer") Signed-off-by: Dmitry V. Levin --- include/uapi/linux/trace_mmap.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/include/uapi/linux/trace_mmap.h b/include/uapi/linux/trace_mmap.h index bd1066754220..cb858f1b8367 100644 --- a/include/uapi/linux/trace_mmap.h +++ b/include/uapi/linux/trace_mmap.h @@ -43,6 +43,6 @@ struct trace_buffer_meta { __u64 Reserved2; }; -#define TRACE_MMAP_IOCTL_GET_READER_IO('T', 0x1) +#define TRACE_MMAP_IOCTL_GET_READER_IOC(_IOC_NONE, 'T', 0x1, 0x1) #endif /* _TRACE_MMAP_H_ */ -- ldv
Re: [PATCH v23 3/5] tracing: Allow user-space mapping of the ring-buffer
On Tue, Jul 02, 2024 at 11:32:53AM -0400, Mathieu Desnoyers wrote: [...] > Note that user events also has this issue: the ioctl is not reserved in > the ioctl-number.rst list. See include/uapi/linux/user_events.h: > > #define DIAG_IOC_MAGIC '*' > > /* Request to register a user_event */ > #define DIAG_IOCSREG _IOWR(DIAG_IOC_MAGIC, 0, struct user_reg *) > > /* Request to delete a user_event */ > #define DIAG_IOCSDEL _IOW(DIAG_IOC_MAGIC, 1, char *) > > /* Requests to unregister a user_event */ > #define DIAG_IOCSUNREG _IOW(DIAG_IOC_MAGIC, 2, struct user_unreg*) > > Where '*' maps to Code 0x2A. Looking at the list I don't see any > conflicts there, but we should definitely add it. > > If we use '*' for user events already, perhaps we'd want to consider > using the same range for the ring buffer ioctls ? Arguably one is > about instrumentation and the other is about ring buffer interaction > (data transport), but those are both related to tracing. FWIW, I've checked the list of ioctls known to strace and can confirm that currently there are no more users of 0x2a ioctl code besides these three DIAG_* ioctls. -- ldv
Re: [PATCH v23 3/5] tracing: Allow user-space mapping of the ring-buffer
On Tue, Jul 02, 2024 at 11:18:07AM -0400, Steven Rostedt wrote: > On Tue, 2 Jul 2024 10:36:03 -0400 > Mathieu Desnoyers wrote: > > > > I can send a patch this week to update it. Or feel free to send a patch > > > yourself. > > > > You need to reserve an unused ioctl Code and Seq# range within: > > > > Documentation/userspace-api/ioctl/ioctl-number.rst > > Ug, it's been so long, I completely forgot about that file. > > Thanks for catching this. > > > > > Otherwise this duplicate will confuse all system call instrumentation > > tooling. > > Agreed, what if we did this then: > > -- Steve > > diff --git a/Documentation/userspace-api/ioctl/ioctl-number.rst > b/Documentation/userspace-api/ioctl/ioctl-number.rst > index a141e8e65c5d..9a97030c6c8d 100644 > --- a/Documentation/userspace-api/ioctl/ioctl-number.rst > +++ b/Documentation/userspace-api/ioctl/ioctl-number.rst > @@ -186,6 +186,7 @@ Code Seq#Include File >Comments > 'Q' alllinux/soundcard.h > 'R' 00-1F linux/random.h > conflict! > 'R' 01 linux/rfkill.h > conflict! > +'R' 20-2F linux/trace_mmap.h > 'R' C0-DF net/bluetooth/rfcomm.h > 'R' E0 uapi/linux/fsl_mc.h > 'S' alllinux/cdrom.h > conflict! Just in case, I've checked the list of ioctls known to strace and can confirm that there are no users of 'R' ioctl code in 0x20..0x2f range yet. By the way, this file is definitely not up to date, the 'R' part of it should have contained the following: 'R' 00-1F uapi/linux/random.h conflict! 'R' 01-02 uapi/linux/rfkill.h conflict! 'R' 01-0D uapi/misc/fastrpc.h conflict! 'R' C0-DF net/bluetooth/rfcomm.h 'R' E0 uapi/linux/fsl_mc.h -- ldv
Re: [PATCH 1/2] uprobe: Change uretprobe syscall scope and number
On Fri, Jul 12, 2024 at 03:52:27PM +0200, Jiri Olsa wrote: > After discussing with Arnd [1] it's preferable to change uretprobe > syscall number to 467 to omit the merge conflict with xattrat syscalls. > > Also changing the ABI to 'common' which will ease up the global > scripts/syscall.tbl management. One consequence is we generate uretprobe > syscall numbers for ABIs that do not support uretprobe syscall, but the > syscall still returns -ENOSYS when called in that ABI. > > [1] > https://lore.kernel.org/lkml/784a34e5-4654-44c9-9c07-f9f4ffd95...@app.fastmail.com/ > > Fixes: 190fec72df4a ("uprobe: Wire up uretprobe system call") > Suggested-by: Arnd Bergmann > Signed-off-by: Jiri Olsa > --- > arch/x86/entry/syscalls/syscall_64.tbl | 2 +- > 1 file changed, 1 insertion(+), 1 deletion(-) > > diff --git a/arch/x86/entry/syscalls/syscall_64.tbl > b/arch/x86/entry/syscalls/syscall_64.tbl > index 6452c2ec469a..dabf1982de6d 100644 > --- a/arch/x86/entry/syscalls/syscall_64.tbl > +++ b/arch/x86/entry/syscalls/syscall_64.tbl > @@ -384,7 +384,7 @@ > 460 common lsm_set_self_attr sys_lsm_set_self_attr > 461 common lsm_list_modulessys_lsm_list_modules > 462 common mseal sys_mseal > -463 64 uretprobe sys_uretprobe > +467 common uretprobe sys_uretprobe > > # > # Due to a historical design error, certain syscalls are numbered differently Isn't include/uapi/asm-generic/unistd.h expected to be updated as well? As of mainline commit v6.10-12246-g786c8248dbd3, it still contains #define __NR_uretprobe 463 -- ldv
[PATCH] vfs: show_vfsstat: do not ignore errors from show_devname method
Explicitly check show_devname method return code and bail out in case of an error. This fixes regression introduced by commit 9d4d65748a5c. Signed-off-by: Dmitry V. Levin --- fs/proc_namespace.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/fs/proc_namespace.c b/fs/proc_namespace.c index 8db932d..a5644c4 100644 --- a/fs/proc_namespace.c +++ b/fs/proc_namespace.c @@ -196,17 +196,19 @@ static int show_vfsstat(struct seq_file *m, struct vfsmount *mnt) if (sb->s_op->show_devname) { seq_puts(m, "device "); err = sb->s_op->show_devname(m, mnt_path.dentry); + if (err) + goto out; } else { if (r->mnt_devname) { seq_puts(m, "device "); mangle(m, r->mnt_devname); } else seq_puts(m, "no device"); } /* mount point */ seq_puts(m, " mounted on "); /* mountpoints outside of chroot jail will give SEQ_SKIP on this */ err = seq_path_root(m, &mnt_path, &p->root, " \t\n\\"); if (err) goto out; -- ldv -- To unsubscribe from this list: send the line "unsubscribe linux-kernel" in the body of a message to majord...@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html Please read the FAQ at http://www.tux.org/lkml/
[PATCH] uapi: fix asm/bootparam.h userspace compilation errors
Consistently use types provided by to fix the following asm/bootparam.h userspace compilation errors: /usr/include/asm/bootparam.h:140:2: error: unknown type name 'u16' u16 version; /usr/include/asm/bootparam.h:141:2: error: unknown type name 'u16' u16 compatible_version; /usr/include/asm/bootparam.h:142:2: error: unknown type name 'u16' u16 pm_timer_address; /usr/include/asm/bootparam.h:143:2: error: unknown type name 'u16' u16 num_cpus; /usr/include/asm/bootparam.h:144:2: error: unknown type name 'u64' u64 pci_mmconfig_base; /usr/include/asm/bootparam.h:145:2: error: unknown type name 'u32' u32 tsc_khz; /usr/include/asm/bootparam.h:146:2: error: unknown type name 'u32' u32 apic_khz; /usr/include/asm/bootparam.h:147:2: error: unknown type name 'u8' u8 standard_ioapic; /usr/include/asm/bootparam.h:148:2: error: unknown type name 'u8' u8 cpu_ids[255]; Fixes: 4a362601baa6 ("x86/jailhouse: Add infrastructure for running in non-root cell") Cc: # v4.16 Signed-off-by: Dmitry V. Levin --- arch/x86/include/uapi/asm/bootparam.h | 18 +- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/arch/x86/include/uapi/asm/bootparam.h b/arch/x86/include/uapi/asm/bootparam.h index aebf60357758..a06cbf019744 100644 --- a/arch/x86/include/uapi/asm/bootparam.h +++ b/arch/x86/include/uapi/asm/bootparam.h @@ -137,15 +137,15 @@ struct boot_e820_entry { * setup data structure. */ struct jailhouse_setup_data { - u16 version; - u16 compatible_version; - u16 pm_timer_address; - u16 num_cpus; - u64 pci_mmconfig_base; - u32 tsc_khz; - u32 apic_khz; - u8 standard_ioapic; - u8 cpu_ids[255]; + __u16 version; + __u16 compatible_version; + __u16 pm_timer_address; + __u16 num_cpus; + __u64 pci_mmconfig_base; + __u32 tsc_khz; + __u32 apic_khz; + __u8standard_ioapic; + __u8cpu_ids[255]; } __attribute__((packed)); /* The so-called "zeropage" */ -- ldv
[PATCH] uapi: fix linux/kfd_ioctl.h userspace compilation errors
Consistently use types provided by via to fix the following linux/kfd_ioctl.h userspace compilation errors: /usr/include/linux/kfd_ioctl.h:266:2: error: unknown type name 'uint64_t' uint64_t tba_addr; /* to KFD */ /usr/include/linux/kfd_ioctl.h:267:2: error: unknown type name 'uint64_t' uint64_t tma_addr; /* to KFD */ /usr/include/linux/kfd_ioctl.h:268:2: error: unknown type name 'uint32_t' uint32_t gpu_id; /* to KFD */ /usr/include/linux/kfd_ioctl.h:269:2: error: unknown type name 'uint32_t' uint32_t pad; Fixes: d7b9bd2248d79 ("drm/amdkfd: Add support for user-mode trap handlers") Cc: # v4.16 Signed-off-by: Dmitry V. Levin --- include/uapi/linux/kfd_ioctl.h | 8 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/include/uapi/linux/kfd_ioctl.h b/include/uapi/linux/kfd_ioctl.h index f4cab5b3ba9a..111d73ba2d96 100644 --- a/include/uapi/linux/kfd_ioctl.h +++ b/include/uapi/linux/kfd_ioctl.h @@ -263,10 +263,10 @@ struct kfd_ioctl_get_tile_config_args { }; struct kfd_ioctl_set_trap_handler_args { - uint64_t tba_addr; /* to KFD */ - uint64_t tma_addr; /* to KFD */ - uint32_t gpu_id;/* to KFD */ - uint32_t pad; + __u64 tba_addr; /* to KFD */ + __u64 tma_addr; /* to KFD */ + __u32 gpu_id; /* to KFD */ + __u32 pad; }; #define AMDKFD_IOCTL_BASE 'K' -- ldv
Re: [PATCH] uapi: fix asm/bootparam.h userspace compilation errors
On Thu, Apr 05, 2018 at 09:25:26AM +0200, Jan Kiszka wrote: > On 2018-04-05 06:32, Dmitry V. Levin wrote: > > Consistently use types provided by to fix the following > > asm/bootparam.h userspace compilation errors: > > > > /usr/include/asm/bootparam.h:140:2: error: unknown type name 'u16' > > u16 version; > > /usr/include/asm/bootparam.h:141:2: error: unknown type name 'u16' > > u16 compatible_version; > > /usr/include/asm/bootparam.h:142:2: error: unknown type name 'u16' > > u16 pm_timer_address; > > /usr/include/asm/bootparam.h:143:2: error: unknown type name 'u16' > > u16 num_cpus; > > /usr/include/asm/bootparam.h:144:2: error: unknown type name 'u64' > > u64 pci_mmconfig_base; > > /usr/include/asm/bootparam.h:145:2: error: unknown type name 'u32' > > u32 tsc_khz; > > /usr/include/asm/bootparam.h:146:2: error: unknown type name 'u32' > > u32 apic_khz; > > /usr/include/asm/bootparam.h:147:2: error: unknown type name 'u8' > > u8 standard_ioapic; > > /usr/include/asm/bootparam.h:148:2: error: unknown type name 'u8' > > u8 cpu_ids[255]; > > > > Fixes: 4a362601baa6 ("x86/jailhouse: Add infrastructure for running in > > non-root cell") > > Cc: # v4.16 > > Signed-off-by: Dmitry V. Levin > > --- > > arch/x86/include/uapi/asm/bootparam.h | 18 +- > > 1 file changed, 9 insertions(+), 9 deletions(-) > > > > diff --git a/arch/x86/include/uapi/asm/bootparam.h > > b/arch/x86/include/uapi/asm/bootparam.h > > index aebf60357758..a06cbf019744 100644 > > --- a/arch/x86/include/uapi/asm/bootparam.h > > +++ b/arch/x86/include/uapi/asm/bootparam.h > > @@ -137,15 +137,15 @@ struct boot_e820_entry { > > * setup data structure. > > */ > > struct jailhouse_setup_data { > > - u16 version; > > - u16 compatible_version; > > - u16 pm_timer_address; > > - u16 num_cpus; > > - u64 pci_mmconfig_base; > > - u32 tsc_khz; > > - u32 apic_khz; > > - u8 standard_ioapic; > > - u8 cpu_ids[255]; > > + __u16 version; > > + __u16 compatible_version; > > + __u16 pm_timer_address; > > + __u16 num_cpus; > > + __u64 pci_mmconfig_base; > > + __u32 tsc_khz; > > + __u32 apic_khz; > > + __u8standard_ioapic; > > + __u8cpu_ids[255]; > > } __attribute__((packed)); > > > > /* The so-called "zeropage" */ > > > > Acked-by: Jan Kiszka > > But how did you trigger this? Our equivalent of glibc-kernheaders package contains a test for regressions of this kind. -- ldv signature.asc Description: PGP signature
[PATCH] ext4: add crc32c soft dependency
Starting with commit a45403b51582, ext4 unconditionally requires a crc32c provider, which broke certain mkinitrd setups. Add a soft dependency on crc32c so that mkinitrd, dracut, and other initrd image generators could include the required helper module. The dependency on crc32c is quite hard but there seems to be no mechanism to specify a dependency on an alias, so let's use this soft dependency as a workaround. Suggested-by: Alexey Gladkov Fixes: a45403b51582 ("ext4: always initialize the crc32c checksum driver") Cc: sta...@vger.kernel.org Signed-off-by: Dmitry V. Levin --- fs/ext4/super.c | 1 + 1 file changed, 1 insertion(+) diff --git a/fs/ext4/super.c b/fs/ext4/super.c index 185f7e6..eb104e8 100644 --- a/fs/ext4/super.c +++ b/fs/ext4/super.c @@ -5886,5 +5886,6 @@ static void __exit ext4_exit_fs(void) MODULE_AUTHOR("Remy Card, Stephen Tweedie, Andrew Morton, Andreas Dilger, Theodore Ts'o and others"); MODULE_DESCRIPTION("Fourth Extended Filesystem"); MODULE_LICENSE("GPL"); +MODULE_SOFTDEP("pre: crc32c"); module_init(ext4_init_fs) module_exit(ext4_exit_fs) -- ldv
[PATCH v7 15/22] parisc: define syscall_get_error()
syscall_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. Cc: Helge Deller Cc: James E.J. Bottomley Cc: Oleg Nesterov Cc: Andy Lutomirski Cc: Elvira Khabirova Cc: Eugene Syromyatnikov Cc: linux-par...@vger.kernel.org Signed-off-by: Dmitry V. Levin --- This is just a gentle ping, the patch is unchanged. Notes: v7: unchanged v6: unchanged v5: initial revision arch/parisc/include/asm/syscall.h | 7 +++ 1 file changed, 7 insertions(+) diff --git a/arch/parisc/include/asm/syscall.h b/arch/parisc/include/asm/syscall.h index 8bff1a58c97f..477511ff7546 100644 --- a/arch/parisc/include/asm/syscall.h +++ b/arch/parisc/include/asm/syscall.h @@ -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) { -- ldv
[PATCH v7 16/22] powerpc: define syscall_get_error()
syscall_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. Cc: Michael Ellerman Cc: Benjamin Herrenschmidt Cc: Paul Mackerras Cc: Oleg Nesterov Cc: Andy Lutomirski Cc: Elvira Khabirova Cc: Eugene Syromyatnikov Cc: linuxppc-...@lists.ozlabs.org Signed-off-by: Dmitry V. Levin --- This is just a gentle ping, the patch is unchanged. Notes: v7: unchanged 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(+) diff --git a/arch/powerpc/include/asm/syscall.h b/arch/powerpc/include/asm/syscall.h index 1a0e7a8b1c81..b522781ad7c0 100644 --- a/arch/powerpc/include/asm/syscall.h +++ b/arch/powerpc/include/asm/syscall.h @@ -38,6 +38,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 & 0x1000UL) ? -regs->gpr[3] : 0; +} + static inline long syscall_get_return_value(struct task_struct *task, struct pt_regs *regs) { -- ldv
[PATCH] nds32: fix asm/syscall.h
All syscall_get_* and syscall_set_* functions must be defined as static inline. Reported-by: kbuild test robot Fixes: 1932fbe36e02 ("nds32: System calls handling") Cc: Greentime Hu Cc: Vincent Chen Cc: Elvira Khabirova Cc: Eugene Syromyatnikov Cc: sta...@vger.kernel.org # v4.17+ Signed-off-by: Dmitry V. Levin --- This is just a gentle ping, the patch is unchanged. arch/nds32/include/asm/syscall.h | 29 ++--- 1 file changed, 18 insertions(+), 11 deletions(-) diff --git a/arch/nds32/include/asm/syscall.h b/arch/nds32/include/asm/syscall.h index f7e5e86765fe..6b131202d0e9 100644 --- a/arch/nds32/include/asm/syscall.h +++ b/arch/nds32/include/asm/syscall.h @@ -25,7 +25,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 inline int +syscall_get_nr(struct task_struct *task, struct pt_regs *regs) { return regs->syscallno; } @@ -46,7 +47,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 inline void +syscall_rollback(struct task_struct *task, struct pt_regs *regs) { regs->uregs[0] = regs->orig_r0; } @@ -61,7 +63,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 inline long +syscall_get_error(struct task_struct *task, struct pt_regs *regs) { unsigned long error = regs->uregs[0]; return IS_ERR_VALUE(error) ? error : 0; @@ -78,7 +81,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 inline long +syscall_get_return_value(struct task_struct *task, struct pt_regs *regs) { return regs->uregs[0]; } @@ -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 inline void +syscall_set_return_value(struct task_struct *task, struct pt_regs *regs, +int error, long val) { regs->uregs[0] = (long)error ? error : val; } @@ -122,8 +127,9 @@ void syscall_set_return_value(struct task_struct *task, struct pt_regs *regs, * taking up to 6 arguments. */ #define SYSCALL_MAX_ARGS 6 -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) { if (n == 0) return; @@ -163,9 +169,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 inline void +syscall_set_arguments(struct task_struct *task, struct pt_regs *regs, + unsigned int i, unsigned int n, + const unsigned long *args) { if (n == 0) return; -- ldv
[PATCH linux-next v10 3/7] mips: define syscall_get_error()
syscall_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. Acked-by: Paul Burton Cc: Elvira Khabirova Cc: Eugene Syromyatnikov Cc: Ralf Baechle Cc: James Hogan Cc: Oleg Nesterov Cc: Andy Lutomirski Cc: linux-m...@vger.kernel.org Signed-off-by: Dmitry V. Levin --- Notes: v10: unchanged v9: unchanged v8: unchanged v7: added Acked-by v6: unchanged v5: initial revision arch/mips/include/asm/syscall.h | 6 ++ 1 file changed, 6 insertions(+) diff --git a/arch/mips/include/asm/syscall.h b/arch/mips/include/asm/syscall.h index acf80ae0a430..83bb439597d8 100644 --- a/arch/mips/include/asm/syscall.h +++ b/arch/mips/include/asm/syscall.h @@ -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) { -- ldv
[PATCH linux-next v10 2/7] hexagon: define syscall_get_error() and syscall_get_return_value()
syscall_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 2 syscall_get_* functions as documented in asm-generic/syscall.h: syscall_get_error and syscall_get_return_value. Cc: Richard Kuo Cc: Elvira Khabirova Cc: Eugene Syromyatnikov Cc: Oleg Nesterov Cc: Andy Lutomirski Cc: linux-hexa...@vger.kernel.org Signed-off-by: Dmitry V. Levin --- Richard, this patch is waiting for ACK since November. Notes: v10: unchanged v9: unchanged v8: moved syscall_get_arch to separate audit patchset v7: unchanged v6: added missing includes v5: added syscall_get_error and syscall_get_return_value v4: unchanged v3: unchanged v2: unchanged arch/hexagon/include/asm/syscall.h | 14 ++ 1 file changed, 14 insertions(+) diff --git a/arch/hexagon/include/asm/syscall.h b/arch/hexagon/include/asm/syscall.h index dab26a71f577..0f28a6a39c3a 100644 --- a/arch/hexagon/include/asm/syscall.h +++ b/arch/hexagon/include/asm/syscall.h @@ -22,6 +22,8 @@ #define _ASM_HEXAGON_SYSCALL_H #include +#include +#include typedef long (*syscall_fn)(unsigned long, unsigned long, unsigned long, unsigned long, @@ -44,6 +46,18 @@ static inline void syscall_get_arguments(struct task_struct *task, memcpy(args, &(®s->r00)[0], 6 * 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(struct task_struct *task) { return AUDIT_ARCH_HEXAGON; -- ldv
[PATCH linux-next v10 1/7] nds32: fix asm/syscall.h
All syscall_get_*() and syscall_set_*() functions must be defined as static inline as on all other architectures, otherwise asm/syscall.h cannot be included in more than one compilation unit. This bug has to be fixed in order to extend the generic ptrace API with PTRACE_GET_SYSCALL_INFO request. Reported-by: kbuild test robot Fixes: 1932fbe36e02 ("nds32: System calls handling") Acked-by: Greentime Hu Cc: Vincent Chen Cc: Elvira Khabirova Cc: Eugene Syromyatnikov Cc: Oleg Nesterov Cc: Andy Lutomirski Signed-off-by: Dmitry V. Levin --- Notes: v10: added Acked-by v9: rebased to linux-next again due to syscall_get_arguments() signature change v8: unchanged v7: initial revision arch/nds32/include/asm/syscall.h | 27 +-- 1 file changed, 17 insertions(+), 10 deletions(-) diff --git a/arch/nds32/include/asm/syscall.h b/arch/nds32/include/asm/syscall.h index 174b8571d362..d08439a54034 100644 --- a/arch/nds32/include/asm/syscall.h +++ b/arch/nds32/include/asm/syscall.h @@ -26,7 +26,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 inline int +syscall_get_nr(struct task_struct *task, struct pt_regs *regs) { return regs->syscallno; } @@ -47,7 +48,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 inline void +syscall_rollback(struct task_struct *task, struct pt_regs *regs) { regs->uregs[0] = regs->orig_r0; } @@ -62,7 +64,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 inline long +syscall_get_error(struct task_struct *task, struct pt_regs *regs) { unsigned long error = regs->uregs[0]; return IS_ERR_VALUE(error) ? error : 0; @@ -79,7 +82,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 inline long +syscall_get_return_value(struct task_struct *task, struct pt_regs *regs) { return regs->uregs[0]; } @@ -99,8 +103,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 inline void +syscall_set_return_value(struct task_struct *task, struct pt_regs *regs, +int error, long val) { regs->uregs[0] = (long)error ? error : val; } @@ -118,8 +123,9 @@ void 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. */ #define SYSCALL_MAX_ARGS 6 -void syscall_get_arguments(struct task_struct *task, struct pt_regs *regs, - unsigned long *args) +static inline void +syscall_get_arguments(struct task_struct *task, struct pt_regs *regs, + unsigned long *args) { args[0] = regs->orig_r0; args++; @@ -138,8 +144,9 @@ void syscall_get_arguments(struct task_struct *task, struct pt_regs *regs, * It's only valid to call this when @task is stopped for tracing on * entry to a system call, due to %TIF_SYSCALL_TRACE or %TIF_SYSCALL_AUDIT. */ -void syscall_set_arguments(struct task_struct *task, struct pt_regs *regs, - const unsigned long *args) +static inline void +syscall_set_arguments(struct task_struct *task, struct pt_regs *regs, + const unsigned long *args) { regs->orig_r0 = args[0]; args++; -- ldv
[PATCH linux-next v10 4/7] parisc: define syscall_get_error()
syscall_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. Acked-by: Helge Deller # parisc Cc: James E.J. Bottomley Cc: Elvira Khabirova Cc: Eugene Syromyatnikov Cc: Oleg Nesterov Cc: Andy Lutomirski Cc: linux-par...@vger.kernel.org Signed-off-by: Dmitry V. Levin --- Notes: v10: unchanged v9: unchanged v8: added Acked-by v7: unchanged v6: unchanged v5: initial revision arch/parisc/include/asm/syscall.h | 7 +++ 1 file changed, 7 insertions(+) diff --git a/arch/parisc/include/asm/syscall.h b/arch/parisc/include/asm/syscall.h index 80757e43cf2c..00b127a5e09b 100644 --- a/arch/parisc/include/asm/syscall.h +++ b/arch/parisc/include/asm/syscall.h @@ -29,6 +29,13 @@ static inline void syscall_get_arguments(struct task_struct *tsk, args[0] = regs->gr[26]; } +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) { -- ldv
[PATCH linux-next v10 6/7] ptrace: add PTRACE_GET_SYSCALL_INFO request
From: Elvira Khabirova 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. Co-authored-by: Dmitry V. Levin Reviewed-by: Oleg Nesterov Reviewed-by: Kees Cook Cc: Andy Lutomirski Cc: Eugene Syromyatnikov Cc: linux-...@vger.kernel.org Cc: strace-de...@lists.strace.io Signed-off-by: Elvira Khabirova Signed-off-by: Dmitry V. Levin --- Notes: v10: unchanged v9: * Rebased to linux-next again due to syscall_get_arguments() signature change. v8: * Rebased to linux-next. * Moved ptrace_get_syscall_info code under #ifdef CONFIG_HAVE_ARCH_TRACEHOOK, narrowing down the set of architectures supported by this implementation back to those 19 that enable CONFIG_HAVE_ARCH_TRACEHOOK because I failed to get all syscall_get_*(), instruction_pointer(), and user_stack_pointer() functions implemented on some niche architectures. This leaves the following architectures out: alpha, h8300, m68k, microblaze, and unicore32. v7: unchanged 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 PTR
[PATCH linux-next v10 5/7] powerpc: define syscall_get_error()
syscall_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. Cc: Michael Ellerman Cc: Elvira Khabirova Cc: Eugene Syromyatnikov Cc: Benjamin Herrenschmidt Cc: Paul Mackerras Cc: Oleg Nesterov Cc: Andy Lutomirski Cc: linuxppc-...@lists.ozlabs.org Signed-off-by: Dmitry V. Levin --- Michael, this patch is waiting for ACK since early December. Notes: v10: unchanged v9: unchanged v8: unchanged v7: unchanged v6: unchanged v5: initial revision 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. See also https://lore.kernel.org/lkml/874lbbt3k6@concordia.ellerman.id.au/ for more details on powerpc syscall_set_return_value() confusion. arch/powerpc/include/asm/syscall.h | 10 ++ 1 file changed, 10 insertions(+) diff --git a/arch/powerpc/include/asm/syscall.h b/arch/powerpc/include/asm/syscall.h index a048fed0722f..bd9663137d57 100644 --- a/arch/powerpc/include/asm/syscall.h +++ b/arch/powerpc/include/asm/syscall.h @@ -38,6 +38,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 & 0x1000UL) ? -regs->gpr[3] : 0; +} + static inline long syscall_get_return_value(struct task_struct *task, struct pt_regs *regs) { -- ldv
[PATCH linux-next v10 7/7] selftests/ptrace: add a test case for PTRACE_GET_SYSCALL_INFO
Check whether PTRACE_GET_SYSCALL_INFO semantics implemented in the kernel matches userspace expectations. Acked-by: Shuah Khan Cc: Oleg Nesterov Cc: Andy Lutomirski Cc: Elvira Khabirova Cc: Eugene Syromyatnikov Cc: linux-kselft...@vger.kernel.org Signed-off-by: Dmitry V. Levin --- Notes: v10: changed GPL-2.0-or-later to GPL-2.0+, added Acked-by v9: unchanged v8: unchanged v7: unchanged v6: made PTRACE_GET_SYSCALL_INFO return value checks strict v5: initial revision 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 diff --git a/tools/testing/selftests/ptrace/.gitignore b/tools/testing/selftests/ptrace/.gitignore index b3e59d41fd82..cfcc49a7def7 100644 --- a/tools/testing/selftests/ptrace/.gitignore +++ b/tools/testing/selftests/ptrace/.gitignore @@ -1 +1,2 @@ +get_syscall_info peeksiginfo diff --git a/tools/testing/selftests/ptrace/Makefile b/tools/testing/selftests/ptrace/Makefile index 8a2bc5562179..4bc550b6b845 100644 --- a/tools/testing/selftests/ptrace/Makefile +++ b/tools/testing/selftests/ptrace/Makefile @@ -1,5 +1,5 @@ CFLAGS += -iquote../../../../include/uapi -Wall -TEST_GEN_PROGS := peeksiginfo +TEST_GEN_PROGS := get_syscall_info peeksiginfo include ../lib.mk diff --git a/tools/testing/selftests/ptrace/get_syscall_info.c b/tools/testing/selftests/ptrace/get_syscall_info.c new file mode 100644 index ..d1961c3ee72e --- /dev/null +++ b/tools/testing/selftests/ptrace/get_syscall_info.c @@ -0,0 +1,271 @@ +/* SPDX-License-Identifier: GPL-2.0+ + * + * Copyright (c) 2018 Dmitry V. Levin + * All rights reserved. + * + * Check whether PTRACE_GET_SYSCALL_INFO semantics implemented in the kernel + * matches userspace expectations. + */ + +#include "../kselftest_harness.h" +#include +#include +#include +#include "linux/ptrace.h" + +static int +kill_tracee(pid_t pid) +{ + if (!pid) + return 0; + + int saved_errno = errno; + + int rc = kill(pid, SIGKILL); + + errno = saved_errno; + return rc; +} + +static long +sys_ptrace(int request, pid_t pid, unsigned long addr, unsigned long data) +{ + return syscall(__NR_ptrace, request, pid, addr, data); +} + +#define LOG_KILL_TRACEE(fmt, ...) \ + do {\ + kill_tracee(pid); \ + TH_LOG("wait #%d: " fmt,\ + ptrace_stop, ##__VA_ARGS__); \ + } while (0) + +TEST(get_syscall_info) +{ + static const unsigned long args[][7] = { + /* a sequence of architecture-agnostic syscalls */ + { + __NR_chdir, + (unsigned long) "", + 0xbad1fed1, + 0xbad2fed2, + 0xbad3fed3, + 0xbad4fed4, + 0xbad5fed5 + }, + { + __NR_gettid, + 0xcaf0bea0, + 0xcaf1bea1, + 0xcaf2bea2, + 0xcaf3bea3, + 0xcaf4bea4, + 0xcaf5bea5 + }, + { + __NR_exit_group, + 0, + 0xfac1c0d1, + 0xfac2c0d2, + 0xfac3c0d3, + 0xfac4c0d4, + 0xfac5c0d5 + } + }; + const unsigned long *exp_args; + + pid_t pid = fork(); + + ASSERT_LE(0, pid) { + TH_LOG("fork: %m"); + } + + if (pid == 0) { + /* get the pid before PTRACE_TRACEME */ + pid = getpid(); + ASSERT_EQ(0, sys_ptrace(PTRACE_TRACEME, 0, 0, 0)) { + TH_LOG("PTRACE_TRACEME: %m"); + } + ASSERT_EQ(0, kill(pid, SIGSTOP)) { + /* cannot happen */ + TH_LOG("kill SIGSTOP: %m"); + } + for (unsigned int i = 0; i < ARRAY_SIZE(args); ++i) { + syscall(args[i][0], + args[i][1], args[i][2], args[i][3], + args[i][4], args[i][5], args[i][6]); + } + /* unreachable */ + _exit(1); + } + + const struct { + unsigned int is_error; + int rval; + } *exp_param, exit_param[] = { + { 1, -ENOENT }, /* chdir */ + { 0, pid }
Re: [GIT PULL] arch: add pidfd and io_uring syscalls everywhere
Hi, On Tue, Apr 23, 2019 at 09:28:48PM +0200, Arnd Bergmann wrote: > The following changes since commit 9e98c678c2d6ae3a17cb2de55d17f69dddaa231b: > > Linux 5.1-rc1 (2019-03-17 14:22:26 -0700) > > are available in the Git repository at: > > git://git.kernel.org/pub/scm/linux/kernel/git/arnd/asm-generic.git > syscalls-5.1 > > for you to fetch changes up to 39036cd2727395c3369b1051005da74059a85317: > > arch: add pidfd and io_uring syscalls everywhere (2019-04-15 16:31:17 +0200) > > > arch: add pidfd and io_uring syscalls everywhere > > This comes a bit late, but should be in 5.1 anyway: we want the newly > added system calls to be synchronized across all architectures in > the release. > > I hope that in the future, any newly added system calls can be added > to all architectures at the same time, and tested there while they > are in linux-next, avoiding dependencies between the architecture > maintainer trees and the tree that contains the new system call. Is "everywhere" really means everywhere? The reason I'm asking this question is that sh64 seems to be excluded: arch/sh/kernel/syscalls_64.S hasn't got any syscall entries since commit v4.8-rc1~15^2~3. Is sh64 supported in any way at all? -- ldv signature.asc Description: PGP signature
Re: [PATCH v2] x86/syscalls: Mark expected switch fall-throughs
On Tue, Mar 26, 2019 at 04:12:45PM +0100, Oleg Nesterov wrote: > On 03/23, Thomas Gleixner wrote: [...] > > 2) syscall_set_arguments() has been introduced in 2008 and we still have > > no caller. Instead of polishing it, can it be removed completely or are > > there plans to actually use it? > > I think it can die. When PTRACE_GET_SYSCALL_INFO is finally squeezed into the kernel, we could discuss adding PTRACE_SET_SYSCALL_INFO as well, and it will need syscall_set_arguments(). -- ldv signature.asc Description: PGP signature
Re: [PATCH v2] x86/syscalls: Mark expected switch fall-throughs
On Wed, Mar 27, 2019 at 03:29:16PM +0100, Thomas Gleixner wrote: > On Wed, 27 Mar 2019, Dmitry V. Levin wrote: > > On Tue, Mar 26, 2019 at 04:12:45PM +0100, Oleg Nesterov wrote: > > > On 03/23, Thomas Gleixner wrote: > > [...] > > > > 2) syscall_set_arguments() has been introduced in 2008 and we still > > > > have > > > > no caller. Instead of polishing it, can it be removed completely or > > > > are > > > > there plans to actually use it? > > > > > > I think it can die. > > > > When PTRACE_GET_SYSCALL_INFO is finally squeezed into the kernel, > > we could discuss adding PTRACE_SET_SYSCALL_INFO as well, and it > > will need syscall_set_arguments(). > > So if that ever happens, then adding the code back isn't rocket > science. But if not, then there is no point in carrying the dead horse > around another 11 years. Given that it took me roughly 4 months to get a relatively simple revert of commit 5e937a9ae913 accepted into linux-next, adding the code back might be time-consuming. Could we delay the removal of syscall_set_arguments() until PTRACE_GET_SYSCALL_INFO is merged into the kernel? I hope it won't take another 11 years. -- ldv signature.asc Description: PGP signature
Re: [PATCH v2] x86/syscalls: Mark expected switch fall-throughs
On Wed, Mar 27, 2019 at 11:52:19PM +0100, Thomas Gleixner wrote: > On Thu, 28 Mar 2019, Dmitry V. Levin wrote: > > On Wed, Mar 27, 2019 at 03:29:16PM +0100, Thomas Gleixner wrote: > > > On Wed, 27 Mar 2019, Dmitry V. Levin wrote: > > > > On Tue, Mar 26, 2019 at 04:12:45PM +0100, Oleg Nesterov wrote: > > > > > On 03/23, Thomas Gleixner wrote: > > > > [...] > > > > > > 2) syscall_set_arguments() has been introduced in 2008 and we > > > > > > still have > > > > > > no caller. Instead of polishing it, can it be removed > > > > > > completely or are > > > > > > there plans to actually use it? > > > > > > > > > > I think it can die. > > > > > > > > When PTRACE_GET_SYSCALL_INFO is finally squeezed into the kernel, > > > > we could discuss adding PTRACE_SET_SYSCALL_INFO as well, and it > > > > will need syscall_set_arguments(). > > > > > > So if that ever happens, then adding the code back isn't rocket > > > science. But if not, then there is no point in carrying the dead horse > > > around another 11 years. > > > > Given that it took me roughly 4 months to get a relatively simple revert > > of commit 5e937a9ae913 accepted into linux-next, adding the code back > > might be time-consuming. > > > > Could we delay the removal of syscall_set_arguments() until > > PTRACE_GET_SYSCALL_INFO is merged into the kernel? > > I hope it won't take another 11 years. > > Hope dies last :) > > Seriously. If we keep it can we at least remove all the unused arguments > which we have on both functions to simplify the whole mess? In case of syscall_set_arguments() I think we can safely remove "i" and "n" arguments assuming i == 0 and n == 6. All I can say about syscall_get_arguments() is that - all current users invoke it with i == 0, - all current users that invoke it with n != 6 are in kernel/trace/trace_syscalls.c so it may actually be invoked with n < 6. -- ldv signature.asc Description: PGP signature