Skip to content

Commit 2096bd7

Browse files
committed
kernel: add support for disable sucompat
1 parent 101d3ae commit 2096bd7

File tree

2 files changed

+43
-4
lines changed

2 files changed

+43
-4
lines changed

kernel/core_hook.c

Lines changed: 41 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,10 @@ static bool ksu_module_mounted = false;
4949

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

52+
static bool ksu_su_compat_enabled = true;
53+
extern void ksu_sucompat_init();
54+
extern void ksu_sucompat_exit();
55+
5256
static inline bool is_allow_su()
5357
{
5458
if (is_manager()) {
@@ -278,12 +282,12 @@ int ksu_handle_prctl(int option, unsigned long arg2, unsigned long arg3,
278282
if (copy_to_user(arg3, &version, sizeof(version))) {
279283
pr_err("prctl reply error, cmd: %lu\n", arg2);
280284
}
285+
u32 version_flags = 0;
281286
#ifdef MODULE
282-
u32 is_lkm = 0x1;
283-
#else
284-
u32 is_lkm = 0x0;
287+
version_flags |= 0x1;
285288
#endif
286-
if (arg4 && copy_to_user(arg4, &is_lkm, sizeof(is_lkm))) {
289+
if (arg4 &&
290+
copy_to_user(arg4, &version_flags, sizeof(version_flags))) {
287291
pr_err("prctl reply error, cmd: %lu\n", arg2);
288292
}
289293
return 0;
@@ -429,6 +433,39 @@ int ksu_handle_prctl(int option, unsigned long arg2, unsigned long arg3,
429433
return 0;
430434
}
431435

436+
if (arg2 == CMD_IS_SU_ENABLED) {
437+
if (copy_to_user(arg3, &ksu_su_compat_enabled,
438+
sizeof(ksu_su_compat_enabled))) {
439+
pr_err("copy su compat failed\n");
440+
return 0;
441+
}
442+
if (copy_to_user(result, &reply_ok, sizeof(reply_ok))) {
443+
pr_err("prctl reply error, cmd: %lu\n", arg2);
444+
}
445+
return 0;
446+
}
447+
448+
if (arg2 == CMD_ENABLE_SU) {
449+
bool enabled = (arg3 != 0);
450+
if (enabled == ksu_su_compat_enabled) {
451+
pr_info("cmd enable su but no need to change.\n");
452+
return 0;
453+
}
454+
455+
if (enabled) {
456+
ksu_sucompat_init();
457+
} else {
458+
ksu_sucompat_exit();
459+
}
460+
ksu_su_compat_enabled = enabled;
461+
462+
if (copy_to_user(result, &reply_ok, sizeof(reply_ok))) {
463+
pr_err("prctl reply error, cmd: %lu\n", arg2);
464+
}
465+
466+
return 0;
467+
}
468+
432469
return 0;
433470
}
434471

kernel/ksu.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,8 @@
2121
#define CMD_SET_APP_PROFILE 11
2222
#define CMD_UID_GRANTED_ROOT 12
2323
#define CMD_UID_SHOULD_UMOUNT 13
24+
#define CMD_IS_SU_ENABLED 14
25+
#define CMD_ENABLE_SU 15
2426

2527
#define EVENT_POST_FS_DATA 1
2628
#define EVENT_BOOT_COMPLETED 2

0 commit comments

Comments
 (0)