LKML Archive on lore.kernel.org
help / color / mirror / Atom feed
From: Gen Zhang <blackgod016574@gmail.com>
To: Nicolas Pitre <nico@fluxnic.net>
Cc: linux-kernel@vger.kernel.org
Subject: Re: [PATCH v2] vt: Fix a missing-check bug in drivers/tty/vt/vt.c
Date: Wed, 22 May 2019 16:10:29 +0800 [thread overview]
Message-ID: <20190522081029.GB5109@zhanggen-UX430UQ> (raw)
In-Reply-To: <nycvar.YSQ.7.76.1905212218090.1558@knanqh.ubzr>
On Tue, May 21, 2019 at 10:43:11PM -0400, Nicolas Pitre wrote:
> On Tue, 21 May 2019, Gen Zhang wrote:
>
> > On Tue, May 21, 2019 at 12:30:38AM -0400, Nicolas Pitre wrote:
> > > Now imagine that MIN_NR_CONSOLES is defined to 10 instead of 1.
> > >
> > > What happens with allocated memory if the err_vc condition is met on the
> > > 5th loop?
> > Yes, vc->vc_screenbuf from the last loop is still not freed, right? I
> > don't have idea to solve this one. Could please give some advice? Since
> > we have to consider the err_vc condition.
> >
> > > If err_vc_screenbuf condition is encountered on the 5th loop (curcons =
> > > 4), what is the value of vc_cons[4].d? Isn't it the same as vc that you
> > > just freed?
> > >
> > >
> > > Nicolas
> > Thanks for your explaination! You mean a double free situation may
> > happen, right? But in vc_allocate() there is also such a kfree(vc) and
> > vc_cons[currcons].d = NULL operation. This situation is really confusing
> > me.
>
> What you could do is something that looks like:
>
> for (currcons = 0; currcons < MIN_NR_CONSOLES; currcons++) {
> vc_cons[currcons].d = vc = kzalloc(...);
> if (!vc)
> goto fail1;
> ...
> vc->vc_screenbuf = kzalloc(...);
> if (!vc->vc_screenbuf)
> goto fail2;
> ...
>
> return 0;
>
> /* free already allocated memory on error */
> fail1:
> while (curcons > 0) {
> curcons--;
> kfree(vc_cons[currcons].d->vc_screenbuf);
> fail2:
> kfree(vc_cons[currcons].d);
> vc_cons[currcons].d = NULL;
> }
> console_unlock();
> return -ENOMEM;
>
>
> Nicolas
Thanks for your patient explaination, Nicolas!
I will work on it and resubmit it.
Thanks
Gen
next prev parent reply other threads:[~2019-05-22 8:10 UTC|newest]
Thread overview: 14+ messages / expand[flat|nested] mbox.gz Atom feed top
2019-05-21 2:29 Gen Zhang
2019-05-21 2:55 ` Nicolas Pitre
2019-05-21 3:09 ` Gen Zhang
2019-05-21 3:26 ` Nicolas Pitre
2019-05-21 4:00 ` Gen Zhang
2019-05-21 4:30 ` Nicolas Pitre
2019-05-21 7:39 ` Gen Zhang
2019-05-22 2:43 ` Nicolas Pitre
2019-05-22 8:10 ` Gen Zhang [this message]
2019-05-22 12:19 ` [PATCH v3] " Gen Zhang
2019-05-22 14:18 ` Nicolas Pitre
2019-05-24 2:27 ` [PATCH v3] vt: Fix a missing-check bug in con_init() Gen Zhang
2019-05-21 3:21 ` [PATCH v3] vt: Fix a missing-check bug in drivers/tty/vt/vt.c Gen Zhang
2019-05-21 6:46 ` Oleksandr Natalenko
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=20190522081029.GB5109@zhanggen-UX430UQ \
--to=blackgod016574@gmail.com \
--cc=linux-kernel@vger.kernel.org \
--cc=nico@fluxnic.net \
--subject='Re: [PATCH v2] vt: Fix a missing-check bug in drivers/tty/vt/vt.c' \
/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
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).