1#define _GNU_SOURCE
2
3#include <stdio.h>
4#include <string.h>
5#include <sys/stat.h>
6#include <unistd.h>
7#include <dlfcn.h>
8
9static const char sandbox_path[] = "/chrome-sandbox";
10
11int __xstat(int ver, const char* path, struct stat* stat_buf) {
12 static int (*original_xstat)(int, const char*, struct stat*) = NULL;
13 if (original_xstat == NULL) {
14 int (*fun)(int, const char*, struct stat*) = dlsym(RTLD_NEXT, "__xstat");
15 if (fun == NULL) {
16 return -1;
17 };
18 original_xstat = fun;
19 };
20
21 int res = (*original_xstat)(ver, path, stat_buf);
22 if (res == 0) {
23 char* pos = strstr(path, sandbox_path);
24 if (pos != NULL && *(pos + sizeof(sandbox_path) - 1) == '\0') {
25 printf("Lying about chrome-sandbox access rights...\n");
26 stat_buf->st_uid = 0;
27 stat_buf->st_gid = 0;
28 stat_buf->st_mode = 0104755;
29 };
30 }
31 return res;
32}