Re: [GIT PULL] execve updates for v6.13-rc1 (take 2)

Linus Torvalds
2024-11-29T04:44:32Z

On Thu, 28 Nov 2024 at 19:34, Al Viro <viro@zeniv.linux.org.uk> wrote:
>
> Just one thing - IMO we want to use the relative pathname when it's
> not empty. Even in execveat()

Oh, absolutely agreed.

Good catch, because yes, I messed that part up in my suggested patch at

https://lore.kernel.org/all/CAHk-=wjF_09Z6vu7f8UAbQVDDoHnd-j391YpUxmBPLD=SKbKtQ@mail.gmail.com/

which did this dentry name thing for anything that used a base fd, but
yes, as you say, it should only do it when there is no name at all.

So instead of basing it (incorrectly) on that existing

if (fd == AT_FDCWD || filename->name[0] == '/') {

test, the logic should probably look something like

if (!filename->name[0]) {
rcu_read_lock();
strscpy(bprm->comm,
smp_load_acquire(&file->f_path.dentry->d_name.name));
rcu_read_unlock();
} else
strscpy(bprm->comm, kbasename(filename->name));

and it probably wouldn't be a bad idea to separate this out to be a
helper function that just does this one thing.

Linus