Skip to content

Commit 926f1ce

Browse files
authored
Merge branch 'main' into multi-module-impl
2 parents 57089ef + 78e3ec1 commit 926f1ce

File tree

14 files changed

+486
-268
lines changed

14 files changed

+486
-268
lines changed

kernel/core_hook.c

Lines changed: 20 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ static inline bool is_allow_su()
6262
return ksu_is_allow_uid(current_uid().val);
6363
}
6464

65-
static inline bool is_unsupported_uid(uid_t uid)
65+
static inline bool is_unsupported_app_uid(uid_t uid)
6666
{
6767
#define LAST_APPLICATION_UID 19999
6868
uid_t appid = uid % 100000;
@@ -506,14 +506,13 @@ int ksu_handle_prctl(int option, unsigned long arg2, unsigned long arg3,
506506
return 0;
507507
}
508508

509-
static bool is_appuid(kuid_t uid)
509+
static bool is_non_appuid(kuid_t uid)
510510
{
511511
#define PER_USER_RANGE 100000
512512
#define FIRST_APPLICATION_UID 10000
513-
#define LAST_APPLICATION_UID 19999
514513

515514
uid_t appid = uid.val % PER_USER_RANGE;
516-
return appid >= FIRST_APPLICATION_UID && appid <= LAST_APPLICATION_UID;
515+
return appid < FIRST_APPLICATION_UID;
517516
}
518517

519518
static bool should_umount(struct path *path)
@@ -585,13 +584,25 @@ int ksu_handle_setuid(struct cred *new, const struct cred *old)
585584
return 0;
586585
}
587586

588-
if (!is_appuid(new_uid) || is_unsupported_uid(new_uid.val)) {
589-
// pr_info("handle setuid ignore non application or isolated uid: %d\n", new_uid.val);
587+
if (is_non_appuid(new_uid)) {
588+
#ifdef CONFIG_KSU_DEBUG
589+
pr_info("handle setuid ignore non application uid: %d\n", new_uid.val);
590+
#endif
590591
return 0;
591592
}
592593

594+
// isolated process may be directly forked from zygote, always unmount
595+
if (is_unsupported_app_uid(new_uid.val)) {
596+
#ifdef CONFIG_KSU_DEBUG
597+
pr_info("handle umount for unsupported application uid: %d\n", new_uid.val);
598+
#endif
599+
goto do_umount;
600+
}
601+
593602
if (ksu_is_allow_uid(new_uid.val)) {
594-
// pr_info("handle setuid ignore allowed application: %d\n", new_uid.val);
603+
#ifdef CONFIG_KSU_DEBUG
604+
pr_info("handle setuid ignore allowed application: %d\n", new_uid.val);
605+
#endif
595606
return 0;
596607
}
597608

@@ -603,11 +614,11 @@ int ksu_handle_setuid(struct cred *new, const struct cred *old)
603614
#endif
604615
}
605616

