Received: by 2002:a05:6358:489b:b0:bb:da1:e618 with SMTP id x27csp7152274rwn; Tue, 13 Sep 2022 14:58:47 -0700 (PDT) X-Google-Smtp-Source: AA6agR6B+8SI8FCLShGHQO4UrN0ahhckLsxUmF1+ciGYqrAo2CJZNa4HuaOhumVPdNp3xX44CQMT X-Received: by 2002:a05:6402:d05:b0:425:b5c8:faeb with SMTP id eb5-20020a0564020d0500b00425b5c8faebmr27234107edb.273.1663106327695; Tue, 13 Sep 2022 14:58:47 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1663106327; cv=none; d=google.com; s=arc-20160816; b=RhqbRti3Wij5t4ApXqA6znxNZD63obGqVSLWSnoYeBTsl2Chzx3/YNcsYKYfEJQyXS XeKTIz1LEyhKIIKbm/hIllE43hk/GPJ0RSJf+Orc1bLXd+isqnKrX1wvFCCNnr8nilIh sR9dp+bBkhs5L7HQh5dHqit5+tknQGY16v++QY7Q87NfK7CH2bnclLU8GeBHn85Hv6np XB40bsQvtRD5OZ+q9PJmKRF/4qYr495K6NzQdJ5LhGVpR7HdU6dalLZ49AmVsmNhyp/E I4i5N2PVnWneKAC8tgfjHOLevrgrId/UapfKRsgZ7I75TN9QR8eo+6fvpJjiml+2L9o/ u7rw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :message-id:date:subject:cc:to:from:dkim-signature; bh=XmlYbaEGJc+LlSm0Hl/MlVo5GB4vh82klUV6jT04h/Y=; b=e2s0doDOgfNfDgAf4myqNlo5Zmnl1SqFniA2wdv+f09UVIp73nHE+SsL5ZlKPEBp8h 2AheqGE1UiTbLWhSHLSVCPFEX/ZkqrqJgJo7nwHuJ6HwXhiwMkiehoV1PJI05r4d3Mgx Pn8L6FrahnVvAHtRqogs+PupM06NOEQ8q7Ph5FiJKp4LBLD1aeU+pmQQXtTjyhaYE8DZ yC4x3xRQ2WV104Nz7fQVnIwAmwzo8OsGIUHdSzsIdCBxd+PGAnhX9fTsBB/LmwNfsEwQ 80NEOUZBNki4+Wg/u33U6TDMe2ImOzVl2VMp6dD1EnUUrxcSqGj6yFx10fIk0ftGcpmJ OAqw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=JvOyqRNl; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id q17-20020aa7da91000000b0044d9f1406b7si8720586eds.157.2022.09.13.14.58.21; Tue, 13 Sep 2022 14:58:47 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=JvOyqRNl; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229670AbiIMVy7 (ORCPT + 99 others); Tue, 13 Sep 2022 17:54:59 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:47654 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229717AbiIMVyk (ORCPT ); Tue, 13 Sep 2022 17:54:40 -0400 Received: from ams.source.kernel.org (ams.source.kernel.org [145.40.68.75]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 74E264331E for ; Tue, 13 Sep 2022 14:54:39 -0700 (PDT) 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 220ECB810EA for ; 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 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-7.1 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_HI, SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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; -- 2.25.1