Re: [for-linus][PATCH 1/3] eventfs: Have the inodes all for files and directories all be the same

From: Steven Rostedt
Date: Mon Jan 22 2024 - 13:11:45 EST


On Mon, 22 Jan 2024 17:23:29 +0100
Geert Uytterhoeven <geert@xxxxxxxxxxxxxx> wrote:

> > +/* Just try to make something consistent and unique */
> > +static int eventfs_dir_ino(struct event_inode *ei, const char *name)
>
> eventfs_inode

Heh, I fixed that, but must have created the patch before catching it. :-/

>
> > +{
> > + unsigned long sip = (unsigned long)ei;
> > +
> > + sip += strhash(name) + EVENTFS_DIR_INODE_INO;
> > + sip = siphash_1u32((int)sip, &inode_key);
> > +
> > + /* keep it positive */
> > + return sip & ((1U << 31) - 1);
> > +}
> > +
> > /*
> > * The eventfs_inode (ei) itself is protected by SRCU. It is released from
> > * its parent's list and will have is_freed set (under eventfs_mutex).
>
> Thanks, find is happy now the directories have different inode numbers.
> The files still have identical inodes numbers, I hope that doesn't cause
> any issues...

Well, I guess I should ask Linus.

Linus,

I can add this patch to make sure directory inodes are unique, as it causes
a regression in find, but keep the file inodes the same. I can see how the
issue is with directories, as find (and probably other applications) check
for invalid directory loops. But with files, there should be no issue. It
could just think it's another hard link.

The question I have is, should this just make dir inodes unique and keep
files the same, as this patch does? Or make all inodes unique?

This is assuming that my algorithm is good enough to not leak kernel
addresses. I could also chop it down to 28 bits, as that's probably still
"good enough" to keep things unique.

return sip & ((1U << 28) - 1);

That would make it even harder to unhash to get an address.

-- Steve