From patchwork Sun Jan 15 15:13:06 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: 9517481 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 303DC607D4 for ; Sun, 15 Jan 2017 15:13:24 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 24E4428488 for ; Sun, 15 Jan 2017 15:13:24 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 19CB028496; Sun, 15 Jan 2017 15:13:24 +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 B484728488 for ; Sun, 15 Jan 2017 15:13:23 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751117AbdAOPNW (ORCPT ); Sun, 15 Jan 2017 10:13:22 -0500 Received: from mout.web.de ([212.227.15.3]:55720 "EHLO mout.web.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751084AbdAOPNV (ORCPT ); Sun, 15 Jan 2017 10:13:21 -0500 Received: from [192.168.1.2] ([78.49.147.199]) by smtp.web.de (mrweb002 [213.165.67.108]) with ESMTPSA (Nemesis) id 0Letgd-1cmkRu1FdP-00qhm5; Sun, 15 Jan 2017 16:13:09 +0100 Subject: [PATCH 13/46] selinux: Move four assignments for the variable "rc" in genfs_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: <99ebe15e-c30f-d129-82a0-a809769aa5dc@users.sourceforge.net> Date: Sun, 15 Jan 2017 16:13:06 +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:BXrLdmw0j4K6kXLYRt+q3WkiPXj6PQfK21+i1KqQQw8jO5pFvj/ sOHJa3Wn1hnZdNaEwZtNLGms3k5kBqRvEqTUvtx/zcfxG4IvppHky9wmVNfLZQNpE9VFpMd +Hu8o/YuRpdnAvVQrBnob2fN0xptcf8epKREMJy2eg1JKZyN+t9hQJ/FHRq53anK+vrOph0 4IIoGlzJFNQ9F3BVek5Yw== X-UI-Out-Filterresults: notjunk:1; V01:K0:XXExYv0skjY=:pNSKJav/rbspQY6hwYPlyq hPIMEgeD4sGNzULUDjtj7w6iJW9p1QozUsnUCZbGDb54HXcJI/9GjiTLquLzmrjdwATANZwaK a4mun7WD2OO7BPyU6R35MWoVrjU1Ww7F1VhBl00eEuKbmk6nndrjskQGCceE/tmAxWz00S3a3 Li5lnd+EahgwdD4nHjq99Rt7wAK+Rf45XeW4rNsuTvzDYhnbCpjbWxMA2kHeG0o52RMaN9o5u jHjKOqQyHayd2M9VDU19ckFi6gfFWr7m6TEh92MVtS9fpbv/0DxeYemrLTd178SntF6uy0cGD 4EUQW19a3qLJxAqCSIOpw1Mg9nilv39V/1an/AHBtOPPpeHo2zbpioe0jDhup05N5ikfuUaLA jKU7/L4HwHhHFavoXTH3yw9QmkepesrV/+C2b8eadFHBcsK7g1+ysrb7mxYd4+ufXQpEHArPB fJlhtoHODUYqKLTtr1Ir1cf4p7x9Xyd8qQBwWxp7bM6RSARaQLMdpf2cNKDrMYgAzPwyEpLnn b4+6TAupJ6Uqrfz4f15hlrf7zKVyB1XPKuU/4uJ+wBR9bh3+9CJnpwuw4b+xeuc4cs17u82hm oceWbzV9EmLOSgEevdK3DoTOKabpM0Vf9+Ueteyi+R2MKFwQAJCRn8qwkLNOVa3br38OvyUNO eLnFU6veXCsK7rC6+v5Tnq6tA61pQC9l4Uu6OgY16AeGgNQg4Xr5wGdZMnR6ewdXCZBEhPimo nA4BpFK60+vQrJGgru7gjQUkmQS68U+4DFCrsDLzsDlJaxvi5YyT6PX+qRcM1JIjUX2UHjQ6K pO39KpW 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 17:21:59 +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 | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/security/selinux/ss/policydb.c b/security/selinux/ss/policydb.c index 7544e374dec9..a12d9166f0e4 100644 --- a/security/selinux/ss/policydb.c +++ b/security/selinux/ss/policydb.c @@ -2012,11 +2012,11 @@ static int genfs_read(struct policydb *p, void *fp) if (rc) goto out; len = le32_to_cpu(buf[0]); - - rc = -ENOMEM; newgenfs = kzalloc(sizeof(*newgenfs), GFP_KERNEL); - if (!newgenfs) + if (!newgenfs) { + rc = -ENOMEM; goto out; + } rc = str_read(&newgenfs->fstype, GFP_KERNEL, fp, len); if (rc) @@ -2024,10 +2024,10 @@ static int genfs_read(struct policydb *p, void *fp) for (genfs_p = NULL, genfs = p->genfs; genfs; genfs_p = genfs, genfs = genfs->next) { - rc = -EINVAL; if (strcmp(newgenfs->fstype, genfs->fstype) == 0) { printk(KERN_ERR "SELinux: dup genfs fstype %s\n", newgenfs->fstype); + rc = -EINVAL; goto out; } if (strcmp(newgenfs->fstype, genfs->fstype) < 0) @@ -2051,11 +2051,11 @@ static int genfs_read(struct policydb *p, void *fp) if (rc) goto out; len = le32_to_cpu(buf[0]); - - rc = -ENOMEM; newc = kzalloc(sizeof(*newc), GFP_KERNEL); - if (!newc) + if (!newc) { + rc = -ENOMEM; goto out; + } rc = str_read(&newc->u.name, GFP_KERNEL, fp, len); if (rc) @@ -2072,12 +2072,12 @@ static int genfs_read(struct policydb *p, void *fp) for (l = NULL, c = genfs->head; c; l = c, c = c->next) { - rc = -EINVAL; if (!strcmp(newc->u.name, c->u.name) && (!c->v.sclass || !newc->v.sclass || newc->v.sclass == c->v.sclass)) { printk(KERN_ERR "SELinux: dup genfs entry (%s,%s)\n", genfs->fstype, c->u.name); + rc = -EINVAL; goto out; } len = strlen(newc->u.name);