]> git.ipfire.org Git - thirdparty/kernel/stable.git/commitdiff
ocfs2: reject FITRIM ranges shorter than a cluster
authorZhang Cen <rollkingzzc@gmail.com>
Thu, 28 May 2026 15:12:47 +0000 (23:12 +0800)
committerAndrew Morton <akpm@linux-foundation.org>
Thu, 4 Jun 2026 21:49:29 +0000 (14:49 -0700)
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 <rollkingzzc@gmail.com>
Reviewed-by: Joseph Qi <joseph.qi@linux.alibaba.com>
Cc: Mark Fasheh <mark@fasheh.com>
Cc: Joel Becker <jlbec@evilplan.org>
Cc: Junxiao Bi <junxiao.bi@oracle.com>
Cc: Changwei Ge <gechangwei@live.cn>
Cc: Jun Piao <piaojun@huawei.com>
Cc: Heming Zhao <heming.zhao@suse.com>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
fs/ocfs2/alloc.c

index 6e5fd3f12a84c7d3538aeb2e5ac61df18397d41b..be09e766ac1fc9580dba6b804b9209d14529c2e4 100644 (file)
@@ -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);