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: 36788 Return-Path: X-Original-To: linaro@patches.linaro.org Delivered-To: linaro@patches.linaro.org Received: from mail-ie0-f198.google.com (mail-ie0-f198.google.com [209.85.223.198]) by ip-10-151-82-157.ec2.internal (Postfix) with ESMTPS id 6C9BD202E4 for ; Fri, 5 Sep 2014 09:47:51 +0000 (UTC) Received: by mail-ie0-f198.google.com with SMTP id rd18sf172373iec.5 for ; Fri, 05 Sep 2014 02:47:51 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:mime-version:delivered-to:from:to:cc:subject :date:message-id:sender:precedence:list-id:x-original-sender :x-original-authentication-results:mailing-list:list-post:list-help :list-archive:list-unsubscribe; bh=jipBYAOqqiBgh3qC12VgfwhiG6JJrI2Jx+woetc/q7I=; b=aCW5i1Gulxja7dDsX4sBFgo6EQm5s7g8MQ66Rzd2lpier4QMqtlpf4bSMCohPJvMAP wbrWIbBBPcvqJm/7y9FTWPbQ8XZSu98vz4vMcHJ+kBdc1C6YKz0wAVzlmy715AQZql2K j1w8aNbxCb9zbbeDuvI+ozwJIPTs6g9EuUrTyw2twdssMdIxlmzrKoq8DYmdOTuGhPMx o33OcnGrkREMgwIbrzm3eiLUKc2Jps55grn4q74Vi+dV7EgaXIZaFHLYliCI4ajVo7FN DhQyCIjbMXRkEJkp994BvYoI+uvhVztDImwyhsbvpaSeQsmDDhf2WsMnoZ64bojfGY4R /1SQ== X-Gm-Message-State: ALoCoQlpV8MgUaU9S16RGy0LNTKoiFz9u66Ua3BlkomhKHpfU562VwhOSHanASBpz6T3V5ZIlFHO X-Received: by 10.182.24.8 with SMTP id q8mr6281708obf.25.1409910471074; Fri, 05 Sep 2014 02:47:51 -0700 (PDT) MIME-Version: 1.0 X-BeenThere: patchwork-forward@linaro.org Received: by 10.140.95.50 with SMTP id h47ls605135qge.43.gmail; Fri, 05 Sep 2014 02:47:50 -0700 (PDT) X-Received: by 10.52.38.134 with SMTP id g6mr1671078vdk.34.1409910470958; Fri, 05 Sep 2014 02:47:50 -0700 (PDT) Received: from mail-vc0-f182.google.com (mail-vc0-f182.google.com [209.85.220.182]) by mx.google.com with ESMTPS id f2si262388vcy.28.2014.09.05.02.47.50 for (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Fri, 05 Sep 2014 02:47:50 -0700 (PDT) Received-SPF: pass (google.com: domain of patch+caf_=patchwork-forward=linaro.org@linaro.org designates 209.85.220.182 as permitted sender) client-ip=209.85.220.182; Received: by mail-vc0-f182.google.com with SMTP id im17so12343222vcb.27 for ; Fri, 05 Sep 2014 02:47:50 -0700 (PDT) X-Received: by 10.220.97.138 with SMTP id l10mr9259073vcn.25.1409910470871; Fri, 05 Sep 2014 02:47:50 -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.221.45.67 with SMTP id uj3csp56595vcb; Fri, 5 Sep 2014 02:47:50 -0700 (PDT) X-Received: by 10.66.154.234 with SMTP id vr10mr19580569pab.44.1409910469967; Fri, 05 Sep 2014 02:47:49 -0700 (PDT) Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id ro12si2697518pab.236.2014.09.05.02.47.49 for ; Fri, 05 Sep 2014 02:47:49 -0700 (PDT) Received-SPF: none (google.com: linux-kernel-owner@vger.kernel.org does not designate permitted sender hosts) client-ip=209.132.180.67; Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1756882AbaIEJrT (ORCPT + 26 others); Fri, 5 Sep 2014 05:47:19 -0400 Received: from mail-ig0-f169.google.com ([209.85.213.169]:52224 "EHLO mail-ig0-f169.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1756577AbaIEJrO (ORCPT ); Fri, 5 Sep 2014 05:47:14 -0400 Received: by mail-ig0-f169.google.com with SMTP id r2so9149igi.4 for ; Fri, 05 Sep 2014 02:47:13 -0700 (PDT) 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 Cc: viro@zeniv.linux.org.uk, eparis@redhat.com, rgb@redhat.com, dsaxena@linaro.org, linux-arm-kernel@lists.infradead.org, linaro-kernel@lists.linaro.org, linux-kernel@vger.kernel.org, linux-audit@redhat.com, AKASHI Takahiro 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 Sender: linux-kernel-owner@vger.kernel.org Precedence: list List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-Removed-Original-Auth: Dkim didn't pass. X-Original-Sender: takahiro.akashi@linaro.org X-Original-Authentication-Results: mx.google.com; spf=pass (google.com: domain of patch+caf_=patchwork-forward=linaro.org@linaro.org designates 209.85.220.182 as permitted sender) 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 List-Post: , List-Help: , List-Archive: List-Unsubscribe: , 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; }