From: Jiajian Ye yejiajian2018@email.szu.edu.cn
mainline inclusion from mainline-v5.18-rc1 commit 56465a38305f22bca3469c2738d7320a0c333e72 category: bugfix bugzilla: https://gitee.com/openeuler/kernel/issues/I9GSSR
Reference: https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/commit/?i...
--------------------------------
Add a security check after using malloc() to allocate memory.
Link: https://lkml.kernel.org/r/20220301151438.166118-2-yejiajian2018@email.szu.ed... Signed-off-by: Jiajian Ye yejiajian2018@email.szu.edu.cn Cc: Stephen Rothwell sfr@canb.auug.org.au Cc: Yinan Zhang zhangyinan2019@email.szu.edu.cn Cc: Yixuan Cao caoyixuan2019@email.szu.edu.cn Cc: Zhenliang Wei weizhenliang@huawei.com Signed-off-by: Andrew Morton akpm@linux-foundation.org Signed-off-by: Linus Torvalds torvalds@linux-foundation.org Signed-off-by: Jinjiang Tu tujinjiang@huawei.com --- tools/vm/page_owner_sort.c | 6 ++++++ 1 file changed, 6 insertions(+)
diff --git a/tools/vm/page_owner_sort.c b/tools/vm/page_owner_sort.c index 79d69c3b84ed..69fb6ca7c0b7 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);