From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S934268AbcIFVt4 (ORCPT ); Tue, 6 Sep 2016 17:49:56 -0400 Received: from mail-wm0-f51.google.com ([74.125.82.51]:35207 "EHLO mail-wm0-f51.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S933047AbcIFVtx (ORCPT ); Tue, 6 Sep 2016 17:49:53 -0400 MIME-Version: 1.0 In-Reply-To: <3b21b2d7-9856-009c-9bd1-3a76a83bc7fc@users.sourceforge.net> References: <3b21b2d7-9856-009c-9bd1-3a76a83bc7fc@users.sourceforge.net> From: Kees Cook Date: Tue, 6 Sep 2016 17:49:50 -0400 X-Google-Sender-Auth: MB21u0uUIWlLL7vGeVs0qaWHgUA Message-ID: Subject: Re: [PATCH] x86-ksysfs: Use kmalloc_array() in create_setup_data_nodes() To: Ingo Molnar Cc: SF Markus Elfring , "x86@kernel.org" , Dave Young , "H. Peter Anvin" , Matt Fleming , Thomas Gleixner , LKML , kernel-janitors@vger.kernel.org, Julia Lawall , Paolo Bonzini Content-Type: text/plain; charset=UTF-8 Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Sun, Sep 4, 2016 at 4:23 PM, SF Markus Elfring wrote: > From: Markus Elfring > Date: Sun, 4 Sep 2016 22:15:09 +0200 > > 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. Which rule-set was used? > > Signed-off-by: Markus Elfring While probably impossible to overflow in the real world, it's still better to use the right function here. Acked-by: Kees Cook > --- > arch/x86/kernel/ksysfs.c | 2 +- > 1 file changed, 1 insertion(+), 1 deletion(-) > > diff --git a/arch/x86/kernel/ksysfs.c b/arch/x86/kernel/ksysfs.c > index 4afc67f..cddf3c6 100644 > --- a/arch/x86/kernel/ksysfs.c > +++ b/arch/x86/kernel/ksysfs.c > @@ -283,7 +283,7 @@ static int __init create_setup_data_nodes(struct kobject *parent) > if (ret) > goto out_setup_data_kobj; > > - kobjp = kmalloc(sizeof(*kobjp) * nr, GFP_KERNEL); > + kobjp = kmalloc_array(nr, sizeof(*kobjp), GFP_KERNEL); > if (!kobjp) { > ret = -ENOMEM; > goto out_setup_data_kobj; > -- > 2.9.3 > -- Kees Cook Nexus Security