LKML Archive on lore.kernel.org
help / color / mirror / Atom feed
From: Gen Zhang <blackgod016574@gmail.com>
To: Kees Cook <keescook@chromium.org>
Cc: linux-kernel@vger.kernel.org
Subject: Re: [PATCH v2] consolemap: Fix a memory leaking bug in drivers/tty/vt/consolemap.c
Date: Fri, 24 May 2019 10:14:22 +0800	[thread overview]
Message-ID: <20190524021422.GB4753@zhanggen-UX430UQ> (raw)
In-Reply-To: <201905230952.B47ADA17A@keescook>

On Thu, May 23, 2019 at 09:54:18AM -0700, Kees Cook wrote:
> On Thu, May 23, 2019 at 08:34:52AM +0800, Gen Zhang wrote:
> > In function con_insert_unipair(), when allocation for p2 and p1[n]
> > fails, ENOMEM is returned, but previously allocated p1 is not freed, 
> > remains as leaking memory. Thus we should free p1 as well when this
> > allocation fails.
> > 
> > Signed-off-by: Gen Zhang <blackgod016574@gmail.com>
> 
> As far as I can see this is correct, as it's just restoring the prior
> state before the p1 allocation.
> 
> Reviewed-by: Kees Cook <keescook@chromium.org>
> 
Thanks for your review, Kees!

Thanks
Gen
> > ---
> > diff --git a/drivers/tty/vt/consolemap.c b/drivers/tty/vt/consolemap.c
> > index b28aa0d..79fcc96 100644
> > --- a/drivers/tty/vt/consolemap.c
> > +++ b/drivers/tty/vt/consolemap.c
> > @@ -489,7 +489,11 @@ con_insert_unipair(struct uni_pagedir *p, u_short unicode, u_short fontpos)
> >  	p2 = p1[n = (unicode >> 6) & 0x1f];
> >  	if (!p2) {
> >  		p2 = p1[n] = kmalloc_array(64, sizeof(u16), GFP_KERNEL);
> > -		if (!p2) return -ENOMEM;
> > +		if (!p2) {
> > +			kfree(p1);
> > +			p->uni_pgdir[n] = NULL;
> > +			return -ENOMEM;
> > +		}
> >  		memset(p2, 0xff, 64*sizeof(u16)); /* No glyphs for the characters (yet) */
> >  	}
> >  
> > ---
> 
> -- 
> Kees Cook

  reply	other threads:[~2019-05-24  2:14 UTC|newest]

Thread overview: 12+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-05-21  9:29 [PATCH] " Gen Zhang
2019-05-21 20:44 ` Kees Cook
2019-05-22  1:50   ` Gen Zhang
2019-05-22 20:54     ` Kees Cook
2019-05-23  0:29       ` Gen Zhang
2019-05-23  0:34       ` [PATCH v2] " Gen Zhang
2019-05-23 16:54         ` Kees Cook
2019-05-24  2:14           ` Gen Zhang [this message]
2019-05-24  2:19           ` [PATCH v2] consolemap: Fix a memory leaking bug in con_insert_unipair() Gen Zhang
2019-05-24  8:02             ` Greg KH
2019-05-24  9:37           ` [PATCH v2] consolemap: Fix a memory leaking bug in drivers/tty/vt/consolemap.c Jon Hunter
2019-05-25  6:04             ` Kees Cook

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=20190524021422.GB4753@zhanggen-UX430UQ \
    --to=blackgod016574@gmail.com \
    --cc=keescook@chromium.org \
    --cc=linux-kernel@vger.kernel.org \
    --subject='Re: [PATCH v2] consolemap: Fix a memory leaking bug in drivers/tty/vt/consolemap.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).