lkml.org 
[lkml]   [2019]   [Sep]   [20]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
/
Date
From
SubjectRe: [PATCH] tty:vt: Add check the return value of kzalloc to avoid oops
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

\
 
 \ /
  Last update: 2019-09-20 08:05    [W:0.073 / U:0.860 seconds]
©2003-2020 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site