All of lore.kernel.org
 help / color / mirror / Atom feed
* Question about execve.
@ 2010-03-28  3:26 Carlos O'Donell
  2010-03-28 15:42 ` John David Anglin
  0 siblings, 1 reply; 23+ messages in thread
From: Carlos O'Donell @ 2010-03-28  3:26 UTC (permalink / raw)
  To: Helge Deller, Kyle McMartin, linux-parisc

[-- Attachment #1: Type: text/plain, Size: 419 bytes --]

Helge,

On PARISC I'm seeing the following reproducible behvaiour:

* Parent calls vfork()
* Child of vfork() calls execve()
* Child returns from execve() and starts corrupting parent state
eventually leading to a segmentation fault.
* New process (as a result of execve) runs to completion.

What code in the Linux kernel prevents the child, which calls
execve(), from returning?

Test case attached.

Cheers,
Carlos.

[-- Attachment #2: build.sh --]
[-- Type: application/x-sh, Size: 40 bytes --]

[-- Attachment #3: pt-vfork.S --]
[-- Type: application/octet-stream, Size: 1675 bytes --]

.text ! 
.align 4 ! 
.export __vfork ! 
.type __vfork,@function ! 
__vfork: ! 
.PROC ! 
.CALLINFO FRAME=64,CALLS,SAVE_RP,ENTRY_GR=3 ! 
.ENTRY ! ! 
 /* Save return pointer. */
 stw %rp, -20(%sr0,%sp) !

 /* Get 64 bytes on the stack, save sp, and PIC register. */
 stwm %r3, 64(%sp)
 stw %sp, -4(%sp)
 stw %r19, -32(%sp)

 /* Save/restore PIC register around syscall. */
 copy %r19, %r25

 /* Load thread register. */
 mfctl %cr27, %r26 ! 
 /* Load cached parent PID. */
 ldw -1044(%r26),%r1 ! 
 /* Negate it, such that the child runs with
    a negative PID and no functions work until
    the execve. */
 sub %r0,%r1,%r1 ! 
 /* Store it back. */
 stw %r1,-1044(%r26) !

 /* Call vfork. */
 ble 0x100(%sr2,%r0)
 ldi (0 + 113),%r20 

 /* If this is the child jump to thread_start */
 cmpb,=,n %r0,%ret0,.Lthread_start ! 

 /* This is the parent. */
 /* Load thread register. */
 mfctl %cr27, %r26 ! 
 /* Load cached parent PID */
 ldw -1044(%r26),%r1 ! 
 /* Negate it (restoring it) */
 sub %r0,%r1,%r1 ! 
 /* Save it back. */
 stw %r1,-1044(%r26) ! 

 ldi -4096,%r1
 /* Unsigned compre = Was ret0 between -1 and -4096. */
 comclr,>>= %r1,%ret0,%r0
 b,n .Lerror

.Lthread_start: !

 /* Load return pointer and restore stack. */
 ldw -84(%sp), %rp
 bv %r0(%rp)
 ldwm -64(%sp), %r3

.Lerror:
 /* Negate error code. */
 sub %r0,%ret0,%r3
 .import __errno_location,code ! ! 
 /* Get address of errno. */
 bl __errno_location,%rp !

 copy %r25, %r19
 /* Save errno. */
 stw %r3, 0(%ret0)
 /* vfork returns -1 on error. */
 ldi -1, %ret0
 /* Return. */
 ldw -84(%sp), %rp
 bv %r0(%rp)
 ldwm -64(%sp), %r3
.EXIT ! .PROCEND ! .size __vfork, .-__vfork !

.weak vfork ! vfork = __vfork

[-- Attachment #4: vfork.c --]
[-- Type: text/x-csrc, Size: 589 bytes --]

#include <stdio.h>
#include <stdlib.h>
#include <errno.h>
#include <unistd.h>

#define CALL_EXIT 0

int main (void)
{
  pid_t child;
  char *cmd[] = { "bash", "-c", "echo In child $$;", (char *)0 };
  char *env[] = { "HOME=/tmp", (char *)0 };
  int ret;

  child = vfork();

  if (child == 0)
    {
      ret = execve("/bin/bash", cmd, env);
      printf ("ret = %d\n", ret);
#if CALL_EXIT == 1
      _exit(1);
#endif
    }
  else
    {
      printf("child != 0\n");
    }

  printf("parent is %d\n", (unsigned int)getpid());
  printf("child is %d\n", (unsigned int)child);

  return 0;
}

^ permalink raw reply	[flat|nested] 23+ messages in thread

end of thread, other threads:[~2010-04-01 18:55 UTC | newest]

Thread overview: 23+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2010-03-28  3:26 Question about execve Carlos O'Donell
2010-03-28 15:42 ` John David Anglin
2010-03-28 16:03   ` John David Anglin
2010-03-28 17:26   ` Carlos O'Donell
2010-03-28 18:00     ` John David Anglin
2010-03-28 18:47       ` Carlos O'Donell
2010-03-28 19:07       ` John David Anglin
2010-03-28 19:31         ` John David Anglin
2010-03-28 19:40           ` Carlos O'Donell
     [not found]             ` <20100328202239.162785145@hiauly1.hia.nrc.ca>
2010-03-28 20:39               ` Carlos O'Donell
     [not found]                 ` <20100328210134.3D6005145@hiauly1.hia.nrc.ca>
2010-03-28 21:04                   ` Carlos O'Donell
     [not found]                     ` <20100328212110.03F224E77@hiauly1.hia.nrc.ca>
2010-03-28 23:12                       ` Carlos O'Donell
2010-03-28 23:59                         ` John David Anglin
2010-03-29  0:24                           ` Carlos O'Donell
2010-03-29  2:38                             ` John David Anglin
2010-03-29 12:11                               ` Carlos O'Donell
2010-03-29 14:02                                 ` John David Anglin
2010-03-31 13:55                                   ` Carlos O'Donell
2010-04-01 10:54                                     ` Helge Deller
2010-04-01 13:33                                       ` John David Anglin
2010-04-01 18:55                                         ` Helge Deller
2010-03-28 17:32   ` John David Anglin
2010-03-28 18:20     ` Carlos O'Donell

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.