Re: [PATCH] ARC: Fix wrong access to "sp" member in user_regs_struct
On Fri, Jun 30, 2017 at 04:14:14PM +0300, Eugeniy Paltsev wrote: > "sp" register is member of "scratch" structure (which is nested > in user_regs_struct) > > Signed-off-by: Eugeniy Paltsev > --- > linux/arc/arch_regs.c | 2 +- > 1 file changed, 1 insertion(+), 1 deletion(-) > > diff --git a/linux/arc/arch_regs.c b/linux/arc/arch_regs.c > index 9a5c2df..88bb799 100644 > --- a/linux/arc/arch_regs.c > +++ b/linux/arc/arch_regs.c > @@ -1,4 +1,4 @@ > static struct user_regs_struct arc_regs; > -unsigned long *const arc_sp_ptr = &arc_regs.sp; > +unsigned long *const arc_sp_ptr = &arc_regs.scratch.sp; > #define ARCH_REGS_FOR_GETREGSET arc_regs > #define ARCH_PC_REG arc_regs.efa Applied, thanks. -- ldv signature.asc Description: PGP signature ___ linux-snps-arc mailing list linux-snps-arc@lists.infradead.org http://lists.infradead.org/mailman/listinfo/linux-snps-arc
[PATCH 00/13] Prepare for PTRACE_GET_SYSCALL_INFO
syscall_get_arch() is required to be implemented on all architectures that use tracehook_report_syscall_entry() in order to extend the generic ptrace API with PTRACE_GET_SYSCALL_INFO request. Dmitry V. Levin (13): Move EM_HEXAGON to uapi/linux/elf-em.h elf-em.h: add EM_ARC elf-em.h: add EM_NDS32 elf-em.h: add EM_XTENSA m68k: define syscall_get_arch() arc: define syscall_get_arch() c6x: define syscall_get_arch() h8300: define syscall_get_arch() hexagon: define syscall_get_arch() nds32: define syscall_get_arch() nios2: define syscall_get_arch() riscv: define syscall_get_arch() xtensa: define syscall_get_arch() arch/arc/include/asm/syscall.h | 6 ++ arch/c6x/include/asm/syscall.h | 6 ++ arch/h8300/include/asm/syscall.h | 5 + arch/hexagon/include/asm/elf.h | 6 +- arch/hexagon/include/asm/syscall.h | 8 arch/m68k/include/asm/syscall.h| 12 arch/nds32/include/asm/syscall.h | 7 +++ arch/nios2/include/asm/syscall.h | 6 ++ arch/riscv/include/asm/syscall.h | 6 ++ arch/xtensa/include/asm/syscall.h | 7 +++ include/uapi/linux/audit.h | 8 include/uapi/linux/elf-em.h| 5 + 12 files changed, 77 insertions(+), 5 deletions(-) create mode 100644 arch/m68k/include/asm/syscall.h -- ldv ___ linux-snps-arc mailing list linux-snps-arc@lists.infradead.org http://lists.infradead.org/mailman/listinfo/linux-snps-arc
[PATCH 02/13] elf-em.h: add EM_ARC
The uapi/linux/audit.h header is going to use EM_ARC in order to define AUDIT_ARCH_ARC 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_ARC has been taken from http://www.sco.com/developers/gabi/2012-12-31/ch4.eheader.html Signed-off-by: Dmitry V. Levin --- 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 ba3696e3d694..56ff3f9d9633 100644 --- a/include/uapi/linux/elf-em.h +++ b/include/uapi/linux/elf-em.h @@ -26,6 +26,7 @@ #define EM_ARM 40 /* ARM 32 bit */ #define EM_SH 42 /* SuperH */ #define EM_SPARCV9 43 /* SPARC v9 64-bit */ +#define EM_ARC 45 /* Argonaut RISC Core */ #define EM_H8_300 46 /* Renesas H8/300 */ #define EM_IA_64 50 /* HP/Intel IA-64 */ #define EM_X86_64 62 /* AMD x86-64 */ -- ldv ___ linux-snps-arc mailing list linux-snps-arc@lists.infradead.org http://lists.infradead.org/mailman/listinfo/linux-snps-arc
[PATCH 06/13] arc: define syscall_get_arch()
syscall_get_arch() is required to be implemented on all architectures that use tracehook_report_syscall_entry() in order to extend the generic ptrace API with PTRACE_GET_SYSCALL_INFO request. Signed-off-by: Dmitry V. Levin --- arch/arc/include/asm/syscall.h | 6 ++ include/uapi/linux/audit.h | 1 + 2 files changed, 7 insertions(+) diff --git a/arch/arc/include/asm/syscall.h b/arch/arc/include/asm/syscall.h index 29de09804306..5662778a7411 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,9 @@ syscall_get_arguments(struct task_struct *task, struct pt_regs *regs, } } +static inline int syscall_get_arch(void) +{ + return AUDIT_ARCH_ARC; +} + #endif diff --git a/include/uapi/linux/audit.h b/include/uapi/linux/audit.h index 818ae690ab79..a7149ceb5b98 100644 --- a/include/uapi/linux/audit.h +++ b/include/uapi/linux/audit.h @@ -375,6 +375,7 @@ 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_ARC (EM_ARC) #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 ___ linux-snps-arc mailing list linux-snps-arc@lists.infradead.org http://lists.infradead.org/mailman/listinfo/linux-snps-arc
Re: [PATCH 02/13] elf-em.h: add EM_ARC
On Fri, Nov 09, 2018 at 04:41:36PM +, Vineet Gupta wrote: > On 11/8/18 7:15 PM, Dmitry V. Levin wrote: > > The uapi/linux/audit.h header is going to use EM_ARC in order > > to define AUDIT_ARCH_ARC 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_ARC has been taken from > > https://urldefense.proofpoint.com/v2/url?u=http-3A__www.sco.com_developers_gabi_2012-2D12-2D31_ch4.eheader.html&d=DwIBAg&c=DPL6_X_6JkXFx7AXWqB0tg&r=c14YS-cH-kdhTOW89KozFhBtBJgs1zXscZojEZQ0THs&m=UCr-dDO1BWV4K-CXhpcDRnN4Urr4_UgSKBeEaczUAmE&s=XmSWUKeqq324aU46NSTbHc12dH-1vVnA4G3Rm-01WD4&e= > > > > Signed-off-by: Dmitry V. Levin > > --- > > 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 ba3696e3d694..56ff3f9d9633 100644 > > --- a/include/uapi/linux/elf-em.h > > +++ b/include/uapi/linux/elf-em.h > > @@ -26,6 +26,7 @@ > > #define EM_ARM 40 /* ARM 32 bit */ > > #define EM_SH 42 /* SuperH */ > > #define EM_SPARCV9 43 /* SPARC v9 64-bit */ > > +#define EM_ARC 45 /* Argonaut RISC Core */ > > Please use EM_ARCOMPACT (for original ARC ISA) and EM_ARCV2 - both defined in > arch/arc/include/asm/elf.h OK, but we would have to move both EM_ARCOMPACT and EM_ARCV2 to include/uapi/linux/elf-em.h file first, so they could be used to define AUDIT_ARCH_* constants in include/uapi/linux/audit.h file. -- ldv signature.asc Description: PGP signature ___ linux-snps-arc mailing list linux-snps-arc@lists.infradead.org http://lists.infradead.org/mailman/listinfo/linux-snps-arc
[PATCH 02/13 v2] 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. Signed-off-by: Dmitry V. Levin --- v2: do not add EM_ARC, move EM_ARCOMPACT and EM_ARCV2 instead. 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 ba3696e3d694..91b33833630b 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 */ @@ -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_FRV 0x5441 /* Fujitsu FR-V */ -- ldv ___ linux-snps-arc mailing list linux-snps-arc@lists.infradead.org http://lists.infradead.org/mailman/listinfo/linux-snps-arc
[PATCH 06/13 v2] arc: define syscall_get_arch()
syscall_get_arch() is required to be implemented on all architectures that use tracehook_report_syscall_entry() in order to extend the generic ptrace API with PTRACE_GET_SYSCALL_INFO request. Signed-off-by: Dmitry V. Levin --- v2: define AUDIT_ARCH_ARCOMPACT, AUDIT_ARCH_ARCOMPACTLE, AUDIT_ARCH_ARCV2, and AUDIT_ARCH_ARCV2LE instead of AUDIT_ARCH_ARC, update syscall_get_arch() implementation accordingly. arch/arc/include/asm/syscall.h | 18 ++ include/uapi/linux/audit.h | 4 2 files changed, 22 insertions(+) diff --git a/arch/arc/include/asm/syscall.h b/arch/arc/include/asm/syscall.h index 29de09804306..a1b698290778 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,21 @@ syscall_get_arguments(struct task_struct *task, struct pt_regs *regs, } } +static inline int syscall_get_arch(void) +{ +#ifdef CONFIG_ISA_ARCOMPACT +# ifdef CONFIG_CPU_BIG_ENDIAN + return AUDIT_ARCH_ARCOMPACT; +# else + return AUDIT_ARCH_ARCOMPACTLE; +# endif +#else /* CONFIG_ISA_ARCV2 */ +# ifdef CONFIG_CPU_BIG_ENDIAN + return AUDIT_ARCH_ARCV2; +# else + return AUDIT_ARCH_ARCV2LE; +# endif +#endif +} + #endif diff --git a/include/uapi/linux/audit.h b/include/uapi/linux/audit.h index 818ae690ab79..8e70fb70b8f8 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) +#define AUDIT_ARCH_ARCOMPACTLE (EM_ARCOMPACT|__AUDIT_ARCH_LE) +#define AUDIT_ARCH_ARCV2 (EM_ARCV2) +#define AUDIT_ARCH_ARCV2LE (EM_ARCV2|__AUDIT_ARCH_LE) #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 ___ linux-snps-arc mailing list linux-snps-arc@lists.infradead.org http://lists.infradead.org/mailman/listinfo/linux-snps-arc
[PATCH 06/13 v3] arc: define syscall_get_arch()
syscall_get_arch() is required to be implemented on all architectures that use tracehook_report_syscall_entry() in order to extend the generic ptrace API with PTRACE_GET_SYSCALL_INFO request. Signed-off-by: Dmitry V. Levin --- v3: replaced #ifdefs with IS_ENABLED, made LE as default, added BE suffixes variants v2: defined AUDIT_ARCH_ARCOMPACT, AUDIT_ARCH_ARCOMPACTLE, AUDIT_ARCH_ARCV2, and AUDIT_ARCH_ARCV2LE instead of AUDIT_ARCH_ARC, updated syscall_get_arch() implementation accordingly. arch/arc/include/asm/syscall.h | 10 ++ include/uapi/linux/audit.h | 4 2 files changed, 14 insertions(+) diff --git a/arch/arc/include/asm/syscall.h b/arch/arc/include/asm/syscall.h index 29de09804306..10b2e7523bc8 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,13 @@ 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 ___ linux-snps-arc mailing list linux-snps-arc@lists.infradead.org http://lists.infradead.org/mailman/listinfo/linux-snps-arc
[PATCH v2 00/15] Prepare for PTRACE_GET_SYSCALL_INFO
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. The primary intent is that the triple (audit_arch, syscall_nr, arg1..arg6) should describe what system call is being called and what its arguments are. Dmitry V. Levin (15): Move EM_HEXAGON to uapi/linux/elf-em.h Move EM_ARCOMPACT and EM_ARCV2 to uapi/linux/elf-em.h Move EM_UNICORE to uapi/linux/elf-em.h elf-em.h: add EM_NDS32 elf-em.h: add EM_XTENSA m68k: define syscall_get_arch() arc: define syscall_get_arch() c6x: define syscall_get_arch() h8300: define syscall_get_arch() hexagon: define syscall_get_arch() nds32: define syscall_get_arch() nios2: define syscall_get_arch() riscv: define syscall_get_arch() unicore32: define syscall_get_arch() xtensa: define syscall_get_arch() arch/arc/include/asm/elf.h | 6 +- arch/arc/include/asm/syscall.h | 10 ++ arch/c6x/include/asm/syscall.h | 7 +++ arch/h8300/include/asm/syscall.h | 5 + arch/hexagon/include/asm/elf.h | 6 +- arch/hexagon/include/asm/syscall.h | 8 arch/m68k/include/asm/syscall.h | 12 arch/nds32/include/asm/syscall.h | 8 arch/nios2/include/asm/syscall.h | 6 ++ arch/riscv/include/asm/syscall.h | 10 ++ arch/unicore32/include/asm/elf.h | 3 +-- arch/unicore32/include/asm/syscall.h | 12 arch/xtensa/include/asm/syscall.h| 7 +++ include/uapi/linux/audit.h | 15 +++ include/uapi/linux/elf-em.h | 7 +++ 15 files changed, 110 insertions(+), 12 deletions(-) create mode 100644 arch/m68k/include/asm/syscall.h create mode 100644 arch/unicore32/include/asm/syscall.h -- ldv ___ linux-snps-arc mailing list linux-snps-arc@lists.infradead.org http://lists.infradead.org/mailman/listinfo/linux-snps-arc
[PATCH v2 02/15] 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. Signed-off-by: Dmitry V. Levin Acked-by: Vineet Gupta --- v2: added Acked-by to [PATCH 02/13 v2] 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 ba3696e3d694..91b33833630b 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 */ @@ -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_FRV 0x5441 /* Fujitsu FR-V */ -- ldv ___ linux-snps-arc mailing list linux-snps-arc@lists.infradead.org http://lists.infradead.org/mailman/listinfo/linux-snps-arc
[PATCH v2 07/15] arc: 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. Signed-off-by: Dmitry V. Levin Acked-by: Vineet Gupta --- v2: added Acked-by to [PATCH 06/13 v3] arch/arc/include/asm/syscall.h | 10 ++ include/uapi/linux/audit.h | 4 2 files changed, 14 insertions(+) diff --git a/arch/arc/include/asm/syscall.h b/arch/arc/include/asm/syscall.h index 29de09804306..10b2e7523bc8 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,13 @@ 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 ___ linux-snps-arc mailing list linux-snps-arc@lists.infradead.org http://lists.infradead.org/mailman/listinfo/linux-snps-arc
[PATCH v2 16/15] 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 other syscall_get_* functions with a tracee as their argument. This change partially reverts commit 5e937a9ae913 ("syscall_get_arch: remove useless function arguments"). Cc: linux-al...@vger.kernel.org Cc: linux-a...@vger.kernel.org Cc: linux-arm-ker...@lists.infradead.org Cc: linux-au...@redhat.com Cc: linux-c6x-...@linux-c6x.org Cc: linux-hexa...@vger.kernel.org Cc: linux-i...@vger.kernel.org Cc: linux-m...@lists.linux-m68k.org Cc: linux-m...@linux-mips.org Cc: linux-par...@vger.kernel.org Cc: linux-ri...@lists.infradead.org Cc: linux-s...@vger.kernel.org Cc: linux...@vger.kernel.org Cc: linux-snps-arc@lists.infradead.org Cc: linux...@lists.infradead.org Cc: linux-xte...@linux-xtensa.org Cc: linuxppc-...@lists.ozlabs.org Cc: nios2-...@lists.rocketboards.org Cc: openr...@lists.librecores.org Cc: sparcli...@vger.kernel.org Cc: uclinux-h8-de...@lists.sourceforge.jp Cc: x...@kernel.org Signed-off-by: Dmitry V. Levin --- 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/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 | 8 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 | 3 ++- kernel/auditsc.c | 4 ++-- kernel/seccomp.c | 4 ++-- 29 files changed, 51 insertions(+), 41 deletions(-) diff --git a/arch/alpha/include/asm/syscall.h b/arch/alpha/include/asm/syscall.h index d73a6fcb519c..11c688c1d7ec 100644 --- a/arch/alpha/include/asm/syscall.h +++ b/arch/alpha/include/asm/syscall.h @@ -4,7 +4,7 @@ #include -static inline int syscall_get_arch(void) +static inline int 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 10b2e7523bc8..7834baa61de8 100644 --- a/arch/arc/include/asm/syscall.h +++ b/arch/arc/include/asm/syscall.h @@ -69,7 +69,7 @@ syscall_get_arguments(struct task_struct *task, struct pt_regs *regs, } } -static inline int syscall_get_arch(void) +static inline int 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 --- a/arch/arm/include/asm/syscall.h +++ b/arch/arm/include/asm/syscall.h @@ -104,7 +104,7 @@ static inline void syscall_set_arguments(struct task_struct *task, memcpy(®s->ARM_r0 + i, args, n * sizeof(args[0])); } -static inline int syscall_get_arch(void) +static inline int syscall_get_arch(struct task_struct *task) { /* ARM tasks don't change audit architectures on the fly. */ return AUDIT_ARCH_ARM; diff --git a/arch/arm64/include/asm/syscall.h b/arch/arm64/include/asm/syscall.h index ad8be16a39c9..1870df03f774 100644 --- a/arch/arm64/include/asm/syscall.h +++ b/arch/arm64/include/asm/syscall.h @@ -117,9 +117,9 @@ static inline void syscall_set_arguments(struct task_struct *task, * We don't care about endianness (__AUDIT_ARCH_LE bit) here because * AArch64 has the same system calls both on little- and big- endian. */ -static inline int syscall_get_arch(void) +static inline int syscall_get_arch(struct task_struct *task) { - if (is_compat_task()) + if (is_compat_thread(task_thread_info(task))) return AUDIT_ARCH_ARM; return AUDIT_ARCH_AARCH64; diff --git a/arch/c6x/include/asm/syscall.h b/arch/c6x/include/asm/syscall.h index 39dbd1ef994c..595057191c9c 100644 --- a/arch/c6x/include/asm/syscall.h +++ b/arch/c6x/include/asm/syscall.h @@ -121,7 +121,7 @@ static inline void syscall_set_arguments(struct task_struct *task, }
Re: [PATCH v2 16/15] syscall_get_arch: add "struct task_struct *" argument
Hi Paul, On Wed, Nov 21, 2018 at 06:40:06PM +, Paul Burton wrote: > Hi Dmitry, > > On Wed, Nov 21, 2018 at 03:44:22AM +0300, Dmitry V. Levin wrote: > > 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 other syscall_get_* functions > > with a tracee as their argument. > > > > This change partially reverts commit 5e937a9ae913 ("syscall_get_arch: > > remove useless function arguments"). > > > >% > > > > diff --git a/arch/mips/include/asm/syscall.h > > b/arch/mips/include/asm/syscall.h > > index 0170602a1e4e..52b633f20abd 100644 > > --- a/arch/mips/include/asm/syscall.h > > +++ b/arch/mips/include/asm/syscall.h > > @@ -73,7 +73,7 @@ static inline unsigned long mips_get_syscall_arg(unsigned > > long *arg, > > #ifdef CONFIG_64BIT > > case 4: case 5: case 6: case 7: > > #ifdef CONFIG_MIPS32_O32 > > - if (test_thread_flag(TIF_32BIT_REGS)) > > + if (test_ti_thread_flag(task_thread_info(task), TIF_32BIT_REGS)) > > return get_user(*arg, (int *)usp + n); > > else > > #endif > > This ought to be test_tsk_thread_flag(task, TIF_32BIT_REGS) instead of > open-coding test_tsk_thread_flag. This will be corrected, thanks for letting me know. > More fundamentally though, this change doesn't seem to be (directly) > related to the change you describe in the commit message - it's not > syscall_get_arch being modified here. I suspect this should be a > separate commit, or if not please explain in the commit message why this > change is included. Good point, this is a fix that should not have been included into this commit. The bug was found while preparing the syscall_get_arch change, and this hunk just slipped in. I'll send it as a separate commit. > Compounding the lack of clarity is the fact that I only received this > patch, not the whole series, so I can't view the change in the context > of the rest of the series. > > > @@ -140,14 +140,14 @@ extern const unsigned long sys_call_table[]; > > extern const unsigned long sys32_call_table[]; > > extern const unsigned long sysn32_call_table[]; > > > > -static inline int syscall_get_arch(void) > > +static inline int syscall_get_arch(struct task_struct *task) > > { > > int arch = AUDIT_ARCH_MIPS; > > #ifdef CONFIG_64BIT > > - if (!test_thread_flag(TIF_32BIT_REGS)) { > > + if (!test_ti_thread_flag(task_thread_info(task), TIF_32BIT_REGS)) { > > arch |= __AUDIT_ARCH_64BIT; > > /* N32 sets only TIF_32BIT_ADDR */ > > - if (test_thread_flag(TIF_32BIT_ADDR)) > > + if (test_ti_thread_flag(task_thread_info(task), TIF_32BIT_ADDR)) > > arch |= __AUDIT_ARCH_CONVENTION_MIPS64_N32; > > } > > #endif > > This does seem like the described change, but there are 2 more instances > of open-coding test_tsk_thread_flag which ought to be cleaned up. This will be cleaned up, thanks for letting me know. -- ldv signature.asc Description: PGP signature ___ linux-snps-arc mailing list linux-snps-arc@lists.infradead.org http://lists.infradead.org/mailman/listinfo/linux-snps-arc
[PATCH v2 16/15 v2] 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 other syscall_get_* functions with a tracee as their argument. This change partially reverts commit 5e937a9ae913 ("syscall_get_arch: remove useless function arguments"). Reviewed-by: Andy Lutomirski # for x86 Reviewed-by: Palmer Dabbelt Cc: linux-au...@redhat.com Cc: linux-al...@vger.kernel.org Cc: linux-a...@vger.kernel.org Cc: linux-arm-ker...@lists.infradead.org Cc: linux-c6x-...@linux-c6x.org Cc: linux-hexa...@vger.kernel.org Cc: linux-i...@vger.kernel.org Cc: linux-m...@lists.linux-m68k.org Cc: linux-m...@linux-mips.org Cc: linux-par...@vger.kernel.org Cc: linux-ri...@lists.infradead.org Cc: linux-s...@vger.kernel.org Cc: linux...@vger.kernel.org Cc: linux-snps-arc@lists.infradead.org Cc: linux...@lists.infradead.org Cc: linux-xte...@linux-xtensa.org Cc: linuxppc-...@lists.ozlabs.org Cc: nios2-...@lists.rocketboards.org Cc: openr...@lists.librecores.org Cc: sparcli...@vger.kernel.org Cc: uclinux-h8-de...@lists.sourceforge.jp Cc: x...@kernel.org Signed-off-by: Dmitry V. Levin --- 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/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 | 3 ++- kernel/auditsc.c | 4 ++-- kernel/seccomp.c | 4 ++-- 29 files changed, 50 insertions(+), 40 deletions(-) diff --git a/arch/alpha/include/asm/syscall.h b/arch/alpha/include/asm/syscall.h index d73a6fcb519c..11c688c1d7ec 100644 --- a/arch/alpha/include/asm/syscall.h +++ b/arch/alpha/include/asm/syscall.h @@ -4,7 +4,7 @@ #include -static inline int syscall_get_arch(void) +static inline int 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 10b2e7523bc8..7834baa61de8 100644 --- a/arch/arc/include/asm/syscall.h +++ b/arch/arc/include/asm/syscall.h @@ -69,7 +69,7 @@ syscall_get_arguments(struct task_struct *task, struct pt_regs *regs, } } -static inline int syscall_get_arch(void) +static inline int 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 --- a/arch/arm/include/asm/syscall.h +++ b/arch/arm/include/asm/syscall.h @@ -104,7 +104,7 @@ static inline void syscall_set_arguments(struct task_struct *task, memcpy(®s->ARM_r0 + i, args, n * sizeof(args[0])); } -static inline int syscall_get_arch(void) +static inline int syscall_get_arch(struct task_struct *task) { /* ARM tasks don't change audit architectures on the fly. */ return AUDIT_ARCH_ARM; diff --git a/arch/arm64/include/asm/syscall.h b/arch/arm64/include/asm/syscall.h index ad8be16a39c9..1870df03f774 100644 --- a/arch/arm64/include/asm/syscall.h +++ b/arch/arm64/include/asm/syscall.h @@ -117,9 +117,9 @@ static inline void syscall_set_arguments(struct task_struct *task, * We don't care about endianness (__AUDIT_ARCH_LE bit) here because * AArch64 has the same system calls both on little- and big- endian. */ -static inline int syscall_get_arch(void) +static inline int syscall_get_arch(struct task_struct *task) { - if (is_compat_task()) + if (is_compat_thread(task_thread_info(task))) return AUDIT_ARCH_ARM; return AUDIT_ARCH_AARCH64; diff --git a/arch/c6x/include/asm/syscall.h b/arch/c6x/include/asm/syscall.h index 39dbd1ef994c..595057191c9c 100644 --- a/arch/c6x/include/asm/syscall.h +++ b/arch/c6x/include/
[PATCH v5 00/25] ptrace: add PTRACE_GET_SYSCALL_INFO request
E_SYSCALL_INFO_{ENTRY,EXIT} and ptrace_syscall_info.{entry,exit}. v3: * Change struct ptrace_syscall_info. * Support PTRACE_EVENT_SECCOMP by adding ptrace_event to task_struct. * Add proper defines for ptrace_syscall_info.op values. * Rename PT_SYSCALL_IS_ENTERING and PT_SYSCALL_IS_EXITING to PTRACE_EVENTMSG_SYSCALL_ENTRY and PTRACE_EVENTMSG_SYSCALL_EXIT * and move them to uapi. v2: * Do not use task->ptrace. * Replace entry_info.is_compat with entry_info.arch, use syscall_get_arch(). * Use addr argument of sys_ptrace to get expected size of the struct; return full size of the struct. Dmitry V. Levin (23): alpha: define remaining syscall_get_* functions Move EM_ARCOMPACT and EM_ARCV2 to uapi/linux/elf-em.h arc: define syscall_get_arch() c6x: define syscall_get_arch() elf-em.h: add EM_CSKY csky: define syscall_get_arch() h8300: define remaining syscall_get_* functions Move EM_HEXAGON to uapi/linux/elf-em.h hexagon: define remaining syscall_get_* functions Move EM_NDS32 to uapi/linux/elf-em.h nds32: define syscall_get_arch() nios2: define syscall_get_arch() m68k: add asm/syscall.h mips: define syscall_get_error() parisc: define syscall_get_error() powerpc: define syscall_get_error() riscv: define syscall_get_arch() Move EM_XTENSA to uapi/linux/elf-em.h xtensa: define syscall_get_* functions Move EM_UNICORE to uapi/linux/elf-em.h unicore32: add asm/syscall.h syscall_get_arch: add "struct task_struct *" argument selftests/ptrace: add a test case for PTRACE_GET_SYSCALL_INFO Elvira Khabirova (2): powerpc/ptrace: replace ptrace_report_syscall() with a tracehook call ptrace: add PTRACE_GET_SYSCALL_INFO request arch/alpha/include/asm/syscall.h | 29 +- arch/arc/include/asm/elf.h| 6 +- arch/arc/include/asm/syscall.h| 11 + arch/arm/include/asm/syscall.h| 2 +- arch/arm64/include/asm/syscall.h | 4 +- arch/c6x/include/asm/syscall.h| 7 + arch/csky/include/asm/syscall.h | 7 + arch/h8300/include/asm/syscall.h | 18 ++ arch/hexagon/include/asm/elf.h| 6 +- arch/hexagon/include/asm/syscall.h| 20 ++ arch/ia64/include/asm/syscall.h | 2 +- arch/m68k/include/asm/syscall.h | 39 +++ arch/microblaze/include/asm/syscall.h | 2 +- arch/mips/include/asm/syscall.h | 12 +- arch/mips/kernel/ptrace.c | 2 +- arch/nds32/include/asm/elf.h | 3 +- arch/nds32/include/asm/syscall.h | 8 + arch/nios2/include/asm/syscall.h | 6 + arch/openrisc/include/asm/syscall.h | 2 +- arch/parisc/include/asm/syscall.h | 11 +- arch/powerpc/include/asm/syscall.h| 20 +- arch/powerpc/kernel/ptrace.c | 7 +- arch/riscv/include/asm/syscall.h | 10 + arch/s390/include/asm/syscall.h | 4 +- arch/sh/include/asm/syscall_32.h | 2 +- arch/sh/include/asm/syscall_64.h | 2 +- arch/sparc/include/asm/syscall.h | 5 +- arch/unicore32/include/asm/elf.h | 3 +- arch/unicore32/include/asm/syscall.h | 45 +++ arch/x86/include/asm/syscall.h| 8 +- arch/x86/um/asm/syscall.h | 2 +- arch/xtensa/include/asm/elf.h | 2 +- arch/xtensa/include/asm/syscall.h | 69 + include/asm-generic/syscall.h | 5 +- include/linux/tracehook.h | 9 +- include/uapi/linux/audit.h| 16 ++ include/uapi/linux/elf-em.h | 8 + include/uapi/linux/ptrace.h | 39 +++ kernel/auditsc.c | 4 +- kernel/ptrace.c | 99 ++- kernel/seccomp.c | 4 +- tools/testing/selftests/ptrace/.gitignore | 1 + tools/testing/selftests/ptrace/Makefile | 2 +- .../selftests/ptrace/get_syscall_info.c | 272 ++ 44 files changed, 783 insertions(+), 52 deletions(-) create mode 100644 arch/m68k/include/asm/syscall.h create mode 100644 arch/unicore32/include/asm/syscall.h create mode 100644 tools/testing/selftests/ptrace/get_syscall_info.c -- ldv ___ linux-snps-arc mailing list linux-snps-arc@lists.infradead.org http://lists.infradead.org/mailman/listinfo/linux-snps-arc
[PATCH v5 02/25] 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-arc@lists.infradead.org Signed-off-by: Dmitry V. Levin --- Notes: 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 ___ linux-snps-arc mailing list linux-snps-arc@lists.infradead.org http://lists.infradead.org/mailman/listinfo/linux-snps-arc
[PATCH v5 03/25] 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-arc@lists.infradead.org Cc: linux-au...@redhat.com Signed-off-by: Dmitry V. Levin --- Notes: 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 ___ linux-snps-arc mailing list linux-snps-arc@lists.infradead.org http://lists.infradead.org/mailman/listinfo/linux-snps-arc
[PATCH v5 22/25] 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) 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: Mark Salter 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: Kees Cook 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-arc@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: v5: fixed asm-generic docs by reverting 1002d94d3076, 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 437758bdc49f..288779aa9847 100644 --- a/arch/alpha/include/asm/syscall.h +++ b/arch/alpha/include/asm/syscall.h @@ -31,7 +31,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 --- a/arch/arm/include/asm/
[PATCH v6 00/27] ptrace: add PTRACE_GET_SYSCALL_INFO request
OK since all syscall_get_* functions are implemented on all architectures. * Add a test for PTRACE_GET_SYSCALL_INFO to selftests/ptrace. v4: * Do not introduce task_struct.ptrace_event, use child->last_siginfo->si_code instead. * Implement PTRACE_SYSCALL_INFO_SECCOMP and ptrace_syscall_info.seccomp support along with PTRACE_SYSCALL_INFO_{ENTRY,EXIT} and ptrace_syscall_info.{entry,exit}. v3: * Change struct ptrace_syscall_info. * Support PTRACE_EVENT_SECCOMP by adding ptrace_event to task_struct. * Add proper defines for ptrace_syscall_info.op values. * Rename PT_SYSCALL_IS_ENTERING and PT_SYSCALL_IS_EXITING to PTRACE_EVENTMSG_SYSCALL_ENTRY and PTRACE_EVENTMSG_SYSCALL_EXIT * and move them to uapi. v2: * Do not use task->ptrace. * Replace entry_info.is_compat with entry_info.arch, use syscall_get_arch(). * Use addr argument of sys_ptrace to get expected size of the struct; return full size of the struct. Dmitry V. Levin (25): asm-generic/syscall.h: prepare for inclusion by other files asm-generic/syscall.h: turn syscall_[gs]et_arguments into wrappers alpha: define remaining syscall_get_* functions Move EM_ARCOMPACT and EM_ARCV2 to uapi/linux/elf-em.h arc: define syscall_get_arch() c6x: define syscall_get_arch() elf-em.h: add EM_CSKY csky: define syscall_get_arch() h8300: define remaining syscall_get_* functions Move EM_HEXAGON to uapi/linux/elf-em.h hexagon: define remaining syscall_get_* functions Move EM_NDS32 to uapi/linux/elf-em.h nds32: define syscall_get_arch() nios2: define syscall_get_arch() m68k: add asm/syscall.h mips: define syscall_get_error() parisc: define syscall_get_error() powerpc: define syscall_get_error() riscv: define syscall_get_arch() Move EM_XTENSA to uapi/linux/elf-em.h xtensa: define syscall_get_* functions Move EM_UNICORE to uapi/linux/elf-em.h unicore32: add asm/syscall.h syscall_get_arch: add "struct task_struct *" argument selftests/ptrace: add a test case for PTRACE_GET_SYSCALL_INFO Elvira Khabirova (2): powerpc/ptrace: replace ptrace_report_syscall() with a tracehook call ptrace: add PTRACE_GET_SYSCALL_INFO request arch/alpha/include/asm/syscall.h | 31 +- arch/arc/include/asm/elf.h| 6 +- arch/arc/include/asm/syscall.h| 11 + arch/arm/include/asm/syscall.h| 2 +- arch/arm64/include/asm/syscall.h | 4 +- arch/c6x/include/asm/syscall.h| 7 + arch/csky/include/asm/syscall.h | 7 + arch/h8300/include/asm/syscall.h | 19 ++ arch/hexagon/include/asm/elf.h| 6 +- arch/hexagon/include/asm/syscall.h| 22 ++ arch/ia64/include/asm/syscall.h | 2 +- arch/m68k/include/asm/syscall.h | 42 +++ arch/microblaze/include/asm/syscall.h | 2 +- arch/mips/include/asm/syscall.h | 12 +- arch/mips/kernel/ptrace.c | 2 +- arch/nds32/include/asm/elf.h | 3 +- arch/nds32/include/asm/syscall.h | 8 + arch/nios2/include/asm/syscall.h | 6 + arch/openrisc/include/asm/syscall.h | 2 +- arch/parisc/include/asm/syscall.h | 11 +- arch/powerpc/include/asm/syscall.h| 20 +- arch/powerpc/kernel/ptrace.c | 7 +- arch/riscv/include/asm/syscall.h | 10 + arch/s390/include/asm/syscall.h | 4 +- arch/sh/include/asm/syscall_32.h | 2 +- arch/sh/include/asm/syscall_64.h | 2 +- arch/sparc/include/asm/syscall.h | 5 +- arch/unicore32/include/asm/elf.h | 3 +- arch/unicore32/include/asm/syscall.h | 46 +++ arch/x86/include/asm/syscall.h| 8 +- arch/x86/um/asm/syscall.h | 2 +- arch/xtensa/include/asm/elf.h | 2 +- arch/xtensa/include/asm/syscall.h | 65 + include/asm-generic/syscall.h | 85 -- include/linux/tracehook.h | 9 +- include/uapi/linux/audit.h| 16 ++ include/uapi/linux/elf-em.h | 8 + include/uapi/linux/ptrace.h | 35 +++ kernel/auditsc.c | 4 +- kernel/ptrace.c | 101 ++- kernel/seccomp.c | 4 +- tools/testing/selftests/ptrace/.gitignore | 1 + tools/testing/selftests/ptrace/Makefile | 2 +- .../selftests/ptrace/get_syscall_info.c | 271 ++ 44 files changed, 851 insertions(+), 66 deletions(-) create mode 100644 arch/m68k/include/asm/syscall.h create mode 100644 arch/unicore32/include/asm/syscall.h create mode 100644 tools/testing/
[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-arc@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 ___ linux-snps-arc mailing list linux-snps-arc@lists.infradead.org http://lists.infradead.org/mailman/listinfo/linux-snps-arc
[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-arc@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 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-arc@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 ___ linux-snps-arc mailing list linux-snps-arc@lists.infradead.org http://lists.infradead.org/mailman/listinfo/linux-snps-arc
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-arc@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 ___ linux-snps-arc mailing list linux-snps-arc@lists.infradead.org http://lists.infradead.org/mailman/listinfo/linux-snps-arc
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-arc@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 ___ linux-snps-arc mailing list linux-snps-arc@lists.infradead.org http://lists.infradead.org/mailman/listinfo/linux-snps-arc
[PATCH v7 00/22] ptrace: add PTRACE_GET_SYSCALL_INFO request
* Make available for all architectures: do not conditionalize on CONFIG_HAVE_ARCH_TRACEHOOK since all syscall_get_* functions are implemented on all architectures. * Add a test for PTRACE_GET_SYSCALL_INFO to selftests/ptrace. v4: * Do not introduce task_struct.ptrace_event, use child->last_siginfo->si_code instead. * Implement PTRACE_SYSCALL_INFO_SECCOMP and ptrace_syscall_info.seccomp support along with PTRACE_SYSCALL_INFO_{ENTRY,EXIT} and ptrace_syscall_info.{entry,exit}. v3: * Change struct ptrace_syscall_info. * Support PTRACE_EVENT_SECCOMP by adding ptrace_event to task_struct. * Add proper defines for ptrace_syscall_info.op values. * Rename PT_SYSCALL_IS_ENTERING and PT_SYSCALL_IS_EXITING to PTRACE_EVENTMSG_SYSCALL_ENTRY and PTRACE_EVENTMSG_SYSCALL_EXIT * and move them to uapi. v2: * Do not use task->ptrace. * Replace entry_info.is_compat with entry_info.arch, use syscall_get_arch(). * Use addr argument of sys_ptrace to get expected size of the struct; return full size of the struct. Dmitry V. Levin (21): asm-generic/syscall.h: prepare for inclusion by other files asm-generic/syscall.h: turn syscall_[gs]et_arguments into wrappers alpha: define remaining syscall_get_* functions Move EM_ARCOMPACT and EM_ARCV2 to uapi/linux/elf-em.h arc: define syscall_get_arch() c6x: define syscall_get_arch() h8300: define remaining syscall_get_* functions Move EM_HEXAGON to uapi/linux/elf-em.h hexagon: define remaining syscall_get_* functions Move EM_NDS32 to uapi/linux/elf-em.h nds32: define syscall_get_arch() nios2: define syscall_get_arch() m68k: add asm/syscall.h mips: define syscall_get_error() parisc: define syscall_get_error() powerpc: define syscall_get_error() riscv: define syscall_get_arch() Move EM_UNICORE to uapi/linux/elf-em.h unicore32: add asm/syscall.h syscall_get_arch: add "struct task_struct *" argument selftests/ptrace: add a test case for PTRACE_GET_SYSCALL_INFO Elvira Khabirova (1): ptrace: add PTRACE_GET_SYSCALL_INFO request arch/alpha/include/asm/syscall.h | 31 +- arch/arc/include/asm/elf.h| 6 +- arch/arc/include/asm/syscall.h| 11 + arch/arm/include/asm/syscall.h| 2 +- arch/arm64/include/asm/syscall.h | 4 +- arch/c6x/include/asm/syscall.h| 7 + arch/csky/include/asm/syscall.h | 2 +- arch/h8300/include/asm/syscall.h | 19 ++ arch/hexagon/include/asm/elf.h| 6 +- arch/hexagon/include/asm/syscall.h| 22 ++ arch/ia64/include/asm/syscall.h | 2 +- arch/m68k/include/asm/syscall.h | 42 +++ arch/microblaze/include/asm/syscall.h | 2 +- arch/mips/include/asm/syscall.h | 12 +- arch/mips/kernel/ptrace.c | 2 +- arch/nds32/include/asm/elf.h | 3 +- arch/nds32/include/asm/syscall.h | 8 + arch/nios2/include/asm/syscall.h | 6 + arch/openrisc/include/asm/syscall.h | 2 +- arch/parisc/include/asm/syscall.h | 11 +- arch/powerpc/include/asm/syscall.h| 20 +- arch/riscv/include/asm/syscall.h | 10 + arch/s390/include/asm/syscall.h | 4 +- arch/sh/include/asm/syscall_32.h | 2 +- arch/sh/include/asm/syscall_64.h | 2 +- arch/sparc/include/asm/syscall.h | 5 +- arch/unicore32/include/asm/elf.h | 3 +- arch/unicore32/include/asm/syscall.h | 47 +++ 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 | 85 -- include/linux/tracehook.h | 9 +- include/uapi/linux/audit.h| 14 + include/uapi/linux/elf-em.h | 6 + include/uapi/linux/ptrace.h | 35 +++ kernel/auditsc.c | 4 +- kernel/ptrace.c | 101 ++- kernel/seccomp.c | 4 +- tools/testing/selftests/ptrace/.gitignore | 1 + tools/testing/selftests/ptrace/Makefile | 2 +- .../selftests/ptrace/get_syscall_info.c | 271 ++ 42 files changed, 771 insertions(+), 66 deletions(-) create mode 100644 arch/m68k/include/asm/syscall.h create mode 100644 arch/unicore32/include/asm/syscall.h create mode 100644 tools/testing/selftests/ptrace/get_syscall_info.c -- ldv ___ linux-snps-arc mailing list linux-snps-arc@lists.infradead.org http://lists.infradead.org/mailman/listinfo/linux-snps-arc
[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-arc@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 ___ linux-snps-arc mailing list linux-snps-arc@lists.infradead.org http://lists.infradead.org/mailman/listinfo/linux-snps-arc
[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-arc@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 ___ linux-snps-arc mailing list linux-snps-arc@lists.infradead.org http://lists.infradead.org/mailman/listinfo/linux-snps-arc
[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-arc@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 02/14] 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: Alexey Brodkin Cc: Oleg Nesterov Cc: Andy Lutomirski Cc: linux-snps-arc@lists.infradead.org Cc: linux-au...@redhat.com Signed-off-by: Dmitry V. Levin --- 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 ___ linux-snps-arc mailing list linux-snps-arc@lists.infradead.org http://lists.infradead.org/mailman/listinfo/linux-snps-arc
[PATCH 01/14] 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 Acked-by: Paul Moore Cc: Elvira Khabirova Cc: Eugene Syromyatnikov Cc: Alexey Brodkin Cc: Oleg Nesterov Cc: Andy Lutomirski Cc: linux-snps-arc@lists.infradead.org Cc: linux-au...@redhat.com Signed-off-by: Dmitry V. Levin --- 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 ___ linux-snps-arc mailing list linux-snps-arc@lists.infradead.org http://lists.infradead.org/mailman/listinfo/linux-snps-arc
[PATCH 14/14] 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. The primary intent is that the triple (audit_arch, syscall_nr, arg1..arg6) should describe what system call is being called and what its arguments are. 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 Moore 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: Elvira Khabirova Cc: Eugene Syromyatnikov Cc: Oleg Nesterov Cc: x...@kernel.org Cc: linux-al...@vger.kernel.org Cc: linux-snps-arc@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 --- 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 d73a6fcb519c..11c688c1d7ec 100644 --- a/arch/alpha/include/asm/syscall.h +++ b/arch/alpha/include/asm/syscall.h @@ -4,7 +4,7 @@ #include -static inline int syscall_get_arch(void) +static inline int 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 --- a/arch/arm/include/asm/syscall.h +++ b/arch/arm/include/asm/syscall.h @@ -104,7 +104,7 @@ static inline void syscall_set_arguments(struct task_struct *task, memcpy(®s->ARM_r0 + i, args, n * sizeof(args[0])); } -static inline int syscall_get_arch(void) +static inline int syscall_get_arch(struct task_struct *task) { /* ARM tasks don't change audit architectures on the fly. */ return AUDIT_ARCH_ARM; diff --git a/arch/arm64/include/asm/syscall.h b/arch/arm64/include/asm/syscall.h index ad8be16a39c9..1870df03f774 100644 --- a/arch/arm64/include/asm/syscall.h +++ b/arch/arm64/include/asm/syscall.h @@ -117,9 +117,9 @@ static inline void syscall_set_arguments(struct task_struct *task, * We don't care about endianness (__AUDIT_ARCH_LE bit) here because * AArch64 has the
[PATCH v2 01/13] 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 Acked-by: Paul Moore Cc: Elvira Khabirova Cc: Eugene Syromyatnikov Cc: Alexey Brodkin Cc: Oleg Nesterov Cc: Andy Lutomirski Cc: linux-snps-arc@lists.infradead.org Cc: linux-au...@redhat.com Signed-off-by: Dmitry V. Levin --- Notes: v2: unchanged 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 ___ linux-snps-arc mailing list linux-snps-arc@lists.infradead.org http://lists.infradead.org/mailman/listinfo/linux-snps-arc
[PATCH v2 02/13] 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: Alexey Brodkin Cc: Oleg Nesterov Cc: Andy Lutomirski Cc: linux-snps-arc@lists.infradead.org Cc: linux-au...@redhat.com Signed-off-by: Dmitry V. Levin --- Notes: v2: unchanged 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 f28acd952d03..1626727bb921 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 ___ linux-snps-arc mailing list linux-snps-arc@lists.infradead.org http://lists.infradead.org/mailman/listinfo/linux-snps-arc
[PATCH v2 13/13] 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. The primary intent is that the triple (audit_arch, syscall_nr, arg1..arg6) should describe what system call is being called and what its arguments are. 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 Moore 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: Elvira Khabirova Cc: Eugene Syromyatnikov Cc: Oleg Nesterov Cc: x...@kernel.org Cc: linux-al...@vger.kernel.org Cc: linux-snps-arc@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: v2: unchanged 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 d73a6fcb519c..11c688c1d7ec 100644 --- a/arch/alpha/include/asm/syscall.h +++ b/arch/alpha/include/asm/syscall.h @@ -4,7 +4,7 @@ #include -static inline int syscall_get_arch(void) +static inline int 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 --- a/arch/arm/include/asm/syscall.h +++ b/arch/arm/include/asm/syscall.h @@ -104,7 +104,7 @@ static inline void syscall_set_arguments(struct task_struct *task, memcpy(®s->ARM_r0 + i, args, n * sizeof(args[0])); } -static inline int syscall_get_arch(void) +static inline int syscall_get_arch(struct task_struct *task) { /* ARM tasks don't change audit architectures on the fly. */ return AUDIT_ARCH_ARM; diff --git a/arch/arm64/include/asm/syscall.h b/arch/arm64/include/asm/syscall.h index ad8be16a39c9..1870df03f774 100644 --- a/arch/arm64/include/asm/syscall.h +++ b/arch/arm64/include/asm/syscall.h @@ -117,9 +117,9 @@ static inline void syscall_set_arguments(struct task_struct *task, * We don't care about endianness (__AUDIT_ARCH_LE bit) here
Re: [PATCH 6/6 v3] syscalls: Remove start and number from syscall_set_arguments() args
On Mon, Apr 01, 2019 at 09:41:10AM -0400, Steven Rostedt wrote: > From: "Steven Rostedt (VMware)" > > After removing the start and count arguments of syscall_get_arguments() it > seems reasonable to remove them from syscall_set_arguments(). Note, as of > today, there are no users of syscall_set_arguments(). But we are told that > there will be soon. But for now, at least make it consistent with > syscall_get_arguments(). > > Link: http://lkml.kernel.org/r/20190327222014.ga32...@altlinux.org FWIW, you can add Reviewed-by: Dmitry V. Levin There are two places listed below where I'd prefer to see more readable equivalents, but feel free to leave it to respective arch maintainers. > diff --git a/arch/nds32/include/asm/syscall.h > b/arch/nds32/include/asm/syscall.h > index 89a6ec8731d8..671ebd357496 100644 > --- a/arch/nds32/include/asm/syscall.h > +++ b/arch/nds32/include/asm/syscall.h > @@ -129,39 +129,20 @@ void syscall_get_arguments(struct task_struct *task, > struct pt_regs *regs, > * syscall_set_arguments - change system call parameter value > * @task:task of interest, must be in system call entry tracing > * @regs:task_pt_regs() of @task > - * @i: argument index [0,5] > - * @n: number of arguments; n+i must be [1,6]. > * @args:array of argument values to store > * > - * Changes @n arguments to the system call starting with the @i'th argument. > - * Argument @i gets value @args[0], and so on. > - * An arch inline version is probably optimal when @i and @n are constants. > + * Changes 6 arguments to the system call. The first argument gets value > + * @args[0], and so on. > * > * 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. > - * 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) > { > - if (n == 0) > - return; > - > - if (i + n > SYSCALL_MAX_ARGS) { > - pr_warn("%s called with max args %d, handling only %d\n", > - __func__, i + n, SYSCALL_MAX_ARGS); > - n = SYSCALL_MAX_ARGS - i; > - } > - > - if (i == 0) { > - regs->orig_r0 = args[0]; > - args++; > - i++; > - n--; > - } > + regs->orig_r0 = args[0]; > + args++; > > - memcpy(®s->uregs[0] + i, args, n * sizeof(args[0])); > + memcpy(®s->uregs[0] + 1, args, 5 * sizeof(args[0])); > } A shorter and slightly more readable equivalent of the last memcpy is memcpy(®s->uregs[1], args, 5 * sizeof(args[0])); > diff --git a/arch/s390/include/asm/syscall.h b/arch/s390/include/asm/syscall.h > index ee0b1f6aa36d..59c3e91f2cdb 100644 > --- a/arch/s390/include/asm/syscall.h > +++ b/arch/s390/include/asm/syscall.h > @@ -74,15 +74,14 @@ static inline void syscall_get_arguments(struct > task_struct *task, > > static inline void syscall_set_arguments(struct task_struct *task, >struct pt_regs *regs, > - unsigned int i, unsigned int n, >const unsigned long *args) > { > - BUG_ON(i + n > 6); > + unsigned int n = 6; > + > while (n-- > 0) > - if (i + n > 0) > - regs->gprs[2 + i + n] = args[n]; > - if (i == 0) > - regs->orig_gpr2 = args[0]; > + if (n > 0) > + regs->gprs[2 + n] = args[n]; > + regs->orig_gpr2 = args[0]; > } A shorter and slightly more readable equivalent of the loop is while (--n > 0) regs->gprs[2 + n] = args[n]; -- ldv signature.asc Description: PGP signature ___ linux-snps-arc mailing list linux-snps-arc@lists.infradead.org http://lists.infradead.org/mailman/listinfo/linux-snps-arc
Re: [PATCH 5/6 v3] syscalls: Remove start and number from syscall_get_arguments() args
On Mon, Apr 01, 2019 at 09:41:09AM -0400, Steven Rostedt wrote: > From: "Steven Rostedt (Red Hat)" > > At Linux Plumbers, Andy Lutomirski approached me and pointed out that the > function call syscall_get_arguments() implemented in x86 was horribly > written and not optimized for the standard case of passing in 0 and 6 for > the starting index and the number of system calls to get. When looking at > all the users of this function, I discovered that all instances pass in only > 0 and 6 for these arguments. Instead of having this function handle > different cases that are never used, simply rewrite it to return the first 6 > arguments of a system call. > > This should help out the performance of tracing system calls by ptrace, > ftrace and perf. > > Link: http://lkml.kernel.org/r/20161107213233.754809...@goodmis.org FWIW, you can add Reviewed-by: Dmitry V. Levin There are several places listed below where I'd prefer to see more readable equivalents, but feel free to leave it to respective arch maintainers. > diff --git a/arch/hexagon/include/asm/syscall.h > b/arch/hexagon/include/asm/syscall.h > index 4af9c7b6f13a..ae3a1e24fabd 100644 > --- a/arch/hexagon/include/asm/syscall.h > +++ b/arch/hexagon/include/asm/syscall.h > @@ -37,10 +37,8 @@ static inline long syscall_get_nr(struct task_struct *task, > > 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); > - memcpy(args, &(®s->r00)[i], n * sizeof(args[0])); > + memcpy(args, &(®s->r00)[0], 6 * sizeof(args[0])); A shorter and slightly more readable equivalent is memcpy(args, ®s->r00, 6 * sizeof(args[0])); > diff --git a/arch/nds32/include/asm/syscall.h > b/arch/nds32/include/asm/syscall.h > index f7e5e86765fe..89a6ec8731d8 100644 > --- a/arch/nds32/include/asm/syscall.h > +++ b/arch/nds32/include/asm/syscall.h > @@ -108,42 +108,21 @@ void syscall_set_return_value(struct task_struct *task, > struct pt_regs *regs, > * syscall_get_arguments - extract system call parameter values > * @task:task of interest, must be blocked > * @regs:task_pt_regs() of @task > - * @i: argument index [0,5] > - * @n: number of arguments; n+i must be [1,6]. > * @args:array filled with argument values > * > - * Fetches @n arguments to the system call starting with the @i'th argument > - * (from 0 through 5). Argument @i is stored in @args[0], and so on. > - * An arch inline version is probably optimal when @i and @n are constants. > + * Fetches 6 arguments to the system call (from 0 through 5). The first > + * argument is stored in @args[0], and so on. > * > * 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. > - * It's invalid to call this with @i + @n > 6; we only support system calls > - * 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) > +unsigned long *args) > { > - if (n == 0) > - return; > - if (i + n > SYSCALL_MAX_ARGS) { > - unsigned long *args_bad = args + SYSCALL_MAX_ARGS - i; > - unsigned int n_bad = n + i - SYSCALL_MAX_ARGS; > - pr_warning("%s called with max args %d, handling only %d\n", > -__func__, i + n, SYSCALL_MAX_ARGS); > - memset(args_bad, 0, n_bad * sizeof(args[0])); > - memset(args_bad, 0, n_bad * sizeof(args[0])); > - } > - > - if (i == 0) { > - args[0] = regs->orig_r0; > - args++; > - i++; > - n--; > - } > - > - memcpy(args, ®s->uregs[0] + i, n * sizeof(args[0])); > + args[0] = regs->orig_r0; > + args++; > + memcpy(args, ®s->uregs[0] + 1, 5 * sizeof(args[0])); > } A shorter and slightly more readable equivalent of the last memcpy is memcpy(args, ®s->uregs[1], 5 * sizeof(args[0])); > diff --git a/arch/powerpc/include/asm/syscall.h > b/arch/powerpc/include/asm/syscall.h > index 1a0e7a8b1c81..5c9b9dc82b7e 100644 > --- a/arch/powerpc/include/asm/syscall.h > +++ b/arch/powerpc/include/asm/syscall.h > @@ -65,22 +65,20 @@ static inline void syscall_set_return_value(struct > task_struct *task, > > static inl
Re: strace breaks with to be released glibc 2.31
Hi, On Wed, Jan 15, 2020 at 08:10:38PM +, Vineet Gupta wrote: > Hi, > > I've been testing an in-works glibc port for ARC and with 2.31 there's a glibc > change which seems to break strace. > > Commit d1e411e5c786ce3 "Add PTRACE_GET_SYSCALL_INFO from Linux 5.3 to > sys/ptrace.h." > > This now defines PTRACE_GET_SYSCALL_INFO but defines struct > __ptrace_syscall_info > (not the non underscored ver) causing strace to trip. You must've got a relatively rare environment with glibc-2.31 and Linux kernel headers < 5.3. I'm testing a fix. Thanks, -- ldv ___ linux-snps-arc mailing list linux-snps-arc@lists.infradead.org http://lists.infradead.org/mailman/listinfo/linux-snps-arc
Re: [PATCH] ARC: Enable automatic support for newer ARC ISA variants (ARCv3)
On Mon, Feb 22, 2021 at 06:37:54PM -0800, Vineet Gupta wrote: > The syscall TRAP instruction used to be 4 bytes on legacy ARCompact > based ARC700 cores. Since then ARCv2 (circa 2014) and the upcoming ARCv3 > use the same 2-byte TRAP_S instruction. > > To ease porting of software to new ISA, special case ARC700. > > This is the only change needed to get strace working on 64-bit ARCv3 > cores (kudos to strace for making porting so easy) > > Signed-off-by: Vineet Gupta > --- > src/linux/arc/raw_syscall.h | 4 +--- > 1 file changed, 1 insertion(+), 3 deletions(-) > > diff --git a/src/linux/arc/raw_syscall.h b/src/linux/arc/raw_syscall.h > index 6e60a6112b31..f54fe06f33df 100644 > --- a/src/linux/arc/raw_syscall.h > +++ b/src/linux/arc/raw_syscall.h > @@ -21,10 +21,8 @@ raw_syscall_0(const kernel_ulong_t nr, kernel_ulong_t *err) > > # ifdef __A7__ > # define ARC_TRAP_INSN "trap0" > -# elif defined __HS__ > -# define ARC_TRAP_INSN "trap_s 0 " > # else > -# error unrecognized arc > +# define ARC_TRAP_INSN "trap_s 0 " > # endif > > __asm__ __volatile__(ARC_TRAP_INSN Applied, thanks. -- ldv ___ linux-snps-arc mailing list linux-snps-arc@lists.infradead.org http://lists.infradead.org/mailman/listinfo/linux-snps-arc
Re: [PATCH] Recognize arc64
On Wed, Apr 21, 2021 at 12:51:18PM -0700, Vineet Gupta wrote: > This paves way for setting up arc64 software ecosystem. > > $ make check > cd testsuite && bash config-guess.sh && rm uname > PASS: config.guess checks (135 tests) > cd testsuite && bash config-sub.sh > PASS: config.sub checks (852 tests) > PASS: config.sub idempotency checks (789 tests) > PASS: config.sub canonicalise each config.guess testcase (135 tests) > > * config.guess (arc64:Linux:*:*): Recognize. > * config.sub (arc64): Likewise. > * doc/config.guess.1: Regenerate. > * doc/config.sub.1: Likewise. > * testsuite/config-guess.data: Add test cases for arc64. > * testsuite/config-sub.data (arc64, arc*-elf): Add test cases. > > Signed-off-by: Vineet Gupta > --- > config.guess| 4 ++-- > config.sub | 4 ++-- > doc/config.guess.1 | 2 +- > doc/config.sub.1| 2 +- > testsuite/config-guess.data | 1 + > testsuite/config-sub.data | 5 + > 6 files changed, 12 insertions(+), 6 deletions(-) > > diff --git a/config.guess b/config.guess > index 1972fda8eb05..a6646ed28258 100755 > --- a/config.guess > +++ b/config.guess > @@ -2,7 +2,7 @@ > # Attempt to guess a canonical system name. > # Copyright 1992-2021 Free Software Foundation, Inc. > > -timestamp='2021-01-25' > +timestamp='2021-04-21' > > # This file is free software; you can redistribute it and/or modify it > # under the terms of the GNU General Public License as published by > @@ -949,7 +949,7 @@ EOF > if test "$?" = 0 ; then LIBC=gnulibc1 ; fi > echo "$UNAME_MACHINE"-unknown-linux-"$LIBC" > exit ;; > -arc:Linux:*:* | arceb:Linux:*:*) > +arc:Linux:*:* | arceb:Linux:*:* | arc64:Linux:*:*) > echo "$UNAME_MACHINE"-unknown-linux-"$LIBC" > exit ;; > arm*:Linux:*:*) > diff --git a/config.sub b/config.sub > index 7f7d0b055ac5..d70247c08d12 100755 > --- a/config.sub > +++ b/config.sub > @@ -2,7 +2,7 @@ > # Configuration validation subroutine script. > # Copyright 1992-2021 Free Software Foundation, Inc. > > -timestamp='2021-03-10' > +timestamp='2021-04-21' > > # This file is free software; you can redistribute it and/or modify it > # under the terms of the GNU General Public License as published by > @@ -1165,7 +1165,7 @@ case $cpu-$vendor in > | alphapca5[67] | alpha64pca5[67] \ > | am33_2.0 \ > | amdgcn \ > - | arc | arceb \ > + | arc | arceb | arc64 \ > | arm | arm[lb]e | arme[lb] | armv* \ > | avr | avr32 \ > | asmjs \ > diff --git a/doc/config.guess.1 b/doc/config.guess.1 > index 75fbb236fd68..f79f1c5f10c5 100644 > --- a/doc/config.guess.1 > +++ b/doc/config.guess.1 > @@ -1,5 +1,5 @@ > .\" DO NOT MODIFY THIS FILE! It was generated by help2man 1.47.16. > -.TH CONFIG.GUESS "1" "January 2021" "GNU config.guess (2021-01-25)" "User > Commands" > +.TH CONFIG.GUESS "1" "January 2021" "GNU config.guess (2021-04-21)" "User > Commands" > .SH NAME > config.guess \- guess the build system triplet > .SH SYNOPSIS > diff --git a/doc/config.sub.1 b/doc/config.sub.1 > index 317c8c47a180..9d52cebf58d0 100644 > --- a/doc/config.sub.1 > +++ b/doc/config.sub.1 > @@ -1,5 +1,5 @@ > .\" DO NOT MODIFY THIS FILE! It was generated by help2man 1.47.16. > -.TH CONFIG.SUB "1" "March 2021" "GNU config.sub (2021-03-10)" "User Commands" > +.TH CONFIG.SUB "1" "March 2021" "GNU config.sub (2021-04-21)" "User Commands" > .SH NAME > config.sub \- validate and canonicalize a configuration triplet > .SH SYNOPSIS > diff --git a/testsuite/config-guess.data b/testsuite/config-guess.data > index f240e9ce61df..73908abb4e06 100644 > --- a/testsuite/config-guess.data > +++ b/testsuite/config-guess.data > @@ -35,6 +35,7 @@ amd64 | 7.0_RC1 | NetBSD | ignored | x86_64 | > x86_64-unknown-netbsd7.0 > amd64 | 7.2.1 | Isilon OneFS | ignored | ignored | x86_64-unknown-onefs > arc | ignored | Linux | ignored | ignored | arc-unknown-linux-gnu > arceb | ignored | Linux | ignored | ignored | arceb-unknown-linux-gnu > +arc64 | ignored | Linux | ignored | ignored | arc64-unknown-linux-gnu > arm | 12.0 | FreeBSD | ignored | armv6 | armv6-unknown-freebsd12.0-gnueabihf > arm | 12.0 | FreeBSD | ignored | armv7 | armv7-unknown-freebsd12.0-gnueabihf > arm | 12.1 | AROS | ignored | armv7 | arm-unknown-aros > diff --git a/testsuite/config-sub.data b/testsuite/config-sub.data > index 101a4c45ec39..0a59eaf1cec7 100644 > --- a/testsuite/config-sub.data > +++ b/testsuite/config-sub.data > @@ -59,9 +59,14 @@ amix > m68k-unknown-sysv4 > apollo68 m68k-apollo-sysv > apollo68bsd m68k-apollo-bsd > arc arc-unknown-none > +arc-elf arc-unknown-elf > arc-linux
Re: [PATCH] Recognize arc32
On Thu, Jun 03, 2021 at 09:01:25PM -0700, Vineet Gupta wrote: > This is the 32-bit variant of ARCv3 ISA (which is not compatible with the > 32-bit ARCv2 ISA) > > | make check > | cd testsuite && bash config-guess.sh && rm uname > | PASS: config.guess checks (136 tests) > | cd testsuite && bash config-sub.sh > | PASS: config.sub checks (864 tests) > | PASS: config.sub idempotency checks (801 tests) > | PASS: config.sub canonicalise each config.guess testcase (136 tests) > > * config.guess (arc32:Linux:*:*): Recognize. > * config.sub (arc32): Likewise. > * doc/config.guess.1: Regenerate. > * doc/config.sub.1: Likewise. > * testsuite/config-guess.data: Add a test case for arc32. > * testsuite/config-sub.data (arc32, arc*-elf): Add test cases. Merged, thanks! -- ldv ___ linux-snps-arc mailing list linux-snps-arc@lists.infradead.org http://lists.infradead.org/mailman/listinfo/linux-snps-arc
[PATCH 0/6] ptrace: introduce PTRACE_SET_SYSCALL_INFO API
PTRACE_SET_SYSCALL_INFO is a generic ptrace API that complements PTRACE_GET_SYSCALL_INFO by letting the ptracer modify details of system calls the tracee is blocked in. This API allows ptracers to obtain and modify system call details in a straightforward and architecture-agnostic way. Current implementation supports changing only those bits of system call information that are used by strace, namely, syscall number, syscall arguments, and syscall return value. Support of changing additional details returned by PTRACE_GET_SYSCALL_INFO, such as instruction pointer and stack pointer, could be added later if needed, by re-using struct ptrace_syscall_info.reserved to specify the additional details that should be set. Currently, the reserved field of struct ptrace_syscall_info must be initialized with zeroes; arch, instruction_pointer, and stack_pointer fields are ignored. PTRACE_SET_SYSCALL_INFO currently supports only PTRACE_SYSCALL_INFO_ENTRY, PTRACE_SYSCALL_INFO_EXIT, and PTRACE_SYSCALL_INFO_SECCOMP operations. Other operations could be added later if needed. Ideally, PTRACE_SET_SYSCALL_INFO should have been introduced along with PTRACE_GET_SYSCALL_INFO, but it didn't happen. The last straw that convinced me to implement PTRACE_SET_SYSCALL_INFO was apparent failure to provide an API of changing the first system call argument on riscv architecture [1]. ptrace(2) man page: long ptrace(enum __ptrace_request request, pid_t pid, void *addr, void *data); ... PTRACE_SET_SYSCALL_INFO Modify information about the system call that caused the stop. The "data" argument is a pointer to struct ptrace_syscall_info that specifies the system call information to be set. The "addr" argument should be set to sizeof(struct ptrace_syscall_info)). [1] https://lore.kernel.org/all/59505464-c84a-403d-972f-d4b2055ee...@gmail.com/ Dmitry V. Levin (6): Revert "arch: remove unused function syscall_set_arguments()" syscall.h: add syscall_set_arguments() on remaining HAVE_ARCH_TRACEHOOK arches syscall.h: introduce syscall_set_nr() ptrace_get_syscall_info: factor out ptrace_get_syscall_info_op ptrace: introduce PTRACE_SET_SYSCALL_INFO request selftests/ptrace: add a test case for PTRACE_SET_SYSCALL_INFO arch/arc/include/asm/syscall.h| 20 + arch/arm/include/asm/syscall.h| 25 + arch/arm64/include/asm/syscall.h | 20 + arch/csky/include/asm/syscall.h | 13 + arch/hexagon/include/asm/syscall.h| 14 + arch/loongarch/include/asm/syscall.h | 15 + arch/m68k/include/asm/syscall.h | 7 + arch/microblaze/include/asm/syscall.h | 7 + arch/mips/include/asm/syscall.h | 53 +++ arch/nios2/include/asm/syscall.h | 16 + arch/openrisc/include/asm/syscall.h | 13 + arch/parisc/include/asm/syscall.h | 19 + arch/powerpc/include/asm/syscall.h| 15 + arch/riscv/include/asm/syscall.h | 16 + arch/s390/include/asm/syscall.h | 19 + arch/sh/include/asm/syscall_32.h | 19 + arch/sparc/include/asm/syscall.h | 17 + arch/um/include/asm/syscall-generic.h | 19 + arch/x86/include/asm/syscall.h| 43 ++ arch/xtensa/include/asm/syscall.h | 18 + include/asm-generic/syscall.h | 30 ++ include/linux/ptrace.h| 3 + include/uapi/linux/ptrace.h | 3 +- kernel/ptrace.c | 154 ++- tools/testing/selftests/ptrace/Makefile | 2 +- .../selftests/ptrace/set_syscall_info.c | 436 ++ 26 files changed, 994 insertions(+), 22 deletions(-) create mode 100644 tools/testing/selftests/ptrace/set_syscall_info.c -- ldv ___ linux-snps-arc mailing list linux-snps-arc@lists.infradead.org http://lists.infradead.org/mailman/listinfo/linux-snps-arc
[PATCH 2/6] syscall.h: add syscall_set_arguments() on remaining HAVE_ARCH_TRACEHOOK arches
Add syscall_set_arguments() on those few HAVE_ARCH_TRACEHOOK architectures that haven't provided it yet. syscall_set_arguments() is going to be needed on all HAVE_ARCH_TRACEHOOK architectures to implement PTRACE_SET_SYSCALL_INFO API. Signed-off-by: Dmitry V. Levin --- arch/arc/include/asm/syscall.h | 14 + arch/arm/include/asm/syscall.h | 13 arch/arm64/include/asm/syscall.h | 13 arch/csky/include/asm/syscall.h | 13 arch/hexagon/include/asm/syscall.h | 7 + arch/loongarch/include/asm/syscall.h | 8 + arch/mips/include/asm/syscall.h | 46 arch/parisc/include/asm/syscall.h| 12 8 files changed, 126 insertions(+) diff --git a/arch/arc/include/asm/syscall.h b/arch/arc/include/asm/syscall.h index 9709256e31c8..89c1e1736356 100644 --- a/arch/arc/include/asm/syscall.h +++ b/arch/arc/include/asm/syscall.h @@ -67,6 +67,20 @@ syscall_get_arguments(struct task_struct *task, struct pt_regs *regs, } } +static inline void +syscall_set_arguments(struct task_struct *task, struct pt_regs *regs, + unsigned long *args) +{ + unsigned long *inside_ptregs = ®s->r0; + unsigned int n = 6; + unsigned int i = 0; + + while (n--) { + *inside_ptregs = args[i++]; + inside_ptregs--; + } +} + static inline int syscall_get_arch(struct task_struct *task) { diff --git a/arch/arm/include/asm/syscall.h b/arch/arm/include/asm/syscall.h index fe4326d938c1..21927fa0ae2b 100644 --- a/arch/arm/include/asm/syscall.h +++ b/arch/arm/include/asm/syscall.h @@ -80,6 +80,19 @@ static inline void syscall_get_arguments(struct task_struct *task, memcpy(args, ®s->ARM_r0 + 1, 5 * sizeof(args[0])); } +static inline void syscall_set_arguments(struct task_struct *task, +struct pt_regs *regs, +const unsigned long *args) +{ + memcpy(®s->ARM_r0, args, 6 * sizeof(args[0])); + /* +* Also copy the first argument into ARM_ORIG_r0 +* so that syscall_get_arguments() would return it +* instead of the previous value. +*/ + regs->ARM_ORIG_r0 = regs->ARM_r0; +} + static inline int syscall_get_arch(struct task_struct *task) { /* ARM tasks don't change audit architectures on the fly. */ diff --git a/arch/arm64/include/asm/syscall.h b/arch/arm64/include/asm/syscall.h index ab8e14b96f68..76020b66286b 100644 --- a/arch/arm64/include/asm/syscall.h +++ b/arch/arm64/include/asm/syscall.h @@ -73,6 +73,19 @@ static inline void syscall_get_arguments(struct task_struct *task, memcpy(args, ®s->regs[1], 5 * sizeof(args[0])); } +static inline void syscall_set_arguments(struct task_struct *task, +struct pt_regs *regs, +const unsigned long *args) +{ + memcpy(®s->regs[0], args, 6 * sizeof(args[0])); + /* +* Also copy the first argument into orig_x0 +* so that syscall_get_arguments() would return it +* instead of the previous value. +*/ + regs->orig_x0 = regs->regs[0]; +} + /* * We don't care about endianness (__AUDIT_ARCH_LE bit) here because * AArch64 has the same system calls both on little- and big- endian. diff --git a/arch/csky/include/asm/syscall.h b/arch/csky/include/asm/syscall.h index 0de5734950bf..30403f7a0487 100644 --- a/arch/csky/include/asm/syscall.h +++ b/arch/csky/include/asm/syscall.h @@ -59,6 +59,19 @@ syscall_get_arguments(struct task_struct *task, struct pt_regs *regs, memcpy(args, ®s->a1, 5 * sizeof(args[0])); } +static inline void +syscall_set_arguments(struct task_struct *task, struct pt_regs *regs, + const unsigned long *args) +{ + memcpy(®s->a0, args, 6 * sizeof(regs->a0)); + /* +* Also copy the first argument into orig_x0 +* so that syscall_get_arguments() would return it +* instead of the previous value. +*/ + regs->orig_a0 = regs->a0; +} + static inline int syscall_get_arch(struct task_struct *task) { diff --git a/arch/hexagon/include/asm/syscall.h b/arch/hexagon/include/asm/syscall.h index f6e454f18038..12d2df6aaa03 100644 --- a/arch/hexagon/include/asm/syscall.h +++ b/arch/hexagon/include/asm/syscall.h @@ -33,6 +33,13 @@ static inline void syscall_get_arguments(struct task_struct *task, memcpy(args, &(®s->r00)[0], 6 * sizeof(args[0])); } +static inline void syscall_set_arguments(struct task_struct *task, +struct pt_regs *regs, +unsigned long *args) +{ + memcpy(&(®s->r00)[0], args, 6 * sizeof(args[0])); +} + static inline long syscall_get_error(struct task_struct *task,
[PATCH 3/6] syscall.h: introduce syscall_set_nr()
Similar to syscall_set_arguments() that complements syscall_get_arguments(), introduce syscall_set_nr() that complements syscall_get_nr(). syscall_set_nr() is going to be needed along with syscall_set_arguments() on all HAVE_ARCH_TRACEHOOK architectures to implement PTRACE_SET_SYSCALL_INFO API. Signed-off-by: Dmitry V. Levin --- arch/arc/include/asm/syscall.h| 6 ++ arch/arm/include/asm/syscall.h| 12 arch/arm64/include/asm/syscall.h | 7 +++ arch/hexagon/include/asm/syscall.h| 7 +++ arch/loongarch/include/asm/syscall.h | 7 +++ arch/m68k/include/asm/syscall.h | 7 +++ arch/microblaze/include/asm/syscall.h | 7 +++ arch/mips/include/asm/syscall.h | 7 +++ arch/nios2/include/asm/syscall.h | 5 + arch/openrisc/include/asm/syscall.h | 6 ++ arch/parisc/include/asm/syscall.h | 7 +++ arch/powerpc/include/asm/syscall.h| 5 + arch/riscv/include/asm/syscall.h | 7 +++ arch/s390/include/asm/syscall.h | 7 +++ arch/sh/include/asm/syscall_32.h | 7 +++ arch/sparc/include/asm/syscall.h | 7 +++ arch/um/include/asm/syscall-generic.h | 5 + arch/x86/include/asm/syscall.h| 7 +++ arch/xtensa/include/asm/syscall.h | 7 +++ include/asm-generic/syscall.h | 14 ++ 20 files changed, 144 insertions(+) diff --git a/arch/arc/include/asm/syscall.h b/arch/arc/include/asm/syscall.h index 89c1e1736356..6095fbfa74ab 100644 --- a/arch/arc/include/asm/syscall.h +++ b/arch/arc/include/asm/syscall.h @@ -23,6 +23,12 @@ syscall_get_nr(struct task_struct *task, struct pt_regs *regs) return -1; } +static inline void +syscall_set_nr(struct task_struct *task, struct pt_regs *regs, int nr) +{ + regs->r8 = nr; +} + static inline void syscall_rollback(struct task_struct *task, struct pt_regs *regs) { diff --git a/arch/arm/include/asm/syscall.h b/arch/arm/include/asm/syscall.h index 21927fa0ae2b..cfa61f355675 100644 --- a/arch/arm/include/asm/syscall.h +++ b/arch/arm/include/asm/syscall.h @@ -31,6 +31,18 @@ static inline int syscall_get_nr(struct task_struct *task, return task_thread_info(task)->abi_syscall & __NR_SYSCALL_MASK; } +static inline void syscall_set_nr(struct task_struct *task, + struct pt_regs *regs, + int nr) +{ + if (!IS_ENABLED(CONFIG_AEABI) || IS_ENABLED(CONFIG_OABI_COMPAT)) { + if (nr != -1) + nr &= __NR_SYSCALL_MASK; + } + + task_thread_info(task)->abi_syscall = nr; +} + static inline bool __in_oabi_syscall(struct task_struct *task) { return IS_ENABLED(CONFIG_OABI_COMPAT) && diff --git a/arch/arm64/include/asm/syscall.h b/arch/arm64/include/asm/syscall.h index 76020b66286b..0e6807618bed 100644 --- a/arch/arm64/include/asm/syscall.h +++ b/arch/arm64/include/asm/syscall.h @@ -23,6 +23,13 @@ static inline int syscall_get_nr(struct task_struct *task, return regs->syscallno; } +static inline void syscall_set_nr(struct task_struct *task, + struct pt_regs *regs, + int nr) +{ + regs->syscallno = nr; +} + static inline void syscall_rollback(struct task_struct *task, struct pt_regs *regs) { diff --git a/arch/hexagon/include/asm/syscall.h b/arch/hexagon/include/asm/syscall.h index 12d2df6aaa03..72befa719434 100644 --- a/arch/hexagon/include/asm/syscall.h +++ b/arch/hexagon/include/asm/syscall.h @@ -26,6 +26,13 @@ static inline long syscall_get_nr(struct task_struct *task, return regs->r06; } +static inline void syscall_set_nr(struct task_struct *task, + struct pt_regs *regs, + int nr) +{ + regs->r06 = nr; +} + static inline void syscall_get_arguments(struct task_struct *task, struct pt_regs *regs, unsigned long *args) diff --git a/arch/loongarch/include/asm/syscall.h b/arch/loongarch/include/asm/syscall.h index ff415b3c0a8e..81d2733f7b94 100644 --- a/arch/loongarch/include/asm/syscall.h +++ b/arch/loongarch/include/asm/syscall.h @@ -26,6 +26,13 @@ static inline long syscall_get_nr(struct task_struct *task, return regs->regs[11]; } +static inline void syscall_set_nr(struct task_struct *task, + struct pt_regs *regs, + int nr) +{ + regs->regs[11] = nr; +} + static inline void syscall_rollback(struct task_struct *task, struct pt_regs *regs) { diff --git a/arch/m68k/include/asm/syscall.h b/arch/m68k/include/asm/syscall.h index d1453e850cdd..bf84b160c2eb 100644 --- a/arch/m68k/include/asm/syscall.h +++ b/arch/m68k/include/asm/sys
Re: [PATCH v4 0/7] ptrace: introduce PTRACE_SET_SYSCALL_INFO API
On Mon, Feb 03, 2025 at 10:29:37AM +0100, Alexander Gordeev wrote: > On Mon, Feb 03, 2025 at 08:58:49AM +0200, Dmitry V. Levin wrote: > > Hi Dmitry, > > > PTRACE_SET_SYSCALL_INFO is a generic ptrace API that complements > > PTRACE_GET_SYSCALL_INFO by letting the ptracer modify details of > > system calls the tracee is blocked in. > ... > > FWIW, I am getting these on s390: > > # ./tools/testing/selftests/ptrace/set_syscall_info > TAP version 13 > 1..1 > # Starting 1 tests from 1 test cases. > # RUN global.set_syscall_info ... > # set_syscall_info.c:87:set_syscall_info:Expected exp_entry->nr (-1) == > info->entry.nr (65535) > # set_syscall_info.c:88:set_syscall_info:wait #3: PTRACE_GET_SYSCALL_INFO #2: > syscall nr mismatch > # set_syscall_info: Test terminated by assertion > # FAIL global.set_syscall_info > not ok 1 global.set_syscall_info > # FAILED: 0 / 1 tests passed. > # Totals: pass:0 fail:1 xfail:0 xpass:0 skip:0 error:0 > > I remember one of the earlier versions (v1 or v2) was working for me. > > Thanks! In v3, this test was extended to check whether PTRACE_GET_SYSCALL_INFO called immediately after PTRACE_SET_SYSCALL_INFO returns the same syscall number, and on s390 it apparently doesn't, thanks to its implementation of syscall_get_nr() that returns 0x in this case. To workaround this, we could either change syscall_get_nr() to return -1 in this case, or add an #ifdef __s390x__ exception to the test. What would you prefer? -- ldv ___ linux-snps-arc mailing list linux-snps-arc@lists.infradead.org http://lists.infradead.org/mailman/listinfo/linux-snps-arc
[PATCH v5 0/7] ptrace: introduce PTRACE_SET_SYSCALL_INFO API
PTRACE_SET_SYSCALL_INFO is a generic ptrace API that complements PTRACE_GET_SYSCALL_INFO by letting the ptracer modify details of system calls the tracee is blocked in. This API allows ptracers to obtain and modify system call details in a straightforward and architecture-agnostic way, providing a consistent way of manipulating the system call number and arguments across architectures. As in case of PTRACE_GET_SYSCALL_INFO, PTRACE_SET_SYSCALL_INFO also does not aim to address numerous architecture-specific system call ABI peculiarities, like differences in the number of system call arguments for such system calls as pread64 and preadv. The current implementation supports changing only those bits of system call information that are used by strace system call tampering, namely, syscall number, syscall arguments, and syscall return value. Support of changing additional details returned by PTRACE_GET_SYSCALL_INFO, such as instruction pointer and stack pointer, could be added later if needed, by using struct ptrace_syscall_info.flags to specify the additional details that should be set. Currently, "flags" and "reserved" fields of struct ptrace_syscall_info must be initialized with zeroes; "arch", "instruction_pointer", and "stack_pointer" fields are currently ignored. PTRACE_SET_SYSCALL_INFO currently supports only PTRACE_SYSCALL_INFO_ENTRY, PTRACE_SYSCALL_INFO_EXIT, and PTRACE_SYSCALL_INFO_SECCOMP operations. Other operations could be added later if needed. Ideally, PTRACE_SET_SYSCALL_INFO should have been introduced along with PTRACE_GET_SYSCALL_INFO, but it didn't happen. The last straw that convinced me to implement PTRACE_SET_SYSCALL_INFO was apparent failure to provide an API of changing the first system call argument on riscv architecture [1]. ptrace(2) man page: long ptrace(enum __ptrace_request request, pid_t pid, void *addr, void *data); ... PTRACE_SET_SYSCALL_INFO Modify information about the system call that caused the stop. The "data" argument is a pointer to struct ptrace_syscall_info that specifies the system call information to be set. The "addr" argument should be set to sizeof(struct ptrace_syscall_info)). [1] https://lore.kernel.org/all/59505464-c84a-403d-972f-d4b2055ee...@gmail.com/ Notes: v5: * ptrace: Extend the commit message to say that the new API does not aim to address numerous architecture-specific syscall ABI peculiarities * selftests: Add a workaround for s390 16-bit syscall numbers * Add more Acked-by * v4: https://lore.kernel.org/all/20250203065849.ga14...@strace.io/ v4: * Split out syscall_set_return_value() for hexagon into a separate patch * s390: Change the style of syscall_set_arguments() implementation as requested * Add more Reviewed-by * v3: https://lore.kernel.org/all/20250128091445.ga8...@strace.io/ v3: * powerpc: Submit syscall_set_return_value() fix for "sc" case separately * mips: Do not introduce erroneous argument truncation on mips n32, add a detailed description to the commit message of the mips_get_syscall_arg() change * ptrace: Add explicit padding to the end of struct ptrace_syscall_info, simplify obtaining of user ptrace_syscall_info, do not introduce PTRACE_SYSCALL_INFO_SIZE_VER0 * ptrace: Change the return type of ptrace_set_syscall_info_* functions from "unsigned long" to "int" * ptrace: Add -ERANGE check to ptrace_set_syscall_info_exit(), add comments to -ERANGE checks * ptrace: Update comments about supported syscall stops * selftests: Extend set_syscall_info test, fix for mips n32 * Add Tested-by and Reviewed-by v2: * Add patch to fix syscall_set_return_value() on powerpc * Add patch to fix mips_get_syscall_arg() on mips * Add syscall_set_return_value() implementation on hexagon * Add syscall_set_return_value() invocation to syscall_set_nr() on arm and arm64. * Fix syscall_set_nr() and mips_set_syscall_arg() on mips * Add a comment to syscall_set_nr() on arc, powerpc, s390, sh, and sparc * Remove redundant ptrace_syscall_info.op assignments in ptrace_get_syscall_info_* * Minor style tweaks in ptrace_get_syscall_info_op() * Remove syscall_set_return_value() invocation from ptrace_set_syscall_info_entry() * Skip syscall_set_arguments() invocation in case of syscall number -1 in ptrace_set_syscall_info_entry() * Split ptrace_syscall_info.reserved into ptrace_syscall_info.reserved and ptrace_syscall_info.flags * Use __kernel_ulong_t instead of unsigned long in set_syscall_info test Dmitry V. Levin (7): mips: fix mips_get_syscall_arg() for o32 hexagon: add syscall_set_return_value() syscall.h: add syscall_set_arguments() syscall.h: introduce syscall_set_nr() ptrace_get_syscall_info: factor o
[PATCH v5 3/7] syscall.h: add syscall_set_arguments()
This function is going to be needed on all HAVE_ARCH_TRACEHOOK architectures to implement PTRACE_SET_SYSCALL_INFO API. This partially reverts commit 7962c2eddbfe ("arch: remove unused function syscall_set_arguments()") by reusing some of old syscall_set_arguments() implementations. Signed-off-by: Dmitry V. Levin Tested-by: Charlie Jenkins Reviewed-by: Charlie Jenkins Acked-by: Helge Deller # parisc --- arch/arc/include/asm/syscall.h| 14 +++ arch/arm/include/asm/syscall.h| 13 ++ arch/arm64/include/asm/syscall.h | 13 ++ arch/csky/include/asm/syscall.h | 13 ++ arch/hexagon/include/asm/syscall.h| 7 ++ arch/loongarch/include/asm/syscall.h | 8 ++ arch/mips/include/asm/syscall.h | 32 arch/nios2/include/asm/syscall.h | 11 arch/openrisc/include/asm/syscall.h | 7 ++ arch/parisc/include/asm/syscall.h | 12 + arch/powerpc/include/asm/syscall.h| 10 arch/riscv/include/asm/syscall.h | 9 +++ arch/s390/include/asm/syscall.h | 9 +++ arch/sh/include/asm/syscall_32.h | 12 + arch/sparc/include/asm/syscall.h | 10 arch/um/include/asm/syscall-generic.h | 14 +++ arch/x86/include/asm/syscall.h| 36 +++ arch/xtensa/include/asm/syscall.h | 11 include/asm-generic/syscall.h | 16 19 files changed, 257 insertions(+) diff --git a/arch/arc/include/asm/syscall.h b/arch/arc/include/asm/syscall.h index 9709256e31c8..89c1e1736356 100644 --- a/arch/arc/include/asm/syscall.h +++ b/arch/arc/include/asm/syscall.h @@ -67,6 +67,20 @@ syscall_get_arguments(struct task_struct *task, struct pt_regs *regs, } } +static inline void +syscall_set_arguments(struct task_struct *task, struct pt_regs *regs, + unsigned long *args) +{ + unsigned long *inside_ptregs = ®s->r0; + unsigned int n = 6; + unsigned int i = 0; + + while (n--) { + *inside_ptregs = args[i++]; + inside_ptregs--; + } +} + static inline int syscall_get_arch(struct task_struct *task) { diff --git a/arch/arm/include/asm/syscall.h b/arch/arm/include/asm/syscall.h index fe4326d938c1..21927fa0ae2b 100644 --- a/arch/arm/include/asm/syscall.h +++ b/arch/arm/include/asm/syscall.h @@ -80,6 +80,19 @@ static inline void syscall_get_arguments(struct task_struct *task, memcpy(args, ®s->ARM_r0 + 1, 5 * sizeof(args[0])); } +static inline void syscall_set_arguments(struct task_struct *task, +struct pt_regs *regs, +const unsigned long *args) +{ + memcpy(®s->ARM_r0, args, 6 * sizeof(args[0])); + /* +* Also copy the first argument into ARM_ORIG_r0 +* so that syscall_get_arguments() would return it +* instead of the previous value. +*/ + regs->ARM_ORIG_r0 = regs->ARM_r0; +} + static inline int syscall_get_arch(struct task_struct *task) { /* ARM tasks don't change audit architectures on the fly. */ diff --git a/arch/arm64/include/asm/syscall.h b/arch/arm64/include/asm/syscall.h index ab8e14b96f68..76020b66286b 100644 --- a/arch/arm64/include/asm/syscall.h +++ b/arch/arm64/include/asm/syscall.h @@ -73,6 +73,19 @@ static inline void syscall_get_arguments(struct task_struct *task, memcpy(args, ®s->regs[1], 5 * sizeof(args[0])); } +static inline void syscall_set_arguments(struct task_struct *task, +struct pt_regs *regs, +const unsigned long *args) +{ + memcpy(®s->regs[0], args, 6 * sizeof(args[0])); + /* +* Also copy the first argument into orig_x0 +* so that syscall_get_arguments() would return it +* instead of the previous value. +*/ + regs->orig_x0 = regs->regs[0]; +} + /* * We don't care about endianness (__AUDIT_ARCH_LE bit) here because * AArch64 has the same system calls both on little- and big- endian. diff --git a/arch/csky/include/asm/syscall.h b/arch/csky/include/asm/syscall.h index 0de5734950bf..30403f7a0487 100644 --- a/arch/csky/include/asm/syscall.h +++ b/arch/csky/include/asm/syscall.h @@ -59,6 +59,19 @@ syscall_get_arguments(struct task_struct *task, struct pt_regs *regs, memcpy(args, ®s->a1, 5 * sizeof(args[0])); } +static inline void +syscall_set_arguments(struct task_struct *task, struct pt_regs *regs, + const unsigned long *args) +{ + memcpy(®s->a0, args, 6 * sizeof(regs->a0)); + /* +* Also copy the first argument into orig_x0 +* so that syscall_get_arguments() would return it +* instead of the previous value. +*/ + regs->orig_a0 = regs->a0; +} + static inline int syscall_g
[PATCH v5 4/7] syscall.h: introduce syscall_set_nr()
Similar to syscall_set_arguments() that complements syscall_get_arguments(), introduce syscall_set_nr() that complements syscall_get_nr(). syscall_set_nr() is going to be needed along with syscall_set_arguments() on all HAVE_ARCH_TRACEHOOK architectures to implement PTRACE_SET_SYSCALL_INFO API. Signed-off-by: Dmitry V. Levin Tested-by: Charlie Jenkins Reviewed-by: Charlie Jenkins Acked-by: Helge Deller # parisc --- arch/arc/include/asm/syscall.h| 11 +++ arch/arm/include/asm/syscall.h| 24 arch/arm64/include/asm/syscall.h | 16 arch/hexagon/include/asm/syscall.h| 7 +++ arch/loongarch/include/asm/syscall.h | 7 +++ arch/m68k/include/asm/syscall.h | 7 +++ arch/microblaze/include/asm/syscall.h | 7 +++ arch/mips/include/asm/syscall.h | 14 ++ arch/nios2/include/asm/syscall.h | 5 + arch/openrisc/include/asm/syscall.h | 6 ++ arch/parisc/include/asm/syscall.h | 7 +++ arch/powerpc/include/asm/syscall.h| 10 ++ arch/riscv/include/asm/syscall.h | 7 +++ arch/s390/include/asm/syscall.h | 12 arch/sh/include/asm/syscall_32.h | 12 arch/sparc/include/asm/syscall.h | 12 arch/um/include/asm/syscall-generic.h | 5 + arch/x86/include/asm/syscall.h| 7 +++ arch/xtensa/include/asm/syscall.h | 7 +++ include/asm-generic/syscall.h | 14 ++ 20 files changed, 197 insertions(+) diff --git a/arch/arc/include/asm/syscall.h b/arch/arc/include/asm/syscall.h index 89c1e1736356..728d625a10f1 100644 --- a/arch/arc/include/asm/syscall.h +++ b/arch/arc/include/asm/syscall.h @@ -23,6 +23,17 @@ syscall_get_nr(struct task_struct *task, struct pt_regs *regs) return -1; } +static inline void +syscall_set_nr(struct task_struct *task, struct pt_regs *regs, int nr) +{ + /* +* Unlike syscall_get_nr(), syscall_set_nr() can be called only when +* the target task is stopped for tracing on entering syscall, so +* there is no need to have the same check syscall_get_nr() has. +*/ + regs->r8 = nr; +} + static inline void syscall_rollback(struct task_struct *task, struct pt_regs *regs) { diff --git a/arch/arm/include/asm/syscall.h b/arch/arm/include/asm/syscall.h index 21927fa0ae2b..18b102a30741 100644 --- a/arch/arm/include/asm/syscall.h +++ b/arch/arm/include/asm/syscall.h @@ -68,6 +68,30 @@ static inline void syscall_set_return_value(struct task_struct *task, regs->ARM_r0 = (long) error ? error : val; } +static inline void syscall_set_nr(struct task_struct *task, + struct pt_regs *regs, + int nr) +{ + if (nr == -1) { + task_thread_info(task)->abi_syscall = -1; + /* +* When the syscall number is set to -1, the syscall will be +* skipped. In this case the syscall return value has to be +* set explicitly, otherwise the first syscall argument is +* returned as the syscall return value. +*/ + syscall_set_return_value(task, regs, -ENOSYS, 0); + return; + } + if ((IS_ENABLED(CONFIG_AEABI) && !IS_ENABLED(CONFIG_OABI_COMPAT))) { + task_thread_info(task)->abi_syscall = nr; + return; + } + task_thread_info(task)->abi_syscall = + (task_thread_info(task)->abi_syscall & ~__NR_SYSCALL_MASK) | + (nr & __NR_SYSCALL_MASK); +} + #define SYSCALL_MAX_ARGS 7 static inline void syscall_get_arguments(struct task_struct *task, diff --git a/arch/arm64/include/asm/syscall.h b/arch/arm64/include/asm/syscall.h index 76020b66286b..712daa90e643 100644 --- a/arch/arm64/include/asm/syscall.h +++ b/arch/arm64/include/asm/syscall.h @@ -61,6 +61,22 @@ static inline void syscall_set_return_value(struct task_struct *task, regs->regs[0] = val; } +static inline void syscall_set_nr(struct task_struct *task, + struct pt_regs *regs, + int nr) +{ + regs->syscallno = nr; + if (nr == -1) { + /* +* When the syscall number is set to -1, the syscall will be +* skipped. In this case the syscall return value has to be +* set explicitly, otherwise the first syscall argument is +* returned as the syscall return value. +*/ + syscall_set_return_value(task, regs, -ENOSYS, 0); + } +} + #define SYSCALL_MAX_ARGS 6 static inline void syscall_get_arguments(struct task_struct *task, diff --git a/arch/hexagon/include/asm/syscall.h b/arch/hexagon/include/asm/syscall.h index 1024a6548d78..70637261817a 100644 --- a/arch/hexagon/
[PATCH v4 4/7] syscall.h: introduce syscall_set_nr()
Similar to syscall_set_arguments() that complements syscall_get_arguments(), introduce syscall_set_nr() that complements syscall_get_nr(). syscall_set_nr() is going to be needed along with syscall_set_arguments() on all HAVE_ARCH_TRACEHOOK architectures to implement PTRACE_SET_SYSCALL_INFO API. Signed-off-by: Dmitry V. Levin Tested-by: Charlie Jenkins Reviewed-by: Charlie Jenkins --- arch/arc/include/asm/syscall.h| 11 +++ arch/arm/include/asm/syscall.h| 24 arch/arm64/include/asm/syscall.h | 16 arch/hexagon/include/asm/syscall.h| 7 +++ arch/loongarch/include/asm/syscall.h | 7 +++ arch/m68k/include/asm/syscall.h | 7 +++ arch/microblaze/include/asm/syscall.h | 7 +++ arch/mips/include/asm/syscall.h | 14 ++ arch/nios2/include/asm/syscall.h | 5 + arch/openrisc/include/asm/syscall.h | 6 ++ arch/parisc/include/asm/syscall.h | 7 +++ arch/powerpc/include/asm/syscall.h| 10 ++ arch/riscv/include/asm/syscall.h | 7 +++ arch/s390/include/asm/syscall.h | 12 arch/sh/include/asm/syscall_32.h | 12 arch/sparc/include/asm/syscall.h | 12 arch/um/include/asm/syscall-generic.h | 5 + arch/x86/include/asm/syscall.h| 7 +++ arch/xtensa/include/asm/syscall.h | 7 +++ include/asm-generic/syscall.h | 14 ++ 20 files changed, 197 insertions(+) diff --git a/arch/arc/include/asm/syscall.h b/arch/arc/include/asm/syscall.h index 89c1e1736356..728d625a10f1 100644 --- a/arch/arc/include/asm/syscall.h +++ b/arch/arc/include/asm/syscall.h @@ -23,6 +23,17 @@ syscall_get_nr(struct task_struct *task, struct pt_regs *regs) return -1; } +static inline void +syscall_set_nr(struct task_struct *task, struct pt_regs *regs, int nr) +{ + /* +* Unlike syscall_get_nr(), syscall_set_nr() can be called only when +* the target task is stopped for tracing on entering syscall, so +* there is no need to have the same check syscall_get_nr() has. +*/ + regs->r8 = nr; +} + static inline void syscall_rollback(struct task_struct *task, struct pt_regs *regs) { diff --git a/arch/arm/include/asm/syscall.h b/arch/arm/include/asm/syscall.h index 21927fa0ae2b..18b102a30741 100644 --- a/arch/arm/include/asm/syscall.h +++ b/arch/arm/include/asm/syscall.h @@ -68,6 +68,30 @@ static inline void syscall_set_return_value(struct task_struct *task, regs->ARM_r0 = (long) error ? error : val; } +static inline void syscall_set_nr(struct task_struct *task, + struct pt_regs *regs, + int nr) +{ + if (nr == -1) { + task_thread_info(task)->abi_syscall = -1; + /* +* When the syscall number is set to -1, the syscall will be +* skipped. In this case the syscall return value has to be +* set explicitly, otherwise the first syscall argument is +* returned as the syscall return value. +*/ + syscall_set_return_value(task, regs, -ENOSYS, 0); + return; + } + if ((IS_ENABLED(CONFIG_AEABI) && !IS_ENABLED(CONFIG_OABI_COMPAT))) { + task_thread_info(task)->abi_syscall = nr; + return; + } + task_thread_info(task)->abi_syscall = + (task_thread_info(task)->abi_syscall & ~__NR_SYSCALL_MASK) | + (nr & __NR_SYSCALL_MASK); +} + #define SYSCALL_MAX_ARGS 7 static inline void syscall_get_arguments(struct task_struct *task, diff --git a/arch/arm64/include/asm/syscall.h b/arch/arm64/include/asm/syscall.h index 76020b66286b..712daa90e643 100644 --- a/arch/arm64/include/asm/syscall.h +++ b/arch/arm64/include/asm/syscall.h @@ -61,6 +61,22 @@ static inline void syscall_set_return_value(struct task_struct *task, regs->regs[0] = val; } +static inline void syscall_set_nr(struct task_struct *task, + struct pt_regs *regs, + int nr) +{ + regs->syscallno = nr; + if (nr == -1) { + /* +* When the syscall number is set to -1, the syscall will be +* skipped. In this case the syscall return value has to be +* set explicitly, otherwise the first syscall argument is +* returned as the syscall return value. +*/ + syscall_set_return_value(task, regs, -ENOSYS, 0); + } +} + #define SYSCALL_MAX_ARGS 6 static inline void syscall_get_arguments(struct task_struct *task, diff --git a/arch/hexagon/include/asm/syscall.h b/arch/hexagon/include/asm/syscall.h index 1024a6548d78..70637261817a 100644 --- a/arch/hexagon/include/asm/syscall.h +++ b/arc
[PATCH v4 3/7] syscall.h: add syscall_set_arguments()
This function is going to be needed on all HAVE_ARCH_TRACEHOOK architectures to implement PTRACE_SET_SYSCALL_INFO API. This partially reverts commit 7962c2eddbfe ("arch: remove unused function syscall_set_arguments()") by reusing some of old syscall_set_arguments() implementations. Signed-off-by: Dmitry V. Levin Tested-by: Charlie Jenkins Reviewed-by: Charlie Jenkins --- arch/arc/include/asm/syscall.h| 14 +++ arch/arm/include/asm/syscall.h| 13 ++ arch/arm64/include/asm/syscall.h | 13 ++ arch/csky/include/asm/syscall.h | 13 ++ arch/hexagon/include/asm/syscall.h| 7 ++ arch/loongarch/include/asm/syscall.h | 8 ++ arch/mips/include/asm/syscall.h | 32 arch/nios2/include/asm/syscall.h | 11 arch/openrisc/include/asm/syscall.h | 7 ++ arch/parisc/include/asm/syscall.h | 12 + arch/powerpc/include/asm/syscall.h| 10 arch/riscv/include/asm/syscall.h | 9 +++ arch/s390/include/asm/syscall.h | 9 +++ arch/sh/include/asm/syscall_32.h | 12 + arch/sparc/include/asm/syscall.h | 10 arch/um/include/asm/syscall-generic.h | 14 +++ arch/x86/include/asm/syscall.h| 36 +++ arch/xtensa/include/asm/syscall.h | 11 include/asm-generic/syscall.h | 16 19 files changed, 257 insertions(+) diff --git a/arch/arc/include/asm/syscall.h b/arch/arc/include/asm/syscall.h index 9709256e31c8..89c1e1736356 100644 --- a/arch/arc/include/asm/syscall.h +++ b/arch/arc/include/asm/syscall.h @@ -67,6 +67,20 @@ syscall_get_arguments(struct task_struct *task, struct pt_regs *regs, } } +static inline void +syscall_set_arguments(struct task_struct *task, struct pt_regs *regs, + unsigned long *args) +{ + unsigned long *inside_ptregs = ®s->r0; + unsigned int n = 6; + unsigned int i = 0; + + while (n--) { + *inside_ptregs = args[i++]; + inside_ptregs--; + } +} + static inline int syscall_get_arch(struct task_struct *task) { diff --git a/arch/arm/include/asm/syscall.h b/arch/arm/include/asm/syscall.h index fe4326d938c1..21927fa0ae2b 100644 --- a/arch/arm/include/asm/syscall.h +++ b/arch/arm/include/asm/syscall.h @@ -80,6 +80,19 @@ static inline void syscall_get_arguments(struct task_struct *task, memcpy(args, ®s->ARM_r0 + 1, 5 * sizeof(args[0])); } +static inline void syscall_set_arguments(struct task_struct *task, +struct pt_regs *regs, +const unsigned long *args) +{ + memcpy(®s->ARM_r0, args, 6 * sizeof(args[0])); + /* +* Also copy the first argument into ARM_ORIG_r0 +* so that syscall_get_arguments() would return it +* instead of the previous value. +*/ + regs->ARM_ORIG_r0 = regs->ARM_r0; +} + static inline int syscall_get_arch(struct task_struct *task) { /* ARM tasks don't change audit architectures on the fly. */ diff --git a/arch/arm64/include/asm/syscall.h b/arch/arm64/include/asm/syscall.h index ab8e14b96f68..76020b66286b 100644 --- a/arch/arm64/include/asm/syscall.h +++ b/arch/arm64/include/asm/syscall.h @@ -73,6 +73,19 @@ static inline void syscall_get_arguments(struct task_struct *task, memcpy(args, ®s->regs[1], 5 * sizeof(args[0])); } +static inline void syscall_set_arguments(struct task_struct *task, +struct pt_regs *regs, +const unsigned long *args) +{ + memcpy(®s->regs[0], args, 6 * sizeof(args[0])); + /* +* Also copy the first argument into orig_x0 +* so that syscall_get_arguments() would return it +* instead of the previous value. +*/ + regs->orig_x0 = regs->regs[0]; +} + /* * We don't care about endianness (__AUDIT_ARCH_LE bit) here because * AArch64 has the same system calls both on little- and big- endian. diff --git a/arch/csky/include/asm/syscall.h b/arch/csky/include/asm/syscall.h index 0de5734950bf..30403f7a0487 100644 --- a/arch/csky/include/asm/syscall.h +++ b/arch/csky/include/asm/syscall.h @@ -59,6 +59,19 @@ syscall_get_arguments(struct task_struct *task, struct pt_regs *regs, memcpy(args, ®s->a1, 5 * sizeof(args[0])); } +static inline void +syscall_set_arguments(struct task_struct *task, struct pt_regs *regs, + const unsigned long *args) +{ + memcpy(®s->a0, args, 6 * sizeof(regs->a0)); + /* +* Also copy the first argument into orig_x0 +* so that syscall_get_arguments() would return it +* instead of the previous value. +*/ + regs->orig_a0 = regs->a0; +} + static inline int syscall_get_arch(struct task_struct *ta
[PATCH v4 0/7] ptrace: introduce PTRACE_SET_SYSCALL_INFO API
PTRACE_SET_SYSCALL_INFO is a generic ptrace API that complements PTRACE_GET_SYSCALL_INFO by letting the ptracer modify details of system calls the tracee is blocked in. This API allows ptracers to obtain and modify system call details in a straightforward and architecture-agnostic way. Current implementation supports changing only those bits of system call information that are used by strace, namely, syscall number, syscall arguments, and syscall return value. Support of changing additional details returned by PTRACE_GET_SYSCALL_INFO, such as instruction pointer and stack pointer, could be added later if needed, by using struct ptrace_syscall_info.flags to specify the additional details that should be set. Currently, "flags" and "reserved" fields of struct ptrace_syscall_info must be initialized with zeroes; "arch", "instruction_pointer", and "stack_pointer" fields are ignored. PTRACE_SET_SYSCALL_INFO currently supports only PTRACE_SYSCALL_INFO_ENTRY, PTRACE_SYSCALL_INFO_EXIT, and PTRACE_SYSCALL_INFO_SECCOMP operations. Other operations could be added later if needed. Ideally, PTRACE_SET_SYSCALL_INFO should have been introduced along with PTRACE_GET_SYSCALL_INFO, but it didn't happen. The last straw that convinced me to implement PTRACE_SET_SYSCALL_INFO was apparent failure to provide an API of changing the first system call argument on riscv architecture [1]. ptrace(2) man page: long ptrace(enum __ptrace_request request, pid_t pid, void *addr, void *data); ... PTRACE_SET_SYSCALL_INFO Modify information about the system call that caused the stop. The "data" argument is a pointer to struct ptrace_syscall_info that specifies the system call information to be set. The "addr" argument should be set to sizeof(struct ptrace_syscall_info)). [1] https://lore.kernel.org/all/59505464-c84a-403d-972f-d4b2055ee...@gmail.com/ Notes: v4: * Split out syscall_set_return_value() for hexagon into a separate patch * s390: Change the style of syscall_set_arguments() implementation as requested * Add more Reviewed-by * v3: https://lore.kernel.org/all/20250128091445.ga8...@strace.io/ v3: * powerpc: Submit syscall_set_return_value() fix for "sc" case separately * mips: Do not introduce erroneous argument truncation on mips n32, add a detailed description to the commit message of the mips_get_syscall_arg() change * ptrace: Add explicit padding to the end of struct ptrace_syscall_info, simplify obtaining of user ptrace_syscall_info, do not introduce PTRACE_SYSCALL_INFO_SIZE_VER0 * ptrace: Change the return type of ptrace_set_syscall_info_* functions from "unsigned long" to "int" * ptrace: Add -ERANGE check to ptrace_set_syscall_info_exit(), add comments to -ERANGE checks * ptrace: Update comments about supported syscall stops * selftests: Extend set_syscall_info test, fix for mips n32 * Add Tested-by and Reviewed-by v2: * Add patch to fix syscall_set_return_value() on powerpc * Add patch to fix mips_get_syscall_arg() on mips * Add syscall_set_return_value() implementation on hexagon * Add syscall_set_return_value() invocation to syscall_set_nr() on arm and arm64. * Fix syscall_set_nr() and mips_set_syscall_arg() on mips * Add a comment to syscall_set_nr() on arc, powerpc, s390, sh, and sparc * Remove redundant ptrace_syscall_info.op assignments in ptrace_get_syscall_info_* * Minor style tweaks in ptrace_get_syscall_info_op() * Remove syscall_set_return_value() invocation from ptrace_set_syscall_info_entry() * Skip syscall_set_arguments() invocation in case of syscall number -1 in ptrace_set_syscall_info_entry() * Split ptrace_syscall_info.reserved into ptrace_syscall_info.reserved and ptrace_syscall_info.flags * Use __kernel_ulong_t instead of unsigned long in set_syscall_info test v1: Dmitry V. Levin (7): mips: fix mips_get_syscall_arg() for o32 hexagon: add syscall_set_return_value() syscall.h: add syscall_set_arguments() syscall.h: introduce syscall_set_nr() ptrace_get_syscall_info: factor out ptrace_get_syscall_info_op ptrace: introduce PTRACE_SET_SYSCALL_INFO request selftests/ptrace: add a test case for PTRACE_SET_SYSCALL_INFO arch/arc/include/asm/syscall.h| 25 + arch/arm/include/asm/syscall.h| 37 ++ arch/arm64/include/asm/syscall.h | 29 + arch/csky/include/asm/syscall.h | 13 + arch/hexagon/include/asm/syscall.h| 21 + arch/loongarch/include/asm/syscall.h | 15 + arch/m68k/include/asm/syscall.h | 7 + arch/microblaze/include/asm/syscall.h | 7 + arch/mips/include/asm/syscall.h | 70 ++- arch/nios2/include/asm/syscall.h | 16 + a
Re: [PATCH v3 2/6] syscall.h: add syscall_set_arguments() and syscall_set_return_value()
On Thu, Jan 30, 2025 at 09:33:03AM +0100, Sven Schnelle wrote: > "Dmitry V. Levin" writes: > > > These functions are going to be needed on all HAVE_ARCH_TRACEHOOK > > architectures to implement PTRACE_SET_SYSCALL_INFO API. > > > > This partially reverts commit 7962c2eddbfe ("arch: remove unused > > function syscall_set_arguments()") by reusing some of old > > syscall_set_arguments() implementations. > > > > Signed-off-by: Dmitry V. Levin > > Tested-by: Charlie Jenkins > > Reviewed-by: Charlie Jenkins > > --- > > arch/arc/include/asm/syscall.h| 14 +++ > > arch/arm/include/asm/syscall.h| 13 ++ > > arch/arm64/include/asm/syscall.h | 13 ++ > > arch/csky/include/asm/syscall.h | 13 ++ > > arch/hexagon/include/asm/syscall.h| 14 +++ > > arch/loongarch/include/asm/syscall.h | 8 ++ > > arch/mips/include/asm/syscall.h | 32 > > arch/nios2/include/asm/syscall.h | 11 > > arch/openrisc/include/asm/syscall.h | 7 ++ > > arch/parisc/include/asm/syscall.h | 12 + > > arch/powerpc/include/asm/syscall.h| 10 > > arch/riscv/include/asm/syscall.h | 9 +++ > > arch/s390/include/asm/syscall.h | 12 + > > arch/sh/include/asm/syscall_32.h | 12 + > > arch/sparc/include/asm/syscall.h | 10 > > arch/um/include/asm/syscall-generic.h | 14 +++ > > arch/x86/include/asm/syscall.h| 36 +++ > > arch/xtensa/include/asm/syscall.h | 11 > > include/asm-generic/syscall.h | 16 > > 19 files changed, 267 insertions(+) > > > > diff --git a/arch/s390/include/asm/syscall.h > > b/arch/s390/include/asm/syscall.h > > index 27e3d804b311..b3dd883699e7 100644 > > --- a/arch/s390/include/asm/syscall.h > > +++ b/arch/s390/include/asm/syscall.h > > @@ -78,6 +78,18 @@ static inline void syscall_get_arguments(struct > > task_struct *task, > > args[0] = regs->orig_gpr2 & mask; > > } > > > > +static inline void syscall_set_arguments(struct task_struct *task, > > +struct pt_regs *regs, > > +const unsigned long *args) > > +{ > > + unsigned int n = 6; > > + > > + while (n-- > 0) > > + if (n > 0) > > + regs->gprs[2 + n] = args[n]; > > + regs->orig_gpr2 = args[0]; > > +} > > Could that be changed to something like: > > for (int n = 1; n < 6; n++) > regs->gprs[2 + n] = args[n]; > regs->orig_gpr2 = args[0]; > > I think this is way easier to parse. I don't mind changing syscall_set_arguments() this way, but it just mirrors syscall_get_arguments(), so I think it would be better if these two functions were written in the same style. Would you like to change syscall_get_arguments() as well? -- ldv ___ linux-snps-arc mailing list linux-snps-arc@lists.infradead.org http://lists.infradead.org/mailman/listinfo/linux-snps-arc
Re: [PATCH 3/6] syscall.h: introduce syscall_set_nr()
On Fri, Jan 10, 2025 at 08:37:46AM +0100, Sven Schnelle wrote: > "Dmitry V. Levin" writes: > > > Similar to syscall_set_arguments() that complements > > syscall_get_arguments(), introduce syscall_set_nr() > > that complements syscall_get_nr(). > > > > syscall_set_nr() is going to be needed along with > > syscall_set_arguments() on all HAVE_ARCH_TRACEHOOK > > architectures to implement PTRACE_SET_SYSCALL_INFO API. [...] > > diff --git a/arch/s390/include/asm/syscall.h > > b/arch/s390/include/asm/syscall.h > > index b3dd883699e7..1c0e349fd5c9 100644 > > --- a/arch/s390/include/asm/syscall.h > > +++ b/arch/s390/include/asm/syscall.h > > @@ -24,6 +24,13 @@ static inline long syscall_get_nr(struct task_struct > > *task, > > (regs->int_code & 0x) : -1; > > } > > > > +static inline void syscall_set_nr(struct task_struct *task, > > + struct pt_regs *regs, > > + int nr) > > +{ > > I think there should be a > > if (!test_pt_regs_flags(regs, PIF_SYSCALL)) > return; > > before the modification so a user can't accidentally change int_code > when ptrace stopped in a non-syscall path. The reason why syscall_get_nr() has this check on s390 (and similar checks on arc, powerpc, and sparc) is that syscall_get_nr() can be called while the target task is not in syscall. Unlike syscall_get_nr(), syscall_set_nr() can be called only when the target task is stopped for tracing on entering syscall: the description in include/asm-generic/syscall.h explicitly states that, and the follow-up patch that introduces PTRACE_SET_SYSCALL_INFO adds a syscall_set_nr() call when the tracee is stopped on entering syscall in either PTRACE_SYSCALL_INFO_ENTRY or PTRACE_SYSCALL_INFO_SECCOMP state. I don't mind adding a check, but syscall_set_nr() invocation while the target task is not in syscall wouldn't be a result of user actions but a kernel programing error, and in that case WARN_ON_ONCE() would be more appropriate. If calling syscall_set_nr() while the target task is not in syscall was legal, then syscall_set_nr() would have been designed to return a value indicating the status of operation. Anyway, I'll add an explanatory comment to syscall_set_nr() on all architectures where syscall_get_nr() has a check. -- ldv ___ linux-snps-arc mailing list linux-snps-arc@lists.infradead.org http://lists.infradead.org/mailman/listinfo/linux-snps-arc
[PATCH v3 0/6] ptrace: introduce PTRACE_SET_SYSCALL_INFO API
PTRACE_SET_SYSCALL_INFO is a generic ptrace API that complements PTRACE_GET_SYSCALL_INFO by letting the ptracer modify details of system calls the tracee is blocked in. This API allows ptracers to obtain and modify system call details in a straightforward and architecture-agnostic way. Current implementation supports changing only those bits of system call information that are used by strace, namely, syscall number, syscall arguments, and syscall return value. Support of changing additional details returned by PTRACE_GET_SYSCALL_INFO, such as instruction pointer and stack pointer, could be added later if needed, by using struct ptrace_syscall_info.flags to specify the additional details that should be set. Currently, "flags", "reserved", and "seccomp.reserved2" fields of struct ptrace_syscall_info must be initialized with zeroes; "arch", "instruction_pointer", and "stack_pointer" fields are ignored. PTRACE_SET_SYSCALL_INFO currently supports only PTRACE_SYSCALL_INFO_ENTRY, PTRACE_SYSCALL_INFO_EXIT, and PTRACE_SYSCALL_INFO_SECCOMP operations. Other operations could be added later if needed. Ideally, PTRACE_SET_SYSCALL_INFO should have been introduced along with PTRACE_GET_SYSCALL_INFO, but it didn't happen. The last straw that convinced me to implement PTRACE_SET_SYSCALL_INFO was apparent failure to provide an API of changing the first system call argument on riscv architecture [1]. ptrace(2) man page: long ptrace(enum __ptrace_request request, pid_t pid, void *addr, void *data); ... PTRACE_SET_SYSCALL_INFO Modify information about the system call that caused the stop. The "data" argument is a pointer to struct ptrace_syscall_info that specifies the system call information to be set. The "addr" argument should be set to sizeof(struct ptrace_syscall_info)). [1] https://lore.kernel.org/all/59505464-c84a-403d-972f-d4b2055ee...@gmail.com/ Notes: v3: * powerpc: Submit syscall_set_return_value fix for "sc" case separately * mips: Do not introduce erroneous argument truncation on mips n32, add a detailed description to the commit message of the mips_get_syscall_arg change * ptrace: Add explicit padding to the end of struct ptrace_syscall_info, simplify obtaining of user ptrace_syscall_info, do not introduce PTRACE_SYSCALL_INFO_SIZE_VER0 * ptrace: Change the return type of ptrace_set_syscall_info_* functions from "unsigned long" to "int" * ptrace: Add -ERANGE check to ptrace_set_syscall_info_exit, add comments to -ERANGE checks * ptrace: Update comments about supported syscall stops * selftests: Extend set_syscall_info test, fix for mips n32 * Add Tested-by and Reviewed-by v2: * Add patch to fix syscall_set_return_value() on powerpc * Add patch to fix mips_get_syscall_arg() on mips * Add syscall_set_return_value() implementation on hexagon * Add syscall_set_return_value() invocation to syscall_set_nr() on arm and arm64. * Fix syscall_set_nr() and mips_set_syscall_arg() on mips * Add a comment to syscall_set_nr() on arc, powerpc, s390, sh, and sparc * Remove redundant ptrace_syscall_info.op assignments in ptrace_get_syscall_info_* * Minor style tweaks in ptrace_get_syscall_info_op() * Remove syscall_set_return_value() invocation from ptrace_set_syscall_info_entry() * Skip syscall_set_arguments() invocation in case of syscall number -1 in ptrace_set_syscall_info_entry() * Split ptrace_syscall_info.reserved into ptrace_syscall_info.reserved and ptrace_syscall_info.flags * Use __kernel_ulong_t instead of unsigned long in set_syscall_info test Dmitry V. Levin (6): mips: fix mips_get_syscall_arg() for o32 syscall.h: add syscall_set_arguments() and syscall_set_return_value() syscall.h: introduce syscall_set_nr() ptrace_get_syscall_info: factor out ptrace_get_syscall_info_op ptrace: introduce PTRACE_SET_SYSCALL_INFO request selftests/ptrace: add a test case for PTRACE_SET_SYSCALL_INFO arch/arc/include/asm/syscall.h| 25 + arch/arm/include/asm/syscall.h| 37 ++ arch/arm64/include/asm/syscall.h | 29 + arch/csky/include/asm/syscall.h | 13 + arch/hexagon/include/asm/syscall.h| 21 + arch/loongarch/include/asm/syscall.h | 15 + arch/m68k/include/asm/syscall.h | 7 + arch/microblaze/include/asm/syscall.h | 7 + arch/mips/include/asm/syscall.h | 70 ++- arch/nios2/include/asm/syscall.h | 16 + arch/openrisc/include/asm/syscall.h | 13 + arch/parisc/include/asm/syscall.h | 19 + arch/powerpc/include/asm/syscall.h| 20 + arch/riscv/include/asm/syscall.h | 16 + arch/s390/include/asm/syscall.h | 24 +
[PATCH v3 2/6] syscall.h: add syscall_set_arguments() and syscall_set_return_value()
These functions are going to be needed on all HAVE_ARCH_TRACEHOOK architectures to implement PTRACE_SET_SYSCALL_INFO API. This partially reverts commit 7962c2eddbfe ("arch: remove unused function syscall_set_arguments()") by reusing some of old syscall_set_arguments() implementations. Signed-off-by: Dmitry V. Levin Tested-by: Charlie Jenkins Reviewed-by: Charlie Jenkins --- arch/arc/include/asm/syscall.h| 14 +++ arch/arm/include/asm/syscall.h| 13 ++ arch/arm64/include/asm/syscall.h | 13 ++ arch/csky/include/asm/syscall.h | 13 ++ arch/hexagon/include/asm/syscall.h| 14 +++ arch/loongarch/include/asm/syscall.h | 8 ++ arch/mips/include/asm/syscall.h | 32 arch/nios2/include/asm/syscall.h | 11 arch/openrisc/include/asm/syscall.h | 7 ++ arch/parisc/include/asm/syscall.h | 12 + arch/powerpc/include/asm/syscall.h| 10 arch/riscv/include/asm/syscall.h | 9 +++ arch/s390/include/asm/syscall.h | 12 + arch/sh/include/asm/syscall_32.h | 12 + arch/sparc/include/asm/syscall.h | 10 arch/um/include/asm/syscall-generic.h | 14 +++ arch/x86/include/asm/syscall.h| 36 +++ arch/xtensa/include/asm/syscall.h | 11 include/asm-generic/syscall.h | 16 19 files changed, 267 insertions(+) diff --git a/arch/arc/include/asm/syscall.h b/arch/arc/include/asm/syscall.h index 9709256e31c8..89c1e1736356 100644 --- a/arch/arc/include/asm/syscall.h +++ b/arch/arc/include/asm/syscall.h @@ -67,6 +67,20 @@ syscall_get_arguments(struct task_struct *task, struct pt_regs *regs, } } +static inline void +syscall_set_arguments(struct task_struct *task, struct pt_regs *regs, + unsigned long *args) +{ + unsigned long *inside_ptregs = ®s->r0; + unsigned int n = 6; + unsigned int i = 0; + + while (n--) { + *inside_ptregs = args[i++]; + inside_ptregs--; + } +} + static inline int syscall_get_arch(struct task_struct *task) { diff --git a/arch/arm/include/asm/syscall.h b/arch/arm/include/asm/syscall.h index fe4326d938c1..21927fa0ae2b 100644 --- a/arch/arm/include/asm/syscall.h +++ b/arch/arm/include/asm/syscall.h @@ -80,6 +80,19 @@ static inline void syscall_get_arguments(struct task_struct *task, memcpy(args, ®s->ARM_r0 + 1, 5 * sizeof(args[0])); } +static inline void syscall_set_arguments(struct task_struct *task, +struct pt_regs *regs, +const unsigned long *args) +{ + memcpy(®s->ARM_r0, args, 6 * sizeof(args[0])); + /* +* Also copy the first argument into ARM_ORIG_r0 +* so that syscall_get_arguments() would return it +* instead of the previous value. +*/ + regs->ARM_ORIG_r0 = regs->ARM_r0; +} + static inline int syscall_get_arch(struct task_struct *task) { /* ARM tasks don't change audit architectures on the fly. */ diff --git a/arch/arm64/include/asm/syscall.h b/arch/arm64/include/asm/syscall.h index ab8e14b96f68..76020b66286b 100644 --- a/arch/arm64/include/asm/syscall.h +++ b/arch/arm64/include/asm/syscall.h @@ -73,6 +73,19 @@ static inline void syscall_get_arguments(struct task_struct *task, memcpy(args, ®s->regs[1], 5 * sizeof(args[0])); } +static inline void syscall_set_arguments(struct task_struct *task, +struct pt_regs *regs, +const unsigned long *args) +{ + memcpy(®s->regs[0], args, 6 * sizeof(args[0])); + /* +* Also copy the first argument into orig_x0 +* so that syscall_get_arguments() would return it +* instead of the previous value. +*/ + regs->orig_x0 = regs->regs[0]; +} + /* * We don't care about endianness (__AUDIT_ARCH_LE bit) here because * AArch64 has the same system calls both on little- and big- endian. diff --git a/arch/csky/include/asm/syscall.h b/arch/csky/include/asm/syscall.h index 0de5734950bf..30403f7a0487 100644 --- a/arch/csky/include/asm/syscall.h +++ b/arch/csky/include/asm/syscall.h @@ -59,6 +59,19 @@ syscall_get_arguments(struct task_struct *task, struct pt_regs *regs, memcpy(args, ®s->a1, 5 * sizeof(args[0])); } +static inline void +syscall_set_arguments(struct task_struct *task, struct pt_regs *regs, + const unsigned long *args) +{ + memcpy(®s->a0, args, 6 * sizeof(regs->a0)); + /* +* Also copy the first argument into orig_x0 +* so that syscall_get_arguments() would return it +* instead of the previous value. +*/ + regs->orig_a0 = regs->a0; +} + static inline int syscall_get_arch(struct task_struc
[PATCH v3 3/6] syscall.h: introduce syscall_set_nr()
Similar to syscall_set_arguments() that complements syscall_get_arguments(), introduce syscall_set_nr() that complements syscall_get_nr(). syscall_set_nr() is going to be needed along with syscall_set_arguments() on all HAVE_ARCH_TRACEHOOK architectures to implement PTRACE_SET_SYSCALL_INFO API. Signed-off-by: Dmitry V. Levin Tested-by: Charlie Jenkins Reviewed-by: Charlie Jenkins --- arch/arc/include/asm/syscall.h| 11 +++ arch/arm/include/asm/syscall.h| 24 arch/arm64/include/asm/syscall.h | 16 arch/hexagon/include/asm/syscall.h| 7 +++ arch/loongarch/include/asm/syscall.h | 7 +++ arch/m68k/include/asm/syscall.h | 7 +++ arch/microblaze/include/asm/syscall.h | 7 +++ arch/mips/include/asm/syscall.h | 14 ++ arch/nios2/include/asm/syscall.h | 5 + arch/openrisc/include/asm/syscall.h | 6 ++ arch/parisc/include/asm/syscall.h | 7 +++ arch/powerpc/include/asm/syscall.h| 10 ++ arch/riscv/include/asm/syscall.h | 7 +++ arch/s390/include/asm/syscall.h | 12 arch/sh/include/asm/syscall_32.h | 12 arch/sparc/include/asm/syscall.h | 12 arch/um/include/asm/syscall-generic.h | 5 + arch/x86/include/asm/syscall.h| 7 +++ arch/xtensa/include/asm/syscall.h | 7 +++ include/asm-generic/syscall.h | 14 ++ 20 files changed, 197 insertions(+) diff --git a/arch/arc/include/asm/syscall.h b/arch/arc/include/asm/syscall.h index 89c1e1736356..728d625a10f1 100644 --- a/arch/arc/include/asm/syscall.h +++ b/arch/arc/include/asm/syscall.h @@ -23,6 +23,17 @@ syscall_get_nr(struct task_struct *task, struct pt_regs *regs) return -1; } +static inline void +syscall_set_nr(struct task_struct *task, struct pt_regs *regs, int nr) +{ + /* +* Unlike syscall_get_nr(), syscall_set_nr() can be called only when +* the target task is stopped for tracing on entering syscall, so +* there is no need to have the same check syscall_get_nr() has. +*/ + regs->r8 = nr; +} + static inline void syscall_rollback(struct task_struct *task, struct pt_regs *regs) { diff --git a/arch/arm/include/asm/syscall.h b/arch/arm/include/asm/syscall.h index 21927fa0ae2b..18b102a30741 100644 --- a/arch/arm/include/asm/syscall.h +++ b/arch/arm/include/asm/syscall.h @@ -68,6 +68,30 @@ static inline void syscall_set_return_value(struct task_struct *task, regs->ARM_r0 = (long) error ? error : val; } +static inline void syscall_set_nr(struct task_struct *task, + struct pt_regs *regs, + int nr) +{ + if (nr == -1) { + task_thread_info(task)->abi_syscall = -1; + /* +* When the syscall number is set to -1, the syscall will be +* skipped. In this case the syscall return value has to be +* set explicitly, otherwise the first syscall argument is +* returned as the syscall return value. +*/ + syscall_set_return_value(task, regs, -ENOSYS, 0); + return; + } + if ((IS_ENABLED(CONFIG_AEABI) && !IS_ENABLED(CONFIG_OABI_COMPAT))) { + task_thread_info(task)->abi_syscall = nr; + return; + } + task_thread_info(task)->abi_syscall = + (task_thread_info(task)->abi_syscall & ~__NR_SYSCALL_MASK) | + (nr & __NR_SYSCALL_MASK); +} + #define SYSCALL_MAX_ARGS 7 static inline void syscall_get_arguments(struct task_struct *task, diff --git a/arch/arm64/include/asm/syscall.h b/arch/arm64/include/asm/syscall.h index 76020b66286b..712daa90e643 100644 --- a/arch/arm64/include/asm/syscall.h +++ b/arch/arm64/include/asm/syscall.h @@ -61,6 +61,22 @@ static inline void syscall_set_return_value(struct task_struct *task, regs->regs[0] = val; } +static inline void syscall_set_nr(struct task_struct *task, + struct pt_regs *regs, + int nr) +{ + regs->syscallno = nr; + if (nr == -1) { + /* +* When the syscall number is set to -1, the syscall will be +* skipped. In this case the syscall return value has to be +* set explicitly, otherwise the first syscall argument is +* returned as the syscall return value. +*/ + syscall_set_return_value(task, regs, -ENOSYS, 0); + } +} + #define SYSCALL_MAX_ARGS 6 static inline void syscall_get_arguments(struct task_struct *task, diff --git a/arch/hexagon/include/asm/syscall.h b/arch/hexagon/include/asm/syscall.h index 1024a6548d78..70637261817a 100644 --- a/arch/hexagon/include/asm/syscall.h +++ b/arc
Re: [PATCH v3 2/6] syscall.h: add syscall_set_arguments() and syscall_set_return_value()
On Tue, Jan 28, 2025 at 04:04:34PM +0100, Christophe Leroy wrote: > Le 28/01/2025 à 10:16, Dmitry V. Levin a écrit : > > These functions are going to be needed on all HAVE_ARCH_TRACEHOOK > > architectures to implement PTRACE_SET_SYSCALL_INFO API. > > The subject is misleading. syscall_set_return_value() already exists on > most architectures and was not addressed by commit 7962c2eddbfe. > > Maybe it would be better to handle syscall_set_return_value() in a > separate commit. syscall_set_return_value() is being added only on hexagon. I didn't think it worth a separate commit, but it's certainly possible to split this commit into two. -- ldv ___ linux-snps-arc mailing list linux-snps-arc@lists.infradead.org http://lists.infradead.org/mailman/listinfo/linux-snps-arc
Re: [PATCH v3 3/6] syscall.h: introduce syscall_set_nr()
On Tue, Jan 28, 2025 at 04:13:52PM +0100, Christophe Leroy wrote: > Le 28/01/2025 à 10:16, Dmitry V. Levin a écrit : > > Similar to syscall_set_arguments() that complements > > syscall_get_arguments(), introduce syscall_set_nr() > > that complements syscall_get_nr(). > > > > syscall_set_nr() is going to be needed along with > > syscall_set_arguments() on all HAVE_ARCH_TRACEHOOK > > architectures to implement PTRACE_SET_SYSCALL_INFO API. > > > > Signed-off-by: Dmitry V. Levin > > Tested-by: Charlie Jenkins > > Reviewed-by: Charlie Jenkins > > --- > > arch/arc/include/asm/syscall.h| 11 +++ > > arch/arm/include/asm/syscall.h| 24 > > arch/arm64/include/asm/syscall.h | 16 > > arch/hexagon/include/asm/syscall.h| 7 +++ > > arch/loongarch/include/asm/syscall.h | 7 +++ > > arch/m68k/include/asm/syscall.h | 7 +++ > > arch/microblaze/include/asm/syscall.h | 7 +++ > > arch/mips/include/asm/syscall.h | 14 ++ > > arch/nios2/include/asm/syscall.h | 5 + > > arch/openrisc/include/asm/syscall.h | 6 ++ > > arch/parisc/include/asm/syscall.h | 7 +++ > > arch/powerpc/include/asm/syscall.h| 10 ++ > > arch/riscv/include/asm/syscall.h | 7 +++ > > arch/s390/include/asm/syscall.h | 12 > > arch/sh/include/asm/syscall_32.h | 12 > > arch/sparc/include/asm/syscall.h | 12 > > arch/um/include/asm/syscall-generic.h | 5 + > > arch/x86/include/asm/syscall.h| 7 +++ > > arch/xtensa/include/asm/syscall.h | 7 +++ > > include/asm-generic/syscall.h | 14 ++ > > 20 files changed, 197 insertions(+) > > > > > diff --git a/arch/arm64/include/asm/syscall.h > > b/arch/arm64/include/asm/syscall.h > > index 76020b66286b..712daa90e643 100644 > > --- a/arch/arm64/include/asm/syscall.h > > +++ b/arch/arm64/include/asm/syscall.h > > @@ -61,6 +61,22 @@ static inline void syscall_set_return_value(struct > > task_struct *task, > > regs->regs[0] = val; > > } > > > > +static inline void syscall_set_nr(struct task_struct *task, > > + struct pt_regs *regs, > > + int nr) > > +{ > > + regs->syscallno = nr; > > + if (nr == -1) { > > + /* > > +* When the syscall number is set to -1, the syscall will be > > +* skipped. In this case the syscall return value has to be > > +* set explicitly, otherwise the first syscall argument is > > +* returned as the syscall return value. > > +*/ > > + syscall_set_return_value(task, regs, -ENOSYS, 0); > > + } > > +} > > + > > #define SYSCALL_MAX_ARGS 6 > > > > static inline void syscall_get_arguments(struct task_struct *task, > > > diff --git a/arch/powerpc/include/asm/syscall.h > > b/arch/powerpc/include/asm/syscall.h > > index 521f279e6b33..7505dcfed247 100644 > > --- a/arch/powerpc/include/asm/syscall.h > > +++ b/arch/powerpc/include/asm/syscall.h > > @@ -39,6 +39,16 @@ static inline int syscall_get_nr(struct task_struct > > *task, struct pt_regs *regs) > > return -1; > > } > > > > +static inline void syscall_set_nr(struct task_struct *task, struct pt_regs > > *regs, int nr) > > +{ > > + /* > > +* Unlike syscall_get_nr(), syscall_set_nr() can be called only when > > +* the target task is stopped for tracing on entering syscall, so > > +* there is no need to have the same check syscall_get_nr() has. > > +*/ > > + regs->gpr[0] = nr; > > Doesn't the same as for ARM64 apply here as well ? I carefully checked all affected architectures and added that syscall_set_return_value() call only where I think it's needed. On powerpc it's not needed with the current implementation: their do_seccomp() sets -ENOSYS before __secure_computing() invocation, and their do_syscall_trace_enter() sets -ENOSYS in case of an invalid syscall number. -- ldv ___ linux-snps-arc mailing list linux-snps-arc@lists.infradead.org http://lists.infradead.org/mailman/listinfo/linux-snps-arc
[PATCH v2 0/7] ptrace: introduce PTRACE_SET_SYSCALL_INFO API
PTRACE_SET_SYSCALL_INFO is a generic ptrace API that complements PTRACE_GET_SYSCALL_INFO by letting the ptracer modify details of system calls the tracee is blocked in. This API allows ptracers to obtain and modify system call details in a straightforward and architecture-agnostic way. Current implementation supports changing only those bits of system call information that are used by strace, namely, syscall number, syscall arguments, and syscall return value. Support of changing additional details returned by PTRACE_GET_SYSCALL_INFO, such as instruction pointer and stack pointer, could be added later if needed, by using struct ptrace_syscall_info.flags to specify the additional details that should be set. Currently, flags and reserved fields of struct ptrace_syscall_info must be initialized with zeroes; arch, instruction_pointer, and stack_pointer fields are ignored. PTRACE_SET_SYSCALL_INFO currently supports only PTRACE_SYSCALL_INFO_ENTRY, PTRACE_SYSCALL_INFO_EXIT, and PTRACE_SYSCALL_INFO_SECCOMP operations. Other operations could be added later if needed. Ideally, PTRACE_SET_SYSCALL_INFO should have been introduced along with PTRACE_GET_SYSCALL_INFO, but it didn't happen. The last straw that convinced me to implement PTRACE_SET_SYSCALL_INFO was apparent failure to provide an API of changing the first system call argument on riscv architecture [1]. ptrace(2) man page: long ptrace(enum __ptrace_request request, pid_t pid, void *addr, void *data); ... PTRACE_SET_SYSCALL_INFO Modify information about the system call that caused the stop. The "data" argument is a pointer to struct ptrace_syscall_info that specifies the system call information to be set. The "addr" argument should be set to sizeof(struct ptrace_syscall_info)). [1] https://lore.kernel.org/all/59505464-c84a-403d-972f-d4b2055ee...@gmail.com/ --- Notes: v2: * Add patch to fix syscall_set_return_value() on powerpc * Add patch to fix mips_get_syscall_arg() on mips * Merge two patches adding syscall_set_arguments() implementations from different sources into a single patch * Add syscall_set_return_value() implementation on hexagon * Add syscall_set_return_value() invocation to syscall_set_nr() on arm and arm64. * Fix syscall_set_nr() and mips_set_syscall_arg() on mips * Add a comment to syscall_set_nr() on arc, powerpc, s390, sh, and sparc * Remove redundant ptrace_syscall_info.op assignments in ptrace_get_syscall_info_* * Minor style tweaks in ptrace_get_syscall_info_op() * Remove syscall_set_return_value() invocation from ptrace_set_syscall_info_entry() * Skip syscall_set_arguments() invocation in case of syscall number -1 in ptrace_set_syscall_info_entry() * Split ptrace_syscall_info.reserved into ptrace_syscall_info.reserved and ptrace_syscall_info.flags * Use __kernel_ulong_t instead of unsigned long in set_syscall_info test Dmitry V. Levin (7): powerpc: properly negate error in syscall_set_return_value() mips: fix mips_get_syscall_arg() for O32 and N32 syscall.h: add syscall_set_arguments() and syscall_set_return_value() syscall.h: introduce syscall_set_nr() ptrace_get_syscall_info: factor out ptrace_get_syscall_info_op ptrace: introduce PTRACE_SET_SYSCALL_INFO request selftests/ptrace: add a test case for PTRACE_SET_SYSCALL_INFO arch/arc/include/asm/syscall.h| 25 + arch/arm/include/asm/syscall.h| 37 ++ arch/arm64/include/asm/syscall.h | 29 ++ arch/csky/include/asm/syscall.h | 13 + arch/hexagon/include/asm/syscall.h| 21 + arch/loongarch/include/asm/syscall.h | 15 + arch/m68k/include/asm/syscall.h | 7 + arch/microblaze/include/asm/syscall.h | 7 + arch/mips/include/asm/syscall.h | 72 ++- arch/nios2/include/asm/syscall.h | 16 + arch/openrisc/include/asm/syscall.h | 13 + arch/parisc/include/asm/syscall.h | 19 + arch/powerpc/include/asm/syscall.h| 26 +- arch/riscv/include/asm/syscall.h | 16 + arch/s390/include/asm/syscall.h | 24 + arch/sh/include/asm/syscall_32.h | 24 + arch/sparc/include/asm/syscall.h | 22 + arch/um/include/asm/syscall-generic.h | 19 + arch/x86/include/asm/syscall.h| 43 ++ arch/xtensa/include/asm/syscall.h | 18 + include/asm-generic/syscall.h | 30 ++ include/linux/ptrace.h| 3 + include/uapi/linux/ptrace.h | 4 +- kernel/ptrace.c | 153 +- tools/testing/selftests/ptrace/Makefile | 2 +- .../selftests/ptrace/set_syscall_info.c | 441 ++ 26 files changed, 1052 insertions(+), 47 deletions(-) create mode 100644 tools/testing/selftests/
[PATCH v2 4/7] syscall.h: introduce syscall_set_nr()
Similar to syscall_set_arguments() that complements syscall_get_arguments(), introduce syscall_set_nr() that complements syscall_get_nr(). syscall_set_nr() is going to be needed along with syscall_set_arguments() on all HAVE_ARCH_TRACEHOOK architectures to implement PTRACE_SET_SYSCALL_INFO API. Signed-off-by: Dmitry V. Levin --- arch/arc/include/asm/syscall.h| 11 +++ arch/arm/include/asm/syscall.h| 24 arch/arm64/include/asm/syscall.h | 16 arch/hexagon/include/asm/syscall.h| 7 +++ arch/loongarch/include/asm/syscall.h | 7 +++ arch/m68k/include/asm/syscall.h | 7 +++ arch/microblaze/include/asm/syscall.h | 7 +++ arch/mips/include/asm/syscall.h | 14 ++ arch/nios2/include/asm/syscall.h | 5 + arch/openrisc/include/asm/syscall.h | 6 ++ arch/parisc/include/asm/syscall.h | 7 +++ arch/powerpc/include/asm/syscall.h| 10 ++ arch/riscv/include/asm/syscall.h | 7 +++ arch/s390/include/asm/syscall.h | 12 arch/sh/include/asm/syscall_32.h | 12 arch/sparc/include/asm/syscall.h | 12 arch/um/include/asm/syscall-generic.h | 5 + arch/x86/include/asm/syscall.h| 7 +++ arch/xtensa/include/asm/syscall.h | 7 +++ include/asm-generic/syscall.h | 14 ++ 20 files changed, 197 insertions(+) diff --git a/arch/arc/include/asm/syscall.h b/arch/arc/include/asm/syscall.h index 89c1e1736356..728d625a10f1 100644 --- a/arch/arc/include/asm/syscall.h +++ b/arch/arc/include/asm/syscall.h @@ -23,6 +23,17 @@ syscall_get_nr(struct task_struct *task, struct pt_regs *regs) return -1; } +static inline void +syscall_set_nr(struct task_struct *task, struct pt_regs *regs, int nr) +{ + /* +* Unlike syscall_get_nr(), syscall_set_nr() can be called only when +* the target task is stopped for tracing on entering syscall, so +* there is no need to have the same check syscall_get_nr() has. +*/ + regs->r8 = nr; +} + static inline void syscall_rollback(struct task_struct *task, struct pt_regs *regs) { diff --git a/arch/arm/include/asm/syscall.h b/arch/arm/include/asm/syscall.h index 21927fa0ae2b..18b102a30741 100644 --- a/arch/arm/include/asm/syscall.h +++ b/arch/arm/include/asm/syscall.h @@ -68,6 +68,30 @@ static inline void syscall_set_return_value(struct task_struct *task, regs->ARM_r0 = (long) error ? error : val; } +static inline void syscall_set_nr(struct task_struct *task, + struct pt_regs *regs, + int nr) +{ + if (nr == -1) { + task_thread_info(task)->abi_syscall = -1; + /* +* When the syscall number is set to -1, the syscall will be +* skipped. In this case the syscall return value has to be +* set explicitly, otherwise the first syscall argument is +* returned as the syscall return value. +*/ + syscall_set_return_value(task, regs, -ENOSYS, 0); + return; + } + if ((IS_ENABLED(CONFIG_AEABI) && !IS_ENABLED(CONFIG_OABI_COMPAT))) { + task_thread_info(task)->abi_syscall = nr; + return; + } + task_thread_info(task)->abi_syscall = + (task_thread_info(task)->abi_syscall & ~__NR_SYSCALL_MASK) | + (nr & __NR_SYSCALL_MASK); +} + #define SYSCALL_MAX_ARGS 7 static inline void syscall_get_arguments(struct task_struct *task, diff --git a/arch/arm64/include/asm/syscall.h b/arch/arm64/include/asm/syscall.h index 76020b66286b..712daa90e643 100644 --- a/arch/arm64/include/asm/syscall.h +++ b/arch/arm64/include/asm/syscall.h @@ -61,6 +61,22 @@ static inline void syscall_set_return_value(struct task_struct *task, regs->regs[0] = val; } +static inline void syscall_set_nr(struct task_struct *task, + struct pt_regs *regs, + int nr) +{ + regs->syscallno = nr; + if (nr == -1) { + /* +* When the syscall number is set to -1, the syscall will be +* skipped. In this case the syscall return value has to be +* set explicitly, otherwise the first syscall argument is +* returned as the syscall return value. +*/ + syscall_set_return_value(task, regs, -ENOSYS, 0); + } +} + #define SYSCALL_MAX_ARGS 6 static inline void syscall_get_arguments(struct task_struct *task, diff --git a/arch/hexagon/include/asm/syscall.h b/arch/hexagon/include/asm/syscall.h index 1024a6548d78..70637261817a 100644 --- a/arch/hexagon/include/asm/syscall.h +++ b/arch/hexagon/include/asm/syscall.h @@ -26,6 +26,13 @@
[PATCH v2 3/7] syscall.h: add syscall_set_arguments() and syscall_set_return_value()
These functions are going to be needed on all HAVE_ARCH_TRACEHOOK architectures to implement PTRACE_SET_SYSCALL_INFO API. This partially reverts commit 7962c2eddbfe ("arch: remove unused function syscall_set_arguments()") by reusing some of old syscall_set_arguments() implementations. Signed-off-by: Dmitry V. Levin --- Note that I'm not a MIPS expert, I just added mips_set_syscall_arg() by looking at mips_get_syscall_arg() and the result passes tests in qemu on mips O32, mips64 O32, mips64 N32, and mips64 N64. arch/arc/include/asm/syscall.h| 14 +++ arch/arm/include/asm/syscall.h| 13 ++ arch/arm64/include/asm/syscall.h | 13 ++ arch/csky/include/asm/syscall.h | 13 ++ arch/hexagon/include/asm/syscall.h| 14 +++ arch/loongarch/include/asm/syscall.h | 8 ++ arch/mips/include/asm/syscall.h | 32 arch/nios2/include/asm/syscall.h | 11 arch/openrisc/include/asm/syscall.h | 7 ++ arch/parisc/include/asm/syscall.h | 12 + arch/powerpc/include/asm/syscall.h| 10 arch/riscv/include/asm/syscall.h | 9 +++ arch/s390/include/asm/syscall.h | 12 + arch/sh/include/asm/syscall_32.h | 12 + arch/sparc/include/asm/syscall.h | 10 arch/um/include/asm/syscall-generic.h | 14 +++ arch/x86/include/asm/syscall.h| 36 +++ arch/xtensa/include/asm/syscall.h | 11 include/asm-generic/syscall.h | 16 19 files changed, 267 insertions(+) diff --git a/arch/arc/include/asm/syscall.h b/arch/arc/include/asm/syscall.h index 9709256e31c8..89c1e1736356 100644 --- a/arch/arc/include/asm/syscall.h +++ b/arch/arc/include/asm/syscall.h @@ -67,6 +67,20 @@ syscall_get_arguments(struct task_struct *task, struct pt_regs *regs, } } +static inline void +syscall_set_arguments(struct task_struct *task, struct pt_regs *regs, + unsigned long *args) +{ + unsigned long *inside_ptregs = ®s->r0; + unsigned int n = 6; + unsigned int i = 0; + + while (n--) { + *inside_ptregs = args[i++]; + inside_ptregs--; + } +} + static inline int syscall_get_arch(struct task_struct *task) { diff --git a/arch/arm/include/asm/syscall.h b/arch/arm/include/asm/syscall.h index fe4326d938c1..21927fa0ae2b 100644 --- a/arch/arm/include/asm/syscall.h +++ b/arch/arm/include/asm/syscall.h @@ -80,6 +80,19 @@ static inline void syscall_get_arguments(struct task_struct *task, memcpy(args, ®s->ARM_r0 + 1, 5 * sizeof(args[0])); } +static inline void syscall_set_arguments(struct task_struct *task, +struct pt_regs *regs, +const unsigned long *args) +{ + memcpy(®s->ARM_r0, args, 6 * sizeof(args[0])); + /* +* Also copy the first argument into ARM_ORIG_r0 +* so that syscall_get_arguments() would return it +* instead of the previous value. +*/ + regs->ARM_ORIG_r0 = regs->ARM_r0; +} + static inline int syscall_get_arch(struct task_struct *task) { /* ARM tasks don't change audit architectures on the fly. */ diff --git a/arch/arm64/include/asm/syscall.h b/arch/arm64/include/asm/syscall.h index ab8e14b96f68..76020b66286b 100644 --- a/arch/arm64/include/asm/syscall.h +++ b/arch/arm64/include/asm/syscall.h @@ -73,6 +73,19 @@ static inline void syscall_get_arguments(struct task_struct *task, memcpy(args, ®s->regs[1], 5 * sizeof(args[0])); } +static inline void syscall_set_arguments(struct task_struct *task, +struct pt_regs *regs, +const unsigned long *args) +{ + memcpy(®s->regs[0], args, 6 * sizeof(args[0])); + /* +* Also copy the first argument into orig_x0 +* so that syscall_get_arguments() would return it +* instead of the previous value. +*/ + regs->orig_x0 = regs->regs[0]; +} + /* * We don't care about endianness (__AUDIT_ARCH_LE bit) here because * AArch64 has the same system calls both on little- and big- endian. diff --git a/arch/csky/include/asm/syscall.h b/arch/csky/include/asm/syscall.h index 0de5734950bf..30403f7a0487 100644 --- a/arch/csky/include/asm/syscall.h +++ b/arch/csky/include/asm/syscall.h @@ -59,6 +59,19 @@ syscall_get_arguments(struct task_struct *task, struct pt_regs *regs, memcpy(args, ®s->a1, 5 * sizeof(args[0])); } +static inline void +syscall_set_arguments(struct task_struct *task, struct pt_regs *regs, + const unsigned long *args) +{ + memcpy(®s->a0, args, 6 * sizeof(regs->a0)); + /* +* Also copy the first argument into orig_x0 +* so that syscall_get_arguments() would return it +
Re: [PATCH 2/6] syscall.h: add syscall_set_arguments() on remaining HAVE_ARCH_TRACEHOOK arches
On Thu, Jan 09, 2025 at 01:04:53PM +0100, Oleg Nesterov wrote: > On 01/08, Dmitry V. Levin wrote: > > > > arch/arc/include/asm/syscall.h | 14 + > > arch/arm/include/asm/syscall.h | 13 > > arch/arm64/include/asm/syscall.h | 13 > > arch/csky/include/asm/syscall.h | 13 > > arch/hexagon/include/asm/syscall.h | 7 + > > arch/loongarch/include/asm/syscall.h | 8 + > > arch/mips/include/asm/syscall.h | 46 > > arch/parisc/include/asm/syscall.h| 12 > > Confused... arch/x86 needs syscall_set_arguments() too ? Sure, all HAVE_ARCH_TRACEHOOK architectures need them, but most of these architectures already provide them since the previous patch in the series: [PATCH 1/6] Revert "arch: remove unused function syscall_set_arguments()" -- ldv ___ linux-snps-arc mailing list linux-snps-arc@lists.infradead.org http://lists.infradead.org/mailman/listinfo/linux-snps-arc
[PATCH v7 3/6] syscall.h: introduce syscall_set_nr()
Similar to syscall_set_arguments() that complements syscall_get_arguments(), introduce syscall_set_nr() that complements syscall_get_nr(). syscall_set_nr() is going to be needed along with syscall_set_arguments() on all HAVE_ARCH_TRACEHOOK architectures to implement PTRACE_SET_SYSCALL_INFO API. Signed-off-by: Dmitry V. Levin Tested-by: Charlie Jenkins Reviewed-by: Charlie Jenkins Acked-by: Helge Deller # parisc Reviewed-by: Maciej W. Rozycki # mips --- arch/arc/include/asm/syscall.h| 11 +++ arch/arm/include/asm/syscall.h| 24 arch/arm64/include/asm/syscall.h | 16 arch/hexagon/include/asm/syscall.h| 7 +++ arch/loongarch/include/asm/syscall.h | 7 +++ arch/m68k/include/asm/syscall.h | 7 +++ arch/microblaze/include/asm/syscall.h | 7 +++ arch/mips/include/asm/syscall.h | 15 +++ arch/nios2/include/asm/syscall.h | 5 + arch/openrisc/include/asm/syscall.h | 6 ++ arch/parisc/include/asm/syscall.h | 7 +++ arch/powerpc/include/asm/syscall.h| 10 ++ arch/riscv/include/asm/syscall.h | 7 +++ arch/s390/include/asm/syscall.h | 12 arch/sh/include/asm/syscall_32.h | 12 arch/sparc/include/asm/syscall.h | 12 arch/um/include/asm/syscall-generic.h | 5 + arch/x86/include/asm/syscall.h| 7 +++ arch/xtensa/include/asm/syscall.h | 7 +++ include/asm-generic/syscall.h | 14 ++ 20 files changed, 198 insertions(+) diff --git a/arch/arc/include/asm/syscall.h b/arch/arc/include/asm/syscall.h index 89c1e1736356..728d625a10f1 100644 --- a/arch/arc/include/asm/syscall.h +++ b/arch/arc/include/asm/syscall.h @@ -23,6 +23,17 @@ syscall_get_nr(struct task_struct *task, struct pt_regs *regs) return -1; } +static inline void +syscall_set_nr(struct task_struct *task, struct pt_regs *regs, int nr) +{ + /* +* Unlike syscall_get_nr(), syscall_set_nr() can be called only when +* the target task is stopped for tracing on entering syscall, so +* there is no need to have the same check syscall_get_nr() has. +*/ + regs->r8 = nr; +} + static inline void syscall_rollback(struct task_struct *task, struct pt_regs *regs) { diff --git a/arch/arm/include/asm/syscall.h b/arch/arm/include/asm/syscall.h index 21927fa0ae2b..18b102a30741 100644 --- a/arch/arm/include/asm/syscall.h +++ b/arch/arm/include/asm/syscall.h @@ -68,6 +68,30 @@ static inline void syscall_set_return_value(struct task_struct *task, regs->ARM_r0 = (long) error ? error : val; } +static inline void syscall_set_nr(struct task_struct *task, + struct pt_regs *regs, + int nr) +{ + if (nr == -1) { + task_thread_info(task)->abi_syscall = -1; + /* +* When the syscall number is set to -1, the syscall will be +* skipped. In this case the syscall return value has to be +* set explicitly, otherwise the first syscall argument is +* returned as the syscall return value. +*/ + syscall_set_return_value(task, regs, -ENOSYS, 0); + return; + } + if ((IS_ENABLED(CONFIG_AEABI) && !IS_ENABLED(CONFIG_OABI_COMPAT))) { + task_thread_info(task)->abi_syscall = nr; + return; + } + task_thread_info(task)->abi_syscall = + (task_thread_info(task)->abi_syscall & ~__NR_SYSCALL_MASK) | + (nr & __NR_SYSCALL_MASK); +} + #define SYSCALL_MAX_ARGS 7 static inline void syscall_get_arguments(struct task_struct *task, diff --git a/arch/arm64/include/asm/syscall.h b/arch/arm64/include/asm/syscall.h index 76020b66286b..712daa90e643 100644 --- a/arch/arm64/include/asm/syscall.h +++ b/arch/arm64/include/asm/syscall.h @@ -61,6 +61,22 @@ static inline void syscall_set_return_value(struct task_struct *task, regs->regs[0] = val; } +static inline void syscall_set_nr(struct task_struct *task, + struct pt_regs *regs, + int nr) +{ + regs->syscallno = nr; + if (nr == -1) { + /* +* When the syscall number is set to -1, the syscall will be +* skipped. In this case the syscall return value has to be +* set explicitly, otherwise the first syscall argument is +* returned as the syscall return value. +*/ + syscall_set_return_value(task, regs, -ENOSYS, 0); + } +} + #define SYSCALL_MAX_ARGS 6 static inline void syscall_get_arguments(struct task_struct *task, diff --git a/arch/hexagon/include/asm/syscall.h b/arch/hexagon/include/asm/syscall.h index 1024a6548d78
[PATCH v7 2/6] syscall.h: add syscall_set_arguments()
This function is going to be needed on all HAVE_ARCH_TRACEHOOK architectures to implement PTRACE_SET_SYSCALL_INFO API. This partially reverts commit 7962c2eddbfe ("arch: remove unused function syscall_set_arguments()") by reusing some of old syscall_set_arguments() implementations. Signed-off-by: Dmitry V. Levin Tested-by: Charlie Jenkins Reviewed-by: Charlie Jenkins Acked-by: Helge Deller # parisc Reviewed-by: Maciej W. Rozycki # mips --- arch/arc/include/asm/syscall.h| 14 +++ arch/arm/include/asm/syscall.h| 13 ++ arch/arm64/include/asm/syscall.h | 13 ++ arch/csky/include/asm/syscall.h | 13 ++ arch/hexagon/include/asm/syscall.h| 7 ++ arch/loongarch/include/asm/syscall.h | 8 ++ arch/mips/include/asm/syscall.h | 28 + arch/nios2/include/asm/syscall.h | 11 arch/openrisc/include/asm/syscall.h | 7 ++ arch/parisc/include/asm/syscall.h | 12 + arch/powerpc/include/asm/syscall.h| 10 arch/riscv/include/asm/syscall.h | 9 +++ arch/s390/include/asm/syscall.h | 9 +++ arch/sh/include/asm/syscall_32.h | 12 + arch/sparc/include/asm/syscall.h | 10 arch/um/include/asm/syscall-generic.h | 14 +++ arch/x86/include/asm/syscall.h| 36 +++ arch/xtensa/include/asm/syscall.h | 11 include/asm-generic/syscall.h | 16 19 files changed, 253 insertions(+) diff --git a/arch/arc/include/asm/syscall.h b/arch/arc/include/asm/syscall.h index 9709256e31c8..89c1e1736356 100644 --- a/arch/arc/include/asm/syscall.h +++ b/arch/arc/include/asm/syscall.h @@ -67,6 +67,20 @@ syscall_get_arguments(struct task_struct *task, struct pt_regs *regs, } } +static inline void +syscall_set_arguments(struct task_struct *task, struct pt_regs *regs, + unsigned long *args) +{ + unsigned long *inside_ptregs = ®s->r0; + unsigned int n = 6; + unsigned int i = 0; + + while (n--) { + *inside_ptregs = args[i++]; + inside_ptregs--; + } +} + static inline int syscall_get_arch(struct task_struct *task) { diff --git a/arch/arm/include/asm/syscall.h b/arch/arm/include/asm/syscall.h index fe4326d938c1..21927fa0ae2b 100644 --- a/arch/arm/include/asm/syscall.h +++ b/arch/arm/include/asm/syscall.h @@ -80,6 +80,19 @@ static inline void syscall_get_arguments(struct task_struct *task, memcpy(args, ®s->ARM_r0 + 1, 5 * sizeof(args[0])); } +static inline void syscall_set_arguments(struct task_struct *task, +struct pt_regs *regs, +const unsigned long *args) +{ + memcpy(®s->ARM_r0, args, 6 * sizeof(args[0])); + /* +* Also copy the first argument into ARM_ORIG_r0 +* so that syscall_get_arguments() would return it +* instead of the previous value. +*/ + regs->ARM_ORIG_r0 = regs->ARM_r0; +} + static inline int syscall_get_arch(struct task_struct *task) { /* ARM tasks don't change audit architectures on the fly. */ diff --git a/arch/arm64/include/asm/syscall.h b/arch/arm64/include/asm/syscall.h index ab8e14b96f68..76020b66286b 100644 --- a/arch/arm64/include/asm/syscall.h +++ b/arch/arm64/include/asm/syscall.h @@ -73,6 +73,19 @@ static inline void syscall_get_arguments(struct task_struct *task, memcpy(args, ®s->regs[1], 5 * sizeof(args[0])); } +static inline void syscall_set_arguments(struct task_struct *task, +struct pt_regs *regs, +const unsigned long *args) +{ + memcpy(®s->regs[0], args, 6 * sizeof(args[0])); + /* +* Also copy the first argument into orig_x0 +* so that syscall_get_arguments() would return it +* instead of the previous value. +*/ + regs->orig_x0 = regs->regs[0]; +} + /* * We don't care about endianness (__AUDIT_ARCH_LE bit) here because * AArch64 has the same system calls both on little- and big- endian. diff --git a/arch/csky/include/asm/syscall.h b/arch/csky/include/asm/syscall.h index 0de5734950bf..717f44b4d26f 100644 --- a/arch/csky/include/asm/syscall.h +++ b/arch/csky/include/asm/syscall.h @@ -59,6 +59,19 @@ syscall_get_arguments(struct task_struct *task, struct pt_regs *regs, memcpy(args, ®s->a1, 5 * sizeof(args[0])); } +static inline void +syscall_set_arguments(struct task_struct *task, struct pt_regs *regs, + const unsigned long *args) +{ + memcpy(®s->a0, args, 6 * sizeof(regs->a0)); + /* +* Also copy the first argument into orig_a0 +* so that syscall_get_arguments() would return it +* instead of the previous value. +*/ + regs->orig_a0 = regs->a0
[PATCH v7 0/6] ptrace: introduce PTRACE_SET_SYSCALL_INFO API
e of syscall number -1 in ptrace_set_syscall_info_entry() * Split ptrace_syscall_info.reserved into ptrace_syscall_info.reserved and ptrace_syscall_info.flags * Use __kernel_ulong_t instead of unsigned long in set_syscall_info test Dmitry V. Levin (6): hexagon: add syscall_set_return_value() syscall.h: add syscall_set_arguments() syscall.h: introduce syscall_set_nr() ptrace_get_syscall_info: factor out ptrace_get_syscall_info_op ptrace: introduce PTRACE_SET_SYSCALL_INFO request selftests/ptrace: add a test case for PTRACE_SET_SYSCALL_INFO arch/arc/include/asm/syscall.h| 25 + arch/arm/include/asm/syscall.h| 37 ++ arch/arm64/include/asm/syscall.h | 29 + arch/csky/include/asm/syscall.h | 13 + arch/hexagon/include/asm/syscall.h| 21 + arch/loongarch/include/asm/syscall.h | 15 + arch/m68k/include/asm/syscall.h | 7 + arch/microblaze/include/asm/syscall.h | 7 + arch/mips/include/asm/syscall.h | 43 ++ arch/nios2/include/asm/syscall.h | 16 + arch/openrisc/include/asm/syscall.h | 13 + arch/parisc/include/asm/syscall.h | 19 + arch/powerpc/include/asm/syscall.h| 20 + arch/riscv/include/asm/syscall.h | 16 + arch/s390/include/asm/syscall.h | 21 + arch/sh/include/asm/syscall_32.h | 24 + arch/sparc/include/asm/syscall.h | 22 + arch/um/include/asm/syscall-generic.h | 19 + arch/x86/include/asm/syscall.h| 43 ++ arch/xtensa/include/asm/syscall.h | 18 + include/asm-generic/syscall.h | 30 + include/uapi/linux/ptrace.h | 7 +- kernel/ptrace.c | 179 +- tools/testing/selftests/ptrace/Makefile | 2 +- .../selftests/ptrace/set_syscall_info.c | 519 ++ 25 files changed, 1138 insertions(+), 27 deletions(-) create mode 100644 tools/testing/selftests/ptrace/set_syscall_info.c base-commit: 7eb172143d5508b4da468ed59ee857c6e5e01da6 -- ldv ___ linux-snps-arc mailing list linux-snps-arc@lists.infradead.org http://lists.infradead.org/mailman/listinfo/linux-snps-arc
[PATCH v6 3/6] syscall.h: introduce syscall_set_nr()
Similar to syscall_set_arguments() that complements syscall_get_arguments(), introduce syscall_set_nr() that complements syscall_get_nr(). syscall_set_nr() is going to be needed along with syscall_set_arguments() on all HAVE_ARCH_TRACEHOOK architectures to implement PTRACE_SET_SYSCALL_INFO API. Signed-off-by: Dmitry V. Levin Tested-by: Charlie Jenkins Reviewed-by: Charlie Jenkins Acked-by: Helge Deller # parisc --- arch/arc/include/asm/syscall.h| 11 +++ arch/arm/include/asm/syscall.h| 24 arch/arm64/include/asm/syscall.h | 16 arch/hexagon/include/asm/syscall.h| 7 +++ arch/loongarch/include/asm/syscall.h | 7 +++ arch/m68k/include/asm/syscall.h | 7 +++ arch/microblaze/include/asm/syscall.h | 7 +++ arch/mips/include/asm/syscall.h | 14 ++ arch/nios2/include/asm/syscall.h | 5 + arch/openrisc/include/asm/syscall.h | 6 ++ arch/parisc/include/asm/syscall.h | 7 +++ arch/powerpc/include/asm/syscall.h| 10 ++ arch/riscv/include/asm/syscall.h | 7 +++ arch/s390/include/asm/syscall.h | 12 arch/sh/include/asm/syscall_32.h | 12 arch/sparc/include/asm/syscall.h | 12 arch/um/include/asm/syscall-generic.h | 5 + arch/x86/include/asm/syscall.h| 7 +++ arch/xtensa/include/asm/syscall.h | 7 +++ include/asm-generic/syscall.h | 14 ++ 20 files changed, 197 insertions(+) diff --git a/arch/arc/include/asm/syscall.h b/arch/arc/include/asm/syscall.h index 89c1e1736356..728d625a10f1 100644 --- a/arch/arc/include/asm/syscall.h +++ b/arch/arc/include/asm/syscall.h @@ -23,6 +23,17 @@ syscall_get_nr(struct task_struct *task, struct pt_regs *regs) return -1; } +static inline void +syscall_set_nr(struct task_struct *task, struct pt_regs *regs, int nr) +{ + /* +* Unlike syscall_get_nr(), syscall_set_nr() can be called only when +* the target task is stopped for tracing on entering syscall, so +* there is no need to have the same check syscall_get_nr() has. +*/ + regs->r8 = nr; +} + static inline void syscall_rollback(struct task_struct *task, struct pt_regs *regs) { diff --git a/arch/arm/include/asm/syscall.h b/arch/arm/include/asm/syscall.h index 21927fa0ae2b..18b102a30741 100644 --- a/arch/arm/include/asm/syscall.h +++ b/arch/arm/include/asm/syscall.h @@ -68,6 +68,30 @@ static inline void syscall_set_return_value(struct task_struct *task, regs->ARM_r0 = (long) error ? error : val; } +static inline void syscall_set_nr(struct task_struct *task, + struct pt_regs *regs, + int nr) +{ + if (nr == -1) { + task_thread_info(task)->abi_syscall = -1; + /* +* When the syscall number is set to -1, the syscall will be +* skipped. In this case the syscall return value has to be +* set explicitly, otherwise the first syscall argument is +* returned as the syscall return value. +*/ + syscall_set_return_value(task, regs, -ENOSYS, 0); + return; + } + if ((IS_ENABLED(CONFIG_AEABI) && !IS_ENABLED(CONFIG_OABI_COMPAT))) { + task_thread_info(task)->abi_syscall = nr; + return; + } + task_thread_info(task)->abi_syscall = + (task_thread_info(task)->abi_syscall & ~__NR_SYSCALL_MASK) | + (nr & __NR_SYSCALL_MASK); +} + #define SYSCALL_MAX_ARGS 7 static inline void syscall_get_arguments(struct task_struct *task, diff --git a/arch/arm64/include/asm/syscall.h b/arch/arm64/include/asm/syscall.h index 76020b66286b..712daa90e643 100644 --- a/arch/arm64/include/asm/syscall.h +++ b/arch/arm64/include/asm/syscall.h @@ -61,6 +61,22 @@ static inline void syscall_set_return_value(struct task_struct *task, regs->regs[0] = val; } +static inline void syscall_set_nr(struct task_struct *task, + struct pt_regs *regs, + int nr) +{ + regs->syscallno = nr; + if (nr == -1) { + /* +* When the syscall number is set to -1, the syscall will be +* skipped. In this case the syscall return value has to be +* set explicitly, otherwise the first syscall argument is +* returned as the syscall return value. +*/ + syscall_set_return_value(task, regs, -ENOSYS, 0); + } +} + #define SYSCALL_MAX_ARGS 6 static inline void syscall_get_arguments(struct task_struct *task, diff --git a/arch/hexagon/include/asm/syscall.h b/arch/hexagon/include/asm/syscall.h index 1024a6548d78..70637261817a 100644 --- a/arch/hexagon/
[PATCH v6 0/6] ptrace: introduce PTRACE_SET_SYSCALL_INFO API
PTRACE_SET_SYSCALL_INFO is a generic ptrace API that complements PTRACE_GET_SYSCALL_INFO by letting the ptracer modify details of system calls the tracee is blocked in. This API allows ptracers to obtain and modify system call details in a straightforward and architecture-agnostic way, providing a consistent way of manipulating the system call number and arguments across architectures. As in case of PTRACE_GET_SYSCALL_INFO, PTRACE_SET_SYSCALL_INFO also does not aim to address numerous architecture-specific system call ABI peculiarities, like differences in the number of system call arguments for such system calls as pread64 and preadv. The current implementation supports changing only those bits of system call information that are used by strace system call tampering, namely, syscall number, syscall arguments, and syscall return value. Support of changing additional details returned by PTRACE_GET_SYSCALL_INFO, such as instruction pointer and stack pointer, could be added later if needed, by using struct ptrace_syscall_info.flags to specify the additional details that should be set. Currently, "flags" and "reserved" fields of struct ptrace_syscall_info must be initialized with zeroes; "arch", "instruction_pointer", and "stack_pointer" fields are currently ignored. PTRACE_SET_SYSCALL_INFO currently supports only PTRACE_SYSCALL_INFO_ENTRY, PTRACE_SYSCALL_INFO_EXIT, and PTRACE_SYSCALL_INFO_SECCOMP operations. Other operations could be added later if needed. Ideally, PTRACE_SET_SYSCALL_INFO should have been introduced along with PTRACE_GET_SYSCALL_INFO, but it didn't happen. The last straw that convinced me to implement PTRACE_SET_SYSCALL_INFO was apparent failure to provide an API of changing the first system call argument on riscv architecture [1]. ptrace(2) man page: long ptrace(enum __ptrace_request request, pid_t pid, void *addr, void *data); ... PTRACE_SET_SYSCALL_INFO Modify information about the system call that caused the stop. The "data" argument is a pointer to struct ptrace_syscall_info that specifies the system call information to be set. The "addr" argument should be set to sizeof(struct ptrace_syscall_info)). [1] https://lore.kernel.org/all/59505464-c84a-403d-972f-d4b2055ee...@gmail.com/ Notes: v6: * mips: Submit mips_get_syscall_arg() o32 fix via mips tree to get it merged into v6.14-rc3 * Rebase to v6.14-rc3 * v5: https://lore.kernel.org/all/20250210113336.ga...@strace.io/ v5: * ptrace: Extend the commit message to say that the new API does not aim to address numerous architecture-specific syscall ABI peculiarities * selftests: Add a workaround for s390 16-bit syscall numbers * Add more Acked-by * v4: https://lore.kernel.org/all/20250203065849.ga14...@strace.io/ v4: * Split out syscall_set_return_value() for hexagon into a separate patch * s390: Change the style of syscall_set_arguments() implementation as requested * Add more Reviewed-by * v3: https://lore.kernel.org/all/20250128091445.ga8...@strace.io/ v3: * powerpc: Submit syscall_set_return_value() fix for "sc" case separately * mips: Do not introduce erroneous argument truncation on mips n32, add a detailed description to the commit message of the mips_get_syscall_arg() change * ptrace: Add explicit padding to the end of struct ptrace_syscall_info, simplify obtaining of user ptrace_syscall_info, do not introduce PTRACE_SYSCALL_INFO_SIZE_VER0 * ptrace: Change the return type of ptrace_set_syscall_info_* functions from "unsigned long" to "int" * ptrace: Add -ERANGE check to ptrace_set_syscall_info_exit(), add comments to -ERANGE checks * ptrace: Update comments about supported syscall stops * selftests: Extend set_syscall_info test, fix for mips n32 * Add Tested-by and Reviewed-by v2: * Add patch to fix syscall_set_return_value() on powerpc * Add patch to fix mips_get_syscall_arg() on mips * Add syscall_set_return_value() implementation on hexagon * Add syscall_set_return_value() invocation to syscall_set_nr() on arm and arm64. * Fix syscall_set_nr() and mips_set_syscall_arg() on mips * Add a comment to syscall_set_nr() on arc, powerpc, s390, sh, and sparc * Remove redundant ptrace_syscall_info.op assignments in ptrace_get_syscall_info_* * Minor style tweaks in ptrace_get_syscall_info_op() * Remove syscall_set_return_value() invocation from ptrace_set_syscall_info_entry() * Skip syscall_set_arguments() invocation in case of syscall number -1 in ptrace_set_syscall_info_entry() * Split ptrace_syscall_info.reserved into ptrace_syscall_info.reserved and ptrace_syscall_info.flags * Use __kernel_ulong_t instead of unsigned long in set_syscall_info test Dmitry V.
[PATCH v6 2/6] syscall.h: add syscall_set_arguments()
This function is going to be needed on all HAVE_ARCH_TRACEHOOK architectures to implement PTRACE_SET_SYSCALL_INFO API. This partially reverts commit 7962c2eddbfe ("arch: remove unused function syscall_set_arguments()") by reusing some of old syscall_set_arguments() implementations. Signed-off-by: Dmitry V. Levin Tested-by: Charlie Jenkins Reviewed-by: Charlie Jenkins Acked-by: Helge Deller # parisc --- arch/arc/include/asm/syscall.h| 14 +++ arch/arm/include/asm/syscall.h| 13 ++ arch/arm64/include/asm/syscall.h | 13 ++ arch/csky/include/asm/syscall.h | 13 ++ arch/hexagon/include/asm/syscall.h| 7 ++ arch/loongarch/include/asm/syscall.h | 8 ++ arch/mips/include/asm/syscall.h | 32 arch/nios2/include/asm/syscall.h | 11 arch/openrisc/include/asm/syscall.h | 7 ++ arch/parisc/include/asm/syscall.h | 12 + arch/powerpc/include/asm/syscall.h| 10 arch/riscv/include/asm/syscall.h | 9 +++ arch/s390/include/asm/syscall.h | 9 +++ arch/sh/include/asm/syscall_32.h | 12 + arch/sparc/include/asm/syscall.h | 10 arch/um/include/asm/syscall-generic.h | 14 +++ arch/x86/include/asm/syscall.h| 36 +++ arch/xtensa/include/asm/syscall.h | 11 include/asm-generic/syscall.h | 16 19 files changed, 257 insertions(+) diff --git a/arch/arc/include/asm/syscall.h b/arch/arc/include/asm/syscall.h index 9709256e31c8..89c1e1736356 100644 --- a/arch/arc/include/asm/syscall.h +++ b/arch/arc/include/asm/syscall.h @@ -67,6 +67,20 @@ syscall_get_arguments(struct task_struct *task, struct pt_regs *regs, } } +static inline void +syscall_set_arguments(struct task_struct *task, struct pt_regs *regs, + unsigned long *args) +{ + unsigned long *inside_ptregs = ®s->r0; + unsigned int n = 6; + unsigned int i = 0; + + while (n--) { + *inside_ptregs = args[i++]; + inside_ptregs--; + } +} + static inline int syscall_get_arch(struct task_struct *task) { diff --git a/arch/arm/include/asm/syscall.h b/arch/arm/include/asm/syscall.h index fe4326d938c1..21927fa0ae2b 100644 --- a/arch/arm/include/asm/syscall.h +++ b/arch/arm/include/asm/syscall.h @@ -80,6 +80,19 @@ static inline void syscall_get_arguments(struct task_struct *task, memcpy(args, ®s->ARM_r0 + 1, 5 * sizeof(args[0])); } +static inline void syscall_set_arguments(struct task_struct *task, +struct pt_regs *regs, +const unsigned long *args) +{ + memcpy(®s->ARM_r0, args, 6 * sizeof(args[0])); + /* +* Also copy the first argument into ARM_ORIG_r0 +* so that syscall_get_arguments() would return it +* instead of the previous value. +*/ + regs->ARM_ORIG_r0 = regs->ARM_r0; +} + static inline int syscall_get_arch(struct task_struct *task) { /* ARM tasks don't change audit architectures on the fly. */ diff --git a/arch/arm64/include/asm/syscall.h b/arch/arm64/include/asm/syscall.h index ab8e14b96f68..76020b66286b 100644 --- a/arch/arm64/include/asm/syscall.h +++ b/arch/arm64/include/asm/syscall.h @@ -73,6 +73,19 @@ static inline void syscall_get_arguments(struct task_struct *task, memcpy(args, ®s->regs[1], 5 * sizeof(args[0])); } +static inline void syscall_set_arguments(struct task_struct *task, +struct pt_regs *regs, +const unsigned long *args) +{ + memcpy(®s->regs[0], args, 6 * sizeof(args[0])); + /* +* Also copy the first argument into orig_x0 +* so that syscall_get_arguments() would return it +* instead of the previous value. +*/ + regs->orig_x0 = regs->regs[0]; +} + /* * We don't care about endianness (__AUDIT_ARCH_LE bit) here because * AArch64 has the same system calls both on little- and big- endian. diff --git a/arch/csky/include/asm/syscall.h b/arch/csky/include/asm/syscall.h index 0de5734950bf..30403f7a0487 100644 --- a/arch/csky/include/asm/syscall.h +++ b/arch/csky/include/asm/syscall.h @@ -59,6 +59,19 @@ syscall_get_arguments(struct task_struct *task, struct pt_regs *regs, memcpy(args, ®s->a1, 5 * sizeof(args[0])); } +static inline void +syscall_set_arguments(struct task_struct *task, struct pt_regs *regs, + const unsigned long *args) +{ + memcpy(®s->a0, args, 6 * sizeof(regs->a0)); + /* +* Also copy the first argument into orig_x0 +* so that syscall_get_arguments() would return it +* instead of the previous value. +*/ + regs->orig_a0 = regs->a0; +} + static inline int syscall_g