Magisk/jni/hidesu.c
Pierre-Hugues Husson e1279c29c2 Add hidesu program.
This is a test program, this will probably be integrated into su daemon.
This hides su by bind-mounting something (/system) over /sbin, so that
there is no /sbin/su binary.
Usage:
hidesu /proc/<one pid of the namespace>/ns/mnt

This uses the fact that when a program wants access to /sdcard, zygote
does this using mount namespaces, so every program accessing /sdcard
will be in a custom mount namespace, that can be modified.
2016-10-05 04:07:48 +08:00

23 lines
503 B
C

#define _GNU_SOURCE
#include <sched.h>
#include <fcntl.h>
#include <stdlib.h>
#include <stdio.h>
#include <sys/mount.h>
#include <sys/syscall.h>
int main(int argc, char **argv) {
if(argc != 2) exit(5);
int fd = open(argv[1], O_RDONLY);
if(fd == -1) exit(2);
//TODO: Fix non arm platforms
#define SYS_setns 375
int res = syscall(SYS_setns, fd, 0);
if(res == -1) exit(3);
//XXX: What to mount to /sbin...?
res = mount("/system", "/sbin", "bind", MS_BIND, "");
if(res == -1) exit(4);
exit(0);
}