617+
do_umount:
606618
// check old process's selinux context, if it is not zygote, ignore it!
607619
// because some su apps may setuid to untrusted_app but they are in global mount namespace
608620
// when we umount for such process, that is a disaster!
609-
bool is_zygote_child = is_zygote(old->security);
610-
if (!is_zygote_child) {
621+
if (!is_zygote(old->security)) {
611622
pr_info("handle umount ignore non zygote child: %d\n",
612623
current->pid);
613624
return 0;

kernel/sucompat.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -279,7 +279,8 @@ void ksu_sucompat_init()
279279
void ksu_sucompat_exit()
280280
{
281281
#ifdef CONFIG_KPROBES
282-
for (int i = 0; i < ARRAY_SIZE(su_kps); i++) {
282+
int i;
283+
for (i = 0; i < ARRAY_SIZE(su_kps); i++) {
283284
destroy_kprobe(&su_kps[i]);
284285
}
285286
#endif

manager/app/src/main/cpp/jni.cc

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,11 @@
88
#include "ksu.h"
99

1010
#define LOG_TAG "KernelSU"
11+
#ifdef NDEBUG
12+
#define LOGD(...) (void)0
13+
#else
1114
#define LOGD(...) __android_log_print(ANDROID_LOG_DEBUG, LOG_TAG, __VA_ARGS__)
15+
#endif
1216

1317
extern "C"
1418
JNIEXPORT jboolean JNICALL
@@ -305,4 +309,4 @@ extern "C"
305309
JNIEXPORT jboolean JNICALL
306310
Java_me_weishu_kernelsu_Natives_setSuEnabled(JNIEnv *env, jobject thiz, jboolean enabled) {
307311
return set_su_enabled(enabled);
308-
}
312+
}

manager/app/src/main/java/me/weishu/kernelsu/ui/component/Dialog.kt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -420,6 +420,7 @@ private fun ConfirmDialog(
420420
show = showDialog,
421421
title = visuals.title,
422422
onDismissRequest = {
423+
dismiss()
423424
showDialog.value = false
424425
},
425426
content = {

manager/app/src/main/java/me/weishu/kernelsu/ui/component/UninstallDialog.kt

Lines changed: 28 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@ import androidx.compose.foundation.layout.fillMaxWidth
66
import androidx.compose.foundation.layout.padding
77
import androidx.compose.runtime.Composable
88
import androidx.compose.runtime.MutableState
9+
import androidx.compose.runtime.mutableStateOf
10+
import androidx.compose.runtime.remember
911
import androidx.compose.ui.Modifier
1012
import androidx.compose.ui.platform.LocalContext
1113
import androidx.compose.ui.res.stringResource
@@ -43,6 +45,9 @@ fun UninstallDialog(
4345
val showTodo = {
4446
Toast.makeText(context, "TODO", Toast.LENGTH_SHORT).show()
4547
}
48+
val showConfirmDialog = remember(showDialog.value) { mutableStateOf(false) }
49+
val runType = remember(showDialog.value) { mutableStateOf<UninstallType?>(null) }
50+
4651
val run = { type: UninstallType ->
4752
when (type) {
4853
PERMANENT -> navigator.navigate(FlashScreenDestination(FlashIt.FlashUninstall)) {
@@ -84,11 +89,10 @@ fun UninstallDialog(
8489
options.forEachIndexed { index, type ->
8590
SuperArrow(
8691
onClick = {
87-
showDialog.value = false
88-
run(type)
92+
showConfirmDialog.value = true
93+
runType.value = type
8994
},
9095
title = stringResource(type.title),
91-
summary = if (type.message != 0) stringResource(type.message) else null,
9296
leftAction = {
9397
Icon(
9498
imageVector = type.icon,
@@ -112,4 +116,25 @@ fun UninstallDialog(
112116
)
113117
}
114118
)
119+
val confirmDialog = rememberConfirmDialog(
120+
onConfirm = {
121+
showConfirmDialog.value = false
122+
showDialog.value = false
123+
runType.value?.let { type ->
124+
run(type)
125+
}
126+
},
127+
onDismiss = {
128+
showConfirmDialog.value = false
129+
}
130+
)
131+
val dialogTitle = runType.value?.let { type ->
132+
options.find { it == type }?.let { stringResource(it.title) }
133+
} ?: ""
134+
val dialogContent = runType.value?.let { type ->
135+
options.find { it == type }?.let { stringResource(it.message) }
136+
}
137+
if (showConfirmDialog.value) {
138+
confirmDialog.showConfirm(title = dialogTitle, content = dialogContent)
139+
}
115140
}

manager/app/src/main/java/me/weishu/kernelsu/ui/screen/Install.kt

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -259,8 +259,7 @@ private fun SelectInstallMethod(onSelected: (InstallMethod) -> Unit = {}) {
259259
onConfirm = {
260260
selectedOption = InstallMethod.DirectInstallToInactiveSlot
261261
onSelected(InstallMethod.DirectInstallToInactiveSlot)
262-
},
263-
onDismiss = null
262+
}
264263
)
265264
val dialogTitle = stringResource(id = android.R.string.dialog_alert_title)
266265
val dialogContent = stringResource(id = R.string.install_inactive_slot_warning)

0 commit comments

Comments
 (0)