From patchwork Tue Jul 22 09:14:57 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: AKASHI Takahiro X-Patchwork-Id: 4600321 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 50D4BC0514 for ; Tue, 22 Jul 2014 09:18:56 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 7D91720125 for ; Tue, 22 Jul 2014 09:18:55 +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 A09B5200E7 for ; Tue, 22 Jul 2014 09:18:54 +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 1X9WBA-0007Op-Hh; Tue, 22 Jul 2014 09:16:12 +0000 Received: from mail-pd0-f174.google.com ([209.85.192.174]) by bombadil.infradead.org with esmtps (Exim 4.80.1 #2 (Red Hat Linux)) id 1X9WB4-0007H6-1U for linux-arm-kernel@lists.infradead.org; Tue, 22 Jul 2014 09:16:06 +0000 Received: by mail-pd0-f174.google.com with SMTP id fp1so10902036pdb.33 for ; Tue, 22 Jul 2014 02:15:45 -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=SfLAetLFmC+o1kibInxTB9FXq7nIdwf26etQhT5ghMQ=; b=O+h+ZIWkdNqIoys64M8ZdjCQD7O8RnI9ZFkpXxlq1FQbekJ+OYfDsrcRdaN+WBRE6K G1LpfVaNJ16VA/9Z5H73KiZc/wnUNUjz8h9GV8NnOMY75Jj7SXA7+lp0sAaGJXgQWRDp GbCkynU0rBC6LV7r8Qtb/eXMUKK0BKwmo1jrwCQ1gkTlufcdLUoeaBDlRA8ZFbis9c/R Gf4zVtku9ZwZnfXocBLo87LEs9Qxr93T7T+qtjLdti0mUxcTee0vfVUpIvNfw1Z3odny PN6CTBTyHz4BWJd69XrWym67pyWPw4kbIPeLNEA3Wfkjg23ltwgRY9wmA1MGqqxUz1s9 eIwg== X-Gm-Message-State: ALoCoQmgsbfvkMxvoqaY1hIX62bQNukVZPT2IuMD/vdDk3XuMEI3im/OWw0wOeKlKhBFgqKEOkH6 X-Received: by 10.70.102.102 with SMTP id fn6mr31764634pdb.100.1406020544810; Tue, 22 Jul 2014 02:15:44 -0700 (PDT) Received: from localhost.localdomain (KD182249094163.au-net.ne.jp. [182.249.94.163]) by mx.google.com with ESMTPSA id v1sm12071461pbs.1.2014.07.22.02.15.39 for (version=TLSv1.2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Tue, 22 Jul 2014 02:15:43 -0700 (PDT) From: AKASHI Takahiro To: wad@chromium.org, catalin.marinas@arm.com, will.deacon@arm.com, keescook@chromium.org Subject: [PATCH v5 1/3] arm64: ptrace: reload a syscall number after ptrace operations Date: Tue, 22 Jul 2014 18:14:57 +0900 Message-Id: <1406020499-5537-2-git-send-email-takahiro.akashi@linaro.org> X-Mailer: git-send-email 1.9.1 In-Reply-To: <1406020499-5537-1-git-send-email-takahiro.akashi@linaro.org> References: <1406020499-5537-1-git-send-email-takahiro.akashi@linaro.org> X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20140722_021606_111171_16959ABE X-CRM114-Status: GOOD ( 11.90 ) X-Spam-Score: -0.7 (/) Cc: AKASHI Takahiro , dsaxena@linaro.org, linaro-kernel@lists.linaro.org, linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.18-1 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=-1.9 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 Arm64 holds a syscall number in w8(x8) register. Ptrace tracer may change its value either to: * any valid syscall number to alter a system call, or * -1 to skip a system call This patch implements this behavior by reloading that value into syscallno in struct pt_regs after tracehook_report_syscall_entry() or secure_computing(). In case of '-1', a return value of system call can also be changed by the tracer setting the value to x0 register, and so sys_ni_nosyscall() should not be called. See also: 42309ab4, ARM: 8087/1: ptrace: reload syscall number after secure_computing() check Signed-off-by: AKASHI Takahiro --- arch/arm64/kernel/entry.S | 2 ++ arch/arm64/kernel/ptrace.c | 13 +++++++++++++ 2 files changed, 15 insertions(+) diff --git a/arch/arm64/kernel/entry.S b/arch/arm64/kernel/entry.S index 5141e79..de8bdbc 100644 --- a/arch/arm64/kernel/entry.S +++ b/arch/arm64/kernel/entry.S @@ -628,6 +628,8 @@ ENDPROC(el0_svc) __sys_trace: mov x0, sp bl syscall_trace_enter + cmp w0, #-1 // skip syscall? + b.eq ret_to_user adr lr, __sys_trace_return // return address uxtw scno, w0 // syscall number (possibly new) mov x1, sp // pointer to regs diff --git a/arch/arm64/kernel/ptrace.c b/arch/arm64/kernel/ptrace.c index 70526cf..100d7d1 100644 --- a/arch/arm64/kernel/ptrace.c +++ b/arch/arm64/kernel/ptrace.c @@ -21,6 +21,7 @@ #include #include +#include #include #include #include @@ -1109,9 +1110,21 @@ static void tracehook_report_syscall(struct pt_regs *regs, asmlinkage int syscall_trace_enter(struct pt_regs *regs) { + unsigned long saved_x0, saved_x8; + + saved_x0 = regs->regs[0]; + saved_x8 = regs->regs[8]; + if (test_thread_flag(TIF_SYSCALL_TRACE)) tracehook_report_syscall(regs, PTRACE_SYSCALL_ENTER); + regs->syscallno = regs->regs[8]; + if ((long)regs->syscallno == ~0UL) { /* skip this syscall */ + regs->regs[8] = saved_x8; + if (regs->regs[0] == saved_x0) /* not changed by user */ + regs->regs[0] = -ENOSYS; + } + if (test_thread_flag(TIF_SYSCALL_TRACEPOINT)) trace_sys_enter(regs, regs->syscallno);