gramine icon indicating copy to clipboard operation
gramine copied to clipboard

[LibOS] `execve` syscall must treat `argv == NULL` as `argv = {NULL}`

Open dimakuv opened this issue 3 years ago • 1 comments

Description of the problem

The man page for execve says:

On Linux, argv and envp can be specified as NULL. In both cases, this has the same effect as specifying the argument as a pointer to a list containing a single null pointer. Do not take advantage of this nonstandard and nonportable misfeature! On many other UNIX systems, specifying argv as NULL will result in an error (EFAULT). Some other UNIX systems treat the envp==NULL case the same as Linux.

Currently Gramine doesn't implement this special case. See code here: https://github.com/gramineproject/gramine/blob/64b004bb59a237ea2486ef791fd970519888c638/libos/src/sys/libos_exec.c#L144

This should be easy to implement. We just need:

  • argv == NULL -> argv = {NULL}
  • envp == NULL -> envp = {NULL}

For discussions, see https://github.com/gramineproject/gramine/pull/781

dimakuv avatar Jul 26 '22 13:07 dimakuv

Unfortunately, the current quirk in Gramine with respect to envp prevents us from performing envp = {NULL} conversion. See this code: https://github.com/gramineproject/gramine/blob/546c598b694d091121babc215bf6b9f9f52bbb4d/libos/src/sys/libos_exec.c#L150-L152

Also see a previous attempt at fixing a related problem (and failing): https://github.com/gramineproject/gramine/pull/781

So this issue then should deal only with argv = {NULL}. Fortunately, Stefan created a PR to solve this, #979.

dimakuv avatar Oct 14 '22 07:10 dimakuv