Skip to content

Instantly share code, notes, and snippets.

@zyga
Last active March 30, 2017 15:03
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save zyga/652b608517443988754b704a8adf5b3f to your computer and use it in GitHub Desktop.
Save zyga/652b608517443988754b704a8adf5b3f to your computer and use it in GitHub Desktop.
setns apparmor bug

Usage instructions:

make
sudo snap install snapd-hacker-toolbelt --devmode
sudo snapd-hacker-toolbelt.busybox sh
./oops
.PHONY: all clean
CFLAGS += -Wall
all: oops
clean:
rm -f oops
#define _GNU_SOURCE
#include <fcntl.h>
#include <sched.h>
#include <stdio.h>
#include <stdlib.h>
#include <sys/stat.h>
#include <sys/types.h>
#include <unistd.h>
int main(void)
{
int fd = open("/proc/1/ns/mnt", O_RDONLY | O_CLOEXEC | O_PATH);
if (fd < 0) {
perror("cannot open");
return 1;
}
if (setns(fd, CLONE_NEWNS) < 0) {
perror("cannot setns");
return 1;
};
if (close(fd) < 0) {
perror("cannot close");
return 1;
}
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment