Received: by 2002:a05:6a10:9afc:0:0:0:0 with SMTP id t28csp1584pxm; Tue, 1 Mar 2022 13:33:59 -0800 (PST) X-Google-Smtp-Source: ABdhPJz6LXtA4/rO8JUXThXL/Q97tRv6cfPsO/sM6WXuxBAhwvw30OKChx40kbfrdmOQ4mHNFCdN X-Received: by 2002:a65:6e4b:0:b0:373:8350:cef3 with SMTP id be11-20020a656e4b000000b003738350cef3mr23327403pgb.219.1646170439644; Tue, 01 Mar 2022 13:33:59 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1646170439; cv=none; d=google.com; s=arc-20160816; b=tEbMotii0JwQXPaApiVg1wxh5InSmuIvreVTRTKBysjis9ZTtbKEn7NsC/KWusWCs7 994HObH+x/MouXtam9H0N3J0CXeibATVHxN1OP/VoX/0Vs1bG30sZpFth8Ssap7n05lH jdd41uMrDhT7df4fS5cDp1rYDip2KyyXd33tyO6xxmsWAlA2D5KJvy/Kl9FldV5Xx1Xv cWPHQcONKJt/vQo+12fO229jP0r9MsDFpnI81KAlPKWhje0x0d7BmdD+gatTHqIqdmqi zCKMoFwhcy7biQ2VnEHEot/2FdJJmK3og6pPaVGsv9LpScnQXYJLsVDEqvcn9QxhA6AU tR5A== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:message-id:date:subject:cc:to:from :dkim-signature; bh=umGt8PsgZG/C7p7lxMOHmzeS4ILsxJ7YbaAxs7sEjKE=; b=nce2DmW0tUdtTaSYoPlJL+BqcplCo2E69lgQWQEdobeWIK7PcO4SBpPkKJYJDrlZTk HKIbrdO8f2xuuvBd697QMCp2ukMAMTRwx4/JsBkVGpGlNWoSXIsJgJjNacWKipu/SVHZ mrNMONZ7/piPfGYSWrdMHs9MpO7QuH4weia9eh2BJW1wcze96YJ/Cc9UYKC39jZcbxvh FcatGJ4YQUKaiM9vkkjydks5zcB5UhcaKwyT+9n48119CHIiVW6eXk3TvRxxWoQRZNtl wtNEgaQaMYbOGm5uTXCSCkWQpciZtFDRksATcVWRmhLZvvqCNq/9/ElOppYGLFC2TPJM Kv7g== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=boS0m3SG; 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 j34-20020a632322000000b00373d238bf64si13049757pgj.385.2022.03.01.13.33.40; Tue, 01 Mar 2022 13:33:59 -0800 (PST) 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=boS0m3SG; 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 S237118AbiCAS5L (ORCPT + 99 others); Tue, 1 Mar 2022 13:57:11 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:60750 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S237104AbiCAS5J (ORCPT ); Tue, 1 Mar 2022 13:57:09 -0500 Received: from ams.source.kernel.org (ams.source.kernel.org [145.40.68.75]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 05FDE60CDB for ; Tue, 1 Mar 2022 10:56:28 -0800 (PST) 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 8D0C7B81CB0 for ; Tue, 1 Mar 2022 18:56:26 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id CFFE8C340EE; Tue, 1 Mar 2022 18:56:24 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1646160985; bh=usfHRRJQxk5ZPBBjY5lM+QOMJJruSA25LZ2RYqAjsk8=; h=From:To:Cc:Subject:Date:From; b=boS0m3SGvvVYdSDPMbk2vmPxKby2L4qP2A0CRlh1JLasCXH718Gwc5zuNqHnFHDDo 1bS2HQCfW730Eb+VPYoyxy7qyvC0X4GRiFaOTQiRRcwzEnto9FfSjh8juc7OiGgVWa 7kCGiW0awUpro2719e0IwyMHrcZDNvpDf2PCYtkGX8RIYBeLD4rYxYmYOo5LCJcztA 6Dc+k0R8Jhd0M5cN49XzxpxULfU/yV76oE8PlIKTpI4uxs+MS+vyLv2pLZinng0u12 9ZoVseoreMsjOmJZXMzMLgWxjewxjnyfBXMDH0DTSdkA4bV/FKZPfrw37po1BURHgz Zaw4XH5rzM/1g== From: SeongJae Park To: akpm@linux-foundation.org Cc: linux-mm@kvack.org, linux-kernel@vger.kernel.org, SeongJae Park Subject: [PATCH for-mm] mm/damon/sysfs: Fix out-of-bound array access for wmark_metric_strs[] Date: Tue, 1 Mar 2022 18:56:19 +0000 Message-Id: <20220301185619.2904-1-sj@kernel.org> X-Mailer: git-send-email 2.17.1 X-Spam-Status: No, score=-7.5 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 7a8630be880e ("mm/damon/sysfs: support DAMOS watermarks") on -mm tree which introduced by a patch[1] titled mm-damon-sysfs-support-damos-watermarks.patch allows out-of-bound access to damon_sysfs_wmark_metric_strs[] array due to wrong bound check. This commit fixes the wrong bound check. The issue has found by Coverity report for linux-next. [1] https://www.ozlabs.org/~akpm/mmotm/broken-out/mm-damon-sysfs-support-damos-watermarks.patch Addresses-Coverity: ("Out-of-bounds read") Fixes: 7a8630be880e ("mm/damon/sysfs: support DAMOS watermarks") Signed-off-by: SeongJae Park --- mm/damon/sysfs.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/mm/damon/sysfs.c b/mm/damon/sysfs.c index 32a9d21c0db5..fda2506c676f 100644 --- a/mm/damon/sysfs.c +++ b/mm/damon/sysfs.c @@ -266,7 +266,7 @@ static ssize_t metric_store(struct kobject *kobj, struct kobj_attribute *attr, struct damon_sysfs_watermarks, kobj); enum damos_wmark_metric metric; - for (metric = 0; metric <= NR_DAMOS_WMARK_METRICS; metric++) { + for (metric = 0; metric < NR_DAMOS_WMARK_METRICS; metric++) { if (sysfs_streq(buf, damon_sysfs_wmark_metric_strs[metric])) { watermarks->metric = metric; return count; -- 2.17.1