Bug 431456 - syscall() not working with __NR_clone as per documentation
Summary: syscall() not working with __NR_clone as per documentation
Keywords:
Status: CLOSED INSUFFICIENT_DATA
Alias: None
Product: Red Hat Enterprise Linux 5
Classification: Red Hat
Component: kernel
Version: 5.0
Hardware: All
OS: Linux
low
medium
Target Milestone: rc
: ---
Assignee: Anton Arapov
QA Contact: Martin Jenner
URL:
Whiteboard:
Depends On:
Blocks:
TreeView+ depends on / blocked
 
Reported: 2008-02-04 16:43 UTC by Jon Wallace
Modified: 2014-06-18 08:01 UTC (History)
3 users (show)

Fixed In Version:
Doc Type: Bug Fix
Doc Text:
Clone Of:
Environment:
Last Closed: 2008-12-18 11:25:00 UTC
Target Upstream Version:
Embargoed:


Attachments (Terms of Use)

Description Jon Wallace 2008-02-04 16:43:48 UTC
Description of problem:  The syscall() system call using the __NR_clone 
parameter as an alternative to clone(), does not accept any stack pointer size 
larger than zero.  According to various documents, the user application is 
supposed to allocate memory for the child's stack pointer when using the 
CLONE_NEWNS flag.  However, a segfault occurs and shows up 
in /var/log/messages reqardless of the size of the child's stack pointer.  I 
have tried the following, without success:

#define CHILD_STACK_MEM 65536
pid = syscall(__NR_clone, flags, cstack);
pid = syscall(__NR_clone, flags, cstack+CHILD_STACK_MEM);


Version-Release number of selected component (if applicable): RHEL 5.0 + 5.1


How reproducible:  This is easily reproduced with a simple program included 
here.  Usage is <progname> newns

#include "includes.h"
#include <sched.h>

#define CHILD_STACK_MEM 65536

int main(int argc, char **argv)
{
    int exitval, result;
    int flags = CLONE_VFORK;
    char *cstack;
    pid_t pid;

    if (argc != 2) {
        fprintf(stderr, "Usage:\n%s <flag>\n", argv[0]);
        return TEST_ERROR;
    }

    if (!strcmp(argv[1], "newns")) {
        flags |= CLONE_NEWNS;
    } else {
        fprintf(stderr, "Usage:\n%s: unknown flag: %s\n", argv[0], argv[1]);
        return TEST_ERROR;
    }

    cstack = malloc(CHILD_STACK_MEM);
    if (!cstack) {
        perror("do_clone: malloc");
        return TEST_ERROR;
    }

    /* use syscall() to force clone over clone2 */
    errno = 0;
    pid = syscall(__NR_clone, flags, cstack);

    /* child */
    if (pid == 0)
        _exit(0);

    /* parent */
    free(cstack);
    exitval = pid;
    result = exitval < 0;

    printf("%d %d %d\n", result, result ? errno : exitval, getpid());
    return result;
}



Steps to Reproduce:
1. Compile and use the program included above.
2. Usage is: <progname> newns
3. Check /var/log/messages for the segfault.
  
Actual results:
Segfault in /var/logs/messages

Expected results:
No segfault

Additional info:

Comment 1 Anton Arapov 2008-06-16 08:54:06 UTC
Jon, please try to reproduce it in RHEL5.2.
I didn't get segfault in kernel-2.6.18-92.1.1

/me looking how the __NR_clone stuff implemented...


Note You need to log in before you can comment on or make changes to this bug.