Re: [PATCH] powerpc/audit: Simplify syscall_get_arch()

2022-01-13 Thread Dmitry V. Levin
On Fri, Aug 20, 2021 at 09:39:14AM +, Christophe Leroy wrote:
> Make use of is_32bit_task() and CONFIG_CPU_LITTLE_ENDIAN
> to simplify syscall_get_arch().
> 
> Signed-off-by: Christophe Leroy 
> ---
>  arch/powerpc/include/asm/syscall.h | 15 +--
>  1 file changed, 5 insertions(+), 10 deletions(-)

Unfortunately, this commit breaks PTRACE_GET_SYSCALL_INFO and therefore
breaks strace support of AUDIT_ARCH_PPC personality on ppc64.

I've got the following report from the test farm:

=
   strace 5.16: tests-m32/test-suite.log
=

# TOTAL: 1184
# PASS:  138
# SKIP:  189
# XFAIL: 0
# FAIL:  857
# XPASS: 0
# ERROR: 0

$ hostname -f
gcc203.fsffrance.org
$ uname -a
Linux gcc203 5.15.0-2-powerpc64 #1 SMP Debian 5.15.5-2 (2021-12-18) ppc64 
GNU/Linux

It boils down to
$ echo 'int main(){return 0;}' |gcc -m32 -xc -
$ strace --trace=none ./a.out 
syscall_0xc0(0, 0x18357, 0x1, 0x2, 0x3, 0) = 0xf793
syscall_0xc0(0x39, 0x2089c0, 0x5, 0x802, 0x3, 0) = 0x39
syscall_0xc0(0x58, 0x2, 0x3, 0x812, 0x3, 0x1e0) = 0x58
+++ exited with 0 +++

$ strace -qq --signal=none --trace=ptrace strace -qq --trace=none -o/dev/null 
./a.out
...
ptrace(PTRACE_GET_SYSCALL_INFO, 1234567, 88, {op=PTRACE_SYSCALL_INFO_ENTRY, 
arch=AUDIT_ARCH_PPC64, instruction_pointer=0xf7b34594, 
stack_pointer=0xffecfbf0, entry={nr=192, args=[0, 0x18357, 0x1, 0x2, 0x3, 0]}}) 
= 80
ptrace(PTRACE_SYSCALL, 1234567, NULL, 0) = 0
ptrace(PTRACE_GET_SYSCALL_INFO, 1234567, 88, {op=PTRACE_SYSCALL_INFO_EXIT, 
arch=AUDIT_ARCH_PPC64, instruction_pointer=0xf7b34594, 
stack_pointer=0xffecfbf0, exit={rval=4155441152, is_error=0}}) = 33
) = 0xf7af

As you can see, arch=AUDIT_ARCH_PPC64 is wrong here and causes all the damage.

