[PATCH] Linux: Add execveat system call wrapper
Florian Weimer
fw@deneb.enyo.de
Tue Apr 28 17:50:32 GMT 2020
* Adhemerval Zanella via Libc-alpha:
> On 28/04/2020 09:20, Alexandra Hájková via Libc-alpha wrote:
>
>> +/* Execute the file FD refers to, overlaying the running program image.
>> + ARGV and ENVP are passed to the new program, as for `execve'. */
>> +int
>> +execveat (int dirfd, const char *path, char *const argv[], char *const envp[],
>> + int flags)
>> +{
>> + /* Avoid implicit array coercion in syscall macros. */
>> + INLINE_SYSCALL_CALL (execveat, dirfd, path, &argv[0], &envp[0], flags);
>> +#ifndef __ASSUME_EXECVEAT
>> + if (errno != ENOSYS)
>> + return -1;
>> +
>> + int fd = openat (dirfd, path, flags | O_CLOEXEC);
>> + if (fd < 0)
>> + return -1;
>> +
>
> Is this subject to a TOCTOU where a thread might close the fd by explicitly
> reading /proc/self/fd/?
Sure, but that's as undefined as closing a file descriptor that the
code has not opened. This impacts any code in glibc which opens file
descriptors. I don't think it's a problem.
More information about the Libc-alpha
mailing list