Skip to content

Commit 3db42c7

Browse files
Haoxiang LiVasily Gorbik
authored andcommitted
s390/sclp: Add check for get_zeroed_page()
Add check for the return value of get_zeroed_page() in sclp_console_init() to prevent null pointer dereference. Furthermore, to solve the memory leak caused by the loop allocation, add a free helper to do the free job. Signed-off-by: Haoxiang Li <[email protected]> Acked-by: Heiko Carstens <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Vasily Gorbik <[email protected]>
1 parent f0f6db9 commit 3db42c7

File tree

1 file changed

+17
-0
lines changed

1 file changed

+17
-0
lines changed

drivers/s390/char/sclp_con.c

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -263,6 +263,19 @@ static struct console sclp_console =
263263
.index = 0 /* ttyS0 */
264264
};
265265

266+
/*
267+
* Release allocated pages.
268+
*/
269+
static void __init __sclp_console_free_pages(void)
270+
{
271+
struct list_head *page, *p;
272+
273+
list_for_each_safe(page, p, &sclp_con_pages) {
274+
list_del(page);
275+
free_page((unsigned long)page);
276+
}
277+
}
278+
266279
/*
267280
* called by console_init() in drivers/char/tty_io.c at boot-time.
268281
*/
@@ -282,6 +295,10 @@ sclp_console_init(void)
282295
/* Allocate pages for output buffering */
283296
for (i = 0; i < sclp_console_pages; i++) {
284297
page = (void *) get_zeroed_page(GFP_KERNEL | GFP_DMA);
298+
if (!page) {
299+
__sclp_console_free_pages();
300+
return -ENOMEM;
301+
}
285302
list_add_tail(page, &sclp_con_pages);
286303
}
287304
sclp_conbuf = NULL;

0 commit comments

Comments
 (0)