From patchwork Tue Aug 23 20:49:23 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Roberts, William C" X-Patchwork-Id: 9296329 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 9DFD260574 for ; Tue, 23 Aug 2016 20:55:38 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 8FA3B25749 for ; Tue, 23 Aug 2016 20:55:38 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 8452D28CD9; Tue, 23 Aug 2016 20:55:38 +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=-1.9 required=2.0 tests=BAYES_00 autolearn=ham version=3.3.1 Received: from emsm-gh1-uea10.nsa.gov (smtp.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.wl.linuxfoundation.org (Postfix) with ESMTPS id 32F6025749 for ; Tue, 23 Aug 2016 20:55:36 +0000 (UTC) X-IronPort-AV: E=Sophos;i="5.28,567,1464652800"; d="scan'208";a="16873757" IronPort-PHdr: =?us-ascii?q?9a23=3Agr5ItRHHb4Z1MzJGuNbpUJ1GYnF86YWxBRYc798d?= =?us-ascii?q?s5kLTJ74psqwAkXT6L1XgUPTWs2DsrQf2rOQ6PyrADBcqdbZ6TZZIcQKD0dEwe?= =?us-ascii?q?wt3CUYSPafDkP6KPO4JwcbJ+9lEGFfwnegLEJOE9z/bVCB6le77DoVBwmtfVEt?= =?us-ascii?q?fre9JIfegoyN2vyo/NWLOkMT1WP7Ou85dUnq5UWJ749N0NMkcv5wgjLy4VJwM9?= =?us-ascii?q?xMwm1pIV/B1z3d3eyXuKBZziJLpvg6/NRBW6ipN44xTLhfESh0ezttvJ6jiAPH?= =?us-ascii?q?BTeryjNcFzxO00kAPw+Q9xz+X5HsogPmp+F932+cJsSwQrcqHXy54q5tRAXviS?= =?us-ascii?q?tCMz8i7EnLm8dwi+RduxvnqBthh8bPbJq9KOt1fqSbe8gTA2VGQJV/TStEV5y9?= =?us-ascii?q?a48OBu9HNqBCqIPwvUcVhRq4GQSoQujoz2wbzkTq1LE3hrxyWTrN2xYtSpdX6H?= =?us-ascii?q?k=3D?= X-IPAS-Result: =?us-ascii?q?A2E3CQBct7xX/wHyM5BdGwEBAYMLAQEBAQEegVKjboFzlB0?= =?us-ascii?q?jh3RMAQEBAQEBAQIBAlsngjIEAxOCHAIkExQgDgMJAhcIIQgIAwEtFRgHCwUYB?= =?us-ascii?q?IgQvVQBJIgthl8RAYV3BY8VijOPIQKJboVgkDlUghIcgWxQAYRagTYBAQE?= Received: from unknown (HELO tarius.tycho.ncsc.mil) ([144.51.242.1]) by emsm-gh1-uea10.nsa.gov with ESMTP; 23 Aug 2016 20:55:34 +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 u7NKpMn6011597; Tue, 23 Aug 2016 16:51:31 -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 u7NKpMS1124168 for ; Tue, 23 Aug 2016 16:51:22 -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 u7NKpMFX011579; Tue, 23 Aug 2016 16:51:22 -0400 X-IronPort-Anti-Spam-Filtered: true X-IronPort-Anti-Spam-Result: A1DoCACStrxX/yNjr8ZdHAEBgwsBAQEBAR6BUqNukg6EDBSGCYFwTAEBAQEBAQECXoU1UjCBDxKIMb1HATCILYxoBY8VijOPIQKPTpA5VIISHIFsUAGGEAEBAQ X-IPAS-Result: A1DoCACStrxX/yNjr8ZdHAEBgwsBAQEBAR6BUqNukg6EDBSGCYFwTAEBAQEBAQECXoU1UjCBDxKIMb1HATCILYxoBY8VijOPIQKPTpA5VIISHIFsUAGGEAEBAQ X-IronPort-AV: E=Sophos;i="5.28,567,1464667200"; d="scan'208";a="5661314" 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; 23 Aug 2016 16:51:21 -0400 IronPort-PHdr: =?us-ascii?q?9a23=3AnJzbCxbnH4CubPjlo/csR8r/LSx+4OfEezUN459i?= =?us-ascii?q?sYplN5qZpMi7bnLW6fgltlLVR4KTs6sC0LuP9fu8EjVcvd7B6ClEK80UEUddyI?= =?us-ascii?q?0/pE8JOIa9E0r1LfrnPWQRPf9pcxtbxUy9KlVfA83kZlff8TWY5D8WHQjjZ0Iu?= =?us-ascii?q?frymUrDbg8n/7e2u4ZqbO1wO32vkJ+guZ0zq8U2R7pBQ2to6bP5pi1PgmThhQ6?= =?us-ascii?q?xu32RmJFaezV7Xx/yb29pdyRlWoO8r7MVaUK/3LOwSRL1cCyk6YShuvJW4/TGK?= =?us-ascii?q?dwaE52MdX2MKiVIIRlGdtFCpaKz2qDf3utBw0yiCZ4W2Eeh1Cnye6PJwRRvpjj?= =?us-ascii?q?oXHyIo+2HQzMprheRUpwzl7wdyyojYeoaUOL96f7jBVc8LTmpGGMBKXmpOBZ34?= =?us-ascii?q?J5ADFMIdLO1YqM/7vFJIohygVie2A+a61T5Mgn7/2Osxlf4mGwzcwBcIHtQSvX?= =?us-ascii?q?CSp9LwZ/Raavy80KSdlWaLVPhRwzqordaQfw=3D=3D?= X-IronPort-Anti-Spam-Filtered: true X-IronPort-Anti-Spam-Result: =?us-ascii?q?A0FTCgDMtrxX/yNjr8ZdHAEBgwsBAQEBA?= =?us-ascii?q?R6BUqNugXOQG4QMFIYJgXBMAQEBAQEBAQIBAlsngjIEARWCQlIwgQ8SiDG9SAE?= =?us-ascii?q?LJYgtjGgFjxWKM48hAo9OkDlUghIcgWxQAYYQAQEB?= X-IPAS-Result: =?us-ascii?q?A0FTCgDMtrxX/yNjr8ZdHAEBgwsBAQEBAR6BUqNugXOQG4Q?= =?us-ascii?q?MFIYJgXBMAQEBAQEBAQIBAlsngjIEARWCQlIwgQ8SiDG9SAELJYgtjGgFjxWKM?= =?us-ascii?q?48hAo9OkDlUghIcgWxQAYYQAQEB?= X-IronPort-AV: E=Sophos;i="5.28,567,1464652800"; d="scan'208";a="18700775" Received: from fmsmga002-icc.fm.intel.com ([198.175.99.35]) by emsm-gh1-uea11.nsa.gov with ESMTP; 23 Aug 2016 20:51:20 +0000 Received: from fmsmga003-icc.fm.intel.com ([198.175.99.8]) by fmsmga002-icc.fm.intel.com with ESMTP; 23 Aug 2016 13:51:19 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.28,567,1464678000"; d="scan'208";a="752611577" Received: from hshedbal-mobl7.amr.corp.intel.com (HELO wcrobert-MOBL1.amr.corp.intel.com) ([10.254.183.34]) by FMSMGA003.fm.intel.com with ESMTP; 23 Aug 2016 13:51:16 -0700 From: william.c.roberts@intel.com To: selinux@tycho.nsa.gov, seandroid-list@tycho.nsa.gov, sds@tycho.nsa.gov Subject: [PATCH 1/3] selinux: detect invalid ebitmap Date: Tue, 23 Aug 2016 13:49:23 -0700 Message-Id: <1471985365-1197-1-git-send-email-william.c.roberts@intel.com> X-Mailer: git-send-email 1.9.1 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 From: William Roberts When count is 0 and the highbit is not zero, the ebitmap is not valid and the internal node is not allocated. This causes issues when routines, like mls_context_isvalid() attempt to use the ebitmap_for_each_bit() and ebitmap_node_get_bit() as they assume a highbit > 0 will have a node allocated. Signed-off-by: William Roberts --- security/selinux/ss/ebitmap.c | 3 +++ 1 file changed, 3 insertions(+) diff --git a/security/selinux/ss/ebitmap.c b/security/selinux/ss/ebitmap.c index 894b6cd..7d10e5d 100644 --- a/security/selinux/ss/ebitmap.c +++ b/security/selinux/ss/ebitmap.c @@ -374,6 +374,9 @@ int ebitmap_read(struct ebitmap *e, void *fp) goto ok; } + if (e->highbit && !count) + goto bad; + for (i = 0; i < count; i++) { rc = next_entry(&startbit, fp, sizeof(u32)); if (rc < 0) {