Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752273AbdHMOrQ (ORCPT ); Sun, 13 Aug 2017 10:47:16 -0400 Received: from mout.web.de ([212.227.15.14]:59761 "EHLO mout.web.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751344AbdHMOrN (ORCPT ); Sun, 13 Aug 2017 10:47:13 -0400 Subject: [PATCH 2/4] selinux: Adjust jump targets in ebitmap_read() From: SF Markus Elfring To: linux-security-module@vger.kernel.org, selinux@tycho.nsa.gov, Alexey Dobriyan , Daniel Jurgens , Eric Paris , James Morris , Junil Lee , Paul Moore , "Serge E. Hallyn" , Stephen Smalley , William Roberts Cc: LKML , kernel-janitors@vger.kernel.org References: Message-ID: <2c4582c9-efc1-4b8c-1095-84e00062c7de@users.sourceforge.net> Date: Sun, 13 Aug 2017 16:46:53 +0200 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:52.0) Gecko/20100101 Thunderbird/52.2.1 MIME-Version: 1.0 In-Reply-To: Content-Type: text/plain; charset=utf-8 Content-Language: en-GB Content-Transfer-Encoding: 7bit X-Provags-ID: V03:K0:O2544z3KnxrYEwqOKpajpSthAf+ij3faTbCy7o+4wonLDUcPgcl hCjW827/+WPFByW7RQV9mnH8SkmbRr6lnV7JKRUn8MqeNdTJxW81e6rzbpCid1+B6v/BsVR 2JSXPKkxw5ebxqadlRTXN8VWFND4gffOTDaCpUGxGHHu7qpVPBcGWHipjrEke+5xultX4op yGZ1pN44eAbHIKx2LRWoQ== X-UI-Out-Filterresults: notjunk:1;V01:K0:wC3AZ/yp0F8=:vXEyHeC4Xuymld6PSveKSi KtWKUTV+XLw1I0I27n1HPjO+JERoknP6Etr/QBy4K7EdS7eNTUnKeI9J4lMBh8AA0cvqRMVr4 jL3TXe962qk8ck6tdJOq+TgKdpF9GhlYAkyqC0NZhzo/Yo8INyfRdOOMK9cYq+ZDqGJBq5YHL N+fm42tUZelHwF0hUfabq16MA6Xb2JYh3hcaasadJ73jtKOb4A8yX7ou2qBWEHKtZtP5Dgtiw TOfMWR2BixG9OSjzZMhKBwnF3ykuuIwDXObHTqSWn+Bxk7FJlFUwQbpgYSpB5l5HB7cplx18l Go39yL2WkrWDzyOp3Nmvds7WrqYCP0+iFoarWeQrVpfdGij8SMu2TEpR3GwzNqE87tNfLdVUU byFQ3HTbdj3Vyv6y+GnjBcmVsKjgRjMyhOXf1Rc8kIzTdab/nswsQkBdiwWr7sdGVV/Issx8z h9St5P4Mk6pel3AuB2zkB2bGOFVxaf7khAyoUC0Me47NKAoHCPK3QCZ79lUeNtW4VHT/HjN+A 6fJl3rg0L1q33wa/8aNR0x2poHZedKEB90SacZKZqtBZzpiXyoOdNfJwGpz4Q9rDQTXcB1OqU WTvUDOLKcXBNWxJDxIRyETQlWFVBSmEbHDjN7zt5cTV7SiMzFbxhSTKsLyOh0rb8CF89byZwU CtbkjvtDV/l53jXZ/lemcNS86FEZe+EVNoaafgthgycK7urotxg1i84gbbXkLMxzMBP0grPmZ AYroHZ3i6mqQ0ykKVXJEBt6G+aYjEpHKxdo3COGzScksTOXVWO12W+1PDboAXuVxVjTCECjyw yrz3pRZXVzXQCqVIdH2MPxvq+I9H/O8w/yloBr6gC8uz5PP3s0= Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Length: 3275 Lines: 121 From: Markus Elfring Date: Sun, 13 Aug 2017 15:21:43 +0200 Adjust jump targets so that the function implementation becomes smaller. * Move an error message so that it is present only once here. * Avoid another check for the local variable "rc" at the end. Signed-off-by: Markus Elfring --- security/selinux/ss/ebitmap.c | 38 ++++++++++++++++++-------------------- 1 file changed, 18 insertions(+), 20 deletions(-) diff --git a/security/selinux/ss/ebitmap.c b/security/selinux/ss/ebitmap.c index ccf372db689c..03581d7ef817 100644 --- a/security/selinux/ss/ebitmap.c +++ b/security/selinux/ss/ebitmap.c @@ -350,21 +350,20 @@ int ebitmap_read(struct ebitmap *e, void *fp) __le32 buf[3]; int rc, i; - ebitmap_init(e); - rc = next_entry(buf, fp, sizeof buf); if (rc < 0) goto out; - mapunit = le32_to_cpu(buf[0]); + ebitmap_init(e); e->highbit = le32_to_cpu(buf[1]); count = le32_to_cpu(buf[2]); + mapunit = le32_to_cpu(buf[0]); if (mapunit != BITS_PER_U64) { printk(KERN_ERR "SELinux: ebitmap: map size %u does not " "match my size %zd (high bit was %d)\n", mapunit, BITS_PER_U64, e->highbit); - goto bad; + goto destroy_bitmap; } /* round up e->highbit */ @@ -377,27 +376,26 @@ int ebitmap_read(struct ebitmap *e, void *fp) } if (e->highbit && !count) - goto bad; + goto destroy_bitmap; for (i = 0; i < count; i++) { rc = next_entry(&startbit, fp, sizeof(u32)); - if (rc < 0) { - printk(KERN_ERR "SELinux: ebitmap: truncated map\n"); - goto bad; - } + if (rc) + goto report_truncated_map; + startbit = le32_to_cpu(startbit); if (startbit & (mapunit - 1)) { printk(KERN_ERR "SELinux: ebitmap start bit (%d) is " "not a multiple of the map unit size (%u)\n", startbit, mapunit); - goto bad; + goto destroy_bitmap; } if (startbit > e->highbit - mapunit) { printk(KERN_ERR "SELinux: ebitmap start bit (%d) is " "beyond the end of the bitmap (%u)\n", startbit, (e->highbit - mapunit)); - goto bad; + goto destroy_bitmap; } if (!n || startbit >= n->startbit + EBITMAP_SIZE) { @@ -407,7 +405,7 @@ int ebitmap_read(struct ebitmap *e, void *fp) printk(KERN_ERR "SELinux: ebitmap: out of memory\n"); rc = -ENOMEM; - goto bad; + goto destroy_bitmap; } /* round down */ tmp->startbit = startbit - (startbit % EBITMAP_SIZE); @@ -420,14 +418,13 @@ int ebitmap_read(struct ebitmap *e, void *fp) printk(KERN_ERR "SELinux: ebitmap: start bit %d" " comes after start bit %d\n", startbit, n->startbit); - goto bad; + goto destroy_bitmap; } rc = next_entry(&map, fp, sizeof(u64)); - if (rc < 0) { - printk(KERN_ERR "SELinux: ebitmap: truncated map\n"); - goto bad; - } + if (rc) + goto report_truncated_map; + map = le64_to_cpu(map); index = (startbit - n->startbit) / EBITMAP_UNIT_SIZE; @@ -438,9 +435,10 @@ int ebitmap_read(struct ebitmap *e, void *fp) } out: return rc; -bad: - if (!rc) - rc = -EINVAL; +report_truncated_map: + printk(KERN_ERR "SELinux: ebitmap: truncated map\n"); + rc = -EINVAL; +destroy_bitmap: ebitmap_destroy(e); goto out; } -- 2.14.0