From: Jiajian Ye Date: Fri, 25 Mar 2022 01:09:23 +0000 (-0700) Subject: tools/vm/page_owner_sort.c: add a security check X-Git-Tag: v5.18-rc1~120^2~97 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=56465a38305f22bca3469c2738d7320a0c333e72;p=thirdparty%2Fkernel%2Flinux.git tools/vm/page_owner_sort.c: add a security check Add a security check after using malloc() to allocate memory. Link: https://lkml.kernel.org/r/20220301151438.166118-2-yejiajian2018@email.szu.edu.cn Signed-off-by: Jiajian Ye Cc: Stephen Rothwell Cc: Yinan Zhang Cc: Yixuan Cao Cc: Zhenliang Wei Signed-off-by: Andrew Morton Signed-off-by: Linus Torvalds --- diff --git a/tools/vm/page_owner_sort.c b/tools/vm/page_owner_sort.c index 79d69c3b84edb..69fb6ca7c0b7f 100644 --- a/tools/vm/page_owner_sort.c +++ b/tools/vm/page_owner_sort.c @@ -217,7 +217,13 @@ static void add_list(char *buf, int len) printf("max_size too small??\n"); exit(1); } + list[list_size].txt = malloc(len+1); + if (!list[list_size].txt) { + printf("Out of memory\n"); + exit(1); + } + list[list_size].len = len; list[list_size].num = 1; list[list_size].page_num = get_page_num(buf);