From patchwork Wed Nov 6 10:25:44 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: AKASHI Takahiro X-Patchwork-Id: 3146211 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 3F7949F432 for ; Wed, 6 Nov 2013 10:28:02 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 080602047D for ; Wed, 6 Nov 2013 10:28:01 +0000 (UTC) Received: from casper.infradead.org (casper.infradead.org [85.118.1.10]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 2FE6020381 for ; Wed, 6 Nov 2013 10:27:56 +0000 (UTC) Received: from merlin.infradead.org ([2001:4978:20e::2]) by casper.infradead.org with esmtps (Exim 4.80.1 #2 (Red Hat Linux)) id 1Ve0KI-0007Su-TZ; Wed, 06 Nov 2013 10:27:07 +0000 Received: from localhost ([::1] helo=merlin.infradead.org) by merlin.infradead.org with esmtp (Exim 4.80.1 #2 (Red Hat Linux)) id 1Ve0K7-0002nM-OE; Wed, 06 Nov 2013 10:26:55 +0000 Received: from mail-pa0-f43.google.com ([209.85.220.43]) by merlin.infradead.org with esmtps (Exim 4.80.1 #2 (Red Hat Linux)) id 1Ve0K4-0002lM-9I for linux-arm-kernel@lists.infradead.org; Wed, 06 Nov 2013 10:26:52 +0000 Received: by mail-pa0-f43.google.com with SMTP id hz1so10303098pad.16 for ; Wed, 06 Nov 2013 02:26: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:from:to:cc:subject:date:message-id:in-reply-to :references; bh=tLMIes3tcEXkdxlUYypgyiMum+pJpCtkmne+kKWG+ik=; b=eZPxtZtxH6P35W8Ovb189QL2L+QgiZS22dj0vAwW30XBbw+5OtRPrP1jfmv6FhjQ6y 1CT3jauNRnP36emVnAppDv8ar1UoP5FXUSEZFygFduK37HOqM41Qvu9B8Pcq61Oz6w/s 4Usxpiu9Im2g+SwwmKmHjnIc3GQ9sp7sKTcZs5T5H8sQgCqa/337kTsKNBIVSuiML/aM L+V967xvZrl8oCgKD6qzbYkt7BU9lC3XP3BeZHC6bf/ItrqX7NrHCtOeyzs7+Q9fBp03 BacQWwOaz+1ZDYOosKCjKP1wsCvfqy/kOTfs29dymPXvv4YCZsMOSYjQVrHRNGPwGCsX JCuw== X-Gm-Message-State: ALoCoQmO0/sTcp4cPXD2jyYIJY9Tls67/9YkKFFfKngS0biJ/K/GADPXhh1FDVopLSa1KcqGLzjx X-Received: by 10.67.1.101 with SMTP id bf5mr3196163pad.50.1383733590554; Wed, 06 Nov 2013 02:26:30 -0800 (PST) Received: from localhost.localdomain (KD182249092064.au-net.ne.jp. [182.249.92.64]) by mx.google.com with ESMTPSA id qz9sm40405465pbc.3.2013.11.06.02.26.26 for (version=TLSv1.1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Wed, 06 Nov 2013 02:26:29 -0800 (PST) From: AKASHI Takahiro To: catalin.marinas@arm.com, will.deacon@arm.com, linux-arm-kernel@lists.infradead.org, linux-audit@redhat.com Subject: [PATCH 2/4] arm64: Add audit support Date: Wed, 6 Nov 2013 19:25:44 +0900 Message-Id: <1383733546-2846-3-git-send-email-takahiro.akashi@linaro.org> X-Mailer: git-send-email 1.8.3.2 In-Reply-To: <1383733546-2846-1-git-send-email-takahiro.akashi@linaro.org> References: <1383733546-2846-1-git-send-email-takahiro.akashi@linaro.org> X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20131106_052652_412305_982A9DCD X-CRM114-Status: GOOD ( 14.63 ) X-Spam-Score: -2.6 (--) Cc: AKASHI Takahiro , linaro-kernel@lists.linaro.org, patches@linaro.org X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.15 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=-4.2 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_MED, 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 --- arch/arm64/Kconfig | 3 ++ arch/arm64/include/asm/ptrace.h | 5 ++++ arch/arm64/include/asm/syscall.h | 18 ++++++++++++ arch/arm64/kernel/Makefile | 1 + arch/arm64/kernel/audit.c | 59 ++++++++++++++++++++++++++++++++++++++ 5 files changed, 86 insertions(+) create mode 100644 arch/arm64/kernel/audit.c diff --git a/arch/arm64/Kconfig b/arch/arm64/Kconfig index c044548..263c10b 100644 --- a/arch/arm64/Kconfig +++ b/arch/arm64/Kconfig @@ -46,6 +46,9 @@ config 64BIT config ARCH_PHYS_ADDR_T_64BIT def_bool y +config AUDIT_ARCH + def_bool y + config MMU def_bool y diff --git a/arch/arm64/include/asm/ptrace.h b/arch/arm64/include/asm/ptrace.h index 0dacbbf..964f4f6 100644 --- a/arch/arm64/include/asm/ptrace.h +++ b/arch/arm64/include/asm/ptrace.h @@ -133,6 +133,11 @@ struct pt_regs { #define user_stack_pointer(regs) \ ((regs)->sp) +static inline unsigned long regs_return_value(struct pt_regs *regs) +{ + return regs->regs[0]; +} + /* * Are the current registers suitable for user mode? (used to maintain * security in signal handlers) diff --git a/arch/arm64/include/asm/syscall.h b/arch/arm64/include/asm/syscall.h index 89c047f..03040ac 100644 --- a/arch/arm64/include/asm/syscall.h +++ b/arch/arm64/include/asm/syscall.h @@ -16,7 +16,10 @@ #ifndef __ASM_SYSCALL_H #define __ASM_SYSCALL_H +#include #include +#include +#include static inline int syscall_get_nr(struct task_struct *task, @@ -98,4 +101,19 @@ static inline void syscall_set_arguments(struct task_struct *task, memcpy(®s->regs[i], args, n * sizeof(args[0])); } +static inline int syscall_get_arch(struct task_struct *task, + struct pt_regs *regs) +{ +#ifdef CONFIG_COMPAT + if (is_compat_thread(task_thread_info(task))) + return AUDIT_ARCH_ARM; /* FIXME: big endian? */ +#endif + +#ifdef __AARCH64EB__ + return AUDIT_ARCH_AARCH64EB; +#else + return AUDIT_ARCH_AARCH64; +#endif +} + #endif /* __ASM_SYSCALL_H */ diff --git a/arch/arm64/kernel/Makefile b/arch/arm64/kernel/Makefile index 7b4b564..3abab29 100644 --- a/arch/arm64/kernel/Makefile +++ b/arch/arm64/kernel/Makefile @@ -11,6 +11,7 @@ arm64-obj-y := cputable.o debug-monitors.o entry.o irq.o fpsimd.o \ sys.o stacktrace.o time.o traps.o io.o vdso.o \ hyp-stub.o psci.o +arm64-obj-$(CONFIG_AUDIT) += audit.o arm64-obj-$(CONFIG_COMPAT) += sys32.o kuser32.o signal32.o \ sys_compat.o arm64-obj-$(CONFIG_MODULES) += arm64ksyms.o module.o diff --git a/arch/arm64/kernel/audit.c b/arch/arm64/kernel/audit.c new file mode 100644 index 0000000..9aab2b3 --- /dev/null +++ b/arch/arm64/kernel/audit.c @@ -0,0 +1,59 @@ +#include +#include +#include + +static unsigned dir_class[] = { +#include +~0U +}; + +static unsigned read_class[] = { +#include +~0U +}; + +static unsigned write_class[] = { +#include +~0U +}; + +static unsigned chattr_class[] = { +#include +~0U +}; + +static unsigned signal_class[] = { +#include +~0U +}; + +int audit_classify_arch(int arch) +{ + return 0; /* native */ +} + +/* AUTH_PERM support */ +int audit_classify_syscall(int abi, unsigned syscall) +{ + switch(syscall) { + case __NR_openat: + return 3; + case __NR_execve: + return 5; + default: + return 0; /* native */ + } +} + +static int __init audit_classes_init(void) +{ + audit_register_class(AUDIT_CLASS_DIR_WRITE, dir_class); + audit_register_class(AUDIT_CLASS_READ, read_class); + audit_register_class(AUDIT_CLASS_WRITE, write_class); + audit_register_class(AUDIT_CLASS_CHATTR, chattr_class); + audit_register_class(AUDIT_CLASS_SIGNAL, signal_class); + + return 0; +} + +__initcall(audit_classes_init);