From patchwork Tue Aug 23 20:49:24 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: 9296333 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 9B7C860574 for ; Tue, 23 Aug 2016 21:04:18 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 7F90028D25 for ; Tue, 23 Aug 2016 21:04:18 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 7008C28D27; Tue, 23 Aug 2016 21:04:18 +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 A228F28D25 for ; Tue, 23 Aug 2016 21:04:17 +0000 (UTC) X-IronPort-AV: E=Sophos;i="5.28,567,1464652800"; d="scan'208";a="18701110" IronPort-PHdr: =?us-ascii?q?9a23=3AwmUQixEpOnzZGErxpAv8zp1GYnF86YWxBRYc798d?= =?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?A2EPBgAtubxX/wHyM5BdGgEBAQGDCwEBAQEBHoFSpWGUGyW?= =?us-ascii?q?HdEwBAQEBAQEBAgECWyeCMgQDE4IVAgQBAiQTFCAOAwkBARcIIQgIAwEtFREHB?= =?us-ascii?q?wsFGASIEL03AQoBAQEjiC2GXxEBhXcFjxWKM48hAoluhWCQOVSEGlABhFqBNgE?= =?us-ascii?q?BAQ?= Received: from unknown (HELO tarius.tycho.ncsc.mil) ([144.51.242.1]) by emsm-gh1-uea11.nsa.gov with ESMTP; 23 Aug 2016 21:04:14 +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 u7NKwE5H012122; Tue, 23 Aug 2016 16:58:16 -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 u7NKpMSr124173 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 u7NKpMFY011579; Tue, 23 Aug 2016 16:51:22 -0400 X-IronPort-Anti-Spam-Filtered: true X-IronPort-Anti-Spam-Result: A1DNBQCStrxX/yNjr8ZdGgEBAQGDCwEBAQEBHoFStXyEDIYdAoFuTAEBAQEBAQECXoUIAgQnUhAgMVcHEogxvUcBAQEBAQUBAQEBI4gtjGgFjxWKM48hAo9OkDlUhBpQAYYQAQEB X-IPAS-Result: A1DNBQCStrxX/yNjr8ZdGgEBAQGDCwEBAQEBHoFStXyEDIYdAoFuTAEBAQEBAQECXoUIAgQnUhAgMVcHEogxvUcBAQEBAQUBAQEBI4gtjGgFjxWKM48hAo9OkDlUhBpQAYYQAQEB X-IronPort-AV: E=Sophos;i="5.28,567,1464667200"; d="scan'208";a="5661315" 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:22 -0400 IronPort-PHdr: =?us-ascii?q?9a23=3Aj0S+3R/jXNQPnf9uRHKM819IXTAuvvDOBiVQ1KB8?= =?us-ascii?q?1+scTK2v8tzYMVDF4r011RmSDNydsK4P0raK++C4ACpbsM7H6ChDOLV3FDY9wf?= =?us-ascii?q?0MmAIhBMPXQWbaF9XNKxIAIcJZSVV+9Gu6O0UGUOz3ZlnVv2HgpWVKQka3CwN5?= =?us-ascii?q?K6zPF5LIiIzvjqbpqsSVOFkD3WbhKfMqdVPt/F2X7pFXyaJZaY8JgiPTpXVJf+?= =?us-ascii?q?kEjUhJHnm02yjG28Gr4ZR4+D5Rsf9yv+RJUKH9YrhqBecAVGduGykP6cbqrRjO?= =?us-ascii?q?SxeUrjtZCz1O00l+OA/f8Bz2ZJr6szOg/qohgGjJdfHxGKs5XTWk8rdDVA7jiC?= =?us-ascii?q?BBMSUwtm7QlIg4l69Sph67oB1zhorVe529KOt1fqSbe8gTA2VGQIIZTCBaKp+t?= =?us-ascii?q?ZIsISewaNKBXqJeuiUEJqE6hBA2oBerqjDQOnHj80LcmyMwgFx3L2EorGNdd4z?= =?us-ascii?q?zvsNzpOfJKAqiOx67SwGCGMatb?= X-IronPort-Anti-Spam-Filtered: true X-IronPort-Anti-Spam-Result: =?us-ascii?q?A0ETBwDMtrxX/yNjr8ZdGwEBAYMLAQEBA?= =?us-ascii?q?QEegVKlYZAbhAyGHQKBbkwBAQEBAQEBAgECWyeCMgQBFYIVAgQnUhAgMVcHEog?= =?us-ascii?q?xvUgBAQEBAQUBAQEBASKILYxoBY8VijOPIQKPTpA5VIQaUAGGEAEBAQ?= X-IPAS-Result: =?us-ascii?q?A0ETBwDMtrxX/yNjr8ZdGwEBAYMLAQEBAQEegVKlYZAbhAy?= =?us-ascii?q?GHQKBbkwBAQEBAQEBAgECWyeCMgQBFYIVAgQnUhAgMVcHEogxvUgBAQEBAQUBA?= =?us-ascii?q?QEBASKILYxoBY8VijOPIQKPTpA5VIQaUAGGEAEBAQ?= X-IronPort-AV: E=Sophos;i="5.28,567,1464652800"; d="scan'208";a="18700777" 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="752611578" 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 2/3] selinux: initialize structures Date: Tue, 23 Aug 2016 13:49:24 -0700 Message-Id: <1471985365-1197-2-git-send-email-william.c.roberts@intel.com> X-Mailer: git-send-email 1.9.1 In-Reply-To: <1471985365-1197-1-git-send-email-william.c.roberts@intel.com> References: <1471985365-1197-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 libsepol pointed out an issue where its possible to have an unitialized jmp and invalid dereference, fix this. While we're here, zero allocate all the *_val_to_struct structures. Signed-off-by: William Roberts --- security/selinux/ss/policydb.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/security/selinux/ss/policydb.c b/security/selinux/ss/policydb.c index 992a315..4b24385 100644 --- a/security/selinux/ss/policydb.c +++ b/security/selinux/ss/policydb.c @@ -541,21 +541,21 @@ static int policydb_index(struct policydb *p) rc = -ENOMEM; p->class_val_to_struct = - kmalloc(p->p_classes.nprim * sizeof(*(p->class_val_to_struct)), + kzalloc(p->p_classes.nprim * sizeof(*(p->class_val_to_struct)), GFP_KERNEL); if (!p->class_val_to_struct) goto out; rc = -ENOMEM; p->role_val_to_struct = - kmalloc(p->p_roles.nprim * sizeof(*(p->role_val_to_struct)), + kzalloc(p->p_roles.nprim * sizeof(*(p->role_val_to_struct)), GFP_KERNEL); if (!p->role_val_to_struct) goto out; rc = -ENOMEM; p->user_val_to_struct = - kmalloc(p->p_users.nprim * sizeof(*(p->user_val_to_struct)), + kzalloc(p->p_users.nprim * sizeof(*(p->user_val_to_struct)), GFP_KERNEL); if (!p->user_val_to_struct) goto out; @@ -964,7 +964,7 @@ int policydb_context_isvalid(struct policydb *p, struct context *c) * Role must be authorized for the type. */ role = p->role_val_to_struct[c->role - 1]; - if (!ebitmap_get_bit(&role->types, c->type - 1)) + if (!role || !ebitmap_get_bit(&role->types, c->type - 1)) /* role may not be associated with type */ return 0;