From: Kees Cook <keescook@chromium.org>
To: linux-kernel@vger.kernel.org
Cc: "Russell King" <linux@arm.linux.org.uk>,
"Andy Lutomirski" <luto@amacapital.net>,
"Will Deacon" <will.deacon@arm.com>,
"Andrew Morton" <akpm@linux-foundation.org>,
"Jonathan Austin" <jonathan.austin@arm.com>,
"André Hentschel" <nerv@dawncrow.de>,
"Oleg Nesterov" <oleg@redhat.com>,
linux-arm-kernel@lists.infradead.org,
"Ricky Zhou" <rickyz@google.com>
Subject: [PATCH] arm: ptrace: fix syscall modification under PTRACE_O_TRACESECCOMP
Date: Wed, 18 Jun 2014 13:27:48 -0700 [thread overview]
Message-ID: <20140618202748.GA9022@www.outflux.net> (raw)
An x86 tracer wanting to change the syscall uses PTRACE_SETREGS
(stored to regs->orig_ax), and an ARM tracer uses PTRACE_SET_SYSCALL
(stored to current_thread_info()->syscall). When this happens, the
syscall can change across the call to secure_computing(), since it may
block on tracer notification, and the tracer can then make changes
to the process, before we return from secure_computing(). This
means the code must respect the changed syscall after the
secure_computing() call in syscall_trace_enter(). The same is true
for tracehook_report_syscall_entry() which may also block and change
the syscall.
The x86 code handles this (it expects orig_ax to always be the
desired syscall). In the ARM case, this means we should not be touching
current_thread_info()->syscall after its initial assignment. All failures
should result in a -1 syscall, though.
Based on patch by Ricky Zhou.
Signed-off-by: Kees Cook <keescook@chromium.org>
Cc: Ricky Zhou <rickyz@google.com>
Cc: stable@vger.kernel.org
---
arch/arm/kernel/ptrace.c | 20 +++++++++++++-------
1 file changed, 13 insertions(+), 7 deletions(-)
diff --git a/arch/arm/kernel/ptrace.c b/arch/arm/kernel/ptrace.c
index 0dd3b79b15c3..97bd95f6aa01 100644
--- a/arch/arm/kernel/ptrace.c
+++ b/arch/arm/kernel/ptrace.c
@@ -911,6 +911,7 @@ enum ptrace_syscall_dir {
static int tracehook_report_syscall(struct pt_regs *regs,
enum ptrace_syscall_dir dir)
{
+ int ret = 0;
unsigned long ip;
/*
@@ -923,30 +924,35 @@ static int tracehook_report_syscall(struct pt_regs *regs,
if (dir == PTRACE_SYSCALL_EXIT)
tracehook_report_syscall_exit(regs, 0);
else if (tracehook_report_syscall_entry(regs))
- current_thread_info()->syscall = -1;
+ ret = -1;
regs->ARM_ip = ip;
- return current_thread_info()->syscall;
+ return ret;
}
asmlinkage int syscall_trace_enter(struct pt_regs *regs, int scno)
{
+ int ret = 0;
+
+ /* set up syscall, which may be changed in secure_computing */
current_thread_info()->syscall = scno;
/* Do the secure computing check first; failures should be fast. */
if (secure_computing(scno) == -1)
return -1;
- if (test_thread_flag(TIF_SYSCALL_TRACE))
- scno = tracehook_report_syscall(regs, PTRACE_SYSCALL_ENTER);
+ if (test_thread_flag(TIF_SYSCALL_TRACE) &&
+ tracehook_report_syscall(regs, PTRACE_SYSCALL_ENTER))
+ ret = -1;
if (test_thread_flag(TIF_SYSCALL_TRACEPOINT))
- trace_sys_enter(regs, scno);
+ trace_sys_enter(regs, current_thread_info()->syscall);
- audit_syscall_entry(AUDIT_ARCH_ARM, scno, regs->ARM_r0, regs->ARM_r1,
+ audit_syscall_entry(AUDIT_ARCH_ARM, current_thread_info()->syscall,
+ regs->ARM_r0, regs->ARM_r1,
regs->ARM_r2, regs->ARM_r3);
- return scno;
+ return ret ?: current_thread_info()->syscall;
}
asmlinkage void syscall_trace_exit(struct pt_regs *regs)
--
1.7.9.5
--
Kees Cook
Chrome OS Security
next reply other threads:[~2014-06-18 20:30 UTC|newest]
Thread overview: 18+ messages / expand[flat|nested] mbox.gz Atom feed top
2014-06-18 20:27 Kees Cook [this message]
2014-06-18 20:51 ` Andy Lutomirski
2014-06-20 10:22 ` Will Deacon
2014-06-20 16:44 ` Kees Cook
2014-06-20 17:23 ` Will Deacon
2014-06-20 17:36 ` Kees Cook
2014-06-20 18:10 ` Kees Cook
2014-06-23 8:46 ` Will Deacon
2014-06-23 19:46 ` Kees Cook
2014-06-24 8:54 ` Will Deacon
2014-06-24 9:20 ` AKASHI Takahiro
2014-07-03 7:43 ` AKASHI Takahiro
2014-07-03 10:24 ` Will Deacon
2014-07-03 15:39 ` Andy Lutomirski
2014-07-03 16:11 ` Will Deacon
2014-07-03 16:13 ` Andy Lutomirski
2014-07-03 16:32 ` Will Deacon
2014-07-04 23:05 ` Andy Lutomirski
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20140618202748.GA9022@www.outflux.net \
--to=keescook@chromium.org \
--cc=akpm@linux-foundation.org \
--cc=jonathan.austin@arm.com \
--cc=linux-arm-kernel@lists.infradead.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux@arm.linux.org.uk \
--cc=luto@amacapital.net \
--cc=nerv@dawncrow.de \
--cc=oleg@redhat.com \
--cc=rickyz@google.com \
--cc=will.deacon@arm.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®