[vz7,1/2] tty/vt: use kvmalloc for screenbuffer allocation

Submitted by Oleg Babin on May 8, 2018, 12:27 p.m.

Details

Message ID 1525782474-61514-1-git-send-email-obabin@virtuozzo.com
State New
Series "Series without cover letter"
Headers show

Commit Message

Oleg Babin May 8, 2018, 12:27 p.m.
Console driver allocates a screenbuffer with kmalloc(). The
size of the buffer can be up to 32768 bytes which is the 3rd
memory order.

Use kvmalloc() for screenbuffer allocation to fallback to vmalloc()
in case of high order page is not available at the moment.

https://jira.sw.ru/browse/HCI-53
Signed-off-by: Oleg Babin <obabin@virtuozzo.com>
---
 drivers/tty/vt/vt.c | 10 +++++-----
 1 file changed, 5 insertions(+), 5 deletions(-)

Patch hide | download patch | download mbox

diff --git a/drivers/tty/vt/vt.c b/drivers/tty/vt/vt.c
index fbc6290..9408a69 100644
--- a/drivers/tty/vt/vt.c
+++ b/drivers/tty/vt/vt.c
@@ -787,7 +787,7 @@  int vc_allocate(unsigned int currcons)	/* return 0 on success */
 	    visual_init(vc, currcons, 1);
 	    if (!*vc->vc_uni_pagedir_loc)
 		con_set_default_unimap(vc);
-	    vc->vc_screenbuf = kmalloc(vc->vc_screenbuf_size, GFP_KERNEL);
+	    vc->vc_screenbuf = kvmalloc(vc->vc_screenbuf_size, GFP_KERNEL);
 	    if (!vc->vc_screenbuf) {
 		kfree(vc);
 		vc_cons[currcons].d = NULL;
@@ -871,7 +871,7 @@  static int vc_do_resize(struct tty_struct *tty, struct vc_data *vc,
 	if (new_cols == vc->vc_cols && new_rows == vc->vc_rows)
 		return 0;
 
-	newscreen = kmalloc(new_screen_size, GFP_USER);
+	newscreen = kvmalloc(new_screen_size, GFP_USER);
 	if (!newscreen)
 		return -ENOMEM;
 
@@ -880,7 +880,7 @@  static int vc_do_resize(struct tty_struct *tty, struct vc_data *vc,
 
 	err = resize_screen(vc, new_cols, new_rows, user);
 	if (err) {
-		kfree(newscreen);
+		kvfree(newscreen);
 		return err;
 	}
 
@@ -927,7 +927,7 @@  static int vc_do_resize(struct tty_struct *tty, struct vc_data *vc,
 	if (new_scr_end > new_origin)
 		scr_memsetw((void *)new_origin, vc->vc_video_erase_char,
 			    new_scr_end - new_origin);
-	kfree(vc->vc_screenbuf);
+	kvfree(vc->vc_screenbuf);
 	vc->vc_screenbuf = newscreen;
 	vc->vc_screenbuf_size = new_screen_size;
 	set_origin(vc);
@@ -1010,7 +1010,7 @@  struct vc_data *vc_deallocate(unsigned int currcons)
 		vc->vc_sw->con_deinit(vc);
 		put_pid(vc->vt_pid);
 		module_put(vc->vc_sw->owner);
-		kfree(vc->vc_screenbuf);
+		kvfree(vc->vc_screenbuf);
 		vc_cons[currcons].d = NULL;
 	}
 	return vc;

Comments

Andrey Ryabinin May 8, 2018, 1:18 p.m.
On 05/08/2018 03:27 PM, Oleg Babin wrote:
> Console driver allocates a screenbuffer with kmalloc(). The
> size of the buffer can be up to 32768 bytes which is the 3rd
> memory order.
> 
> Use kvmalloc() for screenbuffer allocation to fallback to vmalloc()
> in case of high order page is not available at the moment.
> 
> https://jira.sw.ru/browse/HCI-53
> Signed-off-by: Oleg Babin <obabin@virtuozzo.com>

Reviewed-by: Andrey Ryabinin <aryabinin@virtuozzo.com>

In addition to this will 32b2921e6a7461fe63b71217067a6cf4bddb132f as well,
otherwise it's become too easy for userspace to consume gigabytes of vmalloc.