From patchwork Sun Sep 25 21:34:03 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Petr Lautrbach X-Patchwork-Id: 9349951 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id D3B236077B for ; Sun, 25 Sep 2016 21:35:18 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id BCF0726220 for ; Sun, 25 Sep 2016 21:35:18 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id AF77B28976; Sun, 25 Sep 2016 21:35:18 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-4.2 required=2.0 tests=BAYES_00, RCVD_IN_DNSWL_MED autolearn=ham version=3.3.1 Received: from emsm-gh1-uea11.nsa.gov (emsm-gh1-uea11.nsa.gov [8.44.101.9]) (using TLSv1.2 with cipher DHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id B0B0426220 for ; Sun, 25 Sep 2016 21:35:17 +0000 (UTC) X-IronPort-AV: E=Sophos;i="5.30,395,1470700800"; d="scan'208";a="19531467" IronPort-PHdr: =?us-ascii?q?9a23=3ArExH1xMzYu0jWxRA0G8l6mtUPXoX/o7sNwtQ0KIM?= =?us-ascii?q?zox0KPn7rarrMEGX3/hxlliBBdydsKMezbOM+Pi5EUU7or+5+EgYd5JNUxJXwe?= =?us-ascii?q?43pCcHRPC/NEvgMfTxZDY7FskRHHVs/nW8LFQHUJ2mPw6anHS+4HYoFwnlMkIt?= =?us-ascii?q?f6KuS9SU1p78j7n60qaQSj0AvCC6b7J2IUf+hiTqne5Sv7FfLL0swADCuHpCdr?= =?us-ascii?q?ce72ppIVWOg0S0vZ/or9Ze6SAYh9YNv44FCP27LOwESulDATAnNX0lzNH6vhnE?= =?us-ascii?q?Cw2U7z0TVXtFvABPBl394Q3gFrP4rzfgvON22GHOJcn/UKwuUz2K9apnSBb0zi?= =?us-ascii?q?wAMmhqoynslsVsgfcD81qarBtlztuROdmY?= X-IPAS-Result: =?us-ascii?q?A2GoBQBEQuhX/wHyM5BdHgYMGQYMgxABAQEBAR6BU7p9IId?= =?us-ascii?q?ETAEBAQEBAQEBAgECWyeCMgQDEwWCGAIkExQgDgMJAhcpCAgDAS0VHwsFGASIK?= =?us-ascii?q?r4cJYY3hiKCSBEBhV0dBY40i0KPaAKBbIgPDIVikGdUgxkcgVJwhTl4gScBAQE?= Received: from unknown (HELO tarius.tycho.ncsc.mil) ([144.51.242.1]) by emsm-gh1-uea11.nsa.gov with ESMTP; 25 Sep 2016 21:35:15 +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 u8PLYWkW029856; Sun, 25 Sep 2016 17:34:42 -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 u8PLYV0n238663 for ; Sun, 25 Sep 2016 17:34:31 -0400 Received: from goalie.tycho.ncsc.mil (goalie [144.51.242.250]) by tarius.tycho.ncsc.mil (8.14.4/8.14.4) with ESMTP id u8PLYVLP029854 for ; Sun, 25 Sep 2016 17:34:31 -0400 X-IronPort-Anti-Spam-Filtered: true X-IronPort-Anti-Spam-Result: A1D5AQALQuhXhxy3hNFdHAEBBAEBCgEBgzsBAQEBAYFxpS6CBQGPPYQTFIYKgT9MAQIBAQEBAQITAQEBCgsJCRmFPlKBUYhLvkGGN4YiiDcdBY40i0KPaAKBbIgbhWKQZ4MdUBELgVI8NIdYAQEB X-IPAS-Result: A1D5AQALQuhXhxy3hNFdHAEBBAEBCgEBgzsBAQEBAYFxpS6CBQGPPYQTFIYKgT9MAQIBAQEBAQITAQEBCgsJCRmFPlKBUYhLvkGGN4YiiDcdBY40i0KPaAKBbIgbhWKQZ4MdUBELgVI8NIdYAQEB X-IronPort-AV: E=Sophos;i="5.30,395,1470715200"; d="scan'208";a="5727628" Received: from emsm-gh1-uea11.corp.nsa.gov (HELO emsm-gh1-uea11.nsa.gov) ([10.208.41.37]) by goalie.tycho.ncsc.mil with ESMTP; 25 Sep 2016 17:34:30 -0400 IronPort-PHdr: =?us-ascii?q?9a23=3AMO0nvhFpRPBoBfpZLPZVCJ1GYnF86YWxBRYc798d?= =?us-ascii?q?s5kLTJ75pMmwAkXT6L1XgUPTWs2DsrQf2rCQ6vqrATVIyK3CmUhKSIZLWR4BhJ?= =?us-ascii?q?detC0bK+nBN3fGKuX3ZTcxBsVIWQwt1Xi6NU9IBJS2PAWK8TWM5DIfUi/yKRBy?= =?us-ascii?q?brysXNWD1YLujavqotX6WEZhvHKFe7R8LRG7/036l/I9ps9cEJs30QbDuXBSeu?= =?us-ascii?q?5blitCLFOXmAvgtI/rpMYwu3cYh/V07MNEUKPnb4wkXLdYC3IgKGlz68r15jfZ?= =?us-ascii?q?Sg7a3nYASC0ymwdUGQLM5xGyCo/1uzbmrOB08DOXMc3/UfY/XjH0vPQjcwPhlC?= =?us-ascii?q?pSb21xy2rQkMEl1K8=3D?= X-IronPort-Anti-Spam-Filtered: true X-IronPort-Anti-Spam-Result: =?us-ascii?q?A0G3AgBEQuhXhxy3hNFdHQEFAQsBGQYMg?= =?us-ascii?q?xABAQEBAYFxpS6CBQGPPYQTFIYKgT9MAQEBAQEBAQECAQIQAQEBCgsJCRkvgjI?= =?us-ascii?q?YgkVSgVGIS75BhjeGIog3HQWONItCj2gCgWyIG4VikGeDbRELgVI8NIdYAQEB?= X-IPAS-Result: =?us-ascii?q?A0G3AgBEQuhXhxy3hNFdHQEFAQsBGQYMgxABAQEBAYFxpS6?= =?us-ascii?q?CBQGPPYQTFIYKgT9MAQEBAQEBAQECAQIQAQEBCgsJCRkvgjIYgkVSgVGIS75Bh?= =?us-ascii?q?jeGIog3HQWONItCj2gCgWyIG4VikGeDbRELgVI8NIdYAQEB?= X-IronPort-AV: E=Sophos;i="5.30,395,1470700800"; d="scan'208";a="19531459" Received: from mx1.redhat.com ([209.132.183.28]) by emsm-gh1-uea11.nsa.gov with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 25 Sep 2016 21:34:17 +0000 Received: from int-mx13.intmail.prod.int.phx2.redhat.com (int-mx13.intmail.prod.int.phx2.redhat.com [10.5.11.26]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id B54677F7D0 for ; Sun, 25 Sep 2016 21:34:16 +0000 (UTC) Received: from rhel-at-redhat.localdomain.com ([10.40.2.167]) by int-mx13.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id u8PLYFvw015147; Sun, 25 Sep 2016 17:34:16 -0400 From: Petr Lautrbach To: selinux@tycho.nsa.gov Subject: [PATCH v2] libsemanage: Use pp module name instead of filename Date: Sun, 25 Sep 2016 23:34:03 +0200 Message-Id: <1474839243-22096-1-git-send-email-plautrba@redhat.com> X-Scanned-By: MIMEDefang 2.68 on 10.5.11.26 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.28]); Sun, 25 Sep 2016 21:34:16 +0000 (UTC) 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-Virus-Scanned: ClamAV using ClamSMTP When a user installs a module, the filename is used as the module name. This change was introduced with CIL language where a module name is not stored in the module itself. It means that when a pp module has different filename and stored module name, the filename is used instead of the stored module name. It brings problems with compatibility for scripts and modules which were built and used on older system and were migrated to the new userspace. This patch changes the behavior of semanage_direct_install_file() which is used by 'semodule -i' so that when a module with pp language extension is installed, it tries to get and use a stored module name instead of a filename. A warning message is provided. The warning message in policycoreutils/hll/pp is updated to reflect this change: $ semodule -X 400 -i /root/testfile.pp Warning: SELinux userspace will refer to the module from /root/testfile.pp as testmod rather than testfile $ /usr/libexec/selinux/hll/pp /root/testfile.pp testfile.cil Warning: SELinux userspace will refer to the module from /root/testfile.pp as testmod rather than testfile Signed-off-by: Petr Lautrbach --- libsemanage/src/direct_api.c | 61 +++++++++++++++++++++++++++++++++++++++++++- policycoreutils/hll/pp/pp.c | 2 +- 2 files changed, 61 insertions(+), 2 deletions(-) diff --git a/libsemanage/src/direct_api.c b/libsemanage/src/direct_api.c index 2187b65..4320f43 100644 --- a/libsemanage/src/direct_api.c +++ b/libsemanage/src/direct_api.c @@ -363,6 +363,48 @@ static int semanage_direct_begintrans(semanage_handle_t * sh) /********************* utility functions *********************/ +/* Takes a module stored in 'module_data' and parses its headers. + * Sets reference variables 'module_name' to module's name, and + * 'version' to module's version. The caller is responsible for + * free()ing 'module_name', and 'version'; they will be + * set to NULL upon entering this function. Returns 0 on success, -1 + * if out of memory, or -2 if data did not represent a module. + */ +static int parse_module_headers(semanage_handle_t * sh, char *module_data, + size_t data_len, char **module_name, + char **version) +{ + struct sepol_policy_file *pf; + int file_type; + *module_name = *version = NULL; + + if (sepol_policy_file_create(&pf)) { + ERR(sh, "Out of memory!"); + return -1; + } + sepol_policy_file_set_mem(pf, module_data, data_len); + sepol_policy_file_set_handle(pf, sh->sepolh); + if (module_data == NULL || + data_len == 0 || + sepol_module_package_info(pf, &file_type, module_name, + version) == -1) { + sepol_policy_file_free(pf); + ERR(sh, "Could not parse module data."); + return -2; + } + sepol_policy_file_free(pf); + if (file_type != SEPOL_POLICY_MOD) { + if (file_type == SEPOL_POLICY_BASE) + ERR(sh, + "Received a base module, expected a non-base module."); + else + ERR(sh, "Data did not represent a module."); + return -2; + } + + return 0; +} + #include #include #include @@ -1524,7 +1566,9 @@ static int semanage_direct_install_file(semanage_handle_t * sh, char *path = NULL; char *filename; char *lang_ext = NULL; + char *module_name = NULL; char *separator; + char *version = NULL; if ((data_len = map_file(sh, install_filename, &data, &compressed)) <= 0) { ERR(sh, "Unable to read file %s\n", install_filename); @@ -1564,10 +1608,25 @@ static int semanage_direct_install_file(semanage_handle_t * sh, lang_ext = separator + 1; } - retval = semanage_direct_install(sh, data, data_len, filename, lang_ext); + if (strcmp(lang_ext, "pp") != 0) { + module_name = strdup(filename); + if (module_name == NULL) { + ERR(sh, "No memory available for module_name.\n"); + retval = -1; + goto cleanup; + } + } else { + if ((retval = parse_module_headers(sh, data, data_len, &module_name, &version)) != 0) + goto cleanup; + + fprintf(stderr, "Warning: SELinux userspace will refer to the module from %s as %s rather than %s\n", install_filename, module_name, filename); + free(version); + } + retval = semanage_direct_install(sh, data, data_len, module_name, lang_ext); cleanup: if (data_len > 0) munmap(data, data_len); + free(module_name); free(path); return retval; diff --git a/policycoreutils/hll/pp/pp.c b/policycoreutils/hll/pp/pp.c index 9245975..2c9f53f 100644 --- a/policycoreutils/hll/pp/pp.c +++ b/policycoreutils/hll/pp/pp.c @@ -142,7 +142,7 @@ int main(int argc, char **argv) *separator = '\0'; } if (strcmp(mod_name, cil_name) != 0) { - fprintf(stderr, "Warning: SELinux userspace will refer to the module from %s as %s rather than %s\n", ifile, cil_name, mod_name); + fprintf(stderr, "Warning: SELinux userspace will refer to the module from %s as %s rather than %s\n", ifile, mod_name, cil_name); } free(cil_path); }