Re: [GIT PULL] execve updates for v6.13-rc1

From: Al Viro
Date: Wed Nov 20 2024 - 21:41:25 EST


On Thu, Nov 21, 2024 at 02:36:19AM +0000, Al Viro wrote:
> On Wed, Nov 20, 2024 at 02:50:39PM -0800, Linus Torvalds wrote:
> > So you probably want to do something like
> >
> > const char *name = smp_load_acquire(&dentry->d_name.name);
> >
> > under the RCU read lock before then copying it with strscpy(). It
> > should always be NULL-terminated.
> >
> > If you want to be extra careful, you might surround it with a
> >
> > read_seqbegin_or_lock(&rename_lock, &seq);
>
> What for?
>
> char name[something];
>
> sprintf(name, "%*pD", sizeof(name) - 1, file);
>
> and be done with that...

... or

struct name_snapshot n;

take_dentry_name_snapshot(&n, file->f_path.dentry);

do_something(n.name.name);

release_dentry_name_snapshot(&n);