From patchwork Fri May 6 18:56:43 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: James Carter X-Patchwork-Id: 9035881 Return-Path: X-Original-To: patchwork-selinux@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork2.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.136]) by patchwork2.web.kernel.org (Postfix) with ESMTP id 926D7BF29F for ; Fri, 6 May 2016 18:56:23 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id D144F203A1 for ; Fri, 6 May 2016 18:56:22 +0000 (UTC) Received: from emsm-gh1-uea10.nsa.gov (emsm-gh1-uea10.nsa.gov [8.44.101.8]) (using TLSv1.2 with cipher DHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 6BEE220398 for ; Fri, 6 May 2016 18:56:20 +0000 (UTC) X-IronPort-AV: E=Sophos;i="5.24,587,1454976000"; d="scan'208";a="13444687" IronPort-PHdr: =?us-ascii?q?9a23=3AJj9S4RZlxT1cYYEWGXz4Y1H/LSx+4OfEezUN459i?= =?us-ascii?q?sYplN5qZpcmybnLW6fgltlLVR4KTs6sC0LqH9fi+EjVauN6oizMrTt9lb1c9k8?= =?us-ascii?q?IYnggtUoauKHbQC7rUVRE8B9lIT1R//nu2YgB/Ecf6YEDO8DXptWZBUiv2OQc9?= =?us-ascii?q?HOnpAIma153xjLDjvcWNKFwS3XKUWvBbElaflU3prM4YgI9veO4a6yDihT92Qd?= =?us-ascii?q?lQ3n5iPlmJnhzxtY+a9Z9n9DlM6bp6r5YTGZjge+wEaZAQTHF8ayFmrPHs4ALO?= =?us-ascii?q?SQqJ+2s0TnQdkh0OBRPMqh79QMTfqCz/48h03SSBdeb/V6w5Q3z27bhgQQX00g?= =?us-ascii?q?8bJjU59yfRkcU2g6VF9kHy7ydjypLZNdnGfMF1ebnQKJZAHWc=3D?= X-IPAS-Result: =?us-ascii?q?A2FBBQCp5yxX/wHyM5BeHAGDG4FDD7sBH4czTAEBAQEBAQI?= =?us-ascii?q?CYieCLYIcAiQTFCAOAwkCFykICAMBLRUfCwUYBIgKvnmOfREBhXUFjVyKQ44bA?= =?us-ascii?q?olThT8CjzZigUJDG4FnUoZrgTUBAQE?= Received: from unknown (HELO tarius.tycho.ncsc.mil) ([144.51.242.1]) by emsm-gh1-uea10.nsa.gov with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 06 May 2016 18:56:18 +0000 Received: from prometheus.infosec.tycho.ncsc.mil (prometheus [192.168.25.40]) by tarius.tycho.ncsc.mil (8.14.4/8.14.4) with ESMTP id u46It7ag009956; Fri, 6 May 2016 14:55:16 -0400 Received: from tarius.tycho.ncsc.mil (tarius.infosec.tycho.ncsc.mil [144.51.242.1]) by prometheus.infosec.tycho.ncsc.mil (8.15.2/8.15.2) with ESMTP id u46It5qP235642 for ; Fri, 6 May 2016 14:55:05 -0400 Received: from moss-lions.infosec.tycho.ncsc.mil (moss-lions [192.168.25.4]) by tarius.tycho.ncsc.mil (8.14.4/8.14.4) with ESMTP id u46It5h7009954 for ; Fri, 6 May 2016 14:55:05 -0400 From: James Carter To: selinux@tycho.nsa.gov Subject: [PATCH] libsepol: Change which attributes CIL keeps in the binary policy Date: Fri, 6 May 2016 14:56:43 -0400 Message-Id: <1462561003-2629-1-git-send-email-jwcart2@tycho.nsa.gov> X-Mailer: git-send-email 2.5.5 X-BeenThere: selinux@tycho.nsa.gov X-Mailman-Version: 2.1.20 Precedence: list List-Id: "Security-Enhanced Linux \(SELinux\) mailing list" List-Post: List-Help: MIME-Version: 1.0 Errors-To: selinux-bounces@tycho.nsa.gov Sender: "Selinux" X-Spam-Status: No, score=-4.0 required=5.0 tests=BAYES_00,RP_MATCHES_RCVD, UNPARSEABLE_RELAY autolearn=ham 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 The removal of attributes that are only used in neverallow rules is hindering AOSP adoption of the CIL compiler. This is because AOSP extracts neverallow rules from its policy.conf for use in the Android compatibility test suite. These neverallow rules are applied against the binary policy being tested to check for a violation. Any neverallow rules with an attribute that has been removed cannot be checked. Now attributes are kept unless they are not used in any allow rule and they are auto-generated or named "cil_gen_require" or do not have any types associated with them. Signed-off-by: James Carter --- libsepol/cil/src/cil_post.c | 27 +++++++++++++++++++++++++++ libsepol/src/module_to_cil.c | 8 +++++--- 2 files changed, 32 insertions(+), 3 deletions(-) diff --git a/libsepol/cil/src/cil_post.c b/libsepol/cil/src/cil_post.c index a694b33..f8447c9 100644 --- a/libsepol/cil/src/cil_post.c +++ b/libsepol/cil/src/cil_post.c @@ -47,6 +47,9 @@ #include "cil_verify.h" #include "cil_symtab.h" +#define GEN_REQUIRE_ATTR "cil_gen_require" /* Also in libsepol/src/module_to_cil.c */ +#define TYPEATTR_INFIX "_typeattr_" /* Also in libsepol/src/module_to_cil.c */ + static int __cil_expr_to_bitmap(struct cil_list *expr, ebitmap_t *out, int max, struct cil_db *db); static int __cil_expr_list_to_bitmap(struct cil_list *expr_list, ebitmap_t *out, int max, struct cil_db *db); @@ -1186,6 +1189,27 @@ exit: return SEPOL_ERR; } +static int cil_typeattribute_used(struct cil_typeattribute *cil_attr) +{ + if (cil_attr->used) { + return CIL_TRUE; + } + + if (strcmp(DATUM(cil_attr)->name, GEN_REQUIRE_ATTR) == 0) { + return CIL_FALSE; + } + + if (strstr(DATUM(cil_attr)->name,TYPEATTR_INFIX) != NULL) { + return CIL_FALSE; + } + + if (ebitmap_cardinality(cil_attr->types) == 0) { + return CIL_FALSE; + } + + return CIL_TRUE; +} + static int __cil_post_db_attr_helper(struct cil_tree_node *node, uint32_t *finished, void *extra_args) { int rc = SEPOL_ERR; @@ -1208,6 +1232,9 @@ static int __cil_post_db_attr_helper(struct cil_tree_node *node, uint32_t *finis if (attr->types == NULL) { rc = __evaluate_type_expression(attr, db); if (rc != SEPOL_OK) goto exit; + if (cil_typeattribute_used(attr)) { + attr->used = CIL_TRUE; + } } break; } diff --git a/libsepol/src/module_to_cil.c b/libsepol/src/module_to_cil.c index b9a4af7..bcbb4de 100644 --- a/libsepol/src/module_to_cil.c +++ b/libsepol/src/module_to_cil.c @@ -58,7 +58,9 @@ FILE *out_file; #define STACK_SIZE 16 #define DEFAULT_LEVEL "systemlow" #define DEFAULT_OBJECT "object_r" -#define GEN_REQUIRE_ATTR "cil_gen_require" +#define GEN_REQUIRE_ATTR "cil_gen_require" /* Also in libsepol/cil/src/cil_post.c */ +#define TYPEATTR_INFIX "_typeattr_" /* Also in libsepol/cil/src/cil_post.c */ +#define ROLEATTR_INFIX "_roleattr_" __attribute__ ((format(printf, 1, 2))) static void log_err(const char *fmt, ...) @@ -626,9 +628,9 @@ static int set_to_cil_attr(struct policydb *pdb, int is_type, char ***names, uin num_attrs++; if (is_type) { - attr_infix = "_typeattr_"; + attr_infix = TYPEATTR_INFIX; } else { - attr_infix = "_roleattr_"; + attr_infix = ROLEATTR_INFIX; } len = strlen(pdb->name) + strlen(attr_infix) + num_digits(num_attrs) + 1;