From patchwork Wed Apr 30 09:51: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: 4092261 Return-Path: X-Original-To: patchwork-linux-arm@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork1.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.19.201]) by patchwork1.web.kernel.org (Postfix) with ESMTP id 6A4E79F39D for ; Wed, 30 Apr 2014 09:56:06 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 8449320220 for ; Wed, 30 Apr 2014 09:56:05 +0000 (UTC) Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.9]) (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 85E15201DE for ; Wed, 30 Apr 2014 09:56:04 +0000 (UTC) Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.80.1 #2 (Red Hat Linux)) id 1WfRCe-0003WH-SO; Wed, 30 Apr 2014 09:53:24 +0000 Received: from mail-ig0-f172.google.com ([209.85.213.172]) by bombadil.infradead.org with esmtps (Exim 4.80.1 #2 (Red Hat Linux)) id 1WfRCb-0003SL-Uc for linux-arm-kernel@lists.infradead.org; Wed, 30 Apr 2014 09:53:22 +0000 Received: by mail-ig0-f172.google.com with SMTP id hn18so7324004igb.11 for ; Wed, 30 Apr 2014 02:53: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=9IoiC8Fwy5DC8Z9d1ZvGSu4Uz0Gs+AvVXAuQ3FsXI74=; b=ATIDG+BmpzofGnCICkTOaXI5AwNyqC04Q0VSVhckg+r/2wC6fn3jloRUbp1cMcQ6mM qTrVryr575WMpNylKeJqgu/aOk0/c+vFqA7mI1GDs3pQpugCCslKoYB3qd6zsfPTVtu+ vDAB8mKA+lJHZV1qFpAVD7SGlMdZqPYdmY1Unem0Bm1FMkXi2HDKL+cNKlEfJCkxP9O1 6LrBEQU+sanaC1OqqqqY7BSet88qNH+yGNVFwUfSkGIPYgpH7ottnK1Kx1nFlEu26HQD UqU7EiTtjXV8ROjgzftLb0UbjS9BFBUUkUqxas9eiG/vhnBx83pNE/28owL+93YWlmVQ mV5A== X-Gm-Message-State: ALoCoQnswUjSu8oa7quY5DnHUNm5o5SmjJznUk2XW8GiQ5ZsFK0h+WSdYPQQGmK6rGiOqG1n4Rp4 X-Received: by 10.50.40.103 with SMTP id w7mr3130225igk.33.1398851580729; Wed, 30 Apr 2014 02:53:00 -0700 (PDT) Received: from localhost.localdomain (KD182249095136.au-net.ne.jp. [182.249.95.136]) by mx.google.com with ESMTPSA id s8sm4428691ige.4.2014.04.30.02.52.54 for (version=TLSv1.1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Wed, 30 Apr 2014 02:52:59 -0700 (PDT) From: AKASHI Takahiro To: will.deacon@arm.com Subject: [PATCH v6 2/4] arm64: split syscall_trace() into separate functions for enter/exit Date: Wed, 30 Apr 2014 18:51:30 +0900 Message-Id: <1398851492-16345-3-git-send-email-takahiro.akashi@linaro.org> X-Mailer: git-send-email 1.8.3.2 In-Reply-To: <1398851492-16345-1-git-send-email-takahiro.akashi@linaro.org> References: <1394861948-28712-1-git-send-email-takahiro.akashi@linaro.org> <1398851492-16345-1-git-send-email-takahiro.akashi@linaro.org> X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20140430_025322_023789_50555DDE X-CRM114-Status: GOOD ( 13.57 ) X-Spam-Score: -0.7 (/) 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=-2.5 required=5.0 tests=BAYES_00,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. Acked-by: Will Deacon Signed-off-by: AKASHI Takahiro --- 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..6d666dc 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 regno; 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 scratch register (ip(r12) on AArch32, x7 on AArch64) is + * used to denote syscall entry/exit: + */ + regno = (is_compat_task() ? 12 : 7); + saved_reg = regs->regs[regno]; + regs->regs[regno] = 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[regno] = 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); +}