From patchwork Sat Mar 15 05:39:06 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: AKASHI Takahiro X-Patchwork-Id: 26317 Return-Path: X-Original-To: linaro@patches.linaro.org Delivered-To: linaro@patches.linaro.org Received: from mail-pd0-f197.google.com (mail-pd0-f197.google.com [209.85.192.197]) by ip-10-151-82-157.ec2.internal (Postfix) with ESMTPS id 92F4E202DD for ; Sat, 15 Mar 2014 05:42:30 +0000 (UTC) Received: by mail-pd0-f197.google.com with SMTP id fp1sf7806205pdb.8 for ; Fri, 14 Mar 2014 22:42:29 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:delivered-to:from:to:subject:date:message-id :in-reply-to:references:cc:precedence:list-id:list-unsubscribe :list-archive:list-post:list-help:list-subscribe:mime-version:sender :errors-to:x-original-sender:x-original-authentication-results :mailing-list:content-type:content-transfer-encoding; bh=KDO1rgJ32mOPdgiw1mq0Kocaw1LoTRzUYNlXZYblikI=; b=K8hF1EPNswvKPbf4Zyd7GCFQs+9Ypnij9o/offGaN71m71T5gWJQoxf1vZS6nRSL1N G9JBPwI5HNxdhH8Gh8FzLKbp2jkMXhT2nFTsgAZV/KMt5nIbbIbsF7qaSG1plans0nHM GdQ/XmcC3y57ZJ8ut4XNmSVLxnZgCSRrN1HP8tzXrCJG6M7jU44B0ZENX+OqKLPLmN3d lneQAmFw42zZd9hFmdXzBX5el6kJStL/rWIe0P8IjSGpzWIaOwF6UO3cSb1fxtwbedD+ Bjql7ki1laOeDvAJIMXKNyjK+8E0oq5mEN059gRaoiJInw5RQRiiql0fmRkdS64L7ZTz ZoTA== X-Gm-Message-State: ALoCoQmKox+IhuWtS3QueoDH0kSefFXO3G/Y59DrKdXXKmWUrea1aDytpGv+/7Dd7k0uWKO4az1Q X-Received: by 10.66.141.231 with SMTP id rr7mr4628393pab.47.1394862149845; Fri, 14 Mar 2014 22:42:29 -0700 (PDT) X-BeenThere: patchwork-forward@linaro.org Received: by 10.140.31.35 with SMTP id e32ls870645qge.4.gmail; Fri, 14 Mar 2014 22:42:29 -0700 (PDT) X-Received: by 10.58.37.232 with SMTP id b8mr104410vek.27.1394862149736; Fri, 14 Mar 2014 22:42:29 -0700 (PDT) Received: from mail-ve0-f179.google.com (mail-ve0-f179.google.com [209.85.128.179]) by mx.google.com with ESMTPS id u10si1161968vef.201.2014.03.14.22.42.29 for (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Fri, 14 Mar 2014 22:42:29 -0700 (PDT) Received-SPF: neutral (google.com: 209.85.128.179 is neither permitted nor denied by best guess record for domain of patch+caf_=patchwork-forward=linaro.org@linaro.org) client-ip=209.85.128.179; Received: by mail-ve0-f179.google.com with SMTP id db12so3649511veb.38 for ; Fri, 14 Mar 2014 22:42:29 -0700 (PDT) X-Received: by 10.220.95.139 with SMTP id d11mr676801vcn.21.1394862149589; Fri, 14 Mar 2014 22:42:29 -0700 (PDT) X-Forwarded-To: patchwork-forward@linaro.org X-Forwarded-For: patch@linaro.org patchwork-forward@linaro.org Delivered-To: patch@linaro.org Received: by 10.220.78.9 with SMTP id i9csp72886vck; Fri, 14 Mar 2014 22:42:29 -0700 (PDT) X-Received: by 10.194.21.193 with SMTP id x1mr9477179wje.33.1394862148264; Fri, 14 Mar 2014 22:42:28 -0700 (PDT) Received: from casper.infradead.org (casper.infradead.org. [2001:770:15f::2]) by mx.google.com with ESMTPS id q10si777856wic.7.2014.03.14.22.42.27 for (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 14 Mar 2014 22:42:28 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-arm-kernel-bounces+patch=linaro.org@lists.infradead.org designates 2001:770:15f::2 as permitted sender) client-ip=2001:770:15f::2; Received: from merlin.infradead.org ([2001:4978:20e::2]) by casper.infradead.org with esmtps (Exim 4.80.1 #2 (Red Hat Linux)) id 1WOhKu-0000z4-74; Sat, 15 Mar 2014 05:40:44 +0000 Received: from localhost ([::1] helo=merlin.infradead.org) by merlin.infradead.org with esmtp (Exim 4.80.1 #2 (Red Hat Linux)) id 1WOhKj-0007yb-DY; Sat, 15 Mar 2014 05:40:33 +0000 Received: from mail-pa0-f45.google.com ([209.85.220.45]) by merlin.infradead.org with esmtps (Exim 4.80.1 #2 (Red Hat Linux)) id 1WOhKT-0007vd-RW for linux-arm-kernel@lists.infradead.org; Sat, 15 Mar 2014 05:40:19 +0000 Received: by mail-pa0-f45.google.com with SMTP id kl14so3519701pab.4 for ; Fri, 14 Mar 2014 22:39:54 -0700 (PDT) X-Received: by 10.66.140.104 with SMTP id rf8mr13244694pab.107.1394861994376; Fri, 14 Mar 2014 22:39:54 -0700 (PDT) Received: from localhost.localdomain (pdddd29.tkyoac00.ap.so-net.ne.jp. [218.221.221.41]) by mx.google.com with ESMTPSA id iv2sm22280176pbc.19.2014.03.14.22.39.50 for (version=TLSv1.1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Fri, 14 Mar 2014 22:39:53 -0700 (PDT) From: AKASHI Takahiro To: will.deacon@arm.com Subject: [PATCH v5 2/4] arm64: split syscall_trace() into separate functions for enter/exit Date: Sat, 15 Mar 2014 14:39:06 +0900 Message-Id: <1394861948-28712-3-git-send-email-takahiro.akashi@linaro.org> X-Mailer: git-send-email 1.8.3.2 In-Reply-To: <1394861948-28712-1-git-send-email-takahiro.akashi@linaro.org> References: <1394705491-12343-1-git-send-email-takahiro.akashi@linaro.org> <1394861948-28712-1-git-send-email-takahiro.akashi@linaro.org> X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20140315_014018_028358_9C9F7A6D X-CRM114-Status: GOOD ( 12.18 ) X-Spam-Score: -2.6 (--) X-Spam-Report: SpamAssassin version 3.3.2 on merlin.infradead.org summary: Content analysis details: (-2.6 points) pts rule name description ---- ---------------------- -------------------------------------------------- -0.7 RCVD_IN_DNSWL_LOW RBL: Sender listed at http://www.dnswl.org/, low trust [209.85.220.45 listed in list.dnswl.org] -0.0 SPF_PASS SPF: sender matches SPF record -1.9 BAYES_00 BODY: Bayes spam probability is 0 to 1% [score: 0.0000] 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+patch=linaro.org@lists.infradead.org X-Removed-Original-Auth: Dkim didn't pass. X-Original-Sender: takahiro.akashi@linaro.org X-Original-Authentication-Results: mx.google.com; spf=neutral (google.com: 209.85.128.179 is neither permitted nor denied by best guess record for domain of patch+caf_=patchwork-forward=linaro.org@linaro.org) smtp.mail=patch+caf_=patchwork-forward=linaro.org@linaro.org Mailing-list: list patchwork-forward@linaro.org; contact patchwork-forward+owners@linaro.org X-Google-Group-Id: 836684582541 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 Acked-by: Richard Guy Briggs --- arch/arm64/kernel/entry.S | 10 ++++------ arch/arm64/kernel/ptrace.c | 50 +++++++++++++++++++++++++++------------------- 2 files changed, 33 insertions(+), 27 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..f606276 100644 --- a/arch/arm64/kernel/ptrace.c +++ b/arch/arm64/kernel/ptrace.c @@ -1058,35 +1058,43 @@ 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) +enum ptrace_syscall_dir { + PTRACE_SYSCALL_ENTER = 0, + PTRACE_SYSCALL_EXIT, +}; + +static void tracehook_report_syscall(struct pt_regs *regs, + enum ptrace_syscall_dir dir) { + int scrach; unsigned long saved_reg; - if (!test_thread_flag(TIF_SYSCALL_TRACE)) - return regs->syscallno; - - if (is_compat_task()) { - /* AArch32 uses ip (r12) for scratch */ - saved_reg = regs->regs[12]; - regs->regs[12] = dir; - } 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; - } + /* + * A scrach register (ip(r12) on AArch32, x7 on AArch64) is + * used to denote syscall entry/exit: + */ + scrach = (is_compat_task() ? 12 : 7); + saved_reg = regs->regs[scrach]; + regs->regs[scrach] = dir; - if (dir) + if (dir == PTRACE_SYSCALL_EXIT) tracehook_report_syscall_exit(regs, 0); else if (tracehook_report_syscall_entry(regs)) regs->syscallno = ~0UL; - if (is_compat_task()) - regs->regs[12] = saved_reg; - else - regs->regs[7] = saved_reg; + regs->regs[scrach] = saved_reg; +} + +asmlinkage int syscall_trace_enter(struct pt_regs *regs) +{ + if (test_thread_flag(TIF_SYSCALL_TRACE)) + tracehook_report_syscall(regs, PTRACE_SYSCALL_ENTER); return regs->syscallno; } + +asmlinkage void syscall_trace_exit(struct pt_regs *regs) +{ + if (test_thread_flag(TIF_SYSCALL_TRACE)) + tracehook_report_syscall(regs, PTRACE_SYSCALL_EXIT); +}