From patchwork Sun Jan 15 15:03:33 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: 9517453 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 0C0E760571 for ; Sun, 15 Jan 2017 15:03:55 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 0088628420 for ; Sun, 15 Jan 2017 15:03:55 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id E98232842D; Sun, 15 Jan 2017 15:03:54 +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 9323028420 for ; Sun, 15 Jan 2017 15:03:54 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751132AbdAOPDx (ORCPT ); Sun, 15 Jan 2017 10:03:53 -0500 Received: from mout.web.de ([212.227.15.14]:53396 "EHLO mout.web.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751052AbdAOPDw (ORCPT ); Sun, 15 Jan 2017 10:03:52 -0500 Received: from [192.168.1.2] ([78.49.147.199]) by smtp.web.de (mrweb002 [213.165.67.108]) with ESMTPSA (Nemesis) id 0MF3Nr-1cCavr2c2t-00GGzJ; Sun, 15 Jan 2017 16:03:37 +0100 Subject: [PATCH 06/46] selinux: Use kcalloc() in policydb_index() 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: <2c5e5708-72a3-954f-a773-e5716df174d1@users.sourceforge.net> Date: Sun, 15 Jan 2017 16:03:33 +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:o7oetZRSmqOVMyBLf0ez5557PSULPdcWPDp0dan3rKzYtKPN+bH ZW35iZ9/y3kClt5sP79sMtgdwMFDEHzmVtAZYADnY+98J632bpL5pnKleBPsZNTfRYOgJbb VWIq5W0GiULn0w7oIIPRcQ2QVs5D82+aGZYAKzJOuCKjk03a+FOM/jNvliIBHs6Upo7T4Kw p2RJUn3exEp5uT12uFJsA== X-UI-Out-Filterresults: notjunk:1; V01:K0:0eSNO0eLFfA=:9gjtBq5w8SdK7ees8Y3/2v HQj+L1dYjRsgQyVS1FnoYSRiVuqe9NbegNopdVMOpdXHz5AtE+wASYBgRfSkcmpz41wuBp4Un UhiiKwdCzCqeNcgTCARlbcDRCNjgWeQkcvo6aXgtOtGVB0oyXRFdU+siVyGqELFegWAA6tKLw VbsMOEUfQSi3CcRfPp+Xc2if/E1/vXGm7bE4duWH6k+bwU1vsAjYkMGSHOE8e1E9LKbi/Uzmm bEnIMEIW+W85KOxEMKtDOjSap0RwDlPC9WFzt8yUhVgS28xIXosguMpVIQVVB+N3Jccaom/Md /sm9grQzDaa3YzHqaLuvybxRpoY3strxrb60vWEFG9hJl9k9D1UT1Np55Tz5DaaCodOof3vg9 b7qkjXbMeBP8RX12qaSyOszciZiP4DHX+fnyeyXVW23Ztm/ALvMBiD+gvw6uCAjJE9jNVShtJ zbbzYqHFXUfC41KDYQ6gauknNW6JlBrUtkVKonXTrRqcDGPHcSiaJqhVOCBPFTFZwL5l5gSeK TV7mGyDm7IoBD5F8z4vosMF7u/87SsAc098OL7k5bw4hO3N1QD9nMAnhlSm0B74VDAB2NlR3x zM/Y2LPBLMx3LDwVo1IRxWF0pyUDxZbYUF5aJjThQMahKOiuf3CZYKr2tPRv6jt/kCXs2w5FP rd1O8jZ3OzYrkJ68FfM4tsQl65SmquP+gnWHlMRBC7K9hTB4cSpgZLnFu+Zemt4VDE2w4iFES td7UywrxGun4TVyI7cz7KMgR7irmAixMzqPoBGFO+0gR6my80RTWVFJo+dl3NU965DSyDeI7n SbtQYuJ 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 13:08:59 +0100 Multiplications for the size determination of memory allocations indicated that array data structures should be processed. Thus use the corresponding function "kcalloc". This issue was detected by using the Coccinelle software. Signed-off-by: Markus Elfring --- security/selinux/ss/policydb.c | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/security/selinux/ss/policydb.c b/security/selinux/ss/policydb.c index d719db4219cd..21869b622c0c 100644 --- a/security/selinux/ss/policydb.c +++ b/security/selinux/ss/policydb.c @@ -540,23 +540,23 @@ static int policydb_index(struct policydb *p) #endif rc = -ENOMEM; - p->class_val_to_struct = - kzalloc(p->p_classes.nprim * sizeof(*(p->class_val_to_struct)), - GFP_KERNEL); + 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; rc = -ENOMEM; - p->role_val_to_struct = - kzalloc(p->p_roles.nprim * sizeof(*(p->role_val_to_struct)), - GFP_KERNEL); + 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; rc = -ENOMEM; - p->user_val_to_struct = - kzalloc(p->p_users.nprim * sizeof(*(p->user_val_to_struct)), - GFP_KERNEL); + 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;