From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753616AbdDDLOm (ORCPT ); Tue, 4 Apr 2017 07:14:42 -0400 Received: from mout.web.de ([217.72.192.78]:65338 "EHLO mout.web.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1753783AbdDDLNI (ORCPT ); Tue, 4 Apr 2017 07:13:08 -0400 Subject: [PATCH 1/3] selinux: Return directly after a failed memory allocation in policydb_index() From: SF Markus Elfring To: Casey Schaufler , Eric Paris , James Morris , Paul Moore , "Serge E. Hallyn" , Stephen Smalley , William Roberts , linux-security-module@vger.kernel.org, selinux@tycho.nsa.gov Cc: LKML , kernel-janitors@vger.kernel.org References: <5704e656-708a-b611-5611-70fc65dc67e8@users.sourceforge.net> Message-ID: <8a517289-e5a7-8dde-0f5f-9e57f3e270c7@users.sourceforge.net> Date: Tue, 4 Apr 2017 13:12:46 +0200 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:52.0) Gecko/20100101 Thunderbird/52.0 MIME-Version: 1.0 In-Reply-To: <5704e656-708a-b611-5611-70fc65dc67e8@users.sourceforge.net> Content-Type: text/plain; charset=utf-8 Content-Language: en-GB Content-Transfer-Encoding: 7bit X-Provags-ID: V03:K0:EUBdAkBQ0rD4DlCXaT4nO1/mwUOMz6EJ/HJeggqM3NDSAL8kq5n e6z4oRYlIUzFyIkWISdcRBvgn6sDMVXziGoiXI0bdYXhaC0QVtdVuGvmcXtRIHaR/rpca2d s616o7IBcF98FI7K2BL8ED+MCsEqJ80oObsQr9OfySgsqDE1R+MO/ciThQCj8lrHL7B/4PF cXiHKOmoCZtds4YSVFiZg== X-UI-Out-Filterresults: notjunk:1;V01:K0:GaBOEkNzWX0=:FHnCLdTDhbkbDnd9AyNOkp oIS4p6g0tqATtnQvSHDcJ9smEnUHjh8HnJkcC4Gg1ati7OBrQ5kQvMwylI2IqiM1qDUNsQD4n BL/dOb57VWA36kFQ8ggCdX7WmT9wsPHHIEH3Exc5IMarguDKm8GmdRXd7f+RwgEYEeLeiERJy //GXhP7/OnRUZOP8K3yVy/Zd21jo5uoaZYEqdBFuFXWxCodJEYyKHpXEnWB4Hv1SVPioOZZih L4GKyTU9pLnmzpT1OZAyEQJ0lOitLOIf/HniBQX3iRnLM4q0EzkToj5/Ii5696+/CysiudOrz UjGR8jkokOF5ht8gYQbP0b3e1kaCONK7Q+ldu8x9G0wwKc1Fvj1BK9G1FpHuJ0qN0xKIUQx3o zgzX/5I3UErpguPND7Z7RHHikj+lz42B8GLl5E5XW2pohtweeGx4HPbXZonx0Mk9p7mnvC9Q/ /pihQw0ysTNkAOWj7MMYsIY2jCZb26AUQa6dAbYQWEQPJkuaH/pci9IGokc4I/qqGKEGXeQ56 gQnVQ4Q7MmrhyI6ahJ0oiGeNKFV3pPoJahz11HUCTK+zQx3mY/Y/bGbRSYBFOO2XzjUn6nGMt c8oSmDhu/po7I47E9xngCzz7aXtDYRh+n+WSufIAfu1krqNtYYYF24VfXjLU7OX+Sqv5y5YC6 lNbBuR55WZE09QSrt6/2QIkJwcE47YgG/AQik3WXTAg2QZJYL7oDUBK+LeetY5tIurawSnfU3 mhL/V8vtOThFm8/E4BWU75PP3cH9BzV4SCsTMEnVVD0LAm4lxqK5p8hCmAYnMBlvdtbTpPlv4 sP2d6nh Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Markus Elfring Date: Tue, 4 Apr 2017 10:20:46 +0200 Replace five goto statements (and previous variable assignments) by direct returns after a memory allocation failure in this function. Signed-off-by: Markus Elfring --- security/selinux/ss/policydb.c | 15 +++++---------- 1 file changed, 5 insertions(+), 10 deletions(-) diff --git a/security/selinux/ss/policydb.c b/security/selinux/ss/policydb.c index 0080122760ad..87d645d3a39f 100644 --- a/security/selinux/ss/policydb.c +++ b/security/selinux/ss/policydb.c @@ -538,34 +538,30 @@ static int policydb_index(struct policydb *p) symtab_hash_eval(p->symtab); #endif - rc = -ENOMEM; p->class_val_to_struct = kcalloc(p->p_classes.nprim, sizeof(*p->class_val_to_struct), GFP_KERNEL); if (!p->class_val_to_struct) - goto out; + return -ENOMEM; - rc = -ENOMEM; p->role_val_to_struct = kcalloc(p->p_roles.nprim, sizeof(*p->role_val_to_struct), GFP_KERNEL); if (!p->role_val_to_struct) - goto out; + return -ENOMEM; - rc = -ENOMEM; p->user_val_to_struct = kcalloc(p->p_users.nprim, sizeof(*p->user_val_to_struct), GFP_KERNEL); if (!p->user_val_to_struct) - goto out; + return -ENOMEM; /* Yes, I want the sizeof the pointer, not the structure */ - rc = -ENOMEM; p->type_val_to_struct_array = flex_array_alloc(sizeof(struct type_datum *), p->p_types.nprim, GFP_KERNEL | __GFP_ZERO); if (!p->type_val_to_struct_array) - goto out; + return -ENOMEM; rc = flex_array_prealloc(p->type_val_to_struct_array, 0, p->p_types.nprim, GFP_KERNEL | __GFP_ZERO); @@ -577,12 +573,11 @@ static int policydb_index(struct policydb *p) goto out; for (i = 0; i < SYM_NUM; i++) { - rc = -ENOMEM; p->sym_val_to_name[i] = flex_array_alloc(sizeof(char *), p->symtab[i].nprim, GFP_KERNEL | __GFP_ZERO); if (!p->sym_val_to_name[i]) - goto out; + return -ENOMEM; rc = flex_array_prealloc(p->sym_val_to_name[i], 0, p->symtab[i].nprim, -- 2.12.2 From mboxrd@z Thu Jan 1 00:00:00 1970 From: SF Markus Elfring Date: Tue, 04 Apr 2017 11:12:46 +0000 Subject: [PATCH 1/3] selinux: Return directly after a failed memory allocation in policydb_index() Message-Id: <8a517289-e5a7-8dde-0f5f-9e57f3e270c7@users.sourceforge.net> List-Id: References: <5704e656-708a-b611-5611-70fc65dc67e8@users.sourceforge.net> In-Reply-To: <5704e656-708a-b611-5611-70fc65dc67e8@users.sourceforge.net> MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit To: linux-security-module@vger.kernel.org From: Markus Elfring Date: Tue, 4 Apr 2017 10:20:46 +0200 Replace five goto statements (and previous variable assignments) by direct returns after a memory allocation failure in this function. Signed-off-by: Markus Elfring --- security/selinux/ss/policydb.c | 15 +++++---------- 1 file changed, 5 insertions(+), 10 deletions(-) diff --git a/security/selinux/ss/policydb.c b/security/selinux/ss/policydb.c index 0080122760ad..87d645d3a39f 100644 --- a/security/selinux/ss/policydb.c +++ b/security/selinux/ss/policydb.c @@ -538,34 +538,30 @@ static int policydb_index(struct policydb *p) symtab_hash_eval(p->symtab); #endif - rc = -ENOMEM; p->class_val_to_struct = kcalloc(p->p_classes.nprim, sizeof(*p->class_val_to_struct), GFP_KERNEL); if (!p->class_val_to_struct) - goto out; + return -ENOMEM; - rc = -ENOMEM; p->role_val_to_struct = kcalloc(p->p_roles.nprim, sizeof(*p->role_val_to_struct), GFP_KERNEL); if (!p->role_val_to_struct) - goto out; + return -ENOMEM; - rc = -ENOMEM; p->user_val_to_struct = kcalloc(p->p_users.nprim, sizeof(*p->user_val_to_struct), GFP_KERNEL); if (!p->user_val_to_struct) - goto out; + return -ENOMEM; /* Yes, I want the sizeof the pointer, not the structure */ - rc = -ENOMEM; p->type_val_to_struct_array = flex_array_alloc(sizeof(struct type_datum *), p->p_types.nprim, GFP_KERNEL | __GFP_ZERO); if (!p->type_val_to_struct_array) - goto out; + return -ENOMEM; rc = flex_array_prealloc(p->type_val_to_struct_array, 0, p->p_types.nprim, GFP_KERNEL | __GFP_ZERO); @@ -577,12 +573,11 @@ static int policydb_index(struct policydb *p) goto out; for (i = 0; i < SYM_NUM; i++) { - rc = -ENOMEM; p->sym_val_to_name[i] = flex_array_alloc(sizeof(char *), p->symtab[i].nprim, GFP_KERNEL | __GFP_ZERO); if (!p->sym_val_to_name[i]) - goto out; + return -ENOMEM; rc = flex_array_prealloc(p->sym_val_to_name[i], 0, p->symtab[i].nprim, -- 2.12.2 From mboxrd@z Thu Jan 1 00:00:00 1970 From: elfring@users.sourceforge.net (SF Markus Elfring) Date: Tue, 4 Apr 2017 13:12:46 +0200 Subject: [PATCH 1/3] selinux: Return directly after a failed memory allocation in policydb_index() In-Reply-To: <5704e656-708a-b611-5611-70fc65dc67e8@users.sourceforge.net> References: <5704e656-708a-b611-5611-70fc65dc67e8@users.sourceforge.net> Message-ID: <8a517289-e5a7-8dde-0f5f-9e57f3e270c7@users.sourceforge.net> To: linux-security-module@vger.kernel.org List-Id: linux-security-module.vger.kernel.org From: Markus Elfring Date: Tue, 4 Apr 2017 10:20:46 +0200 Replace five goto statements (and previous variable assignments) by direct returns after a memory allocation failure in this function. Signed-off-by: Markus Elfring --- security/selinux/ss/policydb.c | 15 +++++---------- 1 file changed, 5 insertions(+), 10 deletions(-) diff --git a/security/selinux/ss/policydb.c b/security/selinux/ss/policydb.c index 0080122760ad..87d645d3a39f 100644 --- a/security/selinux/ss/policydb.c +++ b/security/selinux/ss/policydb.c @@ -538,34 +538,30 @@ static int policydb_index(struct policydb *p) symtab_hash_eval(p->symtab); #endif - rc = -ENOMEM; p->class_val_to_struct = kcalloc(p->p_classes.nprim, sizeof(*p->class_val_to_struct), GFP_KERNEL); if (!p->class_val_to_struct) - goto out; + return -ENOMEM; - rc = -ENOMEM; p->role_val_to_struct = kcalloc(p->p_roles.nprim, sizeof(*p->role_val_to_struct), GFP_KERNEL); if (!p->role_val_to_struct) - goto out; + return -ENOMEM; - rc = -ENOMEM; p->user_val_to_struct = kcalloc(p->p_users.nprim, sizeof(*p->user_val_to_struct), GFP_KERNEL); if (!p->user_val_to_struct) - goto out; + return -ENOMEM; /* Yes, I want the sizeof the pointer, not the structure */ - rc = -ENOMEM; p->type_val_to_struct_array = flex_array_alloc(sizeof(struct type_datum *), p->p_types.nprim, GFP_KERNEL | __GFP_ZERO); if (!p->type_val_to_struct_array) - goto out; + return -ENOMEM; rc = flex_array_prealloc(p->type_val_to_struct_array, 0, p->p_types.nprim, GFP_KERNEL | __GFP_ZERO); @@ -577,12 +573,11 @@ static int policydb_index(struct policydb *p) goto out; for (i = 0; i < SYM_NUM; i++) { - rc = -ENOMEM; p->sym_val_to_name[i] = flex_array_alloc(sizeof(char *), p->symtab[i].nprim, GFP_KERNEL | __GFP_ZERO); if (!p->sym_val_to_name[i]) - goto out; + return -ENOMEM; rc = flex_array_prealloc(p->sym_val_to_name[i], 0, p->symtab[i].nprim, -- 2.12.2 -- To unsubscribe from this list: send the line "unsubscribe linux-security-module" in the body of a message to majordomo at vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html