-
Notifications
You must be signed in to change notification settings - Fork 0
/
lsmsb-install.c
48 lines (37 loc) · 887 Bytes
/
lsmsb-install.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
#include <stdint.h>
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <fcntl.h>
#include <sys/stat.h>
static int
usage(const char *argv0) {
fprintf(stderr, "Usage: %s <sandbox file>\n", argv0);
return 1;
}
int
main(int argc, char **argv) {
if (argc != 2)
return usage(argv[0]);
const int fd = open(argv[1], O_RDONLY);
if (fd < 0) {
perror("opening input");
return 1;
}
struct stat st;
fstat(fd, &st);
uint8_t *buffer = malloc(st.st_size);
read(fd, buffer, st.st_size);
const int sandboxfd = open("/proc/self/attr/current", O_WRONLY);
if (sandboxfd < 0) {
perror("Opening /proc/self/attr/current");
return 1;
}
if (write(sandboxfd, buffer, st.st_size) == -1) {
perror("Installing sandbox");
return 1;
}
fprintf(stderr, "Sandbox installed\n");
execl("/bin/bash", "/bin/bash", NULL);
return 127;
}