mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: "Xiaoke Wang" <xkernel.wang@foxmail.com>
To: "Greg KH" <gregkh@linuxfoundation.org>
Cc: linux <linux@dominikbrodowski.net>,
	akpm <akpm@linux-foundation.org>,
	pombredanne <pombredanne@nexb.com>, arnd <arnd@arndb.de>,
	"luc.vanoostenryck" <luc.vanoostenryck@gmail.com>,
	linux-kernel <linux-kernel@vger.kernel.org>
Subject: Re: [PATCH] init/initramfs.c: check the return value of kstrdup()
Date: Fri, 4 Mar 2022 23:55:35 +0800	[thread overview]
Message-ID: <tencent_72848F2829FCD381DC30F3E7DA737050880A@qq.com> (raw)
In-Reply-To: <YiIesoVGiVm2KcUD@kroah.com>

On Fri, 04 Mar 2022 22:14:21 +0800, Greg KH <gregkh@linuxfoundation.org> wrote:
>> struct dir_entry *de = kmalloc(sizeof(struct dir_entry), GFP_KERNEL);
>> if (!de)
>>  panic_show_mem("can't allocate dir_entry buffer");
>> - INIT_LIST_HEAD(&de->list);
>> de->name = kstrdup(name, GFP_KERNEL);
>> + if (!de->name) {
>
> How can this fail?  Have you ever hit this in real life?
>
>> +kfree(de);
>> +panic_show_mem("can't duplicate dir name");
>
> Why are you freeing memory if you are panicing?
>
> How was this tested?

Thank you for taking the time.
I found this with a static tool, without dynamic testing.
kstrdup() allocates memory for copying the string and I noticed all the
other allocation functions in this file have the check for their return
value such as `de` on the above code. So I suppose this is also needed
to be checked and I intuitively add kfree() on the error path.
I'm sorry to bother you if this is actually unnecessary.

Regards,
Xiaoke Wang

  reply	other threads:[~2022-03-04 15:55 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-03-04  9:27 xkernel.wang
2022-03-04 14:14 ` Greg KH
2022-03-04 15:55   ` Xiaoke Wang [this message]
2022-03-07  1:28 ` Andrew Morton
  -- strict thread matches above, loose matches on Subject: below --
2021-12-13  8:58 Xiaoke Wang

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=tencent_72848F2829FCD381DC30F3E7DA737050880A@qq.com \
    --to=xkernel.wang@foxmail.com \
    --cc=akpm@linux-foundation.org \
    --cc=arnd@arndb.de \
    --cc=gregkh@linuxfoundation.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux@dominikbrodowski.net \
    --cc=luc.vanoostenryck@gmail.com \
    --cc=pombredanne@nexb.com \
    /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

all inboxes | Powered by JetHome®