Skip to content

Instantly share code, notes, and snippets.

@mkenigs
Created March 10, 2020 20:14
Show Gist options
  • Save mkenigs/e92e5942182b984ff1fdec95eccfbf9e to your computer and use it in GitHub Desktop.
Save mkenigs/e92e5942182b984ff1fdec95eccfbf9e to your computer and use it in GitHub Desktop.
#include <stdio.h>
#include <unistd.h>
#include <stdlib.h>
#include <sched.h>
#include <signal.h>
#include <sys/wait.h>
#include <sys/types.h>
static int childFunc(void *arg)
{
printf("UID inside the namespace is %ld\n", (long)geteuid());
printf("GID inside the namespace is %ld\n", (long)getegid());
return 0;
}
static char child_stack[1024*1024];
int main(int argc, char *argv[])
{
pid_t child_pid;
child_pid = clone(&childFunc, child_stack + (1024*1024), CLONE_NEWUSER, 0);
printf("UID outside the namespace is %ld\n", (long)geteuid());
printf("GID outside the namespace is %ld\n", (long)getegid());
waitpid(child_pid, NULL, 0);
exit(EXIT_SUCCESS);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment