Re: [PATCH v2] btrfs: verity: propagate orphan insertion errors when enabling verity

From: Qu Wenruo

Date: Thu Oct 15 2026 - 06:45:47 EST




在 2026/10/15 20:29, guolingxing 写道:
btrfs_begin_enable_verity() ignores the return value of
btrfs_orphan_add() and unconditionally returns 0. If orphan insertion
fails, btrfs_orphan_add() aborts the transaction, but the generic
fs-verity code still proceeds with Merkle tree construction because
the begin_enable_verity callback reported success.

Return the error so that fs-verity stops immediately instead of
continuing after the initialization failure.

The transaction is already aborted by btrfs_orphan_add() and the
handle is released by btrfs_end_transaction(), so no additional
cleanup is needed.

Fixes: 705242538ff3 ("btrfs: verity metadata orphan items")
Signed-off-by: guolingxing <guolingxing@xxxxxxxxxx>

Reviewed-by: Qu Wenruo <wqu@xxxxxxxx>

Will push to for-next branch soon.

---
Hi Qu, you are right. The claim about leaving the on-disk state
inconsistent was incorrect.

btrfs_orphan_add() aborts the transaction on failure, so I do not
have evidence that ignoring its return value can cause on-disk
inconsistency. The real issue is that btrfs_begin_enable_verity()
reports success despite the initialization failure, letting the
generic fs-verity code proceed with Merkle tree construction only to
encounter an error later, instead of returning the original error
immediately. This revision removes the on-disk inconsistency claim and
describes the error propagation issue instead.

Thanks for pointing this out.

Changes in v2:
- Remove the incorrect claim about on-disk inconsistency.
- Clarify that the fix propagates the initialization error immediately.

fs/btrfs/verity.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/fs/btrfs/verity.c b/fs/btrfs/verity.c
index 600337a84fbe..d92c9dab0293 100644
--- a/fs/btrfs/verity.c
+++ b/fs/btrfs/verity.c
@@ -615,7 +615,7 @@ static int btrfs_begin_enable_verity(struct file *filp)
set_bit(BTRFS_INODE_VERITY_IN_PROGRESS, &inode->runtime_flags);
btrfs_end_transaction(trans);
- return 0;
+ return ret;
}
/*