LKML Archive on lore.kernel.org
 help / color / Atom feed
From: Jiri Slaby <jirislaby@kernel.org>
To: James Bond <jameslouisebond@gmail.com>
Cc: Greg Kroah-Hartman <gregkh@linuxfoundation.org>,
	Andrew Morton <akpm@linux-foundation.org>,
	Kees Cook <keescook@chromium.org>,
	Michel Lespinasse <walken@google.com>,
	Vlastimil Babka <vbabka@suse.cz>,
	Denis Efremov <efremov@linux.com>,
	linux-kernel@vger.kernel.org, Ben Hutchings <ben@decadent.org.uk>
Subject: Re: [PATCH] tty/vt: fix a memory leak in con_insert_unipair
Date: Mon, 10 Aug 2020 07:16:48 +0200
Message-ID: <dd4ac5db-9ae7-fbf7-535b-c0d3fa098942@kernel.org> (raw)
In-Reply-To: <20200809221453.10235-1-jameslouisebond@gmail.com>

On 10. 08. 20, 0:14, James Bond wrote:
> Syzkaller find a memory leak in con_insert_unipair:
>     BUG: memory leak
>     unreferenced object 0xffff88804893d100 (size 256):
>     comm "syz-executor.3", pid 16154, jiffies 4295043307 (age 2392.340s)
>     hex dump (first 32 bytes):
>     80 af 88 4e 80 88 ff ff 00 a8 88 4e 80 88 ff ff  ...N.......N....
>     80 ad 88 4e 80 88 ff ff 00 aa 88 4e 80 88 ff ff  ...N.......N....
>     backtrace:
>     [<00000000f76ff1de>] kmalloc include/linux/slab.h:555 [inline]
>     [<00000000f76ff1de>] kmalloc_array include/linux/slab.h:596 [inline]
>     [<00000000f76ff1de>] con_insert_unipair+0x9e/0x1a0 drivers/tty/vt/consolemap.c:482
>     [<000000002f1ad7da>] con_set_unimap+0x244/0x2a0 drivers/tty/vt/consolemap.c:595
>     [<0000000046ccb106>] do_unimap_ioctl drivers/tty/vt/vt_ioctl.c:297 [inline]
>     [<0000000046ccb106>] vt_ioctl+0x863/0x12f0 drivers/tty/vt/vt_ioctl.c:1018
>     [<00000000db1577ff>] tty_ioctl+0x4cd/0xa30 drivers/tty/tty_io.c:2656
>     [<00000000e5cdf5ed>] vfs_ioctl fs/ioctl.c:48 [inline]
>     [<00000000e5cdf5ed>] ksys_ioctl+0xa6/0xd0 fs/ioctl.c:753
>     [<00000000fb4aa12c>] __do_sys_ioctl fs/ioctl.c:762 [inline]
>     [<00000000fb4aa12c>] __se_sys_ioctl fs/ioctl.c:760 [inline]
>     [<00000000fb4aa12c>] __x64_sys_ioctl+0x1a/0x20 fs/ioctl.c:760
>     [<00000000f561f260>] do_syscall_64+0x4c/0xe0 arch/x86/entry/common.c:384
>     [<0000000056206928>] entry_SYSCALL_64_after_hwframe+0x44/0xa9
>     BUG: leak checking failed
> 
> To fix this issue, we need to release the pointer p1 when the call of
> the function kmalloc_array fail.

This reminds me of:
commit 15b3cd8ef46ad1b100e0d3c7e38774f330726820
Author: Ben Hutchings <ben@decadent.org.uk>
Date:   Tue Jun 4 19:00:39 2019 +0100

    Revert "consolemap: Fix a memory leaking bug in
drivers/tty/vt/consolemap.c"

    This reverts commit 84ecc2f6eb1cb12e6d44818f94fa49b50f06e6ac.



So NACK.


Do we have some annotations for this instead?

> Signed-off-by: James Bond <jameslouisebond@gmail.com>
> ---
>  drivers/tty/vt/consolemap.c | 5 ++++-
>  1 file changed, 4 insertions(+), 1 deletion(-)
> 
> diff --git a/drivers/tty/vt/consolemap.c b/drivers/tty/vt/consolemap.c
> index 5947b54d92be..1e8d06c32ca1 100644
> --- a/drivers/tty/vt/consolemap.c
> +++ b/drivers/tty/vt/consolemap.c
> @@ -489,7 +489,10 @@ 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);
> +			return -ENOMEM;
> +		}
>  		memset(p2, 0xff, 64*sizeof(u16)); /* No glyphs for the characters (yet) */
>  	}

thanks,
-- 
js
suse labs

  reply index

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-08-09 22:14 James Bond
2020-08-10  5:16 ` Jiri Slaby [this message]
2020-08-10  7:51   ` Greg Kroah-Hartman
2020-08-10  8:14     ` Jiri Slaby

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=dd4ac5db-9ae7-fbf7-535b-c0d3fa098942@kernel.org \
    --to=jirislaby@kernel.org \
    --cc=akpm@linux-foundation.org \
    --cc=ben@decadent.org.uk \
    --cc=efremov@linux.com \
    --cc=gregkh@linuxfoundation.org \
    --cc=jameslouisebond@gmail.com \
    --cc=keescook@chromium.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=vbabka@suse.cz \
    --cc=walken@google.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

LKML Archive on lore.kernel.org

Archives are clonable:
	git clone --mirror https://lore.kernel.org/lkml/0 lkml/git/0.git
	git clone --mirror https://lore.kernel.org/lkml/1 lkml/git/1.git
	git clone --mirror https://lore.kernel.org/lkml/2 lkml/git/2.git
	git clone --mirror https://lore.kernel.org/lkml/3 lkml/git/3.git
	git clone --mirror https://lore.kernel.org/lkml/4 lkml/git/4.git
	git clone --mirror https://lore.kernel.org/lkml/5 lkml/git/5.git
	git clone --mirror https://lore.kernel.org/lkml/6 lkml/git/6.git
	git clone --mirror https://lore.kernel.org/lkml/7 lkml/git/7.git
	git clone --mirror https://lore.kernel.org/lkml/8 lkml/git/8.git
	git clone --mirror https://lore.kernel.org/lkml/9 lkml/git/9.git

	# If you have public-inbox 1.1+ installed, you may
	# initialize and index your mirror using the following commands:
	public-inbox-init -V2 lkml lkml/ https://lore.kernel.org/lkml \
		linux-kernel@vger.kernel.org
	public-inbox-index lkml

Example config snippet for mirrors

Newsgroup available over NNTP:
	nntp://nntp.lore.kernel.org/org.kernel.vger.linux-kernel


AGPL code for this site: git clone https://public-inbox.org/public-inbox.git