Bug 431456 - syscall() not working with __NR_clone as per documentation
syscall() not working with __NR_clone as per documentation
Status: CLOSED INSUFFICIENT_DATA
Product: Red Hat Enterprise Linux 5
Classification: Red Hat
Component: kernel (Show other bugs)
5.0
All Linux
low Severity medium
: rc
: ---
Assigned To: Anton Arapov
Martin Jenner
: SELinux
Depends On:
Blocks:
  Show dependency treegraph
 
Reported: 2008-02-04 11:43 EST by Jon Wallace
Modified: 2014-06-18 04:01 EDT (History)
3 users (show)

See Also:
Fixed In Version:
Doc Type: Bug Fix
Doc Text:
Story Points: ---
Clone Of:
Environment:
Last Closed: 2008-12-18 06:25:00 EST
Type: ---
Regression: ---
Mount Type: ---
Documentation: ---
CRM:
Verified Versions:
Category: ---
oVirt Team: ---
RHEL 7.3 requirements from Atomic Host:


Attachments (Terms of Use)

  None (edit)
Description Jon Wallace 2008-02-04 11:43:48 EST
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 04:54:06 EDT
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.