From patchwork Wed Mar 2 18:02:52 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Colin Ian King X-Patchwork-Id: 12766484 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 9F79BC433FE for ; Wed, 2 Mar 2022 18:02:56 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 340358D0003; Wed, 2 Mar 2022 13:02:56 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 2ED6C8D0001; Wed, 2 Mar 2022 13:02:56 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 1B65B8D0003; Wed, 2 Mar 2022 13:02:56 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (relay.a.hostedemail.com [64.99.140.24]) by kanga.kvack.org (Postfix) with ESMTP id 0F9438D0001 for ; Wed, 2 Mar 2022 13:02:56 -0500 (EST) Received: from smtpin05.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay10.hostedemail.com (Postfix) with ESMTP id C62281E61 for ; Wed, 2 Mar 2022 18:02:55 +0000 (UTC) X-FDA: 79200217110.05.88DACFD Received: from mail-wr1-f43.google.com (mail-wr1-f43.google.com [209.85.221.43]) by imf12.hostedemail.com (Postfix) with ESMTP id D0C5A4002F for ; Wed, 2 Mar 2022 18:02:54 +0000 (UTC) Received: by mail-wr1-f43.google.com with SMTP id p9so4005672wra.12 for ; Wed, 02 Mar 2022 10:02:54 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=SLLfjD749xSnL6xg2oAyC7SKFLVc/brW6p/9hUhDG8k=; b=YzBwb+1Gi/Isd4K6+XoKfHngkObvdDjfOMeTAf9cbaKPpz/n9eGDMAufz7dq4Q8Wlf uCJebMTuBQJnRvgFsS0ByF72owbw9eSp1477MHGZRq7Up3jkkfHVWhIrxbNK+6sbvf/Y SbbNQ3arejFoEpc0YyexG0QgJ9jEkrY5qUumnx/KJt9nrJR+E87NT5eaNkDUZ5/428eI nTgLenBBT7H9nYdMdKDDrB1p71yuLqAGNtiv5M12lokHmGrbNaDIdrd/sZ1Pxn/56+5/ Vp3hR0R2vgIeV/CdNBG6xsvLOHFmU9bnMtYlq8lefHRs/zx+Sh5KdSv262if3fo7H8eD y9sQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=SLLfjD749xSnL6xg2oAyC7SKFLVc/brW6p/9hUhDG8k=; b=mMxfqptMpYGz/UK84hOD0Ol2WmLq0SioAIZVtjGCy0PMySIUVgIvaTdU16ALzJXHS1 uO8eLYQBwh1tdzbtVc5/eQREZgsYGevmjojHiEG9ZPr0SVCHayDmLTbLtt01+f5XbuFK XJdRqMx2qQeJURaM3ksIYE8HV34dmYMOVqgkcIGWkMNVjweUxPiCvKqN4ADjXe5E427y QbcTWUvtxCzrNORYf/JsIJzBgG4Mfnok4v9P6ZSYUxQibWXxysL7rLJrLLsImflrG7CO z4mr2SYHTmzsb0vR73MT83rH+/9dORm3jBtVJ1HGQWC4UHPJtf0X+9v51I4PhbdCH5lg IFPA== X-Gm-Message-State: AOAM531Ci92jge3h38ZTGp/iO8bLJp0KdQN3GXekals5G8gOsHrwgk2X 0yLO5OF/6O/aWeGI+waWmCs= X-Google-Smtp-Source: ABdhPJxHQ7Py2A1/Xrj9k1ikIUZwbzyE7O+78XWO4g23mCyJzGBqZytwDf8Rr/KkRHc+5rXedOYG1w== X-Received: by 2002:adf:eb44:0:b0:1f0:483c:f015 with SMTP id u4-20020adfeb44000000b001f0483cf015mr1334771wrn.397.1646244173507; Wed, 02 Mar 2022 10:02:53 -0800 (PST) Received: from localhost (cpc154979-craw9-2-0-cust193.16-3.cable.virginm.net. [80.193.200.194]) by smtp.gmail.com with ESMTPSA id k17-20020a05600c1c9100b00386bb6e9c50sm1068631wms.45.2022.03.02.10.02.52 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 02 Mar 2022 10:02:53 -0800 (PST) From: Colin Ian King To: SeongJae Park , Andrew Morton , Stephen Rothwell , linux-mm@kvack.org Cc: kernel-janitors@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH] mm/damon/sysfs: Fix an array out-of-bounds read error due Date: Wed, 2 Mar 2022 18:02:52 +0000 Message-Id: <20220302180252.1099406-1-colin.i.king@gmail.com> X-Mailer: git-send-email 2.34.1 MIME-Version: 1.0 X-Rspamd-Queue-Id: D0C5A4002F X-Stat-Signature: co839qi74oe5ab6nzmug3witr9wm9thh X-Rspam-User: Authentication-Results: imf12.hostedemail.com; dkim=pass header.d=gmail.com header.s=20210112 header.b=YzBwb+1G; dmarc=pass (policy=none) header.from=gmail.com; spf=pass (imf12.hostedemail.com: domain of colin.i.king@gmail.com designates 209.85.221.43 as permitted sender) smtp.mailfrom=colin.i.king@gmail.com X-Rspamd-Server: rspam03 X-HE-Tag: 1646244174-264475 X-Bogosity: Ham, tests=bogofilter, spamicity=0.000522, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: There is an off-by-one error in the upper limit to a for-loop that causes an out-of-bounds read error on the array damon_sysfs_wmark_metric_strs. Fix the comparison by replacing the <= operator with <. Fixes: 8f614da9d987 ("mm/damon/sysfs: support DAMOS watermarks") Signed-off-by: Colin Ian King --- 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;