Re: [PATCH] btrfs: verity: return error from btrfs_orphan_add in begin_enable_verity

From: Qu Wenruo

Date: Thu Oct 15 2026 - 05:13:54 EST




在 2026/10/15 17:41, guolingxing 写道:
btrfs_begin_enable_verity() ignores the return value of
btrfs_orphan_add() and unconditionally returns 0. When inserting the
orphan item fails (e.g. -ENOMEM), the error is swallowed and the
caller continues to build the Merkle tree even though the orphan item
was never written and BTRFS_INODE_VERITY_IN_PROGRESS was not set,
leaving the on-disk state inconsistent.

This conflicts with your statement just lines below:

"The transaction is already aborted inside btrfs_orphan_add() on failure"

So why the on-disk state can still be inconsistent?


Propagate the error to the caller so that fsverity_ioctl_enable()
aborts before building the Merkle tree. The transaction is already
aborted inside btrfs_orphan_add() on failure and released by the
unconditional btrfs_end_transaction(), so only the return value needs
to change.

Fixes: 705242538ff3 ("btrfs: verity metadata orphan items")
Cc: stable@xxxxxxxxxxxxxxx
Signed-off-by: guolingxing <guolingxing@xxxxxxxxxx>
---
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;
}
/*