From patchwork Tue Nov 18 01:10:34 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: AKASHI Takahiro X-Patchwork-Id: 5325041 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 163E89F1E1 for ; Tue, 18 Nov 2014 01:14:12 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 3B4B020120 for ; Tue, 18 Nov 2014 01:14:11 +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 6026D200E5 for ; Tue, 18 Nov 2014 01:14:10 +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 1XqXLD-0000hx-QJ; Tue, 18 Nov 2014 01:12:23 +0000 Received: from mail-pa0-f50.google.com ([209.85.220.50]) by bombadil.infradead.org with esmtps (Exim 4.80.1 #2 (Red Hat Linux)) id 1XqXKs-0000GD-LZ for linux-arm-kernel@lists.infradead.org; Tue, 18 Nov 2014 01:12:03 +0000 Received: by mail-pa0-f50.google.com with SMTP id bj1so3149303pad.23 for ; Mon, 17 Nov 2014 17:11:41 -0800 (PST) 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=Ycu4mOgiX31zssBUbA/M/s278kOTSRluK2F6VXxYBwI=; b=F0xJTnAbM4x7GGjjAzYAizmPHUCKUnIbgfjGr12XsQ3lYkk+vFMAxNrSuNq6IqBLcZ +t33gE6PqWD7ljyvhabE5aSEoL8UYR4cXi90gThMLV25S+K6MJ1OR4gBb+10NRE8MXWt U2OIL+ZokI6AAz72+IHL7hfL//o819AQ025OXQqnXXWY5RpTTiyr0Xw7f/eCo10EospA tTbqr8vgiaA2yD3/TytOnoTFZm431M/7x0GgO1EV2rldqpY12n4PYYaV1WuruTBTfUz9 yWhnbfS0/fHdKwIJH1aIe5sZKtXo76bCO0Fgj7KYi+LL0QDs0pvV1akBidkRhVzfoDd+ GefA== X-Gm-Message-State: ALoCoQnqn/3QtiCNNuxs3bO/uD+kC2n8X8d5lPoh1sLZr8iYdMaEgUXtVyIS7ZxBvTy1869R9aLL X-Received: by 10.68.162.66 with SMTP id xy2mr12885185pbb.28.1416273101708; Mon, 17 Nov 2014 17:11:41 -0800 (PST) Received: from localhost.localdomain (KD182249087116.au-net.ne.jp. [182.249.87.116]) by mx.google.com with ESMTPSA id cf12sm36225005pdb.77.2014.11.17.17.11.36 for (version=TLSv1.2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Mon, 17 Nov 2014 17:11:40 -0800 (PST) From: AKASHI Takahiro To: keescook@chromium.org, catalin.marinas@arm.com, will.deacon@arm.com Subject: [PATCH v8 2/6] arm64: ptrace: allow tracer to skip a system call Date: Tue, 18 Nov 2014 10:10:34 +0900 Message-Id: <1416273038-15590-3-git-send-email-takahiro.akashi@linaro.org> X-Mailer: git-send-email 1.9.1 In-Reply-To: <1416273038-15590-1-git-send-email-takahiro.akashi@linaro.org> References: <1416273038-15590-1-git-send-email-takahiro.akashi@linaro.org> X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20141117_171202_753273_B0FBEE44 X-CRM114-Status: GOOD ( 14.30 ) X-Spam-Score: -0.7 (/) Cc: linaro-kernel@lists.linaro.org, arndb@arndb.de, linux-kernel@vger.kernel.org, AKASHI Takahiro , dsaxena@linaro.org, linux-arm-kernel@lists.infradead.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=-2.6 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_LOW, 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 If tracer specifies -1 as a syscall number, this traced system call should be skipped with a return value specified in x0. This patch implements this semantics, but there is one restriction here: syscall(-1) always return ENOSYS whatever value is stored in x0 (a return value) at syscall entry. Normally, with ptrace off, syscall(-1) returns -ENOSYS. With ptrace on, however, if a tracer didn't pay any attention to user-issued syscall(-1) and just let it go, it would return a value in x0 as in other system call cases. This means that this system call might succeed and yet see any bogus return value. This should be definitely avoided. Please also note: * syscall entry tracing and syscall exit tracing (ftrace tracepoint and audit) are always executed, if enabled, even when skipping a system call (that is, -1). In this way, we can avoid a potential bug where audit_syscall_entry() might be called without audit_syscall_exit() at the previous system call being called, that would cause OOPs in audit_syscall_entry(). Signed-off-by: AKASHI Takahiro --- arch/arm64/kernel/entry.S | 3 +++ arch/arm64/kernel/ptrace.c | 18 ++++++++++++++++++ 2 files changed, 21 insertions(+) diff --git a/arch/arm64/kernel/entry.S b/arch/arm64/kernel/entry.S index 726b910..01118b1 100644 --- a/arch/arm64/kernel/entry.S +++ b/arch/arm64/kernel/entry.S @@ -670,6 +670,8 @@ ENDPROC(el0_svc) __sys_trace: mov x0, sp bl syscall_trace_enter + cmp w0, #-1 // skip the syscall? + b.eq __sys_trace_return_skipped adr lr, __sys_trace_return // return address uxtw scno, w0 // syscall number (possibly new) mov x1, sp // pointer to regs @@ -684,6 +686,7 @@ __sys_trace: __sys_trace_return: str x0, [sp] // save returned x0 +__sys_trace_return_skipped: 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 8b98781..34b1e85 100644 --- a/arch/arm64/kernel/ptrace.c +++ b/arch/arm64/kernel/ptrace.c @@ -1149,6 +1149,8 @@ static void tracehook_report_syscall(struct pt_regs *regs, asmlinkage int syscall_trace_enter(struct pt_regs *regs) { + int orig_syscallno = regs->syscallno; + if (test_thread_flag(TIF_SYSCALL_TRACE)) tracehook_report_syscall(regs, PTRACE_SYSCALL_ENTER); @@ -1158,6 +1160,22 @@ asmlinkage int syscall_trace_enter(struct pt_regs *regs) audit_syscall_entry(regs->syscallno, regs->orig_x0, regs->regs[1], regs->regs[2], regs->regs[3]); + if (((int)regs->syscallno == -1) && (orig_syscallno == -1)) { + /* + * user-issued syscall(-1): + * RESTRICTION: We always return ENOSYS whatever value is + * stored in x0 (a return value) at this point. + * Normally, with ptrace off, syscall(-1) returns -ENOSYS. + * With ptrace on, however, if a tracer didn't pay any + * attention to user-issued syscall(-1) and just let it go + * without a hack here, it would return a value in x0 as in + * other system call cases. This means that this system call + * might succeed and see any bogus return value. + * This should be definitely avoided. + */ + regs->regs[0] = -ENOSYS; + } + return regs->syscallno; }