> diff --git a/arch/powerpc/include/asm/syscall.h 
> b/arch/powerpc/include/asm/syscall.h
> index ba0f88f3a30d..ac766037e8a1 100644
> --- a/arch/powerpc/include/asm/syscall.h
> +++ b/arch/powerpc/include/asm/syscall.h
> @@ -116,16 +116,11 @@ static inline void syscall_set_arguments(struct 
> task_struct *task,
>  
>  static inline int syscall_get_arch(struct task_struct *task)
>  {
> - int arch;
> -
> - if (IS_ENABLED(CONFIG_PPC64) && !test_tsk_thread_flag(task, TIF_32BIT))
> - arch = AUDIT_ARCH_PPC64;
> + if (is_32bit_task())
> + return AUDIT_ARCH_PPC;
> + else if (IS_ENABLED(CONFIG_CPU_LITTLE_ENDIAN))
> + return AUDIT_ARCH_PPC64LE;
>   else
> - arch = AUDIT_ARCH_PPC;
> -
> -#ifdef __LITTLE_ENDIAN__
> - arch |= __AUDIT_ARCH_LE;
> -#endif
> - return arch;
> + return AUDIT_ARCH_PPC64;
>  }
>  #endif   /* _ASM_SYSCALL_H */

Please revert or fix.


-- 
ldv


Re: Linux powerpc new system call instruction and ABI

2021-05-21 Thread Dmitry V. Levin
On Fri, May 21, 2021 at 05:00:36PM -0300, Matheus Castanho wrote:
> Florian Weimer  writes:
> > * Matheus Castanho via Libc-alpha:
> >> From: Nicholas Piggin 
> >> Subject: [PATCH 1/1] powerpc: Fix handling of scv return error codes
> >>
> >> When using scv on templated ASM syscalls, current code interprets any
> >> negative return value as error, but the only valid error codes are in
> >> the range -4095..-1 according to the ABI.
> >>
> >> Reviewed-by: Matheus Castanho 
> >
> > Please reference bug 27892 in the commit message.  I'd also appreciate a
> > backport to the 2.33 release branch (where you need to add NEWS manually
> > to add the bug reference).
> 
> No problem. [BZ #27892] appended to the commit title. I'll make sure to
> backport to 2.33 as well.

Could you also mention in the commit message that the change fixes
'signal.gen.test' strace test where it was observed initially?


-- 
ldv


Re: [PATCH 2/2] powerpc/64s/syscall: Fix ptrace syscall info with scv syscalls

2021-05-20 Thread Dmitry V. Levin
On Thu, May 20, 2021 at 09:19:31PM +1000, Nicholas Piggin wrote:
> The scv implementation missed updating syscall return value and error
> value get/set functions to deal with the changed register ABI. This
> broke ptrace PTRACE_GET_SYSCALL_INFO as well as some kernel auditing
> and tracing functions.
> 
> Fix. tools/testing/selftests/ptrace/get_syscall_info now passes when
> scv is used.
> 
> Fixes: 7fa95f9adaee ("powerpc/64s: system call support for scv/rfscv 
> instructions")
> Reported-by: "Dmitry V. Levin" 
> Signed-off-by: Nicholas Piggin 

Thanks, feel free to add
Reviewed-by: Dmitry V. Levin 

Also consider adding
Cc: sta...@vger.kernel.org # 5.9+


-- 
ldv


Re: [PATCH 1/2] powerpc/64s/syscall: Use pt_regs.trap to distinguish syscall ABI difference between sc and scv syscalls

2021-05-20 Thread Dmitry V. Levin
On Thu, May 20, 2021 at 09:19:30PM +1000, Nicholas Piggin wrote:
> The sc and scv 0 system calls have different ABI conventions, and
> ptracers need to know which system call type is being used if it wants
> to look at the syscall registers.

typo: s/if it wants/if they want/

> Document that pt_regs.trap can be used for this, and fix one in-tree user
> to work with scv 0 syscalls.
> 
> Fixes: 7fa95f9adaee ("powerpc/64s: system call support for scv/rfscv 
> instructions")
> Reported-by: "Dmitry V. Levin" 
> Suggested-by: "Dmitry V. Levin" 
> Signed-off-by: Nicholas Piggin 

Also consider adding
Cc: sta...@vger.kernel.org # 5.9+

Besides that, looks good, thanks!


-- 
ldv


Re: Linux powerpc new system call instruction and ABI

2021-05-19 Thread Dmitry V. Levin
On Thu, May 20, 2021 at 12:40:36PM +1000, Nicholas Piggin wrote:
[...]
> > Looks like struct pt_regs.trap already contains the information that could
> > be used to tell 'sc' from 'scv': if (pt_regs.trap & ~0xf) == 0x3000, then
> > it's scv.  Is my reading of arch/powerpc/include/asm/ptrace.h correct?
> 
> Hmm, I think it is. Certainly in the kernel regs struct it is, I had in 
> my mind that we put it to 0xc00 when populating the user struct for
> compatibility, but it seems not. So I guess this would work.

OK, can we state that (pt_regs.trap & ~0xf) == 0x3000 is a part of the scv
ABI, so it's not going to change and could be relied upon by userspace?
Could this be documented in Documentation/powerpc/syscall64-abi.rst,
please?


-- 
ldv


Re: Linux powerpc new system call instruction and ABI

2021-05-19 Thread Dmitry V. Levin
On Thu, May 20, 2021 at 12:45:57PM +1000, Nicholas Piggin wrote:
> Excerpts from Dmitry V. Levin's message of May 20, 2021 11:06 am:
> > On Wed, May 19, 2021 at 07:48:47PM -0400, Rich Felker wrote:
> >> On Wed, May 19, 2021 at 06:09:25PM +, Joakim Tjernlund wrote:
> > [...]
> >> > W.r.t breaking ABI, isn't that what PowerPC is trying to do with the new 
> >> > syscall I/F? 
> >> 
> >> No, it's a new independent interface.
> > 
> > Unfortunately, being a new independent interface doesn't mean it isn't
> > an ABI break.  In fact, it was a severe ABI break, and this thread is
> > an attempt to find a hotfix.
> 
> It is an ABI break, that was known. The ptrace info stuff I fixed with 
> the patch earlier was obviously a bug in my initial implementation and 
> not intended (sorry my ptrace testing was not sufficient, and thanks for
> reporting it, by the way).

Could you check whether tools/testing/selftests/ptrace/get_syscall_info.c
passes again with your fix, please?
If yes, then PTRACE_GET_SYSCALL_INFO is fixed.

By the way, kernel tracing and audit subsystems also use those functions
from asm/syscall.h and asm/ptrace.h, so your ptrace fix is likely to fix
these subsystems as well.


-- 
ldv


Re: Linux powerpc new system call instruction and ABI

2021-05-19 Thread Dmitry V. Levin
On Wed, May 19, 2021 at 07:48:47PM -0400, Rich Felker wrote:
> On Wed, May 19, 2021 at 06:09:25PM +, Joakim Tjernlund wrote:
[...]
> > W.r.t breaking ABI, isn't that what PowerPC is trying to do with the new 
> > syscall I/F? 
> 
> No, it's a new independent interface.

Unfortunately, being a new independent interface doesn't mean it isn't
an ABI break.  In fact, it was a severe ABI break, and this thread is
an attempt to find a hotfix.


-- 
ldv


Re: Linux powerpc new system call instruction and ABI

2021-05-19 Thread Dmitry V. Levin
On Thu, May 20, 2021 at 08:51:53AM +1000, Nicholas Piggin wrote:
> Excerpts from Dmitry V. Levin's message of May 19, 2021 11:26 pm:
> > On Wed, May 19, 2021 at 08:59:05PM +1000, Nicholas Piggin wrote:
> >> Excerpts from Dmitry V. Levin's message of May 19, 2021 8:24 pm:
> >> > On Wed, May 19, 2021 at 12:50:24PM +1000, Nicholas Piggin wrote:
> >> > [...]
> >> >> With this patch, I think the ptrace ABI should mostly be fixed. I think 
> >> >> a problem remains with applications that look at system call return 
> >> >> registers directly and have powerpc specific error cases. Those probably
> >> >> will just need to be updated unfortunately. Michael thought it might be
> >> >> possible to return an indication via ptrace somehow that the syscall is
> >> >> using a new ABI, so such apps can be updated to test for it. I don't 
> >> >> know how that would be done.
> >> > 
> >> > Is there any sane way for these applications to handle the scv case?
> >> > How can they tell that the scv semantics is being used for the given
> >> > syscall invocation?  Can this information be obtained e.g. from struct
> >> > pt_regs?
> >> 
> >> Not that I know of. Michael suggested there might be a way to add 
> >> something. ptrace_syscall_info has some pad bytes, could
> >> we use one for flags bits and set a bit for "new system call ABI"?
> > 
> > PTRACE_GET_SYSCALL_INFO is an architecture-agnostic API, it hides all
> > architecture-specific details behind struct ptrace_syscall_info which has
> > the same meaning on all architectures.  ptrace_syscall_info.exit contains
> > both rval and is_error fields to support every architecture regardless of
> > its syscall ABI.
> > 
> > ptrace_syscall_info.exit is extensible, but every architecture would have
> > to define a method of telling whether the system call follows the "new
> > system call ABI" conventions to export this bit of information.
> 
> It's already architecture speicfic if you look at registers of syscall 
> exit state so I don't see a problem with a flag that ppc can use for
> ABI.

To be honest, I don't see anything architecture-specific in
PTRACE_GET_SYSCALL_INFO API.  Yes, it's implementation uses various
functions defined in asm/syscall.h, but this doesn't make the interface
architecture-specific.

PTRACE_GET_SYSCALL_INFO saves its users from necessity to be aware of
tracee registers.  That's why the only place where strace has to deal
with tracee registers nowadays is syscall tampering.  The most reliable
solution is to introduce PTRACE_SET_SYSCALL_INFO, this would make the
whole syscall abi issue irrelevant for ptracers, maybe the time has come
to implement it.

Unfortunately, extending ptrace API takes time, and it's not going to be
backported to older kernels anyway, but scv-enabled kernels are already
in the wild, so we need a quick powerpc-specific fix that would be
backported to all maintained scv-enabled kernels.

[...]
> > I wonder why can't this information be just exported to the tracer via
> > struct pt_regs?
> 
> It might be able to, I don't see why that would be superior though.
> 
> Where could you put it... I guess it could go in the trap field in a 
> high bit. But could that break things that just test for syscall 
> trap number (and don't care about register ABI)? I'm not sure.

Looks like struct pt_regs.trap already contains the information that could
be used to tell 'sc' from 'scv': if (pt_regs.trap & ~0xf) == 0x3000, then
it's scv.  Is my reading of arch/powerpc/include/asm/ptrace.h correct?


-- 
ldv


Re: Linux powerpc new system call instruction and ABI

2021-05-19 Thread Dmitry V. Levin
On Wed, May 19, 2021 at 08:59:05PM +1000, Nicholas Piggin wrote:
> Excerpts from Dmitry V. Levin's message of May 19, 2021 8:24 pm:
> > On Wed, May 19, 2021 at 12:50:24PM +1000, Nicholas Piggin wrote:
> > [...]
> >> With this patch, I think the ptrace ABI should mostly be fixed. I think 
> >> a problem remains with applications that look at system call return 
> >> registers directly and have powerpc specific error cases. Those probably
> >> will just need to be updated unfortunately. Michael thought it might be
> >> possible to return an indication via ptrace somehow that the syscall is
> >> using a new ABI, so such apps can be updated to test for it. I don't 
> >> know how that would be done.
> > 
> > Is there any sane way for these applications to handle the scv case?
> > How can they tell that the scv semantics is being used for the given
> > syscall invocation?  Can this information be obtained e.g. from struct
> > pt_regs?
> 
> Not that I know of. Michael suggested there might be a way to add 
> something. ptrace_syscall_info has some pad bytes, could
> we use one for flags bits and set a bit for "new system call ABI"?

PTRACE_GET_SYSCALL_INFO is an architecture-agnostic API, it hides all
architecture-specific details behind struct ptrace_syscall_info which has
the same meaning on all architectures.  ptrace_syscall_info.exit contains
both rval and is_error fields to support every architecture regardless of
its syscall ABI.

ptrace_syscall_info.exit is extensible, but every architecture would have
to define a method of telling whether the system call follows the "new
system call ABI" conventions to export this bit of information.

This essentially means implementing something like
static inline long syscall_get_error_abi(struct task_struct *task, struct 
pt_regs *regs)
for every architecture, and using it along with syscall_get_error
in ptrace_get_syscall_info_exit to initialize the new field in
ptrace_syscall_info.exit structure.

> As a more hacky thing you could make a syscall with -1 and see how
> the error looks, and then assume all syscalls will be the same.

This would be very unreliable because sc and scv are allowed to intermingle,
so every syscall invocation can follow any of these two error handling
conventions.

> Or... is it possible at syscall entry to peek the address of
> the instruction which caused the call and see if that was a
> scv instruction? That would be about as reliable as possible
> without having that new flag bit.

No other architecture requires peeking into tracee memory just to find out
the syscall ABI.  This would make powerpc the most ugly architecture for
ptracing.

I wonder why can't this information be just exported to the tracer via
struct pt_regs?


-- 
ldv


Re: Linux powerpc new system call instruction and ABI

2021-05-19 Thread Dmitry V. Levin
On Wed, May 19, 2021 at 12:50:24PM +1000, Nicholas Piggin wrote:
[...]
> With this patch, I think the ptrace ABI should mostly be fixed. I think 
> a problem remains with applications that look at system call return 
> registers directly and have powerpc specific error cases. Those probably
> will just need to be updated unfortunately. Michael thought it might be
> possible to return an indication via ptrace somehow that the syscall is
> using a new ABI, so such apps can be updated to test for it. I don't 
> know how that would be done.

Is there any sane way for these applications to handle the scv case?
How can they tell that the scv semantics is being used for the given
syscall invocation?  Can this information be obtained e.g. from struct
pt_regs?

For example, in strace we have the following powerpc-specific code used
for syscall tampering:

$ cat src/linux/powerpc/set_error.c
/*
 * Copyright (c) 2016-2021 The strace developers.
 * All rights reserved.
 *
 * SPDX-License-Identifier: LGPL-2.1-or-later
 */

static int
arch_set_r3_ccr(struct tcb *tcp, const unsigned long r3,
const unsigned long ccr_set, const unsigned long ccr_clear)
{
if (ptrace_syscall_info_is_valid() &&
upeek(tcp, sizeof(long) * PT_CCR, &ppc_regs.ccr))
return -1;
const unsigned long old_ccr = ppc_regs.ccr;
ppc_regs.gpr[3] = r3;
ppc_regs.ccr |= ccr_set;
ppc_regs.ccr &= ~ccr_clear;
if (ppc_regs.ccr != old_ccr &&
upoke(tcp, sizeof(long) * PT_CCR, ppc_regs.ccr))
return -1;
return upoke(tcp, sizeof(long) * (PT_R0 + 3), ppc_regs.gpr[3]);
}

static int
arch_set_error(struct tcb *tcp)
{
return arch_set_r3_ccr(tcp, tcp->u_error, 0x1000, 0);
}

static int
arch_set_success(struct tcb *tcp)
{
return arch_set_r3_ccr(tcp, tcp->u_rval, 0, 0x1000);
}


-- 
ldv


Re: Linux powerpc new system call instruction and ABI

2021-05-18 Thread Dmitry V. Levin
Hi,

On Thu, Jun 11, 2020 at 06:12:01PM +1000, Nicholas Piggin wrote:
[...]
> - Error handling: The consensus among kernel, glibc, and musl is to move to
>   using negative return values in r3 rather than CR0[SO]=1 to indicate error,
>   which matches most other architectures, and is closer to a function call.

Apparently, the patchset merged by commit v5.9-rc1~100^2~164 was
incomplete: all functions defined in arch/powerpc/include/asm/ptrace.h and
arch/powerpc/include/asm/syscall.h that use ccr are broken when scv is used.
This includes syscall_get_error() and all its users including
PTRACE_GET_SYSCALL_INFO API, which in turn makes strace unusable
when scv is used.

See also https://bugzilla.redhat.com/1929836


-- 
ldv


Re: [PATCH v9 08/10] open: openat2(2) syscall

2019-07-18 Thread Dmitry V. Levin
On Thu, Jul 18, 2019 at 11:29:50PM +0200, Arnd Bergmann wrote:
[...]
> 5. you get the same problem with seccomp and strace that
>clone3() has -- these and others only track the register
>arguments by default.

Just for the record, this is definitely not the case for strace:
it decodes arrays, structures, netlink messages, and so on by default.


-- 
ldv


signature.asc
Description: PGP signature


Re: [PATCH v9 08/10] open: openat2(2) syscall

2019-07-18 Thread Dmitry V. Levin
On Sun, Jul 07, 2019 at 12:57:35AM +1000, Aleksa Sarai wrote:
[...]
> +/**
> + * Arguments for how openat2(2) should open the target path. If @extra is 
> zero,
> + * then openat2(2) is identical to openat(2).
> + *
> + * @flags: O_* flags (unknown flags ignored).

What was the rationale for implementing this semantics?
Ignoring unknown flags makes potential extension of this new interface
problematic.  This has bitten us many times already, so ...

> + * @mode: O_CREAT file mode (ignored otherwise).
> + * @upgrade_mask: restrict how the O_PATH may be re-opened (ignored 
> otherwise).
> + * @resolve: RESOLVE_* flags (-EINVAL on unknown flags).

... could you consider implementing this (-EINVAL on unknown flags) semantics
for @flags as well, please?


-- 
ldv


signature.asc
Description: PGP signature


[PATCH v11 5/7] powerpc: define syscall_get_error()

2019-05-10 Thread Dmitry V. Levin
syscall_get_error() is required to be implemented on this
architecture in addition to already implemented syscall_get_nr(),
syscall_get_arguments(), syscall_get_return_value(), and
syscall_get_arch() functions in order to extend the generic
ptrace API with PTRACE_GET_SYSCALL_INFO request.

Acked-by: Michael Ellerman 
Cc: Elvira Khabirova 
Cc: Eugene Syromyatnikov 
Cc: Benjamin Herrenschmidt 
Cc: Paul Mackerras 
Cc: Oleg Nesterov 
Cc: Andy Lutomirski 
Cc: linuxppc-dev@lists.ozlabs.org
Signed-off-by: Dmitry V. Levin 
---

Notes:
v11: added Acked-by from 
https://lore.kernel.org/lkml/87woj3wwmf@concordia.ellerman.id.au/
v10: unchanged
v9: unchanged
v8: unchanged
v7: unchanged
v6: unchanged
v5: initial revision

This change has been tested with
tools/testing/selftests/ptrace/get_syscall_info.c and strace,
so it's correct from PTRACE_GET_SYSCALL_INFO point of view.

This cast doubts on commit v4.3-rc1~86^2~81 that changed
syscall_set_return_value() in a way that doesn't quite match
syscall_get_error(), but syscall_set_return_value() is out
of scope of this series, so I'll just let you know my concerns.

See also 
https://lore.kernel.org/lkml/874lbbt3k6@concordia.ellerman.id.au/
and https://lore.kernel.org/lkml/87woj3wwmf@concordia.ellerman.id.au/
for more details on powerpc syscall_set_return_value() confusion.

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

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


[PATCH v11 0/7] ptrace: add PTRACE_GET_SYSCALL_INFO request

2019-05-10 Thread Dmitry V. Levin
, h8300, m68k, microblaze, and unicore32.

v7:
* Rebased to v5.0-rc1.
* 5 arch-specific preparatory patches out of 25 have been merged
  into v5.0-rc1 via arch trees.

v6:
* Added syscall_get_arguments and syscall_set_arguments wrappers
  to asm-generic/syscall.h, requested by Geert.
* Changed PTRACE_GET_SYSCALL_INFO return code: do not take trailing paddings
  into account, use the end of the last field of the structure being 
written.
* Changed struct ptrace_syscall_info:
  * remove .frame_pointer field, is is not needed and not portable;
  * make .arch field explicitly aligned, remove no longer needed
padding before .arch field;
  * remove trailing pads, they are no longer needed.

v5:
* Merged separate series and patches into the single series.
* Changed PTRACE_EVENTMSG_SYSCALL_{ENTRY,EXIT} values as requested by Oleg.
* Changed struct ptrace_syscall_info: generalized instruction_pointer,
  stack_pointer, and frame_pointer fields by moving them from
  ptrace_syscall_info.{entry,seccomp} substructures to ptrace_syscall_info
  and initializing them for all stops.
* Added PTRACE_SYSCALL_INFO_NONE, set it when not in a syscall stop,
  so e.g. "strace -i" could use PTRACE_SYSCALL_INFO_SECCOMP to obtain
  instruction_pointer when the tracee is in a signal stop.
* Patched all remaining architectures to provide all necessary
  syscall_get_* functions.
* Made available for all architectures: do not conditionalize on
  CONFIG_HAVE_ARCH_TRACEHOOK since all syscall_get_* functions
  are implemented on all architectures.
* Added a test for PTRACE_GET_SYSCALL_INFO to selftests/ptrace.

v4:
* Revisited PTRACE_EVENT_SECCOMP support:
  do not introduce task_struct.ptrace_event, use 
child->last_siginfo->si_code instead.
* Implemented PTRACE_SYSCALL_INFO_SECCOMP and ptrace_syscall_info.seccomp
  support along with PTRACE_SYSCALL_INFO_{ENTRY,EXIT} and
  ptrace_syscall_info.{entry,exit}.

v3:
* Changed struct ptrace_syscall_info.
* Added PTRACE_EVENT_SECCOMP support by adding ptrace_event to task_struct.
* Added proper defines for ptrace_syscall_info.op values.
* Renamed PT_SYSCALL_IS_ENTERING and PT_SYSCALL_IS_EXITING to
  PTRACE_EVENTMSG_SYSCALL_ENTRY and PTRACE_EVENTMSG_SYSCALL_EXIT
  and moved them to uapi.

v2:
* Stopped using task->ptrace.
* Replaced entry_info.is_compat with entry_info.arch, used 
syscall_get_arch().
* Used addr argument of sys_ptrace to get expected size of the struct;
      return full size of the struct.

Dmitry V. Levin (6):
  nds32: fix asm/syscall.h # acked
  hexagon: define syscall_get_error() and syscall_get_return_value() # waiting 
for ack since November
  mips: define syscall_get_error() # acked
  parisc: define syscall_get_error() # acked
  powerpc: define syscall_get_error() # acked
  selftests/ptrace: add a test case for PTRACE_GET_SYSCALL_INFO # acked

Elvira Khabirova (1):
  ptrace: add PTRACE_GET_SYSCALL_INFO request # reviewed

 arch/hexagon/include/asm/syscall.h|  14 +
 arch/mips/include/asm/syscall.h   |   6 +
 arch/nds32/include/asm/syscall.h  |  27 +-
 arch/parisc/include/asm/syscall.h |   7 +
 arch/powerpc/include/asm/syscall.h|  10 +
 include/linux/tracehook.h |   9 +-
 include/uapi/linux/ptrace.h   |  35 +++
 kernel/ptrace.c   | 101 ++-
 tools/testing/selftests/ptrace/.gitignore |   1 +
 tools/testing/selftests/ptrace/Makefile   |   2 +-
 .../selftests/ptrace/get_syscall_info.c   | 271 ++
 11 files changed, 468 insertions(+), 15 deletions(-)
 create mode 100644 tools/testing/selftests/ptrace/get_syscall_info.c

-- 
ldv


[PATCH linux-next v10 5/7] powerpc: define syscall_get_error()

2019-04-15 Thread Dmitry V. Levin
syscall_get_error() is required to be implemented on this
architecture in addition to already implemented syscall_get_nr(),
syscall_get_arguments(), syscall_get_return_value(), and
syscall_get_arch() functions in order to extend the generic
ptrace API with PTRACE_GET_SYSCALL_INFO request.

Cc: Michael Ellerman 
Cc: Elvira Khabirova 
Cc: Eugene Syromyatnikov 
Cc: Benjamin Herrenschmidt 
Cc: Paul Mackerras 
Cc: Oleg Nesterov 
Cc: Andy Lutomirski 
Cc: linuxppc-dev@lists.ozlabs.org
Signed-off-by: Dmitry V. Levin 
---

Michael, this patch is waiting for ACK since early December.

Notes:
v10: unchanged
v9: unchanged
v8: unchanged
v7: unchanged
v6: unchanged
v5: initial revision

This change has been tested with
tools/testing/selftests/ptrace/get_syscall_info.c and strace,
so it's correct from PTRACE_GET_SYSCALL_INFO point of view.

This cast doubts on commit v4.3-rc1~86^2~81 that changed
syscall_set_return_value() in a way that doesn't quite match
syscall_get_error(), but syscall_set_return_value() is out
of scope of this series, so I'll just let you know my concerns.

See also 
https://lore.kernel.org/lkml/874lbbt3k6@concordia.ellerman.id.au/
for more details on powerpc syscall_set_return_value() confusion.

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

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


[PATCH linux-next v10 0/7] ptrace: add PTRACE_GET_SYSCALL_INFO request

2019-04-15 Thread Dmitry V. Levin
o longer needed
padding before .arch field;
  * remove trailing pads, they are no longer needed.

v5:
* Merge separate series and patches into the single series.
* Change PTRACE_EVENTMSG_SYSCALL_{ENTRY,EXIT} values as requested by Oleg.
* Change struct ptrace_syscall_info: generalize instruction_pointer,
  stack_pointer, and frame_pointer fields by moving them from
  ptrace_syscall_info.{entry,seccomp} substructures to ptrace_syscall_info
  and initializing them for all stops.
* Add PTRACE_SYSCALL_INFO_NONE, set it when not in a syscall stop,
  so e.g. "strace -i" could use PTRACE_SYSCALL_INFO_SECCOMP to obtain
  instruction_pointer when the tracee is in a signal stop.
* Patch all remaining architectures to provide all necessary
  syscall_get_* functions.
* Make available for all architectures: do not conditionalize on
  CONFIG_HAVE_ARCH_TRACEHOOK since all syscall_get_* functions
  are implemented on all architectures.
* Add a test for PTRACE_GET_SYSCALL_INFO to selftests/ptrace.

v4:
* Do not introduce task_struct.ptrace_event,
  use child->last_siginfo->si_code instead.
* Implement PTRACE_SYSCALL_INFO_SECCOMP and ptrace_syscall_info.seccomp
  support along with PTRACE_SYSCALL_INFO_{ENTRY,EXIT} and
  ptrace_syscall_info.{entry,exit}.

v3:
* Change struct ptrace_syscall_info.
* Support PTRACE_EVENT_SECCOMP by adding ptrace_event to task_struct.
* Add proper defines for ptrace_syscall_info.op values.
* Rename PT_SYSCALL_IS_ENTERING and PT_SYSCALL_IS_EXITING to
  PTRACE_EVENTMSG_SYSCALL_ENTRY and PTRACE_EVENTMSG_SYSCALL_EXIT
* and move them to uapi.

v2:
* Do not use task->ptrace.
* Replace entry_info.is_compat with entry_info.arch, use syscall_get_arch().
* Use addr argument of sys_ptrace to get expected size of the struct;
  return full size of the struct.

Dmitry V. Levin (6):
  nds32: fix asm/syscall.h # acked
  hexagon: define syscall_get_error() and syscall_get_return_value() # waiting 
for ack since November
  mips: define syscall_get_error() # acked
  parisc: define syscall_get_error() # acked
  powerpc: define syscall_get_error() # waiting for ack since early December
  selftests/ptrace: add a test case for PTRACE_GET_SYSCALL_INFO # acked

Elvira Khabirova (1):
  ptrace: add PTRACE_GET_SYSCALL_INFO request # reviewed

 arch/hexagon/include/asm/syscall.h|  14 +
 arch/mips/include/asm/syscall.h   |   6 +
 arch/nds32/include/asm/syscall.h  |  27 +-
 arch/parisc/include/asm/syscall.h |   7 +
 arch/powerpc/include/asm/syscall.h|  10 +
 include/linux/tracehook.h |   9 +-
 include/uapi/linux/ptrace.h   |  35 +++
 kernel/ptrace.c   | 103 ++-
 tools/testing/selftests/ptrace/.gitignore |   1 +
 tools/testing/selftests/ptrace/Makefile   |   2 +-
 .../selftests/ptrace/get_syscall_info.c   | 271 ++
 11 files changed, 470 insertions(+), 15 deletions(-)
 create mode 100644 tools/testing/selftests/ptrace/get_syscall_info.c

-- 
ldv


[PATCH linux-next v9 5/7] powerpc: define syscall_get_error()

2019-04-08 Thread Dmitry V. Levin
syscall_get_error() is required to be implemented on this
architecture in addition to already implemented syscall_get_nr(),
syscall_get_arguments(), syscall_get_return_value(), and
syscall_get_arch() functions in order to extend the generic
ptrace API with PTRACE_GET_SYSCALL_INFO request.

Cc: Michael Ellerman 
Cc: Elvira Khabirova 
Cc: Eugene Syromyatnikov 
Cc: Benjamin Herrenschmidt 
Cc: Paul Mackerras 
Cc: Oleg Nesterov 
Cc: Andy Lutomirski 
Cc: linuxppc-dev@lists.ozlabs.org
Signed-off-by: Dmitry V. Levin 
---

Michael, this patch is waiting for ACK since early December.

Notes:
v9: unchanged
v8: unchanged
v7: unchanged
v6: unchanged
v5: initial revision

This change has been tested with
tools/testing/selftests/ptrace/get_syscall_info.c and strace,
so it's correct from PTRACE_GET_SYSCALL_INFO point of view.

This cast doubts on commit v4.3-rc1~86^2~81 that changed
syscall_set_return_value() in a way that doesn't quite match
syscall_get_error(), but syscall_set_return_value() is out
of scope of this series, so I'll just let you know my concerns.

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

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


[PATCH linux-next v9 0/7] ptrace: add PTRACE_GET_SYSCALL_INFO request

2019-04-08 Thread Dmitry V. Levin
 padding before .arch field;
  * remove trailing pads, they are no longer needed.

v5:
* Merge separate series and patches into the single series.
* Change PTRACE_EVENTMSG_SYSCALL_{ENTRY,EXIT} values as requested by Oleg.
* Change struct ptrace_syscall_info: generalize instruction_pointer,
  stack_pointer, and frame_pointer fields by moving them from
  ptrace_syscall_info.{entry,seccomp} substructures to ptrace_syscall_info
  and initializing them for all stops.
* Add PTRACE_SYSCALL_INFO_NONE, set it when not in a syscall stop,
  so e.g. "strace -i" could use PTRACE_SYSCALL_INFO_SECCOMP to obtain
  instruction_pointer when the tracee is in a signal stop.
* Patch all remaining architectures to provide all necessary
  syscall_get_* functions.
* Make available for all architectures: do not conditionalize on
  CONFIG_HAVE_ARCH_TRACEHOOK since all syscall_get_* functions
  are implemented on all architectures.
* Add a test for PTRACE_GET_SYSCALL_INFO to selftests/ptrace.

v4:
* Do not introduce task_struct.ptrace_event,
  use child->last_siginfo->si_code instead.
* Implement PTRACE_SYSCALL_INFO_SECCOMP and ptrace_syscall_info.seccomp
  support along with PTRACE_SYSCALL_INFO_{ENTRY,EXIT} and
  ptrace_syscall_info.{entry,exit}.

v3:
* Change struct ptrace_syscall_info.
* Support PTRACE_EVENT_SECCOMP by adding ptrace_event to task_struct.
* Add proper defines for ptrace_syscall_info.op values.
* Rename PT_SYSCALL_IS_ENTERING and PT_SYSCALL_IS_EXITING to
  PTRACE_EVENTMSG_SYSCALL_ENTRY and PTRACE_EVENTMSG_SYSCALL_EXIT
* and move them to uapi.

v2:
* Do not use task->ptrace.
* Replace entry_info.is_compat with entry_info.arch, use syscall_get_arch().
* Use addr argument of sys_ptrace to get expected size of the struct;
  return full size of the struct.

Dmitry V. Levin (6):
  nds32: fix asm/syscall.h # waiting for ack since early January
  hexagon: define syscall_get_error() and syscall_get_return_value() # waiting 
for ack since November
  mips: define syscall_get_error() # acked
  parisc: define syscall_get_error() # acked
  powerpc: define syscall_get_error() # waiting for ack since early December
  selftests/ptrace: add a test case for PTRACE_GET_SYSCALL_INFO

Elvira Khabirova (1):
  ptrace: add PTRACE_GET_SYSCALL_INFO request # reviewed

 arch/hexagon/include/asm/syscall.h|  14 +
 arch/mips/include/asm/syscall.h   |   6 +
 arch/nds32/include/asm/syscall.h  |  27 +-
 arch/parisc/include/asm/syscall.h |   7 +
 arch/powerpc/include/asm/syscall.h|  10 +
 include/linux/tracehook.h |   9 +-
 include/uapi/linux/ptrace.h   |  35 +++
 kernel/ptrace.c   | 103 ++-
 tools/testing/selftests/ptrace/.gitignore |   1 +
 tools/testing/selftests/ptrace/Makefile   |   2 +-
 .../selftests/ptrace/get_syscall_info.c   | 271 ++
 11 files changed, 470 insertions(+), 15 deletions(-)
 create mode 100644 tools/testing/selftests/ptrace/get_syscall_info.c

-- 
ldv


Re: [PATCH 6/6 v3] syscalls: Remove start and number from syscall_set_arguments() args

2019-04-04 Thread Dmitry V. Levin
On Mon, Apr 01, 2019 at 09:41:10AM -0400, Steven Rostedt wrote:
> From: "Steven Rostedt (VMware)" 
> 
> After removing the start and count arguments of syscall_get_arguments() it
> seems reasonable to remove them from syscall_set_arguments(). Note, as of
> today, there are no users of syscall_set_arguments(). But we are told that
> there will be soon. But for now, at least make it consistent with
> syscall_get_arguments().
> 
> Link: http://lkml.kernel.org/r/20190327222014.ga32...@altlinux.org

FWIW, you can add
Reviewed-by: Dmitry V. Levin 
 
There are two places listed below where I'd prefer to see more readable
equivalents, but feel free to leave it to respective arch maintainers.

> diff --git a/arch/nds32/include/asm/syscall.h 
> b/arch/nds32/include/asm/syscall.h
> index 89a6ec8731d8..671ebd357496 100644
> --- a/arch/nds32/include/asm/syscall.h
> +++ b/arch/nds32/include/asm/syscall.h
> @@ -129,39 +129,20 @@ void syscall_get_arguments(struct task_struct *task, 
> struct pt_regs *regs,
>   * syscall_set_arguments - change system call parameter value
>   * @task:task of interest, must be in system call entry tracing
>   * @regs:task_pt_regs() of @task
> - * @i:   argument index [0,5]
> - * @n:   number of arguments; n+i must be [1,6].
>   * @args:array of argument values to store
>   *
> - * Changes @n arguments to the system call starting with the @i'th argument.
> - * Argument @i gets value @args[0], and so on.
> - * An arch inline version is probably optimal when @i and @n are constants.
> + * Changes 6 arguments to the system call. The first argument gets value
> + * @args[0], and so on.
>   *
>   * It's only valid to call this when @task is stopped for tracing on
>   * entry to a system call, due to %TIF_SYSCALL_TRACE or %TIF_SYSCALL_AUDIT.
> - * It's invalid to call this with @i + @n > 6; we only support system calls
> - * taking up to 6 arguments.
>   */
>  void syscall_set_arguments(struct task_struct *task, struct pt_regs *regs,
> -unsigned int i, unsigned int n,
>  const unsigned long *args)
>  {
> - if (n == 0)
> - return;
> -
> - if (i + n > SYSCALL_MAX_ARGS) {
> - pr_warn("%s called with max args %d, handling only %d\n",
> - __func__, i + n, SYSCALL_MAX_ARGS);
> - n = SYSCALL_MAX_ARGS - i;
> - }
> -
> - if (i == 0) {
> - regs->orig_r0 = args[0];
> - args++;
> - i++;
> - n--;
> - }
> + regs->orig_r0 = args[0];
> + args++;
>  
> - memcpy(®s->uregs[0] + i, args, n * sizeof(args[0]));
> + memcpy(®s->uregs[0] + 1, args, 5 * sizeof(args[0]));
>  }

A shorter and slightly more readable equivalent of the last memcpy is

memcpy(®s->uregs[1], args, 5 * sizeof(args[0]));

> diff --git a/arch/s390/include/asm/syscall.h b/arch/s390/include/asm/syscall.h
> index ee0b1f6aa36d..59c3e91f2cdb 100644
> --- a/arch/s390/include/asm/syscall.h
> +++ b/arch/s390/include/asm/syscall.h
> @@ -74,15 +74,14 @@ static inline void syscall_get_arguments(struct 
> task_struct *task,
>  
>  static inline void syscall_set_arguments(struct task_struct *task,
>struct pt_regs *regs,
> -  unsigned int i, unsigned int n,
>const unsigned long *args)
>  {
> - BUG_ON(i + n > 6);
> + unsigned int n = 6;
> +
>   while (n-- > 0)
> - if (i + n > 0)
> - regs->gprs[2 + i + n] = args[n];
> - if (i == 0)
> - regs->orig_gpr2 = args[0];
> + if (n > 0)
> + regs->gprs[2 + n] = args[n];
> + regs->orig_gpr2 = args[0];
>  }

A shorter and slightly more readable equivalent of the loop is

while (--n > 0)
regs->gprs[2 + n] = args[n];


-- 
ldv


signature.asc
Description: PGP signature


Re: [PATCH 5/6 v3] syscalls: Remove start and number from syscall_get_arguments() args

2019-04-04 Thread Dmitry V. Levin
On Mon, Apr 01, 2019 at 09:41:09AM -0400, Steven Rostedt wrote:
> From: "Steven Rostedt (Red Hat)" 
> 
> At Linux Plumbers, Andy Lutomirski approached me and pointed out that the
> function call syscall_get_arguments() implemented in x86 was horribly
> written and not optimized for the standard case of passing in 0 and 6 for
> the starting index and the number of system calls to get. When looking at
> all the users of this function, I discovered that all instances pass in only
> 0 and 6 for these arguments. Instead of having this function handle
> different cases that are never used, simply rewrite it to return the first 6
> arguments of a system call.
> 
> This should help out the performance of tracing system calls by ptrace,
> ftrace and perf.
> 
> Link: http://lkml.kernel.org/r/20161107213233.754809...@goodmis.org

FWIW, you can add
Reviewed-by: Dmitry V. Levin 

There are several places listed below where I'd prefer to see more readable
equivalents, but feel free to leave it to respective arch maintainers.

> diff --git a/arch/hexagon/include/asm/syscall.h 
> b/arch/hexagon/include/asm/syscall.h
> index 4af9c7b6f13a..ae3a1e24fabd 100644
> --- a/arch/hexagon/include/asm/syscall.h
> +++ b/arch/hexagon/include/asm/syscall.h
> @@ -37,10 +37,8 @@ static inline long syscall_get_nr(struct task_struct *task,
>  
>  static inline void syscall_get_arguments(struct task_struct *task,
>struct pt_regs *regs,
> -  unsigned int i, unsigned int n,
>unsigned long *args)
>  {
> - BUG_ON(i + n > 6);
> - memcpy(args, &(®s->r00)[i], n * sizeof(args[0]));
> + memcpy(args, &(®s->r00)[0], 6 * sizeof(args[0]));

A shorter and slightly more readable equivalent is

memcpy(args, ®s->r00, 6 * sizeof(args[0]));

> diff --git a/arch/nds32/include/asm/syscall.h 
> b/arch/nds32/include/asm/syscall.h
> index f7e5e86765fe..89a6ec8731d8 100644
> --- a/arch/nds32/include/asm/syscall.h
> +++ b/arch/nds32/include/asm/syscall.h
> @@ -108,42 +108,21 @@ void syscall_set_return_value(struct task_struct *task, 
> struct pt_regs *regs,
>   * syscall_get_arguments - extract system call parameter values
>   * @task:task of interest, must be blocked
>   * @regs:task_pt_regs() of @task
> - * @i:   argument index [0,5]
> - * @n:   number of arguments; n+i must be [1,6].
>   * @args:array filled with argument values
>   *
> - * Fetches @n arguments to the system call starting with the @i'th argument
> - * (from 0 through 5).  Argument @i is stored in @args[0], and so on.
> - * An arch inline version is probably optimal when @i and @n are constants.
> + * Fetches 6 arguments to the system call (from 0 through 5). The first
> + * argument is stored in @args[0], and so on.
>   *
>   * It's only valid to call this when @task is stopped for tracing on
>   * entry to a system call, due to %TIF_SYSCALL_TRACE or %TIF_SYSCALL_AUDIT.
> - * It's invalid to call this with @i + @n > 6; we only support system calls
> - * taking up to 6 arguments.
>   */
>  #define SYSCALL_MAX_ARGS 6
>  void syscall_get_arguments(struct task_struct *task, struct pt_regs *regs,
> -unsigned int i, unsigned int n, unsigned long *args)
> +unsigned long *args)
>  {
> - if (n == 0)
> - return;
> - if (i + n > SYSCALL_MAX_ARGS) {
> - unsigned long *args_bad = args + SYSCALL_MAX_ARGS - i;
> - unsigned int n_bad = n + i - SYSCALL_MAX_ARGS;
> - pr_warning("%s called with max args %d, handling only %d\n",
> -__func__, i + n, SYSCALL_MAX_ARGS);
> - memset(args_bad, 0, n_bad * sizeof(args[0]));
> - memset(args_bad, 0, n_bad * sizeof(args[0]));
> - }
> -
> - if (i == 0) {
> - args[0] = regs->orig_r0;
> - args++;
> - i++;
> - n--;
> - }
> -
> - memcpy(args, ®s->uregs[0] + i, n * sizeof(args[0]));
> + args[0] = regs->orig_r0;
> + args++;
> + memcpy(args, ®s->uregs[0] + 1, 5 * sizeof(args[0]));
>  }

A shorter and slightly more readable equivalent of the last memcpy is

memcpy(args, ®s->uregs[1], 5 * sizeof(args[0]));

> diff --git a/arch/powerpc/include/asm/syscall.h 
> b/arch/powerpc/include/asm/syscall.h
> index 1a0e7a8b1c81..5c9b9dc82b7e 100644
> --- a/arch/powerpc/include/asm/syscall.h
> +++ b/arch/powerpc/include/asm/syscall.h
> @@ -65,22 +65,20 @@ static inline void syscall_set_return_value(struct 
> task_struct *task,
>  
>  static inl

[PATCH linux-next v8 5/7] powerpc: define syscall_get_error()

2019-03-21 Thread Dmitry V. Levin
syscall_get_error() is required to be implemented on this
architecture in addition to already implemented syscall_get_nr(),
syscall_get_arguments(), syscall_get_return_value(), and
syscall_get_arch() functions in order to extend the generic
ptrace API with PTRACE_GET_SYSCALL_INFO request.

Cc: Michael Ellerman 
Cc: Elvira Khabirova 
Cc: Eugene Syromyatnikov 
Cc: Benjamin Herrenschmidt 
Cc: Paul Mackerras 
Cc: Oleg Nesterov 
Cc: Andy Lutomirski 
Cc: linuxppc-dev@lists.ozlabs.org
Signed-off-by: Dmitry V. Levin 
---

Notes:
v8: unchanged
v7: unchanged
v6: unchanged
v5: initial revision

This change has been tested with
tools/testing/selftests/ptrace/get_syscall_info.c and strace,
so it's correct from PTRACE_GET_SYSCALL_INFO point of view.

This cast doubts on commit v4.3-rc1~86^2~81 that changed
syscall_set_return_value() in a way that doesn't quite match
syscall_get_error(), but syscall_set_return_value() is out
of scope of this series, so I'll just let you know my concerns.

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

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


[PATCH linux-next v8 0/7] ptrace: add PTRACE_GET_SYSCALL_INFO request

2019-03-21 Thread Dmitry V. Levin
s.
* Change PTRACE_EVENTMSG_SYSCALL_{ENTRY,EXIT} values as requested by Oleg.
* Change struct ptrace_syscall_info: generalize instruction_pointer,
  stack_pointer, and frame_pointer fields by moving them from
  ptrace_syscall_info.{entry,seccomp} substructures to ptrace_syscall_info
  and initializing them for all stops.
* Add PTRACE_SYSCALL_INFO_NONE, set it when not in a syscall stop,
  so e.g. "strace -i" could use PTRACE_SYSCALL_INFO_SECCOMP to obtain
  instruction_pointer when the tracee is in a signal stop.
* Patch all remaining architectures to provide all necessary
  syscall_get_* functions.
* Make available for all architectures: do not conditionalize on
  CONFIG_HAVE_ARCH_TRACEHOOK since all syscall_get_* functions
  are implemented on all architectures.
* Add a test for PTRACE_GET_SYSCALL_INFO to selftests/ptrace.

v4:
* Do not introduce task_struct.ptrace_event,
  use child->last_siginfo->si_code instead.
* Implement PTRACE_SYSCALL_INFO_SECCOMP and ptrace_syscall_info.seccomp
  support along with PTRACE_SYSCALL_INFO_{ENTRY,EXIT} and
  ptrace_syscall_info.{entry,exit}.

v3:
* Change struct ptrace_syscall_info.
* Support PTRACE_EVENT_SECCOMP by adding ptrace_event to task_struct.
* Add proper defines for ptrace_syscall_info.op values.
* Rename PT_SYSCALL_IS_ENTERING and PT_SYSCALL_IS_EXITING to
  PTRACE_EVENTMSG_SYSCALL_ENTRY and PTRACE_EVENTMSG_SYSCALL_EXIT
* and move them to uapi.

v2:
* Do not use task->ptrace.
* Replace entry_info.is_compat with entry_info.arch, use syscall_get_arch().
* Use addr argument of sys_ptrace to get expected size of the struct;
  return full size of the struct.

Dmitry V. Levin (6):
  nds32: fix asm/syscall.h
  hexagon: define syscall_get_error() and syscall_get_return_value()
  mips: define syscall_get_error()
  parisc: define syscall_get_error()
  powerpc: define syscall_get_error()
  selftests/ptrace: add a test case for PTRACE_GET_SYSCALL_INFO

Elvira Khabirova (1):
  ptrace: add PTRACE_GET_SYSCALL_INFO request

 arch/hexagon/include/asm/syscall.h|  14 +
 arch/mips/include/asm/syscall.h   |   6 +
 arch/nds32/include/asm/syscall.h  |  29 +-
 arch/parisc/include/asm/syscall.h |   7 +
 arch/powerpc/include/asm/syscall.h|  10 +
 include/linux/tracehook.h |   9 +-
 include/uapi/linux/ptrace.h   |  35 +++
 kernel/ptrace.c   | 103 ++-
 tools/testing/selftests/ptrace/.gitignore |   1 +
 tools/testing/selftests/ptrace/Makefile   |   2 +-
 .../selftests/ptrace/get_syscall_info.c   | 271 ++
 11 files changed, 471 insertions(+), 16 deletions(-)
 create mode 100644 tools/testing/selftests/ptrace/get_syscall_info.c

-- 
ldv


Re: [PATCH v2 2/6] ptrace: introduce ptrace_syscall_enter to consolidate PTRACE_SYSEMU handling

2019-03-18 Thread Dmitry V. Levin
On Mon, Mar 18, 2019 at 10:49:21AM +, Sudeep Holla wrote:
> Currently each architecture handles PTRACE_SYSEMU in very similar way.
> It's completely arch independent and can be handled in the code helping
> to consolidate PTRACE_SYSEMU handling.
> 
> Let's introduce a hook 'ptrace_syscall_enter' that arch specific syscall
> entry code can call.

Sorry if I'm late for the party, but the new name looks confusing.
If all it does is related to TIF_SYSCALL_EMU, why does it have a generic
name 'ptrace_syscall_enter' without any hint of being specific to
TIF_SYSCALL_EMU?


-- 
ldv


signature.asc
Description: PGP signature


Re: [PATCH v2 2/6] ptrace: introduce ptrace_syscall_enter to consolidate PTRACE_SYSEMU handling

2019-03-18 Thread Dmitry V. Levin
On Mon, Mar 18, 2019 at 10:49:21AM +, Sudeep Holla wrote:
> Currently each architecture handles PTRACE_SYSEMU in very similar way.
> It's completely arch independent and can be handled in the code helping
> to consolidate PTRACE_SYSEMU handling.
> 
> Let's introduce a hook 'ptrace_syscall_enter' that arch specific syscall
> entry code can call.
> 
> Cc: Oleg Nesterov 
> Signed-off-by: Sudeep Holla 
> ---
>  include/linux/ptrace.h |  1 +
>  kernel/ptrace.c| 22 ++
>  2 files changed, 23 insertions(+)
> 
> diff --git a/include/linux/ptrace.h b/include/linux/ptrace.h
> index edb9b040c94c..e30f51e3363e 100644
> --- a/include/linux/ptrace.h
> +++ b/include/linux/ptrace.h
> @@ -407,6 +407,7 @@ static inline void user_single_step_report(struct pt_regs 
> *regs)
>  #define current_user_stack_pointer() user_stack_pointer(current_pt_regs())
>  #endif
>  
> +extern long ptrace_syscall_enter(struct pt_regs *regs);
>  extern int task_current_syscall(struct task_struct *target, long *callno,
>   unsigned long args[6], unsigned int maxargs,
>   unsigned long *sp, unsigned long *pc);
> diff --git a/kernel/ptrace.c b/kernel/ptrace.c
> index 4fa3b7f4c3c7..c9c505c483df 100644
> --- a/kernel/ptrace.c
> +++ b/kernel/ptrace.c
> @@ -29,6 +29,7 @@
>  #include 
>  #include 
>  #include 
> +#include 
>  
>  /*
>   * Access another process' address space via ptrace.
> @@ -557,6 +558,27 @@ static int ptrace_detach(struct task_struct *child, 
> unsigned int data)
>   return 0;
>  }
>  
> +/*
> + * Hook to check and report for PTRACE_SYSEMU, can be called from arch
> + * arch syscall entry code
> + */
> +long ptrace_syscall_enter(struct pt_regs *regs)
> +{
> +#ifdef TIF_SYSCALL_EMU
> + if (test_thread_flag(TIF_SYSCALL_EMU)) {
> + if (tracehook_report_syscall_entry(regs))
> + /*
> +  * We can ignore the return code here as we need
> +  * return -1 always for syscall emulation irrespective
> +  * of whether the tracehook report fails or succeed.
> +  */
> + ;

This is problematic as it causes build errors with -Werror=empty-body,
see https://lore.kernel.org/lkml/20181218205305.26647-1-ma...@debian.org/


-- 
ldv


signature.asc
Description: PGP signature


Re: [PATCH v2 4/6] powerpc: use common ptrace_syscall_enter hook to handle _TIF_SYSCALL_EMU

2019-03-18 Thread Dmitry V. Levin
On Mon, Mar 18, 2019 at 10:49:23AM +, Sudeep Holla wrote:
> Now that we have a new hook ptrace_syscall_enter that can be called from
> syscall entry code and it handles PTRACE_SYSEMU in generic code, we
> can do some cleanup using the same in do_syscall_trace_enter.
> 
> Cc: Oleg Nesterov 
> Cc: Paul Mackerras 
> Cc: Michael Ellerman 
> Signed-off-by: Sudeep Holla 
> ---
>  arch/powerpc/kernel/ptrace.c | 48 
>  1 file changed, 21 insertions(+), 27 deletions(-)
> 
> diff --git a/arch/powerpc/kernel/ptrace.c b/arch/powerpc/kernel/ptrace.c
> index 2e2183b800a8..05579a5dcb12 100644
> --- a/arch/powerpc/kernel/ptrace.c
> +++ b/arch/powerpc/kernel/ptrace.c
> @@ -3278,35 +3278,29 @@ long do_syscall_trace_enter(struct pt_regs *regs)
>  
>   user_exit();
>  
> - flags = READ_ONCE(current_thread_info()->flags) &
> - (_TIF_SYSCALL_EMU | _TIF_SYSCALL_TRACE);
> -
> - if (flags) {
> - int rc = tracehook_report_syscall_entry(regs);
> + if (unlikely(ptrace_syscall_enter(regs))) {
> + /*
> +  * A nonzero return code from tracehook_report_syscall_entry()
> +  * tells us to prevent the syscall execution, but we are not
> +  * going to execute it anyway.
> +  *
> +  * Returning -1 will skip the syscall execution. We want to
> +  * avoid clobbering any registers, so we don't goto the skip
> +  * label below.
> +  */
> + return -1;
> + }

This comment is out of sync with the changed code.


-- 
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-dev@lists.ozlabs.org
Cc: linux-ri...@lists.infradead.org
Cc: linux-s...@vger.kernel.org
Cc: linux...@vger.kernel.org
Cc: sparcli...@vger.kernel.org
Cc: linux...@lists.infradead.org
Cc: linux-xte...@linux-xtensa.org
Cc: linux-a...@vger.kernel.org
Cc: linux-au...@redhat.com
Signed-off-by: Dmitry V. Levin 
---

Notes:
v2: unchanged

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

diff --git a/arch/alpha/include/asm/syscall.h b/arch/alpha/include/asm/syscall.h
index d73a6fcb519c..11c688c1d7ec 100644
--- a/arch/alpha/include/asm/syscall.h
+++ b/arch/alpha/include/asm/syscall.h
@@ -4,7 +4,7 @@
 
 #include 
 
-static inline int syscall_get_arch(void)
+static inline int syscall_get_arch(struct task_struct *task)
 {
return AUDIT_ARCH_ALPHA;
 }
diff --git a/arch/arc/include/asm/syscall.h b/arch/arc/include/asm/syscall.h
index c7fc4c0c3bcb..caf2697ef5b7 100644
--- a/arch/arc/include/asm/syscall.h
+++ b/arch/arc/include/asm/syscall.h
@@ -70,7 +70,7 @@ syscall_get_arguments(struct task_struct *task, struct 
pt_regs *regs,
 }
 
 static inline int
-syscall_get_arch(void)
+syscall_get_arch(struct task_struct *task)
 {
return IS_ENABLED(CONFIG_ISA_ARCOMPACT)
? (IS_ENABLED(CONFIG_CPU_BIG_ENDIAN)
diff --git a/arch/arm/include/asm/syscall.h b/arch/arm/include/asm/syscall.h
index 06dea6bce293..3940ceac0bdc 100644
--- a/arch/arm/include/asm/syscall.h
+++ b/arch/arm/include/asm/syscall.h
@@ -104,7 +104,7 @@ static inline void syscall_set_arguments(struct task_struct 
*task,
memcpy(®s->ARM_r0 + i, args, n * sizeof(args[0]));
 }
 
-static inline int syscall_get_arch(void)
+static inline int syscall_get_arch(struct task_struct *task)
 {
/* ARM tasks don't change audit architectures on the fly. */
return AUDIT_ARCH_ARM;
diff --git a/arch/arm64/include/asm/syscall.h b/arch/arm64/include/asm/syscall.h
index ad8be16a39c9..1870df03f774 100644
--- a/arch/arm64/include/asm/syscall.h
+++ b/arch/arm64/include/asm/syscall.h
@@ -117,9 +117,9 @@ static inline void syscall_set_arguments(struct task_struct 
*task,
  * We don't care about endianness (__AUDIT_ARCH_LE bit) here

[PATCH v7 16/22] powerpc: define syscall_get_error()

2019-02-28 Thread Dmitry V. Levin
syscall_get_error() is required to be implemented on this
architecture in addition to already implemented syscall_get_nr(),
syscall_get_arguments(), syscall_get_return_value(), and
syscall_get_arch() functions in order to extend the generic
ptrace API with PTRACE_GET_SYSCALL_INFO request.

Cc: Michael Ellerman 
Cc: Benjamin Herrenschmidt 
Cc: Paul Mackerras 
Cc: Oleg Nesterov 
Cc: Andy Lutomirski 
Cc: Elvira Khabirova 
Cc: Eugene Syromyatnikov 
Cc: linuxppc-dev@lists.ozlabs.org
Signed-off-by: Dmitry V. Levin 
---

This is just a gentle ping, the patch is unchanged.

Notes:
v7: unchanged
v6: unchanged
v5:
This change has been tested with
tools/testing/selftests/ptrace/get_syscall_info.c and strace,
so it's correct from PTRACE_GET_SYSCALL_INFO point of view.

This cast doubts on commit v4.3-rc1~86^2~81 that changed
syscall_set_return_value() in a way that doesn't quite match
syscall_get_error(), but syscall_set_return_value() is out
of scope of this series, so I'll just let you know my concerns.

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

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


[PATCH 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-dev@lists.ozlabs.org
Cc: linux-ri...@lists.infradead.org
Cc: linux-s...@vger.kernel.org
Cc: linux...@vger.kernel.org
Cc: sparcli...@vger.kernel.org
Cc: linux...@lists.infradead.org
Cc: linux-xte...@linux-xtensa.org
Cc: linux-a...@vger.kernel.org
Cc: linux-au...@redhat.com
Signed-off-by: Dmitry V. Levin 
---
 arch/alpha/include/asm/syscall.h  |  2 +-
 arch/arc/include/asm/syscall.h|  2 +-
 arch/arm/include/asm/syscall.h|  2 +-
 arch/arm64/include/asm/syscall.h  |  4 ++--
 arch/c6x/include/asm/syscall.h|  2 +-
 arch/csky/include/asm/syscall.h   |  2 +-
 arch/h8300/include/asm/syscall.h  |  2 +-
 arch/hexagon/include/asm/syscall.h|  2 +-
 arch/ia64/include/asm/syscall.h   |  2 +-
 arch/m68k/include/asm/syscall.h   |  2 +-
 arch/microblaze/include/asm/syscall.h |  2 +-
 arch/mips/include/asm/syscall.h   |  6 +++---
 arch/mips/kernel/ptrace.c |  2 +-
 arch/nds32/include/asm/syscall.h  |  2 +-
 arch/nios2/include/asm/syscall.h  |  2 +-
 arch/openrisc/include/asm/syscall.h   |  2 +-
 arch/parisc/include/asm/syscall.h |  4 ++--
 arch/powerpc/include/asm/syscall.h| 10 --
 arch/riscv/include/asm/syscall.h  |  2 +-
 arch/s390/include/asm/syscall.h   |  4 ++--
 arch/sh/include/asm/syscall_32.h  |  2 +-
 arch/sh/include/asm/syscall_64.h  |  2 +-
 arch/sparc/include/asm/syscall.h  |  5 +++--
 arch/unicore32/include/asm/syscall.h  |  2 +-
 arch/x86/include/asm/syscall.h|  8 +---
 arch/x86/um/asm/syscall.h |  2 +-
 arch/xtensa/include/asm/syscall.h |  2 +-
 include/asm-generic/syscall.h |  5 +++--
 kernel/auditsc.c  |  4 ++--
 kernel/seccomp.c  |  4 ++--
 30 files changed, 52 insertions(+), 42 deletions(-)

diff --git a/arch/alpha/include/asm/syscall.h b/arch/alpha/include/asm/syscall.h
index d73a6fcb519c..11c688c1d7ec 100644
--- a/arch/alpha/include/asm/syscall.h
+++ b/arch/alpha/include/asm/syscall.h
@@ -4,7 +4,7 @@
 
 #include 
 
-static inline int syscall_get_arch(void)
+static inline int syscall_get_arch(struct task_struct *task)
 {
return AUDIT_ARCH_ALPHA;
 }
diff --git a/arch/arc/include/asm/syscall.h b/arch/arc/include/asm/syscall.h
index c7fc4c0c3bcb..caf2697ef5b7 100644
--- a/arch/arc/include/asm/syscall.h
+++ b/arch/arc/include/asm/syscall.h
@@ -70,7 +70,7 @@ syscall_get_arguments(struct task_struct *task, struct 
pt_regs *regs,
 }
 
 static inline int
-syscall_get_arch(void)
+syscall_get_arch(struct task_struct *task)
 {
return IS_ENABLED(CONFIG_ISA_ARCOMPACT)
? (IS_ENABLED(CONFIG_CPU_BIG_ENDIAN)
diff --git a/arch/arm/include/asm/syscall.h b/arch/arm/include/asm/syscall.h
index 06dea6bce293..3940ceac0bdc 100644
--- a/arch/arm/include/asm/syscall.h
+++ b/arch/arm/include/asm/syscall.h
@@ -104,7 +104,7 @@ static inline void syscall_set_arguments(struct task_struct 
*task,
memcpy(®s->ARM_r0 + i, args, n * sizeof(args[0]));
 }
 
-static inline int syscall_get_arch(void)
+static inline int syscall_get_arch(struct task_struct *task)
 {
/* ARM tasks don't change audit architectures on the fly. */
return AUDIT_ARCH_ARM;
diff --git a/arch/arm64/include/asm/syscall.h b/arch/arm64/include/asm/syscall.h
index ad8be16a39c9..1870df03f774 100644
--- a/arch/arm64/include/asm/syscall.h
+++ b/arch/arm64/include/asm/syscall.h
@@ -117,9 +117,9 @@ static inline void syscall_set_arguments(struct task_struct 
*task,
  * We don't care about endianness (__AUDIT_ARCH_LE bit) here because
  * AArch64 has the

[PATCH 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-dev@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 00/22] ptrace: add PTRACE_GET_SYSCALL_INFO request

2019-01-06 Thread Dmitry V. Levin
 * Make available for all architectures: do not conditionalize on
  CONFIG_HAVE_ARCH_TRACEHOOK since all syscall_get_* functions
  are implemented on all architectures.
* Add a test for PTRACE_GET_SYSCALL_INFO to selftests/ptrace.

v4:
* Do not introduce task_struct.ptrace_event,
  use child->last_siginfo->si_code instead.
* Implement PTRACE_SYSCALL_INFO_SECCOMP and ptrace_syscall_info.seccomp
  support along with PTRACE_SYSCALL_INFO_{ENTRY,EXIT} and
  ptrace_syscall_info.{entry,exit}.

v3:
* Change struct ptrace_syscall_info.
* Support PTRACE_EVENT_SECCOMP by adding ptrace_event to task_struct.
* Add proper defines for ptrace_syscall_info.op values.
* Rename PT_SYSCALL_IS_ENTERING and PT_SYSCALL_IS_EXITING to
  PTRACE_EVENTMSG_SYSCALL_ENTRY and PTRACE_EVENTMSG_SYSCALL_EXIT
* and move them to uapi.

v2:
* Do not use task->ptrace.
* Replace entry_info.is_compat with entry_info.arch, use syscall_get_arch().
* Use addr argument of sys_ptrace to get expected size of the struct;
  return full size of the struct.

Dmitry V. Levin (21):
  asm-generic/syscall.h: prepare for inclusion by other files
  asm-generic/syscall.h: turn syscall_[gs]et_arguments into wrappers
  alpha: define remaining syscall_get_* functions
  Move EM_ARCOMPACT and EM_ARCV2 to uapi/linux/elf-em.h
  arc: define syscall_get_arch()
  c6x: define syscall_get_arch()
  h8300: define remaining syscall_get_* functions
  Move EM_HEXAGON to uapi/linux/elf-em.h
  hexagon: define remaining syscall_get_* functions
  Move EM_NDS32 to uapi/linux/elf-em.h
  nds32: define syscall_get_arch()
  nios2: define syscall_get_arch()
  m68k: add asm/syscall.h
  mips: define syscall_get_error()
  parisc: define syscall_get_error()
  powerpc: define syscall_get_error()
  riscv: define syscall_get_arch()
  Move EM_UNICORE to uapi/linux/elf-em.h
  unicore32: add asm/syscall.h
  syscall_get_arch: add "struct task_struct *" argument
  selftests/ptrace: add a test case for PTRACE_GET_SYSCALL_INFO

Elvira Khabirova (1):
  ptrace: add PTRACE_GET_SYSCALL_INFO request

 arch/alpha/include/asm/syscall.h  |  31 +-
 arch/arc/include/asm/elf.h|   6 +-
 arch/arc/include/asm/syscall.h|  11 +
 arch/arm/include/asm/syscall.h|   2 +-
 arch/arm64/include/asm/syscall.h  |   4 +-
 arch/c6x/include/asm/syscall.h|   7 +
 arch/csky/include/asm/syscall.h   |   2 +-
 arch/h8300/include/asm/syscall.h  |  19 ++
 arch/hexagon/include/asm/elf.h|   6 +-
 arch/hexagon/include/asm/syscall.h|  22 ++
 arch/ia64/include/asm/syscall.h   |   2 +-
 arch/m68k/include/asm/syscall.h   |  42 +++
 arch/microblaze/include/asm/syscall.h |   2 +-
 arch/mips/include/asm/syscall.h   |  12 +-
 arch/mips/kernel/ptrace.c |   2 +-
 arch/nds32/include/asm/elf.h  |   3 +-
 arch/nds32/include/asm/syscall.h  |   8 +
 arch/nios2/include/asm/syscall.h  |   6 +
 arch/openrisc/include/asm/syscall.h   |   2 +-
 arch/parisc/include/asm/syscall.h |  11 +-
 arch/powerpc/include/asm/syscall.h|  20 +-
 arch/riscv/include/asm/syscall.h  |  10 +
 arch/s390/include/asm/syscall.h   |   4 +-
 arch/sh/include/asm/syscall_32.h  |   2 +-
 arch/sh/include/asm/syscall_64.h  |   2 +-
 arch/sparc/include/asm/syscall.h  |   5 +-
 arch/unicore32/include/asm/elf.h  |   3 +-
 arch/unicore32/include/asm/syscall.h  |  47 +++
 arch/x86/include/asm/syscall.h|   8 +-
 arch/x86/um/asm/syscall.h |   2 +-
 arch/xtensa/include/asm/syscall.h |   2 +-
 include/asm-generic/syscall.h |  85 --
 include/linux/tracehook.h |   9 +-
 include/uapi/linux/audit.h|  14 +
 include/uapi/linux/elf-em.h   |   6 +
 include/uapi/linux/ptrace.h   |  35 +++
 kernel/auditsc.c  |   4 +-
 kernel/ptrace.c   | 101 ++-
 kernel/seccomp.c  |   4 +-
 tools/testing/selftests/ptrace/.gitignore |   1 +
 tools/testing/selftests/ptrace/Makefile   |   2 +-
 .../selftests/ptrace/get_syscall_info.c   | 271 ++
 42 files changed, 771 insertions(+), 66 deletions(-)
 create mode 100644 arch/m68k/include/asm/syscall.h
 create mode 100644 arch/unicore32/include/asm/syscall.h
 create mode 100644 tools/testing/selftests/ptrace/get_syscall_info.c

-- 
ldv


[PATCH v7 16/22] powerpc: define syscall_get_error()

2019-01-06 Thread Dmitry V. Levin
syscall_get_error() is required to be implemented on this
architecture in addition to already implemented syscall_get_nr(),
syscall_get_arguments(), syscall_get_return_value(), and
syscall_get_arch() functions in order to extend the generic
ptrace API with PTRACE_GET_SYSCALL_INFO request.

Cc: Michael Ellerman 
Cc: Benjamin Herrenschmidt 
Cc: Paul Mackerras 
Cc: Oleg Nesterov 
Cc: Andy Lutomirski 
Cc: Elvira Khabirova 
Cc: Eugene Syromyatnikov 
Cc: linuxppc-dev@lists.ozlabs.org
Signed-off-by: Dmitry V. Levin 
---

Notes:
v7: unchanged
v6: unchanged
v5:
This change has been tested with
tools/testing/selftests/ptrace/get_syscall_info.c and strace,
so it's correct from PTRACE_GET_SYSCALL_INFO point of view.

This cast doubts on commit v4.3-rc1~86^2~81 that changed
syscall_set_return_value() in a way that doesn't quite match
syscall_get_error(), but syscall_set_return_value() is out
of scope of this series, so I'll just let you know my concerns.

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

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


Re: [PATCH] powerpc/ptrace: cleanup do_syscall_trace_enter

2018-12-17 Thread Dmitry V. Levin
Hi,

On Mon, Dec 17, 2018 at 10:20:26PM +1100, Michael Ellerman wrote:
> "Dmitry V. Levin"  writes:
> > Invoke tracehook_report_syscall_entry once.
> 
> Thanks.
> 
> > Signed-off-by: Dmitry V. Levin 
> > ---
> >  arch/powerpc/kernel/ptrace.c | 54 +---
> >  1 file changed, 31 insertions(+), 23 deletions(-)
> >
> > diff --git a/arch/powerpc/kernel/ptrace.c b/arch/powerpc/kernel/ptrace.c
> > index 714c3480c52d..8794d32c2d9e 100644
> > --- a/arch/powerpc/kernel/ptrace.c
> > +++ b/arch/powerpc/kernel/ptrace.c
> > @@ -3263,32 +3263,40 @@ static inline int do_seccomp(struct pt_regs *regs) 
> > { return 0; }
> >   */
> >  long do_syscall_trace_enter(struct pt_regs *regs)
> >  {
> > +   u32 cached_flags;
> > +
> 
> Do you mind if I just call it "flags", I find "cached_flags" a bit
> unwieldy for some reason.
> 
> I'm happy to fix it up when applying.

No problem, feel free to call it whatever you like.  Thanks,


-- 
ldv


signature.asc
Description: PGP signature


[PATCH] powerpc/ptrace: cleanup do_syscall_trace_enter

2018-12-16 Thread Dmitry V. Levin
Invoke tracehook_report_syscall_entry once.

Signed-off-by: Dmitry V. Levin 
---
 arch/powerpc/kernel/ptrace.c | 54 +---
 1 file changed, 31 insertions(+), 23 deletions(-)

diff --git a/arch/powerpc/kernel/ptrace.c b/arch/powerpc/kernel/ptrace.c
index 714c3480c52d..8794d32c2d9e 100644
--- a/arch/powerpc/kernel/ptrace.c
+++ b/arch/powerpc/kernel/ptrace.c
@@ -3263,32 +3263,40 @@ static inline int do_seccomp(struct pt_regs *regs) { 
return 0; }
  */
 long do_syscall_trace_enter(struct pt_regs *regs)
 {
+   u32 cached_flags;
+
user_exit();
 
-   if (test_thread_flag(TIF_SYSCALL_EMU)) {
-   /*
-* A nonzero return code from tracehook_report_syscall_entry()
-* tells us to prevent the syscall execution, but we are not
-* going to execute it anyway.
-*
-* Returning -1 will skip the syscall execution. We want to
-* avoid clobbering any register also, thus, not 'gotoing'
-* skip label.
-*/
-   if (tracehook_report_syscall_entry(regs))
-   ;
-   return -1;
-   }
+   cached_flags = READ_ONCE(current_thread_info()->flags) &
+  (_TIF_SYSCALL_EMU | _TIF_SYSCALL_TRACE);
 
-   /*
-* The tracer may decide to abort the syscall, if so tracehook
-* will return !0. Note that the tracer may also just change
-* regs->gpr[0] to an invalid syscall number, that is handled
-* below on the exit path.
-*/
-   if (test_thread_flag(TIF_SYSCALL_TRACE) &&
-   tracehook_report_syscall_entry(regs))
-   goto skip;
+   if (cached_flags) {
+   int rc = tracehook_report_syscall_entry(regs);
+
+   if (unlikely(cached_flags & _TIF_SYSCALL_EMU)) {
+   /*
+* A nonzero return code from
+* tracehook_report_syscall_entry() tells us
+* to prevent the syscall execution, but
+* we are not going to execute it anyway.
+*
+* Returning -1 will skip the syscall execution.
+* We want to avoid clobbering any register also,
+* thus, not 'gotoing' skip label.
+*/
+   return -1;
+   }
+
+   if (rc) {
+   /*
+* The tracer decided to abort the syscall.
+* Note that the tracer may also just change
+* regs->gpr[0] to an invalid syscall number,
+* that is handled below on the exit path.
+*/
+   goto skip;
+   }
+   }
 
/* Run seccomp after ptrace; allow it to set gpr[3]. */
if (do_seccomp(regs))
-- 
ldv


[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-dev@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 00/27] ptrace: add PTRACE_GET_SYSCALL_INFO request

2018-12-13 Thread Dmitry V. Levin
OK since all syscall_get_* functions
  are implemented on all architectures.
* Add a test for PTRACE_GET_SYSCALL_INFO to selftests/ptrace.

v4:
* Do not introduce task_struct.ptrace_event,
  use child->last_siginfo->si_code instead.
* Implement PTRACE_SYSCALL_INFO_SECCOMP and ptrace_syscall_info.seccomp
  support along with PTRACE_SYSCALL_INFO_{ENTRY,EXIT} and
  ptrace_syscall_info.{entry,exit}.

v3:
* Change struct ptrace_syscall_info.
* Support PTRACE_EVENT_SECCOMP by adding ptrace_event to task_struct.
* Add proper defines for ptrace_syscall_info.op values.
* Rename PT_SYSCALL_IS_ENTERING and PT_SYSCALL_IS_EXITING to
  PTRACE_EVENTMSG_SYSCALL_ENTRY and PTRACE_EVENTMSG_SYSCALL_EXIT
* and move them to uapi.

v2:
* Do not use task->ptrace.
* Replace entry_info.is_compat with entry_info.arch, use syscall_get_arch().
* Use addr argument of sys_ptrace to get expected size of the struct;
  return full size of the struct.

Dmitry V. Levin (25):
  asm-generic/syscall.h: prepare for inclusion by other files
  asm-generic/syscall.h: turn syscall_[gs]et_arguments into wrappers
  alpha: define remaining syscall_get_* functions
  Move EM_ARCOMPACT and EM_ARCV2 to uapi/linux/elf-em.h
  arc: define syscall_get_arch()
  c6x: define syscall_get_arch()
  elf-em.h: add EM_CSKY
  csky: define syscall_get_arch()
  h8300: define remaining syscall_get_* functions
  Move EM_HEXAGON to uapi/linux/elf-em.h
  hexagon: define remaining syscall_get_* functions
  Move EM_NDS32 to uapi/linux/elf-em.h
  nds32: define syscall_get_arch()
  nios2: define syscall_get_arch()
  m68k: add asm/syscall.h
  mips: define syscall_get_error()
  parisc: define syscall_get_error()
  powerpc: define syscall_get_error()
  riscv: define syscall_get_arch()
  Move EM_XTENSA to uapi/linux/elf-em.h
  xtensa: define syscall_get_* functions
  Move EM_UNICORE to uapi/linux/elf-em.h
  unicore32: add asm/syscall.h
  syscall_get_arch: add "struct task_struct *" argument
  selftests/ptrace: add a test case for PTRACE_GET_SYSCALL_INFO

Elvira Khabirova (2):
  powerpc/ptrace: replace ptrace_report_syscall() with a tracehook call
  ptrace: add PTRACE_GET_SYSCALL_INFO request

 arch/alpha/include/asm/syscall.h  |  31 +-
 arch/arc/include/asm/elf.h|   6 +-
 arch/arc/include/asm/syscall.h|  11 +
 arch/arm/include/asm/syscall.h|   2 +-
 arch/arm64/include/asm/syscall.h  |   4 +-
 arch/c6x/include/asm/syscall.h|   7 +
 arch/csky/include/asm/syscall.h   |   7 +
 arch/h8300/include/asm/syscall.h  |  19 ++
 arch/hexagon/include/asm/elf.h|   6 +-
 arch/hexagon/include/asm/syscall.h|  22 ++
 arch/ia64/include/asm/syscall.h   |   2 +-
 arch/m68k/include/asm/syscall.h   |  42 +++
 arch/microblaze/include/asm/syscall.h |   2 +-
 arch/mips/include/asm/syscall.h   |  12 +-
 arch/mips/kernel/ptrace.c |   2 +-
 arch/nds32/include/asm/elf.h  |   3 +-
 arch/nds32/include/asm/syscall.h  |   8 +
 arch/nios2/include/asm/syscall.h  |   6 +
 arch/openrisc/include/asm/syscall.h   |   2 +-
 arch/parisc/include/asm/syscall.h |  11 +-
 arch/powerpc/include/asm/syscall.h|  20 +-
 arch/powerpc/kernel/ptrace.c  |   7 +-
 arch/riscv/include/asm/syscall.h  |  10 +
 arch/s390/include/asm/syscall.h   |   4 +-
 arch/sh/include/asm/syscall_32.h  |   2 +-
 arch/sh/include/asm/syscall_64.h  |   2 +-
 arch/sparc/include/asm/syscall.h  |   5 +-
 arch/unicore32/include/asm/elf.h  |   3 +-
 arch/unicore32/include/asm/syscall.h  |  46 +++
 arch/x86/include/asm/syscall.h|   8 +-
 arch/x86/um/asm/syscall.h |   2 +-
 arch/xtensa/include/asm/elf.h |   2 +-
 arch/xtensa/include/asm/syscall.h |  65 +
 include/asm-generic/syscall.h |  85 --
 include/linux/tracehook.h |   9 +-
 include/uapi/linux/audit.h|  16 ++
 include/uapi/linux/elf-em.h   |   8 +
 include/uapi/linux/ptrace.h   |  35 +++
 kernel/auditsc.c  |   4 +-
 kernel/ptrace.c   | 101 ++-
 kernel/seccomp.c  |   4 +-
 tools/testing/selftests/ptrace/.gitignore |   1 +
 tools/testing/selftests/ptrace/Makefile   |   2 +-
 .../selftests/ptrace/get_syscall_info.c   | 271 ++
 44 files changed, 851 insertions(+), 66 deletions(-)
 create mode 100644 arch/m68k/include/asm/syscall.h
 create mode 100644 arch/unicore32/include/asm/syscall.h
 create mode 100644 tools/testing/selftests/ptrace/get_syscall_info.c

-- 
ldv


[PATCH v6 25/27] powerpc/ptrace: replace ptrace_report_syscall() with a tracehook call

2018-12-13 Thread Dmitry V. Levin
From: Elvira Khabirova 

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

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

Co-authored-by: Dmitry V. Levin 
Fixes: 5521eb4bca2d ("powerpc/ptrace: Add support for PTRACE_SYSEMU")
Signed-off-by: Elvira Khabirova 
Signed-off-by: Dmitry V. Levin 
[mpe: Take this as a minimal fix for 4.20, we'll rework it later]
Signed-off-by: Michael Ellerman 
---

Notes:
v6: this is the fix that was taken into powerpc tree
v5: reverted to a simple approach, compile- and run-tested
v4: rewritten to call tracehook_report_syscall_entry() once, compile-tested
v3: add a descriptive comment
v2: explicitly ignore tracehook_report_syscall_entry() return code

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

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


[PATCH v6 18/27] powerpc: define syscall_get_error()

2018-12-13 Thread Dmitry V. Levin
syscall_get_error() is required to be implemented on this
architecture in addition to already implemented syscall_get_nr(),
syscall_get_arguments(), syscall_get_return_value(), and
syscall_get_arch() functions in order to extend the generic
ptrace API with PTRACE_GET_SYSCALL_INFO request.

Cc: Michael Ellerman 
Cc: Benjamin Herrenschmidt 
Cc: Paul Mackerras 
Cc: Oleg Nesterov 
Cc: Andy Lutomirski 
Cc: Elvira Khabirova 
Cc: Eugene Syromyatnikov 
Cc: linuxppc-dev@lists.ozlabs.org
Signed-off-by: Dmitry V. Levin 
---

Notes:
v6: unchanged

v5:
This change has been tested with
tools/testing/selftests/ptrace/get_syscall_info.c and strace,
so it's correct from PTRACE_GET_SYSCALL_INFO point of view.

This cast doubts on commit v4.3-rc1~86^2~81 that changed
syscall_set_return_value() in a way that doesn't quite match
syscall_get_error(), but syscall_set_return_value() is out
of scope of this series, so I'll just let you know my concerns.

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

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


Re: [PATCH v6] powerpc/ptrace: replace ptrace_report_syscall() with a tracehook call

2018-12-10 Thread Dmitry V. Levin
On Mon, Dec 10, 2018 at 02:28:07PM +0100, Oleg Nesterov wrote:
> On 12/07, Dmitry V. Levin wrote:
> >
> > Please make either v5 or v6 edition of this fix, or any similar fix,
> > into v4.20.
> 
> IIUC, v5 above means
> 
>   [PATCH v5 23/25] powerpc/ptrace: replace ptrace_report_syscall() with a 
> tracehook call
> 
> you sent in another series...

They just happen to have the same v5 here and there.
In that series I included the most trivial variant of the change.

> >  long do_syscall_trace_enter(struct pt_regs *regs)
> >  {
> > +   struct thread_info *ti;
> > +   u32 cached_flags;
> > +
> > user_exit();
> >  
> > -   if (test_thread_flag(TIF_SYSCALL_EMU)) {
> > -   ptrace_report_syscall(regs);
> > -   /*
> > -* Returning -1 will skip the syscall execution. We want to
> > -* avoid clobbering any register also, thus, not 'gotoing'
> > -* skip label.
> > -*/
> > -   return -1;
> > -   }
> > +   ti = current_thread_info();
> > +   cached_flags = READ_ONCE(ti->flags) &
> > +  (_TIF_SYSCALL_EMU | _TIF_SYSCALL_TRACE |
> > +   _TIF_SYSCALL_TRACEPOINT);
> >  
> > -   /*
> > -* The tracer may decide to abort the syscall, if so tracehook
> > -* will return !0. Note that the tracer may also just change
> > -* regs->gpr[0] to an invalid syscall number, that is handled
> > -* below on the exit path.
> > -*/
> > -   if (test_thread_flag(TIF_SYSCALL_TRACE) &&
> > -   tracehook_report_syscall_entry(regs))
> > -   goto skip;
> > +   if (cached_flags & (_TIF_SYSCALL_EMU | _TIF_SYSCALL_TRACE)) {
> > +   int rc = tracehook_report_syscall_entry(regs);
> > +
> > +   if (unlikely(cached_flags & _TIF_SYSCALL_EMU)) {
> > +   /*
> > +* A nonzero return code from
> > +* tracehook_report_syscall_entry() tells us
> > +* to prevent the syscall execution, but
> > +* we are not going to execute it anyway.
> > +*
> > +* Returning -1 will skip the syscall execution.
> > +* We want to avoid clobbering any register also,
> > +* thus, not 'gotoing' skip label.
> > +*/
> > +   return -1;
> > +   }
> > +
> > +   if (rc) {
> > +   /*
> > +* The tracer decided to abort the syscall.
> > +* Note that the tracer may also just change
> > +* regs->gpr[0] to an invalid syscall number,
> > +* that is handled below on the exit path.
> > +*/
> > +   goto skip;
> > +   }
> > +   }
> >  
> > /* Run seccomp after ptrace; allow it to set gpr[3]. */
> > if (do_seccomp(regs))
> > @@ -3293,7 +3309,7 @@ long do_syscall_trace_enter(struct pt_regs *regs)
> > if (regs->gpr[0] >= NR_syscalls)
> > goto skip;
> >  
> > -   if (unlikely(test_thread_flag(TIF_SYSCALL_TRACEPOINT)))
> > +   if (unlikely(cached_flags & _TIF_SYSCALL_TRACEPOINT))
> 
> I will leave this to maintainers, but to me this change looks good and imo it
> also cleanups the code.
> 
> However I am not sure cached_flags should include _TIF_SYSCALL_TRACEPOINT. If
> nothing else, the caller can sleep in ptrace_stop() unpredictably long and
> TIF_SYSCALL_TRACEPOINT can be set/cleared meanwhile.

I agree, we shouldn't cache _TIF_SYSCALL_TRACEPOINT.


-- 
ldv


signature.asc
Description: PGP signature


[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-dev@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 00/25] ptrace: add PTRACE_GET_SYSCALL_INFO request

2018-12-09 Thread Dmitry V. Levin
E_SYSCALL_INFO_{ENTRY,EXIT} and
  ptrace_syscall_info.{entry,exit}.

v3:
* Change struct ptrace_syscall_info.
* Support PTRACE_EVENT_SECCOMP by adding ptrace_event to task_struct.
* Add proper defines for ptrace_syscall_info.op values.
* Rename PT_SYSCALL_IS_ENTERING and PT_SYSCALL_IS_EXITING to
  PTRACE_EVENTMSG_SYSCALL_ENTRY and PTRACE_EVENTMSG_SYSCALL_EXIT
* and move them to uapi.

v2:
* Do not use task->ptrace.
* Replace entry_info.is_compat with entry_info.arch, use syscall_get_arch().
* Use addr argument of sys_ptrace to get expected size of the struct;
  return full size of the struct.

Dmitry V. Levin (23):
  alpha: define remaining syscall_get_* functions
  Move EM_ARCOMPACT and EM_ARCV2 to uapi/linux/elf-em.h
  arc: define syscall_get_arch()
  c6x: define syscall_get_arch()
  elf-em.h: add EM_CSKY
  csky: define syscall_get_arch()
  h8300: define remaining syscall_get_* functions
  Move EM_HEXAGON to uapi/linux/elf-em.h
  hexagon: define remaining syscall_get_* functions
  Move EM_NDS32 to uapi/linux/elf-em.h
  nds32: define syscall_get_arch()
  nios2: define syscall_get_arch()
  m68k: add asm/syscall.h
  mips: define syscall_get_error()
  parisc: define syscall_get_error()
  powerpc: define syscall_get_error()
  riscv: define syscall_get_arch()
  Move EM_XTENSA to uapi/linux/elf-em.h
  xtensa: define syscall_get_* functions
  Move EM_UNICORE to uapi/linux/elf-em.h
  unicore32: add asm/syscall.h
  syscall_get_arch: add "struct task_struct *" argument
  selftests/ptrace: add a test case for PTRACE_GET_SYSCALL_INFO

Elvira Khabirova (2):
  powerpc/ptrace: replace ptrace_report_syscall() with a tracehook call
  ptrace: add PTRACE_GET_SYSCALL_INFO request

 arch/alpha/include/asm/syscall.h  |  29 +-
 arch/arc/include/asm/elf.h|   6 +-
 arch/arc/include/asm/syscall.h|  11 +
 arch/arm/include/asm/syscall.h|   2 +-
 arch/arm64/include/asm/syscall.h  |   4 +-
 arch/c6x/include/asm/syscall.h|   7 +
 arch/csky/include/asm/syscall.h   |   7 +
 arch/h8300/include/asm/syscall.h  |  18 ++
 arch/hexagon/include/asm/elf.h|   6 +-
 arch/hexagon/include/asm/syscall.h|  20 ++
 arch/ia64/include/asm/syscall.h   |   2 +-
 arch/m68k/include/asm/syscall.h   |  39 +++
 arch/microblaze/include/asm/syscall.h |   2 +-
 arch/mips/include/asm/syscall.h   |  12 +-
 arch/mips/kernel/ptrace.c |   2 +-
 arch/nds32/include/asm/elf.h  |   3 +-
 arch/nds32/include/asm/syscall.h  |   8 +
 arch/nios2/include/asm/syscall.h  |   6 +
 arch/openrisc/include/asm/syscall.h   |   2 +-
 arch/parisc/include/asm/syscall.h |  11 +-
 arch/powerpc/include/asm/syscall.h|  20 +-
 arch/powerpc/kernel/ptrace.c  |   7 +-
 arch/riscv/include/asm/syscall.h  |  10 +
 arch/s390/include/asm/syscall.h   |   4 +-
 arch/sh/include/asm/syscall_32.h  |   2 +-
 arch/sh/include/asm/syscall_64.h  |   2 +-
 arch/sparc/include/asm/syscall.h  |   5 +-
 arch/unicore32/include/asm/elf.h  |   3 +-
 arch/unicore32/include/asm/syscall.h  |  45 +++
 arch/x86/include/asm/syscall.h|   8 +-
 arch/x86/um/asm/syscall.h |   2 +-
 arch/xtensa/include/asm/elf.h |   2 +-
 arch/xtensa/include/asm/syscall.h |  69 +
 include/asm-generic/syscall.h |   5 +-
 include/linux/tracehook.h |   9 +-
 include/uapi/linux/audit.h|  16 ++
 include/uapi/linux/elf-em.h   |   8 +
 include/uapi/linux/ptrace.h   |  39 +++
 kernel/auditsc.c  |   4 +-
 kernel/ptrace.c   |  99 ++-
 kernel/seccomp.c  |   4 +-
 tools/testing/selftests/ptrace/.gitignore |   1 +
 tools/testing/selftests/ptrace/Makefile   |   2 +-
 .../selftests/ptrace/get_syscall_info.c   | 272 ++
 44 files changed, 783 insertions(+), 52 deletions(-)
 create mode 100644 arch/m68k/include/asm/syscall.h
 create mode 100644 arch/unicore32/include/asm/syscall.h
 create mode 100644 tools/testing/selftests/ptrace/get_syscall_info.c

-- 
ldv


[PATCH v5 23/25] powerpc/ptrace: replace ptrace_report_syscall() with a tracehook call

2018-12-09 Thread Dmitry V. Levin
From: Elvira Khabirova 

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

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

Co-authored-by: Dmitry V. Levin 
Fixes: 5521eb4bca2d ("powerpc/ptrace: Add support for PTRACE_SYSEMU")
Cc: Michael Ellerman 
Cc: Oleg Nesterov 
Cc: Eugene Syromyatnikov 
Cc: Benjamin Herrenschmidt 
Cc: Paul Mackerras 
Cc: Breno Leitao 
Cc: Andy Lutomirski 
Cc: linuxppc-dev@lists.ozlabs.org
Signed-off-by: Elvira Khabirova 
Signed-off-by: Dmitry V. Levin 
---

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

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

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


[PATCH v5 16/25] powerpc: define syscall_get_error()

2018-12-09 Thread Dmitry V. Levin
syscall_get_error() is required to be implemented on this
architecture in addition to already implemented syscall_get_nr(),
syscall_get_arguments(), syscall_get_return_value(), and
syscall_get_arch() functions in order to extend the generic
ptrace API with PTRACE_GET_SYSCALL_INFO request.

Cc: Michael Ellerman 
Cc: Benjamin Herrenschmidt 
Cc: Paul Mackerras 
Cc: Oleg Nesterov 
Cc: Andy Lutomirski 
Cc: Elvira Khabirova 
Cc: Eugene Syromyatnikov 
Cc: linuxppc-dev@lists.ozlabs.org
Signed-off-by: Dmitry V. Levin 
---

Notes:
This change has been tested with
tools/testing/selftests/ptrace/get_syscall_info.c and strace,
so it's correct from PTRACE_GET_SYSCALL_INFO point of view.

This cast doubts on commit v4.3-rc1~86^2~81 that changed
syscall_set_return_value() in a way that doesn't quite match
syscall_get_error(), but syscall_set_return_value() is out
of scope of this series, so I just air my concerns.

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

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


[PATCH v6] powerpc/ptrace: replace ptrace_report_syscall() with a tracehook call

2018-12-07 Thread Dmitry V. Levin
From: Elvira Khabirova 

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

Co-authored-by: Dmitry V. Levin 
Fixes: 5521eb4bca2d ("powerpc/ptrace: Add support for PTRACE_SYSEMU")
Cc: Michael Ellerman 
Cc: Benjamin Herrenschmidt 
Cc: Paul Mackerras 
Cc: Oleg Nesterov 
Cc: Breno Leitao 
Cc: Andy Lutomirski 
Cc: Eugene Syromyatnikov 
Cc: linuxppc-dev@lists.ozlabs.org
Signed-off-by: Elvira Khabirova 
Signed-off-by: Dmitry V. Levin 
---
Please make either v5 or v6 edition of this fix, or any similar fix,
into v4.20.

v6: reverted to a fixed version of v4, compile- and run-tested with strace
v5: reverted to a simple approach, compile- and run-tested
v4: rewritten to call tracehook_report_syscall_entry() once, compile-tested
v3: add a descriptive comment
v2: explicitly ignore tracehook_report_syscall_entry() return code
 arch/powerpc/kernel/ptrace.c | 54 +++-
 1 file changed, 35 insertions(+), 19 deletions(-)

diff --git a/arch/powerpc/kernel/ptrace.c b/arch/powerpc/kernel/ptrace.c
index afb819f4ca68..fcfdc1229f08 100644
--- a/arch/powerpc/kernel/ptrace.c
+++ b/arch/powerpc/kernel/ptrace.c
@@ -3263,27 +3263,43 @@ static inline int do_seccomp(struct pt_regs *regs) { 
return 0; }
  */
 long do_syscall_trace_enter(struct pt_regs *regs)
 {
+   struct thread_info *ti;
+   u32 cached_flags;
+
user_exit();
 
-   if (test_thread_flag(TIF_SYSCALL_EMU)) {
-   ptrace_report_syscall(regs);
-   /*
-* Returning -1 will skip the syscall execution. We want to
-* avoid clobbering any register also, thus, not 'gotoing'
-* skip label.
-*/
-   return -1;
-   }
+   ti = current_thread_info();
+   cached_flags = READ_ONCE(ti->flags) &
+  (_TIF_SYSCALL_EMU | _TIF_SYSCALL_TRACE |
+   _TIF_SYSCALL_TRACEPOINT);
 
-   /*
-* The tracer may decide to abort the syscall, if so tracehook
-* will return !0. Note that the tracer may also just change
-* regs->gpr[0] to an invalid syscall number, that is handled
-* below on the exit path.
-*/
-   if (test_thread_flag(TIF_SYSCALL_TRACE) &&
-   tracehook_report_syscall_entry(regs))
-   goto skip;
+   if (cached_flags & (_TIF_SYSCALL_EMU | _TIF_SYSCALL_TRACE)) {
+   int rc = tracehook_report_syscall_entry(regs);
+
+   if (unlikely(cached_flags & _TIF_SYSCALL_EMU)) {
+   /*
+* A nonzero return code from
+* tracehook_report_syscall_entry() tells us
+* to prevent the syscall execution, but
+* we are not going to execute it anyway.
+*
+* Returning -1 will skip the syscall execution.
+* We want to avoid clobbering any register also,
+* thus, not 'gotoing' skip label.
+*/
+   return -1;
+   }
+
+   if (rc) {
+   /*
+* The tracer decided to abort the syscall.
+* Note that the tracer may also just change
+* regs->gpr[0] to an invalid syscall number,
+* that is handled below on the exit path.
+*/
+   goto skip;
+   }
+   }
 
/* Run seccomp after ptrace; allow it to set gpr[3]. */
if (do_seccomp(regs))
@@ -3293,7 +3309,7 @@ long do_syscall_trace_enter(struct pt_regs *regs)
if (regs->gpr[0] >= NR_syscalls)
goto skip;
 
-   if (unlikely(test_thread_flag(TIF_SYSCALL_TRACEPOINT)))
+   if (unlikely(cached_flags & _TIF_SYSCALL_TRACEPOINT))
trace_sys_enter(regs, regs->gpr[0]);
 
 #ifdef CONFIG_PPC64
-- 
ldv


Re: [PATCH v4] powerpc/ptrace: replace ptrace_report_syscall() with a tracehook call

2018-12-07 Thread Dmitry V. Levin
On Fri, Dec 07, 2018 at 05:34:10PM +0100, Oleg Nesterov wrote:
> On 12/07, Dmitry V. Levin wrote:
> > On Fri, Dec 07, 2018 at 10:12:49PM +1100, Michael Ellerman wrote:
> >
> > > > Sorry, this patch does not work, please ignore it.
> > >
> > > Hmm OK. Why exactly?
> >
> > Unfortunately, I have no idea why it doesn't work.
> > All I can say is it breaks strace because the kernel no longer sends
> > syscall entry stops.
> 
> May be because TIF_SYSCALL_EMU/etc is a bit number, not a mask? IOW, rather
> than
> 
>   whatever & TIF_XXX
> 
> you should do
> 
>   whatever & _TIF_XXX
> 
> intstead?

Thanks Oleg, this was exactly the reason why it didn't work.
That kind of things happens when you let userspace people hack you kernel. :)


-- 
ldv


signature.asc
Description: PGP signature


[PATCH v5] powerpc/ptrace: replace ptrace_report_syscall() with a tracehook call

2018-12-07 Thread Dmitry V. Levin
From: Elvira Khabirova 

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

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

Co-authored-by: Dmitry V. Levin 
Fixes: 5521eb4bca2d ("powerpc/ptrace: Add support for PTRACE_SYSEMU")
Cc: Michael Ellerman 
Cc: Benjamin Herrenschmidt 
Cc: Paul Mackerras 
Cc: Oleg Nesterov 
Cc: Breno Leitao 
Cc: Andy Lutomirski 
Cc: Eugene Syromyatnikov 
Cc: linuxppc-dev@lists.ozlabs.org
Signed-off-by: Elvira Khabirova 
Signed-off-by: Dmitry V. Levin 
---
v5: reverted to a simple approach, compile- and run-tested
v4: rewritten to call tracehook_report_syscall_entry() once, compile-tested
v3: add a descriptive comment
v2: explicitly ignore tracehook_report_syscall_entry() return code

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

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


Re: [PATCH v4] powerpc/ptrace: replace ptrace_report_syscall() with a tracehook call

2018-12-07 Thread Dmitry V. Levin
On Fri, Dec 07, 2018 at 10:12:49PM +1100, Michael Ellerman wrote:
> "Dmitry V. Levin"  writes:
> > On Mon, Dec 03, 2018 at 06:18:23AM +0300, Dmitry V. Levin wrote:
> >> From: Elvira Khabirova 
> >> 
> >> Arch code should use tracehook_*() helpers, as documented
> >> in include/linux/tracehook.h,
> >> ptrace_report_syscall() is not expected to be used outside that file.
> >> 
> >> Co-authored-by: Dmitry V. Levin 
> >> Fixes: 5521eb4bca2d ("powerpc/ptrace: Add support for PTRACE_SYSEMU")
> >> Signed-off-by: Elvira Khabirova 
> >> Signed-off-by: Dmitry V. Levin 
> >> ---
> >> v4: rewritten to call tracehook_report_syscall_entry() once, compile-tested
> >> v3: add a descriptive comment
> >> v2: explicitly ignore tracehook_report_syscall_entry() return code
> >> 
> >>  arch/powerpc/kernel/ptrace.c | 54 +++-
> >>  1 file changed, 35 insertions(+), 19 deletions(-)
> >
> > Sorry, this patch does not work, please ignore it.
> 
> Hmm OK. Why exactly?

Unfortunately, I have no idea why it doesn't work.
All I can say is it breaks strace because the kernel no longer sends
syscall entry stops.

> I wrote more or less the same patch, although I used a temporary bool.
> 
> > However, the bug blocks PTRACE_GET_SYSCALL_INFO, so please fix it.
> 
> Sorry, didn't realise it was blocking you.

We are changing ptrace_report_syscall signature to implement
PTRACE_GET_SYSCALL_INFO, and this is the only place in the kernel besides
tracehook_report_syscall_*() that invokes ptrace_report_syscall() directly.

> > I'm going to use
> > if (tracehook_report_syscall_entry(regs))
> > return -1;
> > return -1;
> > in the series until you have a better fix.
> 
> Yeah that's fine by me. I could send that to Linus for 4.20 if you want
> me to, otherwise I'm fine for you to carry it in your series.

Yes, please.  I'll send a v5 shortly.


-- 
ldv


signature.asc
Description: PGP signature


Re: [PATCH v4] powerpc/ptrace: replace ptrace_report_syscall() with a tracehook call

2018-12-06 Thread Dmitry V. Levin
On Mon, Dec 03, 2018 at 06:18:23AM +0300, Dmitry V. Levin wrote:
> From: Elvira Khabirova 
> 
> Arch code should use tracehook_*() helpers, as documented
> in include/linux/tracehook.h,
> ptrace_report_syscall() is not expected to be used outside that file.
> 
> Co-authored-by: Dmitry V. Levin 
> Fixes: 5521eb4bca2d ("powerpc/ptrace: Add support for PTRACE_SYSEMU")
> Signed-off-by: Elvira Khabirova 
> Signed-off-by: Dmitry V. Levin 
> ---
> v4: rewritten to call tracehook_report_syscall_entry() once, compile-tested
> v3: add a descriptive comment
> v2: explicitly ignore tracehook_report_syscall_entry() return code
> 
>  arch/powerpc/kernel/ptrace.c | 54 +++-
>  1 file changed, 35 insertions(+), 19 deletions(-)

Sorry, this patch does not work, please ignore it.
However, the bug blocks PTRACE_GET_SYSCALL_INFO, so please fix it.

I'm going to use
if (tracehook_report_syscall_entry(regs))
return -1;
return -1;
in the series until you have a better fix.


-- 
ldv


signature.asc
Description: PGP signature


[PATCH v4] powerpc/ptrace: replace ptrace_report_syscall() with a tracehook call

2018-12-02 Thread Dmitry V. Levin
From: Elvira Khabirova 

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

Co-authored-by: Dmitry V. Levin 
Fixes: 5521eb4bca2d ("powerpc/ptrace: Add support for PTRACE_SYSEMU")
Signed-off-by: Elvira Khabirova 
Signed-off-by: Dmitry V. Levin 
---
v4: rewritten to call tracehook_report_syscall_entry() once, compile-tested
v3: add a descriptive comment
v2: explicitly ignore tracehook_report_syscall_entry() return code

 arch/powerpc/kernel/ptrace.c | 54 +++-
 1 file changed, 35 insertions(+), 19 deletions(-)

diff --git a/arch/powerpc/kernel/ptrace.c b/arch/powerpc/kernel/ptrace.c
index afb819f4ca68..59c8c9a3d7ea 100644
--- a/arch/powerpc/kernel/ptrace.c
+++ b/arch/powerpc/kernel/ptrace.c
@@ -3263,27 +3263,43 @@ static inline int do_seccomp(struct pt_regs *regs) { 
return 0; }
  */
 long do_syscall_trace_enter(struct pt_regs *regs)
 {
+   struct thread_info *ti;
+   u32 cached_flags;
+
user_exit();
 
-   if (test_thread_flag(TIF_SYSCALL_EMU)) {
-   ptrace_report_syscall(regs);
-   /*
-* Returning -1 will skip the syscall execution. We want to
-* avoid clobbering any register also, thus, not 'gotoing'
-* skip label.
-*/
-   return -1;
-   }
+   ti = current_thread_info();
+   cached_flags =
+   READ_ONCE(ti->flags) &
+   (TIF_SYSCALL_EMU | TIF_SYSCALL_TRACE | TIF_SYSCALL_TRACEPOINT);
 
-   /*
-* The tracer may decide to abort the syscall, if so tracehook
-* will return !0. Note that the tracer may also just change
-* regs->gpr[0] to an invalid syscall number, that is handled
-* below on the exit path.
-*/
-   if (test_thread_flag(TIF_SYSCALL_TRACE) &&
-   tracehook_report_syscall_entry(regs))
-   goto skip;
+   if (cached_flags & (TIF_SYSCALL_EMU | TIF_SYSCALL_TRACE)) {
+   int rc = tracehook_report_syscall_entry(regs);
+
+   if (unlikely(cached_flags & _TIF_SYSCALL_EMU)) {
+   /*
+* A nonzero return code from
+* tracehook_report_syscall_entry() tells us
+* to prevent the syscall execution, but
+* we are not going to execute it anyway.
+*
+* Returning -1 will skip the syscall execution.
+* We want to avoid clobbering any register also,
+* thus, not 'gotoing' skip label.
+*/
+   return -1;
+   }
+
+   if (rc) {
+   /*
+* The tracer decided to abort the syscall.
+* Note that the tracer may also just change
+* regs->gpr[0] to an invalid syscall number,
+* that is handled below on the exit path.
+*/
+   goto skip;
+   }
+   }
 
/* Run seccomp after ptrace; allow it to set gpr[3]. */
if (do_seccomp(regs))
@@ -3293,7 +3309,7 @@ long do_syscall_trace_enter(struct pt_regs *regs)
if (regs->gpr[0] >= NR_syscalls)
goto skip;
 
-   if (unlikely(test_thread_flag(TIF_SYSCALL_TRACEPOINT)))
+   if (unlikely(cached_flags & TIF_SYSCALL_TRACEPOINT))
trace_sys_enter(regs, regs->gpr[0]);
 
 #ifdef CONFIG_PPC64
-- 
ldv


[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-dev@lists.ozlabs.org
Cc: nios2-...@lists.rocketboards.org
Cc: openr...@lists.librecores.org
Cc: sparcli...@vger.kernel.org
Cc: uclinux-h8-de...@lists.sourceforge.jp
Cc: x...@kernel.org
Signed-off-by: Dmitry V. Levin 
---

v2: cleaned up mips part, added Reviewed-by

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

diff --git a/arch/alpha/include/asm/syscall.h b/arch/alpha/include/asm/syscall.h
index d73a6fcb519c..11c688c1d7ec 100644
--- a/arch/alpha/include/asm/syscall.h
+++ b/arch/alpha/include/asm/syscall.h
@@ -4,7 +4,7 @@
 
 #include 
 
-static inline int syscall_get_arch(void)
+static inline int syscall_get_arch(struct task_struct *task)
 {
return AUDIT_ARCH_ALPHA;
 }
diff --git a/arch/arc/include/asm/syscall.h b/arch/arc/include/asm/syscall.h
index 10b2e7523bc8..7834baa61de8 100644
--- a/arch/arc/include/asm/syscall.h
+++ b/arch/arc/include/asm/syscall.h
@@ -69,7 +69,7 @@ syscall_get_arguments(struct task_struct *task, struct 
pt_regs *regs,
}
 }
 
-static inline int syscall_get_arch(void)
+static inline int syscall_get_arch(struct task_struct *task)
 {
return IS_ENABLED(CONFIG_ISA_ARCOMPACT)
? (IS_ENABLED(CONFIG_CPU_BIG_ENDIAN)
diff --git a/arch/arm/include/asm/syscall.h b/arch/arm/include/asm/syscall.h
index 06dea6bce293..3940ceac0bdc 100644
--- a/arch/arm/include/asm/syscall.h
+++ b/arch/arm/include/asm/syscall.h
@@ -104,7 +104,7 @@ static inline void syscall_set_arguments(struct task_struct 
*task,
memcpy(®s->ARM_r0 + i, args, n * sizeof(args[0]));
 }
 
-static inline int syscall_get_arch(void)
+static inline int syscall_get_arch(struct task_struct *task)
 {
/* ARM tasks don't change audit architectures on the fly. */
return AUDIT_ARCH_ARM;
diff --git a/arch/arm64/include/asm/syscall.h b/arch/arm64/include/asm/syscall.h
index ad8be16a39c9..1870df03f774 100644
--- a/arch/arm64/include/asm/syscall.h
+++ b/arch/arm64/include/asm/syscall.h
@@ -117,9 +117,9 @@ static inline void syscall_set_arguments(struct task_struct 
*task,
  * We don't care about endianness (__AUDIT_ARCH_LE bit) here because
  * AArch64 has the same system calls both on little- and big- endian.
  */
-static inline int syscall_get_arch(void)
+static inline int syscall_get_arch(struct task_struct *task)
 {
-   if (is_compat_task())
+   if (is_compat_thread(task_thread_info(task)))
return AUDIT_ARCH_ARM;
 
return AUDIT_ARCH_AARCH64;
diff --git a/arch/c6x/include/asm/syscall.h b/arch/c6x/include/asm/syscall.h
index 39dbd1ef994c..595057191c9c 100644
--- a/arch/c6x/include/asm/syscall.h
+++ b/arch/c6x/include/

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-dev@lists.ozlabs.org
Cc: nios2-...@lists.rocketboards.org
Cc: openr...@lists.librecores.org
Cc: sparcli...@vger.kernel.org
Cc: uclinux-h8-de...@lists.sourceforge.jp
Cc: x...@kernel.org
Signed-off-by: Dmitry V. Levin 
---
 arch/alpha/include/asm/syscall.h  |  2 +-
 arch/arc/include/asm/syscall.h|  2 +-
 arch/arm/include/asm/syscall.h|  2 +-
 arch/arm64/include/asm/syscall.h  |  4 ++--
 arch/c6x/include/asm/syscall.h|  2 +-
 arch/h8300/include/asm/syscall.h  |  2 +-
 arch/hexagon/include/asm/syscall.h|  2 +-
 arch/ia64/include/asm/syscall.h   |  2 +-
 arch/m68k/include/asm/syscall.h   |  2 +-
 arch/microblaze/include/asm/syscall.h |  2 +-
 arch/mips/include/asm/syscall.h   |  8 
 arch/mips/kernel/ptrace.c |  2 +-
 arch/nds32/include/asm/syscall.h  |  2 +-
 arch/nios2/include/asm/syscall.h  |  2 +-
 arch/openrisc/include/asm/syscall.h   |  2 +-
 arch/parisc/include/asm/syscall.h |  4 ++--
 arch/powerpc/include/asm/syscall.h| 10 --
 arch/riscv/include/asm/syscall.h  |  2 +-
 arch/s390/include/asm/syscall.h   |  4 ++--
 arch/sh/include/asm/syscall_32.h  |  2 +-
 arch/sh/include/asm/syscall_64.h  |  2 +-
 arch/sparc/include/asm/syscall.h  |  5 +++--
 arch/unicore32/include/asm/syscall.h  |  2 +-
 arch/x86/include/asm/syscall.h|  8 +---
 arch/x86/um/asm/syscall.h |  2 +-
 arch/xtensa/include/asm/syscall.h |  2 +-
 include/asm-generic/syscall.h |  3 ++-
 kernel/auditsc.c  |  4 ++--
 kernel/seccomp.c  |  4 ++--
 29 files changed, 51 insertions(+), 41 deletions(-)

diff --git a/arch/alpha/include/asm/syscall.h b/arch/alpha/include/asm/syscall.h
index d73a6fcb519c..11c688c1d7ec 100644
--- a/arch/alpha/include/asm/syscall.h
+++ b/arch/alpha/include/asm/syscall.h
@@ -4,7 +4,7 @@
 
 #include 
 
-static inline int syscall_get_arch(void)
+static inline int syscall_get_arch(struct task_struct *task)
 {
return AUDIT_ARCH_ALPHA;
 }
diff --git a/arch/arc/include/asm/syscall.h b/arch/arc/include/asm/syscall.h
index 10b2e7523bc8..7834baa61de8 100644
--- a/arch/arc/include/asm/syscall.h
+++ b/arch/arc/include/asm/syscall.h
@@ -69,7 +69,7 @@ syscall_get_arguments(struct task_struct *task, struct 
pt_regs *regs,
}
 }
 
-static inline int syscall_get_arch(void)
+static inline int syscall_get_arch(struct task_struct *task)
 {
return IS_ENABLED(CONFIG_ISA_ARCOMPACT)
? (IS_ENABLED(CONFIG_CPU_BIG_ENDIAN)
diff --git a/arch/arm/include/asm/syscall.h b/arch/arm/include/asm/syscall.h
index 06dea6bce293..3940ceac0bdc 100644
--- a/arch/arm/include/asm/syscall.h
+++ b/arch/arm/include/asm/syscall.h
@@ -104,7 +104,7 @@ static inline void syscall_set_arguments(struct task_struct 
*task,
memcpy(®s->ARM_r0 + i, args, n * sizeof(args[0]));
 }
 
-static inline int syscall_get_arch(void)
+static inline int syscall_get_arch(struct task_struct *task)
 {
/* ARM tasks don't change audit architectures on the fly. */
return AUDIT_ARCH_ARM;
diff --git a/arch/arm64/include/asm/syscall.h b/arch/arm64/include/asm/syscall.h
index ad8be16a39c9..1870df03f774 100644
--- a/arch/arm64/include/asm/syscall.h
+++ b/arch/arm64/include/asm/syscall.h
@@ -117,9 +117,9 @@ static inline void syscall_set_arguments(struct task_struct 
*task,
  * We don't care about endianness (__AUDIT_ARCH_LE bit) here because
  * AArch64 has the same system calls both on little- and big- endian.
  */
-static inline int syscall_get_arch(void)
+static inline int syscall_get_arch(struct task_struct *task)
 {
-   if (is_compat_task())
+   if (is_compat_thread(task_thread_info(task)))
return AUDIT_ARCH_ARM;
 
return AUDIT_ARCH_AARCH64;
diff --git a/arch/c6x/include/asm/syscall.h b/arch/c6x/include/asm/syscall.h
index 39dbd1ef994c..595057191c9c 100644
--- a/arch/c6x/include/asm/syscall.h
+++ b/arch/c6x/include/asm/syscall.h
@@ -121,7 +121,7 @@ static inline void syscall_set_arguments(struct task_struct 
*task,
}

[PATCH v3] powerpc/ptrace: replace ptrace_report_syscall() with a tracehook call

2018-11-19 Thread Dmitry V. Levin
From: Elvira Khabirova 

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

Co-authored-by: Dmitry V. Levin 
Fixes: 5521eb4bca2d ("powerpc/ptrace: Add support for PTRACE_SYSEMU")
Signed-off-by: Elvira Khabirova 
Signed-off-by: Dmitry V. Levin 
---

v3: add a descriptive comment
v2: explicitly ignore tracehook_report_syscall_entry() return code

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

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


Re: sparc/ppc/arm compat siginfo ABI regressions: sending SIGFPE via kill() returns wrong values in si_pid and si_uid

2018-04-12 Thread Dmitry V. Levin
On Thu, Apr 12, 2018 at 09:50:26AM -0700, Linus Torvalds wrote:
> Does this attached patch perhaps fix the ARM case?
> 
> It just uses FPE_FLTUNK as the default si_code for SIGFPE, which seems
> sane enough. And then gets rid of FPE_FIXME, which should resolve the
> nasty case.
> 
> Hmm? Entirely untested, and I didn't really look at the test-case in
> question since I can't really run it anyway.
> 
> Well, I could run it all on x86-64, but it doesn't have that FPE_FIXME
> case at all.
> 
>  Linus

>  arch/arm/include/uapi/asm/siginfo.h | 7 ---
>  arch/arm/vfp/vfpmodule.c| 4 ++--
>  2 files changed, 2 insertions(+), 9 deletions(-)
> 
> diff --git a/arch/arm/include/uapi/asm/siginfo.h 
> b/arch/arm/include/uapi/asm/siginfo.h
> index d0513880be21..d87beeedb4c4 100644
> --- a/arch/arm/include/uapi/asm/siginfo.h
> +++ b/arch/arm/include/uapi/asm/siginfo.h
> @@ -3,11 +3,4 @@
>  
>  #include 
>  
> -/*
> - * SIGFPE si_codes
> - */
> -#ifdef __KERNEL__
> -#define FPE_FIXME0   /* Broken dup of SI_USER */
> -#endif /* __KERNEL__ */
> -
>  #endif

Looks like the whole file should go away.

> diff --git a/arch/arm/vfp/vfpmodule.c b/arch/arm/vfp/vfpmodule.c
> index 4c375e11ae95..012c6e690303 100644
> --- a/arch/arm/vfp/vfpmodule.c
> +++ b/arch/arm/vfp/vfpmodule.c
> @@ -251,13 +251,13 @@ static void vfp_panic(char *reason, u32 inst)
>   */
>  static void vfp_raise_exceptions(u32 exceptions, u32 inst, u32 fpscr, struct 
> pt_regs *regs)
>  {
> - int si_code = 0;
> + int si_code = FPE_FLTUNK;

Note that this change would affect the following code
at the end of vfp_raise_exceptions:

if (si_code)
vfp_raise_sigfpe(si_code, regs);

>   pr_debug("VFP: raising exceptions %08x\n", exceptions);
>  
>   if (exceptions == VFP_EXCEPTION_ERROR) {
>   vfp_panic("unhandled bounce", inst);
> - vfp_raise_sigfpe(FPE_FIXME, regs);
> + vfp_raise_sigfpe(si_code, regs);
>   return;
>   }
>  

To be on the safe side, I'd just change it this way:

diff --git a/arch/arm/vfp/vfpmodule.c b/arch/arm/vfp/vfpmodule.c
index 4c375e1..66a73ba 100644
--- a/arch/arm/vfp/vfpmodule.c
+++ b/arch/arm/vfp/vfpmodule.c
@@ -257,7 +257,7 @@ static void vfp_raise_exceptions(u32 exceptions, u32 inst, 
u32 fpscr, struct pt_
 
if (exceptions == VFP_EXCEPTION_ERROR) {
vfp_panic("unhandled bounce", inst);
-   vfp_raise_sigfpe(FPE_FIXME, regs);
+   vfp_raise_sigfpe(FPE_FLTUNK, regs);
return;
}

-- 
ldv


signature.asc
Description: PGP signature


Re: sparc/ppc/arm compat siginfo ABI regressions: sending SIGFPE via kill() returns wrong values in si_pid and si_uid

2018-04-12 Thread Dmitry V. Levin
On Thu, Apr 12, 2018 at 01:19:49PM +0100, Russell King - ARM Linux wrote:
> On Thu, Apr 12, 2018 at 02:03:14PM +0300, Dmitry V. Levin wrote:
> > On Thu, Apr 12, 2018 at 10:58:11AM +0100, Russell King - ARM Linux wrote:
> > > On Thu, Apr 12, 2018 at 04:34:35AM +0300, Dmitry V. Levin wrote:
> > > > A similar commit v4.16-rc1~159^2~37
> > > > ("signal/arm: Document conflicts with SI_USER and SIGFPE") must have
> > > > introduced a similar ABI regression to compat arm.
> > > 
> > > So, could you explain how can this change cause a regression?
> > > 
> > > +#define FPE_FIXME  0
> > > -   vfp_raise_sigfpe(0, regs);
> > > +   vfp_raise_sigfpe(FPE_FIXME, regs);
> > 
> > No, this hunk hasn't caused the regression, but another one did:
> > 
> > diff --git a/arch/arm/include/uapi/asm/siginfo.h 
> > b/arch/arm/include/uapi/asm/siginfo.h
> > new file mode 100644
> > index 000..d051388
> > --- /dev/null
> > +++ b/arch/arm/include/uapi/asm/siginfo.h
> > @@ -0,0 +1,13 @@
> > +#ifndef __ASM_SIGINFO_H
> > +#define __ASM_SIGINFO_H
> > +
> > +#include 
> > +
> > +/*
> > + * SIGFPE si_codes
> > + */
> > +#ifdef __KERNEL__
> > +#define FPE_FIXME  0   /* Broken dup of SI_USER */
> > +#endif /* __KERNEL__ */
> > +
> > +#endif
> > 
> > This is due to FPE_FIXME handling in kernel/signal.c
> 
> Building strace 4.22 on ARM and running the test suite reveals no
> problems with the signal_receive test, tested on both 4.14 and 4.16
> kernels - there's no "KERNEL BUG" reports in any of the test results.

https://build.opensuse.org/public/build/home:ldv_alt/openSUSE_Factory_ARM/armv7l/strace/_log
- the test just fails there with
[   50s] + uname -a
[   50s] Linux armbuild01 4.16.0-1-lpae #1 SMP PREEMPT Wed Apr 4 13:35:56 UTC 
2018 (e16f96d) armv7l armv7l armv7l GNU/Linux
...
[  570s] FAIL: signal_receive.gen
[  570s]  SIGFPE {si_signo=SIGFPE, si_code=SI_USER, si_pid=25332, 
si_uid=399} ---
[  570s] +--- SIGFPE {si_signo=SIGFPE, si_code=SI_USER, si_pid=25332, si_uid=0} 
---
[  570s] signal_receive.gen.test: failed test: ../../strace -a16 -e trace=kill 
../signal_receive output mismatch

> However, stock strace 4.22 source doesn't appear to contain the
> "KERNEL BUG" string anywhere, so this may be a Suse specific addition
> to the test:

The "KERNEL BUG" diagnostics I was talking about was added to strace yesterday
as a part of workaround commit, see
https://github.com/strace/strace/commit/34c7794cc16e2511eda7b1d5767c655a83b17309
Before that change the test just failed.

[...]
> Any ideas where the "KERNEL BUG" in Suse builds is coming from?

strace developers use OBS to test strace.git for regressions.
The build environment is provided by OBS, all the rest comes from strace.git.

> Any ideas how to test it on other architectures (iow, where can we get
> source that contains this test?)

Just use master branch of https://github.com/strace/strace
or https://gitlab.com/strace/strace (they are the same).

> Based on previous experience, unfortunately folk don't tend to report
> user ABI regressions to kernel developers, so we'd probably never know
> that there's a problem - I do think the safer thing would've been to
> leave it well alone, and just accept that we'll end up copying more
> words to userspace than is actually intended.

Well, these changes caused visible regressions in strace test suite on arm, ppc,
and sparc - this is the reason why I have reported them to kernel developers.


-- 
ldv


signature.asc
Description: PGP signature


Re: sparc/ppc/arm compat siginfo ABI regressions: sending SIGFPE via kill() returns wrong values in si_pid and si_uid

2018-04-12 Thread Dmitry V. Levin
On Thu, Apr 12, 2018 at 10:58:11AM +0100, Russell King - ARM Linux wrote:
> On Thu, Apr 12, 2018 at 04:34:35AM +0300, Dmitry V. Levin wrote:
> > A similar commit v4.16-rc1~159^2~37
> > ("signal/arm: Document conflicts with SI_USER and SIGFPE") must have
> > introduced a similar ABI regression to compat arm.
> 
> So, could you explain how can this change cause a regression?
> 
> +#define FPE_FIXME  0
> -   vfp_raise_sigfpe(0, regs);
> +   vfp_raise_sigfpe(FPE_FIXME, regs);

No, this hunk hasn't caused the regression, but another one did:

diff --git a/arch/arm/include/uapi/asm/siginfo.h 
b/arch/arm/include/uapi/asm/siginfo.h
new file mode 100644
index 000..d051388
--- /dev/null
+++ b/arch/arm/include/uapi/asm/siginfo.h
@@ -0,0 +1,13 @@
+#ifndef __ASM_SIGINFO_H
+#define __ASM_SIGINFO_H
+
+#include 
+
+/*
+ * SIGFPE si_codes
+ */
+#ifdef __KERNEL__
+#define FPE_FIXME  0   /* Broken dup of SI_USER */
+#endif /* __KERNEL__ */
+
+#endif

This is due to FPE_FIXME handling in kernel/signal.c


-- 
ldv


signature.asc
Description: PGP signature


Re: sparc/ppc/arm compat siginfo ABI regressions: sending SIGFPE via kill() returns wrong values in si_pid and si_uid

2018-04-11 Thread Dmitry V. Levin
Hi,

On Mon, Apr 09, 2018 at 06:22:53PM +0300, Dmitry V. Levin wrote:
> There seems to be a regression in v4.16 on ppc compat very similar
> to sparc compat regression reported earlier at
> https://marc.info/?l=linux-sparc&m=151501500704383 .
> 
> The symptoms are exactly the same: the same signal_receive test from
> the strace test suite fails with the same diagnostics:
> https://build.opensuse.org/public/build/home:ldv_alt/openSUSE_Factory_PowerPC/ppc/strace/_log

The log is big, just look for "KERNEL BUG".

> Unfortunately, I do not have any means to investigate further,
> so just passing this information on to those who care.

OK, the faulty commit is v4.16-rc1~159^2~39
("signal/powerpc: Document conflicts with SI_USER and SIGFPE and SIGTRAP").

One might think that a commit called "Document conflicts" shouldn't
introduce an ABI regression, but this one definitely does by defining
FPE_FIXME and TRAP_FIXME in arch/powerpc/include/uapi/asm/siginfo.h
that affect siginfo_layout().

A similar commit v4.16-rc1~159^2~37
("signal/arm: Document conflicts with SI_USER and SIGFPE") must have
introduced a similar ABI regression to compat arm.

An earlier commit v4.14-rc1~60^2^2~5
("signal/sparc: Document a conflict with SI_USER with SIGFPE") introduced
a similar ABI regression to compat sparc.

There is a clear pattern of sneaking in ABI changes using innocently
looking commit messages.


-- 
ldv


signature.asc
Description: PGP signature


ppc compat v4.16 regression: sending SIGTRAP or SIGFPE via kill() returns wrong values in si_pid and si_uid

2018-04-09 Thread Dmitry V. Levin
Hi,

There seems to be a regression in v4.16 on ppc compat very similar
to sparc compat regression reported earlier at
https://marc.info/?l=linux-sparc&m=151501500704383 .

The symptoms are exactly the same: the same signal_receive test from
the strace test suite fails with the same diagnostics:
https://build.opensuse.org/public/build/home:ldv_alt/openSUSE_Factory_PowerPC/ppc/strace/_log

Unfortunately, I do not have any means to investigate further,
so just passing this information on to those who care.


-- 
ldv


signature.asc
Description: PGP signature


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

2017-03-02 Thread Dmitry V. Levin
On Thu, Mar 02, 2017 at 10:22:18AM -0500, Carlos O'Donell wrote:
> On Wed, Mar 1, 2017 at 11:20 AM, Arnd Bergmann  wrote:
> > On Sun, Feb 26, 2017 at 2:01 AM, Dmitry V. Levin  wrote:
> >> 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.
[...]
> > I'm not sure if this is the best fix. We generally should not include one
> > standard header from another standard header. Would it be possible
> > to use __kernel_size_t instead of size_t?
> 
> In glibc we handle this with special use of __need_size_t with GCC's
> provided stddef.h.
> 
> For example glibc's signal.h does this:
> 
> # define __need_size_t
> # include 

Just to make it clear, do you suggest this approach for asm/signal.h as well?

[...]
> Changing the fundamental type causes the issues you see in patch v2
> where sizeof(size_t) < sizeof(__kernel_size_t).
> 
> It will only lead to problem substituting the wrong type.

I don't see any appetite for creating more ABIs like x32 with
sizeof(size_t) < sizeof(__kernel_size_t), so v2 approach
is not going to be any different from v1 in maintenance.


-- 
ldv


pgpXkNyzcKyrF.pgp
Description: PGP signature


[PATCH] uapi: fix another asm/shmbuf.h userspace compilation error

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

/usr/include/asm-generic/shmbuf.h:28:2: error: unknown type name 'size_t'
  size_t   shm_segsz; /* size of segment (bytes) */

x32 is the only architecture where sizeof(size_t) is less than
sizeof(__kernel_size_t), but as the kernel treats shm_segsz field as
__kernel_size_t anyway, UAPI should follow.  Thanks to little-endiannes
of x32 and 64-bit alignment of the field following shm_segsz, this
change doesn't break ABI, and the difference doesn't manifest itself
easily.

Signed-off-by: Dmitry V. Levin 
---
 include/uapi/asm-generic/shmbuf.h  | 2 +-
 arch/alpha/include/uapi/asm/shmbuf.h   | 2 +-
 arch/avr32/include/uapi/asm/shmbuf.h   | 2 +-
 arch/frv/include/uapi/asm/shmbuf.h | 2 +-
 arch/ia64/include/uapi/asm/shmbuf.h| 2 +-
 arch/m32r/include/uapi/asm/shmbuf.h| 2 +-
 arch/mips/include/uapi/asm/shmbuf.h| 2 +-
 arch/mn10300/include/uapi/asm/shmbuf.h | 2 +-
 arch/powerpc/include/uapi/asm/shmbuf.h | 2 +-
 arch/s390/include/uapi/asm/shmbuf.h| 2 +-
 arch/sparc/include/uapi/asm/shmbuf.h   | 2 +-
 arch/xtensa/include/uapi/asm/shmbuf.h  | 4 ++--
 12 files changed, 13 insertions(+), 13 deletions(-)

diff --git a/include/uapi/asm-generic/shmbuf.h 
b/include/uapi/asm-generic/shmbuf.h
index 2a6d508..0756934 100644
--- a/include/uapi/asm-generic/shmbuf.h
+++ b/include/uapi/asm-generic/shmbuf.h
@@ -25,7 +25,7 @@
 
 struct shmid64_ds {
struct ipc64_perm   shm_perm;   /* operation perms */
-   size_t  shm_segsz;  /* size of segment (bytes) */
+   __kernel_size_t shm_segsz;  /* size of segment (bytes) */
__kernel_time_t shm_atime;  /* last attach time */
 #if __BITS_PER_LONG != 64
unsigned long   __unused1;
diff --git a/arch/alpha/include/uapi/asm/shmbuf.h 
b/arch/alpha/include/uapi/asm/shmbuf.h
index 6156099..e32ed1f 100644
--- a/arch/alpha/include/uapi/asm/shmbuf.h
+++ b/arch/alpha/include/uapi/asm/shmbuf.h
@@ -14,7 +14,7 @@
 
 struct shmid64_ds {
struct ipc64_perm   shm_perm;   /* operation perms */
-   size_t  shm_segsz;  /* size of segment (bytes) */
+   __kernel_size_t shm_segsz;  /* size of segment (bytes) */
__kernel_time_t shm_atime;  /* last attach time */
__kernel_time_t shm_dtime;  /* last detach time */
__kernel_time_t shm_ctime;  /* last change time */
diff --git a/arch/avr32/include/uapi/asm/shmbuf.h 
b/arch/avr32/include/uapi/asm/shmbuf.h
index c8e5234..2804f25 100644
--- a/arch/avr32/include/uapi/asm/shmbuf.h
+++ b/arch/avr32/include/uapi/asm/shmbuf.h
@@ -15,7 +15,7 @@
 
 struct shmid64_ds {
struct ipc64_perm   shm_perm;   /* operation perms */
-   size_t  shm_segsz;  /* size of segment (bytes) */
+   __kernel_size_t shm_segsz;  /* size of segment (bytes) */
__kernel_time_t shm_atime;  /* last attach time */
unsigned long   __unused1;
__kernel_time_t shm_dtime;  /* last detach time */
diff --git a/arch/frv/include/uapi/asm/shmbuf.h 
b/arch/frv/include/uapi/asm/shmbuf.h
index 943746c..2af199f 100644
--- a/arch/frv/include/uapi/asm/shmbuf.h
+++ b/arch/frv/include/uapi/asm/shmbuf.h
@@ -15,7 +15,7 @@
 
 struct shmid64_ds {
struct ipc64_perm   shm_perm;   /* operation perms */
-   size_t  shm_segsz;  /* size of segment (bytes) */
+   __kernel_size_t shm_segsz;  /* size of segment (bytes) */
__kernel_time_t shm_atime;  /* last attach time */
unsigned long   __unused1;
__kernel_time_t shm_dtime;  /* last detach time */
diff --git a/arch/ia64/include/uapi/asm/shmbuf.h 
b/arch/ia64/include/uapi/asm/shmbuf.h
index ca81d77e..8e35495 100644
--- a/arch/ia64/include/uapi/asm/shmbuf.h
+++ b/arch/ia64/include/uapi/asm/shmbuf.h
@@ -14,7 +14,7 @@
 
 struct shmid64_ds {
struct ipc64_perm   shm_perm;   /* operation perms */
-   size_t  shm_segsz;  /* size of segment (bytes) */
+   __kernel_size_t shm_segsz;  /* size of segment (bytes) */
__kernel_time_t shm_atime;  /* last attach time */
__kernel_time_t shm_dtime;  /* last detach time */
__kernel_time_t shm_ctime;  /* last change time */
diff --git a/arch/m32r/include/uapi/asm/shmbuf.h 
b/arch/m32r/include/uapi/asm/shmbuf.h
index 714de6e..fa36b9e 100644
--- a/arch/m32r/include/uapi/asm/shmbuf.h
+++ b/arch/m32r/include/uapi/asm/shmbuf.h
@@ -15,7 +15,7 @@
 
 struct shmid64_ds {
struct ipc64_perm   shm_perm;   /* operation perms */
-   size_t  shm_segsz;  /* size of segment (bytes) */
+   __kernel_size_t shm_segsz;  /* si

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

2017-03-01 Thread Dmitry V. Levin
Include  to fix asm/shmbuf.h userspace compilation errors
like this:

/usr/include/asm-generic/shmbuf.h:26:20: error: field 'shm_perm' has incomplete 
type
  struct ipc64_perm shm_perm; /* operation perms */
/usr/include/asm-generic/shmbuf.h:28:2: error: unknown type name 
'__kernel_time_t'
  __kernel_time_t  shm_atime; /* last attach time */
/usr/include/asm-generic/shmbuf.h:32:2: error: unknown type name 
'__kernel_time_t'
  __kernel_time_t  shm_dtime; /* last detach time */
/usr/include/asm-generic/shmbuf.h:36:2: error: unknown type name 
'__kernel_time_t'
  __kernel_time_t  shm_ctime; /* last change time */
/usr/include/asm-generic/shmbuf.h:40:2: error: unknown type name 
'__kernel_pid_t'
  __kernel_pid_t  shm_cpid; /* pid of creator */
/usr/include/asm-generic/shmbuf.h:41:2: error: unknown type name 
'__kernel_pid_t'
  __kernel_pid_t  shm_lpid; /* pid of last operator */
/usr/include/asm-generic/shmbuf.h:42:2: error: unknown type name 
'__kernel_ulong_t'
  __kernel_ulong_t shm_nattch; /* no. of current attaches */
/usr/include/asm-generic/shmbuf.h:43:2: error: unknown type name 
'__kernel_ulong_t'
  __kernel_ulong_t __unused4;
/usr/include/asm-generic/shmbuf.h:44:2: error: unknown type name 
'__kernel_ulong_t'
  __kernel_ulong_t __unused5;
/usr/include/asm-generic/shmbuf.h:48:2: error: unknown type name 
'__kernel_ulong_t'
  __kernel_ulong_t shmmax;
/usr/include/asm-generic/shmbuf.h:49:2: error: unknown type name 
'__kernel_ulong_t'
  __kernel_ulong_t shmmin;
/usr/include/asm-generic/shmbuf.h:50:2: error: unknown type name 
'__kernel_ulong_t'
  __kernel_ulong_t shmmni;
/usr/include/asm-generic/shmbuf.h:51:2: error: unknown type name 
'__kernel_ulong_t'
  __kernel_ulong_t shmseg;
/usr/include/asm-generic/shmbuf.h:52:2: error: unknown type name 
'__kernel_ulong_t'
  __kernel_ulong_t shmall;
/usr/include/asm-generic/shmbuf.h:53:2: error: unknown type name 
'__kernel_ulong_t'
  __kernel_ulong_t __unused1;
/usr/include/asm-generic/shmbuf.h:54:2: error: unknown type name 
'__kernel_ulong_t'
  __kernel_ulong_t __unused2;
/usr/include/asm-generic/shmbuf.h:55:2: error: unknown type name 
'__kernel_ulong_t'
  __kernel_ulong_t __unused3;
/usr/include/asm-generic/shmbuf.h:56:2: error: unknown type name 
'__kernel_ulong_t'
  __kernel_ulong_t __unused4;

Signed-off-by: Dmitry V. Levin 
---
 include/uapi/asm-generic/shmbuf.h  | 1 +
 arch/alpha/include/uapi/asm/shmbuf.h   | 2 ++
 arch/avr32/include/uapi/asm/shmbuf.h   | 2 ++
 arch/frv/include/uapi/asm/shmbuf.h | 2 ++
 arch/ia64/include/uapi/asm/shmbuf.h| 2 ++
 arch/m32r/include/uapi/asm/shmbuf.h| 2 ++
 arch/mips/include/uapi/asm/shmbuf.h| 2 ++
 arch/mn10300/include/uapi/asm/shmbuf.h | 2 ++
 arch/parisc/include/uapi/asm/shmbuf.h  | 1 +
 arch/powerpc/include/uapi/asm/shmbuf.h | 2 ++
 arch/s390/include/uapi/asm/shmbuf.h| 2 ++
 arch/sparc/include/uapi/asm/shmbuf.h   | 2 ++
 arch/xtensa/include/uapi/asm/shmbuf.h  | 2 ++
 13 files changed, 24 insertions(+)

diff --git a/include/uapi/asm-generic/shmbuf.h 
b/include/uapi/asm-generic/shmbuf.h
index 7e9fb2f..2a6d508 100644
--- a/include/uapi/asm-generic/shmbuf.h
+++ b/include/uapi/asm-generic/shmbuf.h
@@ -1,6 +1,7 @@
 #ifndef __ASM_GENERIC_SHMBUF_H
 #define __ASM_GENERIC_SHMBUF_H
 
+#include 
 #include 
 
 /*
diff --git a/arch/alpha/include/uapi/asm/shmbuf.h 
b/arch/alpha/include/uapi/asm/shmbuf.h
index 37ee84f..6156099 100644
--- a/arch/alpha/include/uapi/asm/shmbuf.h
+++ b/arch/alpha/include/uapi/asm/shmbuf.h
@@ -1,6 +1,8 @@
 #ifndef _ALPHA_SHMBUF_H
 #define _ALPHA_SHMBUF_H
 
+#include 
+
 /* 
  * The shmid64_ds structure for alpha architecture.
  * Note extra padding because this structure is passed back and forth
diff --git a/arch/avr32/include/uapi/asm/shmbuf.h 
b/arch/avr32/include/uapi/asm/shmbuf.h
index b94cf8b..c8e5234 100644
--- a/arch/avr32/include/uapi/asm/shmbuf.h
+++ b/arch/avr32/include/uapi/asm/shmbuf.h
@@ -1,6 +1,8 @@
 #ifndef _UAPI__ASM_AVR32_SHMBUF_H
 #define _UAPI__ASM_AVR32_SHMBUF_H
 
+#include 
+
 /*
  * The shmid64_ds structure for i386 architecture.
  * Note extra padding because this structure is passed back and forth
diff --git a/arch/frv/include/uapi/asm/shmbuf.h 
b/arch/frv/include/uapi/asm/shmbuf.h
index 4c6e711..943746c 100644
--- a/arch/frv/include/uapi/asm/shmbuf.h
+++ b/arch/frv/include/uapi/asm/shmbuf.h
@@ -1,6 +1,8 @@
 #ifndef _ASM_SHMBUF_H
 #define _ASM_SHMBUF_H
 
+#include 
+
 /*
  * The shmid64_ds structure for FR-V architecture.
  * Note extra padding because this structure is passed back and forth
diff --git a/arch/ia64/include/uapi/asm/shmbuf.h 
b/arch/ia64/include/uapi/asm/shmbuf.h
index 585002a..ca81d77e 100644
--- a/arch/ia64/include/uapi/asm/shmbuf.h
+++ b/arch/ia64/include/uapi/asm/shmbuf.h
@@ -1,6 +1,8 @@
 #ifndef _ASM_IA64_SHMBUF_H
 #define _ASM_IA64_SHMBUF_H
 
+#include 
+
 /*

[PATCH 2/3] uapi: fix asm/sembuf.h userspace compilation errors

2017-03-01 Thread Dmitry V. Levin
Include  to fix asm/sembuf.h userspace compilation errors
like this:

/usr/include/asm/sembuf.h:14:20: error: field 'sem_perm' has incomplete type
  struct ipc64_perm sem_perm; /* permissions .. see ipc.h */
/usr/include/asm/sembuf.h:15:2: error: unknown type name '__kernel_time_t'
  __kernel_time_t sem_otime; /* last semop time */
/usr/include/asm/sembuf.h:16:2: error: unknown type name '__kernel_ulong_t'
  __kernel_ulong_t __unused1;
/usr/include/asm/sembuf.h:17:2: error: unknown type name '__kernel_time_t'
  __kernel_time_t sem_ctime; /* last change time */
/usr/include/asm/sembuf.h:18:2: error: unknown type name '__kernel_ulong_t'
  __kernel_ulong_t __unused2;
/usr/include/asm/sembuf.h:19:2: error: unknown type name '__kernel_ulong_t'
  __kernel_ulong_t sem_nsems; /* no. of semaphores in array */
/usr/include/asm/sembuf.h:20:2: error: unknown type name '__kernel_ulong_t'
  __kernel_ulong_t __unused3;
/usr/include/asm/sembuf.h:21:2: error: unknown type name '__kernel_ulong_t'
  __kernel_ulong_t __unused4;

Signed-off-by: Dmitry V. Levin 
---
 include/uapi/asm-generic/sembuf.h  | 1 +
 arch/alpha/include/uapi/asm/sembuf.h   | 2 ++
 arch/avr32/include/uapi/asm/sembuf.h   | 2 ++
 arch/frv/include/uapi/asm/sembuf.h | 2 ++
 arch/ia64/include/uapi/asm/sembuf.h| 2 ++
 arch/m32r/include/uapi/asm/sembuf.h| 2 ++
 arch/mips/include/uapi/asm/sembuf.h| 2 ++
 arch/mn10300/include/uapi/asm/sembuf.h | 2 ++
 arch/parisc/include/uapi/asm/sembuf.h  | 1 +
 arch/powerpc/include/uapi/asm/sembuf.h | 2 ++
 arch/s390/include/uapi/asm/sembuf.h| 2 ++
 arch/sparc/include/uapi/asm/sembuf.h   | 2 ++
 arch/x86/include/uapi/asm/sembuf.h | 2 ++
 arch/xtensa/include/uapi/asm/sembuf.h  | 1 +
 14 files changed, 25 insertions(+)

diff --git a/include/uapi/asm-generic/sembuf.h 
b/include/uapi/asm-generic/sembuf.h
index 4cb2c13..1d910d7 100644
--- a/include/uapi/asm-generic/sembuf.h
+++ b/include/uapi/asm-generic/sembuf.h
@@ -1,6 +1,7 @@
 #ifndef __ASM_GENERIC_SEMBUF_H
 #define __ASM_GENERIC_SEMBUF_H
 
+#include 
 #include 
 
 /*
diff --git a/arch/alpha/include/uapi/asm/sembuf.h 
b/arch/alpha/include/uapi/asm/sembuf.h
index 7b38b15..b6bdd5f 100644
--- a/arch/alpha/include/uapi/asm/sembuf.h
+++ b/arch/alpha/include/uapi/asm/sembuf.h
@@ -1,6 +1,8 @@
 #ifndef _ALPHA_SEMBUF_H
 #define _ALPHA_SEMBUF_H
 
+#include 
+
 /* 
  * The semid64_ds structure for alpha architecture.
  * Note extra padding because this structure is passed back and forth
diff --git a/arch/avr32/include/uapi/asm/sembuf.h 
b/arch/avr32/include/uapi/asm/sembuf.h
index 6c6f7cf..ec4ddd6 100644
--- a/arch/avr32/include/uapi/asm/sembuf.h
+++ b/arch/avr32/include/uapi/asm/sembuf.h
@@ -1,6 +1,8 @@
 #ifndef _UAPI__ASM_AVR32_SEMBUF_H
 #define _UAPI__ASM_AVR32_SEMBUF_H
 
+#include 
+
 /*
 * The semid64_ds structure for AVR32 architecture.
  * Note extra padding because this structure is passed back and forth
diff --git a/arch/frv/include/uapi/asm/sembuf.h 
b/arch/frv/include/uapi/asm/sembuf.h
index 164b127..0d73641 100644
--- a/arch/frv/include/uapi/asm/sembuf.h
+++ b/arch/frv/include/uapi/asm/sembuf.h
@@ -1,6 +1,8 @@
 #ifndef _ASM_SEMBUF_H
 #define _ASM_SEMBUF_H
 
+#include 
+
 /*
  * The semid64_ds structure for FR-V architecture.
  * Note extra padding because this structure is passed back and forth
diff --git a/arch/ia64/include/uapi/asm/sembuf.h 
b/arch/ia64/include/uapi/asm/sembuf.h
index 1340fbc..2e218b0 100644
--- a/arch/ia64/include/uapi/asm/sembuf.h
+++ b/arch/ia64/include/uapi/asm/sembuf.h
@@ -1,6 +1,8 @@
 #ifndef _ASM_IA64_SEMBUF_H
 #define _ASM_IA64_SEMBUF_H
 
+#include 
+
 /*
  * The semid64_ds structure for IA-64 architecture.
  * Note extra padding because this structure is passed back and forth
diff --git a/arch/m32r/include/uapi/asm/sembuf.h 
b/arch/m32r/include/uapi/asm/sembuf.h
index c9873d6..58ad1f8 100644
--- a/arch/m32r/include/uapi/asm/sembuf.h
+++ b/arch/m32r/include/uapi/asm/sembuf.h
@@ -1,6 +1,8 @@
 #ifndef _ASM_M32R_SEMBUF_H
 #define _ASM_M32R_SEMBUF_H
 
+#include 
+
 /*
  * The semid64_ds structure for m32r architecture.
  * Note extra padding because this structure is passed back and forth
diff --git a/arch/mips/include/uapi/asm/sembuf.h 
b/arch/mips/include/uapi/asm/sembuf.h
index e1085ac..a55ab3c 100644
--- a/arch/mips/include/uapi/asm/sembuf.h
+++ b/arch/mips/include/uapi/asm/sembuf.h
@@ -1,6 +1,8 @@
 #ifndef _ASM_SEMBUF_H
 #define _ASM_SEMBUF_H
 
+#include 
+
 /*
  * The semid64_ds structure for the MIPS architecture.
  * Note extra padding because this structure is passed back and forth
diff --git a/arch/mn10300/include/uapi/asm/sembuf.h 
b/arch/mn10300/include/uapi/asm/sembuf.h
index 301f3f9..3529f55 100644
--- a/arch/mn10300/include/uapi/asm/sembuf.h
+++ b/arch/mn10300/include/uapi/asm/sembuf.h
@@ -1,6 +1,8 @@
 #ifndef _ASM_SEMBUF_H
 #define _ASM_SEMBUF_H
 
+#include 
+
 /*
  * The semid64_ds structure for MN10300 architecture.
  * Note extra 

[PATCH 1/3] uapi: fix asm/msgbuf.h userspace compilation errors

2017-03-01 Thread Dmitry V. Levin
Include  to fix asm/msgbuf.h userspace compilation errors
like this:

/usr/include/asm-generic/msgbuf.h:25:20: error: field 'msg_perm' has incomplete 
type
  struct ipc64_perm msg_perm;
/usr/include/asm-generic/msgbuf.h:26:2: error: unknown type name 
'__kernel_time_t'
  __kernel_time_t msg_stime; /* last msgsnd time */
/usr/include/asm-generic/msgbuf.h:30:2: error: unknown type name 
'__kernel_time_t'
  __kernel_time_t msg_rtime; /* last msgrcv time */
/usr/include/asm-generic/msgbuf.h:34:2: error: unknown type name 
'__kernel_time_t'
  __kernel_time_t msg_ctime; /* last change time */
/usr/include/asm-generic/msgbuf.h:38:2: error: unknown type name 
'__kernel_ulong_t'
  __kernel_ulong_t msg_cbytes; /* current number of bytes on queue */
/usr/include/asm-generic/msgbuf.h:39:2: error: unknown type name 
'__kernel_ulong_t'
  __kernel_ulong_t msg_qnum; /* number of messages in queue */
/usr/include/asm-generic/msgbuf.h:40:2: error: unknown type name 
'__kernel_ulong_t'
  __kernel_ulong_t msg_qbytes; /* max number of bytes on queue */
/usr/include/asm-generic/msgbuf.h:41:2: error: unknown type name 
'__kernel_pid_t'
  __kernel_pid_t msg_lspid; /* pid of last msgsnd */
/usr/include/asm-generic/msgbuf.h:42:2: error: unknown type name 
'__kernel_pid_t'
  __kernel_pid_t msg_lrpid; /* last receive pid */
/usr/include/asm-generic/msgbuf.h:43:2: error: unknown type name 
'__kernel_ulong_t'
  __kernel_ulong_t __unused4;
/usr/include/asm-generic/msgbuf.h:44:2: error: unknown type name 
'__kernel_ulong_t'
  __kernel_ulong_t __unused5;

Signed-off-by: Dmitry V. Levin 
---
 include/uapi/asm-generic/msgbuf.h  | 1 +
 arch/alpha/include/uapi/asm/msgbuf.h   | 2 ++
 arch/avr32/include/uapi/asm/msgbuf.h   | 2 ++
 arch/frv/include/uapi/asm/msgbuf.h | 2 ++
 arch/ia64/include/uapi/asm/msgbuf.h| 2 ++
 arch/m32r/include/uapi/asm/msgbuf.h| 2 ++
 arch/mips/include/uapi/asm/msgbuf.h| 1 +
 arch/mn10300/include/uapi/asm/msgbuf.h | 2 ++
 arch/parisc/include/uapi/asm/msgbuf.h  | 1 +
 arch/powerpc/include/uapi/asm/msgbuf.h | 2 ++
 arch/s390/include/uapi/asm/msgbuf.h| 2 ++
 arch/sparc/include/uapi/asm/msgbuf.h   | 2 ++
 arch/xtensa/include/uapi/asm/msgbuf.h  | 2 ++
 13 files changed, 23 insertions(+)

diff --git a/include/uapi/asm-generic/msgbuf.h 
b/include/uapi/asm-generic/msgbuf.h
index f55ecc4..f3c3b43 100644
--- a/include/uapi/asm-generic/msgbuf.h
+++ b/include/uapi/asm-generic/msgbuf.h
@@ -1,6 +1,7 @@
 #ifndef __ASM_GENERIC_MSGBUF_H
 #define __ASM_GENERIC_MSGBUF_H
 
+#include 
 #include 
 /*
  * generic msqid64_ds structure.
diff --git a/arch/alpha/include/uapi/asm/msgbuf.h 
b/arch/alpha/include/uapi/asm/msgbuf.h
index 9849650..8de899a 100644
--- a/arch/alpha/include/uapi/asm/msgbuf.h
+++ b/arch/alpha/include/uapi/asm/msgbuf.h
@@ -1,6 +1,8 @@
 #ifndef _ALPHA_MSGBUF_H
 #define _ALPHA_MSGBUF_H
 
+#include 
+
 /* 
  * The msqid64_ds structure for alpha architecture.
  * Note extra padding because this structure is passed back and forth
diff --git a/arch/avr32/include/uapi/asm/msgbuf.h 
b/arch/avr32/include/uapi/asm/msgbuf.h
index 9eae6ef..45cdffb 100644
--- a/arch/avr32/include/uapi/asm/msgbuf.h
+++ b/arch/avr32/include/uapi/asm/msgbuf.h
@@ -1,6 +1,8 @@
 #ifndef _UAPI__ASM_AVR32_MSGBUF_H
 #define _UAPI__ASM_AVR32_MSGBUF_H
 
+#include 
+
 /*
  * The msqid64_ds structure for i386 architecture.
  * Note extra padding because this structure is passed back and forth
diff --git a/arch/frv/include/uapi/asm/msgbuf.h 
b/arch/frv/include/uapi/asm/msgbuf.h
index 97ceb55..92d6656 100644
--- a/arch/frv/include/uapi/asm/msgbuf.h
+++ b/arch/frv/include/uapi/asm/msgbuf.h
@@ -1,6 +1,8 @@
 #ifndef _ASM_MSGBUF_H
 #define _ASM_MSGBUF_H
 
+#include 
+
 /*
  * The msqid64_ds structure for FR-V architecture.
  * Note extra padding because this structure is passed back and forth
diff --git a/arch/ia64/include/uapi/asm/msgbuf.h 
b/arch/ia64/include/uapi/asm/msgbuf.h
index 6c64c0d..9a31b60 100644
--- a/arch/ia64/include/uapi/asm/msgbuf.h
+++ b/arch/ia64/include/uapi/asm/msgbuf.h
@@ -1,6 +1,8 @@
 #ifndef _ASM_IA64_MSGBUF_H
 #define _ASM_IA64_MSGBUF_H
 
+#include 
+
 /*
  * The msqid64_ds structure for IA-64 architecture.
  * Note extra padding because this structure is passed back and forth
diff --git a/arch/m32r/include/uapi/asm/msgbuf.h 
b/arch/m32r/include/uapi/asm/msgbuf.h
index 0d5a877..4786c0c 100644
--- a/arch/m32r/include/uapi/asm/msgbuf.h
+++ b/arch/m32r/include/uapi/asm/msgbuf.h
@@ -1,6 +1,8 @@
 #ifndef _ASM_M32R_MSGBUF_H
 #define _ASM_M32R_MSGBUF_H
 
+#include 
+
 /*
  * The msqid64_ds structure for m32r architecture.
  * Note extra padding because this structure is passed back and forth
diff --git a/arch/mips/include/uapi/asm/msgbuf.h 
b/arch/mips/include/uapi/asm/msgbuf.h
index df849e8..c84a388 100644
--- a/arch/mips/include/uapi/asm/msgbuf.h
+++ b/arch/mips/include/uapi/asm/msgbuf.h
@@ -1,6 +1,7 @@
 #ifndef _ASM_M

[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 
---
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 --git a/arch/mips/inc

[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 
---
 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
index