From patchwork Mon Aug 15 15:59:14 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: 9281575 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 9FDEB600CB for ; Mon, 15 Aug 2016 16:42:54 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 8FF8428CD7 for ; Mon, 15 Aug 2016 16:42:54 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 8460C28DEC; Mon, 15 Aug 2016 16:42:54 +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 9DA4D28CD7 for ; Mon, 15 Aug 2016 16:42:53 +0000 (UTC) X-IronPort-AV: E=Sophos;i="5.28,526,1464652800"; d="scan'208";a="16602274" IronPort-PHdr: =?us-ascii?q?9a23=3AH71HTRf1XBLFyozAOFd3ySVdlGMj4u6mDksu8pMi?= =?us-ascii?q?zoh2WeGdxc+5bR7h7PlgxGXEQZ/co6odzbGH6ua5BCdZuczJ8ChbNscdD1ld0Y?= =?us-ascii?q?RetjdjKfbNMVf8Iv/uYn5yN+V5f3ghwUuGN1NIEt31fVzYry76xzcTHhLiKVg9?= =?us-ascii?q?fbytScbshsi6n9q/54fUK10RwmHsOPUrcV7v9V+Z9pFPx9AzcuBpklqBi0ALUt?= =?us-ascii?q?we/XlvK1OXkkS0zeaL17knzR5tvek8/dVLS6TwcvdwZ7VZCDM7LzJ9v5Wz5lH+?= =?us-ascii?q?Vw/H2l8wGiVTy0IJUED560ThU5PwtDbqnvZs0ymde8vtRPY7Xirmp6V0QxbylH?= =?us-ascii?q?0vKy8y8GaRjNd5yq1cvlbpvBF2xYLOZ4CZcf5/Zb/1YcIRRW0HWN1YESNGHMf0?= =?us-ascii?q?dIcUJ/YQNuZf6Y/mrh0BqgXtKxOrAbbwyztMh3bzm6Z8yeMrHBvaxyQhGc4DtD?= =?us-ascii?q?Lfq9CmZ+8pTempwfyQnn34ZPRM1GK4sdDF?= X-IPAS-Result: =?us-ascii?q?A2E4BwDF77FX/wHyM5BeGgEBAQGDJ4FSpxqUFiKHVEwBAQE?= =?us-ascii?q?BAQEBAgECWyeCMgQDEYIVAgQBAiQTFCAOAwkBARcIIQgIAwEtFREHBwsFGASIE?= =?us-ascii?q?L16AQoBAQEjiCqGXxEBhXcFjxCKLo8WAolqhVeQL1SEGk4BhW2BNgEBAQ?= Received: from unknown (HELO tarius.tycho.ncsc.mil) ([144.51.242.1]) by emsm-gh1-uea10.nsa.gov with ESMTP; 15 Aug 2016 16:41:00 +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 u7FGdFnX010012; Mon, 15 Aug 2016 12:39:44 -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 u7FFxdUW198310 for ; Mon, 15 Aug 2016 11:59:39 -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 u7FFxUNL005172; Mon, 15 Aug 2016 11:59:38 -0400 X-IronPort-Anti-Spam-Filtered: true X-IronPort-Anti-Spam-Result: A1DFBADi5bFX/yNjr8ZeGgEBAQGDJ4FSty2EDIYdAoFOTAEBAQEBAQECXoUGAgQnUhAgMVcHEogxvW0BAQEBAQEEAQEBASOIKoxoBY8Qii6PFgKPQZAvVIQaHDIBhyMBAQE X-IPAS-Result: A1DFBADi5bFX/yNjr8ZeGgEBAQGDJ4FSty2EDIYdAoFOTAEBAQEBAQECXoUGAgQnUhAgMVcHEogxvW0BAQEBAQEEAQEBASOIKoxoBY8Qii6PFgKPQZAvVIQaHDIBhyMBAQE X-IronPort-AV: E=Sophos;i="5.28,525,1464667200"; d="scan'208";a="5645659" 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; 15 Aug 2016 11:59:35 -0400 IronPort-PHdr: =?us-ascii?q?9a23=3AJvNIIBNBEwKSLwaIsRcl6mtUPXoX/o7sNwtQ0KIM?= =?us-ascii?q?zox0Kfj/rarrMEGX3/hxlliBBdydsKMdzbOL+PG7ESxYuNDa4ShEKMQNHzY+yu?= =?us-ascii?q?wu1zQ6B8CEDUCpZNXLVAcdWPp4aVl+4nugOlJUEsutL3fbo3m18CJAUk6nbVk9?= =?us-ascii?q?GO35F8bogtit0KjqotuIMlwO3Wf2MOg6bE3v616A7o9O2coqA51y4yOBmmFPde?= =?us-ascii?q?VSyDEgDnOotDG42P2N+oV++T9bofMr+p0Ie6z7e6MlUe4QV2x+YCgdrffmvhjb?= =?us-ascii?q?TAaJ+mBUEiBPykIJUED560ThU5PwtDbqnvZs0ymde8vtRPY7Xirmp6V0QxbylH?= =?us-ascii?q?0vKy8y8GaRjNd5yq1cvlbpvBF2xYLOZ4CZcf5/Zb/1YcIRRW0HWN1YESNGHMf0?= =?us-ascii?q?dIcUJ/YQNuZf6Y/mrh0BqgXtKxOrAbbwyztMh3bzm6Z8yeMrHBvaxyQhGc4DtD?= =?us-ascii?q?Lfq9CmZ+8pTempwfyQnn34ZPRM1GK4sdCQfw=3D=3D?= X-IronPort-Anti-Spam-Filtered: true X-IronPort-Anti-Spam-Result: =?us-ascii?q?A0FsCAAe5rFX/yNjr8ZeGwEBAYMngVKnG?= =?us-ascii?q?pAThAyGHQKBTkwBAQEBAQEBAgECWyeCMgQBEwGCFAIEJ1IQIDFXBxKIMb1uAQE?= =?us-ascii?q?BAQEBBAEBAQEBIogqjGgFjxCKLo8WAo9BkC9UhBocMgGHIwEBAQ?= X-IPAS-Result: =?us-ascii?q?A0FsCAAe5rFX/yNjr8ZeGwEBAYMngVKnGpAThAyGHQKBTkw?= =?us-ascii?q?BAQEBAQEBAgECWyeCMgQBEwGCFAIEJ1IQIDFXBxKIMb1uAQEBAQEBBAEBAQEBI?= =?us-ascii?q?ogqjGgFjxCKLo8WAo9BkC9UhBocMgGHIwEBAQ?= X-IronPort-AV: E=Sophos;i="5.28,525,1464652800"; d="scan'208";a="18475760" Received: from fmsmga002-icc.fm.intel.com ([198.175.99.35]) by emsm-gh1-uea11.nsa.gov with ESMTP; 15 Aug 2016 15:59:24 +0000 Received: from orsmga001.jf.intel.com ([10.7.209.18]) by fmsmga002-icc.fm.intel.com with ESMTP; 15 Aug 2016 08:59:20 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos; i="5.28,525,1464678000"; d="scan'208"; a="1014647712" Received: from hkramach-mobl1.amr.corp.intel.com (HELO wcrobert-MOBL1.amr.corp.intel.com) ([10.254.184.14]) by orsmga001.jf.intel.com with ESMTP; 15 Aug 2016 08:59:19 -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 v3 7/7] libsepol: fix unitialized jmp and invalid dereference Date: Mon, 15 Aug 2016 08:59:14 -0700 Message-Id: <1471276754-25266-8-git-send-email-william.c.roberts@intel.com> X-Mailer: git-send-email 1.9.1 In-Reply-To: <1471276754-25266-1-git-send-email-william.c.roberts@intel.com> References: <1471276754-25266-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 initializing role_datum_t array, initialize the array. This corrects this issue: ==25766== Conditional jump or move depends on uninitialised value(s) ==25766== at 0x40ABFE: context_is_valid (context.c:59) ==25766== by 0x40AAED: policydb_context_isvalid (context.c:19) ==25766== by 0x43CBF4: context_read_and_validate (policydb.c:1881) ==25766== by 0x43E7B3: ocontext_read_selinux (policydb.c:2631) ==25766== by 0x43EC4D: ocontext_read (policydb.c:2729) ==25766== by 0x442019: policydb_read (policydb.c:3937) ==25766== by 0x442F15: sepol_policydb_read (policydb_public.c:174) ==25766== by 0x407ED4: init (check_seapp.c:885) ==25766== by 0x408D83: main (check_seapp.c:1230) Also, check for NULL when determining if a role can be associated with a type. Signed-off-by: William Roberts --- libsepol/src/context.c | 2 +- libsepol/src/policydb.c | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/libsepol/src/context.c b/libsepol/src/context.c index 39552f2..a88937f 100644 --- a/libsepol/src/context.c +++ b/libsepol/src/context.c @@ -56,7 +56,7 @@ int context_is_valid(const policydb_t * p, const context_struct_t * c) * Role must be authorized for the type. */ role = p->role_val_to_struct[c->role - 1]; - if (!ebitmap_get_bit(&role->cache, c->type - 1)) + if (!role || !ebitmap_get_bit(&role->cache, c->type - 1)) /* role may not be associated with type */ return 0; diff --git a/libsepol/src/policydb.c b/libsepol/src/policydb.c index 9f1c507..c225ac6 100644 --- a/libsepol/src/policydb.c +++ b/libsepol/src/policydb.c @@ -1068,7 +1068,7 @@ int policydb_index_others(sepol_handle_t * handle, free(p->role_val_to_struct); p->role_val_to_struct = (role_datum_t **) - malloc(p->p_roles.nprim * sizeof(role_datum_t *)); + calloc(p->p_roles.nprim, sizeof(role_datum_t *)); if (!p->role_val_to_struct) return -1;