From patchwork Tue Aug 30 16:28:11 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: 9305659 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 BF3BA607F0 for ; Tue, 30 Aug 2016 16:31:31 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id AF62F28CA0 for ; Tue, 30 Aug 2016 16:31:31 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id A365328CB1; Tue, 30 Aug 2016 16:31:31 +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 6298928CA0 for ; Tue, 30 Aug 2016 16:31:29 +0000 (UTC) X-IronPort-AV: E=Sophos;i="5.30,257,1470700800"; d="scan'208";a="18865025" IronPort-PHdr: =?us-ascii?q?9a23=3AmCQB/Bf3bBoFNVF/tOG0zRBvlGMj4u6mDksu8pMi?= =?us-ascii?q?zoh2WeGdxc+/YR7h7PlgxGXEQZ/co6odzbGH6ua8BydZuc7J8ChbNscdD1ld0Y?= =?us-ascii?q?RetjdjKfbNMVf8Iv/uYn5yN+V5f3ghwUuGN1NIEt31fVzYry76xzcTHhLiKVg9?= =?us-ascii?q?fbytScbshsi6n9q/54fUK10RwmHsOPUucl7v9V2Z9pFPx9AzcuBpklqBi0ALUt?= =?us-ascii?q?we/XlvK1OXkkS0zeaL17knzR5tvek8/dVLS6TwcvdwZ7VZCDM7LzJ9v5Wz5lH+?= =?us-ascii?q?Vw/H2l8wGiVTy0IJUD7+6wvmU5vLvyD7rrA1mHXCfJ6+cbdhQjmm7qF2WDf0mS?= =?us-ascii?q?wHMHg/62iRhctuyOpArRunqwZ4woKRZICOKNJib6jdepUcXmMHUcFPE2RaDpiU?= =?us-ascii?q?c5oED+1HO/1R6Yb6uR9GtRKjASG0Df7rjzpPgWX7m6Y91rcPCwbDiRMhG9YPuX?= =?us-ascii?q?GSp5PvM60fS/yu5KjO0TjHKfhR3GSuoLPUewws9KnfFYl7dtDcnBJ3Gg=3D=3D?= X-IPAS-Result: =?us-ascii?q?A2H0BACGs8VX/wHyM5BcGwEBAQMBAQEXAQEEAQGDCgEBAQE?= =?us-ascii?q?BHoFTpgSUJCOHZEwBAQEBAQEBAQIBAlsngjIEAwMVghgCNxQgDgMJAhcIIQgIA?= =?us-ascii?q?wEtFRgHCwUYBIgjvi4BJIguhl8RAYV4BY8aijaPLgKJcIVlkEFUgkccgW1QAYR?= =?us-ascii?q?MeIEnAQEB?= Received: from unknown (HELO tarius.tycho.ncsc.mil) ([144.51.242.1]) by emsm-gh1-uea11.nsa.gov with ESMTP; 30 Aug 2016 16:31:03 +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 u7UGU3fP016584; Tue, 30 Aug 2016 12:30:13 -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 u7UGSHwV104763 for ; Tue, 30 Aug 2016 12:28:17 -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 u7UGSHke015964; Tue, 30 Aug 2016 12:28:17 -0400 X-IronPort-Anti-Spam-Filtered: true X-IronPort-Anti-Spam-Result: A1AeBgCqs8VX/yNjr8ZcGwEBAQMBAQGDKQEBAQEBHoFTtiKEEBSGCYFgTAECAQEBAQECXoYIMIEPEohEviIBAQgniC6MaQWPGoo2jy4CiXCFZZBBVIJHHIFtUAGGawEBAQ X-IPAS-Result: A1AeBgCqs8VX/yNjr8ZcGwEBAQMBAQGDKQEBAQEBHoFTtiKEEBSGCYFgTAECAQEBAQECXoYIMIEPEohEviIBAQgniC6MaQWPGoo2jy4CiXCFZZBBVIJHHIFtUAGGawEBAQ X-IronPort-AV: E=Sophos;i="5.30,257,1470715200"; d="scan'208";a="5673009" 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; 30 Aug 2016 12:28:17 -0400 IronPort-PHdr: =?us-ascii?q?9a23=3AYpyl1hyVfTSSly3XCy+O+j09IxM/srCxBDY+r6Qd?= =?us-ascii?q?0OwWIJqq85mqBkHD//Il1AaPBtSCra4awLuJ++C4ACpbsM7H6ChDOLV3FDY9wf?= =?us-ascii?q?0MmAIhBMPXQWbaF9XNKxIAIcJZSVV+9Gu6O0UGUOz3ZlnVv2HgpWVKQka3CwN5?= =?us-ascii?q?K6zPF5LIiIzvjqbpqsSVP1sD1WX1Iesrak7n9UOJ7oheqLAhA5558gHOrHpMdr?= =?us-ascii?q?Ye7kJTDnXXoSzB4Nyt9oVo6SVatqFp3cdBVaLnY/ZwFuQAX3wOelo478zztBTF?= =?us-ascii?q?URDHpj5FCj1XwSxzBBLZ4R3AU5zwqnGy9rYlmXrSAcqjVr0wWDK//493WRToj2?= =?us-ascii?q?EBLDd//2bJzoRrgatdrAimphA6x4/PfKmJJfF+eeXbZtpcSm1fGo5KWzdpHpK3?= =?us-ascii?q?b4xJCfEIe+lfsc21v1ITqTOmDBSoQebozSVFwHTx2P4UyeMkRB7H2AghFtdIuz?= =?us-ascii?q?LOq9/4LrsJeeGz0KTMiz7EaqAFkQzh4ZTFJ0hy6cqHWqh9JI+PkUQ=3D?= X-IronPort-Anti-Spam-Filtered: true X-IronPort-Anti-Spam-Result: =?us-ascii?q?A0HyBACGs8VX/yNjr8ZcGwEBAQMBAQEWA?= =?us-ascii?q?QEBAwEBAYMKAQEBAQEegVOmBJAehBAUhgmBYEwBAQEBAQEBAQIBAlsngjIEARU?= =?us-ascii?q?FgxAwgQ8SiES+IgEBCAIliC6MaQWPGoo2jy4CiXCFZZBBVIJHHIFtUAGFK4FAA?= =?us-ascii?q?QEB?= X-IPAS-Result: =?us-ascii?q?A0HyBACGs8VX/yNjr8ZcGwEBAQMBAQEWAQEBAwEBAYMKAQE?= =?us-ascii?q?BAQEegVOmBJAehBAUhgmBYEwBAQEBAQEBAQIBAlsngjIEARUFgxAwgQ8SiES+I?= =?us-ascii?q?gEBCAIliC6MaQWPGoo2jy4CiXCFZZBBVIJHHIFtUAGFK4FAAQEB?= X-IronPort-AV: E=Sophos;i="5.30,257,1470700800"; d="scan'208";a="18864840" Received: from fmsmga002-icc.fm.intel.com ([198.175.99.35]) by emsm-gh1-uea11.nsa.gov with ESMTP; 30 Aug 2016 16:28:15 +0000 Received: from fmsmga001-icc.fm.intel.com ([198.175.99.7]) by fmsmga002-icc.fm.intel.com with ESMTP; 30 Aug 2016 09:28:14 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos; i="5.30,257,1470726000"; d="scan'208"; a="1033232033" Received: from unknown (HELO wcrobert-MOBL1.amr.corp.intel.com) ([10.255.81.153]) by fmsmga001.fm.intel.com with ESMTP; 30 Aug 2016 09:28:14 -0700 From: william.c.roberts@intel.com To: selinux@tycho.nsa.gov, seandroid-list@tycho.nsa.gov, sds@tycho.nsa.gov, paul@paul-moore.com Subject: [PATCH v2] selinux: fix overflow and 0 length allocations Date: Tue, 30 Aug 2016 09:28:11 -0700 Message-Id: <1472574491-31233-1-git-send-email-william.c.roberts@intel.com> X-Mailer: git-send-email 1.9.1 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 Throughout the SE Linux LSM, values taken from sepolicy are used in places where length == 0 or length == matter, find and fix these. Signed-off-by: William Roberts --- security/selinux/ss/conditional.c | 2 ++ security/selinux/ss/policydb.c | 3 +++ 2 files changed, 5 insertions(+) diff --git a/security/selinux/ss/conditional.c b/security/selinux/ss/conditional.c index 456e1a9..34afead 100644 --- a/security/selinux/ss/conditional.c +++ b/security/selinux/ss/conditional.c @@ -242,6 +242,8 @@ int cond_read_bool(struct policydb *p, struct hashtab *h, void *fp) goto err; len = le32_to_cpu(buf[2]); + if (((len == 0) || (len == (u32)-1))) + goto err; rc = -ENOMEM; key = kmalloc(len + 1, GFP_KERNEL); diff --git a/security/selinux/ss/policydb.c b/security/selinux/ss/policydb.c index 4b24385..8c661f0 100644 --- a/security/selinux/ss/policydb.c +++ b/security/selinux/ss/policydb.c @@ -1094,6 +1094,9 @@ static int str_read(char **strp, gfp_t flags, void *fp, u32 len) int rc; char *str; + if ((len == 0) || (len == (u32)-1)) + return -EINVAL; + str = kmalloc(len + 1, flags); if (!str) return -ENOMEM;