[Toybox] [Nommu] Week ending June 27ish.

Rob Landley rob at landley.net
Thu Jul 2 15:08:19 PDT 2015



On 07/02/2015 09:44 AM, Christopher Covington wrote:
> Hi Rob,
> 
> On 06/29/2015 04:26 PM, Rob Landley wrote:
>> On 06/28/2015 09:57 PM, Rich Felker wrote:
> 
>>> but the latter could be dangerous not to have setup right.
>>> I *think* (this needs checking) the new thread created manually by
>>> clone will use the same TLS pointer as the thread that called clone.
>>> In this case, libc internals will potentially be reading and writing
>>> the same data, without any synchronization.
>>
>> See "decided to just use fork(), which means re-exec /proc/self/exe as
>> necessary because exec(NULL) doesn't re-exec yourself despite multiple
>> proposals over the year that the kernel just DO that since the kernel
>> knows the right inode even if proc isn't mounted"...
> 
> Is the following much different from the desired exec(NULL) behavior you're
> describing?
> 
>> For example, if you have an open file descriptor on an executable file, you
>> can execute it by calling execveat(), passing the file descriptor, an empty
>> path, and the AT_EMPTY_PATH flag.
> 
> https://lwn.net/Articles/649115/

The problem is you need to get a file descriptor to your currently
running executable (it's not one of the file descriptors you inherit as
part of your environment), which means you need to find your executable,
which means /proc/self/exe (which may not be mounted) or a search of
$PATH looking for argv[0] (which is just a heuristic, your calling
program can pass you anything in argv and envp; a fun corner cases is
that if you didn't define PATH bash will set a default one but as a
_local_ variable, not exported to the child process).

The kernel already knows this information, it has to be able to provide
/proc/self/exe for you from its internal data about your process. But
there's no way to ask it to use what it's already got, you have to
reconstruct it and feed it back to it.

It would be lovely if this showed up, I've been asking for it on and off
forever: http://lkml.iu.edu/hypermail/linux/kernel/0612.3/0238.html

But then people were going "it would be nice if there was a way to punch
a hole in an exesting file" years before we got a way to do that...

Sigh. The commit that added fexecve() last year
https://git.kernel.org/cgit/linux/kernel/git/torvalds/linux.git/commit/?id=51f39a1f0cea
links to a _reply_ to my above post, while missing the point actually
raised in the first message of the thread.

Rob

 1435874899.0


More information about the Toybox mailing list