2020-05-23 09:18:25 +02:00
|
|
|
#include <initializer_list>
|
|
|
|
|
2020-03-09 09:50:30 +01:00
|
|
|
#include <logging.hpp>
|
|
|
|
#include <magiskpolicy.hpp>
|
2019-02-10 09:57:51 +01:00
|
|
|
|
2020-05-23 09:18:25 +02:00
|
|
|
#include "sepolicy.hpp"
|
2016-09-13 00:19:07 +02:00
|
|
|
|
2020-05-23 09:18:25 +02:00
|
|
|
void sepol_impl::allow_su_client(const char *type) {
|
2020-05-21 15:48:02 +02:00
|
|
|
if (!exists(type))
|
2018-03-11 00:23:30 +01:00
|
|
|
return;
|
2020-05-21 15:48:02 +02:00
|
|
|
allow(type, SEPOL_PROC_DOMAIN, "unix_stream_socket", "connectto");
|
|
|
|
allow(type, SEPOL_PROC_DOMAIN, "unix_stream_socket", "getopt");
|
2018-04-14 21:13:01 +02:00
|
|
|
|
2018-09-20 22:55:16 +02:00
|
|
|
// Allow binder service
|
2020-05-21 15:48:02 +02:00
|
|
|
allow(type, SEPOL_PROC_DOMAIN, "binder", "call");
|
|
|
|
allow(type, SEPOL_PROC_DOMAIN, "binder", "transfer");
|
2019-04-30 03:25:57 +02:00
|
|
|
|
|
|
|
// Allow termios ioctl
|
2020-05-21 15:48:02 +02:00
|
|
|
allow(type, "devpts", "chr_file", "ioctl");
|
|
|
|
allow(type, "untrusted_app_devpts", "chr_file", "ioctl");
|
|
|
|
allow(type, "untrusted_app_25_devpts", "chr_file", "ioctl");
|
|
|
|
allow(type, "untrusted_app_all_devpts", "chr_file", "ioctl");
|
|
|
|
if (db->policyvers >= POLICYDB_VERSION_XPERMS_IOCTL) {
|
|
|
|
allowxperm(type, "devpts", "chr_file", "0x5400-0x54FF");
|
|
|
|
allowxperm(type, "untrusted_app_devpts", "chr_file", "0x5400-0x54FF");
|
|
|
|
allowxperm(type, "untrusted_app_25_devpts", "chr_file", "0x5400-0x54FF");
|
|
|
|
allowxperm(type, "untrusted_app_all_devpts", "chr_file", "0x5400-0x54FF");
|
2019-04-30 03:25:57 +02:00
|
|
|
}
|
2016-09-13 00:19:07 +02:00
|
|
|
}
|
|
|
|
|
2020-05-21 15:48:02 +02:00
|
|
|
void sepolicy::magisk_rules() {
|
2018-11-29 12:31:05 +01:00
|
|
|
// Temp suppress warnings
|
|
|
|
auto bak = log_cb.w;
|
|
|
|
log_cb.w = nop_log;
|
|
|
|
|
2020-05-25 11:30:39 +02:00
|
|
|
// Prevent anything to change sepolicy except ourselves
|
2020-05-21 15:48:02 +02:00
|
|
|
deny(ALL, "kernel", "security", "load_policy");
|
2018-09-20 22:55:16 +02:00
|
|
|
|
2020-05-25 11:30:39 +02:00
|
|
|
type(SEPOL_PROC_DOMAIN, "domain");
|
|
|
|
type(SEPOL_FILE_DOMAIN, "file_type");
|
2020-05-21 15:48:02 +02:00
|
|
|
permissive(SEPOL_PROC_DOMAIN);
|
|
|
|
typeattribute(SEPOL_PROC_DOMAIN, "mlstrustedsubject");
|
|
|
|
typeattribute(SEPOL_PROC_DOMAIN, "netdomain");
|
|
|
|
typeattribute(SEPOL_PROC_DOMAIN, "bluetoothdomain");
|
|
|
|
typeattribute(SEPOL_FILE_DOMAIN, "mlstrustedobject");
|
2018-09-20 22:55:16 +02:00
|
|
|
|
2019-06-26 08:31:59 +02:00
|
|
|
// Let everyone access tmpfs files (for SAR sbin overlay)
|
2020-05-21 15:48:02 +02:00
|
|
|
allow(ALL, "tmpfs", "file", ALL);
|
2019-06-26 08:31:59 +02:00
|
|
|
|
2019-07-04 22:02:36 +02:00
|
|
|
// For normal rootfs file/directory operations when rw (for SAR / overlay)
|
2020-05-21 15:48:02 +02:00
|
|
|
allow("rootfs", "labeledfs", "filesystem", "associate");
|
2019-07-04 22:02:36 +02:00
|
|
|
|
2019-04-30 02:26:51 +02:00
|
|
|
// Let init transit to SEPOL_PROC_DOMAIN
|
2020-05-21 15:48:02 +02:00
|
|
|
allow("kernel", "kernel", "process", "setcurrent");
|
|
|
|
allow("kernel", SEPOL_PROC_DOMAIN, "process", "dyntransition");
|
2019-02-09 07:51:46 +01:00
|
|
|
|
2018-09-20 22:55:16 +02:00
|
|
|
// Let init run stuffs
|
2020-05-21 15:48:02 +02:00
|
|
|
allow("kernel", SEPOL_PROC_DOMAIN, "fd", "use");
|
|
|
|
allow("init", SEPOL_PROC_DOMAIN, "process", ALL);
|
|
|
|
allow("init", "tmpfs", "file", "getattr");
|
|
|
|
allow("init", "tmpfs", "file", "execute");
|
2018-09-20 22:55:16 +02:00
|
|
|
|
2020-05-25 11:30:39 +02:00
|
|
|
// Make our domain unconstrained
|
|
|
|
allow(SEPOL_PROC_DOMAIN, ALL, ALL, ALL);
|
|
|
|
// Allow us to do any ioctl on all block devices
|
|
|
|
if (db->policyvers >= POLICYDB_VERSION_XPERMS_IOCTL)
|
|
|
|
allowxperm(SEPOL_PROC_DOMAIN, ALL, "blk_file", ALL);
|
2018-09-20 22:55:16 +02:00
|
|
|
|
2020-05-25 11:30:39 +02:00
|
|
|
// Make our file type unconstrained
|
|
|
|
allow(ALL, SEPOL_FILE_DOMAIN, "file", ALL);
|
|
|
|
allow(ALL, SEPOL_FILE_DOMAIN, "dir", ALL);
|
|
|
|
allow(ALL, SEPOL_FILE_DOMAIN, "fifo_file", ALL);
|
|
|
|
allow(ALL, SEPOL_FILE_DOMAIN, "chr_file", ALL);
|
2018-09-20 22:55:16 +02:00
|
|
|
|
|
|
|
// Allow these processes to access MagiskSU
|
2020-05-23 09:18:25 +02:00
|
|
|
std::initializer_list<const char *> clients {
|
|
|
|
"init", "shell", "system_app", "priv_app", "platform_app", "untrusted_app",
|
|
|
|
"untrusted_app_25", "untrusted_app_27", "untrusted_app_29", "update_engine" };
|
|
|
|
for (auto type : clients)
|
|
|
|
impl->allow_su_client(type);
|
2018-09-20 22:55:16 +02:00
|
|
|
|
2018-07-20 16:22:49 +02:00
|
|
|
// suRights
|
2020-05-21 15:48:02 +02:00
|
|
|
allow("servicemanager", SEPOL_PROC_DOMAIN, "dir", "search");
|
|
|
|
allow("servicemanager", SEPOL_PROC_DOMAIN, "dir", "read");
|
|
|
|
allow("servicemanager", SEPOL_PROC_DOMAIN, "file", "open");
|
|
|
|
allow("servicemanager", SEPOL_PROC_DOMAIN, "file", "read");
|
|
|
|
allow("servicemanager", SEPOL_PROC_DOMAIN, "process", "getattr");
|
|
|
|
allow("servicemanager", SEPOL_PROC_DOMAIN, "binder", "transfer");
|
|
|
|
allow(ALL, SEPOL_PROC_DOMAIN, "process", "sigchld");
|
2018-09-11 17:04:46 +02:00
|
|
|
|
2016-09-13 00:19:07 +02:00
|
|
|
// allowLog
|
2020-05-21 15:48:02 +02:00
|
|
|
allow("logd", SEPOL_PROC_DOMAIN, "dir", "search");
|
|
|
|
allow("logd", SEPOL_PROC_DOMAIN, "file", "read");
|
|
|
|
allow("logd", SEPOL_PROC_DOMAIN, "file", "open");
|
|
|
|
allow("logd", SEPOL_PROC_DOMAIN, "file", "getattr");
|
2016-09-13 00:19:07 +02:00
|
|
|
|
|
|
|
// suBackL6
|
2020-05-21 15:48:02 +02:00
|
|
|
allow("surfaceflinger", "app_data_file", "dir", ALL);
|
|
|
|
allow("surfaceflinger", "app_data_file", "file", ALL);
|
|
|
|
allow("surfaceflinger", "app_data_file", "lnk_file", ALL);
|
|
|
|
typeattribute("surfaceflinger", "mlstrustedsubject");
|
2016-11-02 18:20:35 +01:00
|
|
|
|
|
|
|
// suMiscL6
|
2020-05-25 11:30:39 +02:00
|
|
|
allow("audioserver", "audioserver", "process", "execmem");
|
2017-06-07 05:42:51 +02:00
|
|
|
|
|
|
|
// Liveboot
|
2020-05-21 15:48:02 +02:00
|
|
|
allow("surfaceflinger", SEPOL_PROC_DOMAIN, "process", "ptrace");
|
|
|
|
allow("surfaceflinger", SEPOL_PROC_DOMAIN, "binder", "transfer");
|
|
|
|
allow("surfaceflinger", SEPOL_PROC_DOMAIN, "binder", "call");
|
|
|
|
allow("surfaceflinger", SEPOL_PROC_DOMAIN, "fd", "use");
|
|
|
|
allow("debuggerd", SEPOL_PROC_DOMAIN, "process", "ptrace");
|
2017-11-28 23:09:35 +01:00
|
|
|
|
|
|
|
// dumpsys
|
2020-05-21 15:48:02 +02:00
|
|
|
allow(ALL, SEPOL_PROC_DOMAIN, "fd", "use");
|
|
|
|
allow(ALL, SEPOL_PROC_DOMAIN, "fifo_file", "write");
|
|
|
|
allow(ALL, SEPOL_PROC_DOMAIN, "fifo_file", "read");
|
|
|
|
allow(ALL, SEPOL_PROC_DOMAIN, "fifo_file", "open");
|
|
|
|
allow(ALL, SEPOL_PROC_DOMAIN, "fifo_file", "getattr");
|
2018-07-20 16:22:49 +02:00
|
|
|
|
|
|
|
// bootctl
|
2020-05-21 15:48:02 +02:00
|
|
|
allow("hwservicemanager", SEPOL_PROC_DOMAIN, "dir", "search");
|
|
|
|
allow("hwservicemanager", SEPOL_PROC_DOMAIN, "file", "read");
|
|
|
|
allow("hwservicemanager", SEPOL_PROC_DOMAIN, "file", "open");
|
|
|
|
allow("hwservicemanager", SEPOL_PROC_DOMAIN, "process", "getattr");
|
|
|
|
allow("hwservicemanager", SEPOL_PROC_DOMAIN, "binder", "transfer");
|
2017-11-28 23:09:35 +01:00
|
|
|
|
2017-12-31 12:20:49 +01:00
|
|
|
// For mounting loop devices, mirrors, tmpfs
|
2020-05-21 15:48:02 +02:00
|
|
|
allow("kernel", ALL, "file", "read");
|
|
|
|
allow("kernel", ALL, "file", "write");
|
2017-03-29 20:02:39 +02:00
|
|
|
|
2019-02-02 19:24:55 +01:00
|
|
|
// Allow all binder transactions
|
2020-05-21 15:48:02 +02:00
|
|
|
allow(ALL, SEPOL_PROC_DOMAIN, "binder", ALL);
|
2019-02-02 19:24:55 +01:00
|
|
|
|
2020-05-25 11:30:39 +02:00
|
|
|
// For changing file context
|
2020-05-21 15:48:02 +02:00
|
|
|
allow("rootfs", "tmpfs", "filesystem", "associate");
|
2017-07-13 18:49:40 +02:00
|
|
|
|
2016-10-02 16:48:49 +02:00
|
|
|
// Xposed
|
2020-05-21 15:48:02 +02:00
|
|
|
allow("untrusted_app", "untrusted_app", "capability", "setgid");
|
|
|
|
allow("system_server", "dex2oat_exec", "file", ALL);
|
2018-07-06 19:36:57 +02:00
|
|
|
|
|
|
|
// Support deodexed ROM on Oreo
|
2020-05-21 15:48:02 +02:00
|
|
|
allow("zygote", "dalvikcache_data_file", "file", "execute");
|
2018-08-03 16:40:49 +02:00
|
|
|
|
2019-02-17 16:34:22 +01:00
|
|
|
// Support deodexed ROM on Pie (Samsung)
|
2020-05-21 15:48:02 +02:00
|
|
|
allow("system_server", "dalvikcache_data_file", "file", "write");
|
|
|
|
allow("system_server", "dalvikcache_data_file", "file", "execute");
|
2019-09-19 16:53:05 +02:00
|
|
|
|
|
|
|
// Allow update_engine/addon.d-v2 to run permissive on all ROMs
|
2020-05-21 15:48:02 +02:00
|
|
|
permissive("update_engine");
|
2018-11-29 12:28:37 +01:00
|
|
|
|
2019-11-23 23:18:55 +01:00
|
|
|
#if 0
|
2019-04-30 02:26:51 +02:00
|
|
|
// Remove all dontaudit in debug mode
|
2020-05-23 09:18:25 +02:00
|
|
|
impl->strip_dontaudit();
|
2019-04-30 02:26:51 +02:00
|
|
|
#endif
|
2018-11-29 12:31:05 +01:00
|
|
|
|
|
|
|
log_cb.w = bak;
|
2017-04-15 20:29:42 +02:00
|
|
|
}
|