From patchwork Tue Aug 16 17:28:36 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: 9284397 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 35EFB60574 for ; Tue, 16 Aug 2016 18:20:35 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 296AA28622 for ; Tue, 16 Aug 2016 18:20:35 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 1DFD3286CA; Tue, 16 Aug 2016 18:20:35 +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 5F0F128622 for ; Tue, 16 Aug 2016 18:20:34 +0000 (UTC) X-IronPort-AV: E=Sophos;i="5.28,529,1464652800"; d="scan'208";a="18518295" IronPort-PHdr: =?us-ascii?q?9a23=3AdbB3MxDlLGvUhWS9tfuNUyQJP3N1i/DPJgcQr6Af?= =?us-ascii?q?oPdwSP/4rsbcNUDSrc9gkEXOFd2CrakV0qyP7Ou5AT1Ioc7Y9itTKNoUD15NoP?= =?us-ascii?q?5VtjRoONSCB0z/IayiRA0BN+MGamVY+WqmO1NeAsf0ag6aiHSz6TkPBke3blIt?= =?us-ascii?q?dazLE4Lfx/66y/q1s8WKJV4Z3XzkPvgrdET+7V2I8JJH2c06cud54yCKi0MAQ/?= =?us-ascii?q?5Ry2JsKADbtDfHzeD0wqRe9T9Nsekq7c9KXPayVa05SbtFEGZuaDhtt4XWrx2L?= =?us-ascii?q?cS+jrjtZCz1XwVJ0BF3e4RX7WIrhmjfrvep6ni+BNIv5Sq5wETa95K5xVEXAlD?= =?us-ascii?q?YMNzl/9nrezMN3kuYTux+ooRBlxI/YJYWUL+ZWYrLWfdRcQ3FIGMlWSWgJGY+n?= =?us-ascii?q?R5ceBOoGe+BDps/yoEVdgwG5AFyzBefryzZNwHSwx6ow3v49CinH2hAtG5QFt3?= =?us-ascii?q?GH/53OKK4OXLXtn+HzxjLZYqYTgG/w?= X-IPAS-Result: =?us-ascii?q?A2GCBQArWbNX/wHyM5BeGgEBAQGDJYFSpyaUFyKHXkwBAQE?= =?us-ascii?q?BAQEBAgECWyeCMgQDEYIVAgQBAiQTFCAOAwkBARcIIQgIAwEtFREHBwsFGASIE?= =?us-ascii?q?L5iAQoBAQEjiCqGXxEBhXcFjxKKL48ZAolrhViQMFSEGk4BhSqBNgEBAQ?= Received: from unknown (HELO tarius.tycho.ncsc.mil) ([144.51.242.1]) by emsm-gh1-uea11.nsa.gov with ESMTP; 16 Aug 2016 18:20:02 +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 u7GIJVED013883; Tue, 16 Aug 2016 14:19:38 -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 u7GHTGF3243305 for ; Tue, 16 Aug 2016 13:29:16 -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 u7GHTFxY007939; Tue, 16 Aug 2016 13:29:15 -0400 X-IronPort-Anti-Spam-Filtered: true X-IronPort-Anti-Spam-Result: A1BvBQCWS7NX/yNjr8ZeGgEBAQGDJ4FStzqEDIYdAoFUTAEBAQEBAQECXoUGAgQnUhAgMVcHEogxvlQBAQEBAQEEAQEBASOIKoxoBY8Sii+PGQKPQ5AwVIQaHDIBhxYBAQE X-IPAS-Result: A1BvBQCWS7NX/yNjr8ZeGgEBAQGDJ4FStzqEDIYdAoFUTAEBAQEBAQECXoUGAgQnUhAgMVcHEogxvlQBAQEBAQEEAQEBASOIKoxoBY8Sii+PGQKPQ5AwVIQaHDIBhxYBAQE X-IronPort-AV: E=Sophos;i="5.28,529,1464667200"; d="scan'208";a="5648264" 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:09 -0400 IronPort-PHdr: =?us-ascii?q?9a23=3A180yRRAHxOlTgCWnLn5rUyQJP3N1i/DPJgcQr6Af?= =?us-ascii?q?oPdwSP//ocbcNUDSrc9gkEXOFd2CrakV0qyP7Ou5AT1Ioc7Y9itTKNoUD15NoP?= =?us-ascii?q?5VtjRoONSCB0z/IayiRA0BN+MGamVY+WqmO1NeAsf0ag6aiHSz6TkPBke3blIt?= =?us-ascii?q?dazLE4Lfx/66y/q1s8WKJV4Z3XzkPvgrdET+7V2I8JJH2c06cud54yCKi0MAQ/?= =?us-ascii?q?5Ry2JsKADbtDfHzeD0wqRe9T9Nsekq7c9KXPayVa05SbtFEGZuaDhtt4XD/CPO?= =?us-ascii?q?RgqX53YaTn5e0l8RW1CEv1nGWcLqvy/7sPdt8DWLNs3xC7YvUHKt6LkvAB33gy?= =?us-ascii?q?4dK2QR7HDciss2irlS5h2muVg32IPdZo2PM/tyO6fcZs8yWXtKXsEXUTdIRIy7?= =?us-ascii?q?cc9HFOYaFfpJpIn64V0VpF2xAhf/Kvnoz2pXh3vy3KQ/le9nCwbM0RY8BPoPtm?= =?us-ascii?q?jZqJP+M6JBAqiO0KDUwGCbPLtt0jDn5d2NK0h5rA=3D=3D?= X-IronPort-Anti-Spam-Filtered: true X-IronPort-Anti-Spam-Result: =?us-ascii?q?A0FYBwBDTLNX/yNjr8ZeGwEBAYMngVKnJ?= =?us-ascii?q?pAUhAyGHQKBVEwBAQEBAQEBAgECWyeCMgQBEwGCFAIEJ1IQIDFXBxKIMb5UAQE?= =?us-ascii?q?BAQEBBAEBAQEBIogqjGgFjxKKL48ZAo9DkDBUhBocMgGHFgEBAQ?= X-IPAS-Result: =?us-ascii?q?A0FYBwBDTLNX/yNjr8ZeGwEBAYMngVKnJpAUhAyGHQKBVEw?= =?us-ascii?q?BAQEBAQEBAgECWyeCMgQBEwGCFAIEJ1IQIDFXBxKIMb5UAQEBAQEBBAEBAQEBI?= =?us-ascii?q?ogqjGgFjxKKL48ZAo9DkDBUhBocMgGHFgEBAQ?= X-IronPort-AV: E=Sophos;i="5.28,529,1464652800"; d="scan'208";a="18515596" Received: from fmsmga002-icc.fm.intel.com ([198.175.99.35]) by emsm-gh1-uea11.nsa.gov with ESMTP; 16 Aug 2016 17:28:48 +0000 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos; i="5.28,529,1464678000"; d="scan'208"; a="1042217089" 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:41 -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 6/7] libsepol: fix unitialized jmp and invalid dereference Date: Tue, 16 Aug 2016 10:28:36 -0700 Message-Id: <1471368517-20552-7-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 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 84dad34..420ee16 100644 --- a/libsepol/src/context.c +++ b/libsepol/src/context.c @@ -55,7 +55,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 b8f6ca8..60761b7 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;