From patchwork Tue Sep 13 21:54:20 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: SeongJae Park X-Patchwork-Id: 12975402 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 4C25DECAAD8 for ; Tue, 13 Sep 2022 21:54:41 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id A29B86B0071; Tue, 13 Sep 2022 17:54:40 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 9D8FB6B0073; Tue, 13 Sep 2022 17:54:40 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 8C75A8D0001; Tue, 13 Sep 2022 17:54:40 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0016.hostedemail.com [216.40.44.16]) by kanga.kvack.org (Postfix) with ESMTP id 7CA2B6B0071 for ; Tue, 13 Sep 2022 17:54:40 -0400 (EDT) Received: from smtpin01.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay10.hostedemail.com (Postfix) with ESMTP id 525CEC049E for ; Tue, 13 Sep 2022 21:54:40 +0000 (UTC) X-FDA: 79908417120.01.71357A5 Received: from ams.source.kernel.org (ams.source.kernel.org [145.40.68.75]) by imf17.hostedemail.com (Postfix) with ESMTP id 0655640096 for ; Tue, 13 Sep 2022 21:54:39 +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 ams.source.kernel.org (Postfix) with ESMTPS id 22B3DB810EE; Tue, 13 Sep 2022 21:54:38 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 6D5B9C433D6; Tue, 13 Sep 2022 21:54:36 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1663106076; bh=ycEw7JynDo34GmuIv/leSXfixPw6mJwy50s6KoPFIzM=; h=From:To:Cc:Subject:Date:From; b=JvOyqRNlgDve60ECg+sQGQiPkA6QZcU9G3NcJ+ZzsEqoFQ33voD7dPMvyEt0QrwzW fDRIpRFhpBTSlZ5J9IwHToYQ6syJZMFAJdWA4LTahz60WyVw2sPZX/DF4qbdK1AGn9 rssdNERTeO8OfvHjoWfWEZhq9eALOSiTvbfCzB7Dxt77ieoIwgUNpcGR4TX0Tw7IiN QbsXH5x+x1G1iUolYqRRadZNHpZ8rjWUmmrOuonI2KCzf6mG1i+sB2M+mTAMUhEhaY TI8swIrECVc+dkaDELvgwRudXjEyuTOkQkOJuVIaKMAtqtAlAKRm9BNK/orUYv47tn RRdjCJmk5rYLw== From: SeongJae Park To: akpm@linux-foundation.org Cc: damon@lists.linux.dev, linux-mm@kvack.org, linux-kernel@vger.kernel.org, SeongJae Park Subject: [PATCH for-mm-unstable] mm/damon/core: handle error from 'damon_fill_regions_holes()' Date: Tue, 13 Sep 2022 21:54:20 +0000 Message-Id: <20220913215420.57761-1-sj@kernel.org> X-Mailer: git-send-email 2.25.1 MIME-Version: 1.0 ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1663106080; a=rsa-sha256; cv=none; b=rXDuXkSwa/fe6ERICC/Nj6fGnIHx8eNcUPivAoyGa5hnhTvdGRfsAASqWpAC3Yi1zhRw6D Ezl6LX7Rga2I7rMCa/owJ05uPqFJ55etWkh9BdipH8ywQCkXfLjF06anX2esB1G+BjCEDU WbqZJak4mDsFFlbqK5B/JwYXkUkFnow= ARC-Authentication-Results: i=1; imf17.hostedemail.com; dkim=pass header.d=kernel.org header.s=k20201202 header.b=JvOyqRNl; dmarc=pass (policy=none) header.from=kernel.org; spf=pass (imf17.hostedemail.com: domain of sj@kernel.org designates 145.40.68.75 as permitted sender) smtp.mailfrom=sj@kernel.org ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1663106080; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-transfer-encoding:content-transfer-encoding: in-reply-to:references:dkim-signature; bh=XmlYbaEGJc+LlSm0Hl/MlVo5GB4vh82klUV6jT04h/Y=; b=Yym91Hza/A4cgbYThpepGl0d0OOlyZo2SiNWSlfjKIit3rIKIne41G6gUGSDS9n/1vKTQV Dh7FUwDY/gQz6E6lkPHcSXMkWNAVeBB2SiNWsdfF1bHA0oju3Jq+xnZ/TiWY1vrl8Y9IH3 PavUL+fo6N2fPqKwdUxrs9igr5Og4B4= X-Rspam-User: Authentication-Results: imf17.hostedemail.com; dkim=pass header.d=kernel.org header.s=k20201202 header.b=JvOyqRNl; dmarc=pass (policy=none) header.from=kernel.org; spf=pass (imf17.hostedemail.com: domain of sj@kernel.org designates 145.40.68.75 as permitted sender) smtp.mailfrom=sj@kernel.org X-Rspamd-Server: rspam11 X-Stat-Signature: 1akf1yh7m6cipmerd7s8msfpqe183dws X-Rspamd-Queue-Id: 0655640096 X-HE-Tag: 1663106079-400810 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: Commit 91fc6af21c61 ("mm/damon/core: avoid holes in newly set monitoring target ranges") in mm-unstable tree introduces 'damon_fill_regions_holes()', which does not check failures of 'damon_new_region()' call, so NULL dereferencing is available. This commit fixes the issue by checking failure of the function and returning an error code. Reported-by: Coverity Static Analyzer CID 1524904 Fixes: 91fc6af21c61 ("mm/damon/core: avoid holes in newly set monitoring target ranges") in mm-unstable Signed-off-by: SeongJae Park --- mm/damon/core.c | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/mm/damon/core.c b/mm/damon/core.c index 520d3bb22d91..3ef3d13e504b 100644 --- a/mm/damon/core.c +++ b/mm/damon/core.c @@ -173,7 +173,7 @@ static bool damon_intersect(struct damon_region *r, /* * Fill holes in regions with new regions. */ -static void damon_fill_regions_holes(struct damon_region *first, +static int damon_fill_regions_holes(struct damon_region *first, struct damon_region *last, struct damon_target *t) { struct damon_region *r = first; @@ -186,9 +186,12 @@ static void damon_fill_regions_holes(struct damon_region *first, next = damon_next_region(r); if (r->ar.end != next->ar.start) { newr = damon_new_region(r->ar.end, next->ar.start); + if (!newr) + return -ENOMEM; damon_insert_region(newr, r, next, t); } } + return 0; } /* @@ -207,6 +210,7 @@ int damon_set_regions(struct damon_target *t, struct damon_addr_range *ranges, { struct damon_region *r, *next; unsigned int i; + int err; /* Remove regions which are not in the new ranges */ damon_for_each_region_safe(r, next, t) { @@ -251,7 +255,9 @@ int damon_set_regions(struct damon_target *t, struct damon_addr_range *ranges, last->ar.end = ALIGN(range->end, DAMON_MIN_REGION); /* fill possible holes in the range */ - damon_fill_regions_holes(first, last, t); + err = damon_fill_regions_holes(first, last, t); + if (err) + return err; } } return 0;