From patchwork Fri Sep 5 09:46:33 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: AKASHI Takahiro X-Patchwork-Id: 4850981 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 7052B9F314 for ; Fri, 5 Sep 2014 09:51:34 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 95B2920251 for ; Fri, 5 Sep 2014 09:51:33 +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 C624A201FB for ; Fri, 5 Sep 2014 09:51:32 +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 1XPq7Q-0000OA-Uu; Fri, 05 Sep 2014 09:47:48 +0000 Received: from mail-ig0-f173.google.com ([209.85.213.173]) by bombadil.infradead.org with esmtps (Exim 4.80.1 #2 (Red Hat Linux)) id 1XPq7O-00008y-J0 for linux-arm-kernel@lists.infradead.org; Fri, 05 Sep 2014 09:47:47 +0000 Received: by mail-ig0-f173.google.com with SMTP id h18so652499igc.12 for ; Fri, 05 Sep 2014 02:47:13 -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; bh=h5reMOdci+Mvhdr/CpPacfK83iUqWxN0qhpJd8G1wT0=; b=Yz5qlUHdD5ByirEOpnSFZ6OO4bZwPWaNoI90A96vbD9RTOf6xhBZgwPT+2OSTZgxnI EivKsCG0AHgzFTS6ngxZvr2auXK8mwSs4BUidoBitxdS+Xg4wKLegkwsc9laX2blacyv gisPostNz050ixiO87qetzHyIHwojkW95iZoehsiSvGbJJffQYA24+edeB6xbvzmAXo+ lEDwltAhX2emI81IyOxUcarl1ZbcLbbZVN1jU5kM1Igg5UVwt7I6m+XTXvfUHjYgc8+u k5oSZUtJQdUnb/ujrqFdZRwtdFXVgq9kgaYdnwHnEKiqp/f7xFuq0zXkjuwHrYqX+cay 0Ppw== X-Gm-Message-State: ALoCoQmUsUaawmVUOgHDDjHs0N3kgo2naeM4+3DOnFAIuyCOB/7tRga3lanRAIjAcjezTz48d4gS X-Received: by 10.66.251.195 with SMTP id zm3mr19571450pac.78.1409910431137; Fri, 05 Sep 2014 02:47:11 -0700 (PDT) Received: from localhost.localdomain (KD182249094004.au-net.ne.jp. [182.249.94.4]) by mx.google.com with ESMTPSA id f12sm1400469pat.36.2014.09.05.02.47.05 for (version=TLSv1.2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Fri, 05 Sep 2014 02:47:10 -0700 (PDT) From: AKASHI Takahiro To: linux@arm.linux.org.uk, will.deacon@arm.com Subject: [PATCH] arm: prevent BUG_ON in audit_syscall_entry() Date: Fri, 5 Sep 2014 18:46:33 +0900 Message-Id: <1409910393-30896-1-git-send-email-takahiro.akashi@linaro.org> X-Mailer: git-send-email 1.9.1 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20140905_024746_677180_252F4473 X-CRM114-Status: GOOD ( 12.70 ) X-Spam-Score: -0.7 (/) Cc: linaro-kernel@lists.linaro.org, rgb@redhat.com, linux-kernel@vger.kernel.org, eparis@redhat.com, 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.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=-3.6 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_NONE, 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 BUG_ON() in audit_syscall_entry() will be hit if user issues syscall(-1) while syscall auditing is enabled (that is, by starting auditd). In fact, syscall(-1) just fails (not signaled despite the expectation, this is another minor bug), but the succeeding syscall hits BUG_ON. When auditing syscall(-1), audit_syscall_entry() is called anyway, but audit_syscall_exit() is not called and then 'in_syscall' flag in thread's audit context is kept on. In this way, audit_syscall_entry() against the succeeding syscall will see BUG_ON(in_syscall). This patch fixes this bug by 1) enforcing syscall exit tracing, including audit_syscall_exit(), to be executed in all cases, 2) handling user-issued syscall(-1) with arm_syscall(). Signed-off-by: AKASHI Takahiro --- arch/arm/kernel/entry-common.S | 4 ++-- arch/arm/kernel/ptrace.c | 10 +++++++++- 2 files changed, 11 insertions(+), 3 deletions(-) diff --git a/arch/arm/kernel/entry-common.S b/arch/arm/kernel/entry-common.S index e52fe5a..28d3931 100644 --- a/arch/arm/kernel/entry-common.S +++ b/arch/arm/kernel/entry-common.S @@ -426,7 +426,6 @@ ENTRY(vector_swi) local_restart: ldr r10, [tsk, #TI_FLAGS] @ check for syscall tracing stmdb sp!, {r4, r5} @ push fifth and sixth args - tst r10, #_TIF_SYSCALL_WORK @ are we tracing syscalls? bne __sys_trace @@ -476,10 +475,11 @@ __sys_trace: cmp scno, #-1 @ skip the syscall? bne 2b add sp, sp, #S_OFF @ restore stack - b ret_slow_syscall + b __sys_trace_return_skipped __sys_trace_return: str r0, [sp, #S_R0 + S_OFF]! @ save returned r0 +__sys_trace_return_skipped: mov r0, sp bl syscall_trace_exit b ret_slow_syscall diff --git a/arch/arm/kernel/ptrace.c b/arch/arm/kernel/ptrace.c index 0c27ed6..f3339c8 100644 --- a/arch/arm/kernel/ptrace.c +++ b/arch/arm/kernel/ptrace.c @@ -928,9 +928,13 @@ static void tracehook_report_syscall(struct pt_regs *regs, regs->ARM_ip = ip; } +extern int arm_syscall(int, struct pt_regs *); + asmlinkage int syscall_trace_enter(struct pt_regs *regs, int scno) { - current_thread_info()->syscall = scno; + int orig_scno; + + current_thread_info()->syscall = orig_scno = scno; /* Do the secure computing check first; failures should be fast. */ if (secure_computing(scno) == -1) @@ -947,6 +951,10 @@ asmlinkage int syscall_trace_enter(struct pt_regs *regs, int scno) audit_syscall_entry(AUDIT_ARCH_ARM, scno, regs->ARM_r0, regs->ARM_r1, regs->ARM_r2, regs->ARM_r3); + /* user-issued syscall of -1 */ + if (scno == -1 && orig_scno == -1) + arm_syscall(scno, regs); + return scno; }