Add webview zygote as umount target

https://github.com/tiann/KernelSU/commit/4521784328352c54334beb29e05c74360b60d7cb
This commit is contained in:
Wang Han
2026-08-30 02:59:46 -07:00
committed by GitHub
parent faa5f85b15
commit b2d86c79c2
5 changed files with 85 additions and 12 deletions
@@ -29,32 +29,36 @@ class CmdlineListItem(line: String) {
} }
const val ISOLATED_MAGIC = "isolated" const val ISOLATED_MAGIC = "isolated"
const val WEBVIEW_ZYGOTE_MAGIC = "webview_zygote"
const val WEBVIEW_ZYGOTE_UID = 1053
@SuppressLint("InlinedApi") @SuppressLint("InlinedApi")
class AppProcessInfo( class AppProcessInfo(
private val info: ApplicationInfo, private val info: ApplicationInfo,
pm: PackageManager, pm: PackageManager,
denyList: List<CmdlineListItem> denyList: List<CmdlineListItem>,
private val labelOverride: String? = null,
private val processesOverride: Collection<ProcessInfo>? = null,
) : Comparable<AppProcessInfo> { ) : Comparable<AppProcessInfo> {
private val denyList = denyList.filter { private val denyList = denyList.filter {
it.packageName == info.packageName || it.packageName == ISOLATED_MAGIC it.packageName == info.packageName || it.packageName == ISOLATED_MAGIC
} }
val label = info.getLabel(pm) val label = labelOverride ?: info.getLabel(pm)
val iconImage: Drawable = runCatching { info.loadIcon(pm) }.getOrDefault(pm.defaultActivityIcon) val iconImage: Drawable = runCatching { info.loadIcon(pm) }.getOrDefault(pm.defaultActivityIcon)
val packageName: String get() = info.packageName val packageName: String get() = info.packageName
var firstInstallTime: Long = 0L var firstInstallTime: Long = 0L
private set private set
var lastUpdateTime: Long = 0L var lastUpdateTime: Long = 0L
private set private set
val processes = fetchProcesses(pm) val processes = processesOverride ?: fetchProcesses(pm)
override fun compareTo(other: AppProcessInfo) = comparator.compare(this, other) override fun compareTo(other: AppProcessInfo) = comparator.compare(this, other)
fun isSystemApp() = info.flags and ApplicationInfo.FLAG_SYSTEM != 0 fun isSystemApp() = info.flags and ApplicationInfo.FLAG_SYSTEM != 0
fun isApp() = ProcessCompat.isApplicationUid(info.uid) fun isApp() = packageName == WEBVIEW_ZYGOTE_MAGIC || ProcessCompat.isApplicationUid(info.uid)
private fun createProcess(name: String, pkg: String = info.packageName) = private fun createProcess(name: String, pkg: String = info.packageName) =
ProcessInfo(name, pkg, denyList.any { it.process == name && it.packageName == pkg }) ProcessInfo(name, pkg, denyList.any { it.process == name && it.packageName == pkg })
@@ -117,6 +121,30 @@ class AppProcessInfo(
} }
companion object { companion object {
fun webViewZygote(
pm: PackageManager,
denyList: List<CmdlineListItem>,
label: String,
): AppProcessInfo {
val info = ApplicationInfo().apply {
packageName = WEBVIEW_ZYGOTE_MAGIC
uid = WEBVIEW_ZYGOTE_UID
}
val enabled = denyList.any {
it.packageName == WEBVIEW_ZYGOTE_MAGIC &&
it.process == WEBVIEW_ZYGOTE_MAGIC
}
return AppProcessInfo(
info,
pm,
denyList,
labelOverride = label,
processesOverride = listOf(
ProcessInfo(WEBVIEW_ZYGOTE_MAGIC, WEBVIEW_ZYGOTE_MAGIC, enabled)
),
)
}
private val comparator = compareBy<AppProcessInfo>( private val comparator = compareBy<AppProcessInfo>(
{ it.label.lowercase(Locale.ROOT) }, { it.label.lowercase(Locale.ROOT) },
{ it.info.packageName } { it.info.packageName }
@@ -190,8 +190,15 @@ class DenyListViewModel : AsyncLoadViewModel() {
.concurrentMap { AppProcessInfo(it, pm, denyList) } .concurrentMap { AppProcessInfo(it, pm, denyList) }
.filter { it.processes.isNotEmpty() } .filter { it.processes.isNotEmpty() }
.concurrentMap { DenyAppState(it) } .concurrentMap { DenyAppState(it) }
.toCollection(ArrayList(size)) .toCollection(ArrayList(size + 1))
} }
apps += DenyAppState(
AppProcessInfo.webViewZygote(
pm,
denyList,
"WebView Zygote",
)
)
apps.sortWith(compareBy( apps.sortWith(compareBy(
{ it.processes.count { p -> p.isEnabled } == 0 }, { it.processes.count { p -> p.isEnabled } == 0 },
{ it.info } { it.info }
+2
View File
@@ -3,6 +3,8 @@
#include <string_view> #include <string_view>
#define ISOLATED_MAGIC "isolated" #define ISOLATED_MAGIC "isolated"
#define WEBVIEW_ZYGOTE_MAGIC "webview_zygote"
#define WEBVIEW_ZYGOTE_UID 1053
namespace DenyRequest { namespace DenyRequest {
enum : int { enum : int {
+27 -7
View File
@@ -132,6 +132,32 @@ static void process_main_buffer(struct log_msg *msg) {
if (android_log_processLogBuffer(&msg->entry, &entry) < 0) return; if (android_log_processLogBuffer(&msg->entry, &entry) < 0) return;
entry.tagLen--; entry.tagLen--;
auto tag = string_view(entry.tag, entry.tagLen); auto tag = string_view(entry.tag, entry.tagLen);
auto revert = [](int pid, const char *name, int uid) {
kill(pid, SIGSTOP);
if (fork_dont_care() == 0) {
LOGI("logcat: revert [%s] PID=[%d] UID=[%d]\n", name, pid, uid);
revert_unmount(pid);
kill(pid, SIGCONT);
_exit(0);
}
};
// Unlike app zygote, webview zygote UID is fixed. This means we don't have to
// handle edge cases where apps print logs themselves and lead us into a honeycomb
if (tag == "WebViewZygoteInit") {
int pid = msg->entry.pid;
if (entry.uid != WEBVIEW_ZYGOTE_UID || entry.message[0] != 'S') {
return;
}
if (is_deny_target(WEBVIEW_ZYGOTE_UID, WEBVIEW_ZYGOTE_MAGIC)) {
revert(pid, WEBVIEW_ZYGOTE_MAGIC, WEBVIEW_ZYGOTE_UID);
} else {
LOGD("logcat: skip [%s] PID=[%d] UID=[%d]\n",
WEBVIEW_ZYGOTE_MAGIC, pid, WEBVIEW_ZYGOTE_UID);
}
return;
}
static bool ready = false; static bool ready = false;
if (tag == "AppZygote") { if (tag == "AppZygote") {
@@ -158,13 +184,7 @@ static void process_main_buffer(struct log_msg *msg) {
if (is_deny_target(entry.uid, cmdline)) { if (is_deny_target(entry.uid, cmdline)) {
int pid = msg->entry.pid; int pid = msg->entry.pid;
kill(pid, SIGSTOP); revert(pid, cmdline, entry.uid);
if (fork_dont_care() == 0) {
LOGI("logcat: revert [%s] PID=[%d] UID=[%d]\n", cmdline, pid, entry.uid);
revert_unmount(pid);
kill(pid, SIGCONT);
_exit(0);
}
} else { } else {
LOGD("logcat: skip [%s] PID=[%d] UID=[%d]\n", cmdline, msg->entry.pid, entry.uid); LOGD("logcat: skip [%s] PID=[%d] UID=[%d]\n", cmdline, msg->entry.pid, entry.uid);
} }
+16
View File
@@ -17,6 +17,7 @@ using namespace std;
// For the following data structures: // For the following data structures:
// If package name == ISOLATED_MAGIC, or app ID == -1, it means isolated service // If package name == ISOLATED_MAGIC, or app ID == -1, it means isolated service
// If package name == WEBVIEW_ZYGOTE_MAGIC, or app ID == 1053, it means webview zygote
// Package name -> list of process names // Package name -> list of process names
static unique_ptr<map<string, set<string, StringCmp>, StringCmp>> pkg_to_procs_; static unique_ptr<map<string, set<string, StringCmp>, StringCmp>> pkg_to_procs_;
@@ -56,6 +57,8 @@ static void collect_users(vector<int> &users) {
static int get_app_id(const string &pkg) { static int get_app_id(const string &pkg) {
if (pkg == ISOLATED_MAGIC) if (pkg == ISOLATED_MAGIC)
return -1; return -1;
if (pkg == WEBVIEW_ZYGOTE_MAGIC)
return WEBVIEW_ZYGOTE_UID;
vector<int> users; vector<int> users;
collect_users(users); collect_users(users);
return get_app_id(users, pkg); return get_app_id(users, pkg);
@@ -144,6 +147,9 @@ static bool validate(const char *pkg, const char *proc) {
proc_valid = false; proc_valid = false;
break; break;
} }
} else if (str_eql(pkg, WEBVIEW_ZYGOTE_MAGIC)) {
pkg_valid = true;
proc_valid = str_eql(proc, WEBVIEW_ZYGOTE_MAGIC);
} else { } else {
for (char c; (c = *pkg); ++pkg) { for (char c; (c = *pkg); ++pkg) {
if (isalnum(c) || c == '_') if (isalnum(c) || c == '_')
@@ -176,6 +182,8 @@ static bool add_hide_set(const char *pkg, const char *proc) {
if (str_eql(pkg, ISOLATED_MAGIC)) { if (str_eql(pkg, ISOLATED_MAGIC)) {
// Kill all matching isolated processes // Kill all matching isolated processes
kill_process<&proc_name_match<str_starts_with>>(proc, true); kill_process<&proc_name_match<str_starts_with>>(proc, true);
} else if (str_eql(pkg, WEBVIEW_ZYGOTE_MAGIC)) {
kill_process<&proc_context_match>("u:r:webview_zygote:s0", true);
} else { } else {
kill_process(proc); kill_process(proc);
} }
@@ -196,6 +204,11 @@ void scan_deny_apps() {
it++; it++;
continue; continue;
} }
if (it->first == WEBVIEW_ZYGOTE_MAGIC) {
update_app_id(WEBVIEW_ZYGOTE_UID, it->first, false);
it++;
continue;
}
int app_id = get_app_id(users, it->first); int app_id = get_app_id(users, it->first);
if (app_id == 0) { if (app_id == 0) {
LOGI("denylist rm: [%s]\n", it->first.data()); LOGI("denylist rm: [%s]\n", it->first.data());
@@ -383,6 +396,9 @@ int enable_deny() {
kill_process("usap64", true); kill_process("usap64", true);
kill_process<&proc_context_match>("u:r:app_zygote:s0", true); kill_process<&proc_context_match>("u:r:app_zygote:s0", true);
} }
if (pkg_to_procs.find(WEBVIEW_ZYGOTE_MAGIC) != pkg_to_procs.end()) {
kill_process<&proc_context_match>("u:r:webview_zygote:s0", true);
}
} }
MagiskD::Get().set_db_setting(DbEntryKey::DenylistConfig, true); MagiskD::Get().set_db_setting(DbEntryKey::DenylistConfig, true);