kernel: added new prctl CMD_GET_MANAGER_UID to get the uid of the crowned manager

manager: show crowned manager uid in infocard when developer options is enabled
This commit is contained in:
Rifat Azad
2025-06-30 14:19:07 +06:00
parent 98b9863041
commit 4e3f06d405
7 changed files with 48 additions and 1 deletions

View File

@@ -328,6 +328,17 @@ int ksu_handle_prctl(int option, unsigned long arg2, unsigned long arg3,
return 0;
}
if (arg2 == CMD_GET_MANAGER_UID) {
uid_t manager_uid = ksu_get_manager_uid();
if (copy_to_user((void __user *)arg3, &manager_uid, sizeof(manager_uid))) {
pr_err("prctl reply error, cmd: %lu\n", arg2);
}
if (copy_to_user(result, &reply_ok, sizeof(reply_ok))) {
pr_err("prctl reply error, cmd: %lu\n", arg2);
}
return 0;
}
if (arg2 == CMD_HOOK_MODE) {
#ifdef CONFIG_KSU_KPROBES_HOOK
const char *mode = "Kprobes";

View File

@@ -24,6 +24,7 @@
#define CMD_IS_SU_ENABLED 14
#define CMD_ENABLE_SU 15
#define CMD_HOOK_MODE 16
#define CMD_GET_MANAGER_UID 17
#define EVENT_POST_FS_DATA 1
#define EVENT_BOOT_COMPLETED 2

View File

@@ -25,6 +25,13 @@ Java_com_rifsxd_ksunext_Natives_getVersion(JNIEnv *env, jobject) {
return get_version();
}
extern "C"
JNIEXPORT jint JNICALL
Java_com_rifsxd_ksunext_Natives_getManagerUid(JNIEnv *env, jobject) {
uid_t manager_uid = get_manager_uid();
return (jint)manager_uid;
}
extern "C"
JNIEXPORT jstring JNICALL
Java_com_rifsxd_ksunext_Natives_getHookMode(JNIEnv *env, jobject) {

View File

@@ -30,6 +30,7 @@
#define CMD_IS_SU_ENABLED 14
#define CMD_ENABLE_SU 15
#define CMD_HOOK_MODE 16
#define CMD_GET_MANAGER_UID 17
static bool ksuctl(int cmd, void* arg1, void* arg2) {
int32_t result = 0;
@@ -63,12 +64,19 @@ int get_version(void) {
return version;
}
uid_t get_manager_uid() {
uid_t manager_uid = (uid_t)-1;
ksuctl(CMD_GET_MANAGER_UID, &manager_uid, nullptr);
return manager_uid;
}
const char* get_hook_mode() {
static char mode[16];
ksuctl(CMD_HOOK_MODE, mode, nullptr);
return mode;
}
bool get_allow_list(int *uids, int *size) {
return ksuctl(CMD_GET_SU_LIST, uids, size);
}

View File

@@ -11,6 +11,8 @@ bool become_manager(const char *);
int get_version();
uid_t get_manager_uid();
const char* get_hook_mode();
bool get_allow_list(int *uids, int *size);

View File

@@ -28,6 +28,9 @@ object Natives {
// 12569: support get hook mode
const val MINIMAL_SUPPORTED_HOOK_MODE = 12569
// 12750: support get manager UID
const val MINIMAL_SUPPORTED_MANAGER_UID = 12751
const val KERNEL_SU_DOMAIN = "u:r:su:s0"
const val ROOT_UID = 0
@@ -54,6 +57,12 @@ object Natives {
external fun uidShouldUmount(uid: Int): Boolean
/**
* Get the UID of the current root manager.
* @return manager UID, or -1 if unavailable.
*/
external fun getManagerUid(): Int
/**
* Get a string indicating the SU hook mode enabled in kernel.
* The return values are:

View File

@@ -550,6 +550,8 @@ private fun InfoCard(autoExpand: Boolean = false) {
var expanded by rememberSaveable { mutableStateOf(false) }
val developerOptionsEnabled = prefs.getBoolean("enable_developer_options", false)
LaunchedEffect(autoExpand) {
if (autoExpand) {
expanded = true
@@ -598,7 +600,14 @@ private fun InfoCard(autoExpand: Boolean = false) {
val managerVersion = getManagerVersion(context)
InfoCardItem(
label = stringResource(R.string.home_manager_version),
content = "${managerVersion.first} (${managerVersion.second})",
content = if (
developerOptionsEnabled &&
Natives.version >= Natives.MINIMAL_SUPPORTED_MANAGER_UID
) {
"${managerVersion.first} (${managerVersion.second}) | UID: ${Natives.getManagerUid()}"
} else {
"${managerVersion.first} (${managerVersion.second})"
},
icon = painterResource(R.drawable.ic_ksu_next),
)