From patchwork Fri Feb 28 05:17:15 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: AKASHI Takahiro X-Patchwork-Id: 25503 Return-Path: X-Original-To: linaro@patches.linaro.org Delivered-To: linaro@patches.linaro.org Received: from mail-ob0-f200.google.com (mail-ob0-f200.google.com [209.85.214.200]) by ip-10-151-82-157.ec2.internal (Postfix) with ESMTPS id 54CC42055D for ; Fri, 28 Feb 2014 05:18:31 +0000 (UTC) Received: by mail-ob0-f200.google.com with SMTP id gq1sf12478031obb.3 for ; Thu, 27 Feb 2014 21:18:30 -0800 (PST) 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:in-reply-to:references:sender:precedence:list-id :x-original-sender:x-original-authentication-results:mailing-list :list-post:list-help:list-archive:list-unsubscribe; bh=EMnUP/VKWH9QwinJ0ZwsoZZ2IT9DmYUIX43Ua9z+svo=; b=OG5NCP5UUxUfA4RZLYuH6nRKLLymQuu2T1xFYNRbflW5tF1eYv4Chza95/NgvAoI/z OVwxKek/mo0PWJKrclOOm6qA5w0L+9SahCPwxswPSddBx89YRqUmKtsv7R5FspyGnnPt TQ3zYSM870DLCqYeNjDvCaX/TqBCwNTl+klDTxyOXJ1dn/vQm2SGYNc1sZsUapYpwmVu wepkrlUPmNrBNAhuAWK641pDR9EMClWvlw5UDb1yrJrY6xwYbSbPi9ejig6QEF3VRUp1 wtj008oq8Leo+VKgToVCTltlV16xuMxosmymaCbYHAYTXIi2SIIt+C4FAfjjTomNUOan VTgw== X-Gm-Message-State: ALoCoQlVROzqmib42vLJTai9HwGzxz+6I0koFMt6Mntekcy1phShOZadW2kf9OgwOwFUpABZ/9uP X-Received: by 10.42.53.135 with SMTP id n7mr3903426icg.11.1393564710886; Thu, 27 Feb 2014 21:18:30 -0800 (PST) MIME-Version: 1.0 X-BeenThere: patchwork-forward@linaro.org Received: by 10.140.80.149 with SMTP id c21ls1013778qgd.52.gmail; Thu, 27 Feb 2014 21:18:30 -0800 (PST) X-Received: by 10.220.95.139 with SMTP id d11mr770609vcn.21.1393564710781; Thu, 27 Feb 2014 21:18:30 -0800 (PST) Received: from mail-vc0-f176.google.com (mail-vc0-f176.google.com [209.85.220.176]) by mx.google.com with ESMTPS id kp12si1165053vcb.91.2014.02.27.21.18.30 for (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Thu, 27 Feb 2014 21:18:30 -0800 (PST) Received-SPF: neutral (google.com: 209.85.220.176 is neither permitted nor denied by best guess record for domain of patch+caf_=patchwork-forward=linaro.org@linaro.org) client-ip=209.85.220.176; Received: by mail-vc0-f176.google.com with SMTP id la4so233219vcb.21 for ; Thu, 27 Feb 2014 21:18:30 -0800 (PST) X-Received: by 10.221.66.73 with SMTP id xp9mr770034vcb.27.1393564710685; Thu, 27 Feb 2014 21:18:30 -0800 (PST) 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.220.130.193 with SMTP id u1csp28861vcs; Thu, 27 Feb 2014 21:18:30 -0800 (PST) X-Received: by 10.66.250.161 with SMTP id zd1mr1236686pac.136.1393564709691; Thu, 27 Feb 2014 21:18:29 -0800 (PST) Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id sh5si642495pbc.20.2014.02.27.21.18.28; Thu, 27 Feb 2014 21:18:29 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751807AbaB1FST (ORCPT + 26 others); Fri, 28 Feb 2014 00:18:19 -0500 Received: from mail-pa0-f46.google.com ([209.85.220.46]:53939 "EHLO mail-pa0-f46.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751732AbaB1FSO (ORCPT ); Fri, 28 Feb 2014 00:18:14 -0500 Received: by mail-pa0-f46.google.com with SMTP id kp14so182526pab.5 for ; Thu, 27 Feb 2014 21:18:14 -0800 (PST) X-Received: by 10.68.233.70 with SMTP id tu6mr1289029pbc.34.1393564694251; Thu, 27 Feb 2014 21:18:14 -0800 (PST) Received: from localhost.localdomain (KD182249084248.au-net.ne.jp. [182.249.84.248]) by mx.google.com with ESMTPSA id hc4sm1758862pbc.29.2014.02.27.21.18.08 for (version=TLSv1.1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Thu, 27 Feb 2014 21:18:13 -0800 (PST) From: AKASHI Takahiro To: viro@zeniv.linux.org.uk, eparis@redhat.com, rgb@redhat.com, catalin.marinas@arm.com, will.deacon@arm.com Cc: dsaxena@linaro.org, arndb@arndb.de, linux-arm-kernel@lists.infradead.org, linaro-kernel@lists.linaro.org, linux-kernel@vger.kernel.org, linux-audit@redhat.com, AKASHI Takahiro Subject: [PATCH v6 2/2] arm64: audit: Add audit hook in ptrace/syscall_trace Date: Fri, 28 Feb 2014 14:17:15 +0900 Message-Id: <1393564635-3921-3-git-send-email-takahiro.akashi@linaro.org> X-Mailer: git-send-email 1.8.3.2 In-Reply-To: <1393564635-3921-1-git-send-email-takahiro.akashi@linaro.org> References: <1393319934-2810-1-git-send-email-takahiro.akashi@linaro.org> <1393564635-3921-1-git-send-email-takahiro.akashi@linaro.org> 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=neutral (google.com: 209.85.220.176 is neither permitted nor denied by best guess record for domain of patch+caf_=patchwork-forward=linaro.org@linaro.org) 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: , This patch adds auditing functions on entry to or exit from every system call invocation. Acked-by: Richard Guy Briggs Signed-off-by: AKASHI Takahiro --- arch/arm64/kernel/ptrace.c | 54 ++++++++++++++++++++++++++------------------ 1 file changed, 32 insertions(+), 22 deletions(-) diff --git a/arch/arm64/kernel/ptrace.c b/arch/arm64/kernel/ptrace.c index 6a8928b..d4ce70e 100644 --- a/arch/arm64/kernel/ptrace.c +++ b/arch/arm64/kernel/ptrace.c @@ -19,6 +19,7 @@ * along with this program. If not, see . */ +#include #include #include #include @@ -38,6 +39,7 @@ #include #include #include +#include #include #include @@ -1062,31 +1064,39 @@ asmlinkage int syscall_trace(int dir, struct pt_regs *regs) { unsigned long saved_reg; - if (!test_thread_flag(TIF_SYSCALL_TRACE)) - return regs->syscallno; + if (dir && test_thread_flag(TIF_SYSCALL_AUDIT)) + audit_syscall_exit(regs); + + if (test_thread_flag(TIF_SYSCALL_TRACE)) { + 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; + } - 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; - } + if (dir) + tracehook_report_syscall_exit(regs, 0); + else if (tracehook_report_syscall_entry(regs)) + regs->syscallno = ~0UL; - if (dir) - 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; + } - if (is_compat_task()) - regs->regs[12] = saved_reg; - else - regs->regs[7] = saved_reg; + if (!dir && test_thread_flag(TIF_SYSCALL_AUDIT)) + audit_syscall_entry(syscall_get_arch(current, regs), + (int)regs->syscallno, + regs->orig_x0, regs->regs[1], + regs->regs[2], regs->regs[3]); return regs->syscallno; }