From patchwork Wed Aug 10 21:51:20 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: 9274251 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 1E4CA600CB for ; Wed, 10 Aug 2016 21:54:39 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 048AE28338 for ; Wed, 10 Aug 2016 21:54:39 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id ED1102840F; Wed, 10 Aug 2016 21:54: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=-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 (smtp.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 46CAE28338 for ; Wed, 10 Aug 2016 21:54:38 +0000 (UTC) X-IronPort-AV: E=Sophos;i="5.28,502,1464652800"; d="scan'208";a="18384201" IronPort-PHdr: =?us-ascii?q?9a23=3ArkMG1Ry2UvTRUX/XCy+O+j09IxM/srCxBDY+r6Qd?= =?us-ascii?q?0OkRIJqq85mqBkHD//Il1AaPBtSCraoawLKG++C4ACpbsM7H6ChDOLV3FDY9wf?= =?us-ascii?q?0MmAIhBMPXQWbaF9XNKxIAIcJZSVV+9Gu6O0UGUOz3ZlnVv2HgpWVKQka3CwN5?= =?us-ascii?q?K6zPF5LIiIzvjqbpqsSVO1sD3Gr1Iesrak7n9UOJ7oheqLAhA5558gHOrHpMdr?= =?us-ascii?q?Ye7kJTDnXXoSzB4Nyt9oVo6SVatqFp3cdBVaLnY/ZwFuQAX3wbKWR92OnH/VmG?= =?us-ascii?q?FFPOtTMgVTANnx5JBRXVxA3rVZf29C3hv6xy3zfedc/pRrkuRW6K87ZgSBiujj?= =?us-ascii?q?wOcTE+7iWfkcF5iq5BpxOt4hh+2JL8fJCeNP04eLjUO9wdWy4JRcpKfzBQCYO7?= =?us-ascii?q?KY0UBqwOOvgLgZP6og4RrB+6BACpQuip0DhCi2XqxoU71fgsFUfN2wlzTJo1rH?= =?us-ascii?q?3IoYCtZ+8pWuevwfyNlG3O?= X-IPAS-Result: =?us-ascii?q?A2EWBAAZoqtX/wHyM5BdGgEBAQGDJ4FSpwmUEyOHZUwBAQE?= =?us-ascii?q?BAQECAlongjIEAxGCFQIEAQIkExQgDgMJAQEXCCEICAMBLRURBwcLBRgEiBDCF?= =?us-ascii?q?QwBJIgqhl8RAYV3BY8Oii6PEgKJaoVXkCxUghIcgWxOAYYagTYBAQE?= Received: from unknown (HELO tarius.tycho.ncsc.mil) ([144.51.242.1]) by emsm-gh1-uea11.nsa.gov with ESMTP; 10 Aug 2016 21:54:36 +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 u7ALsY8w027338; Wed, 10 Aug 2016 17:54:35 -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 u7ALpUlA106418 for ; Wed, 10 Aug 2016 17:51:30 -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 u7ALpTtq027154; Wed, 10 Aug 2016 17:51:29 -0400 X-IronPort-Anti-Spam-Filtered: true X-IronPort-Anti-Spam-Result: A1DPAwCKoKtX/yNjr8ZdGgEBAQGDJ4FStxqEDIYdAoFfTAEBAQEBAV6FBgIEJ1IQIDFXBxKIMcISAQEBAQYCASSIKoxoBY8Oii6PEgKPQZAsVIISHIFsHDIBh1ABAQE X-IPAS-Result: A1DPAwCKoKtX/yNjr8ZdGgEBAQGDJ4FStxqEDIYdAoFfTAEBAQEBAV6FBgIEJ1IQIDFXBxKIMcISAQEBAQYCASSIKoxoBY8Oii6PEgKPQZAsVIISHIFsHDIBh1ABAQE X-IronPort-AV: E=Sophos;i="5.28,502,1464667200"; d="scan'208";a="5637699" 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; 10 Aug 2016 17:51:30 -0400 IronPort-PHdr: =?us-ascii?q?9a23=3Al+pNbR/AWRk9ef9uRHKM819IXTAuvvDOBiVQ1KB8?= =?us-ascii?q?1+4cTK2v8tzYMVDF4r011RmSDNyds6wP07qe8/i5HzdRudDZ6DFKWacPfidNsd?= =?us-ascii?q?8RkQ0kDZzNImzAB9muURYHGt9fXkRu5XCxPBsdMs//Y1rPvi/6tmZKSV3BPAZ4?= =?us-ascii?q?bt74BpTVx5zukbvjotuLPU4Q1HL9Oeo0d0Tu612J94E/ushLEu4J0BzHo39FKa?= =?us-ascii?q?x95FhDAhatpSv6/dq655V58i5d6LoL/s9EVrjmLexjFeQLRBxvCW0+5dXquB/f?= =?us-ascii?q?VkPPoyJECiRF2iZPVhPI6BD8Q4fZrjrxtu073jKTe8LxU/R8Wyup5r13Ejf0mS?= =?us-ascii?q?wHMHg/62iRhctuyOpArRunqwZ4woKRZICOKNJib6jdepUcXmMHUcFPE2RaDpiU?= =?us-ascii?q?c5oED+1HO/1R6Yb6uQggtxy7UBatAOfuwzoOjTns2qc3yfg6OQDAwAEkWdkJtS?= =?us-ascii?q?eH5O7pPbsfBLjmhJLDyi/OOrYPgW/w?= X-IronPort-Anti-Spam-Filtered: true X-IronPort-Anti-Spam-Result: =?us-ascii?q?A0HIBAAjoatX/yNjr8ZdGwEBAYMngVKnC?= =?us-ascii?q?ZARhAyGHQKBX0wBAQEBAQECAlongjIEARMBghQCBCdSECAxVwcSiDHCFAEBAQE?= =?us-ascii?q?GAQEBASOIKoxoBY8Oii6PEgKPQZAsVIISHIFsHDIBh1ABAQE?= X-IPAS-Result: =?us-ascii?q?A0HIBAAjoatX/yNjr8ZdGwEBAYMngVKnCZARhAyGHQKBX0w?= =?us-ascii?q?BAQEBAQECAlongjIEARMBghQCBCdSECAxVwcSiDHCFAEBAQEGAQEBASOIKoxoB?= =?us-ascii?q?Y8Oii6PEgKPQZAsVIISHIFsHDIBh1ABAQE?= X-IronPort-AV: E=Sophos;i="5.28,502,1464652800"; d="scan'208";a="18384158" Received: from fmsmga002-icc.fm.intel.com ([198.175.99.35]) by emsm-gh1-uea11.nsa.gov with ESMTP; 10 Aug 2016 21:51:28 +0000 Received: from orsmga001.jf.intel.com ([10.7.209.18]) by fmsmga002-icc.fm.intel.com with ESMTP; 10 Aug 2016 14:51:27 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos; i="5.28,502,1464678000"; d="scan'208"; a="1012165577" Received: from kamiles-mobl.amr.corp.intel.com (HELO wcrobert-MOBL1.amr.corp.intel.com) ([10.252.141.225]) by orsmga001.jf.intel.com with ESMTP; 10 Aug 2016 14:51:26 -0700 From: william.c.roberts@intel.com To: selinux@tycho.nsa.gov, jwcart2@tycho.nsa.gov, seandroid-list@tycho.nsa.gov, sds@tycho.nsa.gov Subject: [PATCH 3/5] ebitmap: detect invalid bitmap Date: Wed, 10 Aug 2016 14:51:20 -0700 Message-Id: <1470865882-22435-3-git-send-email-william.c.roberts@intel.com> X-Mailer: git-send-email 1.9.1 In-Reply-To: <1470865882-22435-1-git-send-email-william.c.roberts@intel.com> References: <1470865882-22435-1-git-send-email-william.c.roberts@intel.com> 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 --- libsepol/src/ebitmap.c | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/libsepol/src/ebitmap.c b/libsepol/src/ebitmap.c index 58f2fc4..fe8beb8 100644 --- a/libsepol/src/ebitmap.c +++ b/libsepol/src/ebitmap.c @@ -394,6 +394,10 @@ int ebitmap_read(ebitmap_t * e, void *fp) e->highbit, MAPSIZE); goto bad; } + + if (e->highbit && !count) + goto bad; + l = NULL; for (i = 0; i < count; i++) { rc = next_entry(buf, fp, sizeof(uint32_t));