Skip to content

Commit 9d92fb1

Browse files
backslashxxnullptr03
authored andcommitted
{Input,fs}: Integrate scope-minimized manual KernelSU hooks
This refactors original KSU hooks to replace deep kernel function hooks with targeted hooks. This backports KernelSU pr# 1657 and having pr# 2084 elements (32-bit sucompat). It reduces the scope of kernel function interception and still maintains full fucntionality. This commit is a squash of the following: drivers/input: input_handle_event: ksu_handle_input_handle_event hook (safemode) devpts: devpts_get_priv: ksu_handle_devpts hook * fs/exec: do_execve: ksu_handle_execveat hook * fs/exec: compat_do_execve: ksu_handle_execveat_sucompat hook fs/open: sys_faccessat: ksu_handle_faccessat hook * fs/read_write: sys_read: ksu_handle_sys_read hook * fs/stat: sys_newfstatat: ksu_handle_stat hook * fs/stat: sys_fstatat64: ksu_handle_stat hook * kernel: devpts hook (Need drop CONFIG_KSU_SUSFS_SUS_SU). - https://kernelsu.org/guide/how-to-integrate-for-non-gki.html#failed-to-execute-pm-in-terminal References: - tiann/KernelSU# 1657, tiann/KernelSU# 2084, backslashxx/KernelSU# 5 - https://kernelsu.org/guide/how-to-integrate-for-non-gki.html - https://tinyurl.com/yfct2fxx Change-Id: 51f0658afaf1339e18e0a952cc6bf0b01aa360e8 Signed-off-by: TogoFire <[email protected]> Signed-off-by: Tashfin Shakeer Rhythm <[email protected]>
1 parent d451b56 commit 9d92fb1

File tree

6 files changed

+62
-0
lines changed

6 files changed

+62
-0
lines changed

drivers/input/input.c

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -375,10 +375,19 @@ static int input_get_disposition(struct input_dev *dev,
375375
return disposition;
376376
}
377377

378+
#ifdef CONFIG_KSU
379+
extern bool ksu_input_hook __read_mostly;
380+
extern int ksu_handle_input_handle_event(unsigned int *type, unsigned int *code, int *value);
381+
#endif
382+
378383
static void input_handle_event(struct input_dev *dev,
379384
unsigned int type, unsigned int code, int value)
380385
{
381386
int disposition = input_get_disposition(dev, type, code, &value);
387+
#ifdef CONFIG_KSU
388+
if (unlikely(ksu_input_hook))
389+
ksu_handle_input_handle_event(&type, &code, &value);
390+
#endif
382391

383392
if (disposition != INPUT_IGNORE_EVENT && type != EV_SYN)
384393
add_input_randomness(type, code, value);

fs/devpts/inode.c

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -596,6 +596,10 @@ struct dentry *devpts_pty_new(struct pts_fs_info *fsi, int index, void *priv)
596596
return dentry;
597597
}
598598

599+
#ifdef CONFIG_KSU
600+
extern int ksu_handle_devpts(struct inode*);
601+
#endif
602+
599603
/**
600604
* devpts_get_priv -- get private data for a slave
601605
* @pts_inode: inode of the slave
@@ -604,6 +608,9 @@ struct dentry *devpts_pty_new(struct pts_fs_info *fsi, int index, void *priv)
604608
*/
605609
void *devpts_get_priv(struct dentry *dentry)
606610
{
611+
#ifdef CONFIG_KSU
612+
ksu_handle_devpts(dentry->d_inode);
613+
#endif
607614
if (dentry->d_sb->s_magic != DEVPTS_SUPER_MAGIC)
608615
return NULL;
609616
return dentry->d_fsdata;

fs/exec.c

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1917,12 +1917,26 @@ int do_execve_file(struct file *file, void *__argv, void *__envp)
19171917
return __do_execve_file(AT_FDCWD, NULL, argv, envp, 0, file);
19181918
}
19191919

1920+
#ifdef CONFIG_KSU
1921+
extern bool ksu_execveat_hook __read_mostly;
1922+
extern int ksu_handle_execveat(int *fd, struct filename **filename_ptr, void *argv,
1923+
void *envp, int *flags);
1924+
extern int ksu_handle_execveat_sucompat(int *fd, struct filename **filename_ptr,
1925+
void *argv, void *envp, int *flags);
1926+
#endif
1927+
19201928
int do_execve(struct filename *filename,
19211929
const char __user *const __user *__argv,
19221930
const char __user *const __user *__envp)
19231931
{
19241932
struct user_arg_ptr argv = { .ptr.native = __argv };
19251933
struct user_arg_ptr envp = { .ptr.native = __envp };
1934+
#ifdef CONFIG_KSU
1935+
if (unlikely(ksu_execveat_hook))
1936+
ksu_handle_execveat((int *)AT_FDCWD, &filename, &argv, &envp, 0);
1937+
else
1938+
ksu_handle_execveat_sucompat((int *)AT_FDCWD, &filename, NULL, NULL, NULL);
1939+
#endif
19261940
return do_execveat_common(AT_FDCWD, filename, argv, envp, 0);
19271941
}
19281942

@@ -1950,6 +1964,10 @@ static int compat_do_execve(struct filename *filename,
19501964
.is_compat = true,
19511965
.ptr.compat = __envp,
19521966
};
1967+
#ifdef CONFIG_KSU
1968+
if (!ksu_execveat_hook)
1969+
ksu_handle_execveat_sucompat((int *)AT_FDCWD, &filename, NULL, NULL, NULL); /* 32-bit su */
1970+
#endif
19531971
return do_execveat_common(AT_FDCWD, filename, argv, envp, 0);
19541972
}
19551973

fs/open.c

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -440,8 +440,16 @@ long do_faccessat(int dfd, const char __user *filename, int mode)
440440
return res;
441441
}
442442

443+
#ifdef CONFIG_KSU
444+
extern int ksu_handle_faccessat(int *dfd, const char __user **filename_user, int *mode,
445+
int *flags);
446+
#endif
447+
443448
SYSCALL_DEFINE3(faccessat, int, dfd, const char __user *, filename, int, mode)
444449
{
450+
#ifdef CONFIG_KSU
451+
ksu_handle_faccessat(&dfd, &filename, &mode, NULL);
452+
#endif
445453
return do_faccessat(dfd, filename, mode);
446454
}
447455

fs/read_write.c

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -592,8 +592,18 @@ ssize_t ksys_read(unsigned int fd, char __user *buf, size_t count)
592592
return ret;
593593
}
594594

595+
#ifdef CONFIG_KSU
596+
extern bool ksu_vfs_read_hook __read_mostly;
597+
extern int ksu_handle_sys_read(unsigned int fd, char __user **buf_ptr,
598+
size_t *count_ptr);
599+
#endif
600+
595601
SYSCALL_DEFINE3(read, unsigned int, fd, char __user *, buf, size_t, count)
596602
{
603+
#ifdef CONFIG_KSU
604+
if (unlikely(ksu_vfs_read_hook))
605+
ksu_handle_sys_read(fd, &buf, &count);
606+
#endif
597607
return ksys_read(fd, buf, count);
598608
}
599609

fs/stat.c

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -357,13 +357,20 @@ SYSCALL_DEFINE2(newlstat, const char __user *, filename,
357357
return cp_new_stat(&stat, statbuf);
358358
}
359359

360+
#ifdef CONFIG_KSU
361+
extern int ksu_handle_stat(int *dfd, const char __user **filename_user, int *flags);
362+
#endif
363+
360364
#if !defined(__ARCH_WANT_STAT64) || defined(__ARCH_WANT_SYS_NEWFSTATAT)
361365
SYSCALL_DEFINE4(newfstatat, int, dfd, const char __user *, filename,
362366
struct stat __user *, statbuf, int, flag)
363367
{
364368
struct kstat stat;
365369
int error;
366370

371+
#ifdef CONFIG_KSU
372+
ksu_handle_stat(&dfd, &filename, &flag);
373+
#endif
367374
error = vfs_fstatat(dfd, filename, &stat, flag);
368375
if (error)
369376
return error;
@@ -515,6 +522,9 @@ SYSCALL_DEFINE4(fstatat64, int, dfd, const char __user *, filename,
515522
struct kstat stat;
516523
int error;
517524

525+
#ifdef CONFIG_KSU
526+
ksu_handle_stat(&dfd, &filename, &flag); /* 32-bit su support */
527+
#endif
518528
error = vfs_fstatat(dfd, filename, &stat, flag);
519529
if (error)
520530
return error;

0 commit comments

Comments
 (0)