From patchwork Sun Jan 15 15:39:11 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: 9517585 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 ACABA6200C for ; Sun, 15 Jan 2017 15:39:31 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 9C4DD28387 for ; Sun, 15 Jan 2017 15:39:31 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 8EE68283AC; Sun, 15 Jan 2017 15:39: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=-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 3AB0028387 for ; Sun, 15 Jan 2017 15:39:31 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751266AbdAOPja (ORCPT ); Sun, 15 Jan 2017 10:39:30 -0500 Received: from mout.web.de ([212.227.15.3]:57383 "EHLO mout.web.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751098AbdAOPj3 (ORCPT ); Sun, 15 Jan 2017 10:39:29 -0500 Received: from [192.168.1.2] ([78.49.147.199]) by smtp.web.de (mrweb001 [213.165.67.108]) with ESMTPSA (Nemesis) id 0LgYi5-1cpU841co9-00nwYE; Sun, 15 Jan 2017 16:39:13 +0100 Subject: [PATCH 39/46] selinux: Move two assignments for the variable "rc" in ocontext_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: <1f2cc0bf-0904-0c9d-22f2-ee851214252e@users.sourceforge.net> Date: Sun, 15 Jan 2017 16:39:11 +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:y2ISkEFPuaex3pGkPHbPgHfLpiLr20e0GNjz9CwqqZj7CcQi7nZ oICea0QiVLoBqaA8NGgjmPEylpnMFy2T3AyOq6EW/F83sBe5+Rc7EuycoaF8RXBmXli4y+n cwpcHszVwTS52Kxb9FhJv2LxJSBJZQzkHwMdMHQH+HNWQxVDOOcZS6Fn+QkndomnNLaCnOZ LLKJe5379tT2xKnbkjekA== X-UI-Out-Filterresults: notjunk:1; V01:K0:W8LL9JfY9jw=:44IpSw1Z8QMSNMhcTpZTHh N6OcEUeDUtGTPew32XCvrclZCJeGEOte66uDevPRkXeXrFVvLH/tGb82BM5Wz1hVq36EBvBtI Xg2rnC8qtZqRK20PBgD7m97bYhRKRH+AgZv6CngrxX+zNwBAXWm0yoalgyrBb3q6+eDvvkJs5 NLIbCxupbxcrgcJ5nEDWEU+zRFqPnaNv2AJ3TEedkHchx1qV/mTDVYwUgeqRXJiL3raddx+VS INd9qA+5m9wvuEONE48fbvcTs5VgA/zgtrqBFXNhGtS0m1pmpKtUUMxN5TKDdm+a8di1A4JGj J6aG+s4gVqYcXLVFgC0kN3WQLfI3vtovBoHfOREI1Z+Bm5wumzrehagLlMyWyPu05kxQ2SeV7 ZB+yYEUUFLEgEP0dVWSzHckdZWBUTDPuPCeuGw877/VU4ZkX4CFSaUt1e4G7VyEua/ECIab4u TeXUD7T/0PdRfqnq7oaBeQI4V2l+5xvp8qHziDHEE5PIyt4KbTCOrVXEU9lbcB+aK//7gybA5 tq5VOCG6ihiD1TQXzZ6O5ExWKi0B0zqgkS8znMgrAImUOezOAtq07Zck6RvgBPrULs7x16oiJ nAr+/199SbbVQWIX0Zzt0Tu2Kbruo8CPsp09Tusi9OrEQ8NALoMizVHvh7e4cj+mdW++cMz6W jablqEsfwmxktsAAQVkTmt2koZJJaws++3EQzb80a/6ncG99THaes8OY8AbzL/1ZiD/o07TAB x/jlPaNTkyzmWeKi23+Idrp1OF9Wu0Xpb+ZGcUE9m9k7vVkYUbOlGrxdqkIR3mF6SE/acJGJL 5GCqRot Sender: owner-linux-security-module@vger.kernel.org Precedence: bulk List-ID: X-Virus-Scanned: ClamAV using ClamSMTP From: Markus Elfring Date: Sun, 15 Jan 2017 11:30:12 +0100 One local variable was set to an error code in two 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 | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/security/selinux/ss/policydb.c b/security/selinux/ss/policydb.c index 88730b372277..8b9ed3f1b132 100644 --- a/security/selinux/ss/policydb.c +++ b/security/selinux/ss/policydb.c @@ -2121,10 +2121,11 @@ static int ocontext_read(struct policydb *p, struct policydb_compat_info *info, l = NULL; for (j = 0; j < nel; j++) { - rc = -ENOMEM; c = kzalloc(sizeof(*c), GFP_KERNEL); - if (!c) + if (!c) { + rc = -ENOMEM; goto out; + } if (l) l->next = c; else @@ -2186,13 +2187,13 @@ static int ocontext_read(struct policydb *p, struct policydb_compat_info *info, if (rc) goto out; - rc = -EINVAL; c->v.behavior = le32_to_cpu(buf[0]); /* Determined at runtime, not in policy DB. */ - if (c->v.behavior == SECURITY_FS_USE_MNTPOINT) - goto out; - if (c->v.behavior > SECURITY_FS_USE_MAX) + if (c->v.behavior == SECURITY_FS_USE_MNTPOINT || + c->v.behavior > SECURITY_FS_USE_MAX) { + rc = -EINVAL; goto out; + } len = le32_to_cpu(buf[1]); rc = str_read(&c->u.name, GFP_KERNEL, fp, len);