linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH v5 01/25] alpha: define remaining syscall_get_* functions
       [not found] <20181210042352.GA6092@altlinux.org>
@ 2018-12-10  4:27 ` Dmitry V. Levin
  2018-12-10  4:28 ` [PATCH v5 02/25] Move EM_ARCOMPACT and EM_ARCV2 to uapi/linux/elf-em.h Dmitry V. Levin
                   ` (23 subsequent siblings)
  24 siblings, 0 replies; 65+ messages in thread
From: Dmitry V. Levin @ 2018-12-10  4:27 UTC (permalink / raw)
  To: Richard Henderson, Ivan Kokshaysky, Matt Turner, Oleg Nesterov,
	Andy Lutomirski
  Cc: Elvira Khabirova, Eugene Syromyatnikov, linux-alpha, linux-kernel

syscall_get_* functions are required to be implemented on all
architectures in order to extend the generic ptrace API with
PTRACE_GET_SYSCALL_INFO request.

This adds remaining 4 syscall_get_* functions as documented
in asm-generic/syscall.h: syscall_get_nr, syscall_get_arguments,
syscall_get_error, and syscall_get_return_value.

Cc: Richard Henderson <rth@twiddle.net>
Cc: Ivan Kokshaysky <ink@jurassic.park.msu.ru>
Cc: Matt Turner <mattst88@gmail.com>
Cc: Oleg Nesterov <oleg@redhat.com>
Cc: Andy Lutomirski <luto@kernel.org>
Cc: Elvira Khabirova <lineprinter@altlinux.org>
Cc: Eugene Syromyatnikov <esyr@redhat.com>
Cc: linux-alpha@vger.kernel.org
Signed-off-by: Dmitry V. Levin <ldv@altlinux.org>
---
 arch/alpha/include/asm/syscall.h | 29 ++++++++++++++++++++++++++++-
 1 file changed, 28 insertions(+), 1 deletion(-)

diff --git a/arch/alpha/include/asm/syscall.h b/arch/alpha/include/asm/syscall.h
index d73a6fcb519c..437758bdc49f 100644
--- a/arch/alpha/include/asm/syscall.h
+++ b/arch/alpha/include/asm/syscall.h
@@ -4,7 +4,34 @@
 
 #include <uapi/linux/audit.h>
 
-static inline int syscall_get_arch(void)
+static inline int
+syscall_get_nr(struct task_struct *task, struct pt_regs *regs)
+{
+	return regs->r0;
+}
+
+static inline void
+syscall_get_arguments(struct task_struct *task, struct pt_regs *regs,
+		      unsigned int i, unsigned int n, unsigned long *args)
+{
+	BUG_ON(i + n > 6);
+	memcpy(args, &regs->r16 + i, n * sizeof(args[0]));
+}
+
+static inline long
+syscall_get_error(struct task_struct *task, struct pt_regs *regs)
+{
+	return regs->r19 ? -regs->r0 : 0;
+}
+
+static inline long
+syscall_get_return_value(struct task_struct *task, struct pt_regs *regs)
+{
+	return regs->r0;
+}
+
+static inline int
+syscall_get_arch(void)
 {
 	return AUDIT_ARCH_ALPHA;
 }
-- 
ldv

^ permalink raw reply related	[flat|nested] 65+ messages in thread

* [PATCH v5 02/25] Move EM_ARCOMPACT and EM_ARCV2 to uapi/linux/elf-em.h
       [not found] <20181210042352.GA6092@altlinux.org>
  2018-12-10  4:27 ` [PATCH v5 01/25] alpha: define remaining syscall_get_* functions Dmitry V. Levin
@ 2018-12-10  4:28 ` Dmitry V. Levin
  2018-12-10  4:29 ` [PATCH v5 03/25] arc: define syscall_get_arch() Dmitry V. Levin
                   ` (22 subsequent siblings)
  24 siblings, 0 replies; 65+ messages in thread
From: Dmitry V. Levin @ 2018-12-10  4:28 UTC (permalink / raw)
  To: Vineet Gupta
  Cc: Elvira Khabirova, Eugene Syromyatnikov, Oleg Nesterov,
	Andy Lutomirski, Alexey Brodkin, linux-snps-arc, linux-kernel

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 <vgupta@synopsys.com>
Cc: Elvira Khabirova <lineprinter@altlinux.org>
Cc: Eugene Syromyatnikov <esyr@redhat.com>
Cc: Oleg Nesterov <oleg@redhat.com>
Cc: Andy Lutomirski <luto@kernel.org>
Cc: Alexey Brodkin <alexey.brodkin@synopsys.com>
Cc: linux-snps-arc@lists.infradead.org
Signed-off-by: Dmitry V. Levin <ldv@altlinux.org>
---

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 <linux/types.h>
+#include <linux/elf-em.h>
 #include <uapi/asm/elf.h>
 
-/* These ELF defines belong to uapi but libc elf.h already defines them */
-#define EM_ARCOMPACT		93
-
-#define EM_ARCV2		195	/* ARCv2 Cores */
-
 #define EM_ARC_INUSE		(IS_ENABLED(CONFIG_ISA_ARCOMPACT) ? \
 					EM_ARCOMPACT : EM_ARCV2)
 
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_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

^ permalink raw reply related	[flat|nested] 65+ messages in thread

* [PATCH v5 03/25] arc: define syscall_get_arch()
       [not found] <20181210042352.GA6092@altlinux.org>
  2018-12-10  4:27 ` [PATCH v5 01/25] alpha: define remaining syscall_get_* functions Dmitry V. Levin
  2018-12-10  4:28 ` [PATCH v5 02/25] Move EM_ARCOMPACT and EM_ARCV2 to uapi/linux/elf-em.h Dmitry V. Levin
@ 2018-12-10  4:29 ` Dmitry V. Levin
  2018-12-10  4:29 ` [PATCH v5 04/25] c6x: " Dmitry V. Levin
                   ` (21 subsequent siblings)
  24 siblings, 0 replies; 65+ messages in thread
From: Dmitry V. Levin @ 2018-12-10  4:29 UTC (permalink / raw)
  To: Vineet Gupta
  Cc: Elvira Khabirova, Eugene Syromyatnikov, Oleg Nesterov,
	Andy Lutomirski, Alexey Brodkin, Paul Moore, Eric Paris,
	linux-snps-arc, linux-audit, linux-kernel

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 <vgupta@synopsys.com>
Cc: Elvira Khabirova <lineprinter@altlinux.org>
Cc: Eugene Syromyatnikov <esyr@redhat.com>
Cc: Oleg Nesterov <oleg@redhat.com>
Cc: Andy Lutomirski <luto@kernel.org>
Cc: Alexey Brodkin <alexey.brodkin@synopsys.com>
Cc: Paul Moore <paul@paul-moore.com>
Cc: Eric Paris <eparis@redhat.com>
Cc: linux-snps-arc@lists.infradead.org
Cc: linux-audit@redhat.com
Signed-off-by: Dmitry V. Levin <ldv@altlinux.org>
---

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 <uapi/linux/audit.h>
 #include <linux/err.h>
 #include <linux/sched.h>
 #include <asm/unistd.h>
@@ -68,4 +69,14 @@ syscall_get_arguments(struct task_struct *task, struct pt_regs *regs,
 	}
 }
 
+static inline int
+syscall_get_arch(void)
+{
+	return IS_ENABLED(CONFIG_ISA_ARCOMPACT)
+		? (IS_ENABLED(CONFIG_CPU_BIG_ENDIAN)
+			? AUDIT_ARCH_ARCOMPACTBE : AUDIT_ARCH_ARCOMPACT)
+		: (IS_ENABLED(CONFIG_CPU_BIG_ENDIAN)
+			? AUDIT_ARCH_ARCV2BE : AUDIT_ARCH_ARCV2);
+}
+
 #endif
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

^ permalink raw reply related	[flat|nested] 65+ messages in thread

* [PATCH v5 04/25] c6x: define syscall_get_arch()
       [not found] <20181210042352.GA6092@altlinux.org>
                   ` (2 preceding siblings ...)
  2018-12-10  4:29 ` [PATCH v5 03/25] arc: define syscall_get_arch() Dmitry V. Levin
@ 2018-12-10  4:29 ` Dmitry V. Levin
  2018-12-11 22:40   ` Mark Salter
  2018-12-10  4:29 ` [PATCH v5 05/25] elf-em.h: add EM_CSKY Dmitry V. Levin
                   ` (20 subsequent siblings)
  24 siblings, 1 reply; 65+ messages in thread
From: Dmitry V. Levin @ 2018-12-10  4:29 UTC (permalink / raw)
  To: Mark Salter, Aurelien Jacquiot, Paul Moore, Eric Paris,
	Oleg Nesterov, Andy Lutomirski
  Cc: Elvira Khabirova, Eugene Syromyatnikov, linux-c6x-dev,
	linux-audit, linux-kernel

syscall_get_arch() is required to be implemented on all architectures
in addition to already implemented syscall_get_nr(),
syscall_get_arguments(), syscall_get_error(), and
syscall_get_return_value() functions in order to extend the generic
ptrace API with PTRACE_GET_SYSCALL_INFO request.

Cc: Mark Salter <msalter@redhat.com>
Cc: Aurelien Jacquiot <jacquiot.aurelien@gmail.com>
Cc: Paul Moore <paul@paul-moore.com>
Cc: Eric Paris <eparis@redhat.com>
Cc: Oleg Nesterov <oleg@redhat.com>
Cc: Andy Lutomirski <luto@kernel.org>
Cc: Elvira Khabirova <lineprinter@altlinux.org>
Cc: Eugene Syromyatnikov <esyr@redhat.com>
Cc: linux-c6x-dev@linux-c6x.org
Cc: linux-audit@redhat.com
Signed-off-by: Dmitry V. Levin <ldv@altlinux.org>
---

Notes:
    v5: added Cc

 arch/c6x/include/asm/syscall.h | 7 +++++++
 include/uapi/linux/audit.h     | 2 ++
 2 files changed, 9 insertions(+)

diff --git a/arch/c6x/include/asm/syscall.h b/arch/c6x/include/asm/syscall.h
index ae2be315ee9c..39dbd1ef994c 100644
--- a/arch/c6x/include/asm/syscall.h
+++ b/arch/c6x/include/asm/syscall.h
@@ -11,6 +11,7 @@
 #ifndef __ASM_C6X_SYSCALL_H
 #define __ASM_C6X_SYSCALL_H
 
+#include <uapi/linux/audit.h>
 #include <linux/err.h>
 #include <linux/sched.h>
 
@@ -120,4 +121,10 @@ static inline void syscall_set_arguments(struct task_struct *task,
 	}
 }
 
+static inline int syscall_get_arch(void)
+{
+	return IS_ENABLED(CONFIG_CPU_BIG_ENDIAN)
+		? AUDIT_ARCH_C6XBE : AUDIT_ARCH_C6X;
+}
+
 #endif /* __ASM_C6X_SYSCALLS_H */
diff --git a/include/uapi/linux/audit.h b/include/uapi/linux/audit.h
index bedf3bf54c3a..72aeea0a740d 100644
--- a/include/uapi/linux/audit.h
+++ b/include/uapi/linux/audit.h
@@ -381,6 +381,8 @@ enum {
 #define AUDIT_ARCH_ARCV2BE	(EM_ARCV2)
 #define AUDIT_ARCH_ARM		(EM_ARM|__AUDIT_ARCH_LE)
 #define AUDIT_ARCH_ARMEB	(EM_ARM)
+#define AUDIT_ARCH_C6X		(EM_TI_C6000|__AUDIT_ARCH_LE)
+#define AUDIT_ARCH_C6XBE	(EM_TI_C6000)
 #define AUDIT_ARCH_CRIS		(EM_CRIS|__AUDIT_ARCH_LE)
 #define AUDIT_ARCH_FRV		(EM_FRV)
 #define AUDIT_ARCH_I386		(EM_386|__AUDIT_ARCH_LE)
-- 
ldv

^ permalink raw reply related	[flat|nested] 65+ messages in thread

* [PATCH v5 05/25] elf-em.h: add EM_CSKY
       [not found] <20181210042352.GA6092@altlinux.org>
                   ` (3 preceding siblings ...)
  2018-12-10  4:29 ` [PATCH v5 04/25] c6x: " Dmitry V. Levin
@ 2018-12-10  4:29 ` Dmitry V. Levin
  2018-12-10  4:29 ` [PATCH v5 06/25] csky: define syscall_get_arch() Dmitry V. Levin
                   ` (19 subsequent siblings)
  24 siblings, 0 replies; 65+ messages in thread
From: Dmitry V. Levin @ 2018-12-10  4:29 UTC (permalink / raw)
  To: Guo Ren, Oleg Nesterov, Andy Lutomirski
  Cc: Elvira Khabirova, Eugene Syromyatnikov, linux-kernel

The uapi/linux/audit.h header is going to use EM_CSKY in order
to define AUDIT_ARCH_CSKY which is needed to implement
syscall_get_arch() which in turn is required to extend
the generic ptrace API with PTRACE_GET_SYSCALL_INFO request.

The value for EM_CSKY has been taken from arch/csky/include/asm/elf.h
and confirmed by binutils:include/elf/common.h

Cc: Guo Ren <guoren@kernel.org>
Cc: Oleg Nesterov <oleg@redhat.com>
Cc: Andy Lutomirski <luto@kernel.org>
Cc: Elvira Khabirova <lineprinter@altlinux.org>
Cc: Eugene Syromyatnikov <esyr@redhat.com>
Signed-off-by: Dmitry V. Levin <ldv@altlinux.org>
---
 include/uapi/linux/elf-em.h | 1 +
 1 file changed, 1 insertion(+)

diff --git a/include/uapi/linux/elf-em.h b/include/uapi/linux/elf-em.h
index 42b7546352a6..ee0b26ab92b0 100644
--- a/include/uapi/linux/elf-em.h
+++ b/include/uapi/linux/elf-em.h
@@ -45,6 +45,7 @@
 #define EM_ARCV2	195	/* ARCv2 Cores */
 #define EM_RISCV	243	/* RISC-V */
 #define EM_BPF		247	/* Linux BPF - in-kernel virtual machine */
+#define EM_CSKY		252	/* C-SKY processor family */
 #define EM_FRV		0x5441	/* Fujitsu FR-V */
 
 /*
-- 
ldv

^ permalink raw reply related	[flat|nested] 65+ messages in thread

* [PATCH v5 06/25] csky: define syscall_get_arch()
       [not found] <20181210042352.GA6092@altlinux.org>
                   ` (4 preceding siblings ...)
  2018-12-10  4:29 ` [PATCH v5 05/25] elf-em.h: add EM_CSKY Dmitry V. Levin
@ 2018-12-10  4:29 ` Dmitry V. Levin
  2018-12-10  4:29 ` [PATCH v5 07/25] h8300: define remaining syscall_get_* functions Dmitry V. Levin
                   ` (18 subsequent siblings)
  24 siblings, 0 replies; 65+ messages in thread
From: Dmitry V. Levin @ 2018-12-10  4:29 UTC (permalink / raw)
  To: Guo Ren, Paul Moore, Eric Paris, Oleg Nesterov, Andy Lutomirski
  Cc: Elvira Khabirova, Eugene Syromyatnikov, linux-audit, linux-kernel

syscall_get_arch() is required to be implemented on all architectures
in order to extend the generic ptrace API with PTRACE_GET_SYSCALL_INFO
request.

Cc: Guo Ren <guoren@kernel.org>
Cc: Paul Moore <paul@paul-moore.com>
Cc: Eric Paris <eparis@redhat.com>
Cc: Oleg Nesterov <oleg@redhat.com>
Cc: Andy Lutomirski <luto@kernel.org>
Cc: Elvira Khabirova <lineprinter@altlinux.org>
Cc: Eugene Syromyatnikov <esyr@redhat.com>
Cc: linux-audit@redhat.com
Signed-off-by: Dmitry V. Levin <ldv@altlinux.org>
---
 arch/csky/include/asm/syscall.h | 7 +++++++
 include/uapi/linux/audit.h      | 1 +
 2 files changed, 8 insertions(+)

diff --git a/arch/csky/include/asm/syscall.h b/arch/csky/include/asm/syscall.h
index 926a64a8b4ee..d637445737b7 100644
--- a/arch/csky/include/asm/syscall.h
+++ b/arch/csky/include/asm/syscall.h
@@ -6,6 +6,7 @@
 #include <linux/sched.h>
 #include <linux/err.h>
 #include <abi/regdef.h>
+#include <uapi/linux/audit.h>
 
 static inline int
 syscall_get_nr(struct task_struct *task, struct pt_regs *regs)
@@ -68,4 +69,10 @@ syscall_set_arguments(struct task_struct *task, struct pt_regs *regs,
 	memcpy(&regs->a1 + i * sizeof(regs->a1), args, n * sizeof(regs->a0));
 }
 
+static inline int
+syscall_get_arch(void)
+{
+	return AUDIT_ARCH_CSKY;
+}
+
 #endif	/* __ASM_SYSCALL_H */
diff --git a/include/uapi/linux/audit.h b/include/uapi/linux/audit.h
index 72aeea0a740d..55904a40d768 100644
--- a/include/uapi/linux/audit.h
+++ b/include/uapi/linux/audit.h
@@ -384,6 +384,7 @@ enum {
 #define AUDIT_ARCH_C6X		(EM_TI_C6000|__AUDIT_ARCH_LE)
 #define AUDIT_ARCH_C6XBE	(EM_TI_C6000)
 #define AUDIT_ARCH_CRIS		(EM_CRIS|__AUDIT_ARCH_LE)
+#define AUDIT_ARCH_CSKY		(EM_CSKY|__AUDIT_ARCH_LE)
 #define AUDIT_ARCH_FRV		(EM_FRV)
 #define AUDIT_ARCH_I386		(EM_386|__AUDIT_ARCH_LE)
 #define AUDIT_ARCH_IA64		(EM_IA_64|__AUDIT_ARCH_64BIT|__AUDIT_ARCH_LE)
-- 
ldv

^ permalink raw reply related	[flat|nested] 65+ messages in thread

* [PATCH v5 07/25] h8300: define remaining syscall_get_* functions
       [not found] <20181210042352.GA6092@altlinux.org>
                   ` (5 preceding siblings ...)
  2018-12-10  4:29 ` [PATCH v5 06/25] csky: define syscall_get_arch() Dmitry V. Levin
@ 2018-12-10  4:29 ` Dmitry V. Levin
  2018-12-10  4:29 ` [PATCH v5 08/25] Move EM_HEXAGON to uapi/linux/elf-em.h Dmitry V. Levin
                   ` (17 subsequent siblings)
  24 siblings, 0 replies; 65+ messages in thread
From: Dmitry V. Levin @ 2018-12-10  4:29 UTC (permalink / raw)
  To: Yoshinori Sato, Paul Moore, Eric Paris, Oleg Nesterov, Andy Lutomirski
  Cc: Elvira Khabirova, Eugene Syromyatnikov, uclinux-h8-devel,
	linux-audit, linux-kernel

syscall_get_* functions are required to be implemented on all
architectures in order to extend the generic ptrace API with
PTRACE_GET_SYSCALL_INFO request.

This adds remaining 3 syscall_get_* functions as documented in
asm-generic/syscall.h: syscall_get_error, syscall_get_return_value,
and syscall_get_arch.

Cc: Yoshinori Sato <ysato@users.sourceforge.jp>
Cc: Paul Moore <paul@paul-moore.com>
Cc: Eric Paris <eparis@redhat.com>
Cc: Oleg Nesterov <oleg@redhat.com>
Cc: Andy Lutomirski <luto@kernel.org>
Cc: Elvira Khabirova <lineprinter@altlinux.org>
Cc: Eugene Syromyatnikov <esyr@redhat.com>
Cc: uclinux-h8-devel@lists.sourceforge.jp
Cc: linux-audit@redhat.com
Signed-off-by: Dmitry V. Levin <ldv@altlinux.org>
---

Notes:
    v5: added syscall_get_error and syscall_get_return_value

 arch/h8300/include/asm/syscall.h | 18 ++++++++++++++++++
 include/uapi/linux/audit.h       |  1 +
 2 files changed, 19 insertions(+)

diff --git a/arch/h8300/include/asm/syscall.h b/arch/h8300/include/asm/syscall.h
index 924990401237..5c881ffe962a 100644
--- a/arch/h8300/include/asm/syscall.h
+++ b/arch/h8300/include/asm/syscall.h
@@ -8,6 +8,7 @@
 #include <linux/linkage.h>
 #include <linux/types.h>
 #include <linux/ptrace.h>
+#include <uapi/linux/audit.h>
 
 static inline int
 syscall_get_nr(struct task_struct *task, struct pt_regs *regs)
@@ -47,6 +48,23 @@ syscall_get_arguments(struct task_struct *task, struct pt_regs *regs,
 	}
 }
 
+static inline long
+syscall_get_error(struct task_struct *task, struct pt_regs *regs)
+{
+	return IS_ERR_VALUE(regs->er0) ? regs->er0 : 0;
+}
+
+static inline long
+syscall_get_return_value(struct task_struct *task, struct pt_regs *regs)
+{
+	return regs->er0;
+}
+
+static inline int
+syscall_get_arch(void)
+{
+	return AUDIT_ARCH_H8300;
+}
 
 
 /* Misc syscall related bits */
diff --git a/include/uapi/linux/audit.h b/include/uapi/linux/audit.h
index 55904a40d768..672c6d9d7577 100644
--- a/include/uapi/linux/audit.h
+++ b/include/uapi/linux/audit.h
@@ -386,6 +386,7 @@ enum {
 #define AUDIT_ARCH_CRIS		(EM_CRIS|__AUDIT_ARCH_LE)
 #define AUDIT_ARCH_CSKY		(EM_CSKY|__AUDIT_ARCH_LE)
 #define AUDIT_ARCH_FRV		(EM_FRV)
+#define AUDIT_ARCH_H8300	(EM_H8_300)
 #define AUDIT_ARCH_I386		(EM_386|__AUDIT_ARCH_LE)
 #define AUDIT_ARCH_IA64		(EM_IA_64|__AUDIT_ARCH_64BIT|__AUDIT_ARCH_LE)
 #define AUDIT_ARCH_M32R		(EM_M32R)
-- 
ldv

^ permalink raw reply related	[flat|nested] 65+ messages in thread

* [PATCH v5 08/25] Move EM_HEXAGON to uapi/linux/elf-em.h
       [not found] <20181210042352.GA6092@altlinux.org>
                   ` (6 preceding siblings ...)
  2018-12-10  4:29 ` [PATCH v5 07/25] h8300: define remaining syscall_get_* functions Dmitry V. Levin
@ 2018-12-10  4:29 ` Dmitry V. Levin
  2018-12-10  4:29 ` [PATCH v5 09/25] hexagon: define remaining syscall_get_* functions Dmitry V. Levin
                   ` (16 subsequent siblings)
  24 siblings, 0 replies; 65+ messages in thread
From: Dmitry V. Levin @ 2018-12-10  4:29 UTC (permalink / raw)
  To: Richard Kuo, Oleg Nesterov, Andy Lutomirski
  Cc: Elvira Khabirova, Eugene Syromyatnikov, linux-hexagon, linux-kernel

This should never have been defined in the arch tree to begin with,
and now uapi/linux/audit.h header is going to use EM_HEXAGON
in order to define AUDIT_ARCH_HEXAGON which is needed to implement
syscall_get_arch() which in turn is required to extend
the generic ptrace API with PTRACE_GET_SYSCALL_INFO request.

Cc: Richard Kuo <rkuo@codeaurora.org>
Cc: Oleg Nesterov <oleg@redhat.com>
Cc: Andy Lutomirski <luto@kernel.org>
Cc: Elvira Khabirova <lineprinter@altlinux.org>
Cc: Eugene Syromyatnikov <esyr@redhat.com>
Cc: linux-hexagon@vger.kernel.org
Signed-off-by: Dmitry V. Levin <ldv@altlinux.org>
---

Notes:
    v5: added Cc

 arch/hexagon/include/asm/elf.h | 6 +-----
 include/uapi/linux/elf-em.h    | 1 +
 2 files changed, 2 insertions(+), 5 deletions(-)

diff --git a/arch/hexagon/include/asm/elf.h b/arch/hexagon/include/asm/elf.h
index 80311e7b8ca6..d10fbd54ae51 100644
--- a/arch/hexagon/include/asm/elf.h
+++ b/arch/hexagon/include/asm/elf.h
@@ -23,11 +23,7 @@
 
 #include <asm/ptrace.h>
 #include <asm/user.h>
-
-/*
- * This should really be in linux/elf-em.h.
- */
-#define EM_HEXAGON	164   /* QUALCOMM Hexagon */
+#include <linux/elf-em.h>
 
 struct elf32_hdr;
 
diff --git a/include/uapi/linux/elf-em.h b/include/uapi/linux/elf-em.h
index ee0b26ab92b0..e0fb2794bbad 100644
--- a/include/uapi/linux/elf-em.h
+++ b/include/uapi/linux/elf-em.h
@@ -38,6 +38,7 @@
 #define EM_BLACKFIN     106     /* ADI Blackfin Processor */
 #define EM_ALTERA_NIOS2	113	/* Altera Nios II soft-core processor */
 #define EM_TI_C6000	140	/* TI C6X DSPs */
+#define EM_HEXAGON	164	/* QUALCOMM Hexagon */
 #define EM_AARCH64	183	/* ARM 64 bit */
 #define EM_TILEPRO	188	/* Tilera TILEPro */
 #define EM_MICROBLAZE	189	/* Xilinx MicroBlaze */
-- 
ldv

^ permalink raw reply related	[flat|nested] 65+ messages in thread

* [PATCH v5 09/25] hexagon: define remaining syscall_get_* functions
       [not found] <20181210042352.GA6092@altlinux.org>
                   ` (7 preceding siblings ...)
  2018-12-10  4:29 ` [PATCH v5 08/25] Move EM_HEXAGON to uapi/linux/elf-em.h Dmitry V. Levin
@ 2018-12-10  4:29 ` Dmitry V. Levin
  2018-12-10  4:29 ` [PATCH v5 10/25] Move EM_NDS32 to uapi/linux/elf-em.h Dmitry V. Levin
                   ` (15 subsequent siblings)
  24 siblings, 0 replies; 65+ messages in thread
From: Dmitry V. Levin @ 2018-12-10  4:29 UTC (permalink / raw)
  To: Richard Kuo, Paul Moore, Eric Paris, Oleg Nesterov, Andy Lutomirski
  Cc: Elvira Khabirova, Eugene Syromyatnikov, linux-hexagon,
	linux-audit, linux-kernel

syscall_get_* functions are required to be implemented on all
architectures in order to extend the generic ptrace API with
PTRACE_GET_SYSCALL_INFO request.

This adds remaining 3 syscall_get_* functions as documented in
asm-generic/syscall.h: syscall_get_error, syscall_get_return_value,
and syscall_get_arch.

Cc: Richard Kuo <rkuo@codeaurora.org>
Cc: Paul Moore <paul@paul-moore.com>
Cc: Eric Paris <eparis@redhat.com>
Cc: Oleg Nesterov <oleg@redhat.com>
Cc: Andy Lutomirski <luto@kernel.org>
Cc: Elvira Khabirova <lineprinter@altlinux.org>
Cc: Eugene Syromyatnikov <esyr@redhat.com>
Cc: linux-hexagon@vger.kernel.org
Cc: linux-audit@redhat.com
Signed-off-by: Dmitry V. Levin <ldv@altlinux.org>
---

Notes:
    v5: added syscall_get_error and syscall_get_return_value

 arch/hexagon/include/asm/syscall.h | 20 ++++++++++++++++++++
 include/uapi/linux/audit.h         |  1 +
 2 files changed, 21 insertions(+)

diff --git a/arch/hexagon/include/asm/syscall.h b/arch/hexagon/include/asm/syscall.h
index 4af9c7b6f13a..09c7b2884475 100644
--- a/arch/hexagon/include/asm/syscall.h
+++ b/arch/hexagon/include/asm/syscall.h
@@ -21,6 +21,8 @@
 #ifndef _ASM_HEXAGON_SYSCALL_H
 #define _ASM_HEXAGON_SYSCALL_H
 
+#include <uapi/linux/audit.h>
+
 typedef long (*syscall_fn)(unsigned long, unsigned long,
 	unsigned long, unsigned long,
 	unsigned long, unsigned long);
@@ -43,4 +45,22 @@ static inline void syscall_get_arguments(struct task_struct *task,
 	BUG_ON(i + n > 6);
 	memcpy(args, &(&regs->r00)[i], n * sizeof(args[0]));
 }
+
+static inline long syscall_get_error(struct task_struct *task,
+				     struct pt_regs *regs)
+{
+	return IS_ERR_VALUE(regs->r00) ? regs->r00 : 0;
+}
+
+static inline long syscall_get_return_value(struct task_struct *task,
+					    struct pt_regs *regs)
+{
+	return regs->r00;
+}
+
+static inline int syscall_get_arch(void)
+{
+	return AUDIT_ARCH_HEXAGON;
+}
+
 #endif
diff --git a/include/uapi/linux/audit.h b/include/uapi/linux/audit.h
index 672c6d9d7577..b8e848736031 100644
--- a/include/uapi/linux/audit.h
+++ b/include/uapi/linux/audit.h
@@ -387,6 +387,7 @@ enum {
 #define AUDIT_ARCH_CSKY		(EM_CSKY|__AUDIT_ARCH_LE)
 #define AUDIT_ARCH_FRV		(EM_FRV)
 #define AUDIT_ARCH_H8300	(EM_H8_300)
+#define AUDIT_ARCH_HEXAGON	(EM_HEXAGON)
 #define AUDIT_ARCH_I386		(EM_386|__AUDIT_ARCH_LE)
 #define AUDIT_ARCH_IA64		(EM_IA_64|__AUDIT_ARCH_64BIT|__AUDIT_ARCH_LE)
 #define AUDIT_ARCH_M32R		(EM_M32R)
-- 
ldv

^ permalink raw reply related	[flat|nested] 65+ messages in thread

* [PATCH v5 10/25] Move EM_NDS32 to uapi/linux/elf-em.h
       [not found] <20181210042352.GA6092@altlinux.org>
                   ` (8 preceding siblings ...)
  2018-12-10  4:29 ` [PATCH v5 09/25] hexagon: define remaining syscall_get_* functions Dmitry V. Levin
@ 2018-12-10  4:29 ` Dmitry V. Levin
  2018-12-10  4:29 ` [PATCH v5 11/25] nds32: define syscall_get_arch() Dmitry V. Levin
                   ` (14 subsequent siblings)
  24 siblings, 0 replies; 65+ messages in thread
From: Dmitry V. Levin @ 2018-12-10  4:29 UTC (permalink / raw)
  To: Greentime Hu, Vincent Chen, Oleg Nesterov, Andy Lutomirski
  Cc: Elvira Khabirova, Eugene Syromyatnikov, linux-kernel

This should never have been defined in the arch tree to begin with,
and now uapi/linux/audit.h header is going to use EM_NDS32
in order to define AUDIT_ARCH_NDS32 which is needed to implement
syscall_get_arch() which in turn is required to extend
the generic ptrace API with PTRACE_GET_SYSCALL_INFO request.

Cc: Greentime Hu <green.hu@gmail.com>
Cc: Vincent Chen <deanbo422@gmail.com>
Cc: Oleg Nesterov <oleg@redhat.com>
Cc: Andy Lutomirski <luto@kernel.org>
Cc: Elvira Khabirova <lineprinter@altlinux.org>
Cc: Eugene Syromyatnikov <esyr@redhat.com>
Signed-off-by: Dmitry V. Levin <ldv@altlinux.org>
---

Notes:
    v5: added Cc

 arch/nds32/include/asm/elf.h | 3 +--
 include/uapi/linux/elf-em.h  | 2 ++
 2 files changed, 3 insertions(+), 2 deletions(-)

diff --git a/arch/nds32/include/asm/elf.h b/arch/nds32/include/asm/elf.h
index f5f9cf7e0544..71f9d51481a2 100644
--- a/arch/nds32/include/asm/elf.h
+++ b/arch/nds32/include/asm/elf.h
@@ -9,14 +9,13 @@
  */
 
 #include <asm/ptrace.h>
+#include <linux/elf-em.h>
 
 typedef unsigned long elf_greg_t;
 typedef unsigned long elf_freg_t[3];
 
 extern unsigned int elf_hwcap;
 
-#define EM_NDS32			167
-
 #define R_NDS32_NONE			0
 #define R_NDS32_16_RELA			19
 #define R_NDS32_32_RELA			20
diff --git a/include/uapi/linux/elf-em.h b/include/uapi/linux/elf-em.h
index e0fb2794bbad..d8695ad90f6b 100644
--- a/include/uapi/linux/elf-em.h
+++ b/include/uapi/linux/elf-em.h
@@ -39,6 +39,8 @@
 #define EM_ALTERA_NIOS2	113	/* Altera Nios II soft-core processor */
 #define EM_TI_C6000	140	/* TI C6X DSPs */
 #define EM_HEXAGON	164	/* QUALCOMM Hexagon */
+#define EM_NDS32	167	/* Andes Technology compact code size
+				   embedded RISC processor family */
 #define EM_AARCH64	183	/* ARM 64 bit */
 #define EM_TILEPRO	188	/* Tilera TILEPro */
 #define EM_MICROBLAZE	189	/* Xilinx MicroBlaze */
-- 
ldv

^ permalink raw reply related	[flat|nested] 65+ messages in thread

* [PATCH v5 11/25] nds32: define syscall_get_arch()
       [not found] <20181210042352.GA6092@altlinux.org>
                   ` (9 preceding siblings ...)
  2018-12-10  4:29 ` [PATCH v5 10/25] Move EM_NDS32 to uapi/linux/elf-em.h Dmitry V. Levin
@ 2018-12-10  4:29 ` Dmitry V. Levin
  2018-12-10  4:30 ` [PATCH v5 12/25] nios2: " Dmitry V. Levin
                   ` (13 subsequent siblings)
  24 siblings, 0 replies; 65+ messages in thread
From: Dmitry V. Levin @ 2018-12-10  4:29 UTC (permalink / raw)
  To: Greentime Hu, Vincent Chen, Paul Moore, Eric Paris,
	Oleg Nesterov, Andy Lutomirski
  Cc: Elvira Khabirova, Eugene Syromyatnikov, linux-audit, linux-kernel

syscall_get_arch() is required to be implemented on all architectures
in addition to already implemented syscall_get_nr(),
syscall_get_arguments(), syscall_get_error(), and
syscall_get_return_value() functions in order to extend the generic
ptrace API with PTRACE_GET_SYSCALL_INFO request.

Cc: Greentime Hu <green.hu@gmail.com>
Cc: Vincent Chen <deanbo422@gmail.com>
Cc: Paul Moore <paul@paul-moore.com>
Cc: Eric Paris <eparis@redhat.com>
Cc: Oleg Nesterov <oleg@redhat.com>
Cc: Andy Lutomirski <luto@kernel.org>
Cc: Elvira Khabirova <lineprinter@altlinux.org>
Cc: Eugene Syromyatnikov <esyr@redhat.com>
Cc: linux-audit@redhat.com
Signed-off-by: Dmitry V. Levin <ldv@altlinux.org>
---

Notes:
    v5: added Cc
    v2: apparently, this architecture can be configured as big-endian,
        so changed AUDIT_ARCH_NDS32 to be little-endian, and added
        AUDIT_ARCH_NDS32BE.

 arch/nds32/include/asm/syscall.h | 8 ++++++++
 include/uapi/linux/audit.h       | 2 ++
 2 files changed, 10 insertions(+)

diff --git a/arch/nds32/include/asm/syscall.h b/arch/nds32/include/asm/syscall.h
index f7e5e86765fe..569149ca25da 100644
--- a/arch/nds32/include/asm/syscall.h
+++ b/arch/nds32/include/asm/syscall.h
@@ -5,6 +5,7 @@
 #ifndef _ASM_NDS32_SYSCALL_H
 #define _ASM_NDS32_SYSCALL_H	1
 
+#include <uapi/linux/audit.h>
 #include <linux/err.h>
 struct task_struct;
 struct pt_regs;
@@ -185,4 +186,11 @@ void syscall_set_arguments(struct task_struct *task, struct pt_regs *regs,
 
 	memcpy(&regs->uregs[0] + i, args, n * sizeof(args[0]));
 }
+
+static inline int syscall_get_arch(void)
+{
+	return IS_ENABLED(CONFIG_CPU_BIG_ENDIAN)
+		? AUDIT_ARCH_NDS32BE : AUDIT_ARCH_NDS32;
+}
+
 #endif /* _ASM_NDS32_SYSCALL_H */
diff --git a/include/uapi/linux/audit.h b/include/uapi/linux/audit.h
index b8e848736031..54551adb3d5d 100644
--- a/include/uapi/linux/audit.h
+++ b/include/uapi/linux/audit.h
@@ -401,6 +401,8 @@ enum {
 #define AUDIT_ARCH_MIPSEL64	(EM_MIPS|__AUDIT_ARCH_64BIT|__AUDIT_ARCH_LE)
 #define AUDIT_ARCH_MIPSEL64N32	(EM_MIPS|__AUDIT_ARCH_64BIT|__AUDIT_ARCH_LE|\
 				 __AUDIT_ARCH_CONVENTION_MIPS64_N32)
+#define AUDIT_ARCH_NDS32	(EM_NDS32|__AUDIT_ARCH_LE)
+#define AUDIT_ARCH_NDS32BE	(EM_NDS32)
 #define AUDIT_ARCH_OPENRISC	(EM_OPENRISC)
 #define AUDIT_ARCH_PARISC	(EM_PARISC)
 #define AUDIT_ARCH_PARISC64	(EM_PARISC|__AUDIT_ARCH_64BIT)
-- 
ldv

^ permalink raw reply related	[flat|nested] 65+ messages in thread

* [PATCH v5 12/25] nios2: define syscall_get_arch()
       [not found] <20181210042352.GA6092@altlinux.org>
                   ` (10 preceding siblings ...)
  2018-12-10  4:29 ` [PATCH v5 11/25] nds32: define syscall_get_arch() Dmitry V. Levin
@ 2018-12-10  4:30 ` Dmitry V. Levin
  2018-12-10  4:30 ` [PATCH v5 13/25] m68k: add asm/syscall.h Dmitry V. Levin
                   ` (12 subsequent siblings)
  24 siblings, 0 replies; 65+ messages in thread
From: Dmitry V. Levin @ 2018-12-10  4:30 UTC (permalink / raw)
  To: Ley Foon Tan, Paul Moore, Eric Paris, Oleg Nesterov, Andy Lutomirski
  Cc: Elvira Khabirova, Eugene Syromyatnikov, nios2-dev, linux-audit,
	linux-kernel

syscall_get_arch() is required to be implemented on all architectures
in addition to already implemented syscall_get_nr(),
syscall_get_arguments(), syscall_get_error(), and
syscall_get_return_value() functions in order to extend the generic
ptrace API with PTRACE_GET_SYSCALL_INFO request.

Cc: Ley Foon Tan <lftan@altera.com>
Cc: Paul Moore <paul@paul-moore.com>
Cc: Eric Paris <eparis@redhat.com>
Cc: Oleg Nesterov <oleg@redhat.com>
Cc: Andy Lutomirski <luto@kernel.org>
Cc: Elvira Khabirova <lineprinter@altlinux.org>
Cc: Eugene Syromyatnikov <esyr@redhat.com>
Cc: nios2-dev@lists.rocketboards.org
Cc: linux-audit@redhat.com
Signed-off-by: Dmitry V. Levin <ldv@altlinux.org>
---

Notes:
    v5: added Cc

 arch/nios2/include/asm/syscall.h | 6 ++++++
 include/uapi/linux/audit.h       | 1 +
 2 files changed, 7 insertions(+)

diff --git a/arch/nios2/include/asm/syscall.h b/arch/nios2/include/asm/syscall.h
index 9de220854c4a..cf35e210fc4d 100644
--- a/arch/nios2/include/asm/syscall.h
+++ b/arch/nios2/include/asm/syscall.h
@@ -17,6 +17,7 @@
 #ifndef __ASM_NIOS2_SYSCALL_H__
 #define __ASM_NIOS2_SYSCALL_H__
 
+#include <uapi/linux/audit.h>
 #include <linux/err.h>
 #include <linux/sched.h>
 
@@ -135,4 +136,9 @@ static inline void syscall_set_arguments(struct task_struct *task,
 	}
 }
 
+static inline int syscall_get_arch(void)
+{
+	return AUDIT_ARCH_NIOS2;
+}
+
 #endif
diff --git a/include/uapi/linux/audit.h b/include/uapi/linux/audit.h
index 54551adb3d5d..883c5f56be9c 100644
--- a/include/uapi/linux/audit.h
+++ b/include/uapi/linux/audit.h
@@ -403,6 +403,7 @@ enum {
 				 __AUDIT_ARCH_CONVENTION_MIPS64_N32)
 #define AUDIT_ARCH_NDS32	(EM_NDS32|__AUDIT_ARCH_LE)
 #define AUDIT_ARCH_NDS32BE	(EM_NDS32)
+#define AUDIT_ARCH_NIOS2	(EM_ALTERA_NIOS2|__AUDIT_ARCH_LE)
 #define AUDIT_ARCH_OPENRISC	(EM_OPENRISC)
 #define AUDIT_ARCH_PARISC	(EM_PARISC)
 #define AUDIT_ARCH_PARISC64	(EM_PARISC|__AUDIT_ARCH_64BIT)
-- 
ldv

^ permalink raw reply related	[flat|nested] 65+ messages in thread

* [PATCH v5 13/25] m68k: add asm/syscall.h
       [not found] <20181210042352.GA6092@altlinux.org>
                   ` (11 preceding siblings ...)
  2018-12-10  4:30 ` [PATCH v5 12/25] nios2: " Dmitry V. Levin
@ 2018-12-10  4:30 ` Dmitry V. Levin
  2018-12-10  8:45   ` Geert Uytterhoeven
  2018-12-10  4:30 ` [PATCH v5 14/25] mips: define syscall_get_error() Dmitry V. Levin
                   ` (11 subsequent siblings)
  24 siblings, 1 reply; 65+ messages in thread
From: Dmitry V. Levin @ 2018-12-10  4:30 UTC (permalink / raw)
  To: Geert Uytterhoeven, Oleg Nesterov, Andy Lutomirski
  Cc: Elvira Khabirova, Eugene Syromyatnikov, linux-m68k, linux-kernel

syscall_get_* functions are required to be implemented on all
architectures in order to extend the generic ptrace API with
PTRACE_GET_SYSCALL_INFO request.

This introduces asm/syscall.h on m68k implementing all 5 syscall_get_*
functions as documented in asm-generic/syscall.h: syscall_get_nr,
syscall_get_arguments, syscall_get_error, syscall_get_return_value,
and syscall_get_arch.

Cc: Geert Uytterhoeven <geert@linux-m68k.org>
Cc: Oleg Nesterov <oleg@redhat.com>
Cc: Andy Lutomirski <luto@kernel.org>
Cc: Elvira Khabirova <lineprinter@altlinux.org>
Cc: Eugene Syromyatnikov <esyr@redhat.com>
Cc: linux-m68k@lists.linux-m68k.org
Signed-off-by: Dmitry V. Levin <ldv@altlinux.org>
---

Notes:
    v5: added syscall_get_nr, syscall_get_arguments, syscall_get_error,
        and syscall_get_return_value
    v1: added syscall_get_arch

 arch/m68k/include/asm/syscall.h | 39 +++++++++++++++++++++++++++++++++
 1 file changed, 39 insertions(+)
 create mode 100644 arch/m68k/include/asm/syscall.h

diff --git a/arch/m68k/include/asm/syscall.h b/arch/m68k/include/asm/syscall.h
new file mode 100644
index 000000000000..75a24cf90620
--- /dev/null
+++ b/arch/m68k/include/asm/syscall.h
@@ -0,0 +1,39 @@
+/* SPDX-License-Identifier: GPL-2.0 */
+#ifndef _ASM_M68K_SYSCALL_H
+#define _ASM_M68K_SYSCALL_H
+
+#include <uapi/linux/audit.h>
+
+static inline int
+syscall_get_nr(struct task_struct *task, struct pt_regs *regs)
+{
+	return regs->orig_d0;
+}
+
+static inline void
+syscall_get_arguments(struct task_struct *task, struct pt_regs *regs,
+		      unsigned int i, unsigned int n, unsigned long *args)
+{
+	BUG_ON(i + n > 6);
+	memcpy(args, &regs->d1 + i, n * sizeof(args[0]));
+}
+
+static inline long
+syscall_get_error(struct task_struct *task, struct pt_regs *regs)
+{
+	return IS_ERR_VALUE(regs->d0) ? regs->d0 : 0;
+}
+
+static inline long
+syscall_get_return_value(struct task_struct *task, struct pt_regs *regs)
+{
+	return regs->d0;
+}
+
+static inline int
+syscall_get_arch(void)
+{
+	return AUDIT_ARCH_M68K;
+}
+
+#endif	/* _ASM_M68K_SYSCALL_H */
-- 
ldv

^ permalink raw reply related	[flat|nested] 65+ messages in thread

* [PATCH v5 14/25] mips: define syscall_get_error()
       [not found] <20181210042352.GA6092@altlinux.org>
                   ` (12 preceding siblings ...)
  2018-12-10  4:30 ` [PATCH v5 13/25] m68k: add asm/syscall.h Dmitry V. Levin
@ 2018-12-10  4:30 ` Dmitry V. Levin
  2018-12-10  4:30 ` [PATCH v5 15/25] parisc: " Dmitry V. Levin
                   ` (10 subsequent siblings)
  24 siblings, 0 replies; 65+ messages in thread
From: Dmitry V. Levin @ 2018-12-10  4:30 UTC (permalink / raw)
  To: Paul Burton, Ralf Baechle, James Hogan, Oleg Nesterov, Andy Lutomirski
  Cc: Elvira Khabirova, Eugene Syromyatnikov, linux-mips, linux-kernel

syscall_get_error() is required to be implemented on all
architectures in addition to already implemented syscall_get_nr(),
syscall_get_arguments(), syscall_get_return_value(), and
syscall_get_arch() functions in order to extend the generic
ptrace API with PTRACE_GET_SYSCALL_INFO request.

Cc: Paul Burton <paul.burton@mips.com>
Cc: Ralf Baechle <ralf@linux-mips.org>
Cc: James Hogan <jhogan@kernel.org>
Cc: Oleg Nesterov <oleg@redhat.com>
Cc: Andy Lutomirski <luto@kernel.org>
Cc: Elvira Khabirova <lineprinter@altlinux.org>
Cc: Eugene Syromyatnikov <esyr@redhat.com>
Cc: linux-mips@vger.kernel.org
Signed-off-by: Dmitry V. Levin <ldv@altlinux.org>
---
 arch/mips/include/asm/syscall.h | 6 ++++++
 1 file changed, 6 insertions(+)

diff --git a/arch/mips/include/asm/syscall.h b/arch/mips/include/asm/syscall.h
index 6cf8ffb5367e..04ab927ff47d 100644
--- a/arch/mips/include/asm/syscall.h
+++ b/arch/mips/include/asm/syscall.h
@@ -89,6 +89,12 @@ static inline unsigned long mips_get_syscall_arg(unsigned long *arg,
 	unreachable();
 }
 
+static inline long syscall_get_error(struct task_struct *task,
+				     struct pt_regs *regs)
+{
+	return regs->regs[7] ? -regs->regs[2] : 0;
+}
+
 static inline long syscall_get_return_value(struct task_struct *task,
 					    struct pt_regs *regs)
 {
-- 
ldv

^ permalink raw reply related	[flat|nested] 65+ messages in thread

* [PATCH v5 15/25] parisc: define syscall_get_error()
       [not found] <20181210042352.GA6092@altlinux.org>
                   ` (13 preceding siblings ...)
  2018-12-10  4:30 ` [PATCH v5 14/25] mips: define syscall_get_error() Dmitry V. Levin
@ 2018-12-10  4:30 ` Dmitry V. Levin
  2018-12-10  4:30 ` [PATCH v5 16/25] powerpc: " Dmitry V. Levin
                   ` (9 subsequent siblings)
  24 siblings, 0 replies; 65+ messages in thread
From: Dmitry V. Levin @ 2018-12-10  4:30 UTC (permalink / raw)
  To: Helge Deller, James E.J. Bottomley, Oleg Nesterov, Andy Lutomirski
  Cc: Elvira Khabirova, Eugene Syromyatnikov, linux-parisc, linux-kernel

syscall_get_error() is required to be implemented on all
architectures in addition to already implemented syscall_get_nr(),
syscall_get_arguments(), syscall_get_return_value(), and
syscall_get_arch() functions in order to extend the generic
ptrace API with PTRACE_GET_SYSCALL_INFO request.

Cc: Helge Deller <deller@gmx.de>
Cc: James E.J. Bottomley <jejb@parisc-linux.org>
Cc: Oleg Nesterov <oleg@redhat.com>
Cc: Andy Lutomirski <luto@kernel.org>
Cc: Elvira Khabirova <lineprinter@altlinux.org>
Cc: Eugene Syromyatnikov <esyr@redhat.com>
Cc: linux-parisc@vger.kernel.org
Signed-off-by: Dmitry V. Levin <ldv@altlinux.org>
---
 arch/parisc/include/asm/syscall.h | 7 +++++++
 1 file changed, 7 insertions(+)

diff --git a/arch/parisc/include/asm/syscall.h b/arch/parisc/include/asm/syscall.h
index 8bff1a58c97f..477511ff7546 100644
--- a/arch/parisc/include/asm/syscall.h
+++ b/arch/parisc/include/asm/syscall.h
@@ -43,6 +43,13 @@ static inline void syscall_get_arguments(struct task_struct *tsk,
 	}
 }
 
+static inline long syscall_get_error(struct task_struct *task,
+				     struct pt_regs *regs)
+{
+	unsigned long error = regs->gr[28];
+	return IS_ERR_VALUE(error) ? error : 0;
+}
+
 static inline long syscall_get_return_value(struct task_struct *task,
 						struct pt_regs *regs)
 {
-- 
ldv

^ permalink raw reply related	[flat|nested] 65+ messages in thread

* [PATCH v5 16/25] powerpc: define syscall_get_error()
       [not found] <20181210042352.GA6092@altlinux.org>
                   ` (14 preceding siblings ...)
  2018-12-10  4:30 ` [PATCH v5 15/25] parisc: " Dmitry V. Levin
@ 2018-12-10  4:30 ` Dmitry V. Levin
  2018-12-10  4:30 ` [PATCH v5 17/25] riscv: define syscall_get_arch() Dmitry V. Levin
                   ` (8 subsequent siblings)
  24 siblings, 0 replies; 65+ messages in thread
From: Dmitry V. Levin @ 2018-12-10  4:30 UTC (permalink / raw)
  To: Michael Ellerman, Benjamin Herrenschmidt, Paul Mackerras,
	Oleg Nesterov, Andy Lutomirski
  Cc: Elvira Khabirova, Eugene Syromyatnikov, linuxppc-dev, linux-kernel

syscall_get_error() is required to be implemented on this
architecture in addition to already implemented syscall_get_nr(),
syscall_get_arguments(), syscall_get_return_value(), and
syscall_get_arch() functions in order to extend the generic
ptrace API with PTRACE_GET_SYSCALL_INFO request.

Cc: Michael Ellerman <mpe@ellerman.id.au>
Cc: Benjamin Herrenschmidt <benh@kernel.crashing.org>
Cc: Paul Mackerras <paulus@samba.org>
Cc: Oleg Nesterov <oleg@redhat.com>
Cc: Andy Lutomirski <luto@kernel.org>
Cc: Elvira Khabirova <lineprinter@altlinux.org>
Cc: Eugene Syromyatnikov <esyr@redhat.com>
Cc: linuxppc-dev@lists.ozlabs.org
Signed-off-by: Dmitry V. Levin <ldv@altlinux.org>
---

Notes:
    This change has been tested with
    tools/testing/selftests/ptrace/get_syscall_info.c and strace,
    so it's correct from PTRACE_GET_SYSCALL_INFO point of view.
    
    This cast doubts on commit v4.3-rc1~86^2~81 that changed
    syscall_set_return_value() in a way that doesn't quite match
    syscall_get_error(), but syscall_set_return_value() is out
    of scope of this series, so I just air my concerns.

 arch/powerpc/include/asm/syscall.h | 10 ++++++++++
 1 file changed, 10 insertions(+)

diff --git a/arch/powerpc/include/asm/syscall.h b/arch/powerpc/include/asm/syscall.h
index ab9f3f0a8637..1d03e753391d 100644
--- a/arch/powerpc/include/asm/syscall.h
+++ b/arch/powerpc/include/asm/syscall.h
@@ -39,6 +39,16 @@ static inline void syscall_rollback(struct task_struct *task,
 	regs->gpr[3] = regs->orig_gpr3;
 }
 
+static inline long syscall_get_error(struct task_struct *task,
+				     struct pt_regs *regs)
+{
+	/*
+	 * If the system call failed,
+	 * regs->gpr[3] contains a positive ERRORCODE.
+	 */
+	return (regs->ccr & 0x10000000UL) ? -regs->gpr[3] : 0;
+}
+
 static inline long syscall_get_return_value(struct task_struct *task,
 					    struct pt_regs *regs)
 {
-- 
ldv

^ permalink raw reply related	[flat|nested] 65+ messages in thread

* [PATCH v5 17/25] riscv: define syscall_get_arch()
       [not found] <20181210042352.GA6092@altlinux.org>
                   ` (15 preceding siblings ...)
  2018-12-10  4:30 ` [PATCH v5 16/25] powerpc: " Dmitry V. Levin
@ 2018-12-10  4:30 ` Dmitry V. Levin
  2018-12-10  4:30 ` [PATCH v5 18/25] Move EM_XTENSA to uapi/linux/elf-em.h Dmitry V. Levin
                   ` (7 subsequent siblings)
  24 siblings, 0 replies; 65+ messages in thread
From: Dmitry V. Levin @ 2018-12-10  4:30 UTC (permalink / raw)
  To: Palmer Dabbelt
  Cc: Elvira Khabirova, Eugene Syromyatnikov, Oleg Nesterov,
	Andy Lutomirski, Albert Ou, Paul Moore, Eric Paris, linux-riscv,
	linux-audit, linux-kernel

syscall_get_arch() is required to be implemented on all architectures
in addition to already implemented syscall_get_nr(),
syscall_get_arguments(), syscall_get_error(), and
syscall_get_return_value() functions in order to extend the generic
ptrace API with PTRACE_GET_SYSCALL_INFO request.

Based-on-patch-by: David Abdurachmanov <david.abdurachmanov@gmail.com>
Reviewed-by: Palmer Dabbelt <palmer@sifive.com>
Cc: Elvira Khabirova <lineprinter@altlinux.org>
Cc: Eugene Syromyatnikov <esyr@redhat.com>
Cc: Oleg Nesterov <oleg@redhat.com>
Cc: Andy Lutomirski <luto@kernel.org>
Cc: Albert Ou <aou@eecs.berkeley.edu>
Cc: Paul Moore <paul@paul-moore.com>
Cc: Eric Paris <eparis@redhat.com>
Cc: linux-riscv@lists.infradead.org
Cc: linux-audit@redhat.com
Signed-off-by: Dmitry V. Levin <ldv@altlinux.org>
---

Notes:
    v5: added Cc
    v2: added Reviewed-by

 arch/riscv/include/asm/syscall.h | 10 ++++++++++
 include/uapi/linux/audit.h       |  2 ++
 2 files changed, 12 insertions(+)

diff --git a/arch/riscv/include/asm/syscall.h b/arch/riscv/include/asm/syscall.h
index 8d25f8904c00..bba3da6ef157 100644
--- a/arch/riscv/include/asm/syscall.h
+++ b/arch/riscv/include/asm/syscall.h
@@ -18,6 +18,7 @@
 #ifndef _ASM_RISCV_SYSCALL_H
 #define _ASM_RISCV_SYSCALL_H
 
+#include <uapi/linux/audit.h>
 #include <linux/sched.h>
 #include <linux/err.h>
 
@@ -99,4 +100,13 @@ static inline void syscall_set_arguments(struct task_struct *task,
 	memcpy(&regs->a1 + i * sizeof(regs->a1), args, n * sizeof(regs->a0));
 }
 
+static inline int syscall_get_arch(void)
+{
+#ifdef CONFIG_64BIT
+	return AUDIT_ARCH_RISCV64;
+#else
+	return AUDIT_ARCH_RISCV32;
+#endif
+}
+
 #endif	/* _ASM_RISCV_SYSCALL_H */
diff --git a/include/uapi/linux/audit.h b/include/uapi/linux/audit.h
index 883c5f56be9c..1e9808f3a240 100644
--- a/include/uapi/linux/audit.h
+++ b/include/uapi/linux/audit.h
@@ -411,6 +411,8 @@ enum {
 /* do not define AUDIT_ARCH_PPCLE since it is not supported by audit */
 #define AUDIT_ARCH_PPC64	(EM_PPC64|__AUDIT_ARCH_64BIT)
 #define AUDIT_ARCH_PPC64LE	(EM_PPC64|__AUDIT_ARCH_64BIT|__AUDIT_ARCH_LE)
+#define AUDIT_ARCH_RISCV32	(EM_RISCV|__AUDIT_ARCH_LE)
+#define AUDIT_ARCH_RISCV64	(EM_RISCV|__AUDIT_ARCH_64BIT|__AUDIT_ARCH_LE)
 #define AUDIT_ARCH_S390		(EM_S390)
 #define AUDIT_ARCH_S390X	(EM_S390|__AUDIT_ARCH_64BIT)
 #define AUDIT_ARCH_SH		(EM_SH)
-- 
ldv

^ permalink raw reply related	[flat|nested] 65+ messages in thread

* [PATCH v5 18/25] Move EM_XTENSA to uapi/linux/elf-em.h
       [not found] <20181210042352.GA6092@altlinux.org>
                   ` (16 preceding siblings ...)
  2018-12-10  4:30 ` [PATCH v5 17/25] riscv: define syscall_get_arch() Dmitry V. Levin
@ 2018-12-10  4:30 ` Dmitry V. Levin
  2018-12-10  4:30 ` [PATCH v5 19/25] xtensa: define syscall_get_* functions Dmitry V. Levin
                   ` (6 subsequent siblings)
  24 siblings, 0 replies; 65+ messages in thread
From: Dmitry V. Levin @ 2018-12-10  4:30 UTC (permalink / raw)
  To: Max Filippov, Oleg Nesterov, Andy Lutomirski
  Cc: Elvira Khabirova, Eugene Syromyatnikov, Chris Zankel,
	linux-xtensa, linux-kernel

This should never have been defined in the arch tree to begin with,
and now uapi/linux/audit.h header is going to use EM_XTENSA
in order to define AUDIT_ARCH_XTENSA which is needed to implement
syscall_get_arch() which in turn is required to extend
the generic ptrace API with PTRACE_GET_SYSCALL_INFO request.

Cc: Max Filippov <jcmvbkbc@gmail.com>
Cc: Oleg Nesterov <oleg@redhat.com>
Cc: Andy Lutomirski <luto@kernel.org>
Cc: Elvira Khabirova <lineprinter@altlinux.org>
Cc: Eugene Syromyatnikov <esyr@redhat.com>
Cc: Chris Zankel <chris@zankel.net>
Cc: linux-xtensa@linux-xtensa.org
Signed-off-by: Dmitry V. Levin <ldv@altlinux.org>
---

Notes:
    v5: move EM_XTENSA to elf-em.h instead of adding,
        I didn't realize it was already defined in the arch tree
    v2: added Reviewed-by

 arch/xtensa/include/asm/elf.h | 2 +-
 include/uapi/linux/elf-em.h   | 1 +
 2 files changed, 2 insertions(+), 1 deletion(-)

diff --git a/arch/xtensa/include/asm/elf.h b/arch/xtensa/include/asm/elf.h
index eacb25a41718..344f1c6a546e 100644
--- a/arch/xtensa/include/asm/elf.h
+++ b/arch/xtensa/include/asm/elf.h
@@ -15,10 +15,10 @@
 
 #include <asm/ptrace.h>
 #include <asm/coprocessor.h>
+#include <linux/elf-em.h>
 
 /* Xtensa processor ELF architecture-magic number */
 
-#define EM_XTENSA	94
 #define EM_XTENSA_OLD	0xABC7
 
 /* Xtensa relocations defined by the ABIs */
diff --git a/include/uapi/linux/elf-em.h b/include/uapi/linux/elf-em.h
index d8695ad90f6b..f392dd9d07f7 100644
--- a/include/uapi/linux/elf-em.h
+++ b/include/uapi/linux/elf-em.h
@@ -35,6 +35,7 @@
 #define EM_MN10300	89	/* Panasonic/MEI MN10300, AM33 */
 #define EM_OPENRISC     92     /* OpenRISC 32-bit embedded processor */
 #define EM_ARCOMPACT	93	/* ARCompact processor */
+#define EM_XTENSA	94	/* Tensilica Xtensa Architecture */
 #define EM_BLACKFIN     106     /* ADI Blackfin Processor */
 #define EM_ALTERA_NIOS2	113	/* Altera Nios II soft-core processor */
 #define EM_TI_C6000	140	/* TI C6X DSPs */
-- 
ldv

^ permalink raw reply related	[flat|nested] 65+ messages in thread

* [PATCH v5 19/25] xtensa: define syscall_get_* functions
       [not found] <20181210042352.GA6092@altlinux.org>
                   ` (17 preceding siblings ...)
  2018-12-10  4:30 ` [PATCH v5 18/25] Move EM_XTENSA to uapi/linux/elf-em.h Dmitry V. Levin
@ 2018-12-10  4:30 ` Dmitry V. Levin
  2018-12-10  5:02   ` Max Filippov
                     ` (2 more replies)
  2018-12-10  4:30 ` [PATCH v5 20/25] Move EM_UNICORE to uapi/linux/elf-em.h Dmitry V. Levin
                   ` (5 subsequent siblings)
  24 siblings, 3 replies; 65+ messages in thread
From: Dmitry V. Levin @ 2018-12-10  4:30 UTC (permalink / raw)
  To: Max Filippov, Oleg Nesterov, Andy Lutomirski
  Cc: Elvira Khabirova, Eugene Syromyatnikov, Chris Zankel, Paul Moore,
	Eric Paris, linux-xtensa, linux-audit, linux-kernel

syscall_get_* functions are required to be implemented on all
architectures in order to extend the generic ptrace API with
PTRACE_GET_SYSCALL_INFO request.

This adds all 5 syscall_get_* functions on xtensa as documented
in asm-generic/syscall.h: syscall_get_nr, syscall_get_arguments,
syscall_get_error, syscall_get_return_value, and syscall_get_arch.

Cc: Max Filippov <jcmvbkbc@gmail.com>
Cc: Oleg Nesterov <oleg@redhat.com>
Cc: Andy Lutomirski <luto@kernel.org>
Cc: Elvira Khabirova <lineprinter@altlinux.org>
Cc: Eugene Syromyatnikov <esyr@redhat.com>
Cc: Chris Zankel <chris@zankel.net>
Cc: Paul Moore <paul@paul-moore.com>
Cc: Eric Paris <eparis@redhat.com>
Cc: linux-xtensa@linux-xtensa.org
Cc: linux-audit@redhat.com
Signed-off-by: Dmitry V. Levin <ldv@altlinux.org>
---

Notes:
    v5: added syscall_get_nr, syscall_get_arguments, syscall_get_error,
        and syscall_get_return_value
    v2: added Acked-by
    v1: added syscall_get_arch

 arch/xtensa/include/asm/syscall.h | 69 +++++++++++++++++++++++++++++++
 include/uapi/linux/audit.h        |  1 +
 2 files changed, 70 insertions(+)

diff --git a/arch/xtensa/include/asm/syscall.h b/arch/xtensa/include/asm/syscall.h
index 3673ff1f1bc5..d529c855a144 100644
--- a/arch/xtensa/include/asm/syscall.h
+++ b/arch/xtensa/include/asm/syscall.h
@@ -8,6 +8,75 @@
  * Copyright (C) 2001 - 2007 Tensilica Inc.
  */
 
+#include <uapi/linux/audit.h>
+
+static inline int
+syscall_get_nr(struct task_struct *task, struct pt_regs *regs)
+{
+	return regs->syscall;
+}
+
+static inline void
+syscall_get_arguments(struct task_struct *task, struct pt_regs *regs,
+		      unsigned int i, unsigned int n, unsigned long *args)
+{
+	switch (i) {
+	case 0:
+		if (!n--)
+			break;
+		*args++ = regs->areg[6];
+		/* fall through */
+	case 1:
+		if (!n--)
+			break;
+		*args++ = regs->areg[3];
+		/* fall through */
+	case 2:
+		if (!n--)
+			break;
+		*args++ = regs->areg[4];
+		/* fall through */
+	case 3:
+		if (!n--)
+			break;
+		*args++ = regs->areg[5];
+		/* fall through */
+	case 4:
+		if (!n--)
+			break;
+		*args++ = regs->areg[8];
+		/* fall through */
+	case 5:
+		if (!n--)
+			break;
+		*args++ = regs->areg[9];
+		/* fall through */
+	case 6:
+		if (!n--)
+			break;
+		/* fall through */
+	default:
+		BUG();
+	}
+}
+
+static inline long
+syscall_get_error(struct task_struct *task, struct pt_regs *regs)
+{
+	return IS_ERR_VALUE(regs->areg[2]) ? regs->areg[2] : 0;
+
+static inline long
+syscall_get_return_value(struct task_struct *task, struct pt_regs *regs)
+{
+	return regs->areg[2];
+}
+
+static inline int
+syscall_get_arch(void)
+{
+	return AUDIT_ARCH_XTENSA;
+}
+
 struct pt_regs;
 asmlinkage long xtensa_ptrace(long, long, long, long);
 asmlinkage long xtensa_sigreturn(struct pt_regs*);
diff --git a/include/uapi/linux/audit.h b/include/uapi/linux/audit.h
index 1e9808f3a240..bcc0619b046f 100644
--- a/include/uapi/linux/audit.h
+++ b/include/uapi/linux/audit.h
@@ -425,6 +425,7 @@ enum {
 #define AUDIT_ARCH_TILEGX32	(EM_TILEGX|__AUDIT_ARCH_LE)
 #define AUDIT_ARCH_TILEPRO	(EM_TILEPRO|__AUDIT_ARCH_LE)
 #define AUDIT_ARCH_X86_64	(EM_X86_64|__AUDIT_ARCH_64BIT|__AUDIT_ARCH_LE)
+#define AUDIT_ARCH_XTENSA	(EM_XTENSA)
 
 #define AUDIT_PERM_EXEC		1
 #define AUDIT_PERM_WRITE	2
-- 
ldv

^ permalink raw reply related	[flat|nested] 65+ messages in thread

* [PATCH v5 20/25] Move EM_UNICORE to uapi/linux/elf-em.h
       [not found] <20181210042352.GA6092@altlinux.org>
                   ` (18 preceding siblings ...)
  2018-12-10  4:30 ` [PATCH v5 19/25] xtensa: define syscall_get_* functions Dmitry V. Levin
@ 2018-12-10  4:30 ` Dmitry V. Levin
  2018-12-10  4:30 ` [PATCH v5 21/25] unicore32: add asm/syscall.h Dmitry V. Levin
                   ` (4 subsequent siblings)
  24 siblings, 0 replies; 65+ messages in thread
From: Dmitry V. Levin @ 2018-12-10  4:30 UTC (permalink / raw)
  To: Guan Xuetao, Oleg Nesterov, Andy Lutomirski
  Cc: Elvira Khabirova, Eugene Syromyatnikov, linux-kernel

This should never have been defined in the arch tree to begin with,
and now uapi/linux/audit.h header is going to use EM_UNICORE
in order to define AUDIT_ARCH_UNICORE which is needed to implement
syscall_get_arch() which in turn is required to extend
the generic ptrace API with PTRACE_GET_SYSCALL_INFO request.

Cc: Guan Xuetao <gxt@pku.edu.cn>
Cc: Oleg Nesterov <oleg@redhat.com>
Cc: Andy Lutomirski <luto@kernel.org>
Cc: Elvira Khabirova <lineprinter@altlinux.org>
Cc: Eugene Syromyatnikov <esyr@redhat.com>
Signed-off-by: Dmitry V. Levin <ldv@altlinux.org>
---

Notes:
    v5: added Cc

 arch/unicore32/include/asm/elf.h | 3 +--
 include/uapi/linux/elf-em.h      | 1 +
 2 files changed, 2 insertions(+), 2 deletions(-)

diff --git a/arch/unicore32/include/asm/elf.h b/arch/unicore32/include/asm/elf.h
index 829042d07722..ae66dc1be49e 100644
--- a/arch/unicore32/include/asm/elf.h
+++ b/arch/unicore32/include/asm/elf.h
@@ -19,6 +19,7 @@
  * ELF register definitions..
  */
 #include <asm/ptrace.h>
+#include <linux/elf-em.h>
 
 typedef unsigned long elf_greg_t;
 typedef unsigned long elf_freg_t[3];
@@ -28,8 +29,6 @@ typedef elf_greg_t elf_gregset_t[ELF_NGREG];
 
 typedef struct fp_state elf_fpregset_t;
 
-#define EM_UNICORE		110
-
 #define R_UNICORE_NONE		0
 #define R_UNICORE_PC24		1
 #define R_UNICORE_ABS32		2
diff --git a/include/uapi/linux/elf-em.h b/include/uapi/linux/elf-em.h
index f392dd9d07f7..2533bb1db3ef 100644
--- a/include/uapi/linux/elf-em.h
+++ b/include/uapi/linux/elf-em.h
@@ -37,6 +37,7 @@
 #define EM_ARCOMPACT	93	/* ARCompact processor */
 #define EM_XTENSA	94	/* Tensilica Xtensa Architecture */
 #define EM_BLACKFIN     106     /* ADI Blackfin Processor */
+#define EM_UNICORE	110	/* UniCore-32 */
 #define EM_ALTERA_NIOS2	113	/* Altera Nios II soft-core processor */
 #define EM_TI_C6000	140	/* TI C6X DSPs */
 #define EM_HEXAGON	164	/* QUALCOMM Hexagon */
-- 
ldv

^ permalink raw reply related	[flat|nested] 65+ messages in thread

* [PATCH v5 21/25] unicore32: add asm/syscall.h
       [not found] <20181210042352.GA6092@altlinux.org>
                   ` (19 preceding siblings ...)
  2018-12-10  4:30 ` [PATCH v5 20/25] Move EM_UNICORE to uapi/linux/elf-em.h Dmitry V. Levin
@ 2018-12-10  4:30 ` Dmitry V. Levin
  2018-12-10  4:31 ` [PATCH v5 22/25] syscall_get_arch: add "struct task_struct *" argument Dmitry V. Levin
                   ` (3 subsequent siblings)
  24 siblings, 0 replies; 65+ messages in thread
From: Dmitry V. Levin @ 2018-12-10  4:30 UTC (permalink / raw)
  To: Guan Xuetao, Paul Moore, Eric Paris, Oleg Nesterov, Andy Lutomirski
  Cc: Elvira Khabirova, Eugene Syromyatnikov, linux-audit, linux-kernel

syscall_get_* functions are required to be implemented on all
architectures in order to extend the generic ptrace API with
PTRACE_GET_SYSCALL_INFO request.

This introduces asm/syscall.h on unicore32 implementing all 5
syscall_get_* functions as documented in asm-generic/syscall.h:
syscall_get_nr, syscall_get_arguments, syscall_get_error,
syscall_get_return_value, and syscall_get_arch.

A note for the unicore32 architecture maintainer: I have no idea about
the syscall semantics on this architecture, and the code is of little
help here.  All I could infer from the code is that it looks very
similar to ARM, so the implementation of syscall_get_* functions
is also similar to ARM.

Cc: Guan Xuetao <gxt@pku.edu.cn>
Cc: Paul Moore <paul@paul-moore.com>
Cc: Eric Paris <eparis@redhat.com>
Cc: Oleg Nesterov <oleg@redhat.com>
Cc: Andy Lutomirski <luto@kernel.org>
Cc: Elvira Khabirova <lineprinter@altlinux.org>
Cc: Eugene Syromyatnikov <esyr@redhat.com>
Cc: linux-audit@redhat.com
Signed-off-by: Dmitry V. Levin <ldv@altlinux.org>
---

Notes:
    v5: added syscall_get_nr, syscall_get_arguments, syscall_get_error,
        and syscall_get_return_value
    v1: added syscall_get_arch

 arch/unicore32/include/asm/syscall.h | 45 ++++++++++++++++++++++++++++
 include/uapi/linux/audit.h           |  1 +
 2 files changed, 46 insertions(+)
 create mode 100644 arch/unicore32/include/asm/syscall.h

diff --git a/arch/unicore32/include/asm/syscall.h b/arch/unicore32/include/asm/syscall.h
new file mode 100644
index 000000000000..e30d08acf359
--- /dev/null
+++ b/arch/unicore32/include/asm/syscall.h
@@ -0,0 +1,45 @@
+/* SPDX-License-Identifier: GPL-2.0 */
+#ifndef _ASM_UNICORE_SYSCALL_H
+#define _ASM_UNICORE_SYSCALL_H
+
+#include <uapi/linux/audit.h>
+
+static inline int
+syscall_get_nr(struct task_struct *task, struct pt_regs *regs)
+{
+	return task_thread_info(task)->syscall;
+}
+
+static inline void
+syscall_get_arguments(struct task_struct *task, struct pt_regs *regs,
+		      unsigned int i, unsigned int n, unsigned long *args)
+{
+	BUG_ON(i + n > 6);
+	if (i == 0) {
+		args[0] = regs->UCreg_ORIG_00;
+		args++;
+		i++;
+		n--;
+	}
+	memcpy(args, &regs->UCreg_00 + i, n * sizeof(args[0]));
+}
+
+static inline long
+syscall_get_error(struct task_struct *task, struct pt_regs *regs)
+{
+	return IS_ERR_VALUE(regs->UCreg_00) ? regs->UCreg_00 : 0;
+}
+
+static inline long
+syscall_get_return_value(struct task_struct *task, struct pt_regs *regs)
+{
+	return regs->UCreg_00;
+}
+
+static inline int
+syscall_get_arch(void)
+{
+	return AUDIT_ARCH_UNICORE;
+}
+
+#endif	/* _ASM_UNICORE_SYSCALL_H */
diff --git a/include/uapi/linux/audit.h b/include/uapi/linux/audit.h
index bcc0619b046f..3901c51c0b93 100644
--- a/include/uapi/linux/audit.h
+++ b/include/uapi/linux/audit.h
@@ -424,6 +424,7 @@ enum {
 #define AUDIT_ARCH_TILEGX	(EM_TILEGX|__AUDIT_ARCH_64BIT|__AUDIT_ARCH_LE)
 #define AUDIT_ARCH_TILEGX32	(EM_TILEGX|__AUDIT_ARCH_LE)
 #define AUDIT_ARCH_TILEPRO	(EM_TILEPRO|__AUDIT_ARCH_LE)
+#define AUDIT_ARCH_UNICORE	(EM_UNICORE|__AUDIT_ARCH_LE)
 #define AUDIT_ARCH_X86_64	(EM_X86_64|__AUDIT_ARCH_64BIT|__AUDIT_ARCH_LE)
 #define AUDIT_ARCH_XTENSA	(EM_XTENSA)
 
-- 
ldv

^ permalink raw reply related	[flat|nested] 65+ messages in thread

* [PATCH v5 22/25] syscall_get_arch: add "struct task_struct *" argument
       [not found] <20181210042352.GA6092@altlinux.org>
                   ` (20 preceding siblings ...)
  2018-12-10  4:30 ` [PATCH v5 21/25] unicore32: add asm/syscall.h Dmitry V. Levin
@ 2018-12-10  4:31 ` Dmitry V. Levin
  2018-12-10 17:29   ` Kees Cook
  2018-12-11 22:44   ` Mark Salter
  2018-12-10  4:31 ` [PATCH v5 23/25] powerpc/ptrace: replace ptrace_report_syscall() with a tracehook call Dmitry V. Levin
                   ` (2 subsequent siblings)
  24 siblings, 2 replies; 65+ messages in thread
From: Dmitry V. Levin @ 2018-12-10  4:31 UTC (permalink / raw)
  To: Andy Lutomirski, Palmer Dabbelt, Paul Burton, Michael Ellerman,
	Eric Paris, Paul Moore, Richard Henderson, Ivan Kokshaysky,
	Matt Turner, Vineet Gupta, Russell King, Catalin Marinas,
	Will Deacon, Mark Salter, Aurelien Jacquiot, Yoshinori Sato,
	Richard Kuo, Tony Luck, Fenghua Yu, Geert Uytterhoeven,
	Michal Simek, Greentime Hu, Vincent Chen, Ley Foon Tan,
	Jonas Bonn, Stefan Kristiansson, Stafford Horne,
	James E.J. Bottomley, Helge Deller, Albert Ou,
	Martin Schwidefsky, Heiko Carstens, Rich Felker, David S. Miller,
	Guan Xuetao, Jeff Dike, Richard Weinberger, Chris Zankel,
	Max Filippov, Arnd Bergmann, Kees Cook, Will Drewry,
	Oleg Nesterov
  Cc: Elvira Khabirova, Eugene Syromyatnikov, Ralf Baechle,
	James Hogan, Benjamin Herrenschmidt, Paul Mackerras,
	Thomas Gleixner, Ingo Molnar, Borislav Petkov, H. Peter Anvin,
	x86, linux-alpha, linux-snps-arc, linux-arm-kernel,
	linux-c6x-dev, uclinux-h8-devel, linux-hexagon, linux-ia64,
	linux-m68k, linux-mips, nios2-dev, openrisc, linux-parisc,
	linuxppc-dev, linux-riscv, linux-s390, linux-sh, sparclinux,
	linux-um, linux-xtensa, linux-arch, linux-audit, linux-kernel

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 <luto@kernel.org> # for x86
Reviewed-by: Palmer Dabbelt <palmer@sifive.com>
Acked-by: Paul Burton <paul.burton@mips.com> # MIPS parts
Acked-by: Michael Ellerman <mpe@ellerman.id.au> (powerpc)
Cc: Eric Paris <eparis@redhat.com>
Cc: Paul Moore <paul@paul-moore.com>
Cc: Richard Henderson <rth@twiddle.net>
Cc: Ivan Kokshaysky <ink@jurassic.park.msu.ru>
Cc: Matt Turner <mattst88@gmail.com>
Cc: Vineet Gupta <vgupta@synopsys.com>
Cc: Russell King <linux@armlinux.org.uk>
Cc: Catalin Marinas <catalin.marinas@arm.com>
Cc: Will Deacon <will.deacon@arm.com>
Cc: Mark Salter <msalter@redhat.com>
Cc: Aurelien Jacquiot <jacquiot.aurelien@gmail.com>
Cc: Yoshinori Sato <ysato@users.sourceforge.jp>
Cc: Richard Kuo <rkuo@codeaurora.org>
Cc: Tony Luck <tony.luck@intel.com>
Cc: Fenghua Yu <fenghua.yu@intel.com>
Cc: Geert Uytterhoeven <geert@linux-m68k.org>
Cc: Michal Simek <monstr@monstr.eu>
Cc: Greentime Hu <green.hu@gmail.com>
Cc: Vincent Chen <deanbo422@gmail.com>
Cc: Ley Foon Tan <lftan@altera.com>
Cc: Jonas Bonn <jonas@southpole.se>
Cc: Stefan Kristiansson <stefan.kristiansson@saunalahti.fi>
Cc: Stafford Horne <shorne@gmail.com>
Cc: James E.J. Bottomley <jejb@parisc-linux.org>
Cc: Helge Deller <deller@gmx.de>
Cc: Albert Ou <aou@eecs.berkeley.edu>
Cc: Martin Schwidefsky <schwidefsky@de.ibm.com>
Cc: Heiko Carstens <heiko.carstens@de.ibm.com>
Cc: Rich Felker <dalias@libc.org>
Cc: David S. Miller <davem@davemloft.net>
Cc: Guan Xuetao <gxt@pku.edu.cn>
Cc: Jeff Dike <jdike@addtoit.com>
Cc: Richard Weinberger <richard@nod.at>
Cc: Chris Zankel <chris@zankel.net>
Cc: Max Filippov <jcmvbkbc@gmail.com>
Cc: Arnd Bergmann <arnd@arndb.de>
Cc: Kees Cook <keescook@chromium.org>
Cc: Will Drewry <wad@chromium.org>
Cc: Oleg Nesterov <oleg@redhat.com>
Cc: Elvira Khabirova <lineprinter@altlinux.org>
Cc: Eugene Syromyatnikov <esyr@redhat.com>
Cc: Ralf Baechle <ralf@linux-mips.org>
Cc: James Hogan <jhogan@kernel.org>
Cc: Benjamin Herrenschmidt <benh@kernel.crashing.org>
Cc: Paul Mackerras <paulus@samba.org>
Cc: Thomas Gleixner <tglx@linutronix.de>
Cc: Ingo Molnar <mingo@redhat.com>
Cc: Borislav Petkov <bp@alien8.de>
Cc: H. Peter Anvin <hpa@zytor.com>
Cc: x86@kernel.org
Cc: linux-alpha@vger.kernel.org
Cc: linux-snps-arc@lists.infradead.org
Cc: linux-arm-kernel@lists.infradead.org
Cc: linux-c6x-dev@linux-c6x.org
Cc: uclinux-h8-devel@lists.sourceforge.jp
Cc: linux-hexagon@vger.kernel.org
Cc: linux-ia64@vger.kernel.org
Cc: linux-m68k@lists.linux-m68k.org
Cc: linux-mips@vger.kernel.org
Cc: nios2-dev@lists.rocketboards.org
Cc: openrisc@lists.librecores.org
Cc: linux-parisc@vger.kernel.org
Cc: linuxppc-dev@lists.ozlabs.org
Cc: linux-riscv@lists.infradead.org
Cc: linux-s390@vger.kernel.org
Cc: linux-sh@vger.kernel.org
Cc: sparclinux@vger.kernel.org
Cc: linux-um@lists.infradead.org
Cc: linux-xtensa@linux-xtensa.org
Cc: linux-arch@vger.kernel.org
Cc: linux-audit@redhat.com
Signed-off-by: Dmitry V. Levin <ldv@altlinux.org>
---

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/syscall.h
+++ b/arch/arm/include/asm/syscall.h
@@ -104,7 +104,7 @@ static inline void syscall_set_arguments(struct task_struct *task,
 	memcpy(&regs->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,
 	}
 }
 
-static inline int syscall_get_arch(void)
+static inline int syscall_get_arch(struct task_struct *task)
 {
 	return IS_ENABLED(CONFIG_CPU_BIG_ENDIAN)
 		? AUDIT_ARCH_C6XBE : AUDIT_ARCH_C6X;
diff --git a/arch/csky/include/asm/syscall.h b/arch/csky/include/asm/syscall.h
index d637445737b7..150ffb894fa2 100644
--- a/arch/csky/include/asm/syscall.h
+++ b/arch/csky/include/asm/syscall.h
@@ -70,7 +70,7 @@ syscall_set_arguments(struct task_struct *task, struct pt_regs *regs,
 }
 
 static inline int
-syscall_get_arch(void)
+syscall_get_arch(struct task_struct *task)
 {
 	return AUDIT_ARCH_CSKY;
 }
diff --git a/arch/h8300/include/asm/syscall.h b/arch/h8300/include/asm/syscall.h
index 5c881ffe962a..9cb1f14ddd77 100644
--- a/arch/h8300/include/asm/syscall.h
+++ b/arch/h8300/include/asm/syscall.h
@@ -61,7 +61,7 @@ syscall_get_return_value(struct task_struct *task, struct pt_regs *regs)
 }
 
 static inline int
-syscall_get_arch(void)
+syscall_get_arch(struct task_struct *task)
 {
 	return AUDIT_ARCH_H8300;
 }
diff --git a/arch/hexagon/include/asm/syscall.h b/arch/hexagon/include/asm/syscall.h
index 09c7b2884475..c6bc69513be8 100644
--- a/arch/hexagon/include/asm/syscall.h
+++ b/arch/hexagon/include/asm/syscall.h
@@ -58,7 +58,7 @@ static inline long syscall_get_return_value(struct task_struct *task,
 	return regs->r00;
 }
 
-static inline int syscall_get_arch(void)
+static inline int syscall_get_arch(struct task_struct *task)
 {
 	return AUDIT_ARCH_HEXAGON;
 }
diff --git a/arch/ia64/include/asm/syscall.h b/arch/ia64/include/asm/syscall.h
index 1d0b875fec44..47ab33f5448a 100644
--- a/arch/ia64/include/asm/syscall.h
+++ b/arch/ia64/include/asm/syscall.h
@@ -81,7 +81,7 @@ static inline void syscall_set_arguments(struct task_struct *task,
 	ia64_syscall_get_set_arguments(task, regs, i, n, args, 1);
 }
 
-static inline int syscall_get_arch(void)
+static inline int syscall_get_arch(struct task_struct *task)
 {
 	return AUDIT_ARCH_IA64;
 }
diff --git a/arch/m68k/include/asm/syscall.h b/arch/m68k/include/asm/syscall.h
index 75a24cf90620..69d2b6eb97fd 100644
--- a/arch/m68k/include/asm/syscall.h
+++ b/arch/m68k/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_M68K;
 }
diff --git a/arch/microblaze/include/asm/syscall.h b/arch/microblaze/include/asm/syscall.h
index 220decd605a4..77a86fafa974 100644
--- a/arch/microblaze/include/asm/syscall.h
+++ b/arch/microblaze/include/asm/syscall.h
@@ -101,7 +101,7 @@ static inline void syscall_set_arguments(struct task_struct *task,
 asmlinkage unsigned long do_syscall_trace_enter(struct pt_regs *regs);
 asmlinkage void do_syscall_trace_leave(struct pt_regs *regs);
 
-static inline int syscall_get_arch(void)
+static inline int syscall_get_arch(struct task_struct *task)
 {
 	return AUDIT_ARCH_MICROBLAZE;
 }
diff --git a/arch/mips/include/asm/syscall.h b/arch/mips/include/asm/syscall.h
index 04ab927ff47d..466957d0474b 100644
--- a/arch/mips/include/asm/syscall.h
+++ b/arch/mips/include/asm/syscall.h
@@ -146,14 +146,14 @@ extern const unsigned long sys_call_table[];
 extern const unsigned long sys32_call_table[];
 extern const unsigned long sysn32_call_table[];
 
-static inline int syscall_get_arch(void)
+static inline int syscall_get_arch(struct task_struct *task)
 {
 	int arch = AUDIT_ARCH_MIPS;
 #ifdef CONFIG_64BIT
-	if (!test_thread_flag(TIF_32BIT_REGS)) {
+	if (!test_tsk_thread_flag(task, TIF_32BIT_REGS)) {
 		arch |= __AUDIT_ARCH_64BIT;
 		/* N32 sets only TIF_32BIT_ADDR */
-		if (test_thread_flag(TIF_32BIT_ADDR))
+		if (test_tsk_thread_flag(task, TIF_32BIT_ADDR))
 			arch |= __AUDIT_ARCH_CONVENTION_MIPS64_N32;
 	}
 #endif
diff --git a/arch/mips/kernel/ptrace.c b/arch/mips/kernel/ptrace.c
index e5ba56c01ee0..e112c525c3a7 100644
--- a/arch/mips/kernel/ptrace.c
+++ b/arch/mips/kernel/ptrace.c
@@ -1272,7 +1272,7 @@ asmlinkage long syscall_trace_enter(struct pt_regs *regs, long syscall)
 		unsigned long args[6];
 
 		sd.nr = syscall;
-		sd.arch = syscall_get_arch();
+		sd.arch = syscall_get_arch(current);
 		syscall_get_arguments(current, regs, 0, 6, args);
 		for (i = 0; i < 6; i++)
 			sd.args[i] = args[i];
diff --git a/arch/nds32/include/asm/syscall.h b/arch/nds32/include/asm/syscall.h
index 569149ca25da..e109acd225e6 100644
--- a/arch/nds32/include/asm/syscall.h
+++ b/arch/nds32/include/asm/syscall.h
@@ -187,7 +187,7 @@ void syscall_set_arguments(struct task_struct *task, struct pt_regs *regs,
 	memcpy(&regs->uregs[0] + i, args, n * sizeof(args[0]));
 }
 
-static inline int syscall_get_arch(void)
+static inline int syscall_get_arch(struct task_struct *task)
 {
 	return IS_ENABLED(CONFIG_CPU_BIG_ENDIAN)
 		? AUDIT_ARCH_NDS32BE : AUDIT_ARCH_NDS32;
diff --git a/arch/nios2/include/asm/syscall.h b/arch/nios2/include/asm/syscall.h
index cf35e210fc4d..f0f6ae208e78 100644
--- a/arch/nios2/include/asm/syscall.h
+++ b/arch/nios2/include/asm/syscall.h
@@ -136,7 +136,7 @@ static inline void syscall_set_arguments(struct task_struct *task,
 	}
 }
 
-static inline int syscall_get_arch(void)
+static inline int syscall_get_arch(struct task_struct *task)
 {
 	return AUDIT_ARCH_NIOS2;
 }
diff --git a/arch/openrisc/include/asm/syscall.h b/arch/openrisc/include/asm/syscall.h
index 2db9f1cf0694..46b10c674bd2 100644
--- a/arch/openrisc/include/asm/syscall.h
+++ b/arch/openrisc/include/asm/syscall.h
@@ -72,7 +72,7 @@ syscall_set_arguments(struct task_struct *task, struct pt_regs *regs,
 	memcpy(&regs->gpr[3 + i], args, n * sizeof(args[0]));
 }
 
-static inline int syscall_get_arch(void)
+static inline int syscall_get_arch(struct task_struct *task)
 {
 	return AUDIT_ARCH_OPENRISC;
 }
diff --git a/arch/parisc/include/asm/syscall.h b/arch/parisc/include/asm/syscall.h
index 477511ff7546..310016e1925d 100644
--- a/arch/parisc/include/asm/syscall.h
+++ b/arch/parisc/include/asm/syscall.h
@@ -69,11 +69,11 @@ static inline void syscall_rollback(struct task_struct *task,
 	/* do nothing */
 }
 
-static inline int syscall_get_arch(void)
+static inline int syscall_get_arch(struct task_struct *task)
 {
 	int arch = AUDIT_ARCH_PARISC;
 #ifdef CONFIG_64BIT
-	if (!is_compat_task())
+	if (!__is_compat_task(task))
 		arch = AUDIT_ARCH_PARISC64;
 #endif
 	return arch;
diff --git a/arch/powerpc/include/asm/syscall.h b/arch/powerpc/include/asm/syscall.h
index 1d03e753391d..70f9e538e1b3 100644
--- a/arch/powerpc/include/asm/syscall.h
+++ b/arch/powerpc/include/asm/syscall.h
@@ -110,9 +110,15 @@ static inline void syscall_set_arguments(struct task_struct *task,
 		regs->orig_gpr3 = args[0];
 }
 
-static inline int syscall_get_arch(void)
+static inline int syscall_get_arch(struct task_struct *task)
 {
-	int arch = is_32bit_task() ? AUDIT_ARCH_PPC : AUDIT_ARCH_PPC64;
+	int arch;
+
+	if (IS_ENABLED(CONFIG_PPC64) && !test_tsk_thread_flag(task, TIF_32BIT))
+		arch = AUDIT_ARCH_PPC64;
+	else
+		arch = AUDIT_ARCH_PPC;
+
 #ifdef __LITTLE_ENDIAN__
 	arch |= __AUDIT_ARCH_LE;
 #endif
diff --git a/arch/riscv/include/asm/syscall.h b/arch/riscv/include/asm/syscall.h
index bba3da6ef157..ca120a36a037 100644
--- a/arch/riscv/include/asm/syscall.h
+++ b/arch/riscv/include/asm/syscall.h
@@ -100,7 +100,7 @@ static inline void syscall_set_arguments(struct task_struct *task,
 	memcpy(&regs->a1 + i * sizeof(regs->a1), args, n * sizeof(regs->a0));
 }
 
-static inline int syscall_get_arch(void)
+static inline int syscall_get_arch(struct task_struct *task)
 {
 #ifdef CONFIG_64BIT
 	return AUDIT_ARCH_RISCV64;
diff --git a/arch/s390/include/asm/syscall.h b/arch/s390/include/asm/syscall.h
index 96f9a9151fde..5a40ea8b90ea 100644
--- a/arch/s390/include/asm/syscall.h
+++ b/arch/s390/include/asm/syscall.h
@@ -92,10 +92,10 @@ static inline void syscall_set_arguments(struct task_struct *task,
 		regs->orig_gpr2 = args[0];
 }
 
-static inline int syscall_get_arch(void)
+static inline int syscall_get_arch(struct task_struct *task)
 {
 #ifdef CONFIG_COMPAT
-	if (test_tsk_thread_flag(current, TIF_31BIT))
+	if (test_tsk_thread_flag(task, TIF_31BIT))
 		return AUDIT_ARCH_S390;
 #endif
 	return AUDIT_ARCH_S390X;
diff --git a/arch/sh/include/asm/syscall_32.h b/arch/sh/include/asm/syscall_32.h
index 6e118799831c..08de429eccd4 100644
--- a/arch/sh/include/asm/syscall_32.h
+++ b/arch/sh/include/asm/syscall_32.h
@@ -95,7 +95,7 @@ static inline void syscall_set_arguments(struct task_struct *task,
 	}
 }
 
-static inline int syscall_get_arch(void)
+static inline int syscall_get_arch(struct task_struct *task)
 {
 	int arch = AUDIT_ARCH_SH;
 
diff --git a/arch/sh/include/asm/syscall_64.h b/arch/sh/include/asm/syscall_64.h
index 43882580c7f9..9b62a2404531 100644
--- a/arch/sh/include/asm/syscall_64.h
+++ b/arch/sh/include/asm/syscall_64.h
@@ -63,7 +63,7 @@ static inline void syscall_set_arguments(struct task_struct *task,
 	memcpy(&regs->regs[2 + i], args, n * sizeof(args[0]));
 }
 
-static inline int syscall_get_arch(void)
+static inline int syscall_get_arch(struct task_struct *task)
 {
 	int arch = AUDIT_ARCH_SH;
 
diff --git a/arch/sparc/include/asm/syscall.h b/arch/sparc/include/asm/syscall.h
index 053989e3f6a6..9ffb367c17fd 100644
--- a/arch/sparc/include/asm/syscall.h
+++ b/arch/sparc/include/asm/syscall.h
@@ -128,10 +128,11 @@ static inline void syscall_set_arguments(struct task_struct *task,
 		regs->u_regs[UREG_I0 + i + j] = args[j];
 }
 
-static inline int syscall_get_arch(void)
+static inline int syscall_get_arch(struct task_struct *task)
 {
 #if defined(CONFIG_SPARC64) && defined(CONFIG_COMPAT)
-	return in_compat_syscall() ? AUDIT_ARCH_SPARC : AUDIT_ARCH_SPARC64;
+	return test_tsk_thread_flag(task, TIF_32BIT)
+		? AUDIT_ARCH_SPARC : AUDIT_ARCH_SPARC64;
 #elif defined(CONFIG_SPARC64)
 	return AUDIT_ARCH_SPARC64;
 #else
diff --git a/arch/unicore32/include/asm/syscall.h b/arch/unicore32/include/asm/syscall.h
index e30d08acf359..db8a59ffbcbc 100644
--- a/arch/unicore32/include/asm/syscall.h
+++ b/arch/unicore32/include/asm/syscall.h
@@ -37,7 +37,7 @@ syscall_get_return_value(struct task_struct *task, struct pt_regs *regs)
 }
 
 static inline int
-syscall_get_arch(void)
+syscall_get_arch(struct task_struct *task)
 {
 	return AUDIT_ARCH_UNICORE;
 }
diff --git a/arch/x86/include/asm/syscall.h b/arch/x86/include/asm/syscall.h
index d653139857af..435f3f09279c 100644
--- a/arch/x86/include/asm/syscall.h
+++ b/arch/x86/include/asm/syscall.h
@@ -107,7 +107,7 @@ static inline void syscall_set_arguments(struct task_struct *task,
 	memcpy(&regs->bx + i, args, n * sizeof(args[0]));
 }
 
-static inline int syscall_get_arch(void)
+static inline int syscall_get_arch(struct task_struct *task)
 {
 	return AUDIT_ARCH_I386;
 }
@@ -236,10 +236,12 @@ static inline void syscall_set_arguments(struct task_struct *task,
 		}
 }
 
-static inline int syscall_get_arch(void)
+static inline int syscall_get_arch(struct task_struct *task)
 {
 	/* x32 tasks should be considered AUDIT_ARCH_X86_64. */
-	return in_ia32_syscall() ? AUDIT_ARCH_I386 : AUDIT_ARCH_X86_64;
+	return (IS_ENABLED(CONFIG_IA32_EMULATION) &&
+		task->thread_info.status & TS_COMPAT)
+		? AUDIT_ARCH_I386 : AUDIT_ARCH_X86_64;
 }
 #endif	/* CONFIG_X86_32 */
 
diff --git a/arch/x86/um/asm/syscall.h b/arch/x86/um/asm/syscall.h
index ef898af102d1..56a2f0913e3c 100644
--- a/arch/x86/um/asm/syscall.h
+++ b/arch/x86/um/asm/syscall.h
@@ -9,7 +9,7 @@ typedef asmlinkage long (*sys_call_ptr_t)(unsigned long, unsigned long,
 					  unsigned long, unsigned long,
 					  unsigned long, unsigned long);
 
-static inline int syscall_get_arch(void)
+static inline int syscall_get_arch(struct task_struct *task)
 {
 #ifdef CONFIG_X86_32
 	return AUDIT_ARCH_I386;
diff --git a/arch/xtensa/include/asm/syscall.h b/arch/xtensa/include/asm/syscall.h
index d529c855a144..008e9da4d126 100644
--- a/arch/xtensa/include/asm/syscall.h
+++ b/arch/xtensa/include/asm/syscall.h
@@ -72,7 +72,7 @@ syscall_get_return_value(struct task_struct *task, struct pt_regs *regs)
 }
 
 static inline int
-syscall_get_arch(void)
+syscall_get_arch(struct task_struct *task)
 {
 	return AUDIT_ARCH_XTENSA;
 }
diff --git a/include/asm-generic/syscall.h b/include/asm-generic/syscall.h
index 0c938a4354f6..e0d060b43321 100644
--- a/include/asm-generic/syscall.h
+++ b/include/asm-generic/syscall.h
@@ -144,14 +144,15 @@ void syscall_set_arguments(struct task_struct *task, struct pt_regs *regs,
 
 /**
  * syscall_get_arch - return the AUDIT_ARCH for the current system call
+ * @task:	task of interest, must be blocked
  *
  * Returns the AUDIT_ARCH_* based on the system call convention in use.
  *
- * It's only valid to call this when current is stopped on entry to a system
+ * It's only valid to call this when @task is stopped on entry to a system
  * call, due to %TIF_SYSCALL_TRACE, %TIF_SYSCALL_AUDIT, or %TIF_SECCOMP.
  *
  * Architectures which permit CONFIG_HAVE_ARCH_SECCOMP_FILTER must
  * provide an implementation of this.
  */
-int syscall_get_arch(void);
+int syscall_get_arch(struct task_struct *task);
 #endif	/* _ASM_SYSCALL_H */
diff --git a/kernel/auditsc.c b/kernel/auditsc.c
index b2d1f043f17f..1319e3e7b16c 100644
--- a/kernel/auditsc.c
+++ b/kernel/auditsc.c
@@ -1537,7 +1537,7 @@ void __audit_syscall_entry(int major, unsigned long a1, unsigned long a2,
 			return;
 	}
 
-	context->arch	    = syscall_get_arch();
+	context->arch	    = syscall_get_arch(current);
 	context->major      = major;
 	context->argv[0]    = a1;
 	context->argv[1]    = a2;
@@ -2495,7 +2495,7 @@ void audit_seccomp(unsigned long syscall, long signr, int code)
 		return;
 	audit_log_task(ab);
 	audit_log_format(ab, " sig=%ld arch=%x syscall=%ld compat=%d ip=0x%lx code=0x%x",
-			 signr, syscall_get_arch(), syscall,
+			 signr, syscall_get_arch(current), syscall,
 			 in_compat_syscall(), KSTK_EIP(current), code);
 	audit_log_end(ab);
 }
diff --git a/kernel/seccomp.c b/kernel/seccomp.c
index f2ae2324c232..77cb87bd2eae 100644
--- a/kernel/seccomp.c
+++ b/kernel/seccomp.c
@@ -82,7 +82,7 @@ static void populate_seccomp_data(struct seccomp_data *sd)
 	unsigned long args[6];
 
 	sd->nr = syscall_get_nr(task, regs);
-	sd->arch = syscall_get_arch();
+	sd->arch = syscall_get_arch(task);
 	syscall_get_arguments(task, regs, 0, 6, args);
 	sd->args[0] = args[0];
 	sd->args[1] = args[1];
@@ -529,7 +529,7 @@ static void seccomp_init_siginfo(kernel_siginfo_t *info, int syscall, int reason
 	info->si_code = SYS_SECCOMP;
 	info->si_call_addr = (void __user *)KSTK_EIP(current);
 	info->si_errno = reason;
-	info->si_arch = syscall_get_arch();
+	info->si_arch = syscall_get_arch(current);
 	info->si_syscall = syscall;
 }
 
-- 
ldv

^ permalink raw reply related	[flat|nested] 65+ messages in thread

* [PATCH v5 23/25] powerpc/ptrace: replace ptrace_report_syscall() with a tracehook call
       [not found] <20181210042352.GA6092@altlinux.org>
                   ` (21 preceding siblings ...)
  2018-12-10  4:31 ` [PATCH v5 22/25] syscall_get_arch: add "struct task_struct *" argument Dmitry V. Levin
@ 2018-12-10  4:31 ` Dmitry V. Levin
  2018-12-10  4:31 ` [PATCH v5 24/25] ptrace: add PTRACE_GET_SYSCALL_INFO request Dmitry V. Levin
  2018-12-10  4:31 ` [PATCH v5 25/25] selftests/ptrace: add a test case for PTRACE_GET_SYSCALL_INFO Dmitry V. Levin
  24 siblings, 0 replies; 65+ messages in thread
From: Dmitry V. Levin @ 2018-12-10  4:31 UTC (permalink / raw)
  To: Michael Ellerman, Oleg Nesterov
  Cc: Elvira Khabirova, Eugene Syromyatnikov, Benjamin Herrenschmidt,
	Paul Mackerras, Breno Leitao, Andy Lutomirski, linuxppc-dev,
	linux-kernel

From: Elvira Khabirova <lineprinter@altlinux.org>

Arch code should use tracehook_*() helpers, as documented
in include/linux/tracehook.h,
ptrace_report_syscall() is not expected to be used outside that file.

The patch does not look very nice, but at least it is correct
and opens the way for PTRACE_GET_SYSCALL_INFO API.

Co-authored-by: Dmitry V. Levin <ldv@altlinux.org>
Fixes: 5521eb4bca2d ("powerpc/ptrace: Add support for PTRACE_SYSEMU")
Cc: Michael Ellerman <mpe@ellerman.id.au>
Cc: Oleg Nesterov <oleg@redhat.com>
Cc: Eugene Syromyatnikov <esyr@redhat.com>
Cc: Benjamin Herrenschmidt <benh@kernel.crashing.org>
Cc: Paul Mackerras <paulus@samba.org>
Cc: Breno Leitao <leitao@debian.org>
Cc: Andy Lutomirski <luto@kernel.org>
Cc: linuxppc-dev@lists.ozlabs.org
Signed-off-by: Elvira Khabirova <lineprinter@altlinux.org>
Signed-off-by: Dmitry V. Levin <ldv@altlinux.org>
---

Notes:
    v5: reverted to a simple approach, compile- and run-tested
    v4: rewritten to call tracehook_report_syscall_entry() once, compile-tested
    v3: add a descriptive comment
    v2: explicitly ignore tracehook_report_syscall_entry() return code

 arch/powerpc/kernel/ptrace.c | 7 ++++++-
 1 file changed, 6 insertions(+), 1 deletion(-)

diff --git a/arch/powerpc/kernel/ptrace.c b/arch/powerpc/kernel/ptrace.c
index afb819f4ca68..714c3480c52d 100644
--- a/arch/powerpc/kernel/ptrace.c
+++ b/arch/powerpc/kernel/ptrace.c
@@ -3266,12 +3266,17 @@ long do_syscall_trace_enter(struct pt_regs *regs)
 	user_exit();
 
 	if (test_thread_flag(TIF_SYSCALL_EMU)) {
-		ptrace_report_syscall(regs);
 		/*
+		 * A nonzero return code from tracehook_report_syscall_entry()
+		 * tells us to prevent the syscall execution, but we are not
+		 * going to execute it anyway.
+		 *
 		 * Returning -1 will skip the syscall execution. We want to
 		 * avoid clobbering any register also, thus, not 'gotoing'
 		 * skip label.
 		 */
+		if (tracehook_report_syscall_entry(regs))
+			;
 		return -1;
 	}
 
-- 
ldv

^ permalink raw reply related	[flat|nested] 65+ messages in thread

* [PATCH v5 24/25] ptrace: add PTRACE_GET_SYSCALL_INFO request
       [not found] <20181210042352.GA6092@altlinux.org>
                   ` (22 preceding siblings ...)
  2018-12-10  4:31 ` [PATCH v5 23/25] powerpc/ptrace: replace ptrace_report_syscall() with a tracehook call Dmitry V. Levin
@ 2018-12-10  4:31 ` Dmitry V. Levin
  2018-12-10 14:11   ` Oleg Nesterov
                     ` (3 more replies)
  2018-12-10  4:31 ` [PATCH v5 25/25] selftests/ptrace: add a test case for PTRACE_GET_SYSCALL_INFO Dmitry V. Levin
  24 siblings, 4 replies; 65+ messages in thread
From: Dmitry V. Levin @ 2018-12-10  4:31 UTC (permalink / raw)
  To: Oleg Nesterov, Andy Lutomirski
  Cc: Elvira Khabirova, Eugene Syromyatnikov, Kees Cook, Jann Horn,
	linux-api, strace-devel, linux-kernel

From: Elvira Khabirova <lineprinter@altlinux.org>

PTRACE_GET_SYSCALL_INFO is a generic ptrace API that lets ptracer obtain
details of the syscall the tracee is blocked in.

There are two reasons for a special syscall-related ptrace request.

Firstly, with the current ptrace API there are cases when ptracer cannot
retrieve necessary information about syscalls.  Some examples include:
* The notorious int-0x80-from-64-bit-task issue.  See [1] for details.
In short, if a 64-bit task performs a syscall through int 0x80, its tracer
has no reliable means to find out that the syscall was, in fact,
a compat syscall, and misidentifies it.
* Syscall-enter-stop and syscall-exit-stop look the same for the tracer.
Common practice is to keep track of the sequence of ptrace-stops in order
not to mix the two syscall-stops up.  But it is not as simple as it looks;
for example, strace had a (just recently fixed) long-standing bug where
attaching strace to a tracee that is performing the execve system call
led to the tracer identifying the following syscall-exit-stop as
syscall-enter-stop, which messed up all the state tracking.
* Since the introduction of commit 84d77d3f06e7e8dea057d10e8ec77ad71f721be3
("ptrace: Don't allow accessing an undumpable mm"), both PTRACE_PEEKDATA
and process_vm_readv become unavailable when the process dumpable flag
is cleared.  On such architectures as ia64 this results in all syscall
arguments being unavailable for the tracer.

Secondly, ptracers also have to support a lot of arch-specific code for
obtaining information about the tracee.  For some architectures, this
requires a ptrace(PTRACE_PEEKUSER, ...) invocation for every syscall
argument and return value.

ptrace(2) man page:

long ptrace(enum __ptrace_request request, pid_t pid,
            void *addr, void *data);
...
PTRACE_GET_SYSCALL_INFO
       Retrieve information about the syscall that caused the stop.
       The information is placed into the buffer pointed by "data"
       argument, which should be a pointer to a buffer of type
       "struct ptrace_syscall_info".
       The "addr" argument contains the size of the buffer pointed to
       by "data" argument (i.e., sizeof(struct ptrace_syscall_info)).
       The return value contains the number of bytes available
       to be written by the kernel.
       If the size of data to be written by the kernel exceeds the size
       specified by "addr" argument, the output is truncated.

Co-authored-by: Dmitry V. Levin <ldv@altlinux.org>
Cc: Oleg Nesterov <oleg@redhat.com>
Cc: Andy Lutomirski <luto@kernel.org>
Cc: Eugene Syromyatnikov <esyr@redhat.com>
Cc: Kees Cook <keescook@chromium.org>
Cc: Jann Horn <jannh@google.com>
Cc: linux-api@vger.kernel.org
Cc: strace-devel@lists.strace.io
Signed-off-by: Elvira Khabirova <lineprinter@altlinux.org>
Signed-off-by: Dmitry V. Levin <ldv@altlinux.org>
---

Notes:
    v5:
    * Change PTRACE_EVENTMSG_SYSCALL_{ENTRY,EXIT} values as requested by Oleg.
    * Change struct ptrace_syscall_info: generalize instruction_pointer,
      stack_pointer, and frame_pointer fields by moving them from
      ptrace_syscall_info.{entry,seccomp} substructures to ptrace_syscall_info
      and initializing them for all stops.
    * Add PTRACE_SYSCALL_INFO_NONE, set it when not in a syscall stop,
      so e.g. "strace -i" could use PTRACE_SYSCALL_INFO_SECCOMP to obtain
      instruction_pointer when the tracee is in a signal stop.
    * Make available for all architectures: do not conditionalize on
      CONFIG_HAVE_ARCH_TRACEHOOK since all syscall_get_* functions
      are implemented on all architectures.
    
    v4:
    * Do not introduce task_struct.ptrace_event,
      use child->last_siginfo->si_code instead.
    * Implement PTRACE_SYSCALL_INFO_SECCOMP and ptrace_syscall_info.seccomp
      support along with PTRACE_SYSCALL_INFO_{ENTRY,EXIT} and
      ptrace_syscall_info.{entry,exit}.
    
    v3:
    * Change struct ptrace_syscall_info.
    * Support PTRACE_EVENT_SECCOMP by adding ptrace_event to task_struct.
    * Add proper defines for ptrace_syscall_info.op values.
    * Rename PT_SYSCALL_IS_ENTERING and PT_SYSCALL_IS_EXITING to
      PTRACE_EVENTMSG_SYSCALL_ENTRY and PTRACE_EVENTMSG_SYSCALL_EXIT
    * and move them to uapi.
    
    v2:
    * Do not use task->ptrace.
    * Replace entry_info.is_compat with entry_info.arch, use syscall_get_arch().
    * Use addr argument of sys_ptrace to get expected size of the struct;
      return full size of the struct.

 include/linux/tracehook.h   |  9 ++--
 include/uapi/linux/ptrace.h | 39 +++++++++++++++
 kernel/ptrace.c             | 99 ++++++++++++++++++++++++++++++++++++-
 3 files changed, 143 insertions(+), 4 deletions(-)

diff --git a/include/linux/tracehook.h b/include/linux/tracehook.h
index df20f8bdbfa3..6bc7a3d58e2f 100644
--- a/include/linux/tracehook.h
+++ b/include/linux/tracehook.h
@@ -57,13 +57,15 @@ struct linux_binprm;
 /*
  * ptrace report for syscall entry and exit looks identical.
  */
-static inline int ptrace_report_syscall(struct pt_regs *regs)
+static inline int ptrace_report_syscall(struct pt_regs *regs,
+					unsigned long message)
 {
 	int ptrace = current->ptrace;
 
 	if (!(ptrace & PT_PTRACED))
 		return 0;
 
+	current->ptrace_message = message;
 	ptrace_notify(SIGTRAP | ((ptrace & PT_TRACESYSGOOD) ? 0x80 : 0));
 
 	/*
@@ -76,6 +78,7 @@ static inline int ptrace_report_syscall(struct pt_regs *regs)
 		current->exit_code = 0;
 	}
 
+	current->ptrace_message = 0;
 	return fatal_signal_pending(current);
 }
 
@@ -101,7 +104,7 @@ static inline int ptrace_report_syscall(struct pt_regs *regs)
 static inline __must_check int tracehook_report_syscall_entry(
 	struct pt_regs *regs)
 {
-	return ptrace_report_syscall(regs);
+	return ptrace_report_syscall(regs, PTRACE_EVENTMSG_SYSCALL_ENTRY);
 }
 
 /**
@@ -126,7 +129,7 @@ static inline void tracehook_report_syscall_exit(struct pt_regs *regs, int step)
 	if (step)
 		user_single_step_report(regs);
 	else
-		ptrace_report_syscall(regs);
+		ptrace_report_syscall(regs, PTRACE_EVENTMSG_SYSCALL_EXIT);
 }
 
 /**
diff --git a/include/uapi/linux/ptrace.h b/include/uapi/linux/ptrace.h
index d5a1b8a492b9..f0af09fe4e17 100644
--- a/include/uapi/linux/ptrace.h
+++ b/include/uapi/linux/ptrace.h
@@ -73,6 +73,45 @@ struct seccomp_metadata {
 	__u64 flags;		/* Output: filter's flags */
 };
 
+#define PTRACE_GET_SYSCALL_INFO		0x420e
+#define PTRACE_SYSCALL_INFO_NONE	0
+#define PTRACE_SYSCALL_INFO_ENTRY	1
+#define PTRACE_SYSCALL_INFO_EXIT	2
+#define PTRACE_SYSCALL_INFO_SECCOMP	3
+
+struct ptrace_syscall_info {
+	__u8 op;	/* PTRACE_SYSCALL_INFO_* */
+	__u8 __pad0[3];
+	__u32 arch;
+	__u64 instruction_pointer;
+	__u64 stack_pointer;
+	__u64 frame_pointer;
+	union {
+		struct {
+			__u64 nr;
+			__u64 args[6];
+		} entry;
+		struct {
+			__s64 rval;
+			__u8 is_error;
+			__u8 __pad1[7];
+		} exit;
+		struct {
+			__u64 nr;
+			__u64 args[6];
+			__u32 ret_data;
+			__u8 __pad2[4];
+		} seccomp;
+	};
+};
+
+/*
+ * These values are stored in task->ptrace_message
+ * by tracehook_report_syscall_* to describe the current syscall-stop.
+ */
+#define PTRACE_EVENTMSG_SYSCALL_ENTRY	1
+#define PTRACE_EVENTMSG_SYSCALL_EXIT	2
+
 /* Read signals from a shared (process wide) queue */
 #define PTRACE_PEEKSIGINFO_SHARED	(1 << 0)
 
diff --git a/kernel/ptrace.c b/kernel/ptrace.c
index c2cee9db5204..4562b2cb1087 100644
--- a/kernel/ptrace.c
+++ b/kernel/ptrace.c
@@ -30,6 +30,8 @@
 #include <linux/cn_proc.h>
 #include <linux/compat.h>
 
+#include <asm/syscall.h>	/* For syscall_get_* */
+
 /*
  * Access another process' address space via ptrace.
  * Source/target buffer must be kernel space,
@@ -878,7 +880,98 @@ static int ptrace_regset(struct task_struct *task, int req, unsigned int type,
  * to ensure no machine forgets it.
  */
 EXPORT_SYMBOL_GPL(task_user_regset_view);
-#endif
+#endif /* CONFIG_HAVE_ARCH_TRACEHOOK */
+
+static unsigned long
+ptrace_get_syscall_info_entry(struct task_struct *child, struct pt_regs *regs,
+			      struct ptrace_syscall_info *info)
+{
+	unsigned long args[ARRAY_SIZE(info->entry.args)];
+	int i;
+
+	info->op = PTRACE_SYSCALL_INFO_ENTRY;
+	info->entry.nr = syscall_get_nr(child, regs);
+	syscall_get_arguments(child, regs, 0, ARRAY_SIZE(args), args);
+	for (i = 0; i < ARRAY_SIZE(args); i++)
+		info->entry.args[i] = args[i];
+
+	return offsetofend(struct ptrace_syscall_info, entry);
+}
+
+static unsigned long
+ptrace_get_syscall_info_seccomp(struct task_struct *child, struct pt_regs *regs,
+				struct ptrace_syscall_info *info)
+{
+	/*
+	 * As struct ptrace_syscall_info.entry is currently a subset
+	 * of struct ptrace_syscall_info.seccomp, it makes sense to
+	 * initialize that subset using ptrace_get_syscall_info_entry().
+	 * This can be reconsidered in the future if these structures
+	 * diverge significantly enough.
+	 */
+	ptrace_get_syscall_info_entry(child, regs, info);
+	info->op = PTRACE_SYSCALL_INFO_SECCOMP;
+	info->seccomp.ret_data = child->ptrace_message;
+
+	return offsetofend(struct ptrace_syscall_info, seccomp);
+}
+
+static unsigned long
+ptrace_get_syscall_info_exit(struct task_struct *child, struct pt_regs *regs,
+			     struct ptrace_syscall_info *info)
+{
+	info->op = PTRACE_SYSCALL_INFO_EXIT;
+	info->exit.rval = syscall_get_error(child, regs);
+	info->exit.is_error = !!info->exit.rval;
+	if (!info->exit.is_error)
+		info->exit.rval = syscall_get_return_value(child, regs);
+
+	return offsetofend(struct ptrace_syscall_info, exit);
+}
+
+static int
+ptrace_get_syscall_info(struct task_struct *child, unsigned long user_size,
+			void __user *datavp)
+{
+	struct pt_regs *regs = task_pt_regs(child);
+	struct ptrace_syscall_info info = {
+		.op = PTRACE_SYSCALL_INFO_NONE,
+		.arch = syscall_get_arch(child),
+		.instruction_pointer = instruction_pointer(regs),
+		.stack_pointer = user_stack_pointer(regs),
+		.frame_pointer = frame_pointer(regs)
+	};
+	unsigned long actual_size = offsetof(struct ptrace_syscall_info, entry);
+	unsigned long write_size;
+
+	/*
+	 * This does not need lock_task_sighand() to access
+	 * child->last_siginfo because ptrace_freeze_traced()
+	 * called earlier by ptrace_check_attach() ensures that
+	 * the tracee cannot go away and clear its last_siginfo.
+	 */
+	switch (child->last_siginfo ? child->last_siginfo->si_code : 0) {
+	case SIGTRAP | 0x80:
+		switch (child->ptrace_message) {
+		case PTRACE_EVENTMSG_SYSCALL_ENTRY:
+			actual_size = ptrace_get_syscall_info_entry(child, regs,
+								    &info);
+			break;
+		case PTRACE_EVENTMSG_SYSCALL_EXIT:
+			actual_size = ptrace_get_syscall_info_exit(child, regs,
+								   &info);
+			break;
+		}
+		break;
+	case SIGTRAP | (PTRACE_EVENT_SECCOMP << 8):
+		actual_size = ptrace_get_syscall_info_seccomp(child, regs,
+							      &info);
+		break;
+	}
+
+	write_size = min(actual_size, user_size);
+	return copy_to_user(datavp, &info, write_size) ? -EFAULT : actual_size;
+}
 
 int ptrace_request(struct task_struct *child, long request,
 		   unsigned long addr, unsigned long data)
@@ -1095,6 +1188,10 @@ int ptrace_request(struct task_struct *child, long request,
 		ret = seccomp_get_metadata(child, addr, datavp);
 		break;
 
+	case PTRACE_GET_SYSCALL_INFO:
+		ret = ptrace_get_syscall_info(child, addr, datavp);
+		break;
+
 	default:
 		break;
 	}
-- 
ldv

^ permalink raw reply related	[flat|nested] 65+ messages in thread

* [PATCH v5 25/25] selftests/ptrace: add a test case for PTRACE_GET_SYSCALL_INFO
       [not found] <20181210042352.GA6092@altlinux.org>
                   ` (23 preceding siblings ...)
  2018-12-10  4:31 ` [PATCH v5 24/25] ptrace: add PTRACE_GET_SYSCALL_INFO request Dmitry V. Levin
@ 2018-12-10  4:31 ` Dmitry V. Levin
  24 siblings, 0 replies; 65+ messages in thread
From: Dmitry V. Levin @ 2018-12-10  4:31 UTC (permalink / raw)
  To: Oleg Nesterov, Andy Lutomirski, Shuah Khan
  Cc: Elvira Khabirova, Eugene Syromyatnikov, Michael Ellerman,
	linux-kselftest, linux-kernel

Check whether PTRACE_GET_SYSCALL_INFO semantics implemented in the kernel
matches userspace expectations.

Cc: Oleg Nesterov <oleg@redhat.com>
Cc: Andy Lutomirski <luto@kernel.org>
Cc: Shuah Khan <shuah@kernel.org>
Cc: Elvira Khabirova <lineprinter@altlinux.org>
Cc: Eugene Syromyatnikov <esyr@redhat.com>
Cc: linux-kselftest@vger.kernel.org
Signed-off-by: Dmitry V. Levin <ldv@altlinux.org>
---
 tools/testing/selftests/ptrace/.gitignore     |   1 +
 tools/testing/selftests/ptrace/Makefile       |   2 +-
 .../selftests/ptrace/get_syscall_info.c       | 272 ++++++++++++++++++
 3 files changed, 274 insertions(+), 1 deletion(-)
 create mode 100644 tools/testing/selftests/ptrace/get_syscall_info.c

diff --git a/tools/testing/selftests/ptrace/.gitignore b/tools/testing/selftests/ptrace/.gitignore
index b3e59d41fd82..cfcc49a7def7 100644
--- a/tools/testing/selftests/ptrace/.gitignore
+++ b/tools/testing/selftests/ptrace/.gitignore
@@ -1 +1,2 @@
+get_syscall_info
 peeksiginfo
diff --git a/tools/testing/selftests/ptrace/Makefile b/tools/testing/selftests/ptrace/Makefile
index 8a2bc5562179..4bc550b6b845 100644
--- a/tools/testing/selftests/ptrace/Makefile
+++ b/tools/testing/selftests/ptrace/Makefile
@@ -1,5 +1,5 @@
 CFLAGS += -iquote../../../../include/uapi -Wall
 
-TEST_GEN_PROGS := peeksiginfo
+TEST_GEN_PROGS := get_syscall_info peeksiginfo
 
 include ../lib.mk
diff --git a/tools/testing/selftests/ptrace/get_syscall_info.c b/tools/testing/selftests/ptrace/get_syscall_info.c
new file mode 100644
index 000000000000..21d1180d117e
--- /dev/null
+++ b/tools/testing/selftests/ptrace/get_syscall_info.c
@@ -0,0 +1,272 @@
+/*
+ * SPDX-License-Identifier: GPL-2.0-or-later
+ *
+ * Copyright (c) 2018 Dmitry V. Levin <ldv@altlinux.org>
+ * All rights reserved.
+ *
+ * Check whether PTRACE_GET_SYSCALL_INFO semantics implemented in the kernel
+ * matches userspace expectations.
+ */
+
+#include "../kselftest_harness.h"
+#include <err.h>
+#include <signal.h>
+#include <asm/unistd.h>
+#include "linux/ptrace.h"
+
+static int
+kill_tracee(pid_t pid)
+{
+	if (!pid)
+		return 0;
+
+	int saved_errno = errno;
+
+	int rc = kill(pid, SIGKILL);
+
+	errno = saved_errno;
+	return rc;
+}
+
+static long
+sys_ptrace(int request, pid_t pid, unsigned long addr, unsigned long data)
+{
+	return syscall(__NR_ptrace, request, pid, addr, data);
+}
+
+#define LOG_KILL_TRACEE(fmt, ...)				\
+	do {							\
+		kill_tracee(pid);				\
+		TH_LOG("wait #%d: " fmt,			\
+		       ptrace_stop, ##__VA_ARGS__);		\
+	} while (0)
+
+TEST(get_syscall_info)
+{
+	static const unsigned long args[][7] = {
+		/* a sequence of architecture-agnostic syscalls */
+		{
+			__NR_chdir,
+			(unsigned long) "",
+			0xbad1fed1,
+			0xbad2fed2,
+			0xbad3fed3,
+			0xbad4fed4,
+			0xbad5fed5
+		},
+		{
+			__NR_gettid,
+			0xcaf0bea0,
+			0xcaf1bea1,
+			0xcaf2bea2,
+			0xcaf3bea3,
+			0xcaf4bea4,
+			0xcaf5bea5
+		},
+		{
+			__NR_exit_group,
+			0,
+			0xfac1c0d1,
+			0xfac2c0d2,
+			0xfac3c0d3,
+			0xfac4c0d4,
+			0xfac5c0d5
+		}
+	};
+	const unsigned long *exp_args;
+
+	pid_t pid = fork();
+
+	ASSERT_LE(0, pid) {
+		TH_LOG("fork: %m");
+	}
+
+	if (pid == 0) {
+		/* get the pid before PTRACE_TRACEME */
+		pid = getpid();
+		ASSERT_EQ(0, sys_ptrace(PTRACE_TRACEME, 0, 0, 0)) {
+			TH_LOG("PTRACE_TRACEME: %m");
+		}
+		ASSERT_EQ(0, kill(pid, SIGSTOP)) {
+			/* cannot happen */
+			TH_LOG("kill SIGSTOP: %m");
+		}
+		for (unsigned int i = 0; i < ARRAY_SIZE(args); ++i) {
+			syscall(args[i][0],
+				args[i][1], args[i][2], args[i][3],
+				args[i][4], args[i][5], args[i][6]);
+		}
+		/* unreachable */
+		_exit(1);
+	}
+
+	const struct {
+		unsigned int is_error;
+		int rval;
+	} *exp_param, exit_param[] = {
+		{ 1, -ENOENT },	/* chdir */
+		{ 0, pid }	/* gettid */
+	};
+
+	unsigned int ptrace_stop;
+
+	for (ptrace_stop = 0; ; ++ptrace_stop) {
+		struct ptrace_syscall_info info = {
+			.op = 0xff	/* invalid PTRACE_SYSCALL_INFO_* op */
+		};
+		const size_t size = sizeof(info);
+		const int expected_none_size =
+			(void *) &info.entry - (void *) &info;
+		const int expected_entry_size =
+			(void *) &info.entry.args[6] - (void *) &info;
+		const int expected_exit_size =
+			(void *) (&info.exit.is_error + 1) -
+			(void *) &info;
+		int status;
+		long rc;
+
+		ASSERT_EQ(pid, wait(&status)) {
+			/* cannot happen */
+			LOG_KILL_TRACEE("wait: %m");
+		}
+		if (WIFEXITED(status)) {
+			pid = 0;	/* the tracee is no more */
+			ASSERT_EQ(0, WEXITSTATUS(status));
+			break;
+		}
+		ASSERT_FALSE(WIFSIGNALED(status)) {
+			pid = 0;	/* the tracee is no more */
+			LOG_KILL_TRACEE("unexpected signal %u",
+					WTERMSIG(status));
+		}
+		ASSERT_TRUE(WIFSTOPPED(status)) {
+			/* cannot happen */
+			LOG_KILL_TRACEE("unexpected wait status %#x", status);
+		}
+
+		switch (WSTOPSIG(status)) {
+		case SIGSTOP:
+			ASSERT_EQ(0, ptrace_stop) {
+				LOG_KILL_TRACEE("unexpected signal stop");
+			}
+			ASSERT_EQ(0, sys_ptrace(PTRACE_SETOPTIONS, pid, 0,
+						PTRACE_O_TRACESYSGOOD)) {
+				LOG_KILL_TRACEE("PTRACE_SETOPTIONS: %m");
+			}
+			ASSERT_LT(0, (rc = sys_ptrace(PTRACE_GET_SYSCALL_INFO,
+						      pid, size,
+						      (unsigned long) &info))) {
+				LOG_KILL_TRACEE("PTRACE_GET_SYSCALL_INFO: %m");
+			}
+			ASSERT_LE(expected_none_size, rc) {
+				LOG_KILL_TRACEE("signal stop mismatch");
+			}
+			ASSERT_EQ(PTRACE_SYSCALL_INFO_NONE, info.op) {
+				LOG_KILL_TRACEE("signal stop mismatch");
+			}
+			ASSERT_TRUE(info.arch) {
+				LOG_KILL_TRACEE("signal stop mismatch");
+			}
+			ASSERT_TRUE(info.instruction_pointer) {
+				LOG_KILL_TRACEE("signal stop mismatch");
+			}
+			ASSERT_TRUE(info.stack_pointer) {
+				LOG_KILL_TRACEE("signal stop mismatch");
+			}
+			break;
+
+		case SIGTRAP | 0x80:
+			ASSERT_LT(0, (rc = sys_ptrace(PTRACE_GET_SYSCALL_INFO,
+						      pid, size,
+						      (unsigned long) &info))) {
+				LOG_KILL_TRACEE("PTRACE_GET_SYSCALL_INFO: %m");
+			}
+			switch (ptrace_stop) {
+			case 1: /* entering chdir */
+			case 3: /* entering gettid */
+			case 5: /* entering exit_group */
+				exp_args = args[ptrace_stop / 2];
+				ASSERT_LE(expected_entry_size, rc) {
+					LOG_KILL_TRACEE("entry stop mismatch");
+				}
+				ASSERT_EQ(PTRACE_SYSCALL_INFO_ENTRY, info.op) {
+					LOG_KILL_TRACEE("entry stop mismatch");
+				}
+				ASSERT_TRUE(info.arch) {
+					LOG_KILL_TRACEE("entry stop mismatch");
+				}
+				ASSERT_TRUE(info.instruction_pointer) {
+					LOG_KILL_TRACEE("entry stop mismatch");
+				}
+				ASSERT_TRUE(info.stack_pointer) {
+					LOG_KILL_TRACEE("entry stop mismatch");
+				}
+				ASSERT_EQ(exp_args[0], info.entry.nr) {
+					LOG_KILL_TRACEE("entry stop mismatch");
+				}
+				ASSERT_EQ(exp_args[1], info.entry.args[0]) {
+					LOG_KILL_TRACEE("entry stop mismatch");
+				}
+				ASSERT_EQ(exp_args[2], info.entry.args[1]) {
+					LOG_KILL_TRACEE("entry stop mismatch");
+				}
+				ASSERT_EQ(exp_args[3], info.entry.args[2]) {
+					LOG_KILL_TRACEE("entry stop mismatch");
+				}
+				ASSERT_EQ(exp_args[4], info.entry.args[3]) {
+					LOG_KILL_TRACEE("entry stop mismatch");
+				}
+				ASSERT_EQ(exp_args[5], info.entry.args[4]) {
+					LOG_KILL_TRACEE("entry stop mismatch");
+				}
+				ASSERT_EQ(exp_args[6], info.entry.args[5]) {
+					LOG_KILL_TRACEE("entry stop mismatch");
+				}
+				break;
+			case 2: /* exiting chdir */
+			case 4: /* exiting gettid */
+				exp_param = &exit_param[ptrace_stop / 2 - 1];
+				ASSERT_LE(expected_exit_size, rc) {
+					LOG_KILL_TRACEE("exit stop mismatch");
+				}
+				ASSERT_EQ(PTRACE_SYSCALL_INFO_EXIT, info.op) {
+					LOG_KILL_TRACEE("exit stop mismatch");
+				}
+				ASSERT_TRUE(info.arch) {
+					LOG_KILL_TRACEE("exit stop mismatch");
+				}
+				ASSERT_TRUE(info.instruction_pointer) {
+					LOG_KILL_TRACEE("exit stop mismatch");
+				}
+				ASSERT_TRUE(info.stack_pointer) {
+					LOG_KILL_TRACEE("exit stop mismatch");
+				}
+				ASSERT_EQ(exp_param->is_error,
+					  info.exit.is_error) {
+					LOG_KILL_TRACEE("exit stop mismatch");
+				}
+				ASSERT_EQ(exp_param->rval, info.exit.rval) {
+					LOG_KILL_TRACEE("exit stop mismatch");
+				}
+				break;
+			default:
+				LOG_KILL_TRACEE("unexpected syscall stop");
+				abort();
+			}
+			break;
+
+		default:
+			LOG_KILL_TRACEE("unexpected stop signal %#x",
+					WSTOPSIG(status));
+			abort();
+		}
+
+		ASSERT_EQ(0, sys_ptrace(PTRACE_SYSCALL, pid, 0, 0)) {
+			LOG_KILL_TRACEE("PTRACE_SYSCALL: %m");
+		}
+	}
+
+	ASSERT_EQ(ARRAY_SIZE(args) * 2, ptrace_stop);
+}
+
+TEST_HARNESS_MAIN
-- 
ldv

^ permalink raw reply related	[flat|nested] 65+ messages in thread

* Re: [PATCH v5 19/25] xtensa: define syscall_get_* functions
  2018-12-10  4:30 ` [PATCH v5 19/25] xtensa: define syscall_get_* functions Dmitry V. Levin
@ 2018-12-10  5:02   ` Max Filippov
  2018-12-10 12:53     ` Dmitry V. Levin
  2018-12-12 10:45   ` kbuild test robot
  2018-12-19  5:58   ` kbuild test robot
  2 siblings, 1 reply; 65+ messages in thread
From: Max Filippov @ 2018-12-10  5:02 UTC (permalink / raw)
  To: ldv
  Cc: oleg, Andrew Lutomirski, lineprinter, esyr, Chris Zankel,
	Paul Moore, eparis, linux-xtensa, linux-audit, LKML

Hello,

On Sun, Dec 9, 2018 at 8:30 PM Dmitry V. Levin <ldv@altlinux.org> wrote:
> syscall_get_* functions are required to be implemented on all
> architectures in order to extend the generic ptrace API with
> PTRACE_GET_SYSCALL_INFO request.
>
> This adds all 5 syscall_get_* functions on xtensa as documented
> in asm-generic/syscall.h: syscall_get_nr, syscall_get_arguments,
> syscall_get_error, syscall_get_return_value, and syscall_get_arch.

I have this set of functions plus syscall_set_arguments implemented
for syscall tracing here:
  https://github.com/jcmvbkbc/linux-xtensa/commit/0023f56298cc92ce47e61b1b5dd1038f7be4f826

How should we synchronize our changes?

> diff --git a/arch/xtensa/include/asm/syscall.h b/arch/xtensa/include/asm/syscall.h
> index 3673ff1f1bc5..d529c855a144 100644
> --- a/arch/xtensa/include/asm/syscall.h
> +++ b/arch/xtensa/include/asm/syscall.h

[...]

> +static inline void
> +syscall_get_arguments(struct task_struct *task, struct pt_regs *regs,
> +                     unsigned int i, unsigned int n, unsigned long *args)
> +{
> +       switch (i) {
> +       case 0:
> +               if (!n--)
> +                       break;
> +               *args++ = regs->areg[6];
> +               /* fall through */
> +       case 1:
> +               if (!n--)
> +                       break;
> +               *args++ = regs->areg[3];
> +               /* fall through */
> +       case 2:
> +               if (!n--)
> +                       break;
> +               *args++ = regs->areg[4];
> +               /* fall through */
> +       case 3:
> +               if (!n--)
> +                       break;
> +               *args++ = regs->areg[5];
> +               /* fall through */
> +       case 4:
> +               if (!n--)
> +                       break;
> +               *args++ = regs->areg[8];
> +               /* fall through */
> +       case 5:
> +               if (!n--)
> +                       break;
> +               *args++ = regs->areg[9];
> +               /* fall through */
> +       case 6:
> +               if (!n--)
> +                       break;
> +               /* fall through */
> +       default:
> +               BUG();

A WARN should be enough.

-- 
Thanks.
-- Max

^ permalink raw reply	[flat|nested] 65+ messages in thread

* Re: [PATCH v5 13/25] m68k: add asm/syscall.h
  2018-12-10  4:30 ` [PATCH v5 13/25] m68k: add asm/syscall.h Dmitry V. Levin
@ 2018-12-10  8:45   ` Geert Uytterhoeven
  2018-12-10 12:40     ` Dmitry V. Levin
  0 siblings, 1 reply; 65+ messages in thread
From: Geert Uytterhoeven @ 2018-12-10  8:45 UTC (permalink / raw)
  To: Dmitry V. Levin
  Cc: Oleg Nesterov, Andy Lutomirski, lineprinter,
	Eugene Syromiatnikov, linux-m68k, Linux Kernel Mailing List

Hi Dmitry,

On Mon, Dec 10, 2018 at 5:30 AM Dmitry V. Levin <ldv@altlinux.org> wrote:
> syscall_get_* functions are required to be implemented on all
> architectures in order to extend the generic ptrace API with
> PTRACE_GET_SYSCALL_INFO request.
>
> This introduces asm/syscall.h on m68k implementing all 5 syscall_get_*
> functions as documented in asm-generic/syscall.h: syscall_get_nr,
> syscall_get_arguments, syscall_get_error, syscall_get_return_value,
> and syscall_get_arch.
>
> Cc: Geert Uytterhoeven <geert@linux-m68k.org>
> Cc: Oleg Nesterov <oleg@redhat.com>
> Cc: Andy Lutomirski <luto@kernel.org>
> Cc: Elvira Khabirova <lineprinter@altlinux.org>
> Cc: Eugene Syromyatnikov <esyr@redhat.com>
> Cc: linux-m68k@lists.linux-m68k.org
> Signed-off-by: Dmitry V. Levin <ldv@altlinux.org>
> ---
>
> Notes:
>     v5: added syscall_get_nr, syscall_get_arguments, syscall_get_error,
>         and syscall_get_return_value
>     v1: added syscall_get_arch

> --- /dev/null
> +++ b/arch/m68k/include/asm/syscall.h
> @@ -0,0 +1,39 @@

> +static inline void
> +syscall_get_arguments(struct task_struct *task, struct pt_regs *regs,
> +                     unsigned int i, unsigned int n, unsigned long *args)
> +{
> +       BUG_ON(i + n > 6);

Does this have to crash the kernel?
Perhaps you can return an error code instead?

> +       memcpy(args, &regs->d1 + i, n * sizeof(args[0]));
> +}

Gr{oetje,eeting}s,

                        Geert

-- 
Geert Uytterhoeven -- There's lots of Linux beyond ia32 -- geert@linux-m68k.org

In personal conversations with technical people, I call myself a hacker. But
when I'm talking to journalists I just say "programmer" or something like that.
                                -- Linus Torvalds

^ permalink raw reply	[flat|nested] 65+ messages in thread

* Re: [PATCH v5 13/25] m68k: add asm/syscall.h
  2018-12-10  8:45   ` Geert Uytterhoeven
@ 2018-12-10 12:40     ` Dmitry V. Levin
  2018-12-10 13:06       ` Geert Uytterhoeven
  0 siblings, 1 reply; 65+ messages in thread
From: Dmitry V. Levin @ 2018-12-10 12:40 UTC (permalink / raw)
  To: Geert Uytterhoeven
  Cc: Oleg Nesterov, Andy Lutomirski, lineprinter,
	Eugene Syromiatnikov, linux-m68k, Linux Kernel Mailing List

[-- Attachment #1: Type: text/plain, Size: 1803 bytes --]

Hi Geert,

On Mon, Dec 10, 2018 at 09:45:42AM +0100, Geert Uytterhoeven wrote:
> Hi Dmitry,
> 
> On Mon, Dec 10, 2018 at 5:30 AM Dmitry V. Levin <ldv@altlinux.org> wrote:
> > syscall_get_* functions are required to be implemented on all
> > architectures in order to extend the generic ptrace API with
> > PTRACE_GET_SYSCALL_INFO request.
> >
> > This introduces asm/syscall.h on m68k implementing all 5 syscall_get_*
> > functions as documented in asm-generic/syscall.h: syscall_get_nr,
> > syscall_get_arguments, syscall_get_error, syscall_get_return_value,
> > and syscall_get_arch.
> >
> > Cc: Geert Uytterhoeven <geert@linux-m68k.org>
> > Cc: Oleg Nesterov <oleg@redhat.com>
> > Cc: Andy Lutomirski <luto@kernel.org>
> > Cc: Elvira Khabirova <lineprinter@altlinux.org>
> > Cc: Eugene Syromyatnikov <esyr@redhat.com>
> > Cc: linux-m68k@lists.linux-m68k.org
> > Signed-off-by: Dmitry V. Levin <ldv@altlinux.org>
> > ---
> >
> > Notes:
> >     v5: added syscall_get_nr, syscall_get_arguments, syscall_get_error,
> >         and syscall_get_return_value
> >     v1: added syscall_get_arch
> 
> > --- /dev/null
> > +++ b/arch/m68k/include/asm/syscall.h
> > @@ -0,0 +1,39 @@
> 
> > +static inline void
> > +syscall_get_arguments(struct task_struct *task, struct pt_regs *regs,
> > +                     unsigned int i, unsigned int n, unsigned long *args)
> > +{
> > +       BUG_ON(i + n > 6);
> 
> Does this have to crash the kernel?

This is what most of other architectures do, but we could choose
a softer approach, e.g. use WARN_ON_ONCE instead.

> Perhaps you can return an error code instead?

That would be problematic given the signature of this function
and the nature of the potential bug which would most likely be a usage error.


-- 
ldv

[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 801 bytes --]

^ permalink raw reply	[flat|nested] 65+ messages in thread

* Re: [PATCH v5 19/25] xtensa: define syscall_get_* functions
  2018-12-10  5:02   ` Max Filippov
@ 2018-12-10 12:53     ` Dmitry V. Levin
  2018-12-10 20:14       ` Max Filippov
  0 siblings, 1 reply; 65+ messages in thread
From: Dmitry V. Levin @ 2018-12-10 12:53 UTC (permalink / raw)
  To: Max Filippov
  Cc: oleg, Andrew Lutomirski, lineprinter, esyr, Chris Zankel,
	Paul Moore, eparis, linux-xtensa, linux-audit, LKML

[-- Attachment #1: Type: text/plain, Size: 2908 bytes --]

Hi,

On Sun, Dec 09, 2018 at 09:02:50PM -0800, Max Filippov wrote:
> Hello,
> 
> On Sun, Dec 9, 2018 at 8:30 PM Dmitry V. Levin <ldv@altlinux.org> wrote:
> > syscall_get_* functions are required to be implemented on all
> > architectures in order to extend the generic ptrace API with
> > PTRACE_GET_SYSCALL_INFO request.
> >
> > This adds all 5 syscall_get_* functions on xtensa as documented
> > in asm-generic/syscall.h: syscall_get_nr, syscall_get_arguments,
> > syscall_get_error, syscall_get_return_value, and syscall_get_arch.
> 
> I have this set of functions plus syscall_set_arguments implemented
> for syscall tracing here:
>   https://github.com/jcmvbkbc/linux-xtensa/commit/0023f56298cc92ce47e61b1b5dd1038f7be4f826

Good, but we also need syscall_get_arch for PTRACE_GET_SYSCALL_INFO.

> How should we synchronize our changes?

No problem, I can revert to the previous edition of this patch
that just adds syscall_get_arch.
Alternatively, you can just take that couple of patches (v5 18/25
and v2 15/15) into your tree.

> > diff --git a/arch/xtensa/include/asm/syscall.h b/arch/xtensa/include/asm/syscall.h
> > index 3673ff1f1bc5..d529c855a144 100644
> > --- a/arch/xtensa/include/asm/syscall.h
> > +++ b/arch/xtensa/include/asm/syscall.h
> 
> [...]
> 
> > +static inline void
> > +syscall_get_arguments(struct task_struct *task, struct pt_regs *regs,
> > +                     unsigned int i, unsigned int n, unsigned long *args)
> > +{
> > +       switch (i) {
> > +       case 0:
> > +               if (!n--)
> > +                       break;
> > +               *args++ = regs->areg[6];
> > +               /* fall through */
> > +       case 1:
> > +               if (!n--)
> > +                       break;
> > +               *args++ = regs->areg[3];
> > +               /* fall through */
> > +       case 2:
> > +               if (!n--)
> > +                       break;
> > +               *args++ = regs->areg[4];
> > +               /* fall through */
> > +       case 3:
> > +               if (!n--)
> > +                       break;
> > +               *args++ = regs->areg[5];
> > +               /* fall through */
> > +       case 4:
> > +               if (!n--)
> > +                       break;
> > +               *args++ = regs->areg[8];
> > +               /* fall through */
> > +       case 5:
> > +               if (!n--)
> > +                       break;
> > +               *args++ = regs->areg[9];
> > +               /* fall through */
> > +       case 6:
> > +               if (!n--)
> > +                       break;
> > +               /* fall through */
> > +       default:
> > +               BUG();
> 
> A WARN should be enough.

This is what most of other architectures do in syscall_get_arguments,
but I agree that a WARN_ON_ONCE should be enough.


-- 
ldv

[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 801 bytes --]

^ permalink raw reply	[flat|nested] 65+ messages in thread

* Re: [PATCH v5 13/25] m68k: add asm/syscall.h
  2018-12-10 12:40     ` Dmitry V. Levin
@ 2018-12-10 13:06       ` Geert Uytterhoeven
  2018-12-10 13:30         ` Dmitry V. Levin
  0 siblings, 1 reply; 65+ messages in thread
From: Geert Uytterhoeven @ 2018-12-10 13:06 UTC (permalink / raw)
  To: Dmitry V. Levin
  Cc: Oleg Nesterov, Andy Lutomirski, lineprinter,
	Eugene Syromiatnikov, linux-m68k, Linux Kernel Mailing List

Hi Dmitry,

On Mon, Dec 10, 2018 at 1:41 PM Dmitry V. Levin <ldv@altlinux.org> wrote:
> On Mon, Dec 10, 2018 at 09:45:42AM +0100, Geert Uytterhoeven wrote:
> > On Mon, Dec 10, 2018 at 5:30 AM Dmitry V. Levin <ldv@altlinux.org> wrote:
> > > syscall_get_* functions are required to be implemented on all
> > > architectures in order to extend the generic ptrace API with
> > > PTRACE_GET_SYSCALL_INFO request.
> > >
> > > This introduces asm/syscall.h on m68k implementing all 5 syscall_get_*
> > > functions as documented in asm-generic/syscall.h: syscall_get_nr,
> > > syscall_get_arguments, syscall_get_error, syscall_get_return_value,
> > > and syscall_get_arch.
> > >
> > > Cc: Geert Uytterhoeven <geert@linux-m68k.org>
> > > Cc: Oleg Nesterov <oleg@redhat.com>
> > > Cc: Andy Lutomirski <luto@kernel.org>
> > > Cc: Elvira Khabirova <lineprinter@altlinux.org>
> > > Cc: Eugene Syromyatnikov <esyr@redhat.com>
> > > Cc: linux-m68k@lists.linux-m68k.org
> > > Signed-off-by: Dmitry V. Levin <ldv@altlinux.org>
> > > ---
> > >
> > > Notes:
> > >     v5: added syscall_get_nr, syscall_get_arguments, syscall_get_error,
> > >         and syscall_get_return_value
> > >     v1: added syscall_get_arch
> >
> > > --- /dev/null
> > > +++ b/arch/m68k/include/asm/syscall.h
> > > @@ -0,0 +1,39 @@
> >
> > > +static inline void
> > > +syscall_get_arguments(struct task_struct *task, struct pt_regs *regs,
> > > +                     unsigned int i, unsigned int n, unsigned long *args)
> > > +{
> > > +       BUG_ON(i + n > 6);
> >
> > Does this have to crash the kernel?
>
> This is what most of other architectures do, but we could choose
> a softer approach, e.g. use WARN_ON_ONCE instead.
>
> > Perhaps you can return an error code instead?
>
> That would be problematic given the signature of this function
> and the nature of the potential bug which would most likely be a usage error.

Of course to handle that, the function's signature need to be changed.
Changing it has the advantage that the error handling can be done at the
caller, in common code, instead of duplicating it for all
architectures, possibly
leading to different semantics.

Gr{oetje,eeting}s,

                        Geert

-- 
Geert Uytterhoeven -- There's lots of Linux beyond ia32 -- geert@linux-m68k.org

In personal conversations with technical people, I call myself a hacker. But
when I'm talking to journalists I just say "programmer" or something like that.
                                -- Linus Torvalds

^ permalink raw reply	[flat|nested] 65+ messages in thread

* Re: [PATCH v5 13/25] m68k: add asm/syscall.h
  2018-12-10 13:06       ` Geert Uytterhoeven
@ 2018-12-10 13:30         ` Dmitry V. Levin
  2018-12-12  8:55           ` Dmitry V. Levin
  0 siblings, 1 reply; 65+ messages in thread
From: Dmitry V. Levin @ 2018-12-10 13:30 UTC (permalink / raw)
  To: Geert Uytterhoeven
  Cc: Oleg Nesterov, Andy Lutomirski, lineprinter,
	Eugene Syromiatnikov, linux-m68k, Linux Kernel Mailing List

[-- Attachment #1: Type: text/plain, Size: 2796 bytes --]

Hi Geert,

On Mon, Dec 10, 2018 at 02:06:28PM +0100, Geert Uytterhoeven wrote:
> On Mon, Dec 10, 2018 at 1:41 PM Dmitry V. Levin <ldv@altlinux.org> wrote:
> > On Mon, Dec 10, 2018 at 09:45:42AM +0100, Geert Uytterhoeven wrote:
> > > On Mon, Dec 10, 2018 at 5:30 AM Dmitry V. Levin <ldv@altlinux.org> wrote:
> > > > syscall_get_* functions are required to be implemented on all
> > > > architectures in order to extend the generic ptrace API with
> > > > PTRACE_GET_SYSCALL_INFO request.
> > > >
> > > > This introduces asm/syscall.h on m68k implementing all 5 syscall_get_*
> > > > functions as documented in asm-generic/syscall.h: syscall_get_nr,
> > > > syscall_get_arguments, syscall_get_error, syscall_get_return_value,
> > > > and syscall_get_arch.
> > > >
> > > > Cc: Geert Uytterhoeven <geert@linux-m68k.org>
> > > > Cc: Oleg Nesterov <oleg@redhat.com>
> > > > Cc: Andy Lutomirski <luto@kernel.org>
> > > > Cc: Elvira Khabirova <lineprinter@altlinux.org>
> > > > Cc: Eugene Syromyatnikov <esyr@redhat.com>
> > > > Cc: linux-m68k@lists.linux-m68k.org
> > > > Signed-off-by: Dmitry V. Levin <ldv@altlinux.org>
> > > > ---
> > > >
> > > > Notes:
> > > >     v5: added syscall_get_nr, syscall_get_arguments, syscall_get_error,
> > > >         and syscall_get_return_value
> > > >     v1: added syscall_get_arch
> > >
> > > > --- /dev/null
> > > > +++ b/arch/m68k/include/asm/syscall.h
> > > > @@ -0,0 +1,39 @@
> > >
> > > > +static inline void
> > > > +syscall_get_arguments(struct task_struct *task, struct pt_regs *regs,
> > > > +                     unsigned int i, unsigned int n, unsigned long *args)
> > > > +{
> > > > +       BUG_ON(i + n > 6);
> > >
> > > Does this have to crash the kernel?
> >
> > This is what most of other architectures do, but we could choose
> > a softer approach, e.g. use WARN_ON_ONCE instead.
> >
> > > Perhaps you can return an error code instead?
> >
> > That would be problematic given the signature of this function
> > and the nature of the potential bug which would most likely be a usage error.
> 
> Of course to handle that, the function's signature need to be changed.
> Changing it has the advantage that the error handling can be done at the
> caller, in common code, instead of duplicating it for all
> architectures, possibly
> leading to different semantics.

Given that *all* current users of syscall_get_arguments specify i == 0
(and there is an architecture that has BUG_ON(i)), 
it should be really a usage error to get into situation where i + n > 6,
I wish a BUILD_BUG_ON could be used here instead.

I don't think it worths pushing the change of API just to convert
a "cannot happen" assertion into an error that would have to be dealt with
on the caller side.


-- 
ldv

[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 801 bytes --]

^ permalink raw reply	[flat|nested] 65+ messages in thread

* Re: [PATCH v5 24/25] ptrace: add PTRACE_GET_SYSCALL_INFO request
  2018-12-10  4:31 ` [PATCH v5 24/25] ptrace: add PTRACE_GET_SYSCALL_INFO request Dmitry V. Levin
@ 2018-12-10 14:11   ` Oleg Nesterov
  2018-12-10 16:21     ` Dmitry V. Levin
  2018-12-10 14:26   ` kbuild test robot
                     ` (2 subsequent siblings)
  3 siblings, 1 reply; 65+ messages in thread
From: Oleg Nesterov @ 2018-12-10 14:11 UTC (permalink / raw)
  To: Dmitry V. Levin
  Cc: Andy Lutomirski, Elvira Khabirova, Eugene Syromyatnikov,
	Kees Cook, Jann Horn, linux-api, strace-devel, linux-kernel

On 12/10, Dmitry V. Levin wrote:
>
> +struct ptrace_syscall_info {
> +	__u8 op;	/* PTRACE_SYSCALL_INFO_* */
> +	__u8 __pad0[3];
> +	__u32 arch;
> +	__u64 instruction_pointer;
> +	__u64 stack_pointer;
> +	__u64 frame_pointer;
> +	union {
> +		struct {
> +			__u64 nr;
> +			__u64 args[6];
> +		} entry;
> +		struct {
> +			__s64 rval;
> +			__u8 is_error;
> +			__u8 __pad1[7];
> +		} exit;
> +		struct {
> +			__u64 nr;
> +			__u64 args[6];
> +			__u32 ret_data;
> +			__u8 __pad2[4];
> +		} seccomp;
> +	};
> +};

Could you explain why ptrace_syscall_info needs __pad{0,1,2} ? I simply can't
understand why...

Otherwise the patch looks good to me. I am not going to discuss the API and
data layout, I am fine with anything which suits user-space needs.

I think the patch is technically correct, feel free to add

Reviewed-by: Oleg Nesterov <oleg@redhat.com>


^ permalink raw reply	[flat|nested] 65+ messages in thread

* Re: [PATCH v5 24/25] ptrace: add PTRACE_GET_SYSCALL_INFO request
  2018-12-10  4:31 ` [PATCH v5 24/25] ptrace: add PTRACE_GET_SYSCALL_INFO request Dmitry V. Levin
  2018-12-10 14:11   ` Oleg Nesterov
@ 2018-12-10 14:26   ` kbuild test robot
  2018-12-10 16:09     ` Dmitry V. Levin
  2018-12-10 17:44   ` Kees Cook
  2018-12-12  9:28   ` kbuild test robot
  3 siblings, 1 reply; 65+ messages in thread
From: kbuild test robot @ 2018-12-10 14:26 UTC (permalink / raw)
  To: Dmitry V. Levin
  Cc: kbuild-all, Oleg Nesterov, Andy Lutomirski, Elvira Khabirova,
	Eugene Syromyatnikov, Kees Cook, Jann Horn, linux-api,
	strace-devel, linux-kernel

[-- Attachment #1: Type: text/plain, Size: 3066 bytes --]

Hi Elvira,

Thank you for the patch! Yet something to improve:

[auto build test ERROR on linus/master]
[also build test ERROR on v4.20-rc6]
[cannot apply to next-20181207]
[if your patch is applied to the wrong git tree, please drop us a note to help improve the system]

url:    https://github.com/0day-ci/linux/commits/Dmitry-V-Levin/ptrace-add-PTRACE_GET_SYSCALL_INFO-request/20181210-174745
config: mips-malta_kvm_defconfig (attached as .config)
compiler: mipsel-linux-gnu-gcc (Debian 7.2.0-11) 7.2.0
reproduce:
        wget https://raw.githubusercontent.com/intel/lkp-tests/master/sbin/make.cross -O ~/bin/make.cross
        chmod +x ~/bin/make.cross
        # save the attached .config to linux build tree
        GCC_VERSION=7.2.0 make.cross ARCH=mips 

All errors (new ones prefixed by >>):

   kernel/ptrace.c: In function 'ptrace_get_syscall_info':
>> kernel/ptrace.c:942:20: error: implicit declaration of function 'frame_pointer'; did you mean 'trace_printk'? [-Werror=implicit-function-declaration]
      .frame_pointer = frame_pointer(regs)
                       ^~~~~~~~~~~~~
                       trace_printk
   cc1: some warnings being treated as errors

vim +942 kernel/ptrace.c

   931	
   932	static int
   933	ptrace_get_syscall_info(struct task_struct *child, unsigned long user_size,
   934				void __user *datavp)
   935	{
   936		struct pt_regs *regs = task_pt_regs(child);
   937		struct ptrace_syscall_info info = {
   938			.op = PTRACE_SYSCALL_INFO_NONE,
   939			.arch = syscall_get_arch(child),
   940			.instruction_pointer = instruction_pointer(regs),
   941			.stack_pointer = user_stack_pointer(regs),
 > 942			.frame_pointer = frame_pointer(regs)
   943		};
   944		unsigned long actual_size = offsetof(struct ptrace_syscall_info, entry);
   945		unsigned long write_size;
   946	
   947		/*
   948		 * This does not need lock_task_sighand() to access
   949		 * child->last_siginfo because ptrace_freeze_traced()
   950		 * called earlier by ptrace_check_attach() ensures that
   951		 * the tracee cannot go away and clear its last_siginfo.
   952		 */
   953		switch (child->last_siginfo ? child->last_siginfo->si_code : 0) {
   954		case SIGTRAP | 0x80:
   955			switch (child->ptrace_message) {
   956			case PTRACE_EVENTMSG_SYSCALL_ENTRY:
   957				actual_size = ptrace_get_syscall_info_entry(child, regs,
   958									    &info);
   959				break;
   960			case PTRACE_EVENTMSG_SYSCALL_EXIT:
   961				actual_size = ptrace_get_syscall_info_exit(child, regs,
   962									   &info);
   963				break;
   964			}
   965			break;
   966		case SIGTRAP | (PTRACE_EVENT_SECCOMP << 8):
   967			actual_size = ptrace_get_syscall_info_seccomp(child, regs,
   968								      &info);
   969			break;
   970		}
   971	
   972		write_size = min(actual_size, user_size);
   973		return copy_to_user(datavp, &info, write_size) ? -EFAULT : actual_size;
   974	}
   975	

---
0-DAY kernel test infrastructure                Open Source Technology Center
https://lists.01.org/pipermail/kbuild-all                   Intel Corporation

[-- Attachment #2: .config.gz --]
[-- Type: application/gzip, Size: 19472 bytes --]

^ permalink raw reply	[flat|nested] 65+ messages in thread

* Re: [PATCH v5 24/25] ptrace: add PTRACE_GET_SYSCALL_INFO request
  2018-12-10 14:26   ` kbuild test robot
@ 2018-12-10 16:09     ` Dmitry V. Levin
  2018-12-10 18:04       ` Paul Burton
  2018-12-10 19:38       ` Andy Lutomirski
  0 siblings, 2 replies; 65+ messages in thread
From: Dmitry V. Levin @ 2018-12-10 16:09 UTC (permalink / raw)
  To: Paul Burton, Ralf Baechle, James Hogan, Oleg Nesterov, Andy Lutomirski
  Cc: Elvira Khabirova, Eugene Syromyatnikov, Kees Cook, Jann Horn,
	linux-api, strace-devel, linux-kernel

[-- Attachment #1: Type: text/plain, Size: 4038 bytes --]

Hi, things are getting too complicated and we need some advice how to deal
with this frame_pointer issue.

On Mon, Dec 10, 2018 at 10:26:50PM +0800, kbuild test robot wrote:
> Hi Elvira,
> 
> Thank you for the patch! Yet something to improve:
> 
> [auto build test ERROR on linus/master]
> [also build test ERROR on v4.20-rc6]
> [cannot apply to next-20181207]
> [if your patch is applied to the wrong git tree, please drop us a note to help improve the system]
> 
> url:    https://github.com/0day-ci/linux/commits/Dmitry-V-Levin/ptrace-add-PTRACE_GET_SYSCALL_INFO-request/20181210-174745
> config: mips-malta_kvm_defconfig (attached as .config)
> compiler: mipsel-linux-gnu-gcc (Debian 7.2.0-11) 7.2.0
> reproduce:
>         wget https://raw.githubusercontent.com/intel/lkp-tests/master/sbin/make.cross -O ~/bin/make.cross
>         chmod +x ~/bin/make.cross
>         # save the attached .config to linux build tree
>         GCC_VERSION=7.2.0 make.cross ARCH=mips 
> 
> All errors (new ones prefixed by >>):
> 
>    kernel/ptrace.c: In function 'ptrace_get_syscall_info':
> >> kernel/ptrace.c:942:20: error: implicit declaration of function 'frame_pointer'; did you mean 'trace_printk'? [-Werror=implicit-function-declaration]
>       .frame_pointer = frame_pointer(regs)
>                        ^~~~~~~~~~~~~
>                        trace_printk
>    cc1: some warnings being treated as errors
> 
> vim +942 kernel/ptrace.c
> 
>    931	
>    932	static int
>    933	ptrace_get_syscall_info(struct task_struct *child, unsigned long user_size,
>    934				void __user *datavp)
>    935	{
>    936		struct pt_regs *regs = task_pt_regs(child);
>    937		struct ptrace_syscall_info info = {
>    938			.op = PTRACE_SYSCALL_INFO_NONE,
>    939			.arch = syscall_get_arch(child),
>    940			.instruction_pointer = instruction_pointer(regs),
>    941			.stack_pointer = user_stack_pointer(regs),
>  > 942			.frame_pointer = frame_pointer(regs)
>    943		};
>    944		unsigned long actual_size = offsetof(struct ptrace_syscall_info, entry);
>    945		unsigned long write_size;
>    946	
>    947		/*
>    948		 * This does not need lock_task_sighand() to access
>    949		 * child->last_siginfo because ptrace_freeze_traced()
>    950		 * called earlier by ptrace_check_attach() ensures that
>    951		 * the tracee cannot go away and clear its last_siginfo.
>    952		 */
>    953		switch (child->last_siginfo ? child->last_siginfo->si_code : 0) {
>    954		case SIGTRAP | 0x80:
>    955			switch (child->ptrace_message) {
>    956			case PTRACE_EVENTMSG_SYSCALL_ENTRY:
>    957				actual_size = ptrace_get_syscall_info_entry(child, regs,
>    958									    &info);
>    959				break;
>    960			case PTRACE_EVENTMSG_SYSCALL_EXIT:
>    961				actual_size = ptrace_get_syscall_info_exit(child, regs,
>    962									   &info);
>    963				break;
>    964			}
>    965			break;
>    966		case SIGTRAP | (PTRACE_EVENT_SECCOMP << 8):
>    967			actual_size = ptrace_get_syscall_info_seccomp(child, regs,
>    968								      &info);
>    969			break;
>    970		}
>    971	
>    972		write_size = min(actual_size, user_size);
>    973		return copy_to_user(datavp, &info, write_size) ? -EFAULT : actual_size;
>    974	}
>    975	

We decided to add .frame_pointer to struct ptrace_syscall_info just for
consistency with .instruction_pointer and .stack_pointer; I must have been
misled by comments in asm-generic/ptrace.h into thinking that
frame_pointer() is universally available across architectures.

Unlike .instruction_pointer and .stack_pointer that are actually needed
in strace, .frame_pointer is not used, so from strace PoV we don't really
need it.

So the question is, does anybody need a
struct ptrace_syscall_info.frame_pointer?

If yes, how can frame_pointer() be defined on MIPS?
Or should we just forget about making sense of frame_pointer() and remove
struct ptrace_syscall_info.frame_pointer from the proposed API?


-- 
ldv

[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 801 bytes --]

^ permalink raw reply	[flat|nested] 65+ messages in thread

* Re: [PATCH v5 24/25] ptrace: add PTRACE_GET_SYSCALL_INFO request
  2018-12-10 14:11   ` Oleg Nesterov
@ 2018-12-10 16:21     ` Dmitry V. Levin
  2018-12-11 15:29       ` Oleg Nesterov
  0 siblings, 1 reply; 65+ messages in thread
From: Dmitry V. Levin @ 2018-12-10 16:21 UTC (permalink / raw)
  To: Oleg Nesterov
  Cc: Andy Lutomirski, Elvira Khabirova, Eugene Syromyatnikov,
	Kees Cook, Jann Horn, linux-api, strace-devel, linux-kernel

[-- Attachment #1: Type: text/plain, Size: 1079 bytes --]

On Mon, Dec 10, 2018 at 03:11:07PM +0100, Oleg Nesterov wrote:
> On 12/10, Dmitry V. Levin wrote:
> >
> > +struct ptrace_syscall_info {
> > +	__u8 op;	/* PTRACE_SYSCALL_INFO_* */
> > +	__u8 __pad0[3];
> > +	__u32 arch;
> > +	__u64 instruction_pointer;
> > +	__u64 stack_pointer;
> > +	__u64 frame_pointer;
> > +	union {
> > +		struct {
> > +			__u64 nr;
> > +			__u64 args[6];
> > +		} entry;
> > +		struct {
> > +			__s64 rval;
> > +			__u8 is_error;
> > +			__u8 __pad1[7];
> > +		} exit;
> > +		struct {
> > +			__u64 nr;
> > +			__u64 args[6];
> > +			__u32 ret_data;
> > +			__u8 __pad2[4];
> > +		} seccomp;
> > +	};
> > +};
> 
> Could you explain why ptrace_syscall_info needs __pad{0,1,2} ? I simply can't
> understand why...

I suppose the idea behind the use of these pads was to make the structure
arch-independent.

I don't think we really need to keep it exactly the same on all
architectures - the only practical requirement is to avoid any compat
issues, but I don't mind keeping the structure arch-independent.


-- 
ldv

[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 801 bytes --]

^ permalink raw reply	[flat|nested] 65+ messages in thread

* Re: [PATCH v5 22/25] syscall_get_arch: add "struct task_struct *" argument
  2018-12-10  4:31 ` [PATCH v5 22/25] syscall_get_arch: add "struct task_struct *" argument Dmitry V. Levin
@ 2018-12-10 17:29   ` Kees Cook
  2018-12-11 22:44   ` Mark Salter
  1 sibling, 0 replies; 65+ messages in thread
From: Kees Cook @ 2018-12-10 17:29 UTC (permalink / raw)
  To: Dmitry V. Levin
  Cc: Andy Lutomirski, Palmer Dabbelt, Paul Burton, Michael Ellerman, LKML

On Sun, Dec 9, 2018 at 8:31 PM Dmitry V. Levin <ldv@altlinux.org> 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 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 <luto@kernel.org> # for x86
> Reviewed-by: Palmer Dabbelt <palmer@sifive.com>
> Acked-by: Paul Burton <paul.burton@mips.com> # MIPS parts
> Acked-by: Michael Ellerman <mpe@ellerman.id.au> (powerpc)

For the seccomp parts:

Acked-by: Kees Cook <keescook@chromium.org>

-Kees

> diff --git a/kernel/seccomp.c b/kernel/seccomp.c
> index f2ae2324c232..77cb87bd2eae 100644
> --- a/kernel/seccomp.c
> +++ b/kernel/seccomp.c
> @@ -82,7 +82,7 @@ static void populate_seccomp_data(struct seccomp_data *sd)
>         unsigned long args[6];
>
>         sd->nr = syscall_get_nr(task, regs);
> -       sd->arch = syscall_get_arch();
> +       sd->arch = syscall_get_arch(task);
>         syscall_get_arguments(task, regs, 0, 6, args);
>         sd->args[0] = args[0];
>         sd->args[1] = args[1];
> @@ -529,7 +529,7 @@ static void seccomp_init_siginfo(kernel_siginfo_t *info, int syscall, int reason
>         info->si_code = SYS_SECCOMP;
>         info->si_call_addr = (void __user *)KSTK_EIP(current);
>         info->si_errno = reason;
> -       info->si_arch = syscall_get_arch();
> +       info->si_arch = syscall_get_arch(current);
>         info->si_syscall = syscall;
>  }
>
> --
> ldv



-- 
Kees Cook

^ permalink raw reply	[flat|nested] 65+ messages in thread

* Re: [PATCH v5 24/25] ptrace: add PTRACE_GET_SYSCALL_INFO request
  2018-12-10  4:31 ` [PATCH v5 24/25] ptrace: add PTRACE_GET_SYSCALL_INFO request Dmitry V. Levin
  2018-12-10 14:11   ` Oleg Nesterov
  2018-12-10 14:26   ` kbuild test robot
@ 2018-12-10 17:44   ` Kees Cook
  2018-12-12  9:28   ` kbuild test robot
  3 siblings, 0 replies; 65+ messages in thread
From: Kees Cook @ 2018-12-10 17:44 UTC (permalink / raw)
  To: Dmitry V. Levin
  Cc: Oleg Nesterov, Andy Lutomirski, Elvira Khabirova,
	Eugene Syromiatnikov, Jann Horn, Linux API, strace-devel, LKML

On Sun, Dec 9, 2018 at 8:31 PM Dmitry V. Levin <ldv@altlinux.org> wrote:
>
> From: Elvira Khabirova <lineprinter@altlinux.org>
>
> PTRACE_GET_SYSCALL_INFO is a generic ptrace API that lets ptracer obtain
> details of the syscall the tracee is blocked in.
>
> There are two reasons for a special syscall-related ptrace request.
>
> Firstly, with the current ptrace API there are cases when ptracer cannot
> retrieve necessary information about syscalls.  Some examples include:
> * The notorious int-0x80-from-64-bit-task issue.  See [1] for details.
> In short, if a 64-bit task performs a syscall through int 0x80, its tracer
> has no reliable means to find out that the syscall was, in fact,
> a compat syscall, and misidentifies it.
> * Syscall-enter-stop and syscall-exit-stop look the same for the tracer.
> Common practice is to keep track of the sequence of ptrace-stops in order
> not to mix the two syscall-stops up.  But it is not as simple as it looks;
> for example, strace had a (just recently fixed) long-standing bug where
> attaching strace to a tracee that is performing the execve system call
> led to the tracer identifying the following syscall-exit-stop as
> syscall-enter-stop, which messed up all the state tracking.
> * Since the introduction of commit 84d77d3f06e7e8dea057d10e8ec77ad71f721be3
> ("ptrace: Don't allow accessing an undumpable mm"), both PTRACE_PEEKDATA
> and process_vm_readv become unavailable when the process dumpable flag
> is cleared.  On such architectures as ia64 this results in all syscall
> arguments being unavailable for the tracer.
>
> Secondly, ptracers also have to support a lot of arch-specific code for
> obtaining information about the tracee.  For some architectures, this
> requires a ptrace(PTRACE_PEEKUSER, ...) invocation for every syscall
> argument and return value.
>
> ptrace(2) man page:
>
> long ptrace(enum __ptrace_request request, pid_t pid,
>             void *addr, void *data);
> ...
> PTRACE_GET_SYSCALL_INFO
>        Retrieve information about the syscall that caused the stop.
>        The information is placed into the buffer pointed by "data"
>        argument, which should be a pointer to a buffer of type
>        "struct ptrace_syscall_info".
>        The "addr" argument contains the size of the buffer pointed to
>        by "data" argument (i.e., sizeof(struct ptrace_syscall_info)).
>        The return value contains the number of bytes available
>        to be written by the kernel.
>        If the size of data to be written by the kernel exceeds the size
>        specified by "addr" argument, the output is truncated.
>
> Co-authored-by: Dmitry V. Levin <ldv@altlinux.org>
> Cc: Oleg Nesterov <oleg@redhat.com>
> Cc: Andy Lutomirski <luto@kernel.org>
> Cc: Eugene Syromyatnikov <esyr@redhat.com>
> Cc: Kees Cook <keescook@chromium.org>
> Cc: Jann Horn <jannh@google.com>
> Cc: linux-api@vger.kernel.org
> Cc: strace-devel@lists.strace.io
> Signed-off-by: Elvira Khabirova <lineprinter@altlinux.org>
> Signed-off-by: Dmitry V. Levin <ldv@altlinux.org>

Reviewed-by: Kees Cook <keescook@chromium.org>

-Kees

> ---
>
> Notes:
>     v5:
>     * Change PTRACE_EVENTMSG_SYSCALL_{ENTRY,EXIT} values as requested by Oleg.
>     * Change struct ptrace_syscall_info: generalize instruction_pointer,
>       stack_pointer, and frame_pointer fields by moving them from
>       ptrace_syscall_info.{entry,seccomp} substructures to ptrace_syscall_info
>       and initializing them for all stops.
>     * Add PTRACE_SYSCALL_INFO_NONE, set it when not in a syscall stop,
>       so e.g. "strace -i" could use PTRACE_SYSCALL_INFO_SECCOMP to obtain
>       instruction_pointer when the tracee is in a signal stop.
>     * Make available for all architectures: do not conditionalize on
>       CONFIG_HAVE_ARCH_TRACEHOOK since all syscall_get_* functions
>       are implemented on all architectures.
>
>     v4:
>     * Do not introduce task_struct.ptrace_event,
>       use child->last_siginfo->si_code instead.
>     * Implement PTRACE_SYSCALL_INFO_SECCOMP and ptrace_syscall_info.seccomp
>       support along with PTRACE_SYSCALL_INFO_{ENTRY,EXIT} and
>       ptrace_syscall_info.{entry,exit}.
>
>     v3:
>     * Change struct ptrace_syscall_info.
>     * Support PTRACE_EVENT_SECCOMP by adding ptrace_event to task_struct.
>     * Add proper defines for ptrace_syscall_info.op values.
>     * Rename PT_SYSCALL_IS_ENTERING and PT_SYSCALL_IS_EXITING to
>       PTRACE_EVENTMSG_SYSCALL_ENTRY and PTRACE_EVENTMSG_SYSCALL_EXIT
>     * and move them to uapi.
>
>     v2:
>     * Do not use task->ptrace.
>     * Replace entry_info.is_compat with entry_info.arch, use syscall_get_arch().
>     * Use addr argument of sys_ptrace to get expected size of the struct;
>       return full size of the struct.
>
>  include/linux/tracehook.h   |  9 ++--
>  include/uapi/linux/ptrace.h | 39 +++++++++++++++
>  kernel/ptrace.c             | 99 ++++++++++++++++++++++++++++++++++++-
>  3 files changed, 143 insertions(+), 4 deletions(-)
>
> diff --git a/include/linux/tracehook.h b/include/linux/tracehook.h
> index df20f8bdbfa3..6bc7a3d58e2f 100644
> --- a/include/linux/tracehook.h
> +++ b/include/linux/tracehook.h
> @@ -57,13 +57,15 @@ struct linux_binprm;
>  /*
>   * ptrace report for syscall entry and exit looks identical.
>   */
> -static inline int ptrace_report_syscall(struct pt_regs *regs)
> +static inline int ptrace_report_syscall(struct pt_regs *regs,
> +                                       unsigned long message)
>  {
>         int ptrace = current->ptrace;
>
>         if (!(ptrace & PT_PTRACED))
>                 return 0;
>
> +       current->ptrace_message = message;
>         ptrace_notify(SIGTRAP | ((ptrace & PT_TRACESYSGOOD) ? 0x80 : 0));
>
>         /*
> @@ -76,6 +78,7 @@ static inline int ptrace_report_syscall(struct pt_regs *regs)
>                 current->exit_code = 0;
>         }
>
> +       current->ptrace_message = 0;
>         return fatal_signal_pending(current);
>  }
>
> @@ -101,7 +104,7 @@ static inline int ptrace_report_syscall(struct pt_regs *regs)
>  static inline __must_check int tracehook_report_syscall_entry(
>         struct pt_regs *regs)
>  {
> -       return ptrace_report_syscall(regs);
> +       return ptrace_report_syscall(regs, PTRACE_EVENTMSG_SYSCALL_ENTRY);
>  }
>
>  /**
> @@ -126,7 +129,7 @@ static inline void tracehook_report_syscall_exit(struct pt_regs *regs, int step)
>         if (step)
>                 user_single_step_report(regs);
>         else
> -               ptrace_report_syscall(regs);
> +               ptrace_report_syscall(regs, PTRACE_EVENTMSG_SYSCALL_EXIT);
>  }
>
>  /**
> diff --git a/include/uapi/linux/ptrace.h b/include/uapi/linux/ptrace.h
> index d5a1b8a492b9..f0af09fe4e17 100644
> --- a/include/uapi/linux/ptrace.h
> +++ b/include/uapi/linux/ptrace.h
> @@ -73,6 +73,45 @@ struct seccomp_metadata {
>         __u64 flags;            /* Output: filter's flags */
>  };
>
> +#define PTRACE_GET_SYSCALL_INFO                0x420e
> +#define PTRACE_SYSCALL_INFO_NONE       0
> +#define PTRACE_SYSCALL_INFO_ENTRY      1
> +#define PTRACE_SYSCALL_INFO_EXIT       2
> +#define PTRACE_SYSCALL_INFO_SECCOMP    3
> +
> +struct ptrace_syscall_info {
> +       __u8 op;        /* PTRACE_SYSCALL_INFO_* */
> +       __u8 __pad0[3];
> +       __u32 arch;
> +       __u64 instruction_pointer;
> +       __u64 stack_pointer;
> +       __u64 frame_pointer;
> +       union {
> +               struct {
> +                       __u64 nr;
> +                       __u64 args[6];
> +               } entry;
> +               struct {
> +                       __s64 rval;
> +                       __u8 is_error;
> +                       __u8 __pad1[7];
> +               } exit;
> +               struct {
> +                       __u64 nr;
> +                       __u64 args[6];
> +                       __u32 ret_data;
> +                       __u8 __pad2[4];
> +               } seccomp;
> +       };
> +};
> +
> +/*
> + * These values are stored in task->ptrace_message
> + * by tracehook_report_syscall_* to describe the current syscall-stop.
> + */
> +#define PTRACE_EVENTMSG_SYSCALL_ENTRY  1
> +#define PTRACE_EVENTMSG_SYSCALL_EXIT   2
> +
>  /* Read signals from a shared (process wide) queue */
>  #define PTRACE_PEEKSIGINFO_SHARED      (1 << 0)
>
> diff --git a/kernel/ptrace.c b/kernel/ptrace.c
> index c2cee9db5204..4562b2cb1087 100644
> --- a/kernel/ptrace.c
> +++ b/kernel/ptrace.c
> @@ -30,6 +30,8 @@
>  #include <linux/cn_proc.h>
>  #include <linux/compat.h>
>
> +#include <asm/syscall.h>       /* For syscall_get_* */
> +
>  /*
>   * Access another process' address space via ptrace.
>   * Source/target buffer must be kernel space,
> @@ -878,7 +880,98 @@ static int ptrace_regset(struct task_struct *task, int req, unsigned int type,
>   * to ensure no machine forgets it.
>   */
>  EXPORT_SYMBOL_GPL(task_user_regset_view);
> -#endif
> +#endif /* CONFIG_HAVE_ARCH_TRACEHOOK */
> +
> +static unsigned long
> +ptrace_get_syscall_info_entry(struct task_struct *child, struct pt_regs *regs,
> +                             struct ptrace_syscall_info *info)
> +{
> +       unsigned long args[ARRAY_SIZE(info->entry.args)];
> +       int i;
> +
> +       info->op = PTRACE_SYSCALL_INFO_ENTRY;
> +       info->entry.nr = syscall_get_nr(child, regs);
> +       syscall_get_arguments(child, regs, 0, ARRAY_SIZE(args), args);
> +       for (i = 0; i < ARRAY_SIZE(args); i++)
> +               info->entry.args[i] = args[i];
> +
> +       return offsetofend(struct ptrace_syscall_info, entry);
> +}
> +
> +static unsigned long
> +ptrace_get_syscall_info_seccomp(struct task_struct *child, struct pt_regs *regs,
> +                               struct ptrace_syscall_info *info)
> +{
> +       /*
> +        * As struct ptrace_syscall_info.entry is currently a subset
> +        * of struct ptrace_syscall_info.seccomp, it makes sense to
> +        * initialize that subset using ptrace_get_syscall_info_entry().
> +        * This can be reconsidered in the future if these structures
> +        * diverge significantly enough.
> +        */
> +       ptrace_get_syscall_info_entry(child, regs, info);
> +       info->op = PTRACE_SYSCALL_INFO_SECCOMP;
> +       info->seccomp.ret_data = child->ptrace_message;
> +
> +       return offsetofend(struct ptrace_syscall_info, seccomp);
> +}
> +
> +static unsigned long
> +ptrace_get_syscall_info_exit(struct task_struct *child, struct pt_regs *regs,
> +                            struct ptrace_syscall_info *info)
> +{
> +       info->op = PTRACE_SYSCALL_INFO_EXIT;
> +       info->exit.rval = syscall_get_error(child, regs);
> +       info->exit.is_error = !!info->exit.rval;
> +       if (!info->exit.is_error)
> +               info->exit.rval = syscall_get_return_value(child, regs);
> +
> +       return offsetofend(struct ptrace_syscall_info, exit);
> +}
> +
> +static int
> +ptrace_get_syscall_info(struct task_struct *child, unsigned long user_size,
> +                       void __user *datavp)
> +{
> +       struct pt_regs *regs = task_pt_regs(child);
> +       struct ptrace_syscall_info info = {
> +               .op = PTRACE_SYSCALL_INFO_NONE,
> +               .arch = syscall_get_arch(child),
> +               .instruction_pointer = instruction_pointer(regs),
> +               .stack_pointer = user_stack_pointer(regs),
> +               .frame_pointer = frame_pointer(regs)
> +       };
> +       unsigned long actual_size = offsetof(struct ptrace_syscall_info, entry);
> +       unsigned long write_size;
> +
> +       /*
> +        * This does not need lock_task_sighand() to access
> +        * child->last_siginfo because ptrace_freeze_traced()
> +        * called earlier by ptrace_check_attach() ensures that
> +        * the tracee cannot go away and clear its last_siginfo.
> +        */
> +       switch (child->last_siginfo ? child->last_siginfo->si_code : 0) {
> +       case SIGTRAP | 0x80:
> +               switch (child->ptrace_message) {
> +               case PTRACE_EVENTMSG_SYSCALL_ENTRY:
> +                       actual_size = ptrace_get_syscall_info_entry(child, regs,
> +                                                                   &info);
> +                       break;
> +               case PTRACE_EVENTMSG_SYSCALL_EXIT:
> +                       actual_size = ptrace_get_syscall_info_exit(child, regs,
> +                                                                  &info);
> +                       break;
> +               }
> +               break;
> +       case SIGTRAP | (PTRACE_EVENT_SECCOMP << 8):
> +               actual_size = ptrace_get_syscall_info_seccomp(child, regs,
> +                                                             &info);
> +               break;
> +       }
> +
> +       write_size = min(actual_size, user_size);
> +       return copy_to_user(datavp, &info, write_size) ? -EFAULT : actual_size;
> +}
>
>  int ptrace_request(struct task_struct *child, long request,
>                    unsigned long addr, unsigned long data)
> @@ -1095,6 +1188,10 @@ int ptrace_request(struct task_struct *child, long request,
>                 ret = seccomp_get_metadata(child, addr, datavp);
>                 break;
>
> +       case PTRACE_GET_SYSCALL_INFO:
> +               ret = ptrace_get_syscall_info(child, addr, datavp);
> +               break;
> +
>         default:
>                 break;
>         }
> --
> ldv



-- 
Kees Cook

^ permalink raw reply	[flat|nested] 65+ messages in thread

* Re: [PATCH v5 24/25] ptrace: add PTRACE_GET_SYSCALL_INFO request
  2018-12-10 16:09     ` Dmitry V. Levin
@ 2018-12-10 18:04       ` Paul Burton
  2018-12-10 21:04         ` Palmer Dabbelt
  2018-12-10 19:38       ` Andy Lutomirski
  1 sibling, 1 reply; 65+ messages in thread
From: Paul Burton @ 2018-12-10 18:04 UTC (permalink / raw)
  To: Dmitry V. Levin
  Cc: Ralf Baechle, James Hogan, Oleg Nesterov, Andy Lutomirski,
	Elvira Khabirova, Eugene Syromyatnikov, Kees Cook, Jann Horn,
	linux-api, strace-devel, linux-kernel

Hi Dmitry,

On Mon, Dec 10, 2018 at 07:09:40PM +0300, Dmitry V. Levin wrote:
> We decided to add .frame_pointer to struct ptrace_syscall_info just for
> consistency with .instruction_pointer and .stack_pointer; I must have been
> misled by comments in asm-generic/ptrace.h into thinking that
> frame_pointer() is universally available across architectures.

Is it correct to say that you're using frame_pointer() purely on user
register state, not kernel?

If so then one option would be to define it for MIPS as something like:

    static inline unsigned long frame_pointer(struct pt_regs *regs)
    {
    	return regs->regs[30];
    }

My concern with that though would be that providing frame_pointer()
unconditionally might mislead people into thinking that the kernel
always has frame pointers, when in reality current MIPS kernels never
do. In fact a comment in MIPS' asm/ptrace.h seems to suggest the lack of
frame_pointer() is intentional for exactly that reason:

> Don't use asm-generic/ptrace.h it defines FP accessors that don't make
> sense on MIPS.  We rather want an error if they get invoked.

Looking across architectures though MIPS isn't going to be the only one
missing frame_pointer(). With a little grepping it appears that these
architectures provide frame_pointer():

  arm
  arm64
  hexagon
  nds32
  powerpc
  riscv
  sparc
  um
  x86

That leaves a whole bunch of other architectures (16) which don't have
frame_pointer(), or at least not in a way that I could see at a glance.

> Unlike .instruction_pointer and .stack_pointer that are actually needed
> in strace, .frame_pointer is not used, so from strace PoV we don't really
> need it.
> 
> So the question is, does anybody need a
> struct ptrace_syscall_info.frame_pointer?
> 
> If yes, how can frame_pointer() be defined on MIPS?
> Or should we just forget about making sense of frame_pointer() and remove
> struct ptrace_syscall_info.frame_pointer from the proposed API?

So, along these lines my suggestion would be to avoid it if you don't
really need it anyway.

Thanks,
    Paul

^ permalink raw reply	[flat|nested] 65+ messages in thread

* Re: [PATCH v5 24/25] ptrace: add PTRACE_GET_SYSCALL_INFO request
  2018-12-10 16:09     ` Dmitry V. Levin
  2018-12-10 18:04       ` Paul Burton
@ 2018-12-10 19:38       ` Andy Lutomirski
  1 sibling, 0 replies; 65+ messages in thread
From: Andy Lutomirski @ 2018-12-10 19:38 UTC (permalink / raw)
  To: Dmitry V. Levin
  Cc: paul.burton, Ralf Baechle, jhogan, Oleg Nesterov,
	Andrew Lutomirski, Elvira Khabirova, Eugene Syromiatnikov,
	Kees Cook, Jann Horn, Linux API, strace-devel, LKML

> On Dec 10, 2018, at 8:09 AM, Dmitry V. Levin <ldv@altlinux.org> wrote:
>
> Hi, things are getting too complicated and we need some advice how to deal
> with this frame_pointer issue.
>
>> On Mon, Dec 10, 2018 at 10:26:50PM +0800, kbuild test robot wrote:
>> Hi Elvira,
>>
>> Thank you for the patch! Yet something to improve:
>>
>> [auto build test ERROR on linus/master]
>> [also build test ERROR on v4.20-rc6]
>> [cannot apply to next-20181207]
>> [if your patch is applied to the wrong git tree, please drop us a note to help improve the system]
>>
>> url:    https://github.com/0day-ci/linux/commits/Dmitry-V-Levin/ptrace-add-PTRACE_GET_SYSCALL_INFO-request/20181210-174745
>> config: mips-malta_kvm_defconfig (attached as .config)
>> compiler: mipsel-linux-gnu-gcc (Debian 7.2.0-11) 7.2.0
>> reproduce:
>>        wget https://raw.githubusercontent.com/intel/lkp-tests/master/sbin/make.cross -O ~/bin/make.cross
>>        chmod +x ~/bin/make.cross
>>        # save the attached .config to linux build tree
>>        GCC_VERSION=7.2.0 make.cross ARCH=mips
>>
>> All errors (new ones prefixed by >>):
>>
>>   kernel/ptrace.c: In function 'ptrace_get_syscall_info':
>>>> kernel/ptrace.c:942:20: error: implicit declaration of function 'frame_pointer'; did you mean 'trace_printk'? [-Werror=implicit-function-declaration]
>>      .frame_pointer = frame_pointer(regs)
>>                       ^~~~~~~~~~~~~
>>                       trace_printk
>>   cc1: some warnings being treated as errors
>>
>> vim +942 kernel/ptrace.c
>>
>>   931
>>   932    static int
>>   933    ptrace_get_syscall_info(struct task_struct *child, unsigned long user_size,
>>   934                void __user *datavp)
>>   935    {
>>   936        struct pt_regs *regs = task_pt_regs(child);
>>   937        struct ptrace_syscall_info info = {
>>   938            .op = PTRACE_SYSCALL_INFO_NONE,
>>   939            .arch = syscall_get_arch(child),
>>   940            .instruction_pointer = instruction_pointer(regs),
>>   941            .stack_pointer = user_stack_pointer(regs),
>>> 942            .frame_pointer = frame_pointer(regs)
>>   943        };
>>   944        unsigned long actual_size = offsetof(struct ptrace_syscall_info, entry);
>>   945        unsigned long write_size;
>>   946
>>   947        /*
>>   948         * This does not need lock_task_sighand() to access
>>   949         * child->last_siginfo because ptrace_freeze_traced()
>>   950         * called earlier by ptrace_check_attach() ensures that
>>   951         * the tracee cannot go away and clear its last_siginfo.
>>   952         */
>>   953        switch (child->last_siginfo ? child->last_siginfo->si_code : 0) {
>>   954        case SIGTRAP | 0x80:
>>   955            switch (child->ptrace_message) {
>>   956            case PTRACE_EVENTMSG_SYSCALL_ENTRY:
>>   957                actual_size = ptrace_get_syscall_info_entry(child, regs,
>>   958                                        &info);
>>   959                break;
>>   960            case PTRACE_EVENTMSG_SYSCALL_EXIT:
>>   961                actual_size = ptrace_get_syscall_info_exit(child, regs,
>>   962                                       &info);
>>   963                break;
>>   964            }
>>   965            break;
>>   966        case SIGTRAP | (PTRACE_EVENT_SECCOMP << 8):
>>   967            actual_size = ptrace_get_syscall_info_seccomp(child, regs,
>>   968                                      &info);
>>   969            break;
>>   970        }
>>   971
>>   972        write_size = min(actual_size, user_size);
>>   973        return copy_to_user(datavp, &info, write_size) ? -EFAULT : actual_size;
>>   974    }
>>   975
>
> We decided to add .frame_pointer to struct ptrace_syscall_info just for
> consistency with .instruction_pointer and .stack_pointer; I must have been
> misled by comments in asm-generic/ptrace.h into thinking that
> frame_pointer() is universally available across architectures.
>
> Unlike .instruction_pointer and .stack_pointer that are actually needed
> in strace, .frame_pointer is not used, so from strace PoV we don't really
> need it.
>
> So the question is, does anybody need a
> struct ptrace_syscall_info.frame_pointer?
>
> If yes, how can frame_pointer() be defined on MIPS?
> Or should we just forget about making sense of frame_pointer() and remove
> struct ptrace_syscall_info.frame_pointer from the proposed API?
>

I would suggest getting rid of frame_pointer. Anyone who needs that
degree of debugging can use existing ptrace APIs for it.

>
> --
> ldv

^ permalink raw reply	[flat|nested] 65+ messages in thread

* Re: [PATCH v5 19/25] xtensa: define syscall_get_* functions
  2018-12-10 12:53     ` Dmitry V. Levin
@ 2018-12-10 20:14       ` Max Filippov
  2018-12-10 20:24         ` Dmitry V. Levin
  0 siblings, 1 reply; 65+ messages in thread
From: Max Filippov @ 2018-12-10 20:14 UTC (permalink / raw)
  To: ldv
  Cc: oleg, Andrew Lutomirski, lineprinter, esyr, Chris Zankel,
	Paul Moore, eparis, linux-xtensa, linux-audit, LKML

On Mon, Dec 10, 2018 at 4:53 AM Dmitry V. Levin <ldv@altlinux.org> wrote:
> On Sun, Dec 09, 2018 at 09:02:50PM -0800, Max Filippov wrote:
> > How should we synchronize our changes?
>
> No problem, I can revert to the previous edition of this patch
> that just adds syscall_get_arch.
> Alternatively, you can just take that couple of patches (v5 18/25
> and v2 15/15) into your tree.

Sure I can do the second. Will it work for v2 16/15 that changes
syscall_get_arch adding an argument to it?

--
Thanks.
-- Max

^ permalink raw reply	[flat|nested] 65+ messages in thread

* Re: [PATCH v5 19/25] xtensa: define syscall_get_* functions
  2018-12-10 20:14       ` Max Filippov
@ 2018-12-10 20:24         ` Dmitry V. Levin
  2018-12-10 20:30           ` Dmitry V. Levin
  0 siblings, 1 reply; 65+ messages in thread
From: Dmitry V. Levin @ 2018-12-10 20:24 UTC (permalink / raw)
  To: Max Filippov
  Cc: Oleg Nesterov, Andrew Lutomirski, Elvira Khabirova,
	Eugene Syromyatnikov, Chris Zankel, Paul Moore, Eric Paris,
	linux-xtensa, linux-audit, LKML

[-- Attachment #1: Type: text/plain, Size: 713 bytes --]

On Mon, Dec 10, 2018 at 12:14:37PM -0800, Max Filippov wrote:
> On Mon, Dec 10, 2018 at 4:53 AM Dmitry V. Levin <ldv@altlinux.org> wrote:
> > On Sun, Dec 09, 2018 at 09:02:50PM -0800, Max Filippov wrote:
> > > How should we synchronize our changes?
> >
> > No problem, I can revert to the previous edition of this patch
> > that just adds syscall_get_arch.
> > Alternatively, you can just take that couple of patches (v5 18/25
> > and v2 15/15) into your tree.
> 
> Sure I can do the second. Will it work for v2 16/15 that changes
> syscall_get_arch adding an argument to it?

No, I'm afraid it won't work for v2 16/15 (aka v5 22/25), which means
I'd have to keep them in the series.


-- 
ldv

[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 801 bytes --]

^ permalink raw reply	[flat|nested] 65+ messages in thread

* Re: [PATCH v5 19/25] xtensa: define syscall_get_* functions
  2018-12-10 20:24         ` Dmitry V. Levin
@ 2018-12-10 20:30           ` Dmitry V. Levin
  2018-12-10 21:29             ` Max Filippov
  0 siblings, 1 reply; 65+ messages in thread
From: Dmitry V. Levin @ 2018-12-10 20:30 UTC (permalink / raw)
  To: Max Filippov
  Cc: Oleg Nesterov, Andrew Lutomirski, Elvira Khabirova,
	Eugene Syromyatnikov, Chris Zankel, Paul Moore, Eric Paris,
	linux-xtensa, linux-audit, LKML

[-- Attachment #1: Type: text/plain, Size: 971 bytes --]

On Mon, Dec 10, 2018 at 11:24:02PM +0300, Dmitry V. Levin wrote:
> On Mon, Dec 10, 2018 at 12:14:37PM -0800, Max Filippov wrote:
> > On Mon, Dec 10, 2018 at 4:53 AM Dmitry V. Levin <ldv@altlinux.org> wrote:
> > > On Sun, Dec 09, 2018 at 09:02:50PM -0800, Max Filippov wrote:
> > > > How should we synchronize our changes?
> > >
> > > No problem, I can revert to the previous edition of this patch
> > > that just adds syscall_get_arch.
> > > Alternatively, you can just take that couple of patches (v5 18/25
> > > and v2 15/15) into your tree.
> > 
> > Sure I can do the second. Will it work for v2 16/15 that changes
> > syscall_get_arch adding an argument to it?
> 
> No, I'm afraid it won't work for v2 16/15 (aka v5 22/25), which means
> I'd have to keep them in the series.

You can surely take them into your tree, but I'll have to keep them
in the series because of that change of syscall_get_arch signature.
Sorry for confusion.


-- 
ldv

[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 801 bytes --]

^ permalink raw reply	[flat|nested] 65+ messages in thread

* Re: [PATCH v5 24/25] ptrace: add PTRACE_GET_SYSCALL_INFO request
  2018-12-10 18:04       ` Paul Burton
@ 2018-12-10 21:04         ` Palmer Dabbelt
  0 siblings, 0 replies; 65+ messages in thread
From: Palmer Dabbelt @ 2018-12-10 21:04 UTC (permalink / raw)
  To: paul.burton
  Cc: ldv, ralf, jhogan, oleg, luto, lineprinter, esyr, keescook,
	jannh, linux-api, strace-devel, linux-kernel

On Mon, 10 Dec 2018 10:04:22 PST (-0800), paul.burton@mips.com wrote:
> Hi Dmitry,
>
> On Mon, Dec 10, 2018 at 07:09:40PM +0300, Dmitry V. Levin wrote:
>> We decided to add .frame_pointer to struct ptrace_syscall_info just for
>> consistency with .instruction_pointer and .stack_pointer; I must have been
>> misled by comments in asm-generic/ptrace.h into thinking that
>> frame_pointer() is universally available across architectures.
>
> Is it correct to say that you're using frame_pointer() purely on user
> register state, not kernel?
>
> If so then one option would be to define it for MIPS as something like:
>
>     static inline unsigned long frame_pointer(struct pt_regs *regs)
>     {
>     	return regs->regs[30];
>     }
>
> My concern with that though would be that providing frame_pointer()
> unconditionally might mislead people into thinking that the kernel
> always has frame pointers, when in reality current MIPS kernels never
> do. In fact a comment in MIPS' asm/ptrace.h seems to suggest the lack of
> frame_pointer() is intentional for exactly that reason:
>
>> Don't use asm-generic/ptrace.h it defines FP accessors that don't make
>> sense on MIPS.  We rather want an error if they get invoked.
>
> Looking across architectures though MIPS isn't going to be the only one
> missing frame_pointer(). With a little grepping it appears that these
> architectures provide frame_pointer():
>
>   arm
>   arm64
>   hexagon
>   nds32
>   powerpc
>   riscv
>   sparc
>   um
>   x86
>
> That leaves a whole bunch of other architectures (16) which don't have
> frame_pointer(), or at least not in a way that I could see at a glance.

We (RISC-V) default to compiling without frame pointers.  I'm not sure if it 
even makes sense have frame_pointer() on RISC-V, as it'll usually return 
garbage.

>> Unlike .instruction_pointer and .stack_pointer that are actually needed
>> in strace, .frame_pointer is not used, so from strace PoV we don't really
>> need it.
>> 
>> So the question is, does anybody need a
>> struct ptrace_syscall_info.frame_pointer?
>> 
>> If yes, how can frame_pointer() be defined on MIPS?
>> Or should we just forget about making sense of frame_pointer() and remove
>> struct ptrace_syscall_info.frame_pointer from the proposed API?
>
> So, along these lines my suggestion would be to avoid it if you don't
> really need it anyway.
>
> Thanks,
>     Paul

^ permalink raw reply	[flat|nested] 65+ messages in thread

* Re: [PATCH v5 19/25] xtensa: define syscall_get_* functions
  2018-12-10 20:30           ` Dmitry V. Levin
@ 2018-12-10 21:29             ` Max Filippov
  0 siblings, 0 replies; 65+ messages in thread
From: Max Filippov @ 2018-12-10 21:29 UTC (permalink / raw)
  To: ldv
  Cc: oleg, Andrew Lutomirski, lineprinter, esyr, Chris Zankel,
	Paul Moore, eparis, linux-xtensa, linux-audit, LKML

On Mon, Dec 10, 2018 at 12:30 PM Dmitry V. Levin <ldv@altlinux.org> wrote:
> On Mon, Dec 10, 2018 at 11:24:02PM +0300, Dmitry V. Levin wrote:
> > On Mon, Dec 10, 2018 at 12:14:37PM -0800, Max Filippov wrote:
> > > On Mon, Dec 10, 2018 at 4:53 AM Dmitry V. Levin <ldv@altlinux.org> wrote:
> > > > On Sun, Dec 09, 2018 at 09:02:50PM -0800, Max Filippov wrote:
> > > > > How should we synchronize our changes?
> > > >
> > > > No problem, I can revert to the previous edition of this patch
> > > > that just adds syscall_get_arch.
> > > > Alternatively, you can just take that couple of patches (v5 18/25
> > > > and v2 15/15) into your tree.
> > >
> > > Sure I can do the second. Will it work for v2 16/15 that changes
> > > syscall_get_arch adding an argument to it?
> >
> > No, I'm afraid it won't work for v2 16/15 (aka v5 22/25), which means
> > I'd have to keep them in the series.
>
> You can surely take them into your tree, but I'll have to keep them
> in the series because of that change of syscall_get_arch signature.
> Sorry for confusion.

Ok, no problem, I'll take them. I'm planning to merge this branch into the
for-next in a couple of days, let's see how it goes after that.

-- 
Thanks.
-- Max

^ permalink raw reply	[flat|nested] 65+ messages in thread

* Re: [PATCH v5 24/25] ptrace: add PTRACE_GET_SYSCALL_INFO request
  2018-12-10 16:21     ` Dmitry V. Levin
@ 2018-12-11 15:29       ` Oleg Nesterov
  2018-12-11 16:23         ` Dmitry V. Levin
  0 siblings, 1 reply; 65+ messages in thread
From: Oleg Nesterov @ 2018-12-11 15:29 UTC (permalink / raw)
  To: Dmitry V. Levin
  Cc: Andy Lutomirski, Elvira Khabirova, Eugene Syromyatnikov,
	Kees Cook, Jann Horn, linux-api, strace-devel, linux-kernel

On 12/10, Dmitry V. Levin wrote:
>
> On Mon, Dec 10, 2018 at 03:11:07PM +0100, Oleg Nesterov wrote:
> > On 12/10, Dmitry V. Levin wrote:
> > >
> > > +struct ptrace_syscall_info {
> > > +	__u8 op;	/* PTRACE_SYSCALL_INFO_* */
> > > +	__u8 __pad0[3];
> > > +	__u32 arch;
> > > +	__u64 instruction_pointer;
> > > +	__u64 stack_pointer;
> > > +	__u64 frame_pointer;
> > > +	union {
> > > +		struct {
> > > +			__u64 nr;
> > > +			__u64 args[6];
> > > +		} entry;
> > > +		struct {
> > > +			__s64 rval;
> > > +			__u8 is_error;
> > > +			__u8 __pad1[7];
> > > +		} exit;
> > > +		struct {
> > > +			__u64 nr;
> > > +			__u64 args[6];
> > > +			__u32 ret_data;
> > > +			__u8 __pad2[4];
> > > +		} seccomp;
> > > +	};
> > > +};
> >
> > Could you explain why ptrace_syscall_info needs __pad{0,1,2} ? I simply can't
> > understand why...
>
> I suppose the idea behind the use of these pads was to make the structure
> arch-independent.

Still can't understand... are you saying that without (say) __pad2[4]
sizeof(ptrace_syscall_info) or offsetofend(ptrace_syscall_info, seccomp)
will depend on arch? Or what? I am just curious.

> I don't think we really need to keep it exactly the same on all
> architectures - the only practical requirement is to avoid any compat
> issues, but I don't mind keeping the structure arch-independent.

OK, but may be you can add a short comment to explain these pads.

Oleg.


^ permalink raw reply	[flat|nested] 65+ messages in thread

* Re: [PATCH v5 24/25] ptrace: add PTRACE_GET_SYSCALL_INFO request
  2018-12-11 15:29       ` Oleg Nesterov
@ 2018-12-11 16:23         ` Dmitry V. Levin
  2018-12-11 20:27           ` Dmitry V. Levin
  0 siblings, 1 reply; 65+ messages in thread
From: Dmitry V. Levin @ 2018-12-11 16:23 UTC (permalink / raw)
  To: Oleg Nesterov
  Cc: Andy Lutomirski, Elvira Khabirova, Eugene Syromyatnikov,
	Kees Cook, Jann Horn, linux-api, strace-devel, linux-kernel

[-- Attachment #1: Type: text/plain, Size: 2652 bytes --]

On Tue, Dec 11, 2018 at 04:29:54PM +0100, Oleg Nesterov wrote:
> On 12/10, Dmitry V. Levin wrote:
> > On Mon, Dec 10, 2018 at 03:11:07PM +0100, Oleg Nesterov wrote:
> > > On 12/10, Dmitry V. Levin wrote:
> > > >
> > > > +struct ptrace_syscall_info {
> > > > +	__u8 op;	/* PTRACE_SYSCALL_INFO_* */
> > > > +	__u8 __pad0[3];
> > > > +	__u32 arch;
> > > > +	__u64 instruction_pointer;
> > > > +	__u64 stack_pointer;
> > > > +	__u64 frame_pointer;
> > > > +	union {
> > > > +		struct {
> > > > +			__u64 nr;
> > > > +			__u64 args[6];
> > > > +		} entry;
> > > > +		struct {
> > > > +			__s64 rval;
> > > > +			__u8 is_error;
> > > > +			__u8 __pad1[7];
> > > > +		} exit;
> > > > +		struct {
> > > > +			__u64 nr;
> > > > +			__u64 args[6];
> > > > +			__u32 ret_data;
> > > > +			__u8 __pad2[4];
> > > > +		} seccomp;
> > > > +	};
> > > > +};
> > >
> > > Could you explain why ptrace_syscall_info needs __pad{0,1,2} ? I simply can't
> > > understand why...
> >
> > I suppose the idea behind the use of these pads was to make the structure
> > arch-independent.
> 
> Still can't understand... are you saying that without (say) __pad2[4]
> sizeof(ptrace_syscall_info) or offsetofend(ptrace_syscall_info, seccomp)
> will depend on arch? Or what? I am just curious.

Yes, without padding these sizes will depend on architecture:

$ cat t.c
#include <linux/types.h>
int main() {
	struct s {
		__u64 nr;
		__u64 args[6];
		__u32 ret_data;
	};
	return sizeof(struct s);
}

$ gcc -m64 -Wall -O2 t.c && ./a.out; echo $?
64
$ gcc -m32 -Wall -O2 t.c && ./a.out; echo $?
60

This happens because __u64 has 32-bit alignment on some 32-bit
architectures like x86.

There is also m68k where __u32 has 16-bit alignment.

> > I don't think we really need to keep it exactly the same on all
> > architectures - the only practical requirement is to avoid any compat
> > issues, but I don't mind keeping the structure arch-independent.
> 
> OK, but may be you can add a short comment to explain these pads.

Alternatively, we could use __attribute__((aligned(N))), e.g.

struct ptrace_syscall_info {
	__u8 op;	/* PTRACE_SYSCALL_INFO_* */
	__u32 arch __attribute__((aligned(4)));
	__u64 instruction_pointer;
	__u64 stack_pointer;
	union {
		struct {
			__u64 nr __attribute__((aligned(8)));
			__u64 args[6];
		} entry;
		struct {
			__s64 rval __attribute__((aligned(8)));
			__u8 is_error;
		} exit;
		struct {
			__u64 nr __attribute__((aligned(8)));
			__u64 args[6];
			__u32 ret_data;
		} seccomp;
	};
};

Do you prefer __attribute__((aligned(N))) to padding?


-- 
ldv

[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 801 bytes --]

^ permalink raw reply	[flat|nested] 65+ messages in thread

* Re: [PATCH v5 24/25] ptrace: add PTRACE_GET_SYSCALL_INFO request
  2018-12-11 16:23         ` Dmitry V. Levin
@ 2018-12-11 20:27           ` Dmitry V. Levin
  2018-12-12 18:00             ` Oleg Nesterov
  0 siblings, 1 reply; 65+ messages in thread
From: Dmitry V. Levin @ 2018-12-11 20:27 UTC (permalink / raw)
  To: Oleg Nesterov
  Cc: Andy Lutomirski, Elvira Khabirova, Eugene Syromyatnikov,
	Kees Cook, Jann Horn, linux-api, strace-devel, linux-kernel

[-- Attachment #1: Type: text/plain, Size: 2478 bytes --]

On Tue, Dec 11, 2018 at 07:23:05PM +0300, Dmitry V. Levin wrote:
> On Tue, Dec 11, 2018 at 04:29:54PM +0100, Oleg Nesterov wrote:
> > On 12/10, Dmitry V. Levin wrote:
> > > On Mon, Dec 10, 2018 at 03:11:07PM +0100, Oleg Nesterov wrote:
> > > > On 12/10, Dmitry V. Levin wrote:
> > > > >
> > > > > +struct ptrace_syscall_info {
> > > > > +	__u8 op;	/* PTRACE_SYSCALL_INFO_* */
> > > > > +	__u8 __pad0[3];
> > > > > +	__u32 arch;
> > > > > +	__u64 instruction_pointer;
> > > > > +	__u64 stack_pointer;
> > > > > +	__u64 frame_pointer;
> > > > > +	union {
> > > > > +		struct {
> > > > > +			__u64 nr;
> > > > > +			__u64 args[6];
> > > > > +		} entry;
> > > > > +		struct {
> > > > > +			__s64 rval;
> > > > > +			__u8 is_error;
> > > > > +			__u8 __pad1[7];
> > > > > +		} exit;
> > > > > +		struct {
> > > > > +			__u64 nr;
> > > > > +			__u64 args[6];
> > > > > +			__u32 ret_data;
> > > > > +			__u8 __pad2[4];
> > > > > +		} seccomp;
> > > > > +	};
> > > > > +};
> > > >
> > > > Could you explain why ptrace_syscall_info needs __pad{0,1,2} ? I simply can't
> > > > understand why...
> > >
> > > I suppose the idea behind the use of these pads was to make the structure
> > > arch-independent.
> > 
> > Still can't understand... are you saying that without (say) __pad2[4]
> > sizeof(ptrace_syscall_info) or offsetofend(ptrace_syscall_info, seccomp)
> > will depend on arch? Or what? I am just curious.
> 
> Yes, without padding these sizes will depend on architecture:
> 
> $ cat t.c
> #include <linux/types.h>
> int main() {
> 	struct s {
> 		__u64 nr;
> 		__u64 args[6];
> 		__u32 ret_data;
> 	};
> 	return sizeof(struct s);
> }
> 
> $ gcc -m64 -Wall -O2 t.c && ./a.out; echo $?
> 64
> $ gcc -m32 -Wall -O2 t.c && ./a.out; echo $?
> 60
> 
> This happens because __u64 has 32-bit alignment on some 32-bit
> architectures like x86.
> 
> There is also m68k where __u32 has 16-bit alignment.

Said that, I think it would be better if PTRACE_GET_SYSCALL_INFO
did not take these trailing pads into account, e.g.

-       return offsetofend(struct ptrace_syscall_info, seccomp);
+       return offsetofend(struct ptrace_syscall_info, seccomp.ret_data);
...
-       return offsetofend(struct ptrace_syscall_info, exit);
+       return offsetofend(struct ptrace_syscall_info, exit.is_error);

The reason is that it would allow to fill these trailing pads with
something useful in the future.


-- 
ldv

[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 801 bytes --]

^ permalink raw reply	[flat|nested] 65+ messages in thread

* Re: [PATCH v5 04/25] c6x: define syscall_get_arch()
  2018-12-10  4:29 ` [PATCH v5 04/25] c6x: " Dmitry V. Levin
@ 2018-12-11 22:40   ` Mark Salter
  0 siblings, 0 replies; 65+ messages in thread
From: Mark Salter @ 2018-12-11 22:40 UTC (permalink / raw)
  To: Dmitry V. Levin, Aurelien Jacquiot, Paul Moore, Eric Paris,
	Oleg Nesterov, Andy Lutomirski
  Cc: Elvira Khabirova, Eugene Syromyatnikov, linux-c6x-dev,
	linux-audit, linux-kernel

On Mon, 2018-12-10 at 07:29 +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.
> 
> Cc: Mark Salter <msalter@redhat.com>
> Cc: Aurelien Jacquiot <jacquiot.aurelien@gmail.com>
> Cc: Paul Moore <paul@paul-moore.com>
> Cc: Eric Paris <eparis@redhat.com>
> Cc: Oleg Nesterov <oleg@redhat.com>
> Cc: Andy Lutomirski <luto@kernel.org>
> Cc: Elvira Khabirova <lineprinter@altlinux.org>
> Cc: Eugene Syromyatnikov <esyr@redhat.com>
> Cc: linux-c6x-dev@linux-c6x.org
> Cc: linux-audit@redhat.com
> Signed-off-by: Dmitry V. Levin <ldv@altlinux.org>
> ---
> 
> Notes:
>     v5: added Cc
> 
>  arch/c6x/include/asm/syscall.h | 7 +++++++
>  include/uapi/linux/audit.h     | 2 ++
>  2 files changed, 9 insertions(+)
> 
> diff --git a/arch/c6x/include/asm/syscall.h b/arch/c6x/include/asm/syscall.h
> index ae2be315ee9c..39dbd1ef994c 100644
> --- a/arch/c6x/include/asm/syscall.h
> +++ b/arch/c6x/include/asm/syscall.h
> @@ -11,6 +11,7 @@
>  #ifndef __ASM_C6X_SYSCALL_H
>  #define __ASM_C6X_SYSCALL_H
>  
> +#include <uapi/linux/audit.h>
>  #include <linux/err.h>
>  #include <linux/sched.h>
>  
> @@ -120,4 +121,10 @@ static inline void syscall_set_arguments(struct task_struct *task,
>  	}
>  }
>  
> +static inline int syscall_get_arch(void)
> +{
> +	return IS_ENABLED(CONFIG_CPU_BIG_ENDIAN)
> +		? AUDIT_ARCH_C6XBE : AUDIT_ARCH_C6X;
> +}
> +
>  #endif /* __ASM_C6X_SYSCALLS_H */
> diff --git a/include/uapi/linux/audit.h b/include/uapi/linux/audit.h
> index bedf3bf54c3a..72aeea0a740d 100644
> --- a/include/uapi/linux/audit.h
> +++ b/include/uapi/linux/audit.h
> @@ -381,6 +381,8 @@ enum {
>  #define AUDIT_ARCH_ARCV2BE	(EM_ARCV2)
>  #define AUDIT_ARCH_ARM		(EM_ARM|__AUDIT_ARCH_LE)
>  #define AUDIT_ARCH_ARMEB	(EM_ARM)
> +#define AUDIT_ARCH_C6X		(EM_TI_C6000|__AUDIT_ARCH_LE)
> +#define AUDIT_ARCH_C6XBE	(EM_TI_C6000)
>  #define AUDIT_ARCH_CRIS		(EM_CRIS|__AUDIT_ARCH_LE)
>  #define AUDIT_ARCH_FRV		(EM_FRV)
>  #define AUDIT_ARCH_I386		(EM_386|__AUDIT_ARCH_LE)

Acked-by: Mark Salter <msalter@redhat.com>



^ permalink raw reply	[flat|nested] 65+ messages in thread

* Re: [PATCH v5 22/25] syscall_get_arch: add "struct task_struct *" argument
  2018-12-10  4:31 ` [PATCH v5 22/25] syscall_get_arch: add "struct task_struct *" argument Dmitry V. Levin
  2018-12-10 17:29   ` Kees Cook
@ 2018-12-11 22:44   ` Mark Salter
  1 sibling, 0 replies; 65+ messages in thread
From: Mark Salter @ 2018-12-11 22:44 UTC (permalink / raw)
  To: Dmitry V. Levin; +Cc: linux-kernel, linux-c6x-dev

On Mon, 2018-12-10 at 07:31 +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 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 <luto@kernel.org> # for x86
> Reviewed-by: Palmer Dabbelt <palmer@sifive.com>
> Acked-by: Paul Burton <paul.burton@mips.com> # MIPS parts
> Acked-by: Michael Ellerman <mpe@ellerman.id.au> (powerpc)
> Cc: Eric Paris <eparis@redhat.com>
> Cc: Paul Moore <paul@paul-moore.com>
> Cc: Richard Henderson <rth@twiddle.net>
> Cc: Ivan Kokshaysky <ink@jurassic.park.msu.ru>
> Cc: Matt Turner <mattst88@gmail.com>
> Cc: Vineet Gupta <vgupta@synopsys.com>
> Cc: Russell King <linux@armlinux.org.uk>
> Cc: Catalin Marinas <catalin.marinas@arm.com>
> Cc: Will Deacon <will.deacon@arm.com>
> Cc: Mark Salter <msalter@redhat.com>
> Cc: Aurelien Jacquiot <jacquiot.aurelien@gmail.com>
> Cc: Yoshinori Sato <ysato@users.sourceforge.jp>
> Cc: Richard Kuo <rkuo@codeaurora.org>
> Cc: Tony Luck <tony.luck@intel.com>
> Cc: Fenghua Yu <fenghua.yu@intel.com>
> Cc: Geert Uytterhoeven <geert@linux-m68k.org>
> Cc: Michal Simek <monstr@monstr.eu>
> Cc: Greentime Hu <green.hu@gmail.com>
> Cc: Vincent Chen <deanbo422@gmail.com>
> Cc: Ley Foon Tan <lftan@altera.com>
> Cc: Jonas Bonn <jonas@southpole.se>
> Cc: Stefan Kristiansson <stefan.kristiansson@saunalahti.fi>
> Cc: Stafford Horne <shorne@gmail.com>
> Cc: James E.J. Bottomley <jejb@parisc-linux.org>
> Cc: Helge Deller <deller@gmx.de>
> Cc: Albert Ou <aou@eecs.berkeley.edu>
> Cc: Martin Schwidefsky <schwidefsky@de.ibm.com>
> Cc: Heiko Carstens <heiko.carstens@de.ibm.com>
> Cc: Rich Felker <dalias@libc.org>
> Cc: David S. Miller <davem@davemloft.net>
> Cc: Guan Xuetao <gxt@pku.edu.cn>
> Cc: Jeff Dike <jdike@addtoit.com>
> Cc: Richard Weinberger <richard@nod.at>
> Cc: Chris Zankel <chris@zankel.net>
> Cc: Max Filippov <jcmvbkbc@gmail.com>
> Cc: Arnd Bergmann <arnd@arndb.de>
> Cc: Kees Cook <keescook@chromium.org>
> Cc: Will Drewry <wad@chromium.org>
> Cc: Oleg Nesterov <oleg@redhat.com>
> Cc: Elvira Khabirova <lineprinter@altlinux.org>
> Cc: Eugene Syromyatnikov <esyr@redhat.com>
> Cc: Ralf Baechle <ralf@linux-mips.org>
> Cc: James Hogan <jhogan@kernel.org>
> Cc: Benjamin Herrenschmidt <benh@kernel.crashing.org>
> Cc: Paul Mackerras <paulus@samba.org>
> Cc: Thomas Gleixner <tglx@linutronix.de>
> Cc: Ingo Molnar <mingo@redhat.com>
> Cc: Borislav Petkov <bp@alien8.de>
> Cc: H. Peter Anvin <hpa@zytor.com>
> Cc: x86@kernel.org
> Cc: linux-alpha@vger.kernel.org
> Cc: linux-snps-arc@lists.infradead.org
> Cc: linux-arm-kernel@lists.infradead.org
> Cc: linux-c6x-dev@linux-c6x.org
> Cc: uclinux-h8-devel@lists.sourceforge.jp
> Cc: linux-hexagon@vger.kernel.org
> Cc: linux-ia64@vger.kernel.org
> Cc: linux-m68k@lists.linux-m68k.org
> Cc: linux-mips@vger.kernel.org
> Cc: nios2-dev@lists.rocketboards.org
> Cc: openrisc@lists.librecores.org
> Cc: linux-parisc@vger.kernel.org
> Cc: linuxppc-dev@lists.ozlabs.org
> Cc: linux-riscv@lists.infradead.org
> Cc: linux-s390@vger.kernel.org
> Cc: linux-sh@vger.kernel.org
> Cc: sparclinux@vger.kernel.org
> Cc: linux-um@lists.infradead.org
> Cc: linux-xtensa@linux-xtensa.org
> Cc: linux-arch@vger.kernel.org
> Cc: linux-audit@redhat.com
> Signed-off-by: Dmitry V. Levin <ldv@altlinux.org>
> ---
> 
> 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 +-

For the c6x bit,
Acked-by: Mark Salter <msalter@redhat.com>



^ permalink raw reply	[flat|nested] 65+ messages in thread

* Re: [PATCH v5 13/25] m68k: add asm/syscall.h
  2018-12-10 13:30         ` Dmitry V. Levin
@ 2018-12-12  8:55           ` Dmitry V. Levin
  2018-12-12  9:01             ` Geert Uytterhoeven
  2019-03-29 22:04             ` Dmitry V. Levin
  0 siblings, 2 replies; 65+ messages in thread
From: Dmitry V. Levin @ 2018-12-12  8:55 UTC (permalink / raw)
  To: Geert Uytterhoeven
  Cc: Oleg Nesterov, Andy Lutomirski, lineprinter,
	Eugene Syromiatnikov, linux-m68k, Linux Kernel Mailing List

[-- Attachment #1: Type: text/plain, Size: 3680 bytes --]

On Mon, Dec 10, 2018 at 04:30:25PM +0300, Dmitry V. Levin wrote:
> On Mon, Dec 10, 2018 at 02:06:28PM +0100, Geert Uytterhoeven wrote:
> > On Mon, Dec 10, 2018 at 1:41 PM Dmitry V. Levin <ldv@altlinux.org> wrote:
> > > On Mon, Dec 10, 2018 at 09:45:42AM +0100, Geert Uytterhoeven wrote:
> > > > On Mon, Dec 10, 2018 at 5:30 AM Dmitry V. Levin <ldv@altlinux.org> wrote:
> > > > > syscall_get_* functions are required to be implemented on all
> > > > > architectures in order to extend the generic ptrace API with
> > > > > PTRACE_GET_SYSCALL_INFO request.
> > > > >
> > > > > This introduces asm/syscall.h on m68k implementing all 5 syscall_get_*
> > > > > functions as documented in asm-generic/syscall.h: syscall_get_nr,
> > > > > syscall_get_arguments, syscall_get_error, syscall_get_return_value,
> > > > > and syscall_get_arch.
> > > > >
> > > > > Cc: Geert Uytterhoeven <geert@linux-m68k.org>
> > > > > Cc: Oleg Nesterov <oleg@redhat.com>
> > > > > Cc: Andy Lutomirski <luto@kernel.org>
> > > > > Cc: Elvira Khabirova <lineprinter@altlinux.org>
> > > > > Cc: Eugene Syromyatnikov <esyr@redhat.com>
> > > > > Cc: linux-m68k@lists.linux-m68k.org
> > > > > Signed-off-by: Dmitry V. Levin <ldv@altlinux.org>
> > > > > ---
> > > > >
> > > > > Notes:
> > > > >     v5: added syscall_get_nr, syscall_get_arguments, syscall_get_error,
> > > > >         and syscall_get_return_value
> > > > >     v1: added syscall_get_arch
> > > >
> > > > > --- /dev/null
> > > > > +++ b/arch/m68k/include/asm/syscall.h
> > > > > @@ -0,0 +1,39 @@
> > > >
> > > > > +static inline void
> > > > > +syscall_get_arguments(struct task_struct *task, struct pt_regs *regs,
> > > > > +                     unsigned int i, unsigned int n, unsigned long *args)
> > > > > +{
> > > > > +       BUG_ON(i + n > 6);
> > > >
> > > > Does this have to crash the kernel?
> > >
> > > This is what most of other architectures do, but we could choose
> > > a softer approach, e.g. use WARN_ON_ONCE instead.
> > >
> > > > Perhaps you can return an error code instead?
> > >
> > > That would be problematic given the signature of this function
> > > and the nature of the potential bug which would most likely be a usage error.
> > 
> > Of course to handle that, the function's signature need to be changed.
> > Changing it has the advantage that the error handling can be done at the
> > caller, in common code, instead of duplicating it for all
> > architectures, possibly
> > leading to different semantics.
> 
> Given that *all* current users of syscall_get_arguments specify i == 0
> (and there is an architecture that has BUG_ON(i)), 
> it should be really a usage error to get into situation where i + n > 6,
> I wish a BUILD_BUG_ON could be used here instead.
> 
> I don't think it worths pushing the change of API just to convert
> a "cannot happen" assertion into an error that would have to be dealt with
> on the caller side.

I suggest the following BUG_ON replacement for syscall_get_arguments:

#define SYSCALL_MAX_ARGS 6

static inline void
syscall_get_arguments(struct task_struct *task, struct pt_regs *regs,
		      unsigned int i, unsigned int n, unsigned long *args)
{
	/*
	 * Ideally there should have been
	 * BUILD_BUG_ON(i + n > SYSCALL_MAX_ARGS);
	 * instead of these checks.
	 */
	if (unlikely(i > SYSCALL_MAX_ARGS)) {
		WARN_ONCE(1, "i > SYSCALL_MAX_ARGS");
		return;
	}
	if (unlikely(n > SYSCALL_MAX_ARGS - i)) {
		WARN_ONCE(1, "i + n > SYSCALL_MAX_ARGS");
		n = SYSCALL_MAX_ARGS - i;
	}
	BUILD_BUG_ON(sizeof(regs->d1) != sizeof(args[0]));
	memcpy(args, &regs->d1 + i, n * sizeof(args[0]));
}


-- 
ldv

[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 801 bytes --]

^ permalink raw reply	[flat|nested] 65+ messages in thread

* Re: [PATCH v5 13/25] m68k: add asm/syscall.h
  2018-12-12  8:55           ` Dmitry V. Levin
@ 2018-12-12  9:01             ` Geert Uytterhoeven
  2018-12-12  9:27               ` Dmitry V. Levin
  2019-03-29 22:04             ` Dmitry V. Levin
  1 sibling, 1 reply; 65+ messages in thread
From: Geert Uytterhoeven @ 2018-12-12  9:01 UTC (permalink / raw)
  To: Dmitry V. Levin
  Cc: Oleg Nesterov, Andy Lutomirski, lineprinter,
	Eugene Syromiatnikov, linux-m68k, Linux Kernel Mailing List

Hi Dmitry,

On Wed, Dec 12, 2018 at 9:55 AM Dmitry V. Levin <ldv@altlinux.org> wrote:
> On Mon, Dec 10, 2018 at 04:30:25PM +0300, Dmitry V. Levin wrote:
> > On Mon, Dec 10, 2018 at 02:06:28PM +0100, Geert Uytterhoeven wrote:
> > > On Mon, Dec 10, 2018 at 1:41 PM Dmitry V. Levin <ldv@altlinux.org> wrote:
> > > > On Mon, Dec 10, 2018 at 09:45:42AM +0100, Geert Uytterhoeven wrote:
> > > > > On Mon, Dec 10, 2018 at 5:30 AM Dmitry V. Levin <ldv@altlinux.org> wrote:
> > > > > > syscall_get_* functions are required to be implemented on all
> > > > > > architectures in order to extend the generic ptrace API with
> > > > > > PTRACE_GET_SYSCALL_INFO request.
> > > > > >
> > > > > > This introduces asm/syscall.h on m68k implementing all 5 syscall_get_*
> > > > > > functions as documented in asm-generic/syscall.h: syscall_get_nr,
> > > > > > syscall_get_arguments, syscall_get_error, syscall_get_return_value,
> > > > > > and syscall_get_arch.
> > > > > >
> > > > > > Cc: Geert Uytterhoeven <geert@linux-m68k.org>
> > > > > > Cc: Oleg Nesterov <oleg@redhat.com>
> > > > > > Cc: Andy Lutomirski <luto@kernel.org>
> > > > > > Cc: Elvira Khabirova <lineprinter@altlinux.org>
> > > > > > Cc: Eugene Syromyatnikov <esyr@redhat.com>
> > > > > > Cc: linux-m68k@lists.linux-m68k.org
> > > > > > Signed-off-by: Dmitry V. Levin <ldv@altlinux.org>
> > > > > > ---
> > > > > >
> > > > > > Notes:
> > > > > >     v5: added syscall_get_nr, syscall_get_arguments, syscall_get_error,
> > > > > >         and syscall_get_return_value
> > > > > >     v1: added syscall_get_arch
> > > > >
> > > > > > --- /dev/null
> > > > > > +++ b/arch/m68k/include/asm/syscall.h
> > > > > > @@ -0,0 +1,39 @@
> > > > >
> > > > > > +static inline void
> > > > > > +syscall_get_arguments(struct task_struct *task, struct pt_regs *regs,
> > > > > > +                     unsigned int i, unsigned int n, unsigned long *args)
> > > > > > +{
> > > > > > +       BUG_ON(i + n > 6);
> > > > >
> > > > > Does this have to crash the kernel?
> > > >
> > > > This is what most of other architectures do, but we could choose
> > > > a softer approach, e.g. use WARN_ON_ONCE instead.
> > > >
> > > > > Perhaps you can return an error code instead?
> > > >
> > > > That would be problematic given the signature of this function
> > > > and the nature of the potential bug which would most likely be a usage error.
> > >
> > > Of course to handle that, the function's signature need to be changed.
> > > Changing it has the advantage that the error handling can be done at the
> > > caller, in common code, instead of duplicating it for all
> > > architectures, possibly
> > > leading to different semantics.
> >
> > Given that *all* current users of syscall_get_arguments specify i == 0
> > (and there is an architecture that has BUG_ON(i)),
> > it should be really a usage error to get into situation where i + n > 6,
> > I wish a BUILD_BUG_ON could be used here instead.
> >
> > I don't think it worths pushing the change of API just to convert
> > a "cannot happen" assertion into an error that would have to be dealt with
> > on the caller side.
>
> I suggest the following BUG_ON replacement for syscall_get_arguments:
>
> #define SYSCALL_MAX_ARGS 6
>
> static inline void
> syscall_get_arguments(struct task_struct *task, struct pt_regs *regs,
>                       unsigned int i, unsigned int n, unsigned long *args)
> {
>         /*
>          * Ideally there should have been
>          * BUILD_BUG_ON(i + n > SYSCALL_MAX_ARGS);
>          * instead of these checks.
>          */
>         if (unlikely(i > SYSCALL_MAX_ARGS)) {
>                 WARN_ONCE(1, "i > SYSCALL_MAX_ARGS");
>                 return;

Does this have security implications, as args is an output parameter?
I.e. if you don't fill the array, the caller will use whatever is on the stack.
Can this ever be passed to userspace, leaking data?

>         }
>         if (unlikely(n > SYSCALL_MAX_ARGS - i)) {
>                 WARN_ONCE(1, "i + n > SYSCALL_MAX_ARGS");
>                 n = SYSCALL_MAX_ARGS - i;
>         }
>         BUILD_BUG_ON(sizeof(regs->d1) != sizeof(args[0]));
>         memcpy(args, &regs->d1 + i, n * sizeof(args[0]));
> }

Gr{oetje,eeting}s,

                        Geert

-- 
Geert Uytterhoeven -- There's lots of Linux beyond ia32 -- geert@linux-m68k.org

In personal conversations with technical people, I call myself a hacker. But
when I'm talking to journalists I just say "programmer" or something like that.
                                -- Linus Torvalds

^ permalink raw reply	[flat|nested] 65+ messages in thread

* Re: [PATCH v5 13/25] m68k: add asm/syscall.h
  2018-12-12  9:01             ` Geert Uytterhoeven
@ 2018-12-12  9:27               ` Dmitry V. Levin
  2018-12-12  9:43                 ` Geert Uytterhoeven
  0 siblings, 1 reply; 65+ messages in thread
From: Dmitry V. Levin @ 2018-12-12  9:27 UTC (permalink / raw)
  To: Geert Uytterhoeven
  Cc: Oleg Nesterov, Andy Lutomirski, lineprinter,
	Eugene Syromiatnikov, linux-m68k, Linux Kernel Mailing List

[-- Attachment #1: Type: text/plain, Size: 4837 bytes --]

On Wed, Dec 12, 2018 at 10:01:29AM +0100, Geert Uytterhoeven wrote:
> Hi Dmitry,
> 
> On Wed, Dec 12, 2018 at 9:55 AM Dmitry V. Levin <ldv@altlinux.org> wrote:
> > On Mon, Dec 10, 2018 at 04:30:25PM +0300, Dmitry V. Levin wrote:
> > > On Mon, Dec 10, 2018 at 02:06:28PM +0100, Geert Uytterhoeven wrote:
> > > > On Mon, Dec 10, 2018 at 1:41 PM Dmitry V. Levin <ldv@altlinux.org> wrote:
> > > > > On Mon, Dec 10, 2018 at 09:45:42AM +0100, Geert Uytterhoeven wrote:
> > > > > > On Mon, Dec 10, 2018 at 5:30 AM Dmitry V. Levin <ldv@altlinux.org> wrote:
> > > > > > > syscall_get_* functions are required to be implemented on all
> > > > > > > architectures in order to extend the generic ptrace API with
> > > > > > > PTRACE_GET_SYSCALL_INFO request.
> > > > > > >
> > > > > > > This introduces asm/syscall.h on m68k implementing all 5 syscall_get_*
> > > > > > > functions as documented in asm-generic/syscall.h: syscall_get_nr,
> > > > > > > syscall_get_arguments, syscall_get_error, syscall_get_return_value,
> > > > > > > and syscall_get_arch.
> > > > > > >
> > > > > > > Cc: Geert Uytterhoeven <geert@linux-m68k.org>
> > > > > > > Cc: Oleg Nesterov <oleg@redhat.com>
> > > > > > > Cc: Andy Lutomirski <luto@kernel.org>
> > > > > > > Cc: Elvira Khabirova <lineprinter@altlinux.org>
> > > > > > > Cc: Eugene Syromyatnikov <esyr@redhat.com>
> > > > > > > Cc: linux-m68k@lists.linux-m68k.org
> > > > > > > Signed-off-by: Dmitry V. Levin <ldv@altlinux.org>
> > > > > > > ---
> > > > > > >
> > > > > > > Notes:
> > > > > > >     v5: added syscall_get_nr, syscall_get_arguments, syscall_get_error,
> > > > > > >         and syscall_get_return_value
> > > > > > >     v1: added syscall_get_arch
> > > > > >
> > > > > > > --- /dev/null
> > > > > > > +++ b/arch/m68k/include/asm/syscall.h
> > > > > > > @@ -0,0 +1,39 @@
> > > > > >
> > > > > > > +static inline void
> > > > > > > +syscall_get_arguments(struct task_struct *task, struct pt_regs *regs,
> > > > > > > +                     unsigned int i, unsigned int n, unsigned long *args)
> > > > > > > +{
> > > > > > > +       BUG_ON(i + n > 6);
> > > > > >
> > > > > > Does this have to crash the kernel?
> > > > >
> > > > > This is what most of other architectures do, but we could choose
> > > > > a softer approach, e.g. use WARN_ON_ONCE instead.
> > > > >
> > > > > > Perhaps you can return an error code instead?
> > > > >
> > > > > That would be problematic given the signature of this function
> > > > > and the nature of the potential bug which would most likely be a usage error.
> > > >
> > > > Of course to handle that, the function's signature need to be changed.
> > > > Changing it has the advantage that the error handling can be done at the
> > > > caller, in common code, instead of duplicating it for all
> > > > architectures, possibly
> > > > leading to different semantics.
> > >
> > > Given that *all* current users of syscall_get_arguments specify i == 0
> > > (and there is an architecture that has BUG_ON(i)),
> > > it should be really a usage error to get into situation where i + n > 6,
> > > I wish a BUILD_BUG_ON could be used here instead.
> > >
> > > I don't think it worths pushing the change of API just to convert
> > > a "cannot happen" assertion into an error that would have to be dealt with
> > > on the caller side.
> >
> > I suggest the following BUG_ON replacement for syscall_get_arguments:
> >
> > #define SYSCALL_MAX_ARGS 6
> >
> > static inline void
> > syscall_get_arguments(struct task_struct *task, struct pt_regs *regs,
> >                       unsigned int i, unsigned int n, unsigned long *args)
> > {
> >         /*
> >          * Ideally there should have been
> >          * BUILD_BUG_ON(i + n > SYSCALL_MAX_ARGS);
> >          * instead of these checks.
> >          */
> >         if (unlikely(i > SYSCALL_MAX_ARGS)) {
> >                 WARN_ONCE(1, "i > SYSCALL_MAX_ARGS");
> >                 return;
> 
> Does this have security implications, as args is an output parameter?
> I.e. if you don't fill the array, the caller will use whatever is on the stack.
> Can this ever be passed to userspace, leaking data?

In the current kernel code n is always less or equal to 6,
but in theory future changes can potentially break the assertion
and this could lead to leaking data to userspace.

Do you think we should rather be defensive and add some memsets, e.g.

	if (unlikely(i > SYSCALL_MAX_ARGS)) {
		WARN_ONCE(1, "i > SYSCALL_MAX_ARGS");
		memset(args, 0, n * sizeof(args[0]));
		return;
	}
	if (unlikely(n > SYSCALL_MAX_ARGS - i)) {
		unsigned int extra = n - (SYSCALL_MAX_ARGS - i);

		WARN_ONCE(1, "i + n > SYSCALL_MAX_ARGS");
		n = SYSCALL_MAX_ARGS - i;
		memset(&args[n], 0, extra * sizeof(args[0]));
	}
?


-- 
ldv

[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 801 bytes --]

^ permalink raw reply	[flat|nested] 65+ messages in thread

* Re: [PATCH v5 24/25] ptrace: add PTRACE_GET_SYSCALL_INFO request
  2018-12-10  4:31 ` [PATCH v5 24/25] ptrace: add PTRACE_GET_SYSCALL_INFO request Dmitry V. Levin
                     ` (2 preceding siblings ...)
  2018-12-10 17:44   ` Kees Cook
@ 2018-12-12  9:28   ` kbuild test robot
  3 siblings, 0 replies; 65+ messages in thread
From: kbuild test robot @ 2018-12-12  9:28 UTC (permalink / raw)
  To: Dmitry V. Levin
  Cc: kbuild-all, Oleg Nesterov, Andy Lutomirski, Elvira Khabirova,
	Eugene Syromyatnikov, Kees Cook, Jann Horn, linux-api,
	strace-devel, linux-kernel

[-- Attachment #1: Type: text/plain, Size: 2996 bytes --]

Hi Elvira,

Thank you for the patch! Yet something to improve:

[auto build test ERROR on linus/master]
[also build test ERROR on v4.20-rc6]
[cannot apply to next-20181211]
[if your patch is applied to the wrong git tree, please drop us a note to help improve the system]

url:    https://github.com/0day-ci/linux/commits/Dmitry-V-Levin/ptrace-add-PTRACE_GET_SYSCALL_INFO-request/20181210-174745
config: nds32-allmodconfig (attached as .config)
compiler: nds32le-linux-gcc (GCC) 6.4.0
reproduce:
        wget https://raw.githubusercontent.com/intel/lkp-tests/master/sbin/make.cross -O ~/bin/make.cross
        chmod +x ~/bin/make.cross
        # save the attached .config to linux build tree
        GCC_VERSION=6.4.0 make.cross ARCH=nds32 

All errors (new ones prefixed by >>):

   kernel/ptrace.c: In function 'ptrace_get_syscall_info':
>> kernel/ptrace.c:942:20: error: implicit declaration of function 'frame_pointer' [-Werror=implicit-function-declaration]
      .frame_pointer = frame_pointer(regs)
                       ^~~~~~~~~~~~~
   cc1: some warnings being treated as errors

vim +/frame_pointer +942 kernel/ptrace.c

   931	
   932	static int
   933	ptrace_get_syscall_info(struct task_struct *child, unsigned long user_size,
   934				void __user *datavp)
   935	{
   936		struct pt_regs *regs = task_pt_regs(child);
   937		struct ptrace_syscall_info info = {
   938			.op = PTRACE_SYSCALL_INFO_NONE,
   939			.arch = syscall_get_arch(child),
   940			.instruction_pointer = instruction_pointer(regs),
   941			.stack_pointer = user_stack_pointer(regs),
 > 942			.frame_pointer = frame_pointer(regs)
   943		};
   944		unsigned long actual_size = offsetof(struct ptrace_syscall_info, entry);
   945		unsigned long write_size;
   946	
   947		/*
   948		 * This does not need lock_task_sighand() to access
   949		 * child->last_siginfo because ptrace_freeze_traced()
   950		 * called earlier by ptrace_check_attach() ensures that
   951		 * the tracee cannot go away and clear its last_siginfo.
   952		 */
   953		switch (child->last_siginfo ? child->last_siginfo->si_code : 0) {
   954		case SIGTRAP | 0x80:
   955			switch (child->ptrace_message) {
   956			case PTRACE_EVENTMSG_SYSCALL_ENTRY:
   957				actual_size = ptrace_get_syscall_info_entry(child, regs,
   958									    &info);
   959				break;
   960			case PTRACE_EVENTMSG_SYSCALL_EXIT:
   961				actual_size = ptrace_get_syscall_info_exit(child, regs,
   962									   &info);
   963				break;
   964			}
   965			break;
   966		case SIGTRAP | (PTRACE_EVENT_SECCOMP << 8):
   967			actual_size = ptrace_get_syscall_info_seccomp(child, regs,
   968								      &info);
   969			break;
   970		}
   971	
   972		write_size = min(actual_size, user_size);
   973		return copy_to_user(datavp, &info, write_size) ? -EFAULT : actual_size;
   974	}
   975	

---
0-DAY kernel test infrastructure                Open Source Technology Center
https://lists.01.org/pipermail/kbuild-all                   Intel Corporation

[-- Attachment #2: .config.gz --]
[-- Type: application/gzip, Size: 48501 bytes --]

^ permalink raw reply	[flat|nested] 65+ messages in thread

* Re: [PATCH v5 13/25] m68k: add asm/syscall.h
  2018-12-12  9:27               ` Dmitry V. Levin
@ 2018-12-12  9:43                 ` Geert Uytterhoeven
  2018-12-12 12:04                   ` Dmitry V. Levin
  0 siblings, 1 reply; 65+ messages in thread
From: Geert Uytterhoeven @ 2018-12-12  9:43 UTC (permalink / raw)
  To: Dmitry V. Levin
  Cc: Oleg Nesterov, Andy Lutomirski, lineprinter,
	Eugene Syromiatnikov, linux-m68k, Linux Kernel Mailing List

Hi Dmitry,

On Wed, Dec 12, 2018 at 10:27 AM Dmitry V. Levin <ldv@altlinux.org> wrote:
> On Wed, Dec 12, 2018 at 10:01:29AM +0100, Geert Uytterhoeven wrote:
> > On Wed, Dec 12, 2018 at 9:55 AM Dmitry V. Levin <ldv@altlinux.org> wrote:
> > > On Mon, Dec 10, 2018 at 04:30:25PM +0300, Dmitry V. Levin wrote:
> > > > On Mon, Dec 10, 2018 at 02:06:28PM +0100, Geert Uytterhoeven wrote:
> > > > > On Mon, Dec 10, 2018 at 1:41 PM Dmitry V. Levin <ldv@altlinux.org> wrote:
> > > > > > On Mon, Dec 10, 2018 at 09:45:42AM +0100, Geert Uytterhoeven wrote:
> > > > > > > On Mon, Dec 10, 2018 at 5:30 AM Dmitry V. Levin <ldv@altlinux.org> wrote:
> > > > > > > > syscall_get_* functions are required to be implemented on all
> > > > > > > > architectures in order to extend the generic ptrace API with
> > > > > > > > PTRACE_GET_SYSCALL_INFO request.
> > > > > > > >
> > > > > > > > This introduces asm/syscall.h on m68k implementing all 5 syscall_get_*
> > > > > > > > functions as documented in asm-generic/syscall.h: syscall_get_nr,
> > > > > > > > syscall_get_arguments, syscall_get_error, syscall_get_return_value,
> > > > > > > > and syscall_get_arch.
> > > > > > > >
> > > > > > > > Cc: Geert Uytterhoeven <geert@linux-m68k.org>
> > > > > > > > Cc: Oleg Nesterov <oleg@redhat.com>
> > > > > > > > Cc: Andy Lutomirski <luto@kernel.org>
> > > > > > > > Cc: Elvira Khabirova <lineprinter@altlinux.org>
> > > > > > > > Cc: Eugene Syromyatnikov <esyr@redhat.com>
> > > > > > > > Cc: linux-m68k@lists.linux-m68k.org
> > > > > > > > Signed-off-by: Dmitry V. Levin <ldv@altlinux.org>
> > > > > > > > ---
> > > > > > > >
> > > > > > > > Notes:
> > > > > > > >     v5: added syscall_get_nr, syscall_get_arguments, syscall_get_error,
> > > > > > > >         and syscall_get_return_value
> > > > > > > >     v1: added syscall_get_arch
> > > > > > >
> > > > > > > > --- /dev/null
> > > > > > > > +++ b/arch/m68k/include/asm/syscall.h
> > > > > > > > @@ -0,0 +1,39 @@
> > > > > > >
> > > > > > > > +static inline void
> > > > > > > > +syscall_get_arguments(struct task_struct *task, struct pt_regs *regs,
> > > > > > > > +                     unsigned int i, unsigned int n, unsigned long *args)
> > > > > > > > +{
> > > > > > > > +       BUG_ON(i + n > 6);
> > > > > > >
> > > > > > > Does this have to crash the kernel?
> > > > > >
> > > > > > This is what most of other architectures do, but we could choose
> > > > > > a softer approach, e.g. use WARN_ON_ONCE instead.
> > > > > >
> > > > > > > Perhaps you can return an error code instead?
> > > > > >
> > > > > > That would be problematic given the signature of this function
> > > > > > and the nature of the potential bug which would most likely be a usage error.
> > > > >
> > > > > Of course to handle that, the function's signature need to be changed.
> > > > > Changing it has the advantage that the error handling can be done at the
> > > > > caller, in common code, instead of duplicating it for all
> > > > > architectures, possibly
> > > > > leading to different semantics.
> > > >
> > > > Given that *all* current users of syscall_get_arguments specify i == 0
> > > > (and there is an architecture that has BUG_ON(i)),
> > > > it should be really a usage error to get into situation where i + n > 6,
> > > > I wish a BUILD_BUG_ON could be used here instead.
> > > >
> > > > I don't think it worths pushing the change of API just to convert
> > > > a "cannot happen" assertion into an error that would have to be dealt with
> > > > on the caller side.
> > >
> > > I suggest the following BUG_ON replacement for syscall_get_arguments:
> > >
> > > #define SYSCALL_MAX_ARGS 6
> > >
> > > static inline void
> > > syscall_get_arguments(struct task_struct *task, struct pt_regs *regs,
> > >                       unsigned int i, unsigned int n, unsigned long *args)
> > > {
> > >         /*
> > >          * Ideally there should have been
> > >          * BUILD_BUG_ON(i + n > SYSCALL_MAX_ARGS);
> > >          * instead of these checks.
> > >          */
> > >         if (unlikely(i > SYSCALL_MAX_ARGS)) {
> > >                 WARN_ONCE(1, "i > SYSCALL_MAX_ARGS");
> > >                 return;
> >
> > Does this have security implications, as args is an output parameter?
> > I.e. if you don't fill the array, the caller will use whatever is on the stack.
> > Can this ever be passed to userspace, leaking data?
>
> In the current kernel code n is always less or equal to 6,
> but in theory future changes can potentially break the assertion
> and this could lead to leaking data to userspace.

OK.

> Do you think we should rather be defensive and add some memsets, e.g.
>
>         if (unlikely(i > SYSCALL_MAX_ARGS)) {
>                 WARN_ONCE(1, "i > SYSCALL_MAX_ARGS");
>                 memset(args, 0, n * sizeof(args[0]));
>                 return;
>         }
>         if (unlikely(n > SYSCALL_MAX_ARGS - i)) {
>                 unsigned int extra = n - (SYSCALL_MAX_ARGS - i);
>
>                 WARN_ONCE(1, "i + n > SYSCALL_MAX_ARGS");
>                 n = SYSCALL_MAX_ARGS - i;
>                 memset(&args[n], 0, extra * sizeof(args[0]));
>         }
> ?

Yes please.

But please handle all of that in the generic code, so it doesn't have to be
replicated across all architectures.

E.g. make syscall_get_arguments() a wrapper in generic code, calling
__syscall_get_arguments() in architecture-specific code.

And make the latter return int, so it can indicate other failures.

Gr{oetje,eeting}s,

                        Geert

-- 
Geert Uytterhoeven -- There's lots of Linux beyond ia32 -- geert@linux-m68k.org

In personal conversations with technical people, I call myself a hacker. But
when I'm talking to journalists I just say "programmer" or something like that.
                                -- Linus Torvalds

^ permalink raw reply	[flat|nested] 65+ messages in thread

* Re: [PATCH v5 19/25] xtensa: define syscall_get_* functions
  2018-12-10  4:30 ` [PATCH v5 19/25] xtensa: define syscall_get_* functions Dmitry V. Levin
  2018-12-10  5:02   ` Max Filippov
@ 2018-12-12 10:45   ` kbuild test robot
  2018-12-19  5:58   ` kbuild test robot
  2 siblings, 0 replies; 65+ messages in thread
From: kbuild test robot @ 2018-12-12 10:45 UTC (permalink / raw)
  To: Dmitry V. Levin
  Cc: kbuild-all, Max Filippov, Oleg Nesterov, Andy Lutomirski,
	Elvira Khabirova, Eugene Syromyatnikov, Chris Zankel, Paul Moore,
	Eric Paris, linux-xtensa, linux-audit, linux-kernel

[-- Attachment #1: Type: text/plain, Size: 8711 bytes --]

Hi Dmitry,

Thank you for the patch! Yet something to improve:

[auto build test ERROR on linus/master]
[also build test ERROR on v4.20-rc6]
[cannot apply to next-20181211]
[if your patch is applied to the wrong git tree, please drop us a note to help improve the system]

url:    https://github.com/0day-ci/linux/commits/Dmitry-V-Levin/ptrace-add-PTRACE_GET_SYSCALL_INFO-request/20181210-174745
config: xtensa-allmodconfig (attached as .config)
compiler: xtensa-linux-gcc (GCC) 8.1.0
reproduce:
        wget https://raw.githubusercontent.com/intel/lkp-tests/master/sbin/make.cross -O ~/bin/make.cross
        chmod +x ~/bin/make.cross
        # save the attached .config to linux build tree
        GCC_VERSION=8.1.0 make.cross ARCH=xtensa 

All error/warnings (new ones prefixed by >>):

   In file included from arch/xtensa/kernel/syscall.c:19:
   arch/xtensa/include/asm/syscall.h: In function 'syscall_get_error':
   arch/xtensa/include/asm/syscall.h:66:9: error: implicit declaration of function 'IS_ERR_VALUE'; did you mean 'USER_PS_VALUE'? [-Werror=implicit-function-declaration]
     return IS_ERR_VALUE(regs->areg[2]) ? regs->areg[2] : 0;
            ^~~~~~~~~~~~
            USER_PS_VALUE
>> arch/xtensa/include/asm/syscall.h:69:1: error: invalid storage class for function 'syscall_get_return_value'
    syscall_get_return_value(struct task_struct *task, struct pt_regs *regs)
    ^~~~~~~~~~~~~~~~~~~~~~~~
>> arch/xtensa/include/asm/syscall.h:68:1: warning: ISO C90 forbids mixed declarations and code [-Wdeclaration-after-statement]
    static inline long
    ^~~~~~
>> arch/xtensa/include/asm/syscall.h:75:1: error: invalid storage class for function 'syscall_get_arch'
    syscall_get_arch(void)
    ^~~~~~~~~~~~~~~~
   In file included from include/linux/wait_bit.h:8,
                    from include/linux/fs.h:6,
                    from include/uapi/linux/aio_abi.h:31,
                    from include/linux/syscalls.h:74,
                    from arch/xtensa/kernel/syscall.c:24:
   include/linux/wait.h:31:19: error: field 'entry' has incomplete type
     struct list_head entry;
                      ^~~~~
   include/linux/wait.h:36:19: error: field 'head' has incomplete type
     struct list_head head;
                      ^~~~
   include/linux/wait.h:79:20: error: invalid storage class for function 'init_waitqueue_entry'
    static inline void init_waitqueue_entry(struct wait_queue_entry *wq_entry, struct task_struct *p)
                       ^~~~~~~~~~~~~~~~~~~~
   include/linux/wait.h:87:1: error: invalid storage class for function 'init_waitqueue_func_entry'
    init_waitqueue_func_entry(struct wait_queue_entry *wq_entry, wait_queue_func_t func)
    ^~~~~~~~~~~~~~~~~~~~~~~~~
   include/linux/wait.h:124:19: error: invalid storage class for function 'waitqueue_active'
    static inline int waitqueue_active(struct wait_queue_head *wq_head)
                      ^~~~~~~~~~~~~~~~
   include/linux/wait.h:137:20: error: invalid storage class for function 'wq_has_sleeper'
    static inline bool wq_has_sleeper(struct wait_queue_head *wq_head)
                       ^~~~~~~~~~~~~~
   include/linux/wait.h:154:20: error: invalid storage class for function '__add_wait_queue'
    static inline void __add_wait_queue(struct wait_queue_head *wq_head, struct wait_queue_entry *wq_entry)
                       ^~~~~~~~~~~~~~~~
   include/linux/wait.h:163:1: error: invalid storage class for function '__add_wait_queue_exclusive'
    __add_wait_queue_exclusive(struct wait_queue_head *wq_head, struct wait_queue_entry *wq_entry)
    ^~~~~~~~~~~~~~~~~~~~~~~~~~
   include/linux/wait.h:169:20: error: invalid storage class for function '__add_wait_queue_entry_tail'
    static inline void __add_wait_queue_entry_tail(struct wait_queue_head *wq_head, struct wait_queue_entry *wq_entry)
                       ^~~~~~~~~~~~~~~~~~~~~~~~~~~
   include/linux/wait.h:175:1: error: invalid storage class for function '__add_wait_queue_entry_tail_exclusive'
    __add_wait_queue_entry_tail_exclusive(struct wait_queue_head *wq_head, struct wait_queue_entry *wq_entry)
    ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
   include/linux/wait.h:182:1: error: invalid storage class for function '__remove_wait_queue'
    __remove_wait_queue(struct wait_queue_head *wq_head, struct wait_queue_entry *wq_entry)
    ^~~~~~~~~~~~~~~~~~~
   In file included from include/linux/fs.h:6,
                    from include/uapi/linux/aio_abi.h:31,
                    from include/linux/syscalls.h:74,
                    from arch/xtensa/kernel/syscall.c:24:
   include/linux/wait_bit.h:71:1: error: invalid storage class for function 'wait_on_bit'
    wait_on_bit(unsigned long *word, int bit, unsigned mode)
    ^~~~~~~~~~~
   include/linux/wait_bit.h:96:1: error: invalid storage class for function 'wait_on_bit_io'
    wait_on_bit_io(unsigned long *word, int bit, unsigned mode)
    ^~~~~~~~~~~~~~
   include/linux/wait_bit.h:122:1: error: invalid storage class for function 'wait_on_bit_timeout'
    wait_on_bit_timeout(unsigned long *word, int bit, unsigned mode,
    ^~~~~~~~~~~~~~~~~~~
   include/linux/wait_bit.h:150:1: error: invalid storage class for function 'wait_on_bit_action'
    wait_on_bit_action(unsigned long *word, int bit, wait_bit_action_f *action,
    ^~~~~~~~~~~~~~~~~~
   include/linux/wait_bit.h:179:1: error: invalid storage class for function 'wait_on_bit_lock'
    wait_on_bit_lock(unsigned long *word, int bit, unsigned mode)
    ^~~~~~~~~~~~~~~~
   include/linux/wait_bit.h:203:1: error: invalid storage class for function 'wait_on_bit_lock_io'
    wait_on_bit_lock_io(unsigned long *word, int bit, unsigned mode)
    ^~~~~~~~~~~~~~~~~~~
   include/linux/wait_bit.h:229:1: error: invalid storage class for function 'wait_on_bit_lock_action'
    wait_on_bit_lock_action(unsigned long *word, int bit, wait_bit_action_f *action,
    ^~~~~~~~~~~~~~~~~~~~~~~
   include/linux/wait_bit.h:317:20: error: invalid storage class for function 'clear_and_wake_up_bit'
    static inline void clear_and_wake_up_bit(int bit, void *word)
                       ^~~~~~~~~~~~~~~~~~~~~
   In file included from include/linux/fs.h:7,
                    from include/uapi/linux/aio_abi.h:31,
                    from include/linux/syscalls.h:74,
                    from arch/xtensa/kernel/syscall.c:24:
   include/linux/kdev_t.h:24:20: error: invalid storage class for function 'old_valid_dev'
    static inline bool old_valid_dev(dev_t dev)
                       ^~~~~~~~~~~~~
   include/linux/kdev_t.h:29:19: error: invalid storage class for function 'old_encode_dev'
    static inline u16 old_encode_dev(dev_t dev)
                      ^~~~~~~~~~~~~~
   include/linux/kdev_t.h:34:21: error: invalid storage class for function 'old_decode_dev'
    static inline dev_t old_decode_dev(u16 val)
                        ^~~~~~~~~~~~~~
   include/linux/kdev_t.h:39:19: error: invalid storage class for function 'new_encode_dev'
    static inline u32 new_encode_dev(dev_t dev)
                      ^~~~~~~~~~~~~~
   include/linux/kdev_t.h:46:21: error: invalid storage class for function 'new_decode_dev'
    static inline dev_t new_decode_dev(u32 dev)
                        ^~~~~~~~~~~~~~
   include/linux/kdev_t.h:53:19: error: invalid storage class for function 'huge_encode_dev'
    static inline u64 huge_encode_dev(dev_t dev)
                      ^~~~~~~~~~~~~~~
   include/linux/kdev_t.h:58:21: error: invalid storage class for function 'huge_decode_dev'
    static inline dev_t huge_decode_dev(u64 dev)
                        ^~~~~~~~~~~~~~~
   include/linux/kdev_t.h:63:19: error: invalid storage class for function 'sysv_valid_dev'
    static inline int sysv_valid_dev(dev_t dev)
                      ^~~~~~~~~~~~~~
   include/linux/kdev_t.h:68:19: error: invalid storage class for function 'sysv_encode_dev'
    static inline u32 sysv_encode_dev(dev_t dev)
                      ^~~~~~~~~~~~~~~
   include/linux/kdev_t.h:73:24: error: invalid storage class for function 'sysv_major'

vim +/syscall_get_return_value +69 arch/xtensa/include/asm/syscall.h

    62	
    63	static inline long
    64	syscall_get_error(struct task_struct *task, struct pt_regs *regs)
    65	{
  > 66		return IS_ERR_VALUE(regs->areg[2]) ? regs->areg[2] : 0;
    67	
  > 68	static inline long
  > 69	syscall_get_return_value(struct task_struct *task, struct pt_regs *regs)
    70	{
    71		return regs->areg[2];
    72	}
    73	
    74	static inline int
  > 75	syscall_get_arch(void)
    76	{
    77		return AUDIT_ARCH_XTENSA;
    78	}
    79	

---
0-DAY kernel test infrastructure                Open Source Technology Center
https://lists.01.org/pipermail/kbuild-all                   Intel Corporation

[-- Attachment #2: .config.gz --]
[-- Type: application/gzip, Size: 55662 bytes --]

^ permalink raw reply	[flat|nested] 65+ messages in thread

* Re: [PATCH v5 13/25] m68k: add asm/syscall.h
  2018-12-12  9:43                 ` Geert Uytterhoeven
@ 2018-12-12 12:04                   ` Dmitry V. Levin
  2018-12-12 12:27                     ` Geert Uytterhoeven
  0 siblings, 1 reply; 65+ messages in thread
From: Dmitry V. Levin @ 2018-12-12 12:04 UTC (permalink / raw)
  To: Geert Uytterhoeven
  Cc: Oleg Nesterov, Andy Lutomirski, lineprinter,
	Eugene Syromiatnikov, linux-m68k, Linux Kernel Mailing List

[-- Attachment #1: Type: text/plain, Size: 6427 bytes --]

Hi Geert,

On Wed, Dec 12, 2018 at 10:43:33AM +0100, Geert Uytterhoeven wrote:
> On Wed, Dec 12, 2018 at 10:27 AM Dmitry V. Levin <ldv@altlinux.org> wrote:
> > On Wed, Dec 12, 2018 at 10:01:29AM +0100, Geert Uytterhoeven wrote:
> > > On Wed, Dec 12, 2018 at 9:55 AM Dmitry V. Levin <ldv@altlinux.org> wrote:
> > > > On Mon, Dec 10, 2018 at 04:30:25PM +0300, Dmitry V. Levin wrote:
> > > > > On Mon, Dec 10, 2018 at 02:06:28PM +0100, Geert Uytterhoeven wrote:
> > > > > > On Mon, Dec 10, 2018 at 1:41 PM Dmitry V. Levin <ldv@altlinux.org> wrote:
> > > > > > > On Mon, Dec 10, 2018 at 09:45:42AM +0100, Geert Uytterhoeven wrote:
> > > > > > > > On Mon, Dec 10, 2018 at 5:30 AM Dmitry V. Levin <ldv@altlinux.org> wrote:
> > > > > > > > > syscall_get_* functions are required to be implemented on all
> > > > > > > > > architectures in order to extend the generic ptrace API with
> > > > > > > > > PTRACE_GET_SYSCALL_INFO request.
> > > > > > > > >
> > > > > > > > > This introduces asm/syscall.h on m68k implementing all 5 syscall_get_*
> > > > > > > > > functions as documented in asm-generic/syscall.h: syscall_get_nr,
> > > > > > > > > syscall_get_arguments, syscall_get_error, syscall_get_return_value,
> > > > > > > > > and syscall_get_arch.
> > > > > > > > >
> > > > > > > > > Cc: Geert Uytterhoeven <geert@linux-m68k.org>
> > > > > > > > > Cc: Oleg Nesterov <oleg@redhat.com>
> > > > > > > > > Cc: Andy Lutomirski <luto@kernel.org>
> > > > > > > > > Cc: Elvira Khabirova <lineprinter@altlinux.org>
> > > > > > > > > Cc: Eugene Syromyatnikov <esyr@redhat.com>
> > > > > > > > > Cc: linux-m68k@lists.linux-m68k.org
> > > > > > > > > Signed-off-by: Dmitry V. Levin <ldv@altlinux.org>
> > > > > > > > > ---
> > > > > > > > >
> > > > > > > > > Notes:
> > > > > > > > >     v5: added syscall_get_nr, syscall_get_arguments, syscall_get_error,
> > > > > > > > >         and syscall_get_return_value
> > > > > > > > >     v1: added syscall_get_arch
> > > > > > > >
> > > > > > > > > --- /dev/null
> > > > > > > > > +++ b/arch/m68k/include/asm/syscall.h
> > > > > > > > > @@ -0,0 +1,39 @@
> > > > > > > >
> > > > > > > > > +static inline void
> > > > > > > > > +syscall_get_arguments(struct task_struct *task, struct pt_regs *regs,
> > > > > > > > > +                     unsigned int i, unsigned int n, unsigned long *args)
> > > > > > > > > +{
> > > > > > > > > +       BUG_ON(i + n > 6);
> > > > > > > >
> > > > > > > > Does this have to crash the kernel?
> > > > > > >
> > > > > > > This is what most of other architectures do, but we could choose
> > > > > > > a softer approach, e.g. use WARN_ON_ONCE instead.
> > > > > > >
> > > > > > > > Perhaps you can return an error code instead?
> > > > > > >
> > > > > > > That would be problematic given the signature of this function
> > > > > > > and the nature of the potential bug which would most likely be a usage error.
> > > > > >
> > > > > > Of course to handle that, the function's signature need to be changed.
> > > > > > Changing it has the advantage that the error handling can be done at the
> > > > > > caller, in common code, instead of duplicating it for all
> > > > > > architectures, possibly
> > > > > > leading to different semantics.
> > > > >
> > > > > Given that *all* current users of syscall_get_arguments specify i == 0
> > > > > (and there is an architecture that has BUG_ON(i)),
> > > > > it should be really a usage error to get into situation where i + n > 6,
> > > > > I wish a BUILD_BUG_ON could be used here instead.
> > > > >
> > > > > I don't think it worths pushing the change of API just to convert
> > > > > a "cannot happen" assertion into an error that would have to be dealt with
> > > > > on the caller side.
> > > >
> > > > I suggest the following BUG_ON replacement for syscall_get_arguments:
> > > >
> > > > #define SYSCALL_MAX_ARGS 6
> > > >
> > > > static inline void
> > > > syscall_get_arguments(struct task_struct *task, struct pt_regs *regs,
> > > >                       unsigned int i, unsigned int n, unsigned long *args)
> > > > {
> > > >         /*
> > > >          * Ideally there should have been
> > > >          * BUILD_BUG_ON(i + n > SYSCALL_MAX_ARGS);
> > > >          * instead of these checks.
> > > >          */
> > > >         if (unlikely(i > SYSCALL_MAX_ARGS)) {
> > > >                 WARN_ONCE(1, "i > SYSCALL_MAX_ARGS");
> > > >                 return;
> > >
> > > Does this have security implications, as args is an output parameter?
> > > I.e. if you don't fill the array, the caller will use whatever is on the stack.
> > > Can this ever be passed to userspace, leaking data?
> >
> > In the current kernel code n is always less or equal to 6,
> > but in theory future changes can potentially break the assertion
> > and this could lead to leaking data to userspace.
> 
> OK.
> 
> > Do you think we should rather be defensive and add some memsets, e.g.
> >
> >         if (unlikely(i > SYSCALL_MAX_ARGS)) {
> >                 WARN_ONCE(1, "i > SYSCALL_MAX_ARGS");
> >                 memset(args, 0, n * sizeof(args[0]));
> >                 return;
> >         }
> >         if (unlikely(n > SYSCALL_MAX_ARGS - i)) {
> >                 unsigned int extra = n - (SYSCALL_MAX_ARGS - i);
> >
> >                 WARN_ONCE(1, "i + n > SYSCALL_MAX_ARGS");
> >                 n = SYSCALL_MAX_ARGS - i;
> >                 memset(&args[n], 0, extra * sizeof(args[0]));
> >         }
> > ?
> 
> Yes please.
> 
> But please handle all of that in the generic code, so it doesn't have to be
> replicated across all architectures.
> 
> E.g. make syscall_get_arguments() a wrapper in generic code, calling
> __syscall_get_arguments() in architecture-specific code.
> 
> And make the latter return int, so it can indicate other failures.

Other failures?  What syscall_get_arguments is expected to do
if __syscall_get_arguments returned, say, -1?

Anyway, as asm-generic/syscall.h is used for documentation purposes only,
I can try to prepare it for inclusion in other files without risk of
starting a big refactoring that would affect all architectures -- a thing
I'd rather not include into this series which is all about adding
PTRACE_GET_SYSCALL_INFO API.

I suppose there is no rush and arch-specific asm/syscall.h can switch
to use asm-generic/syscall.h gradually.


-- 
ldv

[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 801 bytes --]

^ permalink raw reply	[flat|nested] 65+ messages in thread

* Re: [PATCH v5 13/25] m68k: add asm/syscall.h
  2018-12-12 12:04                   ` Dmitry V. Levin
@ 2018-12-12 12:27                     ` Geert Uytterhoeven
  2018-12-12 12:37                       ` Dmitry V. Levin
  0 siblings, 1 reply; 65+ messages in thread
From: Geert Uytterhoeven @ 2018-12-12 12:27 UTC (permalink / raw)
  To: Dmitry V. Levin
  Cc: Oleg Nesterov, Andy Lutomirski, lineprinter,
	Eugene Syromiatnikov, linux-m68k, Linux Kernel Mailing List

Hi Dmitry,

On Wed, Dec 12, 2018 at 1:04 PM Dmitry V. Levin <ldv@altlinux.org> wrote:
> On Wed, Dec 12, 2018 at 10:43:33AM +0100, Geert Uytterhoeven wrote:
> > On Wed, Dec 12, 2018 at 10:27 AM Dmitry V. Levin <ldv@altlinux.org> wrote:
> > > On Wed, Dec 12, 2018 at 10:01:29AM +0100, Geert Uytterhoeven wrote:
> > > > On Wed, Dec 12, 2018 at 9:55 AM Dmitry V. Levin <ldv@altlinux.org> wrote:
> > > > > On Mon, Dec 10, 2018 at 04:30:25PM +0300, Dmitry V. Levin wrote:
> > > > > > On Mon, Dec 10, 2018 at 02:06:28PM +0100, Geert Uytterhoeven wrote:
> > > > > > > On Mon, Dec 10, 2018 at 1:41 PM Dmitry V. Levin <ldv@altlinux.org> wrote:
> > > > > > > > On Mon, Dec 10, 2018 at 09:45:42AM +0100, Geert Uytterhoeven wrote:
> > > > > > > > > On Mon, Dec 10, 2018 at 5:30 AM Dmitry V. Levin <ldv@altlinux.org> wrote:
> > > > > > > > > > syscall_get_* functions are required to be implemented on all
> > > > > > > > > > architectures in order to extend the generic ptrace API with
> > > > > > > > > > PTRACE_GET_SYSCALL_INFO request.
> > > > > > > > > >
> > > > > > > > > > This introduces asm/syscall.h on m68k implementing all 5 syscall_get_*
> > > > > > > > > > functions as documented in asm-generic/syscall.h: syscall_get_nr,
> > > > > > > > > > syscall_get_arguments, syscall_get_error, syscall_get_return_value,
> > > > > > > > > > and syscall_get_arch.
> > > > > > > > > >
> > > > > > > > > > Cc: Geert Uytterhoeven <geert@linux-m68k.org>
> > > > > > > > > > Cc: Oleg Nesterov <oleg@redhat.com>
> > > > > > > > > > Cc: Andy Lutomirski <luto@kernel.org>
> > > > > > > > > > Cc: Elvira Khabirova <lineprinter@altlinux.org>
> > > > > > > > > > Cc: Eugene Syromyatnikov <esyr@redhat.com>
> > > > > > > > > > Cc: linux-m68k@lists.linux-m68k.org
> > > > > > > > > > Signed-off-by: Dmitry V. Levin <ldv@altlinux.org>
> > > > > > > > > > ---
> > > > > > > > > >
> > > > > > > > > > Notes:
> > > > > > > > > >     v5: added syscall_get_nr, syscall_get_arguments, syscall_get_error,
> > > > > > > > > >         and syscall_get_return_value
> > > > > > > > > >     v1: added syscall_get_arch
> > > > > > > > >
> > > > > > > > > > --- /dev/null
> > > > > > > > > > +++ b/arch/m68k/include/asm/syscall.h
> > > > > > > > > > @@ -0,0 +1,39 @@
> > > > > > > > >
> > > > > > > > > > +static inline void
> > > > > > > > > > +syscall_get_arguments(struct task_struct *task, struct pt_regs *regs,
> > > > > > > > > > +                     unsigned int i, unsigned int n, unsigned long *args)
> > > > > > > > > > +{
> > > > > > > > > > +       BUG_ON(i + n > 6);
> > > > > > > > >
> > > > > > > > > Does this have to crash the kernel?
> > > > > > > >
> > > > > > > > This is what most of other architectures do, but we could choose
> > > > > > > > a softer approach, e.g. use WARN_ON_ONCE instead.
> > > > > > > >
> > > > > > > > > Perhaps you can return an error code instead?
> > > > > > > >
> > > > > > > > That would be problematic given the signature of this function
> > > > > > > > and the nature of the potential bug which would most likely be a usage error.
> > > > > > >
> > > > > > > Of course to handle that, the function's signature need to be changed.
> > > > > > > Changing it has the advantage that the error handling can be done at the
> > > > > > > caller, in common code, instead of duplicating it for all
> > > > > > > architectures, possibly
> > > > > > > leading to different semantics.
> > > > > >
> > > > > > Given that *all* current users of syscall_get_arguments specify i == 0
> > > > > > (and there is an architecture that has BUG_ON(i)),
> > > > > > it should be really a usage error to get into situation where i + n > 6,
> > > > > > I wish a BUILD_BUG_ON could be used here instead.
> > > > > >
> > > > > > I don't think it worths pushing the change of API just to convert
> > > > > > a "cannot happen" assertion into an error that would have to be dealt with
> > > > > > on the caller side.
> > > > >
> > > > > I suggest the following BUG_ON replacement for syscall_get_arguments:
> > > > >
> > > > > #define SYSCALL_MAX_ARGS 6
> > > > >
> > > > > static inline void
> > > > > syscall_get_arguments(struct task_struct *task, struct pt_regs *regs,
> > > > >                       unsigned int i, unsigned int n, unsigned long *args)
> > > > > {
> > > > >         /*
> > > > >          * Ideally there should have been
> > > > >          * BUILD_BUG_ON(i + n > SYSCALL_MAX_ARGS);
> > > > >          * instead of these checks.
> > > > >          */
> > > > >         if (unlikely(i > SYSCALL_MAX_ARGS)) {
> > > > >                 WARN_ONCE(1, "i > SYSCALL_MAX_ARGS");
> > > > >                 return;
> > > >
> > > > Does this have security implications, as args is an output parameter?
> > > > I.e. if you don't fill the array, the caller will use whatever is on the stack.
> > > > Can this ever be passed to userspace, leaking data?
> > >
> > > In the current kernel code n is always less or equal to 6,
> > > but in theory future changes can potentially break the assertion
> > > and this could lead to leaking data to userspace.
> >
> > OK.
> >
> > > Do you think we should rather be defensive and add some memsets, e.g.
> > >
> > >         if (unlikely(i > SYSCALL_MAX_ARGS)) {
> > >                 WARN_ONCE(1, "i > SYSCALL_MAX_ARGS");
> > >                 memset(args, 0, n * sizeof(args[0]));
> > >                 return;
> > >         }
> > >         if (unlikely(n > SYSCALL_MAX_ARGS - i)) {
> > >                 unsigned int extra = n - (SYSCALL_MAX_ARGS - i);
> > >
> > >                 WARN_ONCE(1, "i + n > SYSCALL_MAX_ARGS");
> > >                 n = SYSCALL_MAX_ARGS - i;
> > >                 memset(&args[n], 0, extra * sizeof(args[0]));
> > >         }
> > > ?
> >
> > Yes please.
> >
> > But please handle all of that in the generic code, so it doesn't have to be
> > replicated across all architectures.
> >
> > E.g. make syscall_get_arguments() a wrapper in generic code, calling
> > __syscall_get_arguments() in architecture-specific code.
> >
> > And make the latter return int, so it can indicate other failures.
>
> Other failures?  What syscall_get_arguments is expected to do
> if __syscall_get_arguments returned, say, -1?

Fail. Just like in case of other generic ill conditions it can detect itself.

Gr{oetje,eeting}s,

                        Geert

-- 
Geert Uytterhoeven -- There's lots of Linux beyond ia32 -- geert@linux-m68k.org

In personal conversations with technical people, I call myself a hacker. But
when I'm talking to journalists I just say "programmer" or something like that.
                                -- Linus Torvalds

^ permalink raw reply	[flat|nested] 65+ messages in thread

* Re: [PATCH v5 13/25] m68k: add asm/syscall.h
  2018-12-12 12:27                     ` Geert Uytterhoeven
@ 2018-12-12 12:37                       ` Dmitry V. Levin
  2018-12-12 12:54                         ` Geert Uytterhoeven
  0 siblings, 1 reply; 65+ messages in thread
From: Dmitry V. Levin @ 2018-12-12 12:37 UTC (permalink / raw)
  To: Geert Uytterhoeven
  Cc: Oleg Nesterov, Andy Lutomirski, lineprinter,
	Eugene Syromiatnikov, linux-m68k, Linux Kernel Mailing List

[-- Attachment #1: Type: text/plain, Size: 7030 bytes --]

Hi Geert,

On Wed, Dec 12, 2018 at 01:27:14PM +0100, Geert Uytterhoeven wrote:
> On Wed, Dec 12, 2018 at 1:04 PM Dmitry V. Levin <ldv@altlinux.org> wrote:
> > On Wed, Dec 12, 2018 at 10:43:33AM +0100, Geert Uytterhoeven wrote:
> > > On Wed, Dec 12, 2018 at 10:27 AM Dmitry V. Levin <ldv@altlinux.org> wrote:
> > > > On Wed, Dec 12, 2018 at 10:01:29AM +0100, Geert Uytterhoeven wrote:
> > > > > On Wed, Dec 12, 2018 at 9:55 AM Dmitry V. Levin <ldv@altlinux.org> wrote:
> > > > > > On Mon, Dec 10, 2018 at 04:30:25PM +0300, Dmitry V. Levin wrote:
> > > > > > > On Mon, Dec 10, 2018 at 02:06:28PM +0100, Geert Uytterhoeven wrote:
> > > > > > > > On Mon, Dec 10, 2018 at 1:41 PM Dmitry V. Levin <ldv@altlinux.org> wrote:
> > > > > > > > > On Mon, Dec 10, 2018 at 09:45:42AM +0100, Geert Uytterhoeven wrote:
> > > > > > > > > > On Mon, Dec 10, 2018 at 5:30 AM Dmitry V. Levin <ldv@altlinux.org> wrote:
> > > > > > > > > > > syscall_get_* functions are required to be implemented on all
> > > > > > > > > > > architectures in order to extend the generic ptrace API with
> > > > > > > > > > > PTRACE_GET_SYSCALL_INFO request.
> > > > > > > > > > >
> > > > > > > > > > > This introduces asm/syscall.h on m68k implementing all 5 syscall_get_*
> > > > > > > > > > > functions as documented in asm-generic/syscall.h: syscall_get_nr,
> > > > > > > > > > > syscall_get_arguments, syscall_get_error, syscall_get_return_value,
> > > > > > > > > > > and syscall_get_arch.
> > > > > > > > > > >
> > > > > > > > > > > Cc: Geert Uytterhoeven <geert@linux-m68k.org>
> > > > > > > > > > > Cc: Oleg Nesterov <oleg@redhat.com>
> > > > > > > > > > > Cc: Andy Lutomirski <luto@kernel.org>
> > > > > > > > > > > Cc: Elvira Khabirova <lineprinter@altlinux.org>
> > > > > > > > > > > Cc: Eugene Syromyatnikov <esyr@redhat.com>
> > > > > > > > > > > Cc: linux-m68k@lists.linux-m68k.org
> > > > > > > > > > > Signed-off-by: Dmitry V. Levin <ldv@altlinux.org>
> > > > > > > > > > > ---
> > > > > > > > > > >
> > > > > > > > > > > Notes:
> > > > > > > > > > >     v5: added syscall_get_nr, syscall_get_arguments, syscall_get_error,
> > > > > > > > > > >         and syscall_get_return_value
> > > > > > > > > > >     v1: added syscall_get_arch
> > > > > > > > > >
> > > > > > > > > > > --- /dev/null
> > > > > > > > > > > +++ b/arch/m68k/include/asm/syscall.h
> > > > > > > > > > > @@ -0,0 +1,39 @@
> > > > > > > > > >
> > > > > > > > > > > +static inline void
> > > > > > > > > > > +syscall_get_arguments(struct task_struct *task, struct pt_regs *regs,
> > > > > > > > > > > +                     unsigned int i, unsigned int n, unsigned long *args)
> > > > > > > > > > > +{
> > > > > > > > > > > +       BUG_ON(i + n > 6);
> > > > > > > > > >
> > > > > > > > > > Does this have to crash the kernel?
> > > > > > > > >
> > > > > > > > > This is what most of other architectures do, but we could choose
> > > > > > > > > a softer approach, e.g. use WARN_ON_ONCE instead.
> > > > > > > > >
> > > > > > > > > > Perhaps you can return an error code instead?
> > > > > > > > >
> > > > > > > > > That would be problematic given the signature of this function
> > > > > > > > > and the nature of the potential bug which would most likely be a usage error.
> > > > > > > >
> > > > > > > > Of course to handle that, the function's signature need to be changed.
> > > > > > > > Changing it has the advantage that the error handling can be done at the
> > > > > > > > caller, in common code, instead of duplicating it for all
> > > > > > > > architectures, possibly
> > > > > > > > leading to different semantics.
> > > > > > >
> > > > > > > Given that *all* current users of syscall_get_arguments specify i == 0
> > > > > > > (and there is an architecture that has BUG_ON(i)),
> > > > > > > it should be really a usage error to get into situation where i + n > 6,
> > > > > > > I wish a BUILD_BUG_ON could be used here instead.
> > > > > > >
> > > > > > > I don't think it worths pushing the change of API just to convert
> > > > > > > a "cannot happen" assertion into an error that would have to be dealt with
> > > > > > > on the caller side.
> > > > > >
> > > > > > I suggest the following BUG_ON replacement for syscall_get_arguments:
> > > > > >
> > > > > > #define SYSCALL_MAX_ARGS 6
> > > > > >
> > > > > > static inline void
> > > > > > syscall_get_arguments(struct task_struct *task, struct pt_regs *regs,
> > > > > >                       unsigned int i, unsigned int n, unsigned long *args)
> > > > > > {
> > > > > >         /*
> > > > > >          * Ideally there should have been
> > > > > >          * BUILD_BUG_ON(i + n > SYSCALL_MAX_ARGS);
> > > > > >          * instead of these checks.
> > > > > >          */
> > > > > >         if (unlikely(i > SYSCALL_MAX_ARGS)) {
> > > > > >                 WARN_ONCE(1, "i > SYSCALL_MAX_ARGS");
> > > > > >                 return;
> > > > >
> > > > > Does this have security implications, as args is an output parameter?
> > > > > I.e. if you don't fill the array, the caller will use whatever is on the stack.
> > > > > Can this ever be passed to userspace, leaking data?
> > > >
> > > > In the current kernel code n is always less or equal to 6,
> > > > but in theory future changes can potentially break the assertion
> > > > and this could lead to leaking data to userspace.
> > >
> > > OK.
> > >
> > > > Do you think we should rather be defensive and add some memsets, e.g.
> > > >
> > > >         if (unlikely(i > SYSCALL_MAX_ARGS)) {
> > > >                 WARN_ONCE(1, "i > SYSCALL_MAX_ARGS");
> > > >                 memset(args, 0, n * sizeof(args[0]));
> > > >                 return;
> > > >         }
> > > >         if (unlikely(n > SYSCALL_MAX_ARGS - i)) {
> > > >                 unsigned int extra = n - (SYSCALL_MAX_ARGS - i);
> > > >
> > > >                 WARN_ONCE(1, "i + n > SYSCALL_MAX_ARGS");
> > > >                 n = SYSCALL_MAX_ARGS - i;
> > > >                 memset(&args[n], 0, extra * sizeof(args[0]));
> > > >         }
> > > > ?
> > >
> > > Yes please.
> > >
> > > But please handle all of that in the generic code, so it doesn't have to be
> > > replicated across all architectures.
> > >
> > > E.g. make syscall_get_arguments() a wrapper in generic code, calling
> > > __syscall_get_arguments() in architecture-specific code.
> > >
> > > And make the latter return int, so it can indicate other failures.
> >
> > Other failures?  What syscall_get_arguments is expected to do
> > if __syscall_get_arguments returned, say, -1?
> 
> Fail. Just like in case of other generic ill conditions it can detect itself.

Sorry, I don't quite follow.  syscall_get_arguments() has no return code,
so all it can possibly do is to zero out args[], e.g.

        if (unlikely(__syscall_get_arguments(task, regs, i, n, args) < 0)) {
                memset(args, 0, n * sizeof(args[0]));
                return;
        }

Do you mean this?


-- 
ldv

[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 801 bytes --]

^ permalink raw reply	[flat|nested] 65+ messages in thread

* Re: [PATCH v5 13/25] m68k: add asm/syscall.h
  2018-12-12 12:37                       ` Dmitry V. Levin
@ 2018-12-12 12:54                         ` Geert Uytterhoeven
  2018-12-12 13:07                           ` Dmitry V. Levin
  0 siblings, 1 reply; 65+ messages in thread
From: Geert Uytterhoeven @ 2018-12-12 12:54 UTC (permalink / raw)
  To: Dmitry V. Levin
  Cc: Oleg Nesterov, Andy Lutomirski, lineprinter,
	Eugene Syromiatnikov, linux-m68k, Linux Kernel Mailing List

Hi Dmitry,

On Wed, Dec 12, 2018 at 1:37 PM Dmitry V. Levin <ldv@altlinux.org> wrote:
> On Wed, Dec 12, 2018 at 01:27:14PM +0100, Geert Uytterhoeven wrote:
> > On Wed, Dec 12, 2018 at 1:04 PM Dmitry V. Levin <ldv@altlinux.org> wrote:
> > > On Wed, Dec 12, 2018 at 10:43:33AM +0100, Geert Uytterhoeven wrote:
> > > > On Wed, Dec 12, 2018 at 10:27 AM Dmitry V. Levin <ldv@altlinux.org> wrote:
> > > > > On Wed, Dec 12, 2018 at 10:01:29AM +0100, Geert Uytterhoeven wrote:
> > > > > > On Wed, Dec 12, 2018 at 9:55 AM Dmitry V. Levin <ldv@altlinux.org> wrote:
> > > > > > > On Mon, Dec 10, 2018 at 04:30:25PM +0300, Dmitry V. Levin wrote:
> > > > > > > > On Mon, Dec 10, 2018 at 02:06:28PM +0100, Geert Uytterhoeven wrote:
> > > > > > > > > On Mon, Dec 10, 2018 at 1:41 PM Dmitry V. Levin <ldv@altlinux.org> wrote:
> > > > > > > > > > On Mon, Dec 10, 2018 at 09:45:42AM +0100, Geert Uytterhoeven wrote:
> > > > > > > > > > > On Mon, Dec 10, 2018 at 5:30 AM Dmitry V. Levin <ldv@altlinux.org> wrote:
> > > > > > > > > > > > syscall_get_* functions are required to be implemented on all
> > > > > > > > > > > > architectures in order to extend the generic ptrace API with
> > > > > > > > > > > > PTRACE_GET_SYSCALL_INFO request.
> > > > > > > > > > > >
> > > > > > > > > > > > This introduces asm/syscall.h on m68k implementing all 5 syscall_get_*
> > > > > > > > > > > > functions as documented in asm-generic/syscall.h: syscall_get_nr,
> > > > > > > > > > > > syscall_get_arguments, syscall_get_error, syscall_get_return_value,
> > > > > > > > > > > > and syscall_get_arch.
> > > > > > > > > > > >
> > > > > > > > > > > > Cc: Geert Uytterhoeven <geert@linux-m68k.org>
> > > > > > > > > > > > Cc: Oleg Nesterov <oleg@redhat.com>
> > > > > > > > > > > > Cc: Andy Lutomirski <luto@kernel.org>
> > > > > > > > > > > > Cc: Elvira Khabirova <lineprinter@altlinux.org>
> > > > > > > > > > > > Cc: Eugene Syromyatnikov <esyr@redhat.com>
> > > > > > > > > > > > Cc: linux-m68k@lists.linux-m68k.org
> > > > > > > > > > > > Signed-off-by: Dmitry V. Levin <ldv@altlinux.org>
> > > > > > > > > > > > ---
> > > > > > > > > > > >
> > > > > > > > > > > > Notes:
> > > > > > > > > > > >     v5: added syscall_get_nr, syscall_get_arguments, syscall_get_error,
> > > > > > > > > > > >         and syscall_get_return_value
> > > > > > > > > > > >     v1: added syscall_get_arch
> > > > > > > > > > >
> > > > > > > > > > > > --- /dev/null
> > > > > > > > > > > > +++ b/arch/m68k/include/asm/syscall.h
> > > > > > > > > > > > @@ -0,0 +1,39 @@
> > > > > > > > > > >
> > > > > > > > > > > > +static inline void
> > > > > > > > > > > > +syscall_get_arguments(struct task_struct *task, struct pt_regs *regs,
> > > > > > > > > > > > +                     unsigned int i, unsigned int n, unsigned long *args)
> > > > > > > > > > > > +{
> > > > > > > > > > > > +       BUG_ON(i + n > 6);
> > > > > > > > > > >
> > > > > > > > > > > Does this have to crash the kernel?
> > > > > > > > > >
> > > > > > > > > > This is what most of other architectures do, but we could choose
> > > > > > > > > > a softer approach, e.g. use WARN_ON_ONCE instead.
> > > > > > > > > >
> > > > > > > > > > > Perhaps you can return an error code instead?
> > > > > > > > > >
> > > > > > > > > > That would be problematic given the signature of this function
> > > > > > > > > > and the nature of the potential bug which would most likely be a usage error.
> > > > > > > > >
> > > > > > > > > Of course to handle that, the function's signature need to be changed.
> > > > > > > > > Changing it has the advantage that the error handling can be done at the
> > > > > > > > > caller, in common code, instead of duplicating it for all
> > > > > > > > > architectures, possibly
> > > > > > > > > leading to different semantics.
> > > > > > > >
> > > > > > > > Given that *all* current users of syscall_get_arguments specify i == 0
> > > > > > > > (and there is an architecture that has BUG_ON(i)),
> > > > > > > > it should be really a usage error to get into situation where i + n > 6,
> > > > > > > > I wish a BUILD_BUG_ON could be used here instead.
> > > > > > > >
> > > > > > > > I don't think it worths pushing the change of API just to convert
> > > > > > > > a "cannot happen" assertion into an error that would have to be dealt with
> > > > > > > > on the caller side.
> > > > > > >
> > > > > > > I suggest the following BUG_ON replacement for syscall_get_arguments:
> > > > > > >
> > > > > > > #define SYSCALL_MAX_ARGS 6
> > > > > > >
> > > > > > > static inline void
> > > > > > > syscall_get_arguments(struct task_struct *task, struct pt_regs *regs,
> > > > > > >                       unsigned int i, unsigned int n, unsigned long *args)
> > > > > > > {
> > > > > > >         /*
> > > > > > >          * Ideally there should have been
> > > > > > >          * BUILD_BUG_ON(i + n > SYSCALL_MAX_ARGS);
> > > > > > >          * instead of these checks.
> > > > > > >          */
> > > > > > >         if (unlikely(i > SYSCALL_MAX_ARGS)) {
> > > > > > >                 WARN_ONCE(1, "i > SYSCALL_MAX_ARGS");
> > > > > > >                 return;
> > > > > >
> > > > > > Does this have security implications, as args is an output parameter?
> > > > > > I.e. if you don't fill the array, the caller will use whatever is on the stack.
> > > > > > Can this ever be passed to userspace, leaking data?
> > > > >
> > > > > In the current kernel code n is always less or equal to 6,
> > > > > but in theory future changes can potentially break the assertion
> > > > > and this could lead to leaking data to userspace.
> > > >
> > > > OK.
> > > >
> > > > > Do you think we should rather be defensive and add some memsets, e.g.
> > > > >
> > > > >         if (unlikely(i > SYSCALL_MAX_ARGS)) {
> > > > >                 WARN_ONCE(1, "i > SYSCALL_MAX_ARGS");
> > > > >                 memset(args, 0, n * sizeof(args[0]));
> > > > >                 return;
> > > > >         }
> > > > >         if (unlikely(n > SYSCALL_MAX_ARGS - i)) {
> > > > >                 unsigned int extra = n - (SYSCALL_MAX_ARGS - i);
> > > > >
> > > > >                 WARN_ONCE(1, "i + n > SYSCALL_MAX_ARGS");
> > > > >                 n = SYSCALL_MAX_ARGS - i;
> > > > >                 memset(&args[n], 0, extra * sizeof(args[0]));
> > > > >         }
> > > > > ?
> > > >
> > > > Yes please.
> > > >
> > > > But please handle all of that in the generic code, so it doesn't have to be
> > > > replicated across all architectures.
> > > >
> > > > E.g. make syscall_get_arguments() a wrapper in generic code, calling
> > > > __syscall_get_arguments() in architecture-specific code.
> > > >
> > > > And make the latter return int, so it can indicate other failures.
> > >
> > > Other failures?  What syscall_get_arguments is expected to do
> > > if __syscall_get_arguments returned, say, -1?
> >
> > Fail. Just like in case of other generic ill conditions it can detect itself.
>
> Sorry, I don't quite follow.  syscall_get_arguments() has no return code,

Which may be an indicator for a different problem.
What is e.g. populate_seccomp_data() supposed to do if
syscall_get_arguments() fails?

> so all it can possibly do is to zero out args[], e.g.
>
>         if (unlikely(__syscall_get_arguments(task, regs, i, n, args) < 0)) {
>                 memset(args, 0, n * sizeof(args[0]));
>                 return;
>         }
>
> Do you mean this?

Exactly.
And alternatively do the BUG() thing there.

Gr{oetje,eeting}s,

                        Geert

-- 
Geert Uytterhoeven -- There's lots of Linux beyond ia32 -- geert@linux-m68k.org

In personal conversations with technical people, I call myself a hacker. But
when I'm talking to journalists I just say "programmer" or something like that.
                                -- Linus Torvalds

^ permalink raw reply	[flat|nested] 65+ messages in thread

* Re: [PATCH v5 13/25] m68k: add asm/syscall.h
  2018-12-12 12:54                         ` Geert Uytterhoeven
@ 2018-12-12 13:07                           ` Dmitry V. Levin
  2018-12-12 23:12                             ` Dmitry V. Levin
  0 siblings, 1 reply; 65+ messages in thread
From: Dmitry V. Levin @ 2018-12-12 13:07 UTC (permalink / raw)
  To: Geert Uytterhoeven
  Cc: Oleg Nesterov, Andy Lutomirski, lineprinter,
	Eugene Syromiatnikov, linux-m68k, Linux Kernel Mailing List

[-- Attachment #1: Type: text/plain, Size: 8249 bytes --]

Hi Geert,

On Wed, Dec 12, 2018 at 01:54:05PM +0100, Geert Uytterhoeven wrote:
> On Wed, Dec 12, 2018 at 1:37 PM Dmitry V. Levin <ldv@altlinux.org> wrote:
> > On Wed, Dec 12, 2018 at 01:27:14PM +0100, Geert Uytterhoeven wrote:
> > > On Wed, Dec 12, 2018 at 1:04 PM Dmitry V. Levin <ldv@altlinux.org> wrote:
> > > > On Wed, Dec 12, 2018 at 10:43:33AM +0100, Geert Uytterhoeven wrote:
> > > > > On Wed, Dec 12, 2018 at 10:27 AM Dmitry V. Levin <ldv@altlinux.org> wrote:
> > > > > > On Wed, Dec 12, 2018 at 10:01:29AM +0100, Geert Uytterhoeven wrote:
> > > > > > > On Wed, Dec 12, 2018 at 9:55 AM Dmitry V. Levin <ldv@altlinux.org> wrote:
> > > > > > > > On Mon, Dec 10, 2018 at 04:30:25PM +0300, Dmitry V. Levin wrote:
> > > > > > > > > On Mon, Dec 10, 2018 at 02:06:28PM +0100, Geert Uytterhoeven wrote:
> > > > > > > > > > On Mon, Dec 10, 2018 at 1:41 PM Dmitry V. Levin <ldv@altlinux.org> wrote:
> > > > > > > > > > > On Mon, Dec 10, 2018 at 09:45:42AM +0100, Geert Uytterhoeven wrote:
> > > > > > > > > > > > On Mon, Dec 10, 2018 at 5:30 AM Dmitry V. Levin <ldv@altlinux.org> wrote:
> > > > > > > > > > > > > syscall_get_* functions are required to be implemented on all
> > > > > > > > > > > > > architectures in order to extend the generic ptrace API with
> > > > > > > > > > > > > PTRACE_GET_SYSCALL_INFO request.
> > > > > > > > > > > > >
> > > > > > > > > > > > > This introduces asm/syscall.h on m68k implementing all 5 syscall_get_*
> > > > > > > > > > > > > functions as documented in asm-generic/syscall.h: syscall_get_nr,
> > > > > > > > > > > > > syscall_get_arguments, syscall_get_error, syscall_get_return_value,
> > > > > > > > > > > > > and syscall_get_arch.
> > > > > > > > > > > > >
> > > > > > > > > > > > > Cc: Geert Uytterhoeven <geert@linux-m68k.org>
> > > > > > > > > > > > > Cc: Oleg Nesterov <oleg@redhat.com>
> > > > > > > > > > > > > Cc: Andy Lutomirski <luto@kernel.org>
> > > > > > > > > > > > > Cc: Elvira Khabirova <lineprinter@altlinux.org>
> > > > > > > > > > > > > Cc: Eugene Syromyatnikov <esyr@redhat.com>
> > > > > > > > > > > > > Cc: linux-m68k@lists.linux-m68k.org
> > > > > > > > > > > > > Signed-off-by: Dmitry V. Levin <ldv@altlinux.org>
> > > > > > > > > > > > > ---
> > > > > > > > > > > > >
> > > > > > > > > > > > > Notes:
> > > > > > > > > > > > >     v5: added syscall_get_nr, syscall_get_arguments, syscall_get_error,
> > > > > > > > > > > > >         and syscall_get_return_value
> > > > > > > > > > > > >     v1: added syscall_get_arch
> > > > > > > > > > > >
> > > > > > > > > > > > > --- /dev/null
> > > > > > > > > > > > > +++ b/arch/m68k/include/asm/syscall.h
> > > > > > > > > > > > > @@ -0,0 +1,39 @@
> > > > > > > > > > > >
> > > > > > > > > > > > > +static inline void
> > > > > > > > > > > > > +syscall_get_arguments(struct task_struct *task, struct pt_regs *regs,
> > > > > > > > > > > > > +                     unsigned int i, unsigned int n, unsigned long *args)
> > > > > > > > > > > > > +{
> > > > > > > > > > > > > +       BUG_ON(i + n > 6);
> > > > > > > > > > > >
> > > > > > > > > > > > Does this have to crash the kernel?
> > > > > > > > > > >
> > > > > > > > > > > This is what most of other architectures do, but we could choose
> > > > > > > > > > > a softer approach, e.g. use WARN_ON_ONCE instead.
> > > > > > > > > > >
> > > > > > > > > > > > Perhaps you can return an error code instead?
> > > > > > > > > > >
> > > > > > > > > > > That would be problematic given the signature of this function
> > > > > > > > > > > and the nature of the potential bug which would most likely be a usage error.
> > > > > > > > > >
> > > > > > > > > > Of course to handle that, the function's signature need to be changed.
> > > > > > > > > > Changing it has the advantage that the error handling can be done at the
> > > > > > > > > > caller, in common code, instead of duplicating it for all
> > > > > > > > > > architectures, possibly
> > > > > > > > > > leading to different semantics.
> > > > > > > > >
> > > > > > > > > Given that *all* current users of syscall_get_arguments specify i == 0
> > > > > > > > > (and there is an architecture that has BUG_ON(i)),
> > > > > > > > > it should be really a usage error to get into situation where i + n > 6,
> > > > > > > > > I wish a BUILD_BUG_ON could be used here instead.
> > > > > > > > >
> > > > > > > > > I don't think it worths pushing the change of API just to convert
> > > > > > > > > a "cannot happen" assertion into an error that would have to be dealt with
> > > > > > > > > on the caller side.
> > > > > > > >
> > > > > > > > I suggest the following BUG_ON replacement for syscall_get_arguments:
> > > > > > > >
> > > > > > > > #define SYSCALL_MAX_ARGS 6
> > > > > > > >
> > > > > > > > static inline void
> > > > > > > > syscall_get_arguments(struct task_struct *task, struct pt_regs *regs,
> > > > > > > >                       unsigned int i, unsigned int n, unsigned long *args)
> > > > > > > > {
> > > > > > > >         /*
> > > > > > > >          * Ideally there should have been
> > > > > > > >          * BUILD_BUG_ON(i + n > SYSCALL_MAX_ARGS);
> > > > > > > >          * instead of these checks.
> > > > > > > >          */
> > > > > > > >         if (unlikely(i > SYSCALL_MAX_ARGS)) {
> > > > > > > >                 WARN_ONCE(1, "i > SYSCALL_MAX_ARGS");
> > > > > > > >                 return;
> > > > > > >
> > > > > > > Does this have security implications, as args is an output parameter?
> > > > > > > I.e. if you don't fill the array, the caller will use whatever is on the stack.
> > > > > > > Can this ever be passed to userspace, leaking data?
> > > > > >
> > > > > > In the current kernel code n is always less or equal to 6,
> > > > > > but in theory future changes can potentially break the assertion
> > > > > > and this could lead to leaking data to userspace.
> > > > >
> > > > > OK.
> > > > >
> > > > > > Do you think we should rather be defensive and add some memsets, e.g.
> > > > > >
> > > > > >         if (unlikely(i > SYSCALL_MAX_ARGS)) {
> > > > > >                 WARN_ONCE(1, "i > SYSCALL_MAX_ARGS");
> > > > > >                 memset(args, 0, n * sizeof(args[0]));
> > > > > >                 return;
> > > > > >         }
> > > > > >         if (unlikely(n > SYSCALL_MAX_ARGS - i)) {
> > > > > >                 unsigned int extra = n - (SYSCALL_MAX_ARGS - i);
> > > > > >
> > > > > >                 WARN_ONCE(1, "i + n > SYSCALL_MAX_ARGS");
> > > > > >                 n = SYSCALL_MAX_ARGS - i;
> > > > > >                 memset(&args[n], 0, extra * sizeof(args[0]));
> > > > > >         }
> > > > > > ?
> > > > >
> > > > > Yes please.
> > > > >
> > > > > But please handle all of that in the generic code, so it doesn't have to be
> > > > > replicated across all architectures.
> > > > >
> > > > > E.g. make syscall_get_arguments() a wrapper in generic code, calling
> > > > > __syscall_get_arguments() in architecture-specific code.
> > > > >
> > > > > And make the latter return int, so it can indicate other failures.
> > > >
> > > > Other failures?  What syscall_get_arguments is expected to do
> > > > if __syscall_get_arguments returned, say, -1?
> > >
> > > Fail. Just like in case of other generic ill conditions it can detect itself.
> >
> > Sorry, I don't quite follow.  syscall_get_arguments() has no return code,
> 
> Which may be an indicator for a different problem.
> What is e.g. populate_seccomp_data() supposed to do if
> syscall_get_arguments() fails?

Well, syscall_get_arguments() is not supposed to fail if invoked properly.

Currently populate_seccomp_data() does this:
	struct task_struct *task = current;
	struct pt_regs *regs = task_pt_regs(task);
	unsigned long args[6];
	...
	syscall_get_arguments(task, regs, 0, 6, args);

I don't see how this could fail.

> > so all it can possibly do is to zero out args[], e.g.
> >
> >         if (unlikely(__syscall_get_arguments(task, regs, i, n, args) < 0)) {
> >                 memset(args, 0, n * sizeof(args[0]));
> >                 return;
> >         }
> >
> > Do you mean this?
> 
> Exactly.

OK, I'll prepare the change, thanks.


-- 
ldv

[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 801 bytes --]

^ permalink raw reply	[flat|nested] 65+ messages in thread

* Re: [PATCH v5 24/25] ptrace: add PTRACE_GET_SYSCALL_INFO request
  2018-12-11 20:27           ` Dmitry V. Levin
@ 2018-12-12 18:00             ` Oleg Nesterov
  0 siblings, 0 replies; 65+ messages in thread
From: Oleg Nesterov @ 2018-12-12 18:00 UTC (permalink / raw)
  To: Dmitry V. Levin
  Cc: Andy Lutomirski, Elvira Khabirova, Eugene Syromyatnikov,
	Kees Cook, Jann Horn, linux-api, strace-devel, linux-kernel

On 12/11, Dmitry V. Levin wrote:
>
> > > Still can't understand... are you saying that without (say) __pad2[4]
> > > sizeof(ptrace_syscall_info) or offsetofend(ptrace_syscall_info, seccomp)
> > > will depend on arch? Or what? I am just curious.
> >
> > Yes, without padding these sizes will depend on architecture:
>
> > $ cat t.c
> > #include <linux/types.h>
> > int main() {
> > 	struct s {
> > 		__u64 nr;
> > 		__u64 args[6];
> > 		__u32 ret_data;
> > 	};
> > 	return sizeof(struct s);
> > }
> >
> > $ gcc -m64 -Wall -O2 t.c && ./a.out; echo $?
> > 64
> > $ gcc -m32 -Wall -O2 t.c && ./a.out; echo $?
> > 60
> >
> > This happens because __u64 has 32-bit alignment on some 32-bit
> > architectures like x86.
> >
> > There is also m68k where __u32 has 16-bit alignment.

OK, thanks,

> Said that, I think it would be better if PTRACE_GET_SYSCALL_INFO
> did not take these trailing pads into account, e.g.
>
> -       return offsetofend(struct ptrace_syscall_info, seccomp);
> +       return offsetofend(struct ptrace_syscall_info, seccomp.ret_data);
> ...
> -       return offsetofend(struct ptrace_syscall_info, exit);
> +       return offsetofend(struct ptrace_syscall_info, exit.is_error);
>
> The reason is that it would allow to fill these trailing pads with
> something useful in the future.

Agreed.

But this way everything looks even more confusing. To me it would be
better to simply remove these pads, but I won't insist.

Oleg.


^ permalink raw reply	[flat|nested] 65+ messages in thread

* Re: [PATCH v5 13/25] m68k: add asm/syscall.h
  2018-12-12 13:07                           ` Dmitry V. Levin
@ 2018-12-12 23:12                             ` Dmitry V. Levin
  0 siblings, 0 replies; 65+ messages in thread
From: Dmitry V. Levin @ 2018-12-12 23:12 UTC (permalink / raw)
  To: Geert Uytterhoeven
  Cc: Oleg Nesterov, Andy Lutomirski, lineprinter,
	Eugene Syromiatnikov, linux-m68k, Linux Kernel Mailing List

[-- Attachment #1: Type: text/plain, Size: 9095 bytes --]

Hi Geert,

On Wed, Dec 12, 2018 at 04:07:11PM +0300, Dmitry V. Levin wrote:
> On Wed, Dec 12, 2018 at 01:54:05PM +0100, Geert Uytterhoeven wrote:
> > On Wed, Dec 12, 2018 at 1:37 PM Dmitry V. Levin <ldv@altlinux.org> wrote:
> > > On Wed, Dec 12, 2018 at 01:27:14PM +0100, Geert Uytterhoeven wrote:
> > > > On Wed, Dec 12, 2018 at 1:04 PM Dmitry V. Levin <ldv@altlinux.org> wrote:
> > > > > On Wed, Dec 12, 2018 at 10:43:33AM +0100, Geert Uytterhoeven wrote:
> > > > > > On Wed, Dec 12, 2018 at 10:27 AM Dmitry V. Levin <ldv@altlinux.org> wrote:
> > > > > > > On Wed, Dec 12, 2018 at 10:01:29AM +0100, Geert Uytterhoeven wrote:
> > > > > > > > On Wed, Dec 12, 2018 at 9:55 AM Dmitry V. Levin <ldv@altlinux.org> wrote:
> > > > > > > > > On Mon, Dec 10, 2018 at 04:30:25PM +0300, Dmitry V. Levin wrote:
> > > > > > > > > > On Mon, Dec 10, 2018 at 02:06:28PM +0100, Geert Uytterhoeven wrote:
> > > > > > > > > > > On Mon, Dec 10, 2018 at 1:41 PM Dmitry V. Levin <ldv@altlinux.org> wrote:
> > > > > > > > > > > > On Mon, Dec 10, 2018 at 09:45:42AM +0100, Geert Uytterhoeven wrote:
> > > > > > > > > > > > > On Mon, Dec 10, 2018 at 5:30 AM Dmitry V. Levin <ldv@altlinux.org> wrote:
> > > > > > > > > > > > > > syscall_get_* functions are required to be implemented on all
> > > > > > > > > > > > > > architectures in order to extend the generic ptrace API with
> > > > > > > > > > > > > > PTRACE_GET_SYSCALL_INFO request.
> > > > > > > > > > > > > >
> > > > > > > > > > > > > > This introduces asm/syscall.h on m68k implementing all 5 syscall_get_*
> > > > > > > > > > > > > > functions as documented in asm-generic/syscall.h: syscall_get_nr,
> > > > > > > > > > > > > > syscall_get_arguments, syscall_get_error, syscall_get_return_value,
> > > > > > > > > > > > > > and syscall_get_arch.
> > > > > > > > > > > > > >
> > > > > > > > > > > > > > Cc: Geert Uytterhoeven <geert@linux-m68k.org>
> > > > > > > > > > > > > > Cc: Oleg Nesterov <oleg@redhat.com>
> > > > > > > > > > > > > > Cc: Andy Lutomirski <luto@kernel.org>
> > > > > > > > > > > > > > Cc: Elvira Khabirova <lineprinter@altlinux.org>
> > > > > > > > > > > > > > Cc: Eugene Syromyatnikov <esyr@redhat.com>
> > > > > > > > > > > > > > Cc: linux-m68k@lists.linux-m68k.org
> > > > > > > > > > > > > > Signed-off-by: Dmitry V. Levin <ldv@altlinux.org>
> > > > > > > > > > > > > > ---
> > > > > > > > > > > > > >
> > > > > > > > > > > > > > Notes:
> > > > > > > > > > > > > >     v5: added syscall_get_nr, syscall_get_arguments, syscall_get_error,
> > > > > > > > > > > > > >         and syscall_get_return_value
> > > > > > > > > > > > > >     v1: added syscall_get_arch
> > > > > > > > > > > > >
> > > > > > > > > > > > > > --- /dev/null
> > > > > > > > > > > > > > +++ b/arch/m68k/include/asm/syscall.h
> > > > > > > > > > > > > > @@ -0,0 +1,39 @@
> > > > > > > > > > > > >
> > > > > > > > > > > > > > +static inline void
> > > > > > > > > > > > > > +syscall_get_arguments(struct task_struct *task, struct pt_regs *regs,
> > > > > > > > > > > > > > +                     unsigned int i, unsigned int n, unsigned long *args)
> > > > > > > > > > > > > > +{
> > > > > > > > > > > > > > +       BUG_ON(i + n > 6);
> > > > > > > > > > > > >
> > > > > > > > > > > > > Does this have to crash the kernel?
> > > > > > > > > > > >
> > > > > > > > > > > > This is what most of other architectures do, but we could choose
> > > > > > > > > > > > a softer approach, e.g. use WARN_ON_ONCE instead.
> > > > > > > > > > > >
> > > > > > > > > > > > > Perhaps you can return an error code instead?
> > > > > > > > > > > >
> > > > > > > > > > > > That would be problematic given the signature of this function
> > > > > > > > > > > > and the nature of the potential bug which would most likely be a usage error.
> > > > > > > > > > >
> > > > > > > > > > > Of course to handle that, the function's signature need to be changed.
> > > > > > > > > > > Changing it has the advantage that the error handling can be done at the
> > > > > > > > > > > caller, in common code, instead of duplicating it for all
> > > > > > > > > > > architectures, possibly
> > > > > > > > > > > leading to different semantics.
> > > > > > > > > >
> > > > > > > > > > Given that *all* current users of syscall_get_arguments specify i == 0
> > > > > > > > > > (and there is an architecture that has BUG_ON(i)),
> > > > > > > > > > it should be really a usage error to get into situation where i + n > 6,
> > > > > > > > > > I wish a BUILD_BUG_ON could be used here instead.
> > > > > > > > > >
> > > > > > > > > > I don't think it worths pushing the change of API just to convert
> > > > > > > > > > a "cannot happen" assertion into an error that would have to be dealt with
> > > > > > > > > > on the caller side.
> > > > > > > > >
> > > > > > > > > I suggest the following BUG_ON replacement for syscall_get_arguments:
> > > > > > > > >
> > > > > > > > > #define SYSCALL_MAX_ARGS 6
> > > > > > > > >
> > > > > > > > > static inline void
> > > > > > > > > syscall_get_arguments(struct task_struct *task, struct pt_regs *regs,
> > > > > > > > >                       unsigned int i, unsigned int n, unsigned long *args)
> > > > > > > > > {
> > > > > > > > >         /*
> > > > > > > > >          * Ideally there should have been
> > > > > > > > >          * BUILD_BUG_ON(i + n > SYSCALL_MAX_ARGS);
> > > > > > > > >          * instead of these checks.
> > > > > > > > >          */
> > > > > > > > >         if (unlikely(i > SYSCALL_MAX_ARGS)) {
> > > > > > > > >                 WARN_ONCE(1, "i > SYSCALL_MAX_ARGS");
> > > > > > > > >                 return;
> > > > > > > >
> > > > > > > > Does this have security implications, as args is an output parameter?
> > > > > > > > I.e. if you don't fill the array, the caller will use whatever is on the stack.
> > > > > > > > Can this ever be passed to userspace, leaking data?
> > > > > > >
> > > > > > > In the current kernel code n is always less or equal to 6,
> > > > > > > but in theory future changes can potentially break the assertion
> > > > > > > and this could lead to leaking data to userspace.
> > > > > >
> > > > > > OK.
> > > > > >
> > > > > > > Do you think we should rather be defensive and add some memsets, e.g.
> > > > > > >
> > > > > > >         if (unlikely(i > SYSCALL_MAX_ARGS)) {
> > > > > > >                 WARN_ONCE(1, "i > SYSCALL_MAX_ARGS");
> > > > > > >                 memset(args, 0, n * sizeof(args[0]));
> > > > > > >                 return;
> > > > > > >         }
> > > > > > >         if (unlikely(n > SYSCALL_MAX_ARGS - i)) {
> > > > > > >                 unsigned int extra = n - (SYSCALL_MAX_ARGS - i);
> > > > > > >
> > > > > > >                 WARN_ONCE(1, "i + n > SYSCALL_MAX_ARGS");
> > > > > > >                 n = SYSCALL_MAX_ARGS - i;
> > > > > > >                 memset(&args[n], 0, extra * sizeof(args[0]));
> > > > > > >         }
> > > > > > > ?
> > > > > >
> > > > > > Yes please.
> > > > > >
> > > > > > But please handle all of that in the generic code, so it doesn't have to be
> > > > > > replicated across all architectures.
> > > > > >
> > > > > > E.g. make syscall_get_arguments() a wrapper in generic code, calling
> > > > > > __syscall_get_arguments() in architecture-specific code.
> > > > > >
> > > > > > And make the latter return int, so it can indicate other failures.
> > > > >
> > > > > Other failures?  What syscall_get_arguments is expected to do
> > > > > if __syscall_get_arguments returned, say, -1?
> > > >
> > > > Fail. Just like in case of other generic ill conditions it can detect itself.
> > >
> > > Sorry, I don't quite follow.  syscall_get_arguments() has no return code,
> > 
> > Which may be an indicator for a different problem.
> > What is e.g. populate_seccomp_data() supposed to do if
> > syscall_get_arguments() fails?
> 
> Well, syscall_get_arguments() is not supposed to fail if invoked properly.
> 
> Currently populate_seccomp_data() does this:
> 	struct task_struct *task = current;
> 	struct pt_regs *regs = task_pt_regs(task);
> 	unsigned long args[6];
> 	...
> 	syscall_get_arguments(task, regs, 0, 6, args);
> 
> I don't see how this could fail.
> 
> > > so all it can possibly do is to zero out args[], e.g.
> > >
> > >         if (unlikely(__syscall_get_arguments(task, regs, i, n, args) < 0)) {
> > >                 memset(args, 0, n * sizeof(args[0]));
> > >                 return;
> > >         }
> > >
> > > Do you mean this?
> > 
> > Exactly.
> 
> OK, I'll prepare the change, thanks.

I have the change ready, but I don't like it.  The only architecture
that could benefit from being able of signalling an error condition to
syscall_get_arguments is MIPS, and even in that case the return code is
not suitable because it wouldn't help to distinguish between the first 4
syscall arguments that cannot cause an error and remaining arguments that
can.  It looks like there is no need to make __syscall_get_arguments()
to return int after all.


-- 
ldv

[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 801 bytes --]

^ permalink raw reply	[flat|nested] 65+ messages in thread

* Re: [PATCH v5 19/25] xtensa: define syscall_get_* functions
  2018-12-10  4:30 ` [PATCH v5 19/25] xtensa: define syscall_get_* functions Dmitry V. Levin
  2018-12-10  5:02   ` Max Filippov
  2018-12-12 10:45   ` kbuild test robot
@ 2018-12-19  5:58   ` kbuild test robot
  2 siblings, 0 replies; 65+ messages in thread
From: kbuild test robot @ 2018-12-19  5:58 UTC (permalink / raw)
  To: Dmitry V. Levin
  Cc: kbuild-all, Max Filippov, Oleg Nesterov, Andy Lutomirski,
	Elvira Khabirova, Eugene Syromyatnikov, Chris Zankel, Paul Moore,
	Eric Paris, linux-xtensa, linux-audit, linux-kernel

[-- Attachment #1: Type: text/plain, Size: 16284 bytes --]

Hi Dmitry,

Thank you for the patch! Yet something to improve:

[auto build test ERROR on linus/master]
[also build test ERROR on v4.20-rc7]
[cannot apply to next-20181218]
[if your patch is applied to the wrong git tree, please drop us a note to help improve the system]

url:    https://github.com/0day-ci/linux/commits/Dmitry-V-Levin/ptrace-add-PTRACE_GET_SYSCALL_INFO-request/20181210-174745
config: xtensa-iss_defconfig (attached as .config)
compiler: xtensa-linux-gcc (GCC) 8.1.0
reproduce:
        wget https://raw.githubusercontent.com/intel/lkp-tests/master/sbin/make.cross -O ~/bin/make.cross
        chmod +x ~/bin/make.cross
        # save the attached .config to linux build tree
        GCC_VERSION=8.1.0 make.cross ARCH=xtensa 

All errors (new ones prefixed by >>):

                   ^~~~~~~~~~
   include/linux/signal.h:122:20: note: in definition of macro '_SIG_SET_BINOP'
    static inline void name(sigset_t *r, const sigset_t *a, const sigset_t *b) \
                       ^~~~
   include/linux/signal.h:153:16: error: invalid storage class for function 'sigandnsets'
    _SIG_SET_BINOP(sigandnsets, _sig_andn)
                   ^~~~~~~~~~~
   include/linux/signal.h:122:20: note: in definition of macro '_SIG_SET_BINOP'
    static inline void name(sigset_t *r, const sigset_t *a, const sigset_t *b) \
                       ^~~~
   include/linux/signal.h:177:13: error: invalid storage class for function 'signotset'
    _SIG_SET_OP(signotset, _sig_not)
                ^~~~~~~~~
   include/linux/signal.h:161:20: note: in definition of macro '_SIG_SET_OP'
    static inline void name(sigset_t *set)     \
                       ^~~~
   include/linux/signal.h:182:20: error: invalid storage class for function 'sigemptyset'
    static inline void sigemptyset(sigset_t *set)
                       ^~~~~~~~~~~
   include/linux/signal.h:195:20: error: invalid storage class for function 'sigfillset'
    static inline void sigfillset(sigset_t *set)
                       ^~~~~~~~~~
   include/linux/signal.h:210:20: error: invalid storage class for function 'sigaddsetmask'
    static inline void sigaddsetmask(sigset_t *set, unsigned long mask)
                       ^~~~~~~~~~~~~
   include/linux/signal.h:215:20: error: invalid storage class for function 'sigdelsetmask'
    static inline void sigdelsetmask(sigset_t *set, unsigned long mask)
                       ^~~~~~~~~~~~~
   include/linux/signal.h:220:19: error: invalid storage class for function 'sigtestsetmask'
    static inline int sigtestsetmask(sigset_t *set, unsigned long mask)
                      ^~~~~~~~~~~~~~
   include/linux/signal.h:225:20: error: invalid storage class for function 'siginitset'
    static inline void siginitset(sigset_t *set, unsigned long mask)
                       ^~~~~~~~~~
   include/linux/signal.h:237:20: error: invalid storage class for function 'siginitsetinv'
    static inline void siginitsetinv(sigset_t *set, unsigned long mask)
                       ^~~~~~~~~~~~~
   include/linux/signal.h:251:20: error: invalid storage class for function 'init_sigpending'
    static inline void init_sigpending(struct sigpending *sig)
                       ^~~~~~~~~~~~~~~
   include/linux/signal.h:260:19: error: invalid storage class for function 'valid_signal'
    static inline int valid_signal(unsigned long sig)
                      ^~~~~~~~~~~~
   include/linux/signal.h:285:20: error: invalid storage class for function 'allow_signal'
    static inline void allow_signal(int sig)
                       ^~~~~~~~~~~~
   include/linux/signal.h:295:20: error: invalid storage class for function 'disallow_signal'
    static inline void disallow_signal(int sig)
                       ^~~~~~~~~~~~~~~
   In file included from include/linux/key.h:22,
                    from include/linux/syscalls.h:83,
                    from arch/xtensa/kernel/syscall.c:24:
   include/linux/sysctl.h:100:21: error: invalid storage class for function 'proc_sys_poll_event'
    static inline void *proc_sys_poll_event(struct ctl_table_poll *poll)
                        ^~~~~~~~~~~~~~~~~~~
   In file included from include/linux/static_key.h:1,
                    from include/linux/tracepoint-defs.h:12,
                    from include/linux/tracepoint.h:23,
                    from include/trace/syscall.h:5,
                    from include/linux/syscalls.h:85,
                    from arch/xtensa/kernel/syscall.c:24:
   include/linux/jump_label.h:253:19: error: invalid storage class for function 'static_key_count'
    static inline int static_key_count(struct static_key *key)
                      ^~~~~~~~~~~~~~~~
   include/linux/jump_label.h:258:29: error: invalid storage class for function 'jump_label_init'
    static __always_inline void jump_label_init(void)
                                ^~~~~~~~~~~~~~~
   include/linux/jump_label.h:263:29: error: invalid storage class for function 'static_key_false'
    static __always_inline bool static_key_false(struct static_key *key)
                                ^~~~~~~~~~~~~~~~
   include/linux/jump_label.h:270:29: error: invalid storage class for function 'static_key_true'
    static __always_inline bool static_key_true(struct static_key *key)
                                ^~~~~~~~~~~~~~~
   include/linux/jump_label.h:277:20: error: invalid storage class for function 'static_key_slow_inc'
    static inline void static_key_slow_inc(struct static_key *key)
                       ^~~~~~~~~~~~~~~~~~~
   include/linux/jump_label.h:283:20: error: invalid storage class for function 'static_key_slow_dec'
    static inline void static_key_slow_dec(struct static_key *key)
                       ^~~~~~~~~~~~~~~~~~~
   include/linux/jump_label.h:292:19: error: invalid storage class for function 'jump_label_text_reserved'
    static inline int jump_label_text_reserved(void *start, void *end)
                      ^~~~~~~~~~~~~~~~~~~~~~~~
   include/linux/jump_label.h:297:20: error: invalid storage class for function 'jump_label_lock'
    static inline void jump_label_lock(void) {}
                       ^~~~~~~~~~~~~~~
   include/linux/jump_label.h:298:20: error: invalid storage class for function 'jump_label_unlock'
    static inline void jump_label_unlock(void) {}
                       ^~~~~~~~~~~~~~~~~
   include/linux/jump_label.h:300:19: error: invalid storage class for function 'jump_label_apply_nops'
    static inline int jump_label_apply_nops(struct module *mod)
                      ^~~~~~~~~~~~~~~~~~~~~
   include/linux/jump_label.h:305:20: error: invalid storage class for function 'static_key_enable'
    static inline void static_key_enable(struct static_key *key)
                       ^~~~~~~~~~~~~~~~~
   include/linux/jump_label.h:316:20: error: invalid storage class for function 'static_key_disable'
    static inline void static_key_disable(struct static_key *key)
                       ^~~~~~~~~~~~~~~~~~
   In file included from include/trace/syscall.h:5,
                    from include/linux/syscalls.h:85,
                    from arch/xtensa/kernel/syscall.c:24:
>> include/linux/tracepoint.h:60:20: error: invalid storage class for function 'trace_module_has_bad_taint'
    static inline bool trace_module_has_bad_taint(struct module *mod)
                       ^~~~~~~~~~~~~~~~~~~~~~~~~~
>> include/linux/tracepoint.h:65:5: error: invalid storage class for function 'register_tracepoint_module_notifier'
    int register_tracepoint_module_notifier(struct notifier_block *nb)
        ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
>> include/linux/tracepoint.h:70:5: error: invalid storage class for function 'unregister_tracepoint_module_notifier'
    int unregister_tracepoint_module_notifier(struct notifier_block *nb)
        ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
   include/linux/tracepoint.h:88:20: error: invalid storage class for function 'tracepoint_synchronize_unregister'
    static inline void tracepoint_synchronize_unregister(void)
                       ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
   include/linux/tracepoint.h:114:34: error: invalid storage class for function 'tracepoint_ptr_deref'
    static inline struct tracepoint *tracepoint_ptr_deref(tracepoint_ptr_t *p)
                                     ^~~~~~~~~~~~~~~~~~~~
   In file included from include/linux/mm.h:18,
                    from include/linux/ring_buffer.h:5,
                    from include/linux/trace_events.h:6,
                    from include/trace/syscall.h:7,
                    from include/linux/syscalls.h:85,
                    from arch/xtensa/kernel/syscall.c:24:
   include/linux/range.h:24:31: error: invalid storage class for function 'cap_resource'
    static inline resource_size_t cap_resource(u64 val)
                                  ^~~~~~~~~~~~
   In file included from include/linux/mm.h:20,
                    from include/linux/ring_buffer.h:5,
                    from include/linux/trace_events.h:6,
                    from include/trace/syscall.h:7,
                    from include/linux/syscalls.h:85,
                    from arch/xtensa/kernel/syscall.c:24:
   include/linux/percpu-refcount.h:126:20: error: invalid storage class for function 'percpu_ref_kill'
    static inline void percpu_ref_kill(struct percpu_ref *ref)
                       ^~~~~~~~~~~~~~~
   include/linux/percpu-refcount.h:137:20: error: invalid storage class for function '__ref_is_percpu'
    static inline bool __ref_is_percpu(struct percpu_ref *ref,
                       ^~~~~~~~~~~~~~~
   include/linux/percpu-refcount.h:177:20: error: invalid storage class for function 'percpu_ref_get_many'
    static inline void percpu_ref_get_many(struct percpu_ref *ref, unsigned long nr)
                       ^~~~~~~~~~~~~~~~~~~
   include/linux/percpu-refcount.h:199:20: error: invalid storage class for function 'percpu_ref_get'
    static inline void percpu_ref_get(struct percpu_ref *ref)
                       ^~~~~~~~~~~~~~
   include/linux/percpu-refcount.h:213:20: error: invalid storage class for function 'percpu_ref_tryget'
    static inline bool percpu_ref_tryget(struct percpu_ref *ref)
                       ^~~~~~~~~~~~~~~~~
   include/linux/percpu-refcount.h:247:20: error: invalid storage class for function 'percpu_ref_tryget_live'
    static inline bool percpu_ref_tryget_live(struct percpu_ref *ref)
                       ^~~~~~~~~~~~~~~~~~~~~~
   include/linux/percpu-refcount.h:276:20: error: invalid storage class for function 'percpu_ref_put_many'
    static inline void percpu_ref_put_many(struct percpu_ref *ref, unsigned long nr)
                       ^~~~~~~~~~~~~~~~~~~
   include/linux/percpu-refcount.h:299:20: error: invalid storage class for function 'percpu_ref_put'
    static inline void percpu_ref_put(struct percpu_ref *ref)
                       ^~~~~~~~~~~~~~
   include/linux/percpu-refcount.h:313:20: error: invalid storage class for function 'percpu_ref_is_dying'
    static inline bool percpu_ref_is_dying(struct percpu_ref *ref)
                       ^~~~~~~~~~~~~~~~~~~
   include/linux/percpu-refcount.h:326:20: error: invalid storage class for function 'percpu_ref_is_zero'
    static inline bool percpu_ref_is_zero(struct percpu_ref *ref)
                       ^~~~~~~~~~~~~~~~~~
   In file included from include/linux/mm.h:24,
                    from include/linux/ring_buffer.h:5,
                    from include/linux/trace_events.h:6,
                    from include/trace/syscall.h:7,
                    from include/linux/syscalls.h:85,
                    from arch/xtensa/kernel/syscall.c:24:
   include/linux/page_ext.h:58:20: error: invalid storage class for function 'pgdat_page_ext_init'
    static inline void pgdat_page_ext_init(struct pglist_data *pgdat)
                       ^~~~~~~~~~~~~~~~~~~
   include/linux/page_ext.h:62:32: error: invalid storage class for function 'lookup_page_ext'
    static inline struct page_ext *lookup_page_ext(const struct page *page)
                                   ^~~~~~~~~~~~~~~
   include/linux/page_ext.h:67:20: error: invalid storage class for function 'page_ext_init'
    static inline void page_ext_init(void)
                       ^~~~~~~~~~~~~
   include/linux/page_ext.h:71:20: error: invalid storage class for function 'page_ext_init_flatmem'
    static inline void page_ext_init_flatmem(void)
                       ^~~~~~~~~~~~~~~~~~~~~
   In file included from include/linux/page_ref.h:7,
                    from include/linux/mm.h:26,
                    from include/linux/ring_buffer.h:5,
                    from include/linux/trace_events.h:6,
                    from include/trace/syscall.h:7,
                    from include/linux/syscalls.h:85,
                    from arch/xtensa/kernel/syscall.c:24:
   include/linux/page-flags.h:141:28: error: invalid storage class for function 'compound_head'
    static inline struct page *compound_head(struct page *page)
                               ^~~~~~~~~~~~~
   include/linux/page-flags.h:150:28: error: invalid storage class for function 'PageTail'
    static __always_inline int PageTail(struct page *page)
                               ^~~~~~~~
   include/linux/page-flags.h:155:28: error: invalid storage class for function 'PageCompound'
    static __always_inline int PageCompound(struct page *page)
                               ^~~~~~~~~~~~
   include/linux/page-flags.h:161:19: error: invalid storage class for function 'PagePoisoned'
    static inline int PagePoisoned(const struct page *page)
                      ^~~~~~~~~~~~
   include/linux/page-flags.h:169:20: error: invalid storage class for function 'page_init_poison'
    static inline void page_init_poison(struct page *page, size_t size)
                       ^~~~~~~~~~~~~~~~
   include/linux/page-flags.h:216:28: error: invalid storage class for function 'PageLocked'
    static __always_inline int Page##uname(struct page *page)  \
                               ^~~~
   include/linux/page-flags.h:249:2: note: in expansion of macro 'TESTPAGEFLAG'
     TESTPAGEFLAG(uname, lname, policy)    \
     ^~~~~~~~~~~~
   include/linux/page-flags.h:281:1: note: in expansion of macro '__PAGEFLAG'

vim +/trace_module_has_bad_taint +60 include/linux/tracepoint.h

de7b29739 Mathieu Desnoyers        2014-04-08  55  
45ab2813d Steven Rostedt (Red Hat  2014-02-26  56) bool trace_module_has_bad_taint(struct module *mod);
de7b29739 Mathieu Desnoyers        2014-04-08  57  extern int register_tracepoint_module_notifier(struct notifier_block *nb);
de7b29739 Mathieu Desnoyers        2014-04-08  58  extern int unregister_tracepoint_module_notifier(struct notifier_block *nb);
45ab2813d Steven Rostedt (Red Hat  2014-02-26  59) #else
45ab2813d Steven Rostedt (Red Hat  2014-02-26 @60) static inline bool trace_module_has_bad_taint(struct module *mod)
45ab2813d Steven Rostedt (Red Hat  2014-02-26  61) {
45ab2813d Steven Rostedt (Red Hat  2014-02-26  62) 	return false;
45ab2813d Steven Rostedt (Red Hat  2014-02-26  63) }
de7b29739 Mathieu Desnoyers        2014-04-08  64  static inline
de7b29739 Mathieu Desnoyers        2014-04-08 @65  int register_tracepoint_module_notifier(struct notifier_block *nb)
de7b29739 Mathieu Desnoyers        2014-04-08  66  {
de7b29739 Mathieu Desnoyers        2014-04-08  67  	return 0;
de7b29739 Mathieu Desnoyers        2014-04-08  68  }
de7b29739 Mathieu Desnoyers        2014-04-08  69  static inline
de7b29739 Mathieu Desnoyers        2014-04-08 @70  int unregister_tracepoint_module_notifier(struct notifier_block *nb)
de7b29739 Mathieu Desnoyers        2014-04-08  71  {
de7b29739 Mathieu Desnoyers        2014-04-08  72  	return 0;
de7b29739 Mathieu Desnoyers        2014-04-08  73  }
b75ef8b44 Mathieu Desnoyers        2011-08-10  74  #endif /* CONFIG_MODULES */
b75ef8b44 Mathieu Desnoyers        2011-08-10  75  

:::::: The code at line 60 was first introduced by commit
:::::: 45ab2813d40d88fc575e753c38478de242d03f88 tracing: Do not add event files for modules that fail tracepoints

:::::: TO: Steven Rostedt (Red Hat) <rostedt@goodmis.org>
:::::: CC: Steven Rostedt <rostedt@goodmis.org>

---
0-DAY kernel test infrastructure                Open Source Technology Center
https://lists.01.org/pipermail/kbuild-all                   Intel Corporation

[-- Attachment #2: .config.gz --]
[-- Type: application/gzip, Size: 8183 bytes --]

^ permalink raw reply	[flat|nested] 65+ messages in thread

* Re: [PATCH v5 13/25] m68k: add asm/syscall.h
  2018-12-12  8:55           ` Dmitry V. Levin
  2018-12-12  9:01             ` Geert Uytterhoeven
@ 2019-03-29 22:04             ` Dmitry V. Levin
  2019-03-30 20:57               ` Geert Uytterhoeven
  1 sibling, 1 reply; 65+ messages in thread
From: Dmitry V. Levin @ 2019-03-29 22:04 UTC (permalink / raw)
  To: Geert Uytterhoeven
  Cc: Oleg Nesterov, Andy Lutomirski, Elvira Khabirova,
	Eugene Syromiatnikov, linux-m68k, Linux Kernel Mailing List

[-- Attachment #1: Type: text/plain, Size: 4392 bytes --]

On Wed, Dec 12, 2018 at 11:55:16AM +0300, Dmitry V. Levin wrote:
> On Mon, Dec 10, 2018 at 04:30:25PM +0300, Dmitry V. Levin wrote:
> > On Mon, Dec 10, 2018 at 02:06:28PM +0100, Geert Uytterhoeven wrote:
> > > On Mon, Dec 10, 2018 at 1:41 PM Dmitry V. Levin <ldv@altlinux.org> wrote:
> > > > On Mon, Dec 10, 2018 at 09:45:42AM +0100, Geert Uytterhoeven wrote:
> > > > > On Mon, Dec 10, 2018 at 5:30 AM Dmitry V. Levin <ldv@altlinux.org> wrote:
> > > > > > syscall_get_* functions are required to be implemented on all
> > > > > > architectures in order to extend the generic ptrace API with
> > > > > > PTRACE_GET_SYSCALL_INFO request.
> > > > > >
> > > > > > This introduces asm/syscall.h on m68k implementing all 5 syscall_get_*
> > > > > > functions as documented in asm-generic/syscall.h: syscall_get_nr,
> > > > > > syscall_get_arguments, syscall_get_error, syscall_get_return_value,
> > > > > > and syscall_get_arch.
> > > > > >
> > > > > > Cc: Geert Uytterhoeven <geert@linux-m68k.org>
> > > > > > Cc: Oleg Nesterov <oleg@redhat.com>
> > > > > > Cc: Andy Lutomirski <luto@kernel.org>
> > > > > > Cc: Elvira Khabirova <lineprinter@altlinux.org>
> > > > > > Cc: Eugene Syromyatnikov <esyr@redhat.com>
> > > > > > Cc: linux-m68k@lists.linux-m68k.org
> > > > > > Signed-off-by: Dmitry V. Levin <ldv@altlinux.org>
> > > > > > ---
> > > > > >
> > > > > > Notes:
> > > > > >     v5: added syscall_get_nr, syscall_get_arguments, syscall_get_error,
> > > > > >         and syscall_get_return_value
> > > > > >     v1: added syscall_get_arch
> > > > >
> > > > > > --- /dev/null
> > > > > > +++ b/arch/m68k/include/asm/syscall.h
> > > > > > @@ -0,0 +1,39 @@
> > > > >
> > > > > > +static inline void
> > > > > > +syscall_get_arguments(struct task_struct *task, struct pt_regs *regs,
> > > > > > +                     unsigned int i, unsigned int n, unsigned long *args)
> > > > > > +{
> > > > > > +       BUG_ON(i + n > 6);
> > > > >
> > > > > Does this have to crash the kernel?
> > > >
> > > > This is what most of other architectures do, but we could choose
> > > > a softer approach, e.g. use WARN_ON_ONCE instead.
> > > >
> > > > > Perhaps you can return an error code instead?
> > > >
> > > > That would be problematic given the signature of this function
> > > > and the nature of the potential bug which would most likely be a usage error.
> > > 
> > > Of course to handle that, the function's signature need to be changed.
> > > Changing it has the advantage that the error handling can be done at the
> > > caller, in common code, instead of duplicating it for all
> > > architectures, possibly
> > > leading to different semantics.
> > 
> > Given that *all* current users of syscall_get_arguments specify i == 0
> > (and there is an architecture that has BUG_ON(i)), 
> > it should be really a usage error to get into situation where i + n > 6,
> > I wish a BUILD_BUG_ON could be used here instead.
> > 
> > I don't think it worths pushing the change of API just to convert
> > a "cannot happen" assertion into an error that would have to be dealt with
> > on the caller side.
> 
> I suggest the following BUG_ON replacement for syscall_get_arguments:
> 
> #define SYSCALL_MAX_ARGS 6
> 
> static inline void
> syscall_get_arguments(struct task_struct *task, struct pt_regs *regs,
> 		      unsigned int i, unsigned int n, unsigned long *args)
> {
> 	/*
> 	 * Ideally there should have been
> 	 * BUILD_BUG_ON(i + n > SYSCALL_MAX_ARGS);
> 	 * instead of these checks.
> 	 */
> 	if (unlikely(i > SYSCALL_MAX_ARGS)) {
> 		WARN_ONCE(1, "i > SYSCALL_MAX_ARGS");
> 		return;
> 	}
> 	if (unlikely(n > SYSCALL_MAX_ARGS - i)) {
> 		WARN_ONCE(1, "i + n > SYSCALL_MAX_ARGS");
> 		n = SYSCALL_MAX_ARGS - i;
> 	}
> 	BUILD_BUG_ON(sizeof(regs->d1) != sizeof(args[0]));
> 	memcpy(args, &regs->d1 + i, n * sizeof(args[0]));
> }

There seems to be a more straightforward approach to this issue.

Assuming there is a general consensus [1] to get rid of "i" and "n"
arguments of syscall_get_arguments(), the implementation could be
simplified to

static inline void
syscall_get_arguments(struct task_struct *task, struct pt_regs *regs,
		      unsigned long *args)
{
	memcpy(args, &regs->d1, 6 * sizeof(args[0]));
}

[1] https://lore.kernel.org/lkml/20190328230512.486297455@goodmis.org/


-- 
ldv

[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 801 bytes --]

^ permalink raw reply	[flat|nested] 65+ messages in thread

* Re: [PATCH v5 13/25] m68k: add asm/syscall.h
  2019-03-29 22:04             ` Dmitry V. Levin
@ 2019-03-30 20:57               ` Geert Uytterhoeven
  0 siblings, 0 replies; 65+ messages in thread
From: Geert Uytterhoeven @ 2019-03-30 20:57 UTC (permalink / raw)
  To: Dmitry V. Levin
  Cc: Oleg Nesterov, Andy Lutomirski, Elvira Khabirova,
	Eugene Syromiatnikov, linux-m68k, Linux Kernel Mailing List,
	Steven Rostedt

CC Steven

On Fri, Mar 29, 2019 at 11:04 PM Dmitry V. Levin <ldv@altlinux.org> wrote:
> On Wed, Dec 12, 2018 at 11:55:16AM +0300, Dmitry V. Levin wrote:
> > On Mon, Dec 10, 2018 at 04:30:25PM +0300, Dmitry V. Levin wrote:
> > > On Mon, Dec 10, 2018 at 02:06:28PM +0100, Geert Uytterhoeven wrote:
> > > > On Mon, Dec 10, 2018 at 1:41 PM Dmitry V. Levin <ldv@altlinux.org> wrote:
> > > > > On Mon, Dec 10, 2018 at 09:45:42AM +0100, Geert Uytterhoeven wrote:
> > > > > > On Mon, Dec 10, 2018 at 5:30 AM Dmitry V. Levin <ldv@altlinux.org> wrote:
> > > > > > > syscall_get_* functions are required to be implemented on all
> > > > > > > architectures in order to extend the generic ptrace API with
> > > > > > > PTRACE_GET_SYSCALL_INFO request.
> > > > > > >
> > > > > > > This introduces asm/syscall.h on m68k implementing all 5 syscall_get_*
> > > > > > > functions as documented in asm-generic/syscall.h: syscall_get_nr,
> > > > > > > syscall_get_arguments, syscall_get_error, syscall_get_return_value,
> > > > > > > and syscall_get_arch.
> > > > > > >
> > > > > > > Cc: Geert Uytterhoeven <geert@linux-m68k.org>
> > > > > > > Cc: Oleg Nesterov <oleg@redhat.com>
> > > > > > > Cc: Andy Lutomirski <luto@kernel.org>
> > > > > > > Cc: Elvira Khabirova <lineprinter@altlinux.org>
> > > > > > > Cc: Eugene Syromyatnikov <esyr@redhat.com>
> > > > > > > Cc: linux-m68k@lists.linux-m68k.org
> > > > > > > Signed-off-by: Dmitry V. Levin <ldv@altlinux.org>
> > > > > > > ---
> > > > > > >
> > > > > > > Notes:
> > > > > > >     v5: added syscall_get_nr, syscall_get_arguments, syscall_get_error,
> > > > > > >         and syscall_get_return_value
> > > > > > >     v1: added syscall_get_arch
> > > > > >
> > > > > > > --- /dev/null
> > > > > > > +++ b/arch/m68k/include/asm/syscall.h
> > > > > > > @@ -0,0 +1,39 @@
> > > > > >
> > > > > > > +static inline void
> > > > > > > +syscall_get_arguments(struct task_struct *task, struct pt_regs *regs,
> > > > > > > +                     unsigned int i, unsigned int n, unsigned long *args)
> > > > > > > +{
> > > > > > > +       BUG_ON(i + n > 6);
> > > > > >
> > > > > > Does this have to crash the kernel?
> > > > >
> > > > > This is what most of other architectures do, but we could choose
> > > > > a softer approach, e.g. use WARN_ON_ONCE instead.
> > > > >
> > > > > > Perhaps you can return an error code instead?
> > > > >
> > > > > That would be problematic given the signature of this function
> > > > > and the nature of the potential bug which would most likely be a usage error.
> > > >
> > > > Of course to handle that, the function's signature need to be changed.
> > > > Changing it has the advantage that the error handling can be done at the
> > > > caller, in common code, instead of duplicating it for all
> > > > architectures, possibly
> > > > leading to different semantics.
> > >
> > > Given that *all* current users of syscall_get_arguments specify i == 0
> > > (and there is an architecture that has BUG_ON(i)),
> > > it should be really a usage error to get into situation where i + n > 6,
> > > I wish a BUILD_BUG_ON could be used here instead.
> > >
> > > I don't think it worths pushing the change of API just to convert
> > > a "cannot happen" assertion into an error that would have to be dealt with
> > > on the caller side.
> >
> > I suggest the following BUG_ON replacement for syscall_get_arguments:
> >
> > #define SYSCALL_MAX_ARGS 6
> >
> > static inline void
> > syscall_get_arguments(struct task_struct *task, struct pt_regs *regs,
> >                     unsigned int i, unsigned int n, unsigned long *args)
> > {
> >       /*
> >        * Ideally there should have been
> >        * BUILD_BUG_ON(i + n > SYSCALL_MAX_ARGS);
> >        * instead of these checks.
> >        */
> >       if (unlikely(i > SYSCALL_MAX_ARGS)) {
> >               WARN_ONCE(1, "i > SYSCALL_MAX_ARGS");
> >               return;
> >       }
> >       if (unlikely(n > SYSCALL_MAX_ARGS - i)) {
> >               WARN_ONCE(1, "i + n > SYSCALL_MAX_ARGS");
> >               n = SYSCALL_MAX_ARGS - i;
> >       }
> >       BUILD_BUG_ON(sizeof(regs->d1) != sizeof(args[0]));
> >       memcpy(args, &regs->d1 + i, n * sizeof(args[0]));
> > }
>
> There seems to be a more straightforward approach to this issue.
>
> Assuming there is a general consensus [1] to get rid of "i" and "n"
> arguments of syscall_get_arguments(), the implementation could be
> simplified to
>
> static inline void
> syscall_get_arguments(struct task_struct *task, struct pt_regs *regs,
>                       unsigned long *args)
> {
>         memcpy(args, &regs->d1, 6 * sizeof(args[0]));
> }
>
> [1] https://lore.kernel.org/lkml/20190328230512.486297455@goodmis.org/

Yeah, no longer a need for all these ugly checks, good.

Gr{oetje,eeting}s,

                        Geert

-- 
Geert Uytterhoeven -- There's lots of Linux beyond ia32 -- geert@linux-m68k.org

In personal conversations with technical people, I call myself a hacker. But
when I'm talking to journalists I just say "programmer" or something like that.
                                -- Linus Torvalds

^ permalink raw reply	[flat|nested] 65+ messages in thread

end of thread, other threads:[~2019-03-30 20:58 UTC | newest]

Thread overview: 65+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
     [not found] <20181210042352.GA6092@altlinux.org>
2018-12-10  4:27 ` [PATCH v5 01/25] alpha: define remaining syscall_get_* functions Dmitry V. Levin
2018-12-10  4:28 ` [PATCH v5 02/25] Move EM_ARCOMPACT and EM_ARCV2 to uapi/linux/elf-em.h Dmitry V. Levin
2018-12-10  4:29 ` [PATCH v5 03/25] arc: define syscall_get_arch() Dmitry V. Levin
2018-12-10  4:29 ` [PATCH v5 04/25] c6x: " Dmitry V. Levin
2018-12-11 22:40   ` Mark Salter
2018-12-10  4:29 ` [PATCH v5 05/25] elf-em.h: add EM_CSKY Dmitry V. Levin
2018-12-10  4:29 ` [PATCH v5 06/25] csky: define syscall_get_arch() Dmitry V. Levin
2018-12-10  4:29 ` [PATCH v5 07/25] h8300: define remaining syscall_get_* functions Dmitry V. Levin
2018-12-10  4:29 ` [PATCH v5 08/25] Move EM_HEXAGON to uapi/linux/elf-em.h Dmitry V. Levin
2018-12-10  4:29 ` [PATCH v5 09/25] hexagon: define remaining syscall_get_* functions Dmitry V. Levin
2018-12-10  4:29 ` [PATCH v5 10/25] Move EM_NDS32 to uapi/linux/elf-em.h Dmitry V. Levin
2018-12-10  4:29 ` [PATCH v5 11/25] nds32: define syscall_get_arch() Dmitry V. Levin
2018-12-10  4:30 ` [PATCH v5 12/25] nios2: " Dmitry V. Levin
2018-12-10  4:30 ` [PATCH v5 13/25] m68k: add asm/syscall.h Dmitry V. Levin
2018-12-10  8:45   ` Geert Uytterhoeven
2018-12-10 12:40     ` Dmitry V. Levin
2018-12-10 13:06       ` Geert Uytterhoeven
2018-12-10 13:30         ` Dmitry V. Levin
2018-12-12  8:55           ` Dmitry V. Levin
2018-12-12  9:01             ` Geert Uytterhoeven
2018-12-12  9:27               ` Dmitry V. Levin
2018-12-12  9:43                 ` Geert Uytterhoeven
2018-12-12 12:04                   ` Dmitry V. Levin
2018-12-12 12:27                     ` Geert Uytterhoeven
2018-12-12 12:37                       ` Dmitry V. Levin
2018-12-12 12:54                         ` Geert Uytterhoeven
2018-12-12 13:07                           ` Dmitry V. Levin
2018-12-12 23:12                             ` Dmitry V. Levin
2019-03-29 22:04             ` Dmitry V. Levin
2019-03-30 20:57               ` Geert Uytterhoeven
2018-12-10  4:30 ` [PATCH v5 14/25] mips: define syscall_get_error() Dmitry V. Levin
2018-12-10  4:30 ` [PATCH v5 15/25] parisc: " Dmitry V. Levin
2018-12-10  4:30 ` [PATCH v5 16/25] powerpc: " Dmitry V. Levin
2018-12-10  4:30 ` [PATCH v5 17/25] riscv: define syscall_get_arch() Dmitry V. Levin
2018-12-10  4:30 ` [PATCH v5 18/25] Move EM_XTENSA to uapi/linux/elf-em.h Dmitry V. Levin
2018-12-10  4:30 ` [PATCH v5 19/25] xtensa: define syscall_get_* functions Dmitry V. Levin
2018-12-10  5:02   ` Max Filippov
2018-12-10 12:53     ` Dmitry V. Levin
2018-12-10 20:14       ` Max Filippov
2018-12-10 20:24         ` Dmitry V. Levin
2018-12-10 20:30           ` Dmitry V. Levin
2018-12-10 21:29             ` Max Filippov
2018-12-12 10:45   ` kbuild test robot
2018-12-19  5:58   ` kbuild test robot
2018-12-10  4:30 ` [PATCH v5 20/25] Move EM_UNICORE to uapi/linux/elf-em.h Dmitry V. Levin
2018-12-10  4:30 ` [PATCH v5 21/25] unicore32: add asm/syscall.h Dmitry V. Levin
2018-12-10  4:31 ` [PATCH v5 22/25] syscall_get_arch: add "struct task_struct *" argument Dmitry V. Levin
2018-12-10 17:29   ` Kees Cook
2018-12-11 22:44   ` Mark Salter
2018-12-10  4:31 ` [PATCH v5 23/25] powerpc/ptrace: replace ptrace_report_syscall() with a tracehook call Dmitry V. Levin
2018-12-10  4:31 ` [PATCH v5 24/25] ptrace: add PTRACE_GET_SYSCALL_INFO request Dmitry V. Levin
2018-12-10 14:11   ` Oleg Nesterov
2018-12-10 16:21     ` Dmitry V. Levin
2018-12-11 15:29       ` Oleg Nesterov
2018-12-11 16:23         ` Dmitry V. Levin
2018-12-11 20:27           ` Dmitry V. Levin
2018-12-12 18:00             ` Oleg Nesterov
2018-12-10 14:26   ` kbuild test robot
2018-12-10 16:09     ` Dmitry V. Levin
2018-12-10 18:04       ` Paul Burton
2018-12-10 21:04         ` Palmer Dabbelt
2018-12-10 19:38       ` Andy Lutomirski
2018-12-10 17:44   ` Kees Cook
2018-12-12  9:28   ` kbuild test robot
2018-12-10  4:31 ` [PATCH v5 25/25] selftests/ptrace: add a test case for PTRACE_GET_SYSCALL_INFO Dmitry V. Levin

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).