From patchwork Tue Aug 16 17:28:33 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: 9284367 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 CBA8E600CB for ; Tue, 16 Aug 2016 18:07:44 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id C0C4C28642 for ; Tue, 16 Aug 2016 18:07:44 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id B556E2865C; Tue, 16 Aug 2016 18:07:44 +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 8BF4228642 for ; Tue, 16 Aug 2016 18:07:43 +0000 (UTC) X-IronPort-AV: E=Sophos;i="5.28,529,1464652800"; d="scan'208";a="16650007" IronPort-PHdr: =?us-ascii?q?9a23=3AVyreJxXIV+ExcU+XQpRhfOmodpzV8LGtZVwlr6E/?= =?us-ascii?q?grcLSJyIuqrYZxeOt8tkgFKBZ4jH8fUM07OQ6PG5HzVfqs/Z4ThCKMUKDE5dz5?= =?us-ascii?q?1O3kQJO42sMQXDNvnkbig3ToxpdWRO2DWFC3VTA9v0fFbIo3e/vnY4ExT7Mhdp?= =?us-ascii?q?dKyuQtaBx/q+2+36wZDPeQIA3GP7OuIrakzp5lyJ54FW2dIkcfdpjEOR4zNhQK?= =?us-ascii?q?d//StQP1WdnhLxtI+b3aVI1GBugc8n7NNKSq7gfq41HvRyBTUiNH0ptoWw7UGQ?= =?us-ascii?q?BTaV4jMgdkle0l8RW0mWpC39C4z8tir8q/pVxDiRPcqwS6s9Hzul8eMjSgDjgT?= =?us-ascii?q?0bbRYl4WrXjYp2l6sdrxW/41RkzofSbJuSNfY7eqLGYfsGVGFBWYBXTCUHDYSi?= =?us-ascii?q?K8MUA/EpIfdTr467oUAH6xS5G1qCHuTqnyBJgnv31Kh82KI7FgvLxhA7N9MIrH?= =?us-ascii?q?nQ6t7yMfRBGdupxbXFmG2QJ8hd3i3wvc2RKh0=3D?= X-IPAS-Result: =?us-ascii?q?A2GCBQD+VbNX/wHyM5BeGgEBAQGDJYFSpyaUFiOHXkwBAQE?= =?us-ascii?q?BAQEBAgECWyeCMgQDEYIVAgQBAiQTFCAOAwkBARcIIQgIAwEtFREHBwsFGASIE?= =?us-ascii?q?L5hDAEkiCqGXxEBhXcFjxKKL48ZAolrhViQMFSCEhyBbE4BhSqBNgEBAQ?= Received: from unknown (HELO tarius.tycho.ncsc.mil) ([144.51.242.1]) by emsm-gh1-uea10.nsa.gov with ESMTP; 16 Aug 2016 18:06:32 +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 u7GI5OcD012453; Tue, 16 Aug 2016 14:05: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 u7GHT8FU243295 for ; Tue, 16 Aug 2016 13:29:08 -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 u7GHT7Zk007907; Tue, 16 Aug 2016 13:29:08 -0400 X-IronPort-Anti-Spam-Filtered: true X-IronPort-Anti-Spam-Result: A1BvBQCWS7NX/yNjr8ZeGgEBAQGDJ4FStzqEDIYdAoFUTAEBAQEBAQECXoUGAgQnUhAgMVcHEogxvlQBAQEBBgIBJIgqjGgFjxKKL48ZAo9DkDBUghIcgWwcMgGHFgEBAQ X-IPAS-Result: A1BvBQCWS7NX/yNjr8ZeGgEBAQGDJ4FStzqEDIYdAoFUTAEBAQEBAQECXoUGAgQnUhAgMVcHEogxvlQBAQEBBgIBJIgqjGgFjxKKL48ZAo9DkDBUghIcgWwcMgGHFgEBAQ X-IronPort-AV: E=Sophos;i="5.28,529,1464667200"; d="scan'208";a="5648261" 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; 16 Aug 2016 13:29:00 -0400 IronPort-PHdr: =?us-ascii?q?9a23=3AeKuTqRG4R1oFBPD+Gd6fJJ1GYnF86YWxBRYc798d?= =?us-ascii?q?s5kLTJ74o8qwAkXT6L1XgUPTWs2DsrQf2rOQ6v+rADRRqdbZ6TZZIcQKD0dEwe?= =?us-ascii?q?wt3CUYSPafDkP6KPO4JwcbJ+9lEGFfwnegLEJOE9z/bVCB6le77DoVBwmtfVEt?= =?us-ascii?q?fre9JIfegoyN2vyo/NWLOkMT1WP7OOw5dU3n5UWJ749N0NMkcv5wgjLy4VJwM9?= =?us-ascii?q?xMwm1pIV/B1z3d3eyXuKBZziJLpvg6/NRBW6ipN44xTLhfESh0ezttvJ6jnVD5?= =?us-ascii?q?QACO/noRVHkN2loNWlCdrUKyYpCkqSb+t+xgyAGGLMb2SvYyQj3k4KB1DFfqly?= =?us-ascii?q?wOLSJj2H3Ggcx3yqRAqVSuoAI7i5XZaYeZLv1/cubZfMgGbXZQVcZWESpaC8Wz?= =?us-ascii?q?aJVLR/ENJs5EvoL9oB0IthL4Cg6yV831zTodmX7y2awz1qIqVxvB1gE6A8kmsX?= =?us-ascii?q?LIodGzP6AXArP997XB0TiWN6Ae4jz68oWdN0l5+fw=3D?= X-IronPort-Anti-Spam-Filtered: true X-IronPort-Anti-Spam-Result: =?us-ascii?q?A0FYBwBDTLNX/yNjr8ZeGwEBAYMngVKnJ?= =?us-ascii?q?pAUhAyGHQKBVEwBAQEBAQEBAgECWyeCMgQBEwGCFAIEJ1IQIDFXBxKIMb5UAQE?= =?us-ascii?q?BAQYBAQEBI4gqjGgFjxKKL48ZAo9DkDBUghIcgWwcMgGHFgEBAQ?= X-IPAS-Result: =?us-ascii?q?A0FYBwBDTLNX/yNjr8ZeGwEBAYMngVKnJpAUhAyGHQKBVEw?= =?us-ascii?q?BAQEBAQEBAgECWyeCMgQBEwGCFAIEJ1IQIDFXBxKIMb5UAQEBAQYBAQEBI4gqj?= =?us-ascii?q?GgFjxKKL48ZAo9DkDBUghIcgWwcMgGHFgEBAQ?= X-IronPort-AV: E=Sophos;i="5.28,529,1464652800"; d="scan'208";a="18515588" Received: from fmsmga002-icc.fm.intel.com ([198.175.99.35]) by emsm-gh1-uea11.nsa.gov with ESMTP; 16 Aug 2016 17:28:46 +0000 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos; i="5.28,529,1464678000"; d="scan'208"; a="1042217074" Received: from mtbauma1-mobl.amr.corp.intel.com (HELO wcrobert-MOBL1.amr.corp.intel.com) ([10.255.79.225]) by fmsmga002.fm.intel.com with ESMTP; 16 Aug 2016 10:28:40 -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 v4 3/7] ebitmap: detect invalid bitmap Date: Tue, 16 Aug 2016 10:28:33 -0700 Message-Id: <1471368517-20552-4-git-send-email-william.c.roberts@intel.com> X-Mailer: git-send-email 1.9.1 In-Reply-To: <1471368517-20552-1-git-send-email-william.c.roberts@intel.com> References: <1471368517-20552-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));