linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Kees Cook <keescook@chromium.org>
To: Ingo Molnar <mingo@redhat.com>
Cc: SF Markus Elfring <elfring@users.sourceforge.net>,
	"x86@kernel.org" <x86@kernel.org>, Dave Young <dyoung@redhat.com>,
	"H. Peter Anvin" <hpa@zytor.com>,
	Matt Fleming <matt.fleming@intel.com>,
	Thomas Gleixner <tglx@linutronix.de>,
	LKML <linux-kernel@vger.kernel.org>,
	kernel-janitors@vger.kernel.org,
	Julia Lawall <julia.lawall@lip6.fr>,
	Paolo Bonzini <pbonzini@redhat.com>
Subject: Re: [PATCH] x86-ksysfs: Use kmalloc_array() in create_setup_data_nodes()
Date: Tue, 6 Sep 2016 17:49:50 -0400	[thread overview]
Message-ID: <CAGXu5jLSsU+daPP=uX+3T02RkTFguG1rtemOF-7Py_Fi=qYP6A@mail.gmail.com> (raw)
In-Reply-To: <3b21b2d7-9856-009c-9bd1-3a76a83bc7fc@users.sourceforge.net>

On Sun, Sep 4, 2016 at 4:23 PM, SF Markus Elfring
<elfring@users.sourceforge.net> wrote:
> From: Markus Elfring <elfring@users.sourceforge.net>
> 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 <elfring@users.sourceforge.net>

While probably impossible to overflow in the real world, it's still
better to use the right function here.

Acked-by: Kees Cook <keescook@chromium.org>

> ---
>  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

  reply	other threads:[~2016-09-06 21:49 UTC|newest]

Thread overview: 11+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-09-04 20:23 [PATCH] x86-ksysfs: Use kmalloc_array() in create_setup_data_nodes() SF Markus Elfring
2016-09-06 21:49 ` Kees Cook [this message]
2016-09-07  7:49   ` SF Markus Elfring
2016-09-07 10:36     ` Paolo Bonzini
2016-09-07 11:17       ` SF Markus Elfring
2016-09-07 11:20         ` Paolo Bonzini
2016-09-07 11:45           ` SF Markus Elfring
2016-09-07 16:23             ` Kees Cook
2016-09-07 16:37               ` Joe Perches
2016-09-07 17:01                 ` Kees Cook
2016-09-07 16:55               ` SF Markus Elfring

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to='CAGXu5jLSsU+daPP=uX+3T02RkTFguG1rtemOF-7Py_Fi=qYP6A@mail.gmail.com' \
    --to=keescook@chromium.org \
    --cc=dyoung@redhat.com \
    --cc=elfring@users.sourceforge.net \
    --cc=hpa@zytor.com \
    --cc=julia.lawall@lip6.fr \
    --cc=kernel-janitors@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=matt.fleming@intel.com \
    --cc=mingo@redhat.com \
    --cc=pbonzini@redhat.com \
    --cc=tglx@linutronix.de \
    --cc=x86@kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).