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 <[email protected]> Cc: <[email protected]> Acked-by: Sam Ravnborg <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Greg Kroah-Hartman <[email protected]>
1 parent 66bb1c9 commit 9a98e7a

File tree

1 file changed

+3
-2
lines changed

1 file changed

+3
-2
lines changed

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)