From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751405AbdAOPjc (ORCPT ); Sun, 15 Jan 2017 10:39:32 -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 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: Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 7bit 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: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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); -- 2.11.0 From mboxrd@z Thu Jan 1 00:00:00 1970 From: SF Markus Elfring Date: Sun, 15 Jan 2017 15:39:11 +0000 Subject: [PATCH 39/46] selinux: Move two assignments for the variable "rc" in ocontext_read() Message-Id: <1f2cc0bf-0904-0c9d-22f2-ee851214252e@users.sourceforge.net> List-Id: References: In-Reply-To: MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit To: linux-security-module@vger.kernel.org, selinux@tycho.nsa.gov, Eric Paris , James Morris , Paul Moore , "Serge E. Hallyn" , Stephen Smalley , William Roberts Cc: LKML , kernel-janitors@vger.kernel.org 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); -- 2.11.0