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 5DDEB347BC6; Tue, 21 Jul 2026 22:51:32 +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=1784674293; cv=none; b=nRIasFymzeZoxVHKQYjUuWgvDMvBQMwif1bP7ZAxD2q/zjPP4oVFdHvTz9QZRepjtlVf/DPz+C/tv8DHheqapCAMzT0NR4+dUVsk19A8cQDAhPsXtnsYtyts2G8+d8JmGzHEb3fP9aHTAkeJRgDYvPzwQ1Vy7lnHLYAkmGIB2zs= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1784674293; c=relaxed/simple; bh=pbbAvm0J5zCUqse4u0gIkeKpBLXXbv4Pu8JNrk2fco0=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=APxEEu0mfnY7MP0sxe2bRdLPNpZQ7P/2au/P9Kt29iCxfX9jU6i0Y02IAHgM+V7v4SF+Oee6aFiG+9ereI6yTCKEGFU7Om1To+46D05EK49MQd8rHc8aTBKDu9y6i1m36OSfQ9xvUGVJFdwdWQjkXqIDP+u8K73XVi87/VH3Tn4= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.b=YiPKZ+OR; 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="YiPKZ+OR" Received: by smtp.kernel.org (Postfix) with ESMTPSA id C9F9B1F000E9; Tue, 21 Jul 2026 22:51:31 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linuxfoundation.org; s=korg; t=1784674292; bh=Jjwy9EroOCS/QDuIliDiFnQGYaLkE7GT973JRdbZ47o=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=YiPKZ+ORkxjFDd6pPMHqP5uHoFDwc99zvF6jjm4UY3W247jbjPytJbk58uG4eVQ3Y 7FAep5z1IUFuHDz1BIQKxRB3nDF1AE6UxJ7R79FMj2JrsP/IF5zqVIeKD0i3EyEiQZ ANJFHxLfGrkz5QRkvWMQ0OkDTdpHZCTPxoJMQNJI= From: Greg Kroah-Hartman To: stable@vger.kernel.org Cc: Greg Kroah-Hartman , patches@lists.linux.dev, Kyle Zeng , Joseph Qi , Mark Fasheh , Joel Becker , Junxiao Bi , Changwei Ge , Jun Piao , Heming Zhao , Andrew Morton Subject: [PATCH 5.10 485/699] ocfs2: avoid moving extents to occupied clusters Date: Tue, 21 Jul 2026 17:24:04 +0200 Message-ID: <20260721152406.643371549@linuxfoundation.org> X-Mailer: git-send-email 2.55.0 In-Reply-To: <20260721152355.667394603@linuxfoundation.org> References: <20260721152355.667394603@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 5.10-stable review patch. If anyone has any objections, please let me know. ------------------ From: Kyle Zeng commit 22920541c35a9f23f219038ba5874c843a7c4419 upstream. For non-auto OCFS2_IOC_MOVE_EXT operations, userspace supplies a physical me_goal. ocfs2_move_extent() initializes new_phys_cpos from that goal and expects ocfs2_probe_alloc_group() to replace it with a free run in the target block group. The probe currently leaves *phys_cpos unchanged if the scan reaches the end of the group without finding a free run. An occupied goal at the last bit can therefore survive the probe and be passed to __ocfs2_move_extent(), which copies file data into a cluster still owned by another inode before the bitmap is updated. When the probe does find a free run, it also subtracts move_len from the ending bit. The start of an N-bit run ending at i is i - N + 1, so the current calculation can report the bit immediately before the free run. Clear *phys_cpos before scanning and use the correct free-run start. Callers already treat a zero result as -ENOSPC, so failed probes no longer continue with an occupied caller-controlled goal. Link: https://lore.kernel.org/20260611213510.16956-1-kylebot@openai.com Fixes: e6b5859cccfa ("Ocfs2/move_extents: helper to probe a proper region to move in an alloc group.") Fixes: 236b9254f8d1 ("ocfs2: fix non-auto defrag path not working issue") Assisted-by: Codex:gpt-5.5 Signed-off-by: Kyle Zeng Reviewed-by: Joseph Qi Cc: Mark Fasheh Cc: Joel Becker Cc: Junxiao Bi Cc: Changwei Ge Cc: Jun Piao Cc: Heming Zhao Cc: Signed-off-by: Andrew Morton Signed-off-by: Greg Kroah-Hartman --- fs/ocfs2/move_extents.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) --- a/fs/ocfs2/move_extents.c +++ b/fs/ocfs2/move_extents.c @@ -536,6 +536,8 @@ static void ocfs2_probe_alloc_group(stru u32 base_cpos = ocfs2_blocks_to_clusters(inode->i_sb, le64_to_cpu(gd->bg_blkno)); + *phys_cpos = 0; + for (i = base_bit; i < le16_to_cpu(gd->bg_bits); i++) { used = ocfs2_test_bit(i, (unsigned long *)gd->bg_bitmap); @@ -557,7 +559,7 @@ static void ocfs2_probe_alloc_group(stru last_free_bits++; if (last_free_bits == move_len) { - i -= move_len; + i = i - move_len + 1; *goal_bit = i; *phys_cpos = base_cpos + i; break;