From patchwork Sun Jan 15 15:20:03 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: SF Markus Elfring X-Patchwork-Id: 9517509 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 59F86607D4 for ; Sun, 15 Jan 2017 15:20:23 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 4E71628383 for ; Sun, 15 Jan 2017 15:20:23 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 43623283E0; Sun, 15 Jan 2017 15:20:23 +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=-6.9 required=2.0 tests=BAYES_00,RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id C086828387 for ; Sun, 15 Jan 2017 15:20:22 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751186AbdAOPUV (ORCPT ); Sun, 15 Jan 2017 10:20:21 -0500 Received: from mout.web.de ([212.227.15.14]:50226 "EHLO mout.web.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1750831AbdAOPUU (ORCPT ); Sun, 15 Jan 2017 10:20:20 -0500 Received: from [192.168.1.2] ([78.49.147.199]) by smtp.web.de (mrweb002 [213.165.67.108]) with ESMTPSA (Nemesis) id 0MaafB-1c8mmF2SzZ-00KAmS; Sun, 15 Jan 2017 16:20:07 +0100 Subject: [PATCH 20/46] selinux: Move four assignments for the variable "rc" in range_read() To: linux-security-module@vger.kernel.org, selinux@tycho.nsa.gov, Eric Paris , James Morris , Paul Moore , "Serge E. Hallyn" , Stephen Smalley , William Roberts References: Cc: LKML , kernel-janitors@vger.kernel.org From: SF Markus Elfring Message-ID: <196aacb8-6aab-841b-3301-71da75628954@users.sourceforge.net> Date: Sun, 15 Jan 2017 16:20:03 +0100 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:45.0) Gecko/20100101 Thunderbird/45.6.0 MIME-Version: 1.0 In-Reply-To: X-Provags-ID: V03:K0:wfFef8guKVKFwpvQM40j7LTL1TTI3ATy602wfvXWnY/a1TXA79C 6AnLbwXqf3la7r+JxtlTtUe+cGY20m50jnxA82j78q0PtUmIyBMJZFcwO/T5Ck0pNsoQfD+ HM/rPXfi+puyFGr/8PaUqhWl0c2nj9g3T+Ua4JtjYJNdG+wSEheyfqcCEGmIGRn7WtmBc2J xl3TwcNlE7ri8B+XQ+4Og== X-UI-Out-Filterresults: notjunk:1; V01:K0:Ef15Bxflf2g=:73kX4Oip6jOa4+rCkqru0u sXI1J7Oec4Ydiwb0buqsuiSmAn1QXfHEznViWsQm+LgpK5RGf1qHYX4AEumqvkOjie5pcLreZ 6eNbr6V8xQJ5hjCk4/ZQrQo/zJI10KIdfZlcF0SHAKGh39GflgUkVGrFUGgzgrcI7kONP9qhy 0RzP/WDu/mh4UqSe+K0fA0IVtSP7B+itRIdqfm6AoEw2AEEpYNEA8hgR8MKFgD5hQvHcdsvw3 0sAiv/drURbR4T3ZlBB7iY5NBcpyeR57ZLKvsl4JdMWd3j2bi77DGqB9CSlFr0n3MJ0UaZpZh yfSiLaMFzInj60xdy8ZyWxykkwLGg4pcifxBks5kDjt4ua2WHe45kXD2nQVq9+e4ihHk6JPVw vijszu/CiRUsP4iWrq4VwahUDbBhgtBlpqagu6ljAqEUFNY1E1KwbPwElPsL68lWMRIw34MPp A7kFvTToDD4H9ZdrcOLi9k6EoFq9FAP+NTBLs0BsjGfALOH7EkHd98rF4n6xrjJtohZLSuvDR 6KEwuq2ZdRoYIirvqtY/bNWjL++ar2EdhBUtZVkzmoemPLc3+tq1oXcY5rk2VCWzenXfXBYZz FqgdaaVEV0r+R18z0Z5G4UAo73lI2BBkfbVuDUBsjeQpmlDfufQ4HVpLxSNnejI4Y96mMoXmD IcV1ZHEbLQpyavkvpPWeakch5qnppFhWTfbh9lzxDHGreznSpjkYf0C/LKlTNBDhw6d4yEkEL g50K62i3e/8pIxBKst0+0JkkgDa6nyQWh9EUrAIV39ZtoaaKd7aB2ROTu6D28TL/Y/eDpDtu0 Oz3Dvkd Sender: owner-linux-security-module@vger.kernel.org Precedence: bulk List-ID: X-Virus-Scanned: ClamAV using ClamSMTP From: Markus Elfring Date: Sat, 14 Jan 2017 19:55:00 +0100 One local variable was set to an error code in four cases before a concrete error situation was detected. Thus move the corresponding assignments into if branches to indicate a software failure there. Signed-off-by: Markus Elfring --- security/selinux/ss/policydb.c | 17 ++++++++++------- 1 file changed, 10 insertions(+), 7 deletions(-) diff --git a/security/selinux/ss/policydb.c b/security/selinux/ss/policydb.c index a696876fc327..4cd96ce51322 100644 --- a/security/selinux/ss/policydb.c +++ b/security/selinux/ss/policydb.c @@ -1854,10 +1854,11 @@ static int range_read(struct policydb *p, void *fp) nel = le32_to_cpu(buf[0]); for (i = 0; i < nel; i++) { - rc = -ENOMEM; rt = kzalloc(sizeof(*rt), GFP_KERNEL); - if (!rt) + if (!rt) { + rc = -ENOMEM; goto out; + } rc = next_entry(buf, fp, (sizeof(u32) * 2)); if (rc) @@ -1873,24 +1874,26 @@ static int range_read(struct policydb *p, void *fp) } else rt->target_class = p->process_class; - rc = -EINVAL; if (!policydb_type_isvalid(p, rt->source_type) || !policydb_type_isvalid(p, rt->target_type) || - !policydb_class_isvalid(p, rt->target_class)) + !policydb_class_isvalid(p, rt->target_class)) { + rc = -EINVAL; goto out; + } - rc = -ENOMEM; r = kzalloc(sizeof(*r), GFP_KERNEL); - if (!r) + if (!r) { + rc = -ENOMEM; goto out; + } rc = mls_read_range_helper(r, fp); if (rc) goto out; - rc = -EINVAL; if (!mls_range_isvalid(p, r)) { printk(KERN_WARNING "SELinux: rangetrans: invalid range\n"); + rc = -EINVAL; goto out; }