From patchwork Sun Jan 15 14:56:59 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: 9517431 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 9C16960571 for ; Sun, 15 Jan 2017 14:57:25 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 8E2EF2840F for ; Sun, 15 Jan 2017 14:57:25 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 7F91E28411; Sun, 15 Jan 2017 14:57:25 +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 6A64C2840F for ; Sun, 15 Jan 2017 14:57:24 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751121AbdAOO5X (ORCPT ); Sun, 15 Jan 2017 09:57:23 -0500 Received: from mout.web.de ([217.72.192.78]:58814 "EHLO mout.web.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751036AbdAOO5W (ORCPT ); Sun, 15 Jan 2017 09:57:22 -0500 Received: from [192.168.1.2] ([78.49.147.199]) by smtp.web.de (mrweb101 [213.165.67.124]) with ESMTPSA (Nemesis) id 0LwqBg-1cUx0A3toO-016Rl7; Sun, 15 Jan 2017 15:57:03 +0100 Subject: [PATCH 01/46] selinux: Use kmalloc_array() in cond_init_bool_indexes() 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: <68a423a9-2f89-55f9-fb4c-97dd4df4bb1d@users.sourceforge.net> Date: Sun, 15 Jan 2017 15:56:59 +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:dFEd79xP/k1dEVHwjTlt/8ZIUA2fnTrBzLnyCbHbcVWpEFHeDbg 9XX2Ly1h9nJ67x5ck0EzrEVD9pMicSgrrWnc5RwV5A1UrCRMrV0wrl/sjT6F9ARMOtDTnVf pnZ6C6iVEylWfdgFRpxXh3foJpmcOEsbseW9nYwN3a1gnPiUn2A2PxXumMqOnW7ebMOHCs5 j+EVFIBmlDODGO2Glfq+Q== X-UI-Out-Filterresults: notjunk:1; V01:K0:jxRp9QB41O4=:sxSLhBVDlb2cMLVbL0/RQe QKWCoMzIlqtgK0ydu8q4iOR9xPE3tbbue2gKR9ukmHnt1TtCgv+OHp40DKNZl81iMBoxotKmz knySb56ddj5w/0Veb4NjKLnFeqjBU+4p7bW9ih2ZZTmtN4Xu3lvIpckxrR3tzkjMC9Ww9AslM exA9rKu1bGYfZXXvcf4b0DDyhweVgHO6E4HayzL3FFFgri/1FR/FsZUxiIip9+y1VH/e4g48r OFhKpwaKaymnGmcJks5Fm/YH73hjH/0Y1Bbr0oDwCtGXVtA5G1X4QbS5uhPcOp6GRUuNNwHTz dgcvnJ6QmLK8yesj/bsHOEYd4Qwux4MPxrVHzUaqMgTBSkjN9A8Xk4KosHsS05t6uR8KPFKQc Csm/drscLLMxDy/i03n0q3uHaBKJ2cUPFVB5mVSUON0hzSvjdLgkxP/bFysuGv54Qng3kg9Rk nHqdgdvJz//3GoQZhltL+rT+J03S8898mPIuN0p/q+bAgnw1sP8a+oQubWJnZ+JH0ydAE+9LH mTFgG5KsZWaEW9+qwD6PyEt23fIBzO+Y+wg7ajRvPkqKwLk4iWvR7qjo15Bqm5tPw1BSDfyG7 8cC33k10cXonurrStFs+WvELG17QP+pJwBvBz9izsw688qCSF4SNGABe2KeItXoTaMEwRu0cw 5HaBoDFIpvEFC/ftDlJzJ6dB8noKGWd0DXERz0GdCHlD4msgQeYjw7W4Auhg63EklVUC0g+4b 62+jf/oAq+ZgsU4wzd2EMWUPqkQBu3gjXh6pC9b7PK3pkdsAMliuW9X5CahwihRHtRhNRdClq ZiWoLFr 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 10:48:28 +0100 * A multiplication for the size determination of a memory allocation indicated that an array data structure should be processed. Thus use the corresponding function "kmalloc_array". This issue was detected by using the Coccinelle software. * Replace the specification of a data type by a pointer dereference to make the corresponding size determination a bit safer according to the Linux coding style convention. Signed-off-by: Markus Elfring --- security/selinux/ss/conditional.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/security/selinux/ss/conditional.c b/security/selinux/ss/conditional.c index 34afeadd9e73..fcfab2635c11 100644 --- a/security/selinux/ss/conditional.c +++ b/security/selinux/ss/conditional.c @@ -176,8 +176,9 @@ void cond_policydb_destroy(struct policydb *p) int cond_init_bool_indexes(struct policydb *p) { kfree(p->bool_val_to_struct); - p->bool_val_to_struct = - kmalloc(p->p_bools.nprim * sizeof(struct cond_bool_datum *), GFP_KERNEL); + p->bool_val_to_struct = kmalloc_array(p->p_bools.nprim, + sizeof(*p->bool_val_to_struct), + GFP_KERNEL); if (!p->bool_val_to_struct) return -ENOMEM; return 0;