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 421B91C07C9; Tue, 15 Oct 2024 13:02:12 +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=1728997332; cv=none; b=ECa5KI71qrlDNIwCUbKqEvgbbPsLxaptyO4VKyUAqsglFLsnaYcSyeLjg1mqJ/KeNrXcvTNZcxV7O3ygibCjf/8aqK/i0GhCheF0ujk6nhOq7ioCdjpRzEkzoG+owfUyjgZMCjECp3/ZBQflQ/7E8x5v9Ea7UJlwMhhRxIw5YXw= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1728997332; c=relaxed/simple; bh=FxPeSqgvfJtpExeuZtZt6HMZAnf3GVZbh0dw0Z/d1CE=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=CBHTqu0rBlMVNeozLi6MIfF0BAnYUPpynoIcQG+zBVmRQJp4+5lGtsMseYTynyzOTAfDxY5cJHYu7V1MheRDNumxkojajJ7QPHRNRrjknFioxrrW6gXkDRh7C/g7KgkdfSSSq6+N2k0BgRMei/cIDCgfo2Z8LDp5/mbqBGcRqrc= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.b=bTqWBzUD; 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="bTqWBzUD" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 9FAF6C4CECE; Tue, 15 Oct 2024 13:02:11 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1728997332; bh=FxPeSqgvfJtpExeuZtZt6HMZAnf3GVZbh0dw0Z/d1CE=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=bTqWBzUDcrlRSCLP3jLRtILkFZZqB1HnPJw2/FshbgnnBk7RT8+g/DJb9L2XOeY04 sgXrp+j/Y67ZkvgZeHMX+z7X3IWzZQlv0U61Qm7M0mAlRBVZTiVwfGBTlNOWhlS6L6 Eo3S+F++MWYGhAhv7RXq6gocCiKMKVvvWIDBDJ2U= From: Greg Kroah-Hartman To: stable@vger.kernel.org Cc: Greg Kroah-Hartman , patches@lists.linux.dev, Kemeng Shi , Theodore Tso , Sasha Levin Subject: [PATCH 5.10 151/518] ext4: avoid negative min_clusters in find_group_orlov() Date: Tue, 15 Oct 2024 14:40:55 +0200 Message-ID: <20241015123922.836396789@linuxfoundation.org> X-Mailer: git-send-email 2.47.0 In-Reply-To: <20241015123916.821186887@linuxfoundation.org> References: <20241015123916.821186887@linuxfoundation.org> User-Agent: quilt/0.67 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 5.10-stable review patch. If anyone has any objections, please let me know. ------------------ From: Kemeng Shi [ Upstream commit bb0a12c3439b10d88412fd3102df5b9a6e3cd6dc ] min_clusters is signed integer and will be converted to unsigned integer when compared with unsigned number stats.free_clusters. If min_clusters is negative, it will be converted to a huge unsigned value in which case all groups may not meet the actual desired free clusters. Set negative min_clusters to 0 to avoid unexpected behavior. Fixes: ac27a0ec112a ("[PATCH] ext4: initial copy of files from ext3") Signed-off-by: Kemeng Shi Link: https://patch.msgid.link/20240820132234.2759926-4-shikemeng@huaweicloud.com Signed-off-by: Theodore Ts'o Signed-off-by: Sasha Levin --- fs/ext4/ialloc.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/fs/ext4/ialloc.c b/fs/ext4/ialloc.c index 26ebbb0388cc9..c91e0cef04a53 100644 --- a/fs/ext4/ialloc.c +++ b/fs/ext4/ialloc.c @@ -513,6 +513,8 @@ static int find_group_orlov(struct super_block *sb, struct inode *parent, if (min_inodes < 1) min_inodes = 1; min_clusters = avefreec - EXT4_CLUSTERS_PER_GROUP(sb)*flex_size / 4; + if (min_clusters < 0) + min_clusters = 0; /* * Start looking in the flex group where we last allocated an -- 2.43.0