mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Xiaoming Ni <nixiaoming@huawei.com>
To: Greg KH <gregkh@linuxfoundation.org>, Nicolas Pitre <nico@fluxnic.net>
Cc: <penberg@cs.helsinki.fi>, <jslaby@suse.com>,
	<textshell@uchuujin.de>, <sam@ravnborg.org>,
	<daniel.vetter@ffwll.ch>, <mpatocka@redhat.com>,
	<ghalat@redhat.com>, <linux-kernel@vger.kernel.org>,
	<yangyingliang@huawei.com>, <yuehaibing@huawei.com>,
	<zengweilin@huawei.com>
Subject: Re: [PATCH] tty:vt: Add check the return value of kzalloc to avoid oops
Date: Sat, 21 Sep 2019 15:26:38 +0800	[thread overview]
Message-ID: <bee63793-e9f4-ecc4-7966-765207009c75@huawei.com> (raw)
In-Reply-To: <20190920060426.GA473496@kroah.com>


On 2019/9/20 14:04, Greg KH wrote:
> On Thu, Sep 19, 2019 at 10:56:15PM -0400, Nicolas Pitre wrote:
>> On Thu, 19 Sep 2019, Greg KH wrote:
>>
>>> On Thu, Sep 19, 2019 at 05:18:15PM +0800, Xiaoming Ni wrote:
>>>> Using kzalloc() to allocate memory in function con_init(), but not
>>>> checking the return value, there is a risk of null pointer references
>>>> oops.
>>>>
>>>> Signed-off-by: Xiaoming Ni <nixiaoming@huawei.com>
>>>
>>> We keep having this be "reported" :(
>>
>> Something probably needs to be "communicated" about that.
> 
> I know, but it's also kind of fun to see what these "automated" checkers
> find, sometimes the resulting patches almost work properly :)
> 
> This one is really close, I think if the likely/unlikely gets cleaned
> up, it is viable.
> 
>>>>  		vc_cons[currcons].d = vc = kzalloc(sizeof(struct vc_data), GFP_NOWAIT);
>>>> +		if (unlikely(!vc)) {
>>>> +			pr_warn("%s:failed to allocate memory for the %u vc\n",
>>>> +					__func__, currcons);
>>>> +			break;
>>>> +		}
>>>
>>> At init, this really can not happen.  Have you see it ever happen?
>>
>> This is maybe too subtle a fact. The "communication" could be done with 
>> some GFP_WONTFAIL flag, and have the allocator simply pannic() if it 
>> ever fails.
> 
> That's a good idea to do as well.
> 
> thanks,
> 
> greg k-h
> 
> .
> 
Thank you for your advice.

@ Nicolas Pitre
Can I make a v2 patch based on your advice ?
Or you will submit a patch for "GFP_WONTFAIL" yourself ?

thanks
Xiaoming Ni



  reply	other threads:[~2019-09-21  7:26 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-09-19  9:18 Xiaoming Ni
2019-09-19  9:29 ` Greg KH
2019-09-19 15:16   ` Mikulas Patocka
2019-09-20  2:29   ` Nixiaoming
2019-09-20  6:04     ` Greg KH
2019-09-20  2:56   ` Nicolas Pitre
2019-09-20  6:04     ` Greg KH
2019-09-21  7:26       ` Xiaoming Ni [this message]
2019-09-23  3:50         ` Nicolas Pitre
2019-09-25  8:37           ` Xiaoming Ni

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=bee63793-e9f4-ecc4-7966-765207009c75@huawei.com \
    --to=nixiaoming@huawei.com \
    --cc=daniel.vetter@ffwll.ch \
    --cc=ghalat@redhat.com \
    --cc=gregkh@linuxfoundation.org \
    --cc=jslaby@suse.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=mpatocka@redhat.com \
    --cc=nico@fluxnic.net \
    --cc=penberg@cs.helsinki.fi \
    --cc=sam@ravnborg.org \
    --cc=textshell@uchuujin.de \
    --cc=yangyingliang@huawei.com \
    --cc=yuehaibing@huawei.com \
    --cc=zengweilin@huawei.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

Powered by JetHome