From 6bf19ecc34637a4ad5aaccb1ed91eb78e0d1dbff Mon Sep 17 00:00:00 2001 From: topjohnwu Date: Tue, 14 Feb 2017 06:31:18 +0800 Subject: [PATCH] Unlock all blocks to non-read-only Check more info: https://android.googlesource.com/platform/system/core/+/e18c0d5%5E!/ Should fix all root apps with issue gaining rw access to /system --- daemon.c | 31 +++++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) diff --git a/daemon.c b/daemon.c index 4ea08e454..1594c419e 100644 --- a/daemon.c +++ b/daemon.c @@ -24,6 +24,7 @@ #include #include #include +#include #include #include #include @@ -42,6 +43,7 @@ #include #include #include +#include #include #ifdef SUPERUSER_EMBEDDED @@ -451,6 +453,33 @@ static int daemon_accept(int fd) { return run_daemon_child(infd, outfd, errfd, argc, argv); } +static void unlock_blocks() { +#define DEV_BLOCKS "/dev/block" + char path[PATH_MAX]; + DIR *dir; + struct dirent *entry; + int fd, OFF = 0; + + if (!(dir = opendir(DEV_BLOCKS))) + return; + + while((entry = readdir(dir))) { + if (entry->d_type == DT_BLK && strstr(entry->d_name, "mmc") != NULL) { + sprintf(path, "%s/%s", DEV_BLOCKS, entry->d_name); + fd = open(path, O_RDONLY); + if (fd < 0) { + PLOGE("open"); + continue; + } + if (ioctl(fd, BLKROSET, &OFF) == -1) + PLOGE("ioctl"); + close(fd); + } + } + + closedir(dir); +} + int run_daemon() { if (getuid() != AID_ROOT || getgid() != AID_ROOT) { PLOGE("daemon requires root. uid/gid not root"); @@ -476,6 +505,8 @@ int run_daemon() { return -1; } + unlock_blocks(); + int fd; struct sockaddr_un sun;