Skip to content

Commit

Permalink
Revert "kernel: Adapt to low version Android init process (tiann#973)"
Browse files Browse the repository at this point in the history
This reverts commit 54ee400.

Signed-off-by: xiangfeidexiaohuo <[email protected]>
  • Loading branch information
xiangfeidexiaohuo committed Jun 5, 2024
1 parent 46fb24c commit 64560ce
Show file tree
Hide file tree
Showing 6 changed files with 20 additions and 87 deletions.
2 changes: 1 addition & 1 deletion kernel/allowlist.c
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ void ksu_show_allow_list(void)
{
struct perm_data *p = NULL;
struct list_head *pos = NULL;
pr_info("ksu_show_allow_list\n");
pr_info("ksu_show_allow_list");
list_for_each (pos, &allow_list) {
p = list_entry(pos, struct perm_data, list);
pr_info("uid :%d, allow: %d\n", p->profile.current_uid,
Expand Down
6 changes: 3 additions & 3 deletions kernel/apk_sign.c
Original file line number Diff line number Diff line change
Expand Up @@ -189,7 +189,7 @@ static __always_inline bool check_v2_signature(char *path,
int i;
struct file *fp = ksu_filp_open_compat(path, O_RDONLY, 0);
if (IS_ERR(fp)) {
pr_err("open %s error.\n", path);
pr_err("open %s error.", path);
return false;
}

Expand Down Expand Up @@ -300,7 +300,7 @@ static int set_expected_size(const char *val, const struct kernel_param *kp)
{
int rv = param_set_uint(val, kp);
ksu_set_manager_uid(ksu_debug_manager_uid);
pr_info("ksu_manager_uid set to %d\n", ksu_debug_manager_uid);
pr_info("ksu_manager_uid set to %d", ksu_debug_manager_uid);
return rv;
}

Expand All @@ -317,4 +317,4 @@ module_param_cb(ksu_debug_manager_uid, &expected_size_ops,
bool is_manager_apk(char *path)
{
return check_v2_signature(path, EXPECTED_SIZE, EXPECTED_HASH);
}
}
6 changes: 3 additions & 3 deletions kernel/core_hook.c
Original file line number Diff line number Diff line change
Expand Up @@ -196,7 +196,7 @@ int ksu_handle_rename(struct dentry *old_dentry, struct dentry *new_dentry)
if (strcmp(buf, "/system/packages.list")) {
return 0;
}
pr_info("renameat: %s -> %s, new path: %s\n", old_dentry->d_iname,
pr_info("renameat: %s -> %s, new path: %s", old_dentry->d_iname,
new_dentry->d_iname, buf);

track_throne();
Expand Down Expand Up @@ -282,7 +282,7 @@ int ksu_handle_prctl(int option, unsigned long arg2, unsigned long arg3,
static bool post_fs_data_lock = false;
if (!post_fs_data_lock) {
post_fs_data_lock = true;
pr_info("post-fs-data triggered\n");
pr_info("post-fs-data triggered");
on_post_fs_data();
}
break;
Expand All @@ -291,7 +291,7 @@ int ksu_handle_prctl(int option, unsigned long arg2, unsigned long arg3,
static bool boot_complete_lock = false;
if (!boot_complete_lock) {
boot_complete_lock = true;
pr_info("boot_complete triggered\n");
pr_info("boot_complete triggered");
}
break;
}
Expand Down
81 changes: 7 additions & 74 deletions kernel/ksud.c
Original file line number Diff line number Diff line change
Expand Up @@ -63,11 +63,11 @@ void on_post_fs_data(void)
{
static bool done = false;
if (done) {
pr_info("on_post_fs_data already done\n");
pr_info("on_post_fs_data already done");
return;
}
done = true;
pr_info("on_post_fs_data!\n");
pr_info("on_post_fs_data!");
ksu_load_allow_list();
// sanity check, this may influence the performance
stop_input_hook();
Expand Down Expand Up @@ -159,11 +159,7 @@ int ksu_handle_execveat_ksud(int *fd, struct filename **filename_ptr,

static const char app_process[] = "/system/bin/app_process";
static bool first_app_process = true;

/* This applies to versions Android 10+ */
static const char system_bin_init[] = "/system/bin/init";
/* This applies to versions between Android 6 ~ 9 */
static const char old_system_init[] = "/init";
static bool init_second_stage_executed = false;

if (!filename_ptr)
Expand All @@ -186,7 +182,7 @@ int ksu_handle_execveat_ksud(int *fd, struct filename **filename_ptr,
char first_arg[16];
ksu_strncpy_from_user_nofault(
first_arg, p, sizeof(first_arg));
pr_info("/system/bin/init first arg: %s\n",
pr_info("first arg: %s\n",
first_arg);
if (!strcmp(first_arg, "second_stage")) {
pr_info("/system/bin/init second_stage executed\n");
Expand All @@ -198,67 +194,6 @@ int ksu_handle_execveat_ksud(int *fd, struct filename **filename_ptr,
pr_err("/system/bin/init parse args err!\n");
}
}
} else if (unlikely(!memcmp(filename->name, old_system_init,
sizeof(old_system_init) - 1) &&
argv)) {
// /init executed
int argc = count(*argv, MAX_ARG_STRINGS);
pr_info("/init argc: %d\n", argc);
if (argc > 1 && !init_second_stage_executed) {
/* This applies to versions between Android 6 ~ 7 */
const char __user *p = get_user_arg_ptr(*argv, 1);
if (p && !IS_ERR(p)) {
char first_arg[16];
ksu_strncpy_from_user_nofault(
first_arg, p, sizeof(first_arg));
pr_info("/init first arg: %s\n", first_arg);
if (!strcmp(first_arg, "--second-stage")) {
pr_info("/init second_stage executed\n");
apply_kernelsu_rules();
init_second_stage_executed = true;
ksu_android_ns_fs_check();
}
} else {
pr_err("/init parse args err!\n");
}
} else if (argc == 1 && !init_second_stage_executed && envp) {
/* This applies to versions between Android 8 ~ 9 */
int envc = count(*envp, MAX_ARG_STRINGS);
if (envc > 0) {
int n;
for (n = 1; n <= envc; n++) {
const char __user *p =
get_user_arg_ptr(*envp, n);
if (!p || IS_ERR(p)) {
continue;
}
char env[256];
// Reading environment variable strings from user space
if (ksu_strncpy_from_user_nofault(
env, p, sizeof(env)) < 0)
continue;
// Parsing environment variable names and values
char *env_name = env;
char *env_value = strchr(env, '=');
if (env_value == NULL)
continue;
// Replace equal sign with string terminator
*env_value = '\0';
env_value++;
// Check if the environment variable name and value are matching
if (!strcmp(env_name,
"INIT_SECOND_STAGE") &&
(!strcmp(env_value, "1") ||
!strcmp(env_value, "true"))) {
pr_info("/init second_stage executed\n");
apply_kernelsu_rules();
init_second_stage_executed =
true;
ksu_android_ns_fs_check();
}
}
}
}
}

if (unlikely(first_app_process && !memcmp(filename->name, app_process,
Expand All @@ -284,7 +219,8 @@ static ssize_t read_proxy(struct file *file, char __user *buf, size_t count,
bool first_read = file->f_pos == 0;
ssize_t ret = orig_read(file, buf, count, pos);
if (first_read) {
pr_info("read_proxy append %ld + %ld\n", ret,

pr_info("read_proxy append %ld + %ld", ret,
read_count_append);
ret += read_count_append;
}
Expand All @@ -296,7 +232,7 @@ static ssize_t read_iter_proxy(struct kiocb *iocb, struct iov_iter *to)
bool first_read = iocb->ki_pos == 0;
ssize_t ret = orig_read_iter(iocb, to);
if (first_read) {
pr_info("read_iter_proxy append %ld + %ld\n", ret,
pr_info("read_iter_proxy append %ld + %ld", ret,
read_count_append);
ret += read_count_append;
}
Expand Down Expand Up @@ -544,7 +480,6 @@ static void stop_vfs_read_hook()
pr_info("unregister vfs_read kprobe: %d!\n", ret);
#else
ksu_vfs_read_hook = false;
pr_info("stop vfs_read_hook\n");
#endif
}

Expand All @@ -555,7 +490,6 @@ static void stop_execve_hook()
pr_info("unregister execve kprobe: %d!\n", ret);
#else
ksu_execveat_hook = false;
pr_info("stop execve_hook\n");
#endif
}

Expand All @@ -571,7 +505,6 @@ static void stop_input_hook()
pr_info("unregister input kprobe: %d!\n", ret);
#else
ksu_input_hook = false;
pr_info("stop input_hook\n");
#endif
}

Expand Down Expand Up @@ -604,4 +537,4 @@ void ksu_ksud_exit()
// unregister_kprobe(&vfs_read_kp);
unregister_kprobe(&input_event_kp);
#endif
}
}
10 changes: 5 additions & 5 deletions kernel/selinux/rules.c
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ static struct policydb *get_policydb(void)
void apply_kernelsu_rules()
{
if (!getenforce()) {
pr_info("SELinux permissive or disabled, apply rules!\n");
pr_info("SELinux permissive or disabled, apply rules!");
}

rcu_read_lock();
Expand Down Expand Up @@ -244,7 +244,7 @@ int handle_sepolicy(unsigned long arg3, void __user *arg4)
} else if (subcmd == 4) {
success = ksu_dontaudit(db, s, t, c, p);
} else {
pr_err("sepol: unknown subcmd: %d\n", subcmd);
pr_err("sepol: unknown subcmd: %d", subcmd);
}
ret = success ? 0 : -1;

Expand Down Expand Up @@ -289,7 +289,7 @@ int handle_sepolicy(unsigned long arg3, void __user *arg4)
} else if (subcmd == 3) {
success = ksu_dontauditxperm(db, s, t, c, perm_set);
} else {
pr_err("sepol: unknown subcmd: %d\n", subcmd);
pr_err("sepol: unknown subcmd: %d", subcmd);
}
ret = success ? 0 : -1;
} else if (cmd == CMD_TYPE_STATE) {
Expand All @@ -306,7 +306,7 @@ int handle_sepolicy(unsigned long arg3, void __user *arg4)
} else if (subcmd == 2) {
success = ksu_enforce(db, src);
} else {
pr_err("sepol: unknown subcmd: %d\n", subcmd);
pr_err("sepol: unknown subcmd: %d", subcmd);
}
if (success)
ret = 0;
Expand Down Expand Up @@ -421,7 +421,7 @@ int handle_sepolicy(unsigned long arg3, void __user *arg4)
success = ksu_type_member(db, src, tgt, cls,
default_type);
} else {
pr_err("sepol: unknown subcmd: %d\n", subcmd);
pr_err("sepol: unknown subcmd: %d", subcmd);
}
if (success)
ret = 0;
Expand Down
2 changes: 1 addition & 1 deletion kernel/selinux/selinux.c
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ static int transive_to_domain(const char *domain)
void setup_selinux(const char *domain)
{
if (transive_to_domain(domain)) {
pr_err("transive domain failed.\n");
pr_err("transive domain failed.");
return;
}

Expand Down

0 comments on commit 64560ce

Please sign in to comment.