From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-alma10-1.taild15c8.ts.net [100.103.45.18]) (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 AB23346C4AB; Tue, 21 Jul 2026 15:52:53 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=100.103.45.18 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1784649174; cv=none; b=FRlCnsm8oT8uns8jCgm1aeGi1QbNUVBpZ26oQsjZLCSJ0hvOLAbZfR0xOhAmYk1qCHNsPgywtLHUMjU+SXAydq4elIY5mQL7MpgHzIYTyDiTM7qJhK0ZwrcO+DqLWQHI+wJvGr6aR14tDAfai+gFBG6nJc0nQRvzp16X0Xakx9U= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1784649174; c=relaxed/simple; bh=nPYXedyEshP2n/whwhx3HaXDaioM+Dda+LriDbX5bh0=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=EfAg4k8J3Ss2ypcxJvfAskxl/E68KVKHMnLIUED6FJ6TBZXODRGh1VoPN1CkAbSouBp97vB1e9a05J1hYsPmXura0hNxV2H9AWB8DrKsdQNCQti4tUSESrwFshxplp9I1xyQdpGfsiHQz9L4M2bcHadhWnTo4p/WPEYRdZ9E1+4= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.b=lkPWNfQP; arc=none smtp.client-ip=100.103.45.18 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.b="lkPWNfQP" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 1A8EB1F000E9; Tue, 21 Jul 2026 15:52:53 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linuxfoundation.org; s=korg; t=1784649173; bh=M3O6laOmN2Dn1GvFaHeP+Ok0GOqTTeliyZWNYWnJtmQ=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=lkPWNfQPtjHZnNKCh6euO5M6K9toN/jQ9RKsQrh55iMfyRK5Ru0MMBUDDmy9Np7h9 rRK9rAo6t0aR1TFpjYP2yDQPPz4YMOWmnN7blduOBQuVVAIAovkT4vaenEiVhcpVA9 FhKQEbggipfNe4S1NMprv309dsemIkyAs1XfDvVA= From: Greg Kroah-Hartman To: stable@vger.kernel.org Cc: Greg Kroah-Hartman , patches@lists.linux.dev, Zhang Cen , Joseph Qi , Mark Fasheh , Joel Becker , Junxiao Bi , Changwei Ge , Jun Piao , Heming Zhao , Andrew Morton , Sasha Levin Subject: [PATCH 7.1 0478/2077] ocfs2: reject FITRIM ranges shorter than a cluster Date: Tue, 21 Jul 2026 17:02:31 +0200 Message-ID: <20260721152604.080490640@linuxfoundation.org> X-Mailer: git-send-email 2.55.0 In-Reply-To: <20260721152552.646164743@linuxfoundation.org> References: <20260721152552.646164743@linuxfoundation.org> User-Agent: quilt/0.69 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 7.1-stable review patch. If anyone has any objections, please let me know. ------------------ From: Zhang Cen [ Upstream commit ca1afd88f5eaaff9168e1466e5401385edf59543 ] ocfs2_trim_mainbm() trims the global bitmap in cluster units, but its too-short range validation only checks sb->s_blocksize. On filesystems with a cluster size larger than the block size, a FITRIM range that is at least one block but shorter than one cluster is accepted and shifted down to len == 0. The later start + len - 1 and len -= ... arithmetic then underflows and can drive trimming past the requested range. Reject ranges shorter than s_clustersize instead. That preserves the existing -EINVAL behavior for requests that cannot discard even one allocation unit and keeps zero-cluster trims out of the group walk. Link: https://lore.kernel.org/20260528151247.361854-1-rollkingzzc@gmail.com Fixes: aa89762c5480 ("ocfs2: return EINVAL if the given range to discard is less than block size") Assisted-by: Codex:gpt-5.5 Signed-off-by: Zhang Cen Reviewed-by: Joseph Qi Cc: Mark Fasheh Cc: Joel Becker Cc: Junxiao Bi Cc: Changwei Ge Cc: Jun Piao Cc: Heming Zhao Signed-off-by: Andrew Morton Signed-off-by: Sasha Levin --- fs/ocfs2/alloc.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/fs/ocfs2/alloc.c b/fs/ocfs2/alloc.c index 6e5fd3f12a84c7..be09e766ac1fc9 100644 --- a/fs/ocfs2/alloc.c +++ b/fs/ocfs2/alloc.c @@ -7576,7 +7576,7 @@ int ocfs2_trim_mainbm(struct super_block *sb, struct fstrim_range *range) len = range->len >> osb->s_clustersize_bits; minlen = range->minlen >> osb->s_clustersize_bits; - if (minlen >= osb->bitmap_cpg || range->len < sb->s_blocksize) + if (minlen >= osb->bitmap_cpg || range->len < osb->s_clustersize) return -EINVAL; trace_ocfs2_trim_mainbm(start, len, minlen); -- 2.53.0