[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <20190920060454.GB473496@kroah.com>
Date: Fri, 20 Sep 2019 08:04:54 +0200
From: Greg KH <gregkh@...uxfoundation.org>
To: Nixiaoming <nixiaoming@...wei.com>
Cc: "penberg@...helsinki.fi" <penberg@...helsinki.fi>,
"jslaby@...e.com" <jslaby@...e.com>,
"nico@...xnic.net" <nico@...xnic.net>,
"textshell@...uujin.de" <textshell@...uujin.de>,
"sam@...nborg.org" <sam@...nborg.org>,
"daniel.vetter@...ll.ch" <daniel.vetter@...ll.ch>,
"mpatocka@...hat.com" <mpatocka@...hat.com>,
"ghalat@...hat.com" <ghalat@...hat.com>,
"linux-kernel@...r.kernel.org" <linux-kernel@...r.kernel.org>,
Yangyingliang <yangyingliang@...wei.com>,
yuehaibing <yuehaibing@...wei.com>,
Zengweilin <zengweilin@...wei.com>
Subject: Re: [PATCH] tty:vt: Add check the return value of kzalloc to avoid
oops
On Fri, Sep 20, 2019 at 02:29:49AM +0000, Nixiaoming wrote:
> On 2019/9/19 17:30, 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@...wei.com>
> >
> > We keep having this be "reported"
> >
> >> ---
> >> drivers/tty/vt/vt.c | 18 ++++++++++++++++++
> >> 1 file changed, 18 insertions(+)
> >>
> >> diff --git a/drivers/tty/vt/vt.c b/drivers/tty/vt/vt.c
> >> index 34aa39d..db83e52 100644
> >> --- a/drivers/tty/vt/vt.c
> >> +++ b/drivers/tty/vt/vt.c
> >> @@ -3357,15 +3357,33 @@ static int __init con_init(void)
> >>
> >> for (currcons = 0; currcons < MIN_NR_CONSOLES; currcons++) {
> >> 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?
>
> I did not actually observe the null pointer here.
> I am confused when I see the code allocated here without check the return value.
> Small memory allocation failures are difficult to occur during system initialization
> But is it not safe enough if the code is not judged?
> Also if the memory allocation failure is not allowed here, is it better to add the __GFP_NOFAIL flags?
See my response to Nicolas, but yes, that would be a good way to handle
this.
thanks,
greg k-h
Powered by blists - more mailing lists