From patchwork Fri Jan 17 08:11:24 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: AKASHI Takahiro X-Patchwork-Id: 23287 Return-Path: X-Original-To: linaro@patches.linaro.org Delivered-To: linaro@patches.linaro.org Received: from mail-qc0-f199.google.com (mail-qc0-f199.google.com [209.85.216.199]) by ip-10-151-82-157.ec2.internal (Postfix) with ESMTPS id 0B70E202FA for ; Fri, 17 Jan 2014 08:12:01 +0000 (UTC) Received: by mail-qc0-f199.google.com with SMTP id m20sf5709882qcx.10 for ; Fri, 17 Jan 2014 00:12:01 -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=bk74yZtTAq3DyQC8yUPHw+55myaPQMbJu/PnLDpHsUY=; b=FeXCLDTGiNTlDMh17eFQA2sB85eQdYgCkBEQ+EwmON3Yjav//uboA4fC47UmoQj3gJ KFeI9VD+qFAdL2W2oviB/ksKt07/ouNvSDOUS7GGXf/MpbUJ2Cv7t8kXVURuTELtcDNm my0Qsb7vJ+MiTovuCMbCfhA/F30rFFrojlW9X5Y79Q26c7qm6jN+SrcNerI8jsHo+Qj7 73r5NfD/4kljMlB/a82t6gUIpQuMnHgcnorchvTtgvqNfA1wy8uBo9QYrorghkHRkNT7 Gdxs/AA4Tl0Ud+2zlPMk/KzGcvanyoFK2W6vSmDdRPZP/rMFb3ka81To+GXtE+pi3oYO mu4A== X-Gm-Message-State: ALoCoQmMoCDPE+BgC0AmmU4BBwf6y1CnZeDpJxKPmoyBW1isd+4bEB+WXFt66dTuq1aYOpZ3nXKz X-Received: by 10.236.27.79 with SMTP id d55mr165811yha.17.1389946320840; Fri, 17 Jan 2014 00:12:00 -0800 (PST) MIME-Version: 1.0 X-BeenThere: patchwork-forward@linaro.org Received: by 10.140.30.198 with SMTP id d64ls340852qgd.39.gmail; Fri, 17 Jan 2014 00:12:00 -0800 (PST) X-Received: by 10.220.76.201 with SMTP id d9mr207380vck.33.1389946320708; Fri, 17 Jan 2014 00:12:00 -0800 (PST) Received: from mail-vb0-f50.google.com (mail-vb0-f50.google.com [209.85.212.50]) by mx.google.com with ESMTPS id kn3si4552386veb.54.2014.01.17.00.12.00 for (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Fri, 17 Jan 2014 00:12:00 -0800 (PST) Received-SPF: neutral (google.com: 209.85.212.50 is neither permitted nor denied by best guess record for domain of patch+caf_=patchwork-forward=linaro.org@linaro.org) client-ip=209.85.212.50; Received: by mail-vb0-f50.google.com with SMTP id w8so1415031vbj.37 for ; Fri, 17 Jan 2014 00:12:00 -0800 (PST) X-Received: by 10.52.28.70 with SMTP id z6mr167081vdg.57.1389946320618; Fri, 17 Jan 2014 00:12:00 -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.59.13.131 with SMTP id ey3csp2227ved; Fri, 17 Jan 2014 00:12:00 -0800 (PST) X-Received: by 10.68.168.162 with SMTP id zx2mr699558pbb.74.1389946319666; Fri, 17 Jan 2014 00:11:59 -0800 (PST) Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id g5si3051436pad.236.2014.01.17.00.11.59; Fri, 17 Jan 2014 00:11:59 -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 S1752238AbaAQILv (ORCPT + 26 others); Fri, 17 Jan 2014 03:11:51 -0500 Received: from mail-pb0-f46.google.com ([209.85.160.46]:49975 "EHLO mail-pb0-f46.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751079AbaAQILp (ORCPT ); Fri, 17 Jan 2014 03:11:45 -0500 Received: by mail-pb0-f46.google.com with SMTP id ma3so3757442pbc.5 for ; Fri, 17 Jan 2014 00:11:44 -0800 (PST) X-Received: by 10.66.137.109 with SMTP id qh13mr639178pab.140.1389946304591; Fri, 17 Jan 2014 00:11:44 -0800 (PST) Received: from localhost.localdomain (KD182250177246.au-net.ne.jp. [182.250.177.246]) by mx.google.com with ESMTPSA id qw8sm20613337pbb.27.2014.01.17.00.11.42 for (version=TLSv1.1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Fri, 17 Jan 2014 00:11:43 -0800 (PST) From: AKASHI Takahiro To: linux-kernel@vger.kernel.org Cc: AKASHI Takahiro Subject: [PATCH v3] audit: Add generic compat syscall support Date: Fri, 17 Jan 2014 17:11:24 +0900 Message-Id: <1389946284-4428-2-git-send-email-takahiro.akashi@linaro.org> X-Mailer: git-send-email 1.8.3.2 In-Reply-To: <1389946284-4428-1-git-send-email-takahiro.akashi@linaro.org> References: <1389946284-4428-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.212.50 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: , lib/audit.c provides a generic definition for auditing system calls. This patch extends it for compat syscall support on bi-architectures (32/64-bit) by adding lib/compat_audit.c when CONFIG_COMPAT enabled. Each architecture that wants to use this 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 bf1ef22..3d71949 100644 --- a/include/linux/audit.h +++ b/include/linux/audit.h @@ -78,6 +78,15 @@ extern int is_audit_feature_set(int which); 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 a459c31..73ea908 100644 --- a/lib/Makefile +++ b/lib/Makefile @@ -93,6 +93,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..e29ba82 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_32, compat_write_class); + audit_register_class(AUDIT_CLASS_READ_32, compat_read_class); + audit_register_class(AUDIT_CLASS_DIR_WRITE_32, compat_dir_class); + audit_register_class(AUDIT_CLASS_CHATTR_32, compat_chattr_class); + audit_register_class(AUDIT_CLASS_SIGNAL_32, 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; + } +}