From patchwork Fri Mar 25 01:09:23 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andrew Morton X-Patchwork-Id: 12791116 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id 17834C433EF for ; Fri, 25 Mar 2022 01:09:26 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id A1C558D000A; Thu, 24 Mar 2022 21:09:25 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 9CB518D0009; Thu, 24 Mar 2022 21:09:25 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 8BAF38D000A; Thu, 24 Mar 2022 21:09:25 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (relay.hostedemail.com [64.99.140.28]) by kanga.kvack.org (Postfix) with ESMTP id 7D0128D0009 for ; Thu, 24 Mar 2022 21:09:25 -0400 (EDT) Received: from smtpin05.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay07.hostedemail.com (Postfix) with ESMTP id 4818A208CA for ; Fri, 25 Mar 2022 01:09:25 +0000 (UTC) X-FDA: 79281125490.05.7CC4459 Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) by imf30.hostedemail.com (Postfix) with ESMTP id C9E0C80024 for ; Fri, 25 Mar 2022 01:09:24 +0000 (UTC) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by dfw.source.kernel.org (Postfix) with ESMTPS id 47288617ED; Fri, 25 Mar 2022 01:09:24 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 9F96FC340ED; Fri, 25 Mar 2022 01:09:23 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linux-foundation.org; s=korg; t=1648170563; bh=I4n0cuNWnNTimok2wV5y+1RxmAXDYMxo3HM9EsyIPJQ=; h=Date:To:From:In-Reply-To:Subject:From; b=WRVkTICiONqznF4aeqYSAu1Gu3yYiUGMYAqmwjqnocvozIYJAdS6BagrFrXkiqgwM MPPsxF0Mnc2n67T/OCjvlEJeAaNZbDrDkE6wrOzu+M4gFy9npNNOrttMkMOLhmgcnN HPz5A4DRNemoFf9zrU10R3e6OOF/PSgPuugV/ycU= Date: Thu, 24 Mar 2022 18:09:23 -0700 To: zhangyinan2019@email.szu.edu.cn,weizhenliang@huawei.com,sfr@canb.auug.org.au,caoyixuan2019@email.szu.edu.cn,yejiajian2018@email.szu.edu.cn,akpm@linux-foundation.org,patches@lists.linux.dev,linux-mm@kvack.org,mm-commits@vger.kernel.org,torvalds@linux-foundation.org,akpm@linux-foundation.org From: Andrew Morton In-Reply-To: <20220324180758.96b1ac7e17675d6bc474485e@linux-foundation.org> Subject: [patch 016/114] tools/vm/page_owner_sort.c: add a security check Message-Id: <20220325010923.9F96FC340ED@smtp.kernel.org> X-Stat-Signature: ow8eybz7r7zkcu4o6ycxaa4uijjx6mi7 Authentication-Results: imf30.hostedemail.com; dkim=pass header.d=linux-foundation.org header.s=korg header.b=WRVkTICi; dmarc=none; spf=pass (imf30.hostedemail.com: domain of akpm@linux-foundation.org designates 139.178.84.217 as permitted sender) smtp.mailfrom=akpm@linux-foundation.org X-Rspam-User: X-Rspamd-Server: rspam11 X-Rspamd-Queue-Id: C9E0C80024 X-HE-Tag: 1648170564-921999 X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: From: Jiajian Ye Subject: 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 --- tools/vm/page_owner_sort.c | 6 ++++++ 1 file changed, 6 insertions(+) --- a/tools/vm/page_owner_sort.c~tools-vm-page_owner_sortc-add-a-security-check +++ a/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);