Re: [PATCH] bfs: put a inode if link count is 0

From: Al Viro
Date: Thu Jan 09 2025 - 01:22:28 EST


On Thu, Jan 09, 2025 at 11:49:46AM +0800, Lizhi Xu wrote:
>
> The reproducer performs the rename operation on the file twice in succession
> and changes the file to the same file name. After the first rename operation,
> the number of links in the inode is set to 0. In the second execution, the
> same inode is used, resulting in a 0 value warning for i_nlink.
>
> To avoid this issue, put the target inode before exiting the bfs_rename.

This is completely insane - you get an extra drop of in-core inode
refcount, which *will* end up with dangling pointer and memory corruption.
Besides, there is a perfectly legitimate case when you open a file and
rename something on top of it. It MUST remain open and alive until the
last in-core reference to inode goes away, which must not happen before
close().

Frankly, if you do not understand why that is wrong, you should not
mess with anything filesystem-related until you learn the area enough.

NAK.