Re: Patch for a overwriting/corruption of the file system
From: Al Viro
Date: Thu Apr 20 2023 - 23:05:41 EST
On Fri, Apr 21, 2023 at 04:00:17AM +0100, Al Viro wrote:
> On Wed, Mar 15, 2023 at 02:33:48PM +0530, Kirtikumar Anandrao Ramchandani wrote:
> > While I am going through the code at the moment, I think there is one more
> > issue. It probably can't just compare "old_dir" and "new_dir", since those
> > are just pointers to structs. So, both addresses can be completely
> > different, and still represent the same folder, yes?
>
> No, they can not. We should never have different in-core instances of
> struct inode representing the same on-disk object - otherwise all locking
> goes to hell, for example.
... and we should never, ever have two dentries aliasing the same directory
inode, so d_inode() part is also not needed and actively confusing,
since anyone running into it is likely to go "Why is it written that way?
What is it protecting against? Where does <such and such code> protect
itself against the same situation?". And there's a _lot_ of code that
would break horribly if we ever run into such.
Defensive programming can be harmful...