Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > linux.kernel > #1184386 > unrolled thread
| Started by | Michael Ellerman <mpe@ellerman.id.au> |
|---|---|
| First post | 2015-07-15 09:40 +0200 |
| Last post | 2015-07-17 06:50 +0200 |
| Articles | 11 — 3 participants |
Back to article view | Back to linux.kernel
[RFC PATCH 01/12] powerpc/kernel: Get pt_regs from r9 before calling do_syscall_trace_enter() Michael Ellerman <mpe@ellerman.id.au> - 2015-07-15 09:40 +0200
[RFC PATCH 03/12] powerpc/kernel: Change the do_syscall_trace_enter() API Michael Ellerman <mpe@ellerman.id.au> - 2015-07-15 09:40 +0200
[RFC PATCH 11/12] selftests/seccomp: Make seccomp tests work on big endian Michael Ellerman <mpe@ellerman.id.au> - 2015-07-15 09:40 +0200
Re: [RFC PATCH 11/12] selftests/seccomp: Make seccomp tests work on big endian Kees Cook <keescook@chromium.org> - 2015-07-15 17:20 +0200
Re: [RFC PATCH 11/12] selftests/seccomp: Make seccomp tests work on big endian Michael Ellerman <mpe@ellerman.id.au> - 2015-07-16 05:50 +0200
[RFC PATCH 04/12] powerpc: Drop unused syscall_get_error() Michael Ellerman <mpe@ellerman.id.au> - 2015-07-15 09:40 +0200
[RFC PATCH 07/12] powerpc: Use orig_gpr3 in syscall_get_arguments() Michael Ellerman <mpe@ellerman.id.au> - 2015-07-15 09:40 +0200
[RFC PATCH 02/12] powerpc/kernel: Switch to using MAX_ERRNO Michael Ellerman <mpe@ellerman.id.au> - 2015-07-15 09:50 +0200
Re: [RFC PATCH 02/12] powerpc/kernel: Switch to using MAX_ERRNO Benjamin Herrenschmidt <benh@kernel.crashing.org> - 2015-07-17 00:50 +0200
Re: [RFC PATCH 01/12] powerpc/kernel: Get pt_regs from r9 before calling do_syscall_trace_enter() Benjamin Herrenschmidt <benh@kernel.crashing.org> - 2015-07-17 00:50 +0200
Re: [RFC PATCH 01/12] powerpc/kernel: Get pt_regs from r9 before calling do_syscall_trace_enter() Michael Ellerman <mpe@ellerman.id.au> - 2015-07-17 06:50 +0200
| From | Michael Ellerman <mpe@ellerman.id.au> |
|---|---|
| Date | 2015-07-15 09:40 +0200 |
| Subject | [RFC PATCH 01/12] powerpc/kernel: Get pt_regs from r9 before calling do_syscall_trace_enter() |
| Message-ID | <pMpsl-LG-3@gated-at.bofh.it> |
To call do_syscall_trace_enter() we need pt_regs in r3, but we don't need to recalculate it based on r1, it's already in r9. Signed-off-by: Michael Ellerman <mpe@ellerman.id.au> --- arch/powerpc/kernel/entry_64.S | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/arch/powerpc/kernel/entry_64.S b/arch/powerpc/kernel/entry_64.S index 579e0f9a2d57..0796c487d3db 100644 --- a/arch/powerpc/kernel/entry_64.S +++ b/arch/powerpc/kernel/entry_64.S @@ -243,7 +243,9 @@ syscall_error: /* Traced system call support */ syscall_dotrace: bl save_nvgprs - addi r3,r1,STACK_FRAME_OVERHEAD + + /* Get pt_regs into r3 */ + mr r3, r9 bl do_syscall_trace_enter /* * Restore argument registers possibly just changed. -- 2.1.0 -- To unsubscribe from this list: send the line "unsubscribe linux-kernel" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html Please read the FAQ at http://www.tux.org/lkml/
[toc] | [next] | [standalone]
| From | Michael Ellerman <mpe@ellerman.id.au> |
|---|---|
| Date | 2015-07-15 09:40 +0200 |
| Subject | [RFC PATCH 03/12] powerpc/kernel: Change the do_syscall_trace_enter() API |
| Message-ID | <pMpsm-LG-27@gated-at.bofh.it> |
| In reply to | #1184386 |
The API for calling do_syscall_trace_enter() is currently sensible
enough, it just returns the (modified) syscall number.
However once we enable seccomp filter it will get more complicated. When
seccomp filter runs, the seccomp kernel code (via SECCOMP_RET_ERRNO), or
a ptracer (via SECCOMP_RET_TRACE), may reject the syscall and *may* or may
*not* set a return value in r3.
That means the assembler that calls do_syscall_trace_enter() can not
blindly return ENOSYS, it needs to only return ENOSYS if a return value
has not already been set.
There is no way to implement that logic with the current API. So change
the do_syscall_trace_enter() API to make it deal with the return code
juggling, and the assembler can then just return whatever return code it
is given.
Signed-off-by: Michael Ellerman <mpe@ellerman.id.au>
---
arch/powerpc/kernel/entry_32.S | 4 ++++
arch/powerpc/kernel/entry_64.S | 23 ++++++++++++++------
arch/powerpc/kernel/ptrace.c | 48 ++++++++++++++++++++++++++++++++----------
3 files changed, 58 insertions(+), 17 deletions(-)
diff --git a/arch/powerpc/kernel/entry_32.S b/arch/powerpc/kernel/entry_32.S
index 67ecdf61f4e3..2405631e91a2 100644
--- a/arch/powerpc/kernel/entry_32.S
+++ b/arch/powerpc/kernel/entry_32.S
@@ -458,6 +458,10 @@ syscall_dotrace:
lwz r7,GPR7(r1)
lwz r8,GPR8(r1)
REST_NVGPRS(r1)
+
+ cmplwi r0,NR_syscalls
+ /* Return code is already in r3 thanks to do_syscall_trace_enter() */
+ bge- ret_from_syscall
b syscall_dotrace_cont
syscall_exit_work:
diff --git a/arch/powerpc/kernel/entry_64.S b/arch/powerpc/kernel/entry_64.S
index 8292581a42f1..41f8fcf615d7 100644
--- a/arch/powerpc/kernel/entry_64.S
+++ b/arch/powerpc/kernel/entry_64.S
@@ -151,8 +151,7 @@ END_FW_FTR_SECTION_IFSET(FW_FEATURE_SPLPAR)
CURRENT_THREAD_INFO(r11, r1)
ld r10,TI_FLAGS(r11)
andi. r11,r10,_TIF_SYSCALL_DOTRACE
- bne syscall_dotrace
-.Lsyscall_dotrace_cont:
+ bne syscall_dotrace /* does not return */
cmpldi 0,r0,NR_syscalls
bge- syscall_enosys
@@ -248,22 +247,34 @@ syscall_dotrace:
/* Get pt_regs into r3 */
mr r3, r9
bl do_syscall_trace_enter
+
/*
- * Restore argument registers possibly just changed.
- * We use the return value of do_syscall_trace_enter
- * for the call number to look up in the table (r0).
+ * We use the return value of do_syscall_trace_enter() as the syscall
+ * number. If the syscall was rejected for any reason do_syscall_trace_enter()
+ * returns an invalid syscall number and the test below against
+ * NR_syscalls will fail.
*/
mr r0,r3
+
+ /* Restore argument registers just clobbered and/or possibly changed. */
ld r3,GPR3(r1)
ld r4,GPR4(r1)
ld r5,GPR5(r1)
ld r6,GPR6(r1)
ld r7,GPR7(r1)
ld r8,GPR8(r1)
+
+ /* Repopulate r9 and r10 for the system_call path */
addi r9,r1,STACK_FRAME_OVERHEAD
CURRENT_THREAD_INFO(r10, r1)
ld r10,TI_FLAGS(r10)
- b .Lsyscall_dotrace_cont
+
+ cmpldi r0,NR_syscalls
+ blt+ system_call
+
+ /* Return code is already in r3 thanks to do_syscall_trace_enter() */
+ b .Lsyscall_exit
+
syscall_enosys:
li r3,-ENOSYS
diff --git a/arch/powerpc/kernel/ptrace.c b/arch/powerpc/kernel/ptrace.c
index f21897b42057..7484221bb3f8 100644
--- a/arch/powerpc/kernel/ptrace.c
+++ b/arch/powerpc/kernel/ptrace.c
@@ -1762,26 +1762,42 @@ long arch_ptrace(struct task_struct *child, long request,
return ret;
}
-/*
- * We must return the syscall number to actually look up in the table.
- * This can be -1L to skip running any syscall at all.
+/**
+ * do_syscall_trace_enter() - Do syscall tracing on kernel entry.
+ * @regs: the pt_regs of the task to trace (current)
+ *
+ * Performs various types of tracing on syscall entry. This includes seccomp,
+ * ptrace, syscall tracepoints and audit.
+ *
+ * The pt_regs are potentially visible to userspace via ptrace, so their
+ * contents is ABI.
+ *
+ * One or more of the tracers may modify the contents of pt_regs, in particular
+ * to modify arguments or even the syscall number itself.
+ *
+ * It's also possible that a tracer can choose to reject the system call. In
+ * that case this function will return an illegal syscall number, and will put
+ * an appropriate return value in regs->r3.
+ *
+ * Return: the (possibly changed) syscall number.
*/
long do_syscall_trace_enter(struct pt_regs *regs)
{
- long ret = 0;
+ bool abort = false;
user_exit();
secure_computing_strict(regs->gpr[0]);
- if (test_thread_flag(TIF_SYSCALL_TRACE) &&
- tracehook_report_syscall_entry(regs))
+ if (test_thread_flag(TIF_SYSCALL_TRACE)) {
/*
- * Tracing decided this syscall should not happen.
- * We'll return a bogus call number to get an ENOSYS
- * error, but leave the original number in regs->gpr[0].
+ * 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.
*/
- ret = -1L;
+ abort = tracehook_report_syscall_entry(regs) != 0;
+ }
if (unlikely(test_thread_flag(TIF_SYSCALL_TRACEPOINT)))
trace_sys_enter(regs, regs->gpr[0]);
@@ -1798,7 +1814,17 @@ long do_syscall_trace_enter(struct pt_regs *regs)
regs->gpr[5] & 0xffffffff,
regs->gpr[6] & 0xffffffff);
- return ret ?: regs->gpr[0];
+ if (abort || regs->gpr[0] >= NR_syscalls) {
+ /*
+ * If we are aborting explicitly, or if the syscall number is
+ * now invalid, set the return value to -ENOSYS.
+ */
+ regs->gpr[3] = -ENOSYS;
+ return -1;
+ }
+
+ /* Return the possibly modified but valid syscall number */
+ return regs->gpr[0];
}
void do_syscall_trace_leave(struct pt_regs *regs)
--
2.1.0
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/
[toc] | [prev] | [next] | [standalone]
| From | Michael Ellerman <mpe@ellerman.id.au> |
|---|---|
| Date | 2015-07-15 09:40 +0200 |
| Subject | [RFC PATCH 11/12] selftests/seccomp: Make seccomp tests work on big endian |
| Message-ID | <pMpsm-LG-31@gated-at.bofh.it> |
| In reply to | #1184386 |
The seccomp_bpf test uses BPF_LD|BPF_W|BPF_ABS to load 32-bit values
from seccomp_data->args. On big endian machines this will load the high
word of the argument, which is not what the test wants.
Borrow a hack from samples/seccomp/bpf-helper.h which changes the offset
on big endian to account for this.
Signed-off-by: Michael Ellerman <mpe@ellerman.id.au>
---
tools/testing/selftests/seccomp/seccomp_bpf.c | 6 ++++++
1 file changed, 6 insertions(+)
diff --git a/tools/testing/selftests/seccomp/seccomp_bpf.c b/tools/testing/selftests/seccomp/seccomp_bpf.c
index b2374c131340..51adb9afb511 100644
--- a/tools/testing/selftests/seccomp/seccomp_bpf.c
+++ b/tools/testing/selftests/seccomp/seccomp_bpf.c
@@ -82,7 +82,13 @@ struct seccomp_data {
};
#endif
+#if __BYTE_ORDER == __LITTLE_ENDIAN
#define syscall_arg(_n) (offsetof(struct seccomp_data, args[_n]))
+#elif __BYTE_ORDER == __BIG_ENDIAN
+#define syscall_arg(_n) (offsetof(struct seccomp_data, args[_n]) + sizeof(__u32))
+#else
+#error "wut?"
+#endif
#define SIBLING_EXIT_UNKILLED 0xbadbeef
#define SIBLING_EXIT_FAILURE 0xbadface
--
2.1.0
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/
[toc] | [prev] | [next] | [standalone]
| From | Kees Cook <keescook@chromium.org> |
|---|---|
| Date | 2015-07-15 17:20 +0200 |
| Subject | Re: [RFC PATCH 11/12] selftests/seccomp: Make seccomp tests work on big endian |
| Message-ID | <pMwDv-3bC-11@gated-at.bofh.it> |
| In reply to | #1184388 |
On Wed, Jul 15, 2015 at 12:37 AM, Michael Ellerman <mpe@ellerman.id.au> wrote:
> The seccomp_bpf test uses BPF_LD|BPF_W|BPF_ABS to load 32-bit values
> from seccomp_data->args. On big endian machines this will load the high
> word of the argument, which is not what the test wants.
>
> Borrow a hack from samples/seccomp/bpf-helper.h which changes the offset
> on big endian to account for this.
>
> Signed-off-by: Michael Ellerman <mpe@ellerman.id.au>
> ---
> tools/testing/selftests/seccomp/seccomp_bpf.c | 6 ++++++
> 1 file changed, 6 insertions(+)
>
> diff --git a/tools/testing/selftests/seccomp/seccomp_bpf.c b/tools/testing/selftests/seccomp/seccomp_bpf.c
> index b2374c131340..51adb9afb511 100644
> --- a/tools/testing/selftests/seccomp/seccomp_bpf.c
> +++ b/tools/testing/selftests/seccomp/seccomp_bpf.c
> @@ -82,7 +82,13 @@ struct seccomp_data {
> };
> #endif
>
> +#if __BYTE_ORDER == __LITTLE_ENDIAN
> #define syscall_arg(_n) (offsetof(struct seccomp_data, args[_n]))
> +#elif __BYTE_ORDER == __BIG_ENDIAN
> +#define syscall_arg(_n) (offsetof(struct seccomp_data, args[_n]) + sizeof(__u32))
> +#else
> +#error "wut?"
> +#endif
Ah-ha! Yes, thanks. Could you change the #error to something that
describes the particular (impossible) failure condition? "wut? Unknown
__BYTE_ORDER?!". Not a huge deal, but I always like verbose errors. :)
Especially for "impossible" situations. :)
-Kees
>
> #define SIBLING_EXIT_UNKILLED 0xbadbeef
> #define SIBLING_EXIT_FAILURE 0xbadface
> --
> 2.1.0
>
--
Kees Cook
Chrome OS Security
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/
[toc] | [prev] | [next] | [standalone]
| From | Michael Ellerman <mpe@ellerman.id.au> |
|---|---|
| Date | 2015-07-16 05:50 +0200 |
| Subject | Re: [RFC PATCH 11/12] selftests/seccomp: Make seccomp tests work on big endian |
| Message-ID | <pMIlk-3ca-5@gated-at.bofh.it> |
| In reply to | #1184859 |
On Wed, 2015-07-15 at 08:16 -0700, Kees Cook wrote:
> On Wed, Jul 15, 2015 at 12:37 AM, Michael Ellerman <mpe@ellerman.id.au> wrote:
> > diff --git a/tools/testing/selftests/seccomp/seccomp_bpf.c b/tools/testing/selftests/seccomp/seccomp_bpf.c
> > index b2374c131340..51adb9afb511 100644
> > --- a/tools/testing/selftests/seccomp/seccomp_bpf.c
> > +++ b/tools/testing/selftests/seccomp/seccomp_bpf.c
> > @@ -82,7 +82,13 @@ struct seccomp_data {
> > };
> > #endif
> >
> > +#if __BYTE_ORDER == __LITTLE_ENDIAN
> > #define syscall_arg(_n) (offsetof(struct seccomp_data, args[_n]))
> > +#elif __BYTE_ORDER == __BIG_ENDIAN
> > +#define syscall_arg(_n) (offsetof(struct seccomp_data, args[_n]) + sizeof(__u32))
> > +#else
> > +#error "wut?"
> > +#endif
>
> Ah-ha! Yes, thanks. Could you change the #error to something that
> describes the particular (impossible) failure condition? "wut? Unknown
> __BYTE_ORDER?!". Not a huge deal, but I always like verbose errors. :)
> Especially for "impossible" situations. :)
Yeah sorry that was a "quick hack" which got promoted into an actual patch.
Fixed to use your message.
cheers
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/
[toc] | [prev] | [next] | [standalone]
| From | Michael Ellerman <mpe@ellerman.id.au> |
|---|---|
| Date | 2015-07-15 09:40 +0200 |
| Subject | [RFC PATCH 04/12] powerpc: Drop unused syscall_get_error() |
| Message-ID | <pMpsm-LG-41@gated-at.bofh.it> |
| In reply to | #1184386 |
syscall_get_error() is unused, and never has been.
It's also probably wrong, as it negates r3 before returning it, but that
depends on what the caller is expecting.
It also doesn't deal with compat, and doesn't deal with TIF_NOERROR.
Although we could fix those, until it has a caller and it's clear what
semantics the caller wants it's just untested code. So drop it.
Signed-off-by: Michael Ellerman <mpe@ellerman.id.au>
---
arch/powerpc/include/asm/syscall.h | 6 ------
1 file changed, 6 deletions(-)
diff --git a/arch/powerpc/include/asm/syscall.h b/arch/powerpc/include/asm/syscall.h
index ff21b7a2f0cc..c6239dabcfb1 100644
--- a/arch/powerpc/include/asm/syscall.h
+++ b/arch/powerpc/include/asm/syscall.h
@@ -34,12 +34,6 @@ 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)
-{
- return (regs->ccr & 0x10000000) ? -regs->gpr[3] : 0;
-}
-
static inline long syscall_get_return_value(struct task_struct *task,
struct pt_regs *regs)
{
--
2.1.0
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/
[toc] | [prev] | [next] | [standalone]
| From | Michael Ellerman <mpe@ellerman.id.au> |
|---|---|
| Date | 2015-07-15 09:40 +0200 |
| Subject | [RFC PATCH 07/12] powerpc: Use orig_gpr3 in syscall_get_arguments() |
| Message-ID | <pMpsn-LG-51@gated-at.bofh.it> |
| In reply to | #1184386 |
Currently syscall_get_arguments() is used by syscall tracepoints, and
collect_syscall() which is used in some debugging as well as
/proc/pid/syscall.
The current implementation just copies regs->gpr[3 .. 5] out, which is
fine for all the current use cases.
When we enable seccomp filter, that will also start using
syscall_get_arguments(). However for seccomp filter we want to use r3
as the return value of the syscall, and orig_gpr3 as the first
parameter. This will allow seccomp to modify the return value in r3.
To support this we need to modify syscall_get_arguments() to return
orig_gpr3 instead of r3. This is safe for all uses because orig_gpr3
always contains the r3 value that was passed to the syscall. We store it
in the syscall entry path and never modify it.
Update syscall_set_arguments() while we're here, even though it's never
used.
Signed-off-by: Michael Ellerman <mpe@ellerman.id.au>
---
arch/powerpc/include/asm/syscall.h | 16 +++++++++++++---
1 file changed, 13 insertions(+), 3 deletions(-)
diff --git a/arch/powerpc/include/asm/syscall.h b/arch/powerpc/include/asm/syscall.h
index 403e2303fe18..8d79a87c0511 100644
--- a/arch/powerpc/include/asm/syscall.h
+++ b/arch/powerpc/include/asm/syscall.h
@@ -64,7 +64,7 @@ static inline void syscall_get_arguments(struct task_struct *task,
unsigned int i, unsigned int n,
unsigned long *args)
{
- unsigned long mask = -1UL;
+ unsigned long val, mask = -1UL;
BUG_ON(i + n > 6);
@@ -72,8 +72,14 @@ static inline void syscall_get_arguments(struct task_struct *task,
if (test_tsk_thread_flag(task, TIF_32BIT))
mask = 0xffffffff;
#endif
- while (n--)
- args[n] = regs->gpr[3 + i + n] & mask;
+ while (n--) {
+ if (n == 0 && i == 0)
+ val = regs->orig_gpr3;
+ else
+ val = regs->gpr[3 + i + n];
+
+ args[n] = val & mask;
+ }
}
static inline void syscall_set_arguments(struct task_struct *task,
@@ -83,6 +89,10 @@ static inline void syscall_set_arguments(struct task_struct *task,
{
BUG_ON(i + n > 6);
memcpy(®s->gpr[3 + i], args, n * sizeof(args[0]));
+
+ /* Also copy the first argument into orig_gpr3 */
+ if (i == 0 && n > 0)
+ regs->orig_gpr3 = args[0];
}
static inline int syscall_get_arch(void)
--
2.1.0
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/
[toc] | [prev] | [next] | [standalone]
| From | Michael Ellerman <mpe@ellerman.id.au> |
|---|---|
| Date | 2015-07-15 09:50 +0200 |
| Subject | [RFC PATCH 02/12] powerpc/kernel: Switch to using MAX_ERRNO |
| Message-ID | <pMpC2-X9-23@gated-at.bofh.it> |
| In reply to | #1184386 |
Currently on powerpc we have our own #define for the highest (negative) errno value, called _LAST_ERRNO. This is defined to be 516, for reasons which are not clear. The generic code, and x86, use MAX_ERRNO, which is defined to be 4095. In particular seccomp uses MAX_ERRNO to restrict the value that a seccomp filter can return. Currently with the mismatch between _LAST_ERRNO and MAX_ERRNO, a seccomp tracer wanting to return 600, expecting it to be seen as an error, would instead find on powerpc that userspace sees a successful syscall with a return value of 600. To avoid this inconsistency, switch powerpc to use MAX_ERRNO. We are somewhat confident that generic syscalls that can return a non-error value above negative MAX_ERRNO have already been updated to use force_successful_syscall_return(). I have also checked all the powerpc specific syscalls, and believe that none of them expect to return a non-error value between -MAX_ERRNO and -516. So this change should be safe ... Signed-off-by: Michael Ellerman <mpe@ellerman.id.au> --- arch/powerpc/include/uapi/asm/errno.h | 2 -- arch/powerpc/kernel/entry_32.S | 3 ++- arch/powerpc/kernel/entry_64.S | 5 +++-- 3 files changed, 5 insertions(+), 5 deletions(-) diff --git a/arch/powerpc/include/uapi/asm/errno.h b/arch/powerpc/include/uapi/asm/errno.h index 8c145fd17d86..e8b6b5f7de7c 100644 --- a/arch/powerpc/include/uapi/asm/errno.h +++ b/arch/powerpc/include/uapi/asm/errno.h @@ -6,6 +6,4 @@ #undef EDEADLOCK #define EDEADLOCK 58 /* File locking deadlock error */ -#define _LAST_ERRNO 516 - #endif /* _ASM_POWERPC_ERRNO_H */ diff --git a/arch/powerpc/kernel/entry_32.S b/arch/powerpc/kernel/entry_32.S index 46fc0f4d8982..67ecdf61f4e3 100644 --- a/arch/powerpc/kernel/entry_32.S +++ b/arch/powerpc/kernel/entry_32.S @@ -20,6 +20,7 @@ */ #include <linux/errno.h> +#include <linux/err.h> #include <linux/sys.h> #include <linux/threads.h> #include <asm/reg.h> @@ -354,7 +355,7 @@ ret_from_syscall: SYNC MTMSRD(r10) lwz r9,TI_FLAGS(r12) - li r8,-_LAST_ERRNO + li r8,-MAX_ERRNO andi. r0,r9,(_TIF_SYSCALL_DOTRACE|_TIF_SINGLESTEP|_TIF_USER_WORK_MASK|_TIF_PERSYSCALL_MASK) bne- syscall_exit_work cmplw 0,r3,r8 diff --git a/arch/powerpc/kernel/entry_64.S b/arch/powerpc/kernel/entry_64.S index 0796c487d3db..8292581a42f1 100644 --- a/arch/powerpc/kernel/entry_64.S +++ b/arch/powerpc/kernel/entry_64.S @@ -19,6 +19,7 @@ */ #include <linux/errno.h> +#include <linux/err.h> #include <asm/unistd.h> #include <asm/processor.h> #include <asm/page.h> @@ -207,7 +208,7 @@ system_call: /* label this so stack traces look sane */ #endif /* CONFIG_PPC_BOOK3E */ ld r9,TI_FLAGS(r12) - li r11,-_LAST_ERRNO + li r11,-MAX_ERRNO andi. r0,r9,(_TIF_SYSCALL_DOTRACE|_TIF_SINGLESTEP|_TIF_USER_WORK_MASK|_TIF_PERSYSCALL_MASK) bne- syscall_exit_work cmpld r3,r11 @@ -279,7 +280,7 @@ syscall_exit_work: beq+ 0f REST_NVGPRS(r1) b 2f -0: cmpld r3,r11 /* r10 is -LAST_ERRNO */ +0: cmpld r3,r11 /* r11 is -MAX_ERRNO */ blt+ 1f andi. r0,r9,_TIF_NOERROR bne- 1f -- 2.1.0 -- To unsubscribe from this list: send the line "unsubscribe linux-kernel" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html Please read the FAQ at http://www.tux.org/lkml/
[toc] | [prev] | [next] | [standalone]
| From | Benjamin Herrenschmidt <benh@kernel.crashing.org> |
|---|---|
| Date | 2015-07-17 00:50 +0200 |
| Subject | Re: [RFC PATCH 02/12] powerpc/kernel: Switch to using MAX_ERRNO |
| Message-ID | <pN08x-3AR-5@gated-at.bofh.it> |
| In reply to | #1184398 |
On Wed, 2015-07-15 at 17:37 +1000, Michael Ellerman wrote: > Currently on powerpc we have our own #define for the highest (negative) > errno value, called _LAST_ERRNO. This is defined to be 516, for reasons > which are not clear. > > The generic code, and x86, use MAX_ERRNO, which is defined to be 4095. > > In particular seccomp uses MAX_ERRNO to restrict the value that a > seccomp filter can return. > > Currently with the mismatch between _LAST_ERRNO and MAX_ERRNO, a seccomp > tracer wanting to return 600, expecting it to be seen as an error, would > instead find on powerpc that userspace sees a successful syscall with a > return value of 600. > > To avoid this inconsistency, switch powerpc to use MAX_ERRNO. > > We are somewhat confident that generic syscalls that can return a > non-error value above negative MAX_ERRNO have already been updated to > use force_successful_syscall_return(). > > I have also checked all the powerpc specific syscalls, and believe that > none of them expect to return a non-error value between -MAX_ERRNO and > -516. So this change should be safe ... > > Signed-off-by: Michael Ellerman <mpe@ellerman.id.au> Acked-by: Benjamin Herrenschmidt <benh@kernel.crashing.org> > --- > arch/powerpc/include/uapi/asm/errno.h | 2 -- > arch/powerpc/kernel/entry_32.S | 3 ++- > arch/powerpc/kernel/entry_64.S | 5 +++-- > 3 files changed, 5 insertions(+), 5 deletions(-) > > diff --git a/arch/powerpc/include/uapi/asm/errno.h b/arch/powerpc/include/uapi/asm/errno.h > index 8c145fd17d86..e8b6b5f7de7c 100644 > --- a/arch/powerpc/include/uapi/asm/errno.h > +++ b/arch/powerpc/include/uapi/asm/errno.h > @@ -6,6 +6,4 @@ > #undef EDEADLOCK > #define EDEADLOCK 58 /* File locking deadlock error */ > > -#define _LAST_ERRNO 516 > - > #endif /* _ASM_POWERPC_ERRNO_H */ > diff --git a/arch/powerpc/kernel/entry_32.S b/arch/powerpc/kernel/entry_32.S > index 46fc0f4d8982..67ecdf61f4e3 100644 > --- a/arch/powerpc/kernel/entry_32.S > +++ b/arch/powerpc/kernel/entry_32.S > @@ -20,6 +20,7 @@ > */ > > #include <linux/errno.h> > +#include <linux/err.h> > #include <linux/sys.h> > #include <linux/threads.h> > #include <asm/reg.h> > @@ -354,7 +355,7 @@ ret_from_syscall: > SYNC > MTMSRD(r10) > lwz r9,TI_FLAGS(r12) > - li r8,-_LAST_ERRNO > + li r8,-MAX_ERRNO > andi. r0,r9,(_TIF_SYSCALL_DOTRACE|_TIF_SINGLESTEP|_TIF_USER_WORK_MASK|_TIF_PERSYSCALL_MASK) > bne- syscall_exit_work > cmplw 0,r3,r8 > diff --git a/arch/powerpc/kernel/entry_64.S b/arch/powerpc/kernel/entry_64.S > index 0796c487d3db..8292581a42f1 100644 > --- a/arch/powerpc/kernel/entry_64.S > +++ b/arch/powerpc/kernel/entry_64.S > @@ -19,6 +19,7 @@ > */ > > #include <linux/errno.h> > +#include <linux/err.h> > #include <asm/unistd.h> > #include <asm/processor.h> > #include <asm/page.h> > @@ -207,7 +208,7 @@ system_call: /* label this so stack traces look sane */ > #endif /* CONFIG_PPC_BOOK3E */ > > ld r9,TI_FLAGS(r12) > - li r11,-_LAST_ERRNO > + li r11,-MAX_ERRNO > andi. r0,r9,(_TIF_SYSCALL_DOTRACE|_TIF_SINGLESTEP|_TIF_USER_WORK_MASK|_TIF_PERSYSCALL_MASK) > bne- syscall_exit_work > cmpld r3,r11 > @@ -279,7 +280,7 @@ syscall_exit_work: > beq+ 0f > REST_NVGPRS(r1) > b 2f > -0: cmpld r3,r11 /* r10 is -LAST_ERRNO */ > +0: cmpld r3,r11 /* r11 is -MAX_ERRNO */ > blt+ 1f > andi. r0,r9,_TIF_NOERROR > bne- 1f -- To unsubscribe from this list: send the line "unsubscribe linux-kernel" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html Please read the FAQ at http://www.tux.org/lkml/
[toc] | [prev] | [next] | [standalone]
| From | Benjamin Herrenschmidt <benh@kernel.crashing.org> |
|---|---|
| Date | 2015-07-17 00:50 +0200 |
| Subject | Re: [RFC PATCH 01/12] powerpc/kernel: Get pt_regs from r9 before calling do_syscall_trace_enter() |
| Message-ID | <pN08y-3AR-15@gated-at.bofh.it> |
| In reply to | #1184386 |
On Wed, 2015-07-15 at 17:37 +1000, Michael Ellerman wrote: > To call do_syscall_trace_enter() we need pt_regs in r3, but we don't need > to recalculate it based on r1, it's already in r9. > > Signed-off-by: Michael Ellerman <mpe@ellerman.id.au> Is there any performance difference ? I find the addi a bit more robust in case the code gets moved around or the "previous" code gets changed to either not use r9 or clobber it, which would have the potential to introduce a subtle bug ... Ben. > --- > arch/powerpc/kernel/entry_64.S | 4 +++- > 1 file changed, 3 insertions(+), 1 deletion(-) > > diff --git a/arch/powerpc/kernel/entry_64.S b/arch/powerpc/kernel/entry_64.S > index 579e0f9a2d57..0796c487d3db 100644 > --- a/arch/powerpc/kernel/entry_64.S > +++ b/arch/powerpc/kernel/entry_64.S > @@ -243,7 +243,9 @@ syscall_error: > /* Traced system call support */ > syscall_dotrace: > bl save_nvgprs > - addi r3,r1,STACK_FRAME_OVERHEAD > + > + /* Get pt_regs into r3 */ > + mr r3, r9 > bl do_syscall_trace_enter > /* > * Restore argument registers possibly just changed. -- To unsubscribe from this list: send the line "unsubscribe linux-kernel" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html Please read the FAQ at http://www.tux.org/lkml/
[toc] | [prev] | [next] | [standalone]
| From | Michael Ellerman <mpe@ellerman.id.au> |
|---|---|
| Date | 2015-07-17 06:50 +0200 |
| Subject | Re: [RFC PATCH 01/12] powerpc/kernel: Get pt_regs from r9 before calling do_syscall_trace_enter() |
| Message-ID | <pN5KW-3o6-3@gated-at.bofh.it> |
| In reply to | #1186306 |
On Fri, 2015-07-17 at 08:40 +1000, Benjamin Herrenschmidt wrote: > On Wed, 2015-07-15 at 17:37 +1000, Michael Ellerman wrote: > > To call do_syscall_trace_enter() we need pt_regs in r3, but we don't need > > to recalculate it based on r1, it's already in r9. > > > > Signed-off-by: Michael Ellerman <mpe@ellerman.id.au> > > Is there any performance difference ? No. I'm not going to bother measuring it :) > I find the addi a bit more robust in case the code gets moved around or > the "previous" code gets changed to either not use r9 or clobber it, > which would have the potential to > introduce a subtle bug ... Yeah true. There is an "invariant" in that entry code that r9 contains pt_regs, you can see for example the DTL code goes to pains to ensure it puts pt_regs back in r9 after it clobbers it. As does the current syscall_dotrace. But looking closer I don't see where we actually use that (prior to this patch). So yeah I'll drop this and send a clean up to just get rid of all the r9 reloading. cheers -- To unsubscribe from this list: send the line "unsubscribe linux-kernel" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html Please read the FAQ at http://www.tux.org/lkml/
[toc] | [prev] | [standalone]
Back to top | Article view | linux.kernel
csiph-web