All of lore.kernel.org
 help / color / mirror / Atom feed
From: Nicolas Pitre <nico@fluxnic.net>
To: gregkh@linuxfoundation.org
Cc: Chen Wandun <chenwandun@huawei.com>,
	Adam Borowski <kilobyte@angband.pl>,
	jslaby@suse.com, daniel.vetter@ffwll.ch, sam@ravnborg.org,
	b.zolnierkie@samsung.com, lukas@wunner.de, ghalat@redhat.com,
	linux-kernel@vger.kernel.org
Subject: [PATCH] vt: don't use kmalloc() for the unicode screen buffer
Date: Sat, 28 Mar 2020 17:59:25 -0400 (EDT)	[thread overview]
Message-ID: <nycvar.YSQ.7.76.2003281745280.2671@knanqh.ubzr> (raw)

Even if the actual screen size is bounded in vc_do_resize(), the unicode 
buffer is still a little more than twice the size of the glyph buffer
and may exceed MAX_ORDER down the kmalloc() path. This can be triggered
from user space.

Since there is no point having a physically contiguous buffer here, 
let's avoid the above issue as well as reducing pressure on high order
allocations by using vmalloc() instead.

Signed-off-by: Nicolas Pitre <nico@fluxnic.net>
Cc: <stable@vger.kernel.org>

diff --git a/drivers/tty/vt/vt.c b/drivers/tty/vt/vt.c
index 15d2769805..7c10edb648 100644
--- a/drivers/tty/vt/vt.c
+++ b/drivers/tty/vt/vt.c
@@ -350,7 +350,7 @@ static struct uni_screen *vc_uniscr_alloc(unsigned int cols, unsigned int rows)
 	/* allocate everything in one go */
 	memsize = cols * rows * sizeof(char32_t);
 	memsize += rows * sizeof(char32_t *);
-	p = kmalloc(memsize, GFP_KERNEL);
+	p = vmalloc(memsize);
 	if (!p)
 		return NULL;
 
@@ -366,7 +366,7 @@ static struct uni_screen *vc_uniscr_alloc(unsigned int cols, unsigned int rows)
 
 static void vc_uniscr_set(struct vc_data *vc, struct uni_screen *new_uniscr)
 {
-	kfree(vc->vc_uni_screen);
+	vfree(vc->vc_uni_screen);
 	vc->vc_uni_screen = new_uniscr;
 }
 

             reply	other threads:[~2020-03-28 21:59 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-03-28 21:59 Nicolas Pitre [this message]
2020-03-28 23:35 ` [PATCH] vt: don't use kmalloc() for the unicode screen buffer kbuild test robot
2020-03-28 23:35   ` kbuild test robot
2020-03-29  0:13 ` kbuild test robot
2020-03-29  0:13   ` kbuild test robot
2020-03-29  2:25 ` [PATCH v2] " Nicolas Pitre
2020-03-30 19:07   ` Sam Ravnborg
2020-03-31  8:43     ` Daniel Vetter
2020-03-31  9:30       ` Greg KH

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=nycvar.YSQ.7.76.2003281745280.2671@knanqh.ubzr \
    --to=nico@fluxnic.net \
    --cc=b.zolnierkie@samsung.com \
    --cc=chenwandun@huawei.com \
    --cc=daniel.vetter@ffwll.ch \
    --cc=ghalat@redhat.com \
    --cc=gregkh@linuxfoundation.org \
    --cc=jslaby@suse.com \
    --cc=kilobyte@angband.pl \
    --cc=linux-kernel@vger.kernel.org \
    --cc=lukas@wunner.de \
    --cc=sam@ravnborg.org \
    /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
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.