From patchwork Thu Mar 13 10:11:30 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: AKASHI Takahiro X-Patchwork-Id: 3824561 Return-Path: X-Original-To: patchwork-linux-arm@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork2.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.19.201]) by patchwork2.web.kernel.org (Postfix) with ESMTP id 2B5A2BF540 for ; Thu, 13 Mar 2014 10:15:13 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 1682E2020A for ; Thu, 13 Mar 2014 10:15:12 +0000 (UTC) Received: from casper.infradead.org (casper.infradead.org [85.118.1.10]) (using TLSv1.2 with cipher DHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 177AD201E4 for ; Thu, 13 Mar 2014 10:15:11 +0000 (UTC) Received: from merlin.infradead.org ([2001:4978:20e::2]) by casper.infradead.org with esmtps (Exim 4.80.1 #2 (Red Hat Linux)) id 1WO2eF-00017s-3F; Thu, 13 Mar 2014 10:13:59 +0000 Received: from localhost ([::1] helo=merlin.infradead.org) by merlin.infradead.org with esmtp (Exim 4.80.1 #2 (Red Hat Linux)) id 1WO2dv-0002di-Hk; Thu, 13 Mar 2014 10:13:39 +0000 Received: from mail-pa0-f43.google.com ([209.85.220.43]) by merlin.infradead.org with esmtps (Exim 4.80.1 #2 (Red Hat Linux)) id 1WO2df-0002YN-6r for linux-arm-kernel@lists.infradead.org; Thu, 13 Mar 2014 10:13:25 +0000 Received: by mail-pa0-f43.google.com with SMTP id bj1so898998pad.16 for ; Thu, 13 Mar 2014 03:13:00 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=yG3sH+mCMns/rQfbNszkZMzOlXHaW1gHKt+XNPuez4o=; b=IkrbBFvOtX2McDYxePUDFsBsCPGmy9mFGqSXf5GJWH+L4v9fAJRwufV5n4IIrSiPT9 Ba5K8ZP+wjdjRhP/m4GWL6ylIYRWSk+kiAgv2p3Ki4yNg3lwPgN+4dtNzDqjPB7SndcQ e1TzwiV+VloJZKRi5+GIxDBoubVk/xo9LsNe0aukC1S9Y8ZBr85jrEZvqox2kmZTnec4 yPTzjWdhxsGrU19zp6DK7GhDq/pBeLDkiteuGzGqXIrCrzbN78WOLVQdLu7Ez4h91z2m TCWwewS6BSuqeDH6pPMIjRxsAoGyw8Gp4001xYTNcCpLYxODIVONSB5NfU1ZPwX5ttX3 qSbw== X-Gm-Message-State: ALoCoQnf/OzgtbTOItgyH3TqTQEHlobyweGdoDDe/yvqqpN9CcID80yNiXdF/5Z4wDvNF8Fb9x3h X-Received: by 10.67.14.231 with SMTP id fj7mr1123901pad.115.1394705580544; Thu, 13 Mar 2014 03:13:00 -0700 (PDT) Received: from localhost.localdomain (KD182249091179.au-net.ne.jp. [182.249.91.179]) by mx.google.com with ESMTPSA id fn2sm7487532pab.38.2014.03.13.03.12.55 for (version=TLSv1.1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Thu, 13 Mar 2014 03:12:59 -0700 (PDT) From: AKASHI Takahiro To: will.deacon@arm.com Subject: [PATCH v4 2/3] arm64: split syscall_trace() into separate functions for enter/exit Date: Thu, 13 Mar 2014 19:11:30 +0900 Message-Id: <1394705491-12343-3-git-send-email-takahiro.akashi@linaro.org> X-Mailer: git-send-email 1.8.3.2 In-Reply-To: <1394705491-12343-1-git-send-email-takahiro.akashi@linaro.org> References: <1393564465-3862-1-git-send-email-takahiro.akashi@linaro.org> <1394705491-12343-1-git-send-email-takahiro.akashi@linaro.org> X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20140313_061323_383300_457CF157 X-CRM114-Status: GOOD ( 13.64 ) X-Spam-Score: -2.6 (--) Cc: linaro-kernel@lists.linaro.org, rgb@redhat.com, catalin.marinas@arm.com, arndb@arndb.de, eparis@redhat.com, linux-kernel@vger.kernel.org, AKASHI Takahiro , dsaxena@linaro.org, viro@zeniv.linux.org.uk, linux-audit@redhat.com, linux-arm-kernel@lists.infradead.org X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+patchwork-linux-arm=patchwork.kernel.org@lists.infradead.org X-Spam-Status: No, score=-4.2 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_MED, T_RP_MATCHES_RCVD, UNPARSEABLE_RELAY autolearn=unavailable version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP As done in arm, this change makes it easy to confirm we invoke syscall related hooks, including syscall tracepoint, audit and seccomp which would be implemented later, in correct order. That is, undoing operations in the opposite order on exit that they were done on entry. Signed-off-by: AKASHI Takahiro --- arch/arm64/kernel/entry.S | 10 ++++----- arch/arm64/kernel/ptrace.c | 48 ++++++++++++++++++++++++++++++++++---------- 2 files changed, 41 insertions(+), 17 deletions(-) diff --git a/arch/arm64/kernel/entry.S b/arch/arm64/kernel/entry.S index f9f2cae..00d6eb9 100644 --- a/arch/arm64/kernel/entry.S +++ b/arch/arm64/kernel/entry.S @@ -649,9 +649,8 @@ ENDPROC(el0_svc) * switches, and waiting for our parent to respond. */ __sys_trace: - mov x1, sp - mov w0, #0 // trace entry - bl syscall_trace + mov x0, sp + bl syscall_trace_enter adr lr, __sys_trace_return // return address uxtw scno, w0 // syscall number (possibly new) mov x1, sp // pointer to regs @@ -666,9 +665,8 @@ __sys_trace: __sys_trace_return: str x0, [sp] // save returned x0 - mov x1, sp - mov w0, #1 // trace exit - bl syscall_trace + mov x0, sp + bl syscall_trace_exit b ret_to_user /* diff --git a/arch/arm64/kernel/ptrace.c b/arch/arm64/kernel/ptrace.c index 6a8928b..9993a8f 100644 --- a/arch/arm64/kernel/ptrace.c +++ b/arch/arm64/kernel/ptrace.c @@ -1058,29 +1058,27 @@ long arch_ptrace(struct task_struct *child, long request, return ptrace_request(child, request, addr, data); } -asmlinkage int syscall_trace(int dir, struct pt_regs *regs) +asmlinkage int syscall_trace_enter(struct pt_regs *regs) { unsigned long saved_reg; if (!test_thread_flag(TIF_SYSCALL_TRACE)) return regs->syscallno; + /* + * A scrach register (ip(r12) on AArch32, x7 on AArch64) is + * used to denote syscall entry/exit: + * 0 -> entry + */ if (is_compat_task()) { - /* AArch32 uses ip (r12) for scratch */ saved_reg = regs->regs[12]; - regs->regs[12] = dir; + regs->regs[12] = 0; } else { - /* - * Save X7. X7 is used to denote syscall entry/exit: - * X7 = 0 -> entry, = 1 -> exit - */ saved_reg = regs->regs[7]; - regs->regs[7] = dir; + regs->regs[7] = 0; } - if (dir) - tracehook_report_syscall_exit(regs, 0); - else if (tracehook_report_syscall_entry(regs)) + if (tracehook_report_syscall_entry(regs)) regs->syscallno = ~0UL; if (is_compat_task()) @@ -1090,3 +1088,31 @@ asmlinkage int syscall_trace(int dir, struct pt_regs *regs) return regs->syscallno; } + +asmlinkage void syscall_trace_exit(struct pt_regs *regs) +{ + unsigned long saved_reg; + + if (!test_thread_flag(TIF_SYSCALL_TRACE)) + return; + + /* + * A scrach register (ip(r12) on AArch32, x7 on AArch64) is + * used to denote syscall entry/exit: + * 1 -> exit + */ + if (is_compat_task()) { + saved_reg = regs->regs[12]; + regs->regs[12] = 1; + } else { + saved_reg = regs->regs[7]; + regs->regs[7] = 1; + } + + tracehook_report_syscall_exit(regs, 0); + + if (is_compat_task()) + regs->regs[12] = saved_reg; + else + regs->regs[7] = saved_reg; +}