Re: strace for m68k bpf_prog_info mismatch

2019-05-03 Thread Dmitry V. Levin
Hi Geert,

On Fri, May 03, 2019 at 09:04:17AM +0200, Geert Uytterhoeven wrote:
> Hi Baruch,
> 
> On Fri, May 3, 2019 at 6:06 AM Baruch Siach  wrote:
> > strace 5.0 fails to build for m86k/5208 with the Buildroot generated
> > toolchain:
> >
> > In file included from bpf_attr_check.c:6:0:
> > static_assert.h:20:25: error: static assertion failed: 
> > "bpf_prog_info_struct.nr_jited_ksyms offset mismatch"
> >  #  define static_assert _Static_assert
> >  ^
> > bpf_attr_check.c:913:2: note: in expansion of macro ‘static_assert’
> >   static_assert(offsetof(struct bpf_prog_info_struct, nr_jited_ksyms) == 
> > offsetof(struct bpf_prog_info, nr_jited_ksyms),
> >   ^
> >
> > The direct cause is a difference in the hole after the gpl_compatible
> > field. Here is pahole output for the kernel struct (from v4.19):
> >
> > struct bpf_prog_info {
> > ...
> > __u32  ifindex;  /*80 4 */
> > __u32  gpl_compatible:1; /*84: 0  4 */
> >
> > /* XXX 15 bits hole, try to pack */
> > /* Bitfield combined with next fields */
> >
> > __u64  netns_dev;/*86 8 */
> 
> I guess that should be "__aligned_u64 netns_dev;", to not rely on
> implicit alignment.

This is exactly the fix we suggested a year ago in
https://lore.kernel.org/lkml/20180527112842.ga18...@asgard.redhat.com/T/#u
when the issue arose for the first time, but, unfortunately,
bpf maintainers took a more error-prone approach.

I suppose our initial fix is still applicable.

> > And this is for the strace struct:
> >
> > struct bpf_prog_info_struct {
> > ...
> > uint32_t   ifindex;  /*80 4 */
> > uint32_t   gpl_compatible:1; /*84: 0  4 */
> >
> > /* XXX 31 bits hole, try to pack */
> 
> How come the uint64_t below is 8-byte aligned, not 2-byte aligned?
> Does strace use a special definition of uint64_t?
> 
> >
> > uint64_t   netns_dev;/*88 8 */
> >
> > How should this be fixed?
> 
> IMHO all "__u64" in structs tagged "__attribute__((aligned(8)))" should
> be replaced by "__aligned_u64", which is what the (whitespace-damaged)
> diff below does.

This is the approach taken in strace, see e.g.
https://gitlab.com/strace/strace/blob/master/bpf_attr.h#L13

When  in the kernel fails to set proper offsets,
a static assertion in strace is triggered.


-- 
ldv


signature.asc
Description: PGP signature


Re: [PATCH v5 13/25] m68k: add asm/syscall.h

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

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


-- 
ldv


signature.asc
Description: PGP signature


[PATCH v2 13/13] syscall_get_arch: add "struct task_struct *" argument

2019-03-17 Thread Dmitry V. Levin
This argument is required to extend the generic ptrace API with
PTRACE_GET_SYSCALL_INFO request: syscall_get_arch() is going
to be called from ptrace_request() along with syscall_get_nr(),
syscall_get_arguments(), syscall_get_error(), and
syscall_get_return_value() functions with a tracee as their argument.

The primary intent is that the triple (audit_arch, syscall_nr, arg1..arg6)
should describe what system call is being called and what its arguments
are.

Reverts: 5e937a9ae913 ("syscall_get_arch: remove useless function arguments")
Reverts: 1002d94d3076 ("syscall.h: fix doc text for syscall_get_arch()")
Reviewed-by: Andy Lutomirski  # for x86
Reviewed-by: Palmer Dabbelt 
Acked-by: Paul Moore 
Acked-by: Paul Burton  # MIPS parts
Acked-by: Michael Ellerman  (powerpc)
Acked-by: Kees Cook  # seccomp parts
Acked-by: Mark Salter  # for the c6x bit
Cc: Elvira Khabirova 
Cc: Eugene Syromyatnikov 
Cc: Oleg Nesterov 
Cc: x...@kernel.org
Cc: linux-al...@vger.kernel.org
Cc: linux-snps-...@lists.infradead.org
Cc: linux-arm-ker...@lists.infradead.org
Cc: linux-c6x-...@linux-c6x.org
Cc: uclinux-h8-de...@lists.sourceforge.jp
Cc: linux-hexa...@vger.kernel.org
Cc: linux-i...@vger.kernel.org
Cc: linux-m...@lists.linux-m68k.org
Cc: linux-m...@vger.kernel.org
Cc: nios2-...@lists.rocketboards.org
Cc: openr...@lists.librecores.org
Cc: linux-par...@vger.kernel.org
Cc: linuxppc-...@lists.ozlabs.org
Cc: linux-ri...@lists.infradead.org
Cc: linux-s...@vger.kernel.org
Cc: linux...@vger.kernel.org
Cc: sparcli...@vger.kernel.org
Cc: linux...@lists.infradead.org
Cc: linux-xte...@linux-xtensa.org
Cc: linux-a...@vger.kernel.org
Cc: linux-au...@redhat.com
Signed-off-by: Dmitry V. Levin 
---

Notes:
v2: unchanged

 arch/alpha/include/asm/syscall.h  |  2 +-
 arch/arc/include/asm/syscall.h|  2 +-
 arch/arm/include/asm/syscall.h|  2 +-
 arch/arm64/include/asm/syscall.h  |  4 ++--
 arch/c6x/include/asm/syscall.h|  2 +-
 arch/csky/include/asm/syscall.h   |  2 +-
 arch/h8300/include/asm/syscall.h  |  2 +-
 arch/hexagon/include/asm/syscall.h|  2 +-
 arch/ia64/include/asm/syscall.h   |  2 +-
 arch/m68k/include/asm/syscall.h   |  2 +-
 arch/microblaze/include/asm/syscall.h |  2 +-
 arch/mips/include/asm/syscall.h   |  6 +++---
 arch/mips/kernel/ptrace.c |  2 +-
 arch/nds32/include/asm/syscall.h  |  2 +-
 arch/nios2/include/asm/syscall.h  |  2 +-
 arch/openrisc/include/asm/syscall.h   |  2 +-
 arch/parisc/include/asm/syscall.h |  4 ++--
 arch/powerpc/include/asm/syscall.h| 10 --
 arch/riscv/include/asm/syscall.h  |  2 +-
 arch/s390/include/asm/syscall.h   |  4 ++--
 arch/sh/include/asm/syscall_32.h  |  2 +-
 arch/sh/include/asm/syscall_64.h  |  2 +-
 arch/sparc/include/asm/syscall.h  |  5 +++--
 arch/unicore32/include/asm/syscall.h  |  2 +-
 arch/x86/include/asm/syscall.h|  8 +---
 arch/x86/um/asm/syscall.h |  2 +-
 arch/xtensa/include/asm/syscall.h |  2 +-
 include/asm-generic/syscall.h |  5 +++--
 kernel/auditsc.c  |  4 ++--
 kernel/seccomp.c  |  4 ++--
 30 files changed, 52 insertions(+), 42 deletions(-)

diff --git a/arch/alpha/include/asm/syscall.h b/arch/alpha/include/asm/syscall.h
index d73a6fcb519c..11c688c1d7ec 100644
--- a/arch/alpha/include/asm/syscall.h
+++ b/arch/alpha/include/asm/syscall.h
@@ -4,7 +4,7 @@
 
 #include 
 
-static inline int syscall_get_arch(void)
+static inline int syscall_get_arch(struct task_struct *task)
 {
return AUDIT_ARCH_ALPHA;
 }
diff --git a/arch/arc/include/asm/syscall.h b/arch/arc/include/asm/syscall.h
index c7fc4c0c3bcb..caf2697ef5b7 100644
--- a/arch/arc/include/asm/syscall.h
+++ b/arch/arc/include/asm/syscall.h
@@ -70,7 +70,7 @@ syscall_get_arguments(struct task_struct *task, struct 
pt_regs *regs,
 }
 
 static inline int
-syscall_get_arch(void)
+syscall_get_arch(struct task_struct *task)
 {
return IS_ENABLED(CONFIG_ISA_ARCOMPACT)
? (IS_ENABLED(CONFIG_CPU_BIG_ENDIAN)
diff --git a/arch/arm/include/asm/syscall.h b/arch/arm/include/asm/syscall.h
index 06dea6bce293..3940ceac0bdc 100644
--- a/arch/arm/include/asm/syscall.h
+++ b/arch/arm/include/asm/syscall.h
@@ -104,7 +104,7 @@ static inline void syscall_set_arguments(struct task_struct 
*task,
memcpy(>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
  * AArc

[PATCH v2 07/13] m68k: define syscall_get_arch()

2019-03-17 Thread Dmitry V. Levin
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.

Reviewed-by: Geert Uytterhoeven 
Acked-by: Paul Moore 
Cc: Elvira Khabirova 
Cc: Eugene Syromyatnikov 
Cc: Oleg Nesterov 
Cc: Andy Lutomirski 
Cc: linux-m...@lists.linux-m68k.org
Cc: linux-au...@redhat.com
Signed-off-by: Dmitry V. Levin 
---

Notes:
v2: unchanged

 arch/m68k/include/asm/syscall.h | 12 
 1 file changed, 12 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 ..d4d7deda8d50
--- /dev/null
+++ b/arch/m68k/include/asm/syscall.h
@@ -0,0 +1,12 @@
+/* SPDX-License-Identifier: GPL-2.0 */
+#ifndef _ASM_M68K_SYSCALL_H
+#define _ASM_M68K_SYSCALL_H
+
+#include 
+
+static inline int syscall_get_arch(void)
+{
+   return AUDIT_ARCH_M68K;
+}
+
+#endif /* _ASM_M68K_SYSCALL_H */
-- 
ldv


[PATCH 14/14] syscall_get_arch: add "struct task_struct *" argument

2019-01-09 Thread Dmitry V. Levin
This argument is required to extend the generic ptrace API with
PTRACE_GET_SYSCALL_INFO request: syscall_get_arch() is going
to be called from ptrace_request() along with syscall_get_nr(),
syscall_get_arguments(), syscall_get_error(), and
syscall_get_return_value() functions with a tracee as their argument.

The primary intent is that the triple (audit_arch, syscall_nr, arg1..arg6)
should describe what system call is being called and what its arguments
are.

Reverts: 5e937a9ae913 ("syscall_get_arch: remove useless function arguments")
Reverts: 1002d94d3076 ("syscall.h: fix doc text for syscall_get_arch()")
Reviewed-by: Andy Lutomirski  # for x86
Reviewed-by: Palmer Dabbelt 
Acked-by: Paul Moore 
Acked-by: Paul Burton  # MIPS parts
Acked-by: Michael Ellerman  (powerpc)
Acked-by: Kees Cook  # seccomp parts
Acked-by: Mark Salter  # for the c6x bit
Cc: Elvira Khabirova 
Cc: Eugene Syromyatnikov 
Cc: Oleg Nesterov 
Cc: x...@kernel.org
Cc: linux-al...@vger.kernel.org
Cc: linux-snps-...@lists.infradead.org
Cc: linux-arm-ker...@lists.infradead.org
Cc: linux-c6x-...@linux-c6x.org
Cc: uclinux-h8-de...@lists.sourceforge.jp
Cc: linux-hexa...@vger.kernel.org
Cc: linux-i...@vger.kernel.org
Cc: linux-m...@lists.linux-m68k.org
Cc: linux-m...@vger.kernel.org
Cc: nios2-...@lists.rocketboards.org
Cc: openr...@lists.librecores.org
Cc: linux-par...@vger.kernel.org
Cc: linuxppc-...@lists.ozlabs.org
Cc: linux-ri...@lists.infradead.org
Cc: linux-s...@vger.kernel.org
Cc: linux...@vger.kernel.org
Cc: sparcli...@vger.kernel.org
Cc: linux...@lists.infradead.org
Cc: linux-xte...@linux-xtensa.org
Cc: linux-a...@vger.kernel.org
Cc: linux-au...@redhat.com
Signed-off-by: Dmitry V. Levin 
---
 arch/alpha/include/asm/syscall.h  |  2 +-
 arch/arc/include/asm/syscall.h|  2 +-
 arch/arm/include/asm/syscall.h|  2 +-
 arch/arm64/include/asm/syscall.h  |  4 ++--
 arch/c6x/include/asm/syscall.h|  2 +-
 arch/csky/include/asm/syscall.h   |  2 +-
 arch/h8300/include/asm/syscall.h  |  2 +-
 arch/hexagon/include/asm/syscall.h|  2 +-
 arch/ia64/include/asm/syscall.h   |  2 +-
 arch/m68k/include/asm/syscall.h   |  2 +-
 arch/microblaze/include/asm/syscall.h |  2 +-
 arch/mips/include/asm/syscall.h   |  6 +++---
 arch/mips/kernel/ptrace.c |  2 +-
 arch/nds32/include/asm/syscall.h  |  2 +-
 arch/nios2/include/asm/syscall.h  |  2 +-
 arch/openrisc/include/asm/syscall.h   |  2 +-
 arch/parisc/include/asm/syscall.h |  4 ++--
 arch/powerpc/include/asm/syscall.h| 10 --
 arch/riscv/include/asm/syscall.h  |  2 +-
 arch/s390/include/asm/syscall.h   |  4 ++--
 arch/sh/include/asm/syscall_32.h  |  2 +-
 arch/sh/include/asm/syscall_64.h  |  2 +-
 arch/sparc/include/asm/syscall.h  |  5 +++--
 arch/unicore32/include/asm/syscall.h  |  2 +-
 arch/x86/include/asm/syscall.h|  8 +---
 arch/x86/um/asm/syscall.h |  2 +-
 arch/xtensa/include/asm/syscall.h |  2 +-
 include/asm-generic/syscall.h |  5 +++--
 kernel/auditsc.c  |  4 ++--
 kernel/seccomp.c  |  4 ++--
 30 files changed, 52 insertions(+), 42 deletions(-)

diff --git a/arch/alpha/include/asm/syscall.h b/arch/alpha/include/asm/syscall.h
index d73a6fcb519c..11c688c1d7ec 100644
--- a/arch/alpha/include/asm/syscall.h
+++ b/arch/alpha/include/asm/syscall.h
@@ -4,7 +4,7 @@
 
 #include 
 
-static inline int syscall_get_arch(void)
+static inline int syscall_get_arch(struct task_struct *task)
 {
return AUDIT_ARCH_ALPHA;
 }
diff --git a/arch/arc/include/asm/syscall.h b/arch/arc/include/asm/syscall.h
index c7fc4c0c3bcb..caf2697ef5b7 100644
--- a/arch/arc/include/asm/syscall.h
+++ b/arch/arc/include/asm/syscall.h
@@ -70,7 +70,7 @@ syscall_get_arguments(struct task_struct *task, struct 
pt_regs *regs,
 }
 
 static inline int
-syscall_get_arch(void)
+syscall_get_arch(struct task_struct *task)
 {
return IS_ENABLED(CONFIG_ISA_ARCOMPACT)
? (IS_ENABLED(CONFIG_CPU_BIG_ENDIAN)
diff --git a/arch/arm/include/asm/syscall.h b/arch/arm/include/asm/syscall.h
index 06dea6bce293..3940ceac0bdc 100644
--- a/arch/arm/include/asm/syscall.h
+++ b/arch/arm/include/asm/syscall.h
@@ -104,7 +104,7 @@ static inline void syscall_set_arguments(struct task_struct 
*task,
memcpy(>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 syst

[PATCH 07/14] m68k: define syscall_get_arch()

2019-01-09 Thread Dmitry V. Levin
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.

Reviewed-by: Geert Uytterhoeven 
Acked-by: Paul Moore 
Cc: Elvira Khabirova 
Cc: Eugene Syromyatnikov 
Cc: Oleg Nesterov 
Cc: Andy Lutomirski 
Cc: linux-m...@lists.linux-m68k.org
Cc: linux-au...@redhat.com
Signed-off-by: Dmitry V. Levin 
---
 arch/m68k/include/asm/syscall.h | 12 
 1 file changed, 12 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 ..d4d7deda8d50
--- /dev/null
+++ b/arch/m68k/include/asm/syscall.h
@@ -0,0 +1,12 @@
+/* SPDX-License-Identifier: GPL-2.0 */
+#ifndef _ASM_M68K_SYSCALL_H
+#define _ASM_M68K_SYSCALL_H
+
+#include 
+
+static inline int syscall_get_arch(void)
+{
+   return AUDIT_ARCH_M68K;
+}
+
+#endif /* _ASM_M68K_SYSCALL_H */
-- 
ldv


[PATCH v7 20/22] syscall_get_arch: add "struct task_struct *" argument

2019-01-06 Thread Dmitry V. Levin
This argument is required to extend the generic ptrace API with
PTRACE_GET_SYSCALL_INFO request: syscall_get_arch() is going
to be called from ptrace_request() along with syscall_get_nr(),
syscall_get_arguments(), syscall_get_error(), and
syscall_get_return_value() functions with a tracee as their argument.

Reverts: 5e937a9ae913 ("syscall_get_arch: remove useless function arguments")
Reverts: 1002d94d3076 ("syscall.h: fix doc text for syscall_get_arch()")
Reviewed-by: Andy Lutomirski  # for x86
Reviewed-by: Palmer Dabbelt 
Acked-by: Paul Burton  # MIPS parts
Acked-by: Michael Ellerman  (powerpc)
Acked-by: Kees Cook  # seccomp parts
Acked-by: Mark Salter  # for the c6x bit
Acked-by: Paul Moore  # audit related parts
Cc: Eric Paris 
Cc: Richard Henderson 
Cc: Ivan Kokshaysky 
Cc: Matt Turner 
Cc: Vineet Gupta 
Cc: Russell King 
Cc: Catalin Marinas 
Cc: Will Deacon 
Cc: Aurelien Jacquiot 
Cc: Yoshinori Sato 
Cc: Richard Kuo 
Cc: Tony Luck 
Cc: Fenghua Yu 
Cc: Geert Uytterhoeven 
Cc: Michal Simek 
Cc: Greentime Hu 
Cc: Vincent Chen 
Cc: Ley Foon Tan 
Cc: Jonas Bonn 
Cc: Stefan Kristiansson 
Cc: Stafford Horne 
Cc: James E.J. Bottomley 
Cc: Helge Deller 
Cc: Albert Ou 
Cc: Martin Schwidefsky 
Cc: Heiko Carstens 
Cc: Rich Felker 
Cc: David S. Miller 
Cc: Guan Xuetao 
Cc: Jeff Dike 
Cc: Richard Weinberger 
Cc: Chris Zankel 
Cc: Max Filippov 
Cc: Arnd Bergmann 
Cc: Will Drewry 
Cc: Oleg Nesterov 
Cc: Elvira Khabirova 
Cc: Eugene Syromyatnikov 
Cc: Ralf Baechle 
Cc: James Hogan 
Cc: Benjamin Herrenschmidt 
Cc: Paul Mackerras 
Cc: Thomas Gleixner 
Cc: Ingo Molnar 
Cc: Borislav Petkov 
Cc: H. Peter Anvin 
Cc: x...@kernel.org
Cc: linux-al...@vger.kernel.org
Cc: linux-snps-...@lists.infradead.org
Cc: linux-arm-ker...@lists.infradead.org
Cc: linux-c6x-...@linux-c6x.org
Cc: uclinux-h8-de...@lists.sourceforge.jp
Cc: linux-hexa...@vger.kernel.org
Cc: linux-i...@vger.kernel.org
Cc: linux-m...@lists.linux-m68k.org
Cc: linux-m...@vger.kernel.org
Cc: nios2-...@lists.rocketboards.org
Cc: openr...@lists.librecores.org
Cc: linux-par...@vger.kernel.org
Cc: linuxppc-...@lists.ozlabs.org
Cc: linux-ri...@lists.infradead.org
Cc: linux-s...@vger.kernel.org
Cc: linux...@vger.kernel.org
Cc: sparcli...@vger.kernel.org
Cc: linux...@lists.infradead.org
Cc: linux-xte...@linux-xtensa.org
Cc: linux-a...@vger.kernel.org
Cc: linux-au...@redhat.com
Signed-off-by: Dmitry V. Levin 
---

Notes:
v7: added more Acked-by
v6: added more Acked-by
v5: added Cc
v2: cleaned up mips part, added Reviewed-by

 arch/alpha/include/asm/syscall.h  |  2 +-
 arch/arc/include/asm/syscall.h|  2 +-
 arch/arm/include/asm/syscall.h|  2 +-
 arch/arm64/include/asm/syscall.h  |  4 ++--
 arch/c6x/include/asm/syscall.h|  2 +-
 arch/csky/include/asm/syscall.h   |  2 +-
 arch/h8300/include/asm/syscall.h  |  2 +-
 arch/hexagon/include/asm/syscall.h|  2 +-
 arch/ia64/include/asm/syscall.h   |  2 +-
 arch/m68k/include/asm/syscall.h   |  2 +-
 arch/microblaze/include/asm/syscall.h |  2 +-
 arch/mips/include/asm/syscall.h   |  6 +++---
 arch/mips/kernel/ptrace.c |  2 +-
 arch/nds32/include/asm/syscall.h  |  2 +-
 arch/nios2/include/asm/syscall.h  |  2 +-
 arch/openrisc/include/asm/syscall.h   |  2 +-
 arch/parisc/include/asm/syscall.h |  4 ++--
 arch/powerpc/include/asm/syscall.h| 10 --
 arch/riscv/include/asm/syscall.h  |  2 +-
 arch/s390/include/asm/syscall.h   |  4 ++--
 arch/sh/include/asm/syscall_32.h  |  2 +-
 arch/sh/include/asm/syscall_64.h  |  2 +-
 arch/sparc/include/asm/syscall.h  |  5 +++--
 arch/unicore32/include/asm/syscall.h  |  2 +-
 arch/x86/include/asm/syscall.h|  8 +---
 arch/x86/um/asm/syscall.h |  2 +-
 arch/xtensa/include/asm/syscall.h |  2 +-
 include/asm-generic/syscall.h |  5 +++--
 kernel/auditsc.c  |  4 ++--
 kernel/seccomp.c  |  4 ++--
 30 files changed, 52 insertions(+), 42 deletions(-)

diff --git a/arch/alpha/include/asm/syscall.h b/arch/alpha/include/asm/syscall.h
index c67d6a69d7c8..20078aef0922 100644
--- a/arch/alpha/include/asm/syscall.h
+++ b/arch/alpha/include/asm/syscall.h
@@ -33,7 +33,7 @@ syscall_get_return_value(struct task_struct *task, struct 
pt_regs *regs)
 }
 
 static inline int
-syscall_get_arch(void)
+syscall_get_arch(struct task_struct *task)
 {
return AUDIT_ARCH_ALPHA;
 }
diff --git a/arch/arc/include/asm/syscall.h b/arch/arc/include/asm/syscall.h
index c7fc4c0c3bcb..caf2697ef5b7 100644
--- a/arch/arc/include/asm/syscall.h
+++ b/arch/arc/include/asm/syscall.h
@@ -70,7 +70,7 @@ syscall_get_arguments(struct task_struct *task, struct 
pt_regs *regs,
 }
 
 static inline int
-syscall_get_arch(void)
+syscall_get_arch(struct task_struct *task)
 {
return IS_ENABLED(CONFIG_ISA_ARCOMPACT)
? (IS_ENABLED(CONFIG_CPU_BIG_ENDIAN)
diff --git a/arch/arm/include/asm/syscall.h b/arch/arm/include

[PATCH v7 13/22] m68k: add asm/syscall.h

2019-01-06 Thread Dmitry V. Levin
syscall_get_* functions are required to be implemented on all
architectures in order to extend the generic ptrace API with
PTRACE_GET_SYSCALL_INFO request.

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

Acked-by: Paul Moore  # audit related parts
Cc: Geert Uytterhoeven 
Cc: Oleg Nesterov 
Cc: Andy Lutomirski 
Cc: Elvira Khabirova 
Cc: Eugene Syromyatnikov 
Cc: linux-m...@lists.linux-m68k.org
Signed-off-by: Dmitry V. Levin 
---

Notes:
v7: added Acked-by
v6: added missing includes, use asm-generic/syscall.h
v5: added syscall_get_nr, syscall_get_arguments, syscall_get_error,
and syscall_get_return_value
v1: added syscall_get_arch

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

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


[PATCH v6 24/27] syscall_get_arch: add "struct task_struct *" argument

2018-12-13 Thread Dmitry V. Levin
This argument is required to extend the generic ptrace API with
PTRACE_GET_SYSCALL_INFO request: syscall_get_arch() is going
to be called from ptrace_request() along with syscall_get_nr(),
syscall_get_arguments(), syscall_get_error(), and
syscall_get_return_value() functions with a tracee as their argument.

Reverts: 5e937a9ae913 ("syscall_get_arch: remove useless function arguments")
Reverts: 1002d94d3076 ("syscall.h: fix doc text for syscall_get_arch()")
Reviewed-by: Andy Lutomirski  # for x86
Reviewed-by: Palmer Dabbelt 
Acked-by: Paul Burton  # MIPS parts
Acked-by: Michael Ellerman  (powerpc)
Acked-by: Kees Cook  # seccomp parts
Acked-by: Mark Salter  # for the c6x bit
Cc: Eric Paris 
Cc: Paul Moore 
Cc: Richard Henderson 
Cc: Ivan Kokshaysky 
Cc: Matt Turner 
Cc: Vineet Gupta 
Cc: Russell King 
Cc: Catalin Marinas 
Cc: Will Deacon 
Cc: Aurelien Jacquiot 
Cc: Yoshinori Sato 
Cc: Richard Kuo 
Cc: Tony Luck 
Cc: Fenghua Yu 
Cc: Geert Uytterhoeven 
Cc: Michal Simek 
Cc: Greentime Hu 
Cc: Vincent Chen 
Cc: Ley Foon Tan 
Cc: Jonas Bonn 
Cc: Stefan Kristiansson 
Cc: Stafford Horne 
Cc: James E.J. Bottomley 
Cc: Helge Deller 
Cc: Albert Ou 
Cc: Martin Schwidefsky 
Cc: Heiko Carstens 
Cc: Rich Felker 
Cc: David S. Miller 
Cc: Guan Xuetao 
Cc: Jeff Dike 
Cc: Richard Weinberger 
Cc: Chris Zankel 
Cc: Max Filippov 
Cc: Arnd Bergmann 
Cc: Will Drewry 
Cc: Oleg Nesterov 
Cc: Elvira Khabirova 
Cc: Eugene Syromyatnikov 
Cc: Ralf Baechle 
Cc: James Hogan 
Cc: Benjamin Herrenschmidt 
Cc: Paul Mackerras 
Cc: Thomas Gleixner 
Cc: Ingo Molnar 
Cc: Borislav Petkov 
Cc: H. Peter Anvin 
Cc: x...@kernel.org
Cc: linux-al...@vger.kernel.org
Cc: linux-snps-...@lists.infradead.org
Cc: linux-arm-ker...@lists.infradead.org
Cc: linux-c6x-...@linux-c6x.org
Cc: uclinux-h8-de...@lists.sourceforge.jp
Cc: linux-hexa...@vger.kernel.org
Cc: linux-i...@vger.kernel.org
Cc: linux-m...@lists.linux-m68k.org
Cc: linux-m...@vger.kernel.org
Cc: nios2-...@lists.rocketboards.org
Cc: openr...@lists.librecores.org
Cc: linux-par...@vger.kernel.org
Cc: linuxppc-...@lists.ozlabs.org
Cc: linux-ri...@lists.infradead.org
Cc: linux-s...@vger.kernel.org
Cc: linux...@vger.kernel.org
Cc: sparcli...@vger.kernel.org
Cc: linux...@lists.infradead.org
Cc: linux-xte...@linux-xtensa.org
Cc: linux-a...@vger.kernel.org
Cc: linux-au...@redhat.com
Signed-off-by: Dmitry V. Levin 
---

Notes:
v6: added more Acked-by
v5: added Cc
v2: cleaned up mips part, added Reviewed-by

 arch/alpha/include/asm/syscall.h  |  2 +-
 arch/arc/include/asm/syscall.h|  2 +-
 arch/arm/include/asm/syscall.h|  2 +-
 arch/arm64/include/asm/syscall.h  |  4 ++--
 arch/c6x/include/asm/syscall.h|  2 +-
 arch/csky/include/asm/syscall.h   |  2 +-
 arch/h8300/include/asm/syscall.h  |  2 +-
 arch/hexagon/include/asm/syscall.h|  2 +-
 arch/ia64/include/asm/syscall.h   |  2 +-
 arch/m68k/include/asm/syscall.h   |  2 +-
 arch/microblaze/include/asm/syscall.h |  2 +-
 arch/mips/include/asm/syscall.h   |  6 +++---
 arch/mips/kernel/ptrace.c |  2 +-
 arch/nds32/include/asm/syscall.h  |  2 +-
 arch/nios2/include/asm/syscall.h  |  2 +-
 arch/openrisc/include/asm/syscall.h   |  2 +-
 arch/parisc/include/asm/syscall.h |  4 ++--
 arch/powerpc/include/asm/syscall.h| 10 --
 arch/riscv/include/asm/syscall.h  |  2 +-
 arch/s390/include/asm/syscall.h   |  4 ++--
 arch/sh/include/asm/syscall_32.h  |  2 +-
 arch/sh/include/asm/syscall_64.h  |  2 +-
 arch/sparc/include/asm/syscall.h  |  5 +++--
 arch/unicore32/include/asm/syscall.h  |  2 +-
 arch/x86/include/asm/syscall.h|  8 +---
 arch/x86/um/asm/syscall.h |  2 +-
 arch/xtensa/include/asm/syscall.h |  2 +-
 include/asm-generic/syscall.h |  5 +++--
 kernel/auditsc.c  |  4 ++--
 kernel/seccomp.c  |  4 ++--
 30 files changed, 52 insertions(+), 42 deletions(-)

diff --git a/arch/alpha/include/asm/syscall.h b/arch/alpha/include/asm/syscall.h
index c67d6a69d7c8..20078aef0922 100644
--- a/arch/alpha/include/asm/syscall.h
+++ b/arch/alpha/include/asm/syscall.h
@@ -33,7 +33,7 @@ syscall_get_return_value(struct task_struct *task, struct 
pt_regs *regs)
 }
 
 static inline int
-syscall_get_arch(void)
+syscall_get_arch(struct task_struct *task)
 {
return AUDIT_ARCH_ALPHA;
 }
diff --git a/arch/arc/include/asm/syscall.h b/arch/arc/include/asm/syscall.h
index c7fc4c0c3bcb..caf2697ef5b7 100644
--- a/arch/arc/include/asm/syscall.h
+++ b/arch/arc/include/asm/syscall.h
@@ -70,7 +70,7 @@ syscall_get_arguments(struct task_struct *task, struct 
pt_regs *regs,
 }
 
 static inline int
-syscall_get_arch(void)
+syscall_get_arch(struct task_struct *task)
 {
return IS_ENABLED(CONFIG_ISA_ARCOMPACT)
? (IS_ENABLED(CONFIG_CPU_BIG_ENDIAN)
diff --git a/arch/arm/include/asm/syscall.h b/arch/arm/include/asm/syscall.h
index 06dea6bce293..3940ceac0bdc 100644
--

[PATCH v6 15/27] m68k: add asm/syscall.h

2018-12-13 Thread Dmitry V. Levin
syscall_get_* functions are required to be implemented on all
architectures in order to extend the generic ptrace API with
PTRACE_GET_SYSCALL_INFO request.

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

Cc: Geert Uytterhoeven 
Cc: Oleg Nesterov 
Cc: Andy Lutomirski 
Cc: Elvira Khabirova 
Cc: Eugene Syromyatnikov 
Cc: linux-m...@lists.linux-m68k.org
Signed-off-by: Dmitry V. Levin 
---

Notes:
v6: added missing includes, use asm-generic/syscall.h
v5: added syscall_get_nr, syscall_get_arguments, syscall_get_error,
and syscall_get_return_value
v1: added syscall_get_arch

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

diff --git a/arch/m68k/include/asm/syscall.h b/arch/m68k/include/asm/syscall.h
new file mode 100644
index ..c87b14417753
--- /dev/null
+++ b/arch/m68k/include/asm/syscall.h
@@ -0,0 +1,42 @@
+/* SPDX-License-Identifier: GPL-2.0 */
+#ifndef _ASM_M68K_SYSCALL_H
+#define _ASM_M68K_SYSCALL_H
+
+#include 
+#include 
+#include 
+#include 
+
+static inline int
+syscall_get_nr(struct task_struct *task, struct pt_regs *regs)
+{
+   return regs->orig_d0;
+}
+
+static inline void
+__syscall_get_arguments(struct task_struct *task, struct pt_regs *regs,
+   unsigned int i, unsigned int n, unsigned long *args)
+{
+   BUILD_BUG_ON(sizeof(regs->d1) != sizeof(args[0]));
+   memcpy(args, >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


Re: [PATCH v5 13/25] m68k: add asm/syscall.h

2018-12-12 Thread Dmitry V. Levin
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  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  
> > > > 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 
> > > > > >  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 
> > > > > > > >  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 
> > > > > > > > > > >  wrote:
> > > > > > > > > > > > On Mon, Dec 10, 2018 at 09:45:42AM +0100, Geert 
> > > > > > > > > > > > Uytterhoeven wrote:
> > > > > > > > > > > > > On Mon, Dec 10, 2018 at 5:30 AM Dmitry V. Levin 
> > > > > > > > > > > > >  wrote:
> > > > > > > > > > > > > > syscall_get_* functions are required to be 
> > > > > > > > > > > > > > implemented on all
> > > > > > > > > > > > > > architectures in order to extend the generic ptrace 
> > > > > > > > > > > > > > API with
> > > > > > > > > > > > > > PTRACE_GET_SYSCALL_INFO request.
> > > > > > > > > > > > > >
> > > > > > > > > > > > > > This introduces asm/syscall.h on m68k implementing 
> > > > > > > > > > > > > > all 5 syscall_get_*
> > > > > > > > > > > > > > functions as documented in asm-generic/syscall.h: 
> > > > > > > > > > > > > > syscall_get_nr,
> > > > > > > > > > > > > > syscall_get_arguments, syscall_get_error, 
> > > > > > > > > > > > > > syscall_get_return_value,
> > > > > > > > > > > > > > and syscall_get_arch.
> > > > > > > > > > > > > >
> > > > > > > > > > > > > > Cc: Geert Uytterhoeven 
> > > > > > > > > > > > > > Cc: Oleg Nesterov 
> > > > > > > > > > > > > > Cc: Andy Lutomirski 
> > > > > > > > > > > > > > Cc: Elvira Khabirova 
> > > > > > > > > > > > > > Cc: Eugene Syromyatnikov 
> > > > > > > > > > > > > > Cc: linux-m...@lists.linux-m68k.org
> > > > > > > > > > > > > > Signed-off-by: Dmitry V. Levin 
> > > > > > > > > > > > > > ---
> > > > > > > > > > > > > >
> > > > > > > > > > > > > > Notes:
> > > > > > > > > > > > > > v5: added syscall_get_nr, 
> > > > > > > > > > > > > > syscall_get_arguments, syscall_get_error,
> > > > > > > > > > > > > > and syscall_get_return_value
> > > > > > > > > > > > > > v1: added syscall_get_arch
> > > > > > > > > > > > >
> > > > > > > > > > > > > > --- /dev/null
> > > > > > > > > > > > > > +++ b/arch/m68k/include/asm/syscall.h
> > > > > > > > > > > > > > @@ -0,0 +1,39 @@
> > > > > > > > > > > > >
> > > > > > > > > > > > > > +static inline void
> > > > > > > > > > > > > &g

Re: [PATCH v5 13/25] m68k: add asm/syscall.h

2018-12-12 Thread Dmitry V. Levin
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  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  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  
> > > > > 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 
> > > > > > >  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 
> > > > > > > > > >  wrote:
> > > > > > > > > > > On Mon, Dec 10, 2018 at 09:45:42AM +0100, Geert 
> > > > > > > > > > > Uytterhoeven wrote:
> > > > > > > > > > > > On Mon, Dec 10, 2018 at 5:30 AM Dmitry V. Levin 
> > > > > > > > > > > >  wrote:
> > > > > > > > > > > > > syscall_get_* functions are required to be 
> > > > > > > > > > > > > implemented on all
> > > > > > > > > > > > > architectures in order to extend the generic ptrace 
> > > > > > > > > > > > > API with
> > > > > > > > > > > > > PTRACE_GET_SYSCALL_INFO request.
> > > > > > > > > > > > >
> > > > > > > > > > > > > This introduces asm/syscall.h on m68k implementing 
> > > > > > > > > > > > > all 5 syscall_get_*
> > > > > > > > > > > > > functions as documented in asm-generic/syscall.h: 
> > > > > > > > > > > > > syscall_get_nr,
> > > > > > > > > > > > > syscall_get_arguments, syscall_get_error, 
> > > > > > > > > > > > > syscall_get_return_value,
> > > > > > > > > > > > > and syscall_get_arch.
> > > > > > > > > > > > >
> > > > > > > > > > > > > Cc: Geert Uytterhoeven 
> > > > > > > > > > > > > Cc: Oleg Nesterov 
> > > > > > > > > > > > > Cc: Andy Lutomirski 
> > > > > > > > > > > > > Cc: Elvira Khabirova 
> > > > > > > > > > > > > Cc: Eugene Syromyatnikov 
> > > > > > > > > > > > > Cc: linux-m...@lists.linux-m68k.org
> > > > > > > > > > > > > Signed-off-by: Dmitry V. Levin 
> > > > > > > > > > > > > ---
> > > > > > > > > > > > >
> > > > > > > > > > > > > Notes:
> > > > > > > > > > > > > v5: added syscall_get_nr, syscall_get_arguments, 
> > > > > > > > > > > > > syscall_get_error,
> > > > > > > > > > > > > and syscall_get_return_value
> > > > > > > > > > > > > v1: added syscall_get_arch
> > > > > > > > > > > >
> > > > > > > > > > > > > --- /dev/null
> > > > > > > > > > > > > +++ b/arch/m68k/include/asm/syscall.h
> > > > > > > > > > > > > @@ -0,0 +1,39 @@
> > > > > > > > > > > >
> > > > > > > > > > > > > +static inline void
> > > > > > > > > > > > > +syscall_get_arguments(struct task_struct *task, 
> > > > > > > > > > > > > struct pt_regs *regs,
> > > > > > > > > > > > > + unsigned int i, unsigned int n, 
> > > > > > > > > > > > > unsigned long *args)
> > > > > > > > > > > > > +{
> > > &

Re: [PATCH v5 13/25] m68k: add asm/syscall.h

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

Re: [PATCH v5 13/25] m68k: add asm/syscall.h

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

Re: [PATCH v5 13/25] m68k: add asm/syscall.h

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


-- 
ldv


signature.asc
Description: PGP signature


Re: [PATCH v5 13/25] m68k: add asm/syscall.h

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

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, >d1 + i, n * sizeof(args[0]));
}


-- 
ldv


signature.asc
Description: PGP signature


Re: [PATCH v5 13/25] m68k: add asm/syscall.h

2018-12-10 Thread Dmitry V. Levin
Hi Geert,

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

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

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


-- 
ldv


signature.asc
Description: PGP signature


Re: [PATCH v5 13/25] m68k: add asm/syscall.h

2018-12-10 Thread Dmitry V. Levin
Hi Geert,

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

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

> Perhaps you can return an error code instead?

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


-- 
ldv


signature.asc
Description: PGP signature


[PATCH v5 22/25] syscall_get_arch: add "struct task_struct *" argument

2018-12-09 Thread Dmitry V. Levin
This argument is required to extend the generic ptrace API with
PTRACE_GET_SYSCALL_INFO request: syscall_get_arch() is going
to be called from ptrace_request() along with syscall_get_nr(),
syscall_get_arguments(), syscall_get_error(), and
syscall_get_return_value() functions with a tracee as their argument.

Reverts: 5e937a9ae913 ("syscall_get_arch: remove useless function arguments")
Reverts: 1002d94d3076 ("syscall.h: fix doc text for syscall_get_arch()")
Reviewed-by: Andy Lutomirski  # for x86
Reviewed-by: Palmer Dabbelt 
Acked-by: Paul Burton  # MIPS parts
Acked-by: Michael Ellerman  (powerpc)
Cc: Eric Paris 
Cc: Paul Moore 
Cc: Richard Henderson 
Cc: Ivan Kokshaysky 
Cc: Matt Turner 
Cc: Vineet Gupta 
Cc: Russell King 
Cc: Catalin Marinas 
Cc: Will Deacon 
Cc: Mark Salter 
Cc: Aurelien Jacquiot 
Cc: Yoshinori Sato 
Cc: Richard Kuo 
Cc: Tony Luck 
Cc: Fenghua Yu 
Cc: Geert Uytterhoeven 
Cc: Michal Simek 
Cc: Greentime Hu 
Cc: Vincent Chen 
Cc: Ley Foon Tan 
Cc: Jonas Bonn 
Cc: Stefan Kristiansson 
Cc: Stafford Horne 
Cc: James E.J. Bottomley 
Cc: Helge Deller 
Cc: Albert Ou 
Cc: Martin Schwidefsky 
Cc: Heiko Carstens 
Cc: Rich Felker 
Cc: David S. Miller 
Cc: Guan Xuetao 
Cc: Jeff Dike 
Cc: Richard Weinberger 
Cc: Chris Zankel 
Cc: Max Filippov 
Cc: Arnd Bergmann 
Cc: Kees Cook 
Cc: Will Drewry 
Cc: Oleg Nesterov 
Cc: Elvira Khabirova 
Cc: Eugene Syromyatnikov 
Cc: Ralf Baechle 
Cc: James Hogan 
Cc: Benjamin Herrenschmidt 
Cc: Paul Mackerras 
Cc: Thomas Gleixner 
Cc: Ingo Molnar 
Cc: Borislav Petkov 
Cc: H. Peter Anvin 
Cc: x...@kernel.org
Cc: linux-al...@vger.kernel.org
Cc: linux-snps-...@lists.infradead.org
Cc: linux-arm-ker...@lists.infradead.org
Cc: linux-c6x-...@linux-c6x.org
Cc: uclinux-h8-de...@lists.sourceforge.jp
Cc: linux-hexa...@vger.kernel.org
Cc: linux-i...@vger.kernel.org
Cc: linux-m...@lists.linux-m68k.org
Cc: linux-m...@vger.kernel.org
Cc: nios2-...@lists.rocketboards.org
Cc: openr...@lists.librecores.org
Cc: linux-par...@vger.kernel.org
Cc: linuxppc-...@lists.ozlabs.org
Cc: linux-ri...@lists.infradead.org
Cc: linux-s...@vger.kernel.org
Cc: linux...@vger.kernel.org
Cc: sparcli...@vger.kernel.org
Cc: linux...@lists.infradead.org
Cc: linux-xte...@linux-xtensa.org
Cc: linux-a...@vger.kernel.org
Cc: linux-au...@redhat.com
Signed-off-by: Dmitry V. Levin 
---

Notes:
v5: fixed asm-generic docs by reverting 1002d94d3076, added Cc
v2: cleaned up mips part, added Reviewed-by

 arch/alpha/include/asm/syscall.h  |  2 +-
 arch/arc/include/asm/syscall.h|  2 +-
 arch/arm/include/asm/syscall.h|  2 +-
 arch/arm64/include/asm/syscall.h  |  4 ++--
 arch/c6x/include/asm/syscall.h|  2 +-
 arch/csky/include/asm/syscall.h   |  2 +-
 arch/h8300/include/asm/syscall.h  |  2 +-
 arch/hexagon/include/asm/syscall.h|  2 +-
 arch/ia64/include/asm/syscall.h   |  2 +-
 arch/m68k/include/asm/syscall.h   |  2 +-
 arch/microblaze/include/asm/syscall.h |  2 +-
 arch/mips/include/asm/syscall.h   |  6 +++---
 arch/mips/kernel/ptrace.c |  2 +-
 arch/nds32/include/asm/syscall.h  |  2 +-
 arch/nios2/include/asm/syscall.h  |  2 +-
 arch/openrisc/include/asm/syscall.h   |  2 +-
 arch/parisc/include/asm/syscall.h |  4 ++--
 arch/powerpc/include/asm/syscall.h| 10 --
 arch/riscv/include/asm/syscall.h  |  2 +-
 arch/s390/include/asm/syscall.h   |  4 ++--
 arch/sh/include/asm/syscall_32.h  |  2 +-
 arch/sh/include/asm/syscall_64.h  |  2 +-
 arch/sparc/include/asm/syscall.h  |  5 +++--
 arch/unicore32/include/asm/syscall.h  |  2 +-
 arch/x86/include/asm/syscall.h|  8 +---
 arch/x86/um/asm/syscall.h |  2 +-
 arch/xtensa/include/asm/syscall.h |  2 +-
 include/asm-generic/syscall.h |  5 +++--
 kernel/auditsc.c  |  4 ++--
 kernel/seccomp.c  |  4 ++--
 30 files changed, 52 insertions(+), 42 deletions(-)

diff --git a/arch/alpha/include/asm/syscall.h b/arch/alpha/include/asm/syscall.h
index 437758bdc49f..288779aa9847 100644
--- a/arch/alpha/include/asm/syscall.h
+++ b/arch/alpha/include/asm/syscall.h
@@ -31,7 +31,7 @@ syscall_get_return_value(struct task_struct *task, struct 
pt_regs *regs)
 }
 
 static inline int
-syscall_get_arch(void)
+syscall_get_arch(struct task_struct *task)
 {
return AUDIT_ARCH_ALPHA;
 }
diff --git a/arch/arc/include/asm/syscall.h b/arch/arc/include/asm/syscall.h
index c7fc4c0c3bcb..caf2697ef5b7 100644
--- a/arch/arc/include/asm/syscall.h
+++ b/arch/arc/include/asm/syscall.h
@@ -70,7 +70,7 @@ syscall_get_arguments(struct task_struct *task, struct 
pt_regs *regs,
 }
 
 static inline int
-syscall_get_arch(void)
+syscall_get_arch(struct task_struct *task)
 {
return IS_ENABLED(CONFIG_ISA_ARCOMPACT)
? (IS_ENABLED(CONFIG_CPU_BIG_ENDIAN)
diff --git a/arch/arm/include/asm/syscall.h b/arch/arm/include/asm/syscall.h
index 06dea6bce293..3940ceac0bdc 100644
--- a/arch/arm/include/asm/

[PATCH v5 13/25] m68k: add asm/syscall.h

2018-12-09 Thread Dmitry V. Levin
syscall_get_* functions are required to be implemented on all
architectures in order to extend the generic ptrace API with
PTRACE_GET_SYSCALL_INFO request.

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

Cc: Geert Uytterhoeven 
Cc: Oleg Nesterov 
Cc: Andy Lutomirski 
Cc: Elvira Khabirova 
Cc: Eugene Syromyatnikov 
Cc: linux-m...@lists.linux-m68k.org
Signed-off-by: Dmitry V. Levin 
---

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

 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 ..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 
+
+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, >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


Re: [PATCH v2 06/15] m68k: define syscall_get_arch()

2018-12-02 Thread Dmitry V. Levin
Hi Geert,

On Sun, Dec 02, 2018 at 11:29:10AM +0100, Geert Uytterhoeven wrote:
> Hi Dmitry,
> 
> On Tue, Nov 20, 2018 at 1:15 AM Dmitry V. Levin  wrote:
> > syscall_get_arch() is required to be implemented on all architectures
> > in order to extend the generic ptrace API with PTRACE_GET_SYSCALL_INFO
> > request.
> >
> > Signed-off-by: Dmitry V. Levin 
> 
> Reviewed-by: Geert Uytterhoeven 
> 
> What's your plan w.r.t. the upstreaming strategy?
> Do you plan to get this series in as a whole, or through individual 
> architecture
> maintainers?

Given that the last patch in this series adds an argument
to syscall_get_arch(), my plan is to get this series in
as a whole along with PTRACE_GET_SYSCALL_INFO series.


-- 
ldv


signature.asc
Description: PGP signature


[PATCH v2 16/15 v2] syscall_get_arch: add "struct task_struct *" argument

2018-11-21 Thread Dmitry V. Levin
This argument is required to extend the generic ptrace API with
PTRACE_GET_SYSCALL_INFO request: syscall_get_arch() is going to be
called from ptrace_request() along with other syscall_get_* functions
with a tracee as their argument.

This change partially reverts commit 5e937a9ae913 ("syscall_get_arch:
remove useless function arguments").

Reviewed-by: Andy Lutomirski  # for x86
Reviewed-by: Palmer Dabbelt 
Cc: linux-au...@redhat.com
Cc: linux-al...@vger.kernel.org
Cc: linux-a...@vger.kernel.org
Cc: linux-arm-ker...@lists.infradead.org
Cc: linux-c6x-...@linux-c6x.org
Cc: linux-hexa...@vger.kernel.org
Cc: linux-i...@vger.kernel.org
Cc: linux-m...@lists.linux-m68k.org
Cc: linux-m...@linux-mips.org
Cc: linux-par...@vger.kernel.org
Cc: linux-ri...@lists.infradead.org
Cc: linux-s...@vger.kernel.org
Cc: linux...@vger.kernel.org
Cc: linux-snps-...@lists.infradead.org
Cc: linux...@lists.infradead.org
Cc: linux-xte...@linux-xtensa.org
Cc: linuxppc-...@lists.ozlabs.org
Cc: nios2-...@lists.rocketboards.org
Cc: openr...@lists.librecores.org
Cc: sparcli...@vger.kernel.org
Cc: uclinux-h8-de...@lists.sourceforge.jp
Cc: x...@kernel.org
Signed-off-by: Dmitry V. Levin 
---

v2: cleaned up mips part, added Reviewed-by

 arch/alpha/include/asm/syscall.h  |  2 +-
 arch/arc/include/asm/syscall.h|  2 +-
 arch/arm/include/asm/syscall.h|  2 +-
 arch/arm64/include/asm/syscall.h  |  4 ++--
 arch/c6x/include/asm/syscall.h|  2 +-
 arch/h8300/include/asm/syscall.h  |  2 +-
 arch/hexagon/include/asm/syscall.h|  2 +-
 arch/ia64/include/asm/syscall.h   |  2 +-
 arch/m68k/include/asm/syscall.h   |  2 +-
 arch/microblaze/include/asm/syscall.h |  2 +-
 arch/mips/include/asm/syscall.h   |  6 +++---
 arch/mips/kernel/ptrace.c |  2 +-
 arch/nds32/include/asm/syscall.h  |  2 +-
 arch/nios2/include/asm/syscall.h  |  2 +-
 arch/openrisc/include/asm/syscall.h   |  2 +-
 arch/parisc/include/asm/syscall.h |  4 ++--
 arch/powerpc/include/asm/syscall.h| 10 --
 arch/riscv/include/asm/syscall.h  |  2 +-
 arch/s390/include/asm/syscall.h   |  4 ++--
 arch/sh/include/asm/syscall_32.h  |  2 +-
 arch/sh/include/asm/syscall_64.h  |  2 +-
 arch/sparc/include/asm/syscall.h  |  5 +++--
 arch/unicore32/include/asm/syscall.h  |  2 +-
 arch/x86/include/asm/syscall.h|  8 +---
 arch/x86/um/asm/syscall.h |  2 +-
 arch/xtensa/include/asm/syscall.h |  2 +-
 include/asm-generic/syscall.h |  3 ++-
 kernel/auditsc.c  |  4 ++--
 kernel/seccomp.c  |  4 ++--
 29 files changed, 50 insertions(+), 40 deletions(-)

diff --git a/arch/alpha/include/asm/syscall.h b/arch/alpha/include/asm/syscall.h
index d73a6fcb519c..11c688c1d7ec 100644
--- a/arch/alpha/include/asm/syscall.h
+++ b/arch/alpha/include/asm/syscall.h
@@ -4,7 +4,7 @@
 
 #include 
 
-static inline int syscall_get_arch(void)
+static inline int syscall_get_arch(struct task_struct *task)
 {
return AUDIT_ARCH_ALPHA;
 }
diff --git a/arch/arc/include/asm/syscall.h b/arch/arc/include/asm/syscall.h
index 10b2e7523bc8..7834baa61de8 100644
--- a/arch/arc/include/asm/syscall.h
+++ b/arch/arc/include/asm/syscall.h
@@ -69,7 +69,7 @@ syscall_get_arguments(struct task_struct *task, struct 
pt_regs *regs,
}
 }
 
-static inline int syscall_get_arch(void)
+static inline int syscall_get_arch(struct task_struct *task)
 {
return IS_ENABLED(CONFIG_ISA_ARCOMPACT)
? (IS_ENABLED(CONFIG_CPU_BIG_ENDIAN)
diff --git a/arch/arm/include/asm/syscall.h b/arch/arm/include/asm/syscall.h
index 06dea6bce293..3940ceac0bdc 100644
--- a/arch/arm/include/asm/syscall.h
+++ b/arch/arm/include/asm/syscall.h
@@ -104,7 +104,7 @@ static inline void syscall_set_arguments(struct task_struct 
*task,
memcpy(>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/syscal

Re: [PATCH v2 16/15] syscall_get_arch: add "struct task_struct *" argument

2018-11-21 Thread Dmitry V. Levin
Hi Paul,

On Wed, Nov 21, 2018 at 06:40:06PM +, Paul Burton wrote:
> Hi Dmitry,
> 
> On Wed, Nov 21, 2018 at 03:44:22AM +0300, Dmitry V. Levin wrote:
> > This argument is required to extend the generic ptrace API
> > with PTRACE_GET_SYSCALL_INFO request: syscall_get_arch() is going to be
> > called from ptrace_request() along with other syscall_get_* functions
> > with a tracee as their argument.
> > 
> > This change partially reverts commit 5e937a9ae913 ("syscall_get_arch:
> > remove useless function arguments").
> > 
> >%
> > 
> > diff --git a/arch/mips/include/asm/syscall.h 
> > b/arch/mips/include/asm/syscall.h
> > index 0170602a1e4e..52b633f20abd 100644
> > --- a/arch/mips/include/asm/syscall.h
> > +++ b/arch/mips/include/asm/syscall.h
> > @@ -73,7 +73,7 @@ static inline unsigned long mips_get_syscall_arg(unsigned 
> > long *arg,
> >  #ifdef CONFIG_64BIT
> > case 4: case 5: case 6: case 7:
> >  #ifdef CONFIG_MIPS32_O32
> > -   if (test_thread_flag(TIF_32BIT_REGS))
> > +   if (test_ti_thread_flag(task_thread_info(task), TIF_32BIT_REGS))
> > return get_user(*arg, (int *)usp + n);
> > else
> >  #endif
> 
> This ought to be test_tsk_thread_flag(task, TIF_32BIT_REGS) instead of
> open-coding test_tsk_thread_flag.

This will be corrected, thanks for letting me know.

> More fundamentally though, this change doesn't seem to be (directly)
> related to the change you describe in the commit message - it's not
> syscall_get_arch being modified here. I suspect this should be a
> separate commit, or if not please explain in the commit message why this
> change is included.

Good point, this is a fix that should not have been included into this commit.
The bug was found while preparing the syscall_get_arch change, and this
hunk just slipped in.  I'll send it as a separate commit.

> Compounding the lack of clarity is the fact that I only received this
> patch, not the whole series, so I can't view the change in the context
> of the rest of the series.
> 
> > @@ -140,14 +140,14 @@ extern const unsigned long sys_call_table[];
> >  extern const unsigned long sys32_call_table[];
> >  extern const unsigned long sysn32_call_table[];
> >  
> > -static inline int syscall_get_arch(void)
> > +static inline int syscall_get_arch(struct task_struct *task)
> >  {
> > int arch = AUDIT_ARCH_MIPS;
> >  #ifdef CONFIG_64BIT
> > -   if (!test_thread_flag(TIF_32BIT_REGS)) {
> > +   if (!test_ti_thread_flag(task_thread_info(task), TIF_32BIT_REGS)) {
> > arch |= __AUDIT_ARCH_64BIT;
> > /* N32 sets only TIF_32BIT_ADDR */
> > -   if (test_thread_flag(TIF_32BIT_ADDR))
> > +   if (test_ti_thread_flag(task_thread_info(task), TIF_32BIT_ADDR))
> > arch |= __AUDIT_ARCH_CONVENTION_MIPS64_N32;
> > }
> >  #endif
> 
> This does seem like the described change, but there are 2 more instances
> of open-coding test_tsk_thread_flag which ought to be cleaned up.

This will be cleaned up, thanks for letting me know.


-- 
ldv


signature.asc
Description: PGP signature


[PATCH v2 16/15] syscall_get_arch: add "struct task_struct *" argument

2018-11-20 Thread Dmitry V. Levin
This argument is required to extend the generic ptrace API
with PTRACE_GET_SYSCALL_INFO request: syscall_get_arch() is going to be
called from ptrace_request() along with other syscall_get_* functions
with a tracee as their argument.

This change partially reverts commit 5e937a9ae913 ("syscall_get_arch:
remove useless function arguments").

Cc: linux-al...@vger.kernel.org
Cc: linux-a...@vger.kernel.org
Cc: linux-arm-ker...@lists.infradead.org
Cc: linux-au...@redhat.com
Cc: linux-c6x-...@linux-c6x.org
Cc: linux-hexa...@vger.kernel.org
Cc: linux-i...@vger.kernel.org
Cc: linux-m...@lists.linux-m68k.org
Cc: linux-m...@linux-mips.org
Cc: linux-par...@vger.kernel.org
Cc: linux-ri...@lists.infradead.org
Cc: linux-s...@vger.kernel.org
Cc: linux...@vger.kernel.org
Cc: linux-snps-...@lists.infradead.org
Cc: linux...@lists.infradead.org
Cc: linux-xte...@linux-xtensa.org
Cc: linuxppc-...@lists.ozlabs.org
Cc: nios2-...@lists.rocketboards.org
Cc: openr...@lists.librecores.org
Cc: sparcli...@vger.kernel.org
Cc: uclinux-h8-de...@lists.sourceforge.jp
Cc: x...@kernel.org
Signed-off-by: Dmitry V. Levin 
---
 arch/alpha/include/asm/syscall.h  |  2 +-
 arch/arc/include/asm/syscall.h|  2 +-
 arch/arm/include/asm/syscall.h|  2 +-
 arch/arm64/include/asm/syscall.h  |  4 ++--
 arch/c6x/include/asm/syscall.h|  2 +-
 arch/h8300/include/asm/syscall.h  |  2 +-
 arch/hexagon/include/asm/syscall.h|  2 +-
 arch/ia64/include/asm/syscall.h   |  2 +-
 arch/m68k/include/asm/syscall.h   |  2 +-
 arch/microblaze/include/asm/syscall.h |  2 +-
 arch/mips/include/asm/syscall.h   |  8 
 arch/mips/kernel/ptrace.c |  2 +-
 arch/nds32/include/asm/syscall.h  |  2 +-
 arch/nios2/include/asm/syscall.h  |  2 +-
 arch/openrisc/include/asm/syscall.h   |  2 +-
 arch/parisc/include/asm/syscall.h |  4 ++--
 arch/powerpc/include/asm/syscall.h| 10 --
 arch/riscv/include/asm/syscall.h  |  2 +-
 arch/s390/include/asm/syscall.h   |  4 ++--
 arch/sh/include/asm/syscall_32.h  |  2 +-
 arch/sh/include/asm/syscall_64.h  |  2 +-
 arch/sparc/include/asm/syscall.h  |  5 +++--
 arch/unicore32/include/asm/syscall.h  |  2 +-
 arch/x86/include/asm/syscall.h|  8 +---
 arch/x86/um/asm/syscall.h |  2 +-
 arch/xtensa/include/asm/syscall.h |  2 +-
 include/asm-generic/syscall.h |  3 ++-
 kernel/auditsc.c  |  4 ++--
 kernel/seccomp.c  |  4 ++--
 29 files changed, 51 insertions(+), 41 deletions(-)

diff --git a/arch/alpha/include/asm/syscall.h b/arch/alpha/include/asm/syscall.h
index d73a6fcb519c..11c688c1d7ec 100644
--- a/arch/alpha/include/asm/syscall.h
+++ b/arch/alpha/include/asm/syscall.h
@@ -4,7 +4,7 @@
 
 #include 
 
-static inline int syscall_get_arch(void)
+static inline int syscall_get_arch(struct task_struct *task)
 {
return AUDIT_ARCH_ALPHA;
 }
diff --git a/arch/arc/include/asm/syscall.h b/arch/arc/include/asm/syscall.h
index 10b2e7523bc8..7834baa61de8 100644
--- a/arch/arc/include/asm/syscall.h
+++ b/arch/arc/include/asm/syscall.h
@@ -69,7 +69,7 @@ syscall_get_arguments(struct task_struct *task, struct 
pt_regs *regs,
}
 }
 
-static inline int syscall_get_arch(void)
+static inline int syscall_get_arch(struct task_struct *task)
 {
return IS_ENABLED(CONFIG_ISA_ARCOMPACT)
? (IS_ENABLED(CONFIG_CPU_BIG_ENDIAN)
diff --git a/arch/arm/include/asm/syscall.h b/arch/arm/include/asm/syscall.h
index 06dea6bce293..3940ceac0bdc 100644
--- a/arch/arm/include/asm/syscall.h
+++ b/arch/arm/include/asm/syscall.h
@@ -104,7 +104,7 @@ static inline void syscall_set_arguments(struct task_struct 
*task,
memcpy(>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,
}
 }
 
-stat

[PATCH v2 06/15] m68k: define syscall_get_arch()

2018-11-19 Thread Dmitry V. Levin
syscall_get_arch() is required to be implemented on all architectures
in order to extend the generic ptrace API with PTRACE_GET_SYSCALL_INFO
request.

Signed-off-by: Dmitry V. Levin 
---
v2: unchanged since v1

 arch/m68k/include/asm/syscall.h | 12 
 1 file changed, 12 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 ..d4d7deda8d50
--- /dev/null
+++ b/arch/m68k/include/asm/syscall.h
@@ -0,0 +1,12 @@
+/* SPDX-License-Identifier: GPL-2.0 */
+#ifndef _ASM_M68K_SYSCALL_H
+#define _ASM_M68K_SYSCALL_H
+
+#include 
+
+static inline int syscall_get_arch(void)
+{
+   return AUDIT_ARCH_M68K;
+}
+
+#endif /* _ASM_M68K_SYSCALL_H */
-- 
ldv


[PATCH v2 00/15] Prepare for PTRACE_GET_SYSCALL_INFO

2018-11-19 Thread Dmitry V. Levin
syscall_get_arch() is required to be implemented on all architectures
in order to extend the generic ptrace API with PTRACE_GET_SYSCALL_INFO
request.

The primary intent is that the triple (audit_arch, syscall_nr, arg1..arg6)
should describe what system call is being called and what its arguments are.


Dmitry V. Levin (15):
  Move EM_HEXAGON to uapi/linux/elf-em.h
  Move EM_ARCOMPACT and EM_ARCV2 to uapi/linux/elf-em.h
  Move EM_UNICORE to uapi/linux/elf-em.h
  elf-em.h: add EM_NDS32
  elf-em.h: add EM_XTENSA
  m68k: define syscall_get_arch()
  arc: define syscall_get_arch()
  c6x: define syscall_get_arch()
  h8300: define syscall_get_arch()
  hexagon: define syscall_get_arch()
  nds32: define syscall_get_arch()
  nios2: define syscall_get_arch()
  riscv: define syscall_get_arch()
  unicore32: define syscall_get_arch()
  xtensa: define syscall_get_arch()

 arch/arc/include/asm/elf.h   |  6 +-
 arch/arc/include/asm/syscall.h   | 10 ++
 arch/c6x/include/asm/syscall.h   |  7 +++
 arch/h8300/include/asm/syscall.h |  5 +
 arch/hexagon/include/asm/elf.h   |  6 +-
 arch/hexagon/include/asm/syscall.h   |  8 
 arch/m68k/include/asm/syscall.h  | 12 
 arch/nds32/include/asm/syscall.h |  8 
 arch/nios2/include/asm/syscall.h |  6 ++
 arch/riscv/include/asm/syscall.h | 10 ++
 arch/unicore32/include/asm/elf.h |  3 +--
 arch/unicore32/include/asm/syscall.h | 12 
 arch/xtensa/include/asm/syscall.h|  7 +++
 include/uapi/linux/audit.h   | 15 +++
 include/uapi/linux/elf-em.h  |  7 +++
 15 files changed, 110 insertions(+), 12 deletions(-)
 create mode 100644 arch/m68k/include/asm/syscall.h
 create mode 100644 arch/unicore32/include/asm/syscall.h

-- 
ldv


[PATCH 05/13] m68k: define syscall_get_arch()

2018-11-08 Thread Dmitry V. Levin
syscall_get_arch() is required to be implemented on all architectures
that use tracehook_report_syscall_entry() in order to extend
the generic ptrace API with PTRACE_GET_SYSCALL_INFO request.

Signed-off-by: Dmitry V. Levin 
---
 arch/m68k/include/asm/syscall.h | 12 
 1 file changed, 12 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 ..d4d7deda8d50
--- /dev/null
+++ b/arch/m68k/include/asm/syscall.h
@@ -0,0 +1,12 @@
+/* SPDX-License-Identifier: GPL-2.0 */
+#ifndef _ASM_M68K_SYSCALL_H
+#define _ASM_M68K_SYSCALL_H
+
+#include 
+
+static inline int syscall_get_arch(void)
+{
+   return AUDIT_ARCH_M68K;
+}
+
+#endif /* _ASM_M68K_SYSCALL_H */
-- 
ldv


[PATCH 00/13] Prepare for PTRACE_GET_SYSCALL_INFO

2018-11-08 Thread Dmitry V. Levin
syscall_get_arch() is required to be implemented on all architectures
that use tracehook_report_syscall_entry() in order to extend
the generic ptrace API with PTRACE_GET_SYSCALL_INFO request.

Dmitry V. Levin (13):
  Move EM_HEXAGON to uapi/linux/elf-em.h
  elf-em.h: add EM_ARC
  elf-em.h: add EM_NDS32
  elf-em.h: add EM_XTENSA
  m68k: define syscall_get_arch()
  arc: define syscall_get_arch()
  c6x: define syscall_get_arch()
  h8300: define syscall_get_arch()
  hexagon: define syscall_get_arch()
  nds32: define syscall_get_arch()
  nios2: define syscall_get_arch()
  riscv: define syscall_get_arch()
  xtensa: define syscall_get_arch()

 arch/arc/include/asm/syscall.h |  6 ++
 arch/c6x/include/asm/syscall.h |  6 ++
 arch/h8300/include/asm/syscall.h   |  5 +
 arch/hexagon/include/asm/elf.h |  6 +-
 arch/hexagon/include/asm/syscall.h |  8 
 arch/m68k/include/asm/syscall.h| 12 
 arch/nds32/include/asm/syscall.h   |  7 +++
 arch/nios2/include/asm/syscall.h   |  6 ++
 arch/riscv/include/asm/syscall.h   |  6 ++
 arch/xtensa/include/asm/syscall.h  |  7 +++
 include/uapi/linux/audit.h |  8 
 include/uapi/linux/elf-em.h|  5 +
 12 files changed, 77 insertions(+), 5 deletions(-)
 create mode 100644 arch/m68k/include/asm/syscall.h

-- 
ldv


[PATCH v2] uapi: fix asm/signal.h userspace compilation errors

2017-03-01 Thread Dmitry V. Levin
Replace size_t with __kernel_size_t to fix asm/signal.h userspace
compilation errors like this:

/usr/include/asm-generic/signal.h:116:2: error: unknown type name 'size_t'
  size_t ss_size;

This change is not applicable to x86 port because x32 is the only
architecture where sizeof(size_t) < sizeof(__kernel_size_t).

Signed-off-by: Dmitry V. Levin <l...@altlinux.org>
---
v2: create a separate patch for x86,
replace size_t with __kernel_size_t instead of including .

 include/uapi/asm-generic/signal.h  | 2 +-
 arch/alpha/include/uapi/asm/signal.h   | 2 +-
 arch/arm/include/uapi/asm/signal.h | 2 +-
 arch/avr32/include/uapi/asm/signal.h   | 2 +-
 arch/cris/include/uapi/asm/signal.h| 2 +-
 arch/h8300/include/uapi/asm/signal.h   | 2 +-
 arch/ia64/include/uapi/asm/signal.h| 2 +-
 arch/m32r/include/uapi/asm/signal.h| 2 +-
 arch/m68k/include/uapi/asm/signal.h| 2 +-
 arch/mips/include/uapi/asm/signal.h| 2 +-
 arch/mn10300/include/uapi/asm/signal.h | 2 +-
 arch/parisc/include/uapi/asm/signal.h  | 2 +-
 arch/powerpc/include/uapi/asm/signal.h | 2 +-
 arch/s390/include/uapi/asm/signal.h| 2 +-
 arch/sparc/include/uapi/asm/signal.h   | 2 +-
 arch/xtensa/include/uapi/asm/signal.h  | 2 +-
 16 files changed, 16 insertions(+), 16 deletions(-)

diff --git a/include/uapi/asm-generic/signal.h 
b/include/uapi/asm-generic/signal.h
index 3094618..6bbcdfa 100644
--- a/include/uapi/asm-generic/signal.h
+++ b/include/uapi/asm-generic/signal.h
@@ -113,7 +113,7 @@ struct sigaction {
 typedef struct sigaltstack {
void __user *ss_sp;
int ss_flags;
-   size_t ss_size;
+   __kernel_size_t ss_size;
 } stack_t;
 
 #endif /* __ASSEMBLY__ */
diff --git a/arch/alpha/include/uapi/asm/signal.h 
b/arch/alpha/include/uapi/asm/signal.h
index dd4ca4bc..16a2217 100644
--- a/arch/alpha/include/uapi/asm/signal.h
+++ b/arch/alpha/include/uapi/asm/signal.h
@@ -113,7 +113,7 @@ struct sigaction {
 typedef struct sigaltstack {
void __user *ss_sp;
int ss_flags;
-   size_t ss_size;
+   __kernel_size_t ss_size;
 } stack_t;
 
 /* sigstack(2) is deprecated, and will be withdrawn in a future version
diff --git a/arch/arm/include/uapi/asm/signal.h 
b/arch/arm/include/uapi/asm/signal.h
index 33073bd..859f2de 100644
--- a/arch/arm/include/uapi/asm/signal.h
+++ b/arch/arm/include/uapi/asm/signal.h
@@ -113,7 +113,7 @@ struct sigaction {
 typedef struct sigaltstack {
void __user *ss_sp;
int ss_flags;
-   size_t ss_size;
+   __kernel_size_t ss_size;
 } stack_t;
 
 
diff --git a/arch/avr32/include/uapi/asm/signal.h 
b/arch/avr32/include/uapi/asm/signal.h
index ffe8c77..46af348 100644
--- a/arch/avr32/include/uapi/asm/signal.h
+++ b/arch/avr32/include/uapi/asm/signal.h
@@ -115,7 +115,7 @@ struct sigaction {
 typedef struct sigaltstack {
void __user *ss_sp;
int ss_flags;
-   size_t ss_size;
+   __kernel_size_t ss_size;
 } stack_t;
 
 #endif /* _UAPI__ASM_AVR32_SIGNAL_H */
diff --git a/arch/cris/include/uapi/asm/signal.h 
b/arch/cris/include/uapi/asm/signal.h
index ce42fa7..02149d2 100644
--- a/arch/cris/include/uapi/asm/signal.h
+++ b/arch/cris/include/uapi/asm/signal.h
@@ -109,7 +109,7 @@ struct sigaction {
 typedef struct sigaltstack {
void *ss_sp;
int ss_flags;
-   size_t ss_size;
+   __kernel_size_t ss_size;
 } stack_t;
 
 
diff --git a/arch/h8300/include/uapi/asm/signal.h 
b/arch/h8300/include/uapi/asm/signal.h
index af3a6c3..0b1825d 100644
--- a/arch/h8300/include/uapi/asm/signal.h
+++ b/arch/h8300/include/uapi/asm/signal.h
@@ -108,7 +108,7 @@ struct sigaction {
 typedef struct sigaltstack {
void *ss_sp;
int ss_flags;
-   size_t ss_size;
+   __kernel_size_t ss_size;
 } stack_t;
 
 
diff --git a/arch/ia64/include/uapi/asm/signal.h 
b/arch/ia64/include/uapi/asm/signal.h
index c0ea285..04604da 100644
--- a/arch/ia64/include/uapi/asm/signal.h
+++ b/arch/ia64/include/uapi/asm/signal.h
@@ -113,7 +113,7 @@ struct siginfo;
 typedef struct sigaltstack {
void __user *ss_sp;
int ss_flags;
-   size_t ss_size;
+   __kernel_size_t ss_size;
 } stack_t;
 
 
diff --git a/arch/m32r/include/uapi/asm/signal.h 
b/arch/m32r/include/uapi/asm/signal.h
index 54acacb..a7f5c0b 100644
--- a/arch/m32r/include/uapi/asm/signal.h
+++ b/arch/m32r/include/uapi/asm/signal.h
@@ -110,7 +110,7 @@ struct sigaction {
 typedef struct sigaltstack {
void __user *ss_sp;
int ss_flags;
-   size_t ss_size;
+   __kernel_size_t ss_size;
 } stack_t;
 
 
diff --git a/arch/m68k/include/uapi/asm/signal.h 
b/arch/m68k/include/uapi/asm/signal.h
index cba6f85..387fddc 100644
--- a/arch/m68k/include/uapi/asm/signal.h
+++ b/arch/m68k/include/uapi/asm/signal.h
@@ -106,7 +106,7 @@ struct sigaction {
 typedef struct sigaltstack {
void __user *ss_sp;
int ss_flags;
-   size_t ss_size;
+   __kernel_size_t ss_size;
 } stack_t;
 
 #endif /* _UAPI_M68K_SIGNAL_H */
diff --g

[PATCH] uapi: fix asm/signal.h userspace compilation errors

2017-02-25 Thread Dmitry V. Levin
Include  (guarded by #ifndef __KERNEL__) to fix asm/signal.h
userspace compilation errors like this:

/usr/include/asm/signal.h:126:2: error: unknown type name 'size_t'
  size_t ss_size;

As no uapi header provides a definition of size_t, inclusion
of  seems to be the most conservative fix available.

On the kernel side size_t is typedef'ed to __kernel_size_t, so
an alternative fix would be to change the type of sigaltstack.ss_size
from size_t to __kernel_size_t for all architectures except those where
sizeof(size_t) < sizeof(__kernel_size_t), namely, x32 and mips n32.

On x32 and mips n32, however, #include  seems to be the most
straightforward way to obtain the definition for sigaltstack.ss_size's
type.

Signed-off-by: Dmitry V. Levin <l...@altlinux.org>
---
 include/uapi/asm-generic/signal.h  | 3 +++
 arch/alpha/include/uapi/asm/signal.h   | 3 +++
 arch/arm/include/uapi/asm/signal.h | 3 +++
 arch/avr32/include/uapi/asm/signal.h   | 3 +++
 arch/cris/include/uapi/asm/signal.h| 3 +++
 arch/h8300/include/uapi/asm/signal.h   | 3 +++
 arch/ia64/include/uapi/asm/signal.h| 4 
 arch/m32r/include/uapi/asm/signal.h| 3 +++
 arch/m68k/include/uapi/asm/signal.h| 3 +++
 arch/mips/include/uapi/asm/signal.h| 3 +++
 arch/mn10300/include/uapi/asm/signal.h | 3 +++
 arch/parisc/include/uapi/asm/signal.h  | 4 
 arch/powerpc/include/uapi/asm/signal.h | 3 +++
 arch/s390/include/uapi/asm/signal.h| 3 +++
 arch/sparc/include/uapi/asm/signal.h   | 3 +++
 arch/x86/include/uapi/asm/signal.h | 3 +++
 arch/xtensa/include/uapi/asm/signal.h  | 2 ++
 17 files changed, 52 insertions(+)

diff --git a/include/uapi/asm-generic/signal.h 
b/include/uapi/asm-generic/signal.h
index 3094618..e618eab 100644
--- a/include/uapi/asm-generic/signal.h
+++ b/include/uapi/asm-generic/signal.h
@@ -100,6 +100,9 @@ typedef unsigned long old_sigset_t;
 #endif
 
 #ifndef __KERNEL__
+
+#include /* For size_t. */
+
 struct sigaction {
__sighandler_t sa_handler;
unsigned long sa_flags;
diff --git a/arch/alpha/include/uapi/asm/signal.h 
b/arch/alpha/include/uapi/asm/signal.h
index dd4ca4bc..74e09f6 100644
--- a/arch/alpha/include/uapi/asm/signal.h
+++ b/arch/alpha/include/uapi/asm/signal.h
@@ -94,6 +94,9 @@ typedef unsigned long sigset_t;
 #include 
 
 #ifndef __KERNEL__
+
+#include /* For size_t. */
+
 /* Here we must cater to libcs that poke about in kernel headers.  */
 
 struct sigaction {
diff --git a/arch/arm/include/uapi/asm/signal.h 
b/arch/arm/include/uapi/asm/signal.h
index 33073bd..a7b0012 100644
--- a/arch/arm/include/uapi/asm/signal.h
+++ b/arch/arm/include/uapi/asm/signal.h
@@ -93,6 +93,9 @@ typedef unsigned long sigset_t;
 #include 
 
 #ifndef __KERNEL__
+
+#include /* For size_t. */
+
 /* Here we must cater to libcs that poke about in kernel headers.  */
 
 struct sigaction {
diff --git a/arch/avr32/include/uapi/asm/signal.h 
b/arch/avr32/include/uapi/asm/signal.h
index ffe8c77..62f3b88 100644
--- a/arch/avr32/include/uapi/asm/signal.h
+++ b/arch/avr32/include/uapi/asm/signal.h
@@ -95,6 +95,9 @@ typedef unsigned long sigset_t;
 #include 
 
 #ifndef __KERNEL__
+
+#include /* For size_t. */
+
 /* Here we must cater to libcs that poke about in kernel headers.  */
 
 struct sigaction {
diff --git a/arch/cris/include/uapi/asm/signal.h 
b/arch/cris/include/uapi/asm/signal.h
index ce42fa7..bedff78 100644
--- a/arch/cris/include/uapi/asm/signal.h
+++ b/arch/cris/include/uapi/asm/signal.h
@@ -89,6 +89,9 @@ typedef unsigned long sigset_t;
 #include 
 
 #ifndef __KERNEL__
+
+#include /* For size_t. */
+
 /* Here we must cater to libcs that poke about in kernel headers.  */
 
 struct sigaction {
diff --git a/arch/h8300/include/uapi/asm/signal.h 
b/arch/h8300/include/uapi/asm/signal.h
index af3a6c3..361e2e5 100644
--- a/arch/h8300/include/uapi/asm/signal.h
+++ b/arch/h8300/include/uapi/asm/signal.h
@@ -88,6 +88,9 @@ typedef unsigned long sigset_t;
 #include 
 
 #ifndef __KERNEL__
+
+#include /* For size_t. */
+
 /* Here we must cater to libcs that poke about in kernel headers.  */
 
 struct sigaction {
diff --git a/arch/ia64/include/uapi/asm/signal.h 
b/arch/ia64/include/uapi/asm/signal.h
index c0ea285..b089bfc 100644
--- a/arch/ia64/include/uapi/asm/signal.h
+++ b/arch/ia64/include/uapi/asm/signal.h
@@ -107,6 +107,10 @@
 
 #  include 
 
+#  ifndef __KERNEL__
+#   include  /* For size_t. */
+#  endif
+
 /* Avoid too many header ordering problems.  */
 struct siginfo;
 
diff --git a/arch/m32r/include/uapi/asm/signal.h 
b/arch/m32r/include/uapi/asm/signal.h
index 54acacb..269ec39 100644
--- a/arch/m32r/include/uapi/asm/signal.h
+++ b/arch/m32r/include/uapi/asm/signal.h
@@ -90,6 +90,9 @@ typedef unsigned long sigset_t;
 #include 
 
 #ifndef __KERNEL__
+
+#include /* For size_t. */
+
 /* Here we must cater to libcs that poke about in kernel headers.  */
 
 struct sigaction {
diff --git a/arch/m68k/include/uapi/asm/signal.h 
b/arch/m68k/include/uapi/asm/signal.h
inde