Re: [PATCH v2 4/7] tracefs: dentry lookup crapectomy

From: Al Viro
Date: Wed Jan 31 2024 - 22:02:27 EST


On Wed, Jan 31, 2024 at 09:26:42PM -0500, Steven Rostedt wrote:

> > Huh? Just return NULL and be done with that - you'll get an
> > unhashed negative dentry and let the caller turn that into
> > -ENOENT...
>
> We had a problem here with just returning NULL. It leaves the negative
> dentry around and doesn't get refreshed.

Why would that dentry stick around? And how would anyone find
it, anyway, when it's not hashed?

> I did this:
>
> # cd /sys/kernel/tracing
> # ls events/kprobes/sched/
> ls: cannot access 'events/kprobes/sched/': No such file or directory
> # echo 'p:sched schedule' >> kprobe_events
> # ls events/kprobes/sched/
> ls: cannot access 'events/kprobes/sched/': No such file or directory
>
> When it should have been:
>
> # ls events/kprobes/sched/
> enable filter format hist hist_debug id inject trigger
>
> Leaving the negative dentry there will have it fail when the directory
> exists the next time.

Then you have something very deeply fucked up. NULL or ERR_PTR(-ENOENT)
from ->lookup() in the last component of open() would do exactly the
same thing: dput() whatever had been passed to ->lookup() and fail
open(2) with -ENOENT.