kernel: enable sucompat if requested and current UID is in allowlist

This commit is contained in:
Rifat Azad
2025-07-13 20:37:04 +06:00
parent c6b60a24e8
commit 1744286c3e

View File

@@ -505,28 +505,25 @@ int ksu_handle_prctl(int option, unsigned long arg2, unsigned long arg3,
}
if (arg2 == CMD_ENABLE_SU) {
bool enabled = (arg3 != 0);
if (enabled == ksu_su_compat_enabled) {
pr_info("cmd enable su but no need to change.\n");
if (copy_to_user(result, &reply_ok, sizeof(reply_ok))) {// return the reply_ok directly
pr_err("prctl reply error, cmd: %lu\n", arg2);
}
return 0;
}
bool enabled = (arg3 != 0);
if (enabled) {
ksu_sucompat_init();
} else {
ksu_sucompat_exit();
}
ksu_su_compat_enabled = enabled;
// keep sucompat disabled
ksu_sucompat_exit();
if (copy_to_user(result, &reply_ok, sizeof(reply_ok))) {
pr_err("prctl reply error, cmd: %lu\n", arg2);
}
// only enable sucompat if requested and current UID is in allowlist
if (enabled && ksu_is_allow_uid(current_uid().val)) {
ksu_sucompat_init();
ksu_su_compat_enabled = true;
} else {
ksu_su_compat_enabled = false;
}
return 0;
}
if (copy_to_user(result, &reply_ok, sizeof(reply_ok))) {
pr_err("prctl reply error, cmd: %lu\n", arg2);
}
return 0;
}
return 0;
}