Skip to content

Commit 6fe3bcb

Browse files
author
bmax
committed
To ensure compatibility with Termux's su, we commented out some code that enhances robustness.
1 parent bd1bb32 commit 6fe3bcb

File tree

3 files changed

+19
-14
lines changed

3 files changed

+19
-14
lines changed

kernel/patch/android/sucompat.c

Lines changed: 17 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -253,7 +253,7 @@ static uid_t current_uid()
253253
return uid;
254254
}
255255

256-
#define TRY_DIRECT_MODIFY_USER
256+
// #define TRY_DIRECT_MODIFY_USER
257257

258258
static void handle_before_execve(hook_local_t *hook_local, char **__user u_filename_p, char **__user uargv, void *udata)
259259
{
@@ -312,21 +312,25 @@ static void handle_before_execve(hook_local_t *hook_local, char **__user u_filen
312312
}
313313
}
314314

315-
// args0
315+
// change args[0] to ANDROID_SU_PATH or ANDROID_LEGACY_SU_PATH if it's not
316+
// check filename instead of args[0] for convenient
316317
int argv_cplen = 0;
318+
if (strcmp(ANDROID_SU_PATH, filename) && strcmp(ANDROID_LEGACY_SU_PATH, filename)) {
317319
#ifdef TRY_DIRECT_MODIFY_USER
318-
const char __user *p1 = get_user_arg_ptr(0, *uargv, 0);
319-
argv_cplen = compat_copy_to_user((void *__user)p1, default_su_path, sizeof(default_su_path));
320+
const char __user *p1 = get_user_arg_ptr(0, *uargv, 0);
321+
argv_cplen = compat_copy_to_user((void *__user)p1, default_su_path, sizeof(default_su_path));
320322
#endif
321-
if (argv_cplen <= 0) {
322-
sp = sp ?: current_user_stack_pointer();
323-
sp -= sizeof(default_su_path);
324-
sp &= 0xFFFFFFFFFFFFFFF8;
325-
argv_cplen = compat_copy_to_user((void *)sp, default_su_path, sizeof(default_su_path));
326-
if (argv_cplen > 0) {
327-
int rc = set_user_arg_ptr(0, *uargv, 0, sp);
328-
if (rc < 0) { // todo: modify entire argv
329-
logkfi("call apd argv error, uid: %d, to_uid: %d, sctx: %s, rc: %d\n", uid, to_uid, sctx, rc);
323+
if (argv_cplen <= 0) {
324+
sp = sp ?: current_user_stack_pointer();
325+
sp -= sizeof(default_su_path);
326+
sp &= 0xFFFFFFFFFFFFFFF8;
327+
argv_cplen = compat_copy_to_user((void *)sp, default_su_path, sizeof(default_su_path));
328+
if (argv_cplen > 0) {
329+
int rc = set_user_arg_ptr(0, *uargv, 0, sp);
330+
if (rc < 0) { // todo: modify entire argv
331+
logkfi("call apd argv error, uid: %d, to_uid: %d, sctx: %s, rc: %d\n", uid, to_uid, sctx,
332+
rc);
333+
}
330334
}
331335
}
332336
}

kernel/patch/include/uapi/scdefs.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,7 @@ struct su_profile
6464
#define SU_PATH_MAX_LEN 128
6565

6666
#define ANDROID_SU_PATH "/system/bin/kp"
67+
#define ANDROID_LEGACY_SU_PATH "/system/bin/su"
6768
#define KPATCH_DATA_PATH "/data/adb/kpatch"
6869
#define KPATCH_DEV_PATH "/dev/kpatch"
6970
#define KPATCH_DEV_WORK_DIR "/dev/kpatch_work/"

version

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
#define MAJOR 0
22
#define MINOR 10
3-
#define PATCH 2
3+
#define PATCH 3

0 commit comments

Comments
 (0)