From patchwork Tue Nov 19 09:43:55 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: AKASHI Takahiro X-Patchwork-Id: 21609 Return-Path: X-Original-To: linaro@patches.linaro.org Delivered-To: linaro@patches.linaro.org Received: from mail-qe0-f72.google.com (mail-qe0-f72.google.com [209.85.128.72]) by ip-10-151-82-157.ec2.internal (Postfix) with ESMTPS id 79B3523A4E for ; Tue, 19 Nov 2013 09:44:14 +0000 (UTC) Received: by mail-qe0-f72.google.com with SMTP id 5sf545812qeb.11 for ; Tue, 19 Nov 2013 01:44:13 -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:x-original-sender :x-original-authentication-results:precedence:mailing-list:list-id :list-post:list-help:list-archive:list-unsubscribe; bh=DdxsYYBhuxpIILvJJIhr8HrOGhvnmZYRZpMXPcFWItc=; b=W//2Tn/pROTulOMxS0E4tOu3x4C43v//srjkRVanRPmprVTVzOYfnmXWQdIzmRk5EQ F/u4xSDhh9u9w+AUU5/QSo4FZgqtjOCe8WC2fPFnaRbJXi1KYye+wqW5+RwYCK210Jyk E1SCjTKqmKEk4ktp7hwLmxeKcd/stoErSYtBebKv0D0JBaEJG37IFGwSA5TLQ26MHKDg hifCB+FOLnDslBWOiGrx967CAjyludwLnkbGdQXnk6O65I7iN8EBAdC/7Rni5++ll4dW ZRrEMOt1vVDuTI1S8/7p0qNvyCN+fO3PpEtNofHHV0PF2AQxbE7xROxIE3dVv7A3uXua UwOQ== X-Gm-Message-State: ALoCoQm+zCHjh0Y6GtcD4vIlcVlJRrT0gfqRzqY9zgb+UmN9+4rrQJ2gDsjWcw+L66i6YksO2uOS X-Received: by 10.224.124.135 with SMTP id u7mr13316857qar.5.1384854253670; Tue, 19 Nov 2013 01:44:13 -0800 (PST) MIME-Version: 1.0 X-BeenThere: patchwork-forward@linaro.org Received: by 10.49.17.7 with SMTP id k7ls2986055qed.96.gmail; Tue, 19 Nov 2013 01:44:13 -0800 (PST) X-Received: by 10.220.86.69 with SMTP id r5mr20206616vcl.9.1384854253599; Tue, 19 Nov 2013 01:44:13 -0800 (PST) Received: from mail-vc0-f180.google.com (mail-vc0-f180.google.com [209.85.220.180]) by mx.google.com with ESMTPS id ja16si7992921vec.12.2013.11.19.01.44.13 for (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Tue, 19 Nov 2013 01:44:13 -0800 (PST) Received-SPF: neutral (google.com: 209.85.220.180 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.180; Received: by mail-vc0-f180.google.com with SMTP id if17so1013777vcb.39 for ; Tue, 19 Nov 2013 01:44:13 -0800 (PST) X-Received: by 10.58.216.74 with SMTP id oo10mr20208237vec.0.1384854253169; Tue, 19 Nov 2013 01:44:13 -0800 (PST) X-Forwarded-To: patchwork-forward@linaro.org X-Forwarded-For: patch@linaro.org patchwork-forward@linaro.org Delivered-To: patches@linaro.org Received: by 10.220.174.196 with SMTP id u4csp264994vcz; Tue, 19 Nov 2013 01:44:12 -0800 (PST) X-Received: by 10.66.136.101 with SMTP id pz5mr203504pab.118.1384854252201; Tue, 19 Nov 2013 01:44:12 -0800 (PST) Received: from mail-pa0-f46.google.com (mail-pa0-f46.google.com [209.85.220.46]) by mx.google.com with ESMTPS id ar5si11456676pbd.272.2013.11.19.01.44.11 for (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Tue, 19 Nov 2013 01:44:12 -0800 (PST) Received-SPF: neutral (google.com: 209.85.220.46 is neither permitted nor denied by best guess record for domain of takahiro.akashi@linaro.org) client-ip=209.85.220.46; Received: by mail-pa0-f46.google.com with SMTP id kl14so3098855pab.19 for ; Tue, 19 Nov 2013 01:44:11 -0800 (PST) X-Received: by 10.68.42.67 with SMTP id m3mr460909pbl.116.1384854251636; Tue, 19 Nov 2013 01:44:11 -0800 (PST) Received: from localhost.localdomain (KD182249083039.au-net.ne.jp. [182.249.83.39]) by mx.google.com with ESMTPSA id vk17sm33145116pab.5.2013.11.19.01.44.07 for (version=TLSv1.1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Tue, 19 Nov 2013 01:44:10 -0800 (PST) From: AKASHI Takahiro To: linux-audit@redhat.com Cc: will.deacon@arm.com, dsaxena@linaro.org, patches@linaro.org, AKASHI Takahiro Subject: [RFC PATCH v2 1/1] audit: Add generic compat syscall support Date: Tue, 19 Nov 2013 18:43:55 +0900 Message-Id: <1384854235-6567-1-git-send-email-takahiro.akashi@linaro.org> X-Mailer: git-send-email 1.8.3.2 In-Reply-To: <1384846431-5781-2-git-send-email-takahiro.akashi@linaro.org> References: <1384846431-5781-2-git-send-email-takahiro.akashi@linaro.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.180 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 Precedence: list Mailing-list: list patchwork-forward@linaro.org; contact patchwork-forward+owners@linaro.org List-ID: X-Google-Group-Id: 836684582541 List-Post: , List-Help: , List-Archive: List-Unsubscribe: , (v1 was created mistakenly. Please igore it.) lib/audit.c provides a generic definition for auditing system calls. lib/compat_audit.c similarly adds compat syscall support for bi-architectures (32/64-bit). Each architecture must define audit_is_compat() in asm/audit.h. Signed-off-by: AKASHI Takahiro --- include/linux/audit.h | 9 +++++++++ lib/Makefile | 3 +++ lib/audit.c | 17 +++++++++++++++++ lib/compat_audit.c | 51 +++++++++++++++++++++++++++++++++++++++++++++++++ 4 files changed, 80 insertions(+) create mode 100644 lib/compat_audit.c diff --git a/include/linux/audit.h b/include/linux/audit.h index 729a4d1..c49a312 100644 --- a/include/linux/audit.h +++ b/include/linux/audit.h @@ -76,6 +76,15 @@ struct audit_field { extern int __init audit_register_class(int class, unsigned *list); extern int audit_classify_syscall(int abi, unsigned syscall); extern int audit_classify_arch(int arch); +#if defined(CONFIG_AUDIT_GENERIC) && defined(CONFIG_COMPAT) +extern unsigned compat_write_class[]; +extern unsigned compat_read_class[]; +extern unsigned compat_dir_class[]; +extern unsigned compat_chattr_class[]; +extern unsigned compat_signal_class[]; + +extern int audit_classify_compat_syscall(int abi, unsigned syscall); +#endif /* audit_names->type values */ #define AUDIT_TYPE_UNKNOWN 0 /* we don't know yet */ diff --git a/lib/Makefile b/lib/Makefile index f3bb2cb..5bb185a 100644 --- a/lib/Makefile +++ b/lib/Makefile @@ -96,6 +96,9 @@ obj-$(CONFIG_TEXTSEARCH_BM) += ts_bm.o obj-$(CONFIG_TEXTSEARCH_FSM) += ts_fsm.o obj-$(CONFIG_SMP) += percpu_counter.o obj-$(CONFIG_AUDIT_GENERIC) += audit.o +ifeq ($(CONFIG_COMPAT),y) +obj-$(CONFIG_AUDIT_GENERIC) += compat_audit.o +endif obj-$(CONFIG_SWIOTLB) += swiotlb.o obj-$(CONFIG_IOMMU_HELPER) += iommu-helper.o diff --git a/lib/audit.c b/lib/audit.c index 76bbed4..3bf3858 100644 --- a/lib/audit.c +++ b/lib/audit.c @@ -1,6 +1,7 @@ #include #include #include +#include #include static unsigned dir_class[] = { @@ -30,11 +31,20 @@ static unsigned signal_class[] = { int audit_classify_arch(int arch) { +#ifdef CONFIG_COMPAT + if (audit_is_compat(arch)) + return 1; +#endif return 0; } int audit_classify_syscall(int abi, unsigned syscall) { +#ifdef CONFIG_COMPAT + if (audit_is_compat(abi)) + return audit_classify_compat_syscall(abi, syscall); +#endif + switch(syscall) { #ifdef __NR_open case __NR_open: @@ -57,6 +67,13 @@ int audit_classify_syscall(int abi, unsigned syscall) static int __init audit_classes_init(void) { +#ifdef CONFIG_COMPAT + audit_register_class(AUDIT_CLASS_WRITE, compat_write_class); + audit_register_class(AUDIT_CLASS_READ, compat_read_class); + audit_register_class(AUDIT_CLASS_DIR_WRITE, compat_dir_class); + audit_register_class(AUDIT_CLASS_CHATTR, compat_chattr_class); + audit_register_class(AUDIT_CLASS_SIGNAL, compat_signal_class); +#endif audit_register_class(AUDIT_CLASS_WRITE, write_class); audit_register_class(AUDIT_CLASS_READ, read_class); audit_register_class(AUDIT_CLASS_DIR_WRITE, dir_class); diff --git a/lib/compat_audit.c b/lib/compat_audit.c new file mode 100644 index 0000000..94f6480 --- /dev/null +++ b/lib/compat_audit.c @@ -0,0 +1,51 @@ +#include +#include +/* FIXME: this might be architecture dependent */ +#include + +unsigned compat_dir_class[] = { +#include +~0U +}; + +unsigned compat_read_class[] = { +#include +~0U +}; + +unsigned compat_write_class[] = { +#include +~0U +}; + +unsigned compat_chattr_class[] = { +#include +~0U +}; + +unsigned compat_signal_class[] = { +#include +~0U +}; + +int audit_classify_compat_syscall(int abi, unsigned syscall) +{ + switch (syscall) { +#ifdef __NR_open + case __NR_open: + return 2; +#endif +#ifdef __NR_openat + case __NR_openat: + return 3; +#endif +#ifdef __NR_socketcall + case __NR_socketcall: + return 4; +#endif + case __NR_execve: + return 5; + default: + return 1; + } +}