2017-03-18 09:52:38 +01:00
|
|
|
#include "magiskpolicy.h"
|
2017-04-19 22:28:56 +02:00
|
|
|
#include "sepolicy.h"
|
2016-09-13 00:19:07 +02:00
|
|
|
|
|
|
|
void allowSuClient(char *target) {
|
2018-03-11 00:23:30 +01:00
|
|
|
if (!sepol_exists(target))
|
|
|
|
return;
|
2018-04-14 21:13:01 +02:00
|
|
|
sepol_allow(target, SEPOL_PROC_DOMAIN, "unix_stream_socket", "connectto");
|
|
|
|
sepol_allow(target, SEPOL_PROC_DOMAIN, "unix_stream_socket", "getopt");
|
2017-04-19 22:28:56 +02:00
|
|
|
sepol_allow(target, "devpts", "chr_file", "ioctl");
|
2018-04-14 21:13:01 +02:00
|
|
|
sepol_allow(SEPOL_PROC_DOMAIN, target, "fd", "use");
|
|
|
|
sepol_allow(SEPOL_PROC_DOMAIN, target, "fifo_file", ALL);
|
2018-04-21 21:06:26 +02:00
|
|
|
sepol_allow(target, SEPOL_PROC_DOMAIN, "process", "sigchld");
|
2018-04-14 21:13:01 +02:00
|
|
|
|
|
|
|
// Allow access to magisk files
|
|
|
|
sepol_allow(target, SEPOL_FILE_DOMAIN, "sock_file", "read");
|
|
|
|
sepol_allow(target, SEPOL_FILE_DOMAIN, "sock_file", "write");
|
|
|
|
sepol_allow(target, SEPOL_FILE_DOMAIN, "file", ALL);
|
|
|
|
sepol_allow(target, SEPOL_FILE_DOMAIN, "dir", ALL);
|
2016-09-13 00:19:07 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void suRights() {
|
2018-04-14 21:13:01 +02:00
|
|
|
sepol_allow("servicemanager", SEPOL_PROC_DOMAIN, "dir", "search");
|
|
|
|
sepol_allow("servicemanager", SEPOL_PROC_DOMAIN, "dir", "read");
|
|
|
|
sepol_allow("servicemanager", SEPOL_PROC_DOMAIN, "file", "open");
|
|
|
|
sepol_allow("servicemanager", SEPOL_PROC_DOMAIN, "file", "read");
|
|
|
|
sepol_allow("servicemanager", SEPOL_PROC_DOMAIN, "process", "getattr");
|
|
|
|
sepol_allow("servicemanager", SEPOL_PROC_DOMAIN, "binder", "transfer");
|
|
|
|
sepol_allow("system_server", SEPOL_PROC_DOMAIN, "binder", "call");
|
|
|
|
sepol_allow("system_server", SEPOL_PROC_DOMAIN, "fd", "use");
|
|
|
|
|
|
|
|
sepol_allow(SEPOL_PROC_DOMAIN, "servicemanager", "dir", "search");
|
|
|
|
sepol_allow(SEPOL_PROC_DOMAIN, "servicemanager", "dir", "read");
|
|
|
|
sepol_allow(SEPOL_PROC_DOMAIN, "servicemanager", "file", "open");
|
|
|
|
sepol_allow(SEPOL_PROC_DOMAIN, "servicemanager", "file", "read");
|
|
|
|
sepol_allow(SEPOL_PROC_DOMAIN, "servicemanager", "process", "getattr");
|
|
|
|
sepol_allow(SEPOL_PROC_DOMAIN, "servicemanager", "binder", "transfer");
|
|
|
|
sepol_allow(SEPOL_PROC_DOMAIN, "servicemanager", "binder", "call");
|
|
|
|
sepol_allow(SEPOL_PROC_DOMAIN, "system_server", "binder", "transfer");
|
|
|
|
sepol_allow(SEPOL_PROC_DOMAIN, "system_server", "binder", "call");
|
2016-09-13 00:19:07 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void otherToSU() {
|
|
|
|
// allowLog
|
2018-04-14 21:13:01 +02:00
|
|
|
sepol_allow("logd", SEPOL_PROC_DOMAIN, "dir", "search");
|
|
|
|
sepol_allow("logd", SEPOL_PROC_DOMAIN, "file", "read");
|
|
|
|
sepol_allow("logd", SEPOL_PROC_DOMAIN, "file", "open");
|
|
|
|
sepol_allow("logd", SEPOL_PROC_DOMAIN, "file", "getattr");
|
2016-09-13 00:19:07 +02:00
|
|
|
|
|
|
|
// suBackL0
|
2018-04-14 21:13:01 +02:00
|
|
|
sepol_allow("system_server", SEPOL_PROC_DOMAIN, "binder", "call");
|
|
|
|
sepol_allow("system_server", SEPOL_PROC_DOMAIN, "binder", "transfer");
|
2016-09-13 00:19:07 +02:00
|
|
|
|
|
|
|
// suBackL6
|
2017-04-15 13:26:29 +02:00
|
|
|
sepol_allow("surfaceflinger", "app_data_file", "dir", ALL);
|
|
|
|
sepol_allow("surfaceflinger", "app_data_file", "file", ALL);
|
|
|
|
sepol_allow("surfaceflinger", "app_data_file", "lnk_file", ALL);
|
|
|
|
sepol_attradd("surfaceflinger", "mlstrustedsubject");
|
2016-11-02 18:20:35 +01:00
|
|
|
|
|
|
|
// suMiscL6
|
2017-04-15 13:26:29 +02:00
|
|
|
if (sepol_exists("audioserver"))
|
|
|
|
sepol_allow("audioserver", "audioserver", "process", "execmem");
|
2017-06-07 05:42:51 +02:00
|
|
|
|
|
|
|
// Liveboot
|
2018-04-14 21:13:01 +02:00
|
|
|
sepol_allow("surfaceflinger", SEPOL_PROC_DOMAIN, "process", "ptrace");
|
|
|
|
sepol_allow("surfaceflinger", SEPOL_PROC_DOMAIN, "binder", "transfer");
|
|
|
|
sepol_allow("surfaceflinger", SEPOL_PROC_DOMAIN, "binder", "call");
|
|
|
|
sepol_allow("surfaceflinger", SEPOL_PROC_DOMAIN, "fd", "use");
|
|
|
|
sepol_allow("debuggerd", SEPOL_PROC_DOMAIN, "process", "ptrace");
|
2017-11-28 23:09:35 +01:00
|
|
|
|
|
|
|
// dumpsys
|
2018-04-14 21:13:01 +02:00
|
|
|
sepol_allow(ALL, SEPOL_PROC_DOMAIN, "fd", "use");
|
|
|
|
sepol_allow(ALL, SEPOL_PROC_DOMAIN, "fifo_file", "write");
|
|
|
|
sepol_allow(ALL, SEPOL_PROC_DOMAIN, "fifo_file", "read");
|
|
|
|
sepol_allow(ALL, SEPOL_PROC_DOMAIN, "fifo_file", "open");
|
|
|
|
sepol_allow(ALL, SEPOL_PROC_DOMAIN, "fifo_file", "getattr");
|
2016-09-13 00:19:07 +02:00
|
|
|
}
|
|
|
|
|
2017-11-28 23:09:35 +01:00
|
|
|
void sepol_magisk_rules() {
|
|
|
|
// First prevent anything to change sepolicy except ourselves
|
|
|
|
sepol_deny(ALL, "kernel", "security", "load_policy");
|
|
|
|
|
2018-04-14 21:13:01 +02:00
|
|
|
if (!sepol_exists(SEPOL_PROC_DOMAIN))
|
|
|
|
sepol_create(SEPOL_PROC_DOMAIN);
|
|
|
|
if (!sepol_exists(SEPOL_FILE_DOMAIN))
|
|
|
|
sepol_create(SEPOL_FILE_DOMAIN);
|
|
|
|
sepol_permissive(SEPOL_PROC_DOMAIN);
|
2016-10-02 16:48:49 +02:00
|
|
|
|
2018-04-14 21:13:01 +02:00
|
|
|
sepol_attradd(SEPOL_PROC_DOMAIN, "mlstrustedsubject");
|
2018-04-21 21:06:26 +02:00
|
|
|
sepol_attradd(SEPOL_PROC_DOMAIN, "netdomain");
|
|
|
|
sepol_attradd(SEPOL_PROC_DOMAIN, "bluetoothdomain");
|
2018-04-14 21:13:01 +02:00
|
|
|
sepol_attradd(SEPOL_FILE_DOMAIN, "mlstrustedobject");
|
2017-11-03 21:04:00 +01:00
|
|
|
|
2017-12-11 19:36:11 +01:00
|
|
|
// Let init run stuffs
|
2018-04-14 21:13:01 +02:00
|
|
|
sepol_allow("kernel", SEPOL_PROC_DOMAIN, "fd", "use");
|
|
|
|
sepol_allow("init", SEPOL_PROC_DOMAIN, "process", ALL);
|
2016-11-02 18:20:35 +01:00
|
|
|
|
2018-01-01 17:10:49 +01:00
|
|
|
// Shell, properties, logs
|
|
|
|
if (sepol_exists("default_prop"))
|
2018-04-14 21:13:01 +02:00
|
|
|
sepol_allow(SEPOL_PROC_DOMAIN, "default_prop", "property_service", "set");
|
|
|
|
sepol_allow(SEPOL_PROC_DOMAIN, "init", "unix_stream_socket", "connectto");
|
|
|
|
sepol_allow(SEPOL_PROC_DOMAIN, "rootfs", "filesystem", "remount");
|
2017-04-18 15:29:52 +02:00
|
|
|
if (sepol_exists("logd"))
|
2018-04-14 21:13:01 +02:00
|
|
|
sepol_allow(SEPOL_PROC_DOMAIN, "logd", "unix_stream_socket", "connectto");
|
|
|
|
sepol_allow(SEPOL_PROC_DOMAIN, SEPOL_PROC_DOMAIN, ALL, ALL);
|
2016-11-02 18:20:35 +01:00
|
|
|
|
|
|
|
// For sepolicy live patching
|
2018-04-14 21:13:01 +02:00
|
|
|
sepol_allow(SEPOL_PROC_DOMAIN, "kernel", "security", "read_policy");
|
|
|
|
sepol_allow(SEPOL_PROC_DOMAIN, "kernel", "security", "load_policy");
|
2016-10-02 16:48:49 +02:00
|
|
|
|
2017-11-28 23:09:35 +01:00
|
|
|
// Allow these client to access su
|
2018-04-14 21:13:01 +02:00
|
|
|
allowSuClient("init");
|
2017-11-28 23:09:35 +01:00
|
|
|
allowSuClient("shell");
|
|
|
|
allowSuClient("untrusted_app");
|
|
|
|
allowSuClient("system_app");
|
|
|
|
allowSuClient("platform_app");
|
2018-03-11 00:23:30 +01:00
|
|
|
allowSuClient("priv_app");
|
|
|
|
allowSuClient("untrusted_app_25");
|
|
|
|
allowSuClient("untrusted_app_27");
|
2017-11-28 23:09:35 +01:00
|
|
|
|
|
|
|
// Some superuser stuffs
|
|
|
|
suRights();
|
|
|
|
otherToSU();
|
|
|
|
|
2017-12-31 12:20:49 +01:00
|
|
|
// For mounting loop devices, mirrors, tmpfs
|
2018-04-14 21:13:01 +02:00
|
|
|
sepol_allow(SEPOL_PROC_DOMAIN, "kernel", "process", "setsched");
|
|
|
|
sepol_allow(SEPOL_PROC_DOMAIN, "labeledfs", "filesystem", "mount");
|
|
|
|
sepol_allow(SEPOL_PROC_DOMAIN, "labeledfs", "filesystem", "unmount");
|
|
|
|
sepol_allow(SEPOL_PROC_DOMAIN, "tmpfs", "filesystem", "mount");
|
|
|
|
sepol_allow(SEPOL_PROC_DOMAIN, "tmpfs", "filesystem", "unmount");
|
2017-11-22 09:03:57 +01:00
|
|
|
sepol_allow("kernel", ALL, "file", "read");
|
2017-03-29 20:02:39 +02:00
|
|
|
|
2017-11-28 23:09:35 +01:00
|
|
|
// Allow su to do anything to any files/dir/links
|
2018-04-14 21:13:01 +02:00
|
|
|
sepol_allow(SEPOL_PROC_DOMAIN, ALL, "file", ALL);
|
|
|
|
sepol_allow(SEPOL_PROC_DOMAIN, ALL, "dir", ALL);
|
|
|
|
sepol_allow(SEPOL_PROC_DOMAIN, ALL, "lnk_file", ALL);
|
|
|
|
sepol_allow(SEPOL_PROC_DOMAIN, ALL, "blk_file", ALL);
|
|
|
|
sepol_allow(SEPOL_PROC_DOMAIN, ALL, "sock_file", ALL);
|
|
|
|
sepol_allow(SEPOL_PROC_DOMAIN, ALL, "chr_file", ALL);
|
|
|
|
sepol_allow(SEPOL_PROC_DOMAIN, ALL, "fifo_file", ALL);
|
2017-11-28 23:09:35 +01:00
|
|
|
|
2017-07-13 18:49:40 +02:00
|
|
|
// For changing attributes
|
|
|
|
sepol_allow("rootfs", "tmpfs", "filesystem", "associate");
|
2018-04-14 21:13:01 +02:00
|
|
|
sepol_allow(SEPOL_FILE_DOMAIN, "labeledfs", "filesystem", "associate");
|
|
|
|
sepol_allow(SEPOL_FILE_DOMAIN, "tmpfs", "filesystem", "associate");
|
2017-07-13 18:49:40 +02:00
|
|
|
|
2016-10-02 16:48:49 +02:00
|
|
|
// Xposed
|
2017-04-15 13:26:29 +02:00
|
|
|
sepol_allow("untrusted_app", "untrusted_app", "capability", "setgid");
|
|
|
|
sepol_allow("system_server", "dex2oat_exec", "file", ALL);
|
2017-04-19 22:28:56 +02:00
|
|
|
|
|
|
|
// xperms
|
2017-11-22 09:03:57 +01:00
|
|
|
if (policydb->policyvers >= POLICYDB_VERSION_XPERMS_IOCTL) {
|
2017-04-22 00:28:56 +02:00
|
|
|
sepol_allowxperm("domain", "devpts", "chr_file", "0x5400-0x54FF");
|
2017-12-31 12:20:49 +01:00
|
|
|
if (sepol_exists("untrusted_app_25_devpts"))
|
|
|
|
sepol_allowxperm("domain", "untrusted_app_25_devpts", "chr_file", "0x5400-0x54FF");
|
2018-02-18 11:47:25 +01:00
|
|
|
if (sepol_exists("untrusted_app_devpts"))
|
|
|
|
sepol_allowxperm("domain", "untrusted_app_devpts", "chr_file", "0x5400-0x54FF");
|
2017-11-22 09:03:57 +01:00
|
|
|
}
|
2017-04-15 20:29:42 +02:00
|
|
|
}
|