kernel: fix compile errors & warnings on android13-5.15 gki

This commit is contained in:
weishu 2022-12-20 10:51:40 +07:00
parent c5da14ae4b
commit 758c8eb845
3 changed files with 36 additions and 21 deletions

View File

@ -87,13 +87,14 @@ exit:
}
bool ksu_is_allow_uid(uid_t uid) {
struct perm_data *p = NULL;
struct list_head *pos = NULL;
if (uid == 0) {
// already root
return true;
}
struct perm_data *p = NULL;
struct list_head *pos = NULL;
list_for_each(pos, &allow_list) {
p = list_entry(pos, struct perm_data, list);
// pr_info("is_allow_uid uid :%d, allow: %d\n", p->uid, p->allow);
@ -162,7 +163,6 @@ void do_load_allow_list(struct work_struct *work) {
loff_t off = 0;
ssize_t ret = 0;
struct file *fp = NULL;
int n = 0;
u32 magic;
u32 version;

View File

@ -83,21 +83,25 @@ static bool is_manager() {
}
static bool become_manager() {
if (__manager_uid != 0) {
pr_info("manager already exist: %d\n", __manager_uid);
return true;
}
// list current process's files
struct files_struct *current_files;
struct fdtable *files_table;
int i = 0;
struct path files_path;
char *cwd;
char *buf = (char *)kmalloc(GFP_KERNEL, PATH_MAX);
char *buf;
bool result = false;
current_files = current->files;
files_table = files_fdtable(current_files);
if (__manager_uid != 0) {
pr_info("manager already exist: %d\n", __manager_uid);
return true;
}
buf = (char *) kmalloc(GFP_KERNEL, PATH_MAX);
if (!buf) {
pr_err("kalloc path failed.\n");
return false;
}
files_table = files_fdtable(current->files);
// todo: use iterate_fd
while(files_table->fd[i] != NULL) {
@ -168,7 +172,9 @@ static int handler_pre(struct kprobe *p, struct pt_regs *regs) {
// someone wants to be root manager, just check it!
bool success = become_manager();
if (success) {
copy_to_user(result, &reply_ok, sizeof(reply_ok));
if (copy_to_user(result, &reply_ok, sizeof(reply_ok))) {
pr_err("prctl reply error\n");
}
}
return 0;
}
@ -198,21 +204,29 @@ static int handler_pre(struct kprobe *p, struct pt_regs *regs) {
uid_t uid = (uid_t) arg3;
success = ksu_allow_uid(uid, allow);
if (success) {
copy_to_user(result, &reply_ok, sizeof(reply_ok));
if (copy_to_user(result, &reply_ok, sizeof(reply_ok))) {
pr_err("prctl reply error, cmd: %d\n", arg2);
}
}
} else if (arg2 == CMD_GET_ALLOW_LIST || arg2 == CMD_GET_DENY_LIST) {
u32 array[128];
u32 array_length;
bool success = ksu_get_allow_list(array, &array_length, arg2 == CMD_GET_ALLOW_LIST);
if (success) {
copy_to_user(arg4, &array_length, sizeof(array_length));
copy_to_user(arg3, array, sizeof(u32) * array_length);
copy_to_user(result, &reply_ok, sizeof(reply_ok));
if (!copy_to_user(arg4, &array_length, sizeof(array_length)) &&
!copy_to_user(arg3, array, sizeof(u32) * array_length)) {
if (!copy_to_user(result, &reply_ok, sizeof(reply_ok))) {
pr_err("prctl reply error, cmd: %d\n", arg2);
}
} else {
pr_err("prctl copy allowlist error\n");
}
}
} else if (arg2 == CMD_GET_VERSION) {
u32 version = KERNEL_SU_VERSION;
copy_to_user(arg3, &version, sizeof(version));
if (copy_to_user(arg3, &version, sizeof(version))) {
pr_err("prctl reply error, cmd: %d\n", arg2);
}
}
return 0;

View File

@ -93,13 +93,14 @@ static int execve_handler_pre(struct kprobe *p, struct pt_regs *regs) {
const char sh[] = SH_PATH;
const char su[] = SU_PATH;
static const char app_process[] = "/system/bin/app_process";
static bool first_app_process = true;
filename = PT_REGS_PARM2(regs);
if (IS_ERR(filename)) {
return 0;
}
static const char app_process[] = "/system/bin/app_process";
static bool first_app_process = true;
if (first_app_process && !memcmp(filename->name, app_process, sizeof(app_process) - 1)) {
first_app_process = false;
pr_info("exec app_process, /data prepared!\n");