From 1ba9ff2926921ae3e76425caaf753db8994d9168 Mon Sep 17 00:00:00 2001 From: GarfieldHan <2652609017@qq.com> Date: Sat, 15 Jun 2024 09:00:59 +0800 Subject: [PATCH] supercall: Add SUPERCALL_SU_GET_SAFEMODE Signed-off-by: GarfieldHan <2652609017@qq.com> --- kernel/patch/android/userd.c | 2 -- kernel/patch/common/supercall.c | 14 ++++++++++++++ kernel/patch/include/uapi/scdefs.h | 1 + user/supercall.h | 12 ++++++++++++ 4 files changed, 27 insertions(+), 2 deletions(-) diff --git a/kernel/patch/android/userd.c b/kernel/patch/android/userd.c index 7ba122aa..0cd75114 100644 --- a/kernel/patch/android/userd.c +++ b/kernel/patch/android/userd.c @@ -383,8 +383,6 @@ static void before_input_handle_event(hook_fargs4_t *args, void *udata) if (volumedown_pressed_count == 3) { log_boot("entering safemode ..."); android_is_safe_mode = 1; - struct file *filp = filp_open(SAFE_MODE_FLAG_FILE, O_WRONLY | O_CREAT | O_TRUNC, 0666); - if (filp && !IS_ERR(filp)) filp_close(filp, 0); } } } diff --git a/kernel/patch/common/supercall.c b/kernel/patch/common/supercall.c index c5a686b3..53a64a7e 100644 --- a/kernel/patch/common/supercall.c +++ b/kernel/patch/common/supercall.c @@ -199,6 +199,16 @@ static long call_su_allow_uid_nums() return su_allow_uid_nums(); } +#ifdef ANDROID +extern int android_is_safe_mode; +static long call_su_get_safemode() +{ + int result = android_is_safe_mode; + logkfd("[call_su_get_safemode] %d\n", result); + return result; +} +#endif + static long call_su_list_allow_uid(uid_t *__user uids, int num) { return su_allow_uids(1, uids, num); @@ -276,6 +286,10 @@ static long supercall(int is_key_auth, long cmd, long arg1, long arg2, long arg3 return call_su_get_allow_sctx((char *__user)arg1, (int)arg2); case SUPERCALL_SU_SET_ALLOW_SCTX: return call_su_set_allow_sctx((char *__user)arg1); +#ifdef ANDROID + case SUPERCALL_SU_GET_SAFEMODE: + return call_su_get_safemode(); +#endif default: break; } diff --git a/kernel/patch/include/uapi/scdefs.h b/kernel/patch/include/uapi/scdefs.h index 33e61f41..b1392ad4 100644 --- a/kernel/patch/include/uapi/scdefs.h +++ b/kernel/patch/include/uapi/scdefs.h @@ -95,6 +95,7 @@ struct su_profile #define SUPERCALL_SU_SET_ALLOW_SCTX 0x1106 #define SUPERCALL_SU_GET_PATH 0x1110 #define SUPERCALL_SU_RESET_PATH 0x1111 +#define SUPERCALL_SU_GET_SAFEMODE 0x1112 #define SUPERCALL_MAX 0x1200 diff --git a/user/supercall.h b/user/supercall.h index ffd55b22..769d3a1d 100644 --- a/user/supercall.h +++ b/user/supercall.h @@ -416,6 +416,18 @@ static inline long sc_skey_root_enable(const char *key, bool enable) return ret; } +/** + * @brief Get whether in safe mode + * + * @param key + * @return long + */ +static inline long sc_su_get_safemode(const char *key) +{ + if (!key || !key[0]) return -EINVAL; + return syscall(__NR_supercall, key, compact_cmd(key, SUPERCALL_SU_GET_SAFEMODE)); +} + // todo static inline long sc_pid_virt_to_phys(const char *key, pid_t pid, unsigned long vaddr) {