Skip to content

Commit

Permalink
kernel: add support for disable sucompat
Browse files Browse the repository at this point in the history
  • Loading branch information
tiann committed Feb 16, 2025
1 parent 101d3ae commit 2096bd7
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 4 deletions.
45 changes: 41 additions & 4 deletions kernel/core_hook.c
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,10 @@ static bool ksu_module_mounted = false;

extern int handle_sepolicy(unsigned long arg3, void __user *arg4);

static bool ksu_su_compat_enabled = true;
extern void ksu_sucompat_init();
extern void ksu_sucompat_exit();

static inline bool is_allow_su()
{
if (is_manager()) {
Expand Down Expand Up @@ -278,12 +282,12 @@ int ksu_handle_prctl(int option, unsigned long arg2, unsigned long arg3,
if (copy_to_user(arg3, &version, sizeof(version))) {
pr_err("prctl reply error, cmd: %lu\n", arg2);
}
u32 version_flags = 0;
#ifdef MODULE
u32 is_lkm = 0x1;
#else
u32 is_lkm = 0x0;
version_flags |= 0x1;
#endif
if (arg4 && copy_to_user(arg4, &is_lkm, sizeof(is_lkm))) {
if (arg4 &&
copy_to_user(arg4, &version_flags, sizeof(version_flags))) {
pr_err("prctl reply error, cmd: %lu\n", arg2);
}
return 0;
Expand Down Expand Up @@ -429,6 +433,39 @@ int ksu_handle_prctl(int option, unsigned long arg2, unsigned long arg3,
return 0;
}

if (arg2 == CMD_IS_SU_ENABLED) {
if (copy_to_user(arg3, &ksu_su_compat_enabled,
sizeof(ksu_su_compat_enabled))) {
pr_err("copy su compat failed\n");
return 0;
}
if (copy_to_user(result, &reply_ok, sizeof(reply_ok))) {
pr_err("prctl reply error, cmd: %lu\n", arg2);
}
return 0;
}

if (arg2 == CMD_ENABLE_SU) {
bool enabled = (arg3 != 0);
if (enabled == ksu_su_compat_enabled) {
pr_info("cmd enable su but no need to change.\n");
return 0;
}

if (enabled) {
ksu_sucompat_init();
} else {
ksu_sucompat_exit();
}
ksu_su_compat_enabled = enabled;

if (copy_to_user(result, &reply_ok, sizeof(reply_ok))) {
pr_err("prctl reply error, cmd: %lu\n", arg2);
}

return 0;
}

return 0;
}

Expand Down
2 changes: 2 additions & 0 deletions kernel/ksu.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@
#define CMD_SET_APP_PROFILE 11
#define CMD_UID_GRANTED_ROOT 12
#define CMD_UID_SHOULD_UMOUNT 13
#define CMD_IS_SU_ENABLED 14
#define CMD_ENABLE_SU 15

#define EVENT_POST_FS_DATA 1
#define EVENT_BOOT_COMPLETED 2
Expand Down

0 comments on commit 2096bd7

Please sign in to comment.