Skip to content

Commit 9a98e7a

Browse files
npitregregkh
authored andcommitted
vt: don't use kmalloc() for the unicode screen buffer
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>
1 parent 66bb1c9 commit 9a98e7a

1 file changed

Lines changed: 3 additions & 2 deletions

File tree

drivers/tty/vt/vt.c

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,7 @@
8181
#include <linux/errno.h>
8282
#include <linux/kd.h>
8383
#include <linux/slab.h>
84+
#include <linux/vmalloc.h>
8485
#include <linux/major.h>
8586
#include <linux/mm.h>
8687
#include <linux/console.h>
@@ -350,7 +351,7 @@ static struct uni_screen *vc_uniscr_alloc(unsigned int cols, unsigned int rows)
350351
/* allocate everything in one go */
351352
memsize = cols * rows * sizeof(char32_t);
352353
memsize += rows * sizeof(char32_t *);
353-
p = kmalloc(memsize, GFP_KERNEL);
354+
p = vmalloc(memsize);
354355
if (!p)
355356
return NULL;
356357

@@ -366,7 +367,7 @@ static struct uni_screen *vc_uniscr_alloc(unsigned int cols, unsigned int rows)
366367

367368
static void vc_uniscr_set(struct vc_data *vc, struct uni_screen *new_uniscr)
368369
{
369-
kfree(vc->vc_uni_screen);
370+
vfree(vc->vc_uni_screen);
370371
vc->vc_uni_screen = new_uniscr;
371372
}
372373

0 commit comments

Comments
 (0)