diff mbox series

[v3,2/2] ext4: check and assert if marking an no_delete evicting inode dirty

Message ID 20220629112647.4141034-2-yi.zhang@huawei.com
State Accepted, archived
Headers show
Series [v3,1/2] ext4: silence the warning when evicting inode with dioread_nolock | expand

Commit Message

Zhang Yi June 29, 2022, 11:26 a.m. UTC
In ext4_evict_inode(), if we evicting an inode in the 'no_delete' path,
it cannot be raced by another mark_inode_dirty(). If it happens,
someone else may accidentally dirty it without holding inode refcount
and probably cause use-after-free issues in the writeback procedure.
It's indiscoverable and hard to debug, so add an WARN_ON_ONCE() to
check and detect this issue in advance.

Suggested-by: Jan Kara <jack@suse.cz>
Signed-off-by: Zhang Yi <yi.zhang@huawei.com>
---
v2->v3:
 - Switch to use WARN_ON_ONCE instead of ASSERT.

 fs/ext4/inode.c | 6 ++++++
 1 file changed, 6 insertions(+)

Comments

Jan Kara June 29, 2022, 12:40 p.m. UTC | #1
On Wed 29-06-22 19:26:47, Zhang Yi wrote:
> In ext4_evict_inode(), if we evicting an inode in the 'no_delete' path,
> it cannot be raced by another mark_inode_dirty(). If it happens,
> someone else may accidentally dirty it without holding inode refcount
> and probably cause use-after-free issues in the writeback procedure.
> It's indiscoverable and hard to debug, so add an WARN_ON_ONCE() to
> check and detect this issue in advance.
> 
> Suggested-by: Jan Kara <jack@suse.cz>
> Signed-off-by: Zhang Yi <yi.zhang@huawei.com>
> ---
> v2->v3:
>  - Switch to use WARN_ON_ONCE instead of ASSERT.

Thanks! Feel free to add:

Reviewed-by: Jan Kara <jack@suse.cz>

								Honza

> 
>  fs/ext4/inode.c | 6 ++++++
>  1 file changed, 6 insertions(+)
> 
> diff --git a/fs/ext4/inode.c b/fs/ext4/inode.c
> index 702cc208689a..902393373152 100644
> --- a/fs/ext4/inode.c
> +++ b/fs/ext4/inode.c
> @@ -333,6 +333,12 @@ void ext4_evict_inode(struct inode *inode)
>  	ext4_xattr_inode_array_free(ea_inode_array);
>  	return;
>  no_delete:
> +	/*
> +	 * Check out some where else accidentally dirty the evicting inode,
> +	 * which may probably cause inode use-after-free issues later.
> +	 */
> +	WARN_ON_ONCE(!list_empty_careful(&inode->i_io_list));
> +
>  	if (!list_empty(&EXT4_I(inode)->i_fc_list))
>  		ext4_fc_mark_ineligible(inode->i_sb, EXT4_FC_REASON_NOMEM, NULL);
>  	ext4_clear_inode(inode);	/* We must guarantee clearing of inode... */
> -- 
> 2.31.1
>
diff mbox series

Patch

diff --git a/fs/ext4/inode.c b/fs/ext4/inode.c
index 702cc208689a..902393373152 100644
--- a/fs/ext4/inode.c
+++ b/fs/ext4/inode.c
@@ -333,6 +333,12 @@  void ext4_evict_inode(struct inode *inode)
 	ext4_xattr_inode_array_free(ea_inode_array);
 	return;
 no_delete:
+	/*
+	 * Check out some where else accidentally dirty the evicting inode,
+	 * which may probably cause inode use-after-free issues later.
+	 */
+	WARN_ON_ONCE(!list_empty_careful(&inode->i_io_list));
+
 	if (!list_empty(&EXT4_I(inode)->i_fc_list))
 		ext4_fc_mark_ineligible(inode->i_sb, EXT4_FC_REASON_NOMEM, NULL);
 	ext4_clear_inode(inode);	/* We must guarantee clearing of inode... */