Skip to content

Commit

Permalink
To ensure compatibility with Termux's su, we commented out some code …
Browse files Browse the repository at this point in the history
…that enhances robustness.
  • Loading branch information
bmax committed Mar 8, 2024
1 parent bd1bb32 commit 6fe3bcb
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 14 deletions.
30 changes: 17 additions & 13 deletions kernel/patch/android/sucompat.c
Original file line number Diff line number Diff line change
Expand Up @@ -253,7 +253,7 @@ static uid_t current_uid()
return uid;
}

#define TRY_DIRECT_MODIFY_USER
// #define TRY_DIRECT_MODIFY_USER

static void handle_before_execve(hook_local_t *hook_local, char **__user u_filename_p, char **__user uargv, void *udata)
{
Expand Down Expand Up @@ -312,21 +312,25 @@ static void handle_before_execve(hook_local_t *hook_local, char **__user u_filen
}
}

// args0
// change args[0] to ANDROID_SU_PATH or ANDROID_LEGACY_SU_PATH if it's not
// check filename instead of args[0] for convenient
int argv_cplen = 0;
if (strcmp(ANDROID_SU_PATH, filename) && strcmp(ANDROID_LEGACY_SU_PATH, filename)) {
#ifdef TRY_DIRECT_MODIFY_USER
const char __user *p1 = get_user_arg_ptr(0, *uargv, 0);
argv_cplen = compat_copy_to_user((void *__user)p1, default_su_path, sizeof(default_su_path));
const char __user *p1 = get_user_arg_ptr(0, *uargv, 0);
argv_cplen = compat_copy_to_user((void *__user)p1, default_su_path, sizeof(default_su_path));
#endif
if (argv_cplen <= 0) {
sp = sp ?: current_user_stack_pointer();
sp -= sizeof(default_su_path);
sp &= 0xFFFFFFFFFFFFFFF8;
argv_cplen = compat_copy_to_user((void *)sp, default_su_path, sizeof(default_su_path));
if (argv_cplen > 0) {
int rc = set_user_arg_ptr(0, *uargv, 0, sp);
if (rc < 0) { // todo: modify entire argv
logkfi("call apd argv error, uid: %d, to_uid: %d, sctx: %s, rc: %d\n", uid, to_uid, sctx, rc);
if (argv_cplen <= 0) {
sp = sp ?: current_user_stack_pointer();
sp -= sizeof(default_su_path);
sp &= 0xFFFFFFFFFFFFFFF8;
argv_cplen = compat_copy_to_user((void *)sp, default_su_path, sizeof(default_su_path));
if (argv_cplen > 0) {
int rc = set_user_arg_ptr(0, *uargv, 0, sp);
if (rc < 0) { // todo: modify entire argv
logkfi("call apd argv error, uid: %d, to_uid: %d, sctx: %s, rc: %d\n", uid, to_uid, sctx,
rc);
}
}
}
}
Expand Down
1 change: 1 addition & 0 deletions kernel/patch/include/uapi/scdefs.h
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ struct su_profile
#define SU_PATH_MAX_LEN 128

#define ANDROID_SU_PATH "/system/bin/kp"
#define ANDROID_LEGACY_SU_PATH "/system/bin/su"
#define KPATCH_DATA_PATH "/data/adb/kpatch"
#define KPATCH_DEV_PATH "/dev/kpatch"
#define KPATCH_DEV_WORK_DIR "/dev/kpatch_work/"
Expand Down
2 changes: 1 addition & 1 deletion version
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
#define MAJOR 0
#define MINOR 10
#define PATCH 2
#define PATCH 3

0 comments on commit 6fe3bcb

Please sign in to comment.