Skip to content

Commit

Permalink
vt: don't use kmalloc() for the unicode screen buffer
Browse files Browse the repository at this point in the history
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>
Acked-by: Sam Ravnborg <sam@ravnborg.org>
Link: https://lore.kernel.org/r/nycvar.YSQ.7.76.2003282214210.2671@knanqh.ubzr
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
  • Loading branch information
Nicolas Pitre authored and Greg Kroah-Hartman committed Apr 23, 2020
1 parent 66bb1c9 commit 9a98e7a
Showing 1 changed file with 3 additions and 2 deletions.
5 changes: 3 additions & 2 deletions drivers/tty/vt/vt.c
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,7 @@
#include <linux/errno.h>
#include <linux/kd.h>
#include <linux/slab.h>
#include <linux/vmalloc.h>
#include <linux/major.h>
#include <linux/mm.h>
#include <linux/console.h>
Expand Down Expand Up @@ -350,7 +351,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;

Expand All @@ -366,7 +367,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;
}

Expand Down

0 comments on commit 9a98e7a

Please sign in to comment.