From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 15DC41EB1AA; Wed, 17 Sep 2025 12:49:37 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1758113377; cv=none; b=kPS3DMX+L+Y7g+Nbkr1Hjk0Non69woocC/IgIdB9CYD1WahLlJEFqGyupE7h2LMw+CEMDaIJWCs5CoyMKgk+KdDabw35Ji9EQ6494w+s1NB9VLK9TD7sBzsNYfd5heTlwAQRMymKJn7K6+8Q+O8uW5tezSl8TbFmCgM+TBm7zEE= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1758113377; c=relaxed/simple; bh=58NEyvoIVLq+5VzqkxJRAvHI6YXKcAFA8kdO5ObMViM=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=NijYS5f7FSzQrlZr5jbk4n2DveSQ2no7R8s8/Sp6IoWvAhzmm/BsEzOARX1D/8C/L0TjIN5ywO16I72C+qOE1/B/ELJWpTZIbW3iLbhqVbFpQoUYrndBSGPbuhMnK9Ij5NXWxHVyC7BK17wcYxi0SGdxY3NVEKFocUiq3DwZSDM= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.b=dXD8o1E3; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.b="dXD8o1E3" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 785D2C4CEF0; Wed, 17 Sep 2025 12:49:36 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1758113377; bh=58NEyvoIVLq+5VzqkxJRAvHI6YXKcAFA8kdO5ObMViM=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=dXD8o1E33dVK3Eg+jF5/qAidM3MFClY3ZvzR1zGsbl73MFyD3PNsvulrEfUWvZ69y xnXObCjlsYaN0fajdWNQBfCcLgNIqEf/xQVFItbKWdlrb6x3wlmwdQRoQh3O42v7a8 06qah8X/IQaRAm+KEC18vqnm4XD/PWKAUXEQKKew= From: Greg Kroah-Hartman To: stable@vger.kernel.org Cc: Greg Kroah-Hartman , patches@lists.linux.dev, Quanmin Yan , SeongJae Park , Kefeng Wang , ze zuo , Andrew Morton Subject: [PATCH 6.12 066/140] mm/damon/lru_sort: avoid divide-by-zero in damon_lru_sort_apply_parameters() Date: Wed, 17 Sep 2025 14:33:58 +0200 Message-ID: <20250917123345.918036138@linuxfoundation.org> X-Mailer: git-send-email 2.51.0 In-Reply-To: <20250917123344.315037637@linuxfoundation.org> References: <20250917123344.315037637@linuxfoundation.org> User-Agent: quilt/0.68 X-stable: review X-Patchwork-Hint: ignore Precedence: bulk X-Mailing-List: patches@lists.linux.dev List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit 6.12-stable review patch. If anyone has any objections, please let me know. ------------------ From: Quanmin Yan commit 711f19dfd783ffb37ca4324388b9c4cb87e71363 upstream. Patch series "mm/damon: avoid divide-by-zero in DAMON module's parameters application". DAMON's RECLAIM and LRU_SORT modules perform no validation on user-configured parameters during application, which may lead to division-by-zero errors. Avoid the divide-by-zero by adding validation checks when DAMON modules attempt to apply the parameters. This patch (of 2): During the calculation of 'hot_thres' and 'cold_thres', either 'sample_interval' or 'aggr_interval' is used as the divisor, which may lead to division-by-zero errors. Fix it by directly returning -EINVAL when such a case occurs. Additionally, since 'aggr_interval' is already required to be set no smaller than 'sample_interval' in damon_set_attrs(), only the case where 'sample_interval' is zero needs to be checked. Link: https://lkml.kernel.org/r/20250827115858.1186261-2-yanquanmin1@huawei.com Fixes: 40e983cca927 ("mm/damon: introduce DAMON-based LRU-lists Sorting") Signed-off-by: Quanmin Yan Reviewed-by: SeongJae Park Cc: Kefeng Wang Cc: ze zuo Cc: [6.0+] Signed-off-by: Andrew Morton Signed-off-by: Greg Kroah-Hartman --- mm/damon/lru_sort.c | 5 +++++ 1 file changed, 5 insertions(+) --- a/mm/damon/lru_sort.c +++ b/mm/damon/lru_sort.c @@ -198,6 +198,11 @@ static int damon_lru_sort_apply_paramete if (err) return err; + if (!damon_lru_sort_mon_attrs.sample_interval) { + err = -EINVAL; + goto out; + } + err = damon_set_attrs(ctx, &damon_lru_sort_mon_attrs); if (err) goto out;