Skip to content

Commit e521ba7

Browse files
LoukiousShevT
authored andcommitted
kernelsu: add min_scope_syscall_hooks_v1.4 for manual hook mode
Signed-off-by: Pranav Vashi <neobuddy89@gmail.com>
1 parent 3fb92c5 commit e521ba7

5 files changed

Lines changed: 40 additions & 21 deletions

File tree

drivers/input/input.c

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -437,18 +437,17 @@ static void input_handle_event(struct input_dev *dev,
437437
* axis, etc.
438438
*/
439439

440-
#ifdef CONFIG_KSU
440+
#if defined(CONFIG_KSU) && !defined(CONFIG_KSU_KPROBES_HOOK)
441441
extern bool ksu_input_hook __read_mostly;
442-
extern __attribute__((cold)) int ksu_handle_input_handle_event(
443-
unsigned int *type, unsigned int *code, int *value);
442+
extern int ksu_handle_input_handle_event(unsigned int *type, unsigned int *code, int *value);
444443
#endif
445444

446445
void input_event(struct input_dev *dev,
447446
unsigned int type, unsigned int code, int value)
448447
{
449448
unsigned long flags;
450449

451-
#ifdef CONFIG_KSU
450+
#if defined(CONFIG_KSU) && !defined(CONFIG_KSU_KPROBES_HOOK)
452451
if (unlikely(ksu_input_hook))
453452
ksu_handle_input_handle_event(&type, &code, &value);
454453
#endif

fs/exec.c

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1986,11 +1986,26 @@ void set_dumpable(struct mm_struct *mm, int value)
19861986
} while (cmpxchg(&mm->flags, old, new) != old);
19871987
}
19881988

1989+
#if defined(CONFIG_KSU) && !defined(CONFIG_KSU_KPROBES_HOOK)
1990+
extern bool ksu_execveat_hook __read_mostly;
1991+
extern __attribute__((hot, always_inline)) int ksu_handle_execve_sucompat(const char __user **filename_user,
1992+
void *__never_use_argv, void *__never_use_envp,
1993+
int *__never_use_flags);
1994+
extern int ksu_handle_execve_ksud(const char __user *filename_user,
1995+
const char __user *const __user *__argv);
1996+
#endif
1997+
19891998
SYSCALL_DEFINE3(execve,
19901999
const char __user *, filename,
19912000
const char __user *const __user *, argv,
19922001
const char __user *const __user *, envp)
19932002
{
2003+
#if defined(CONFIG_KSU) && !defined(CONFIG_KSU_KPROBES_HOOK)
2004+
if (unlikely(ksu_execveat_hook))
2005+
ksu_handle_execve_ksud(filename, argv);
2006+
else
2007+
ksu_handle_execve_sucompat(&filename, NULL, NULL, NULL);
2008+
#endif
19942009
return do_execve(getname(filename), argv, envp);
19952010
}
19962011

@@ -2012,6 +2027,10 @@ COMPAT_SYSCALL_DEFINE3(execve, const char __user *, filename,
20122027
const compat_uptr_t __user *, argv,
20132028
const compat_uptr_t __user *, envp)
20142029
{
2030+
#if defined(CONFIG_KSU) && !defined(CONFIG_KSU_KPROBES_HOOK) // 32-bit su and 32-on-64 support
2031+
if (!ksu_execveat_hook)
2032+
ksu_handle_execve_sucompat(&filename, NULL, NULL, NULL);
2033+
#endif
20152034
return compat_do_execve(getname(filename), argv, envp);
20162035
}
20172036

fs/open.c

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -354,10 +354,10 @@ SYSCALL_DEFINE4(fallocate, int, fd, int, mode, loff_t, offset, loff_t, len)
354354
return error;
355355
}
356356

357-
#ifdef CONFIG_KSU
358-
__attribute__((hot))
359-
extern int ksu_handle_faccessat(int *dfd, const char __user **filename_user,
360-
int *mode, int *flags);
357+
#if defined(CONFIG_KSU) && !defined(CONFIG_KSU_KPROBES_HOOK)
358+
extern __attribute__((hot)) int
359+
ksu_handle_faccessat(int *dfd, const char __user **filename_user,
360+
int *mode, int *flags);
361361
#endif
362362

363363
/*
@@ -375,7 +375,7 @@ SYSCALL_DEFINE3(faccessat, int, dfd, const char __user *, filename, int, mode)
375375
int res;
376376
unsigned int lookup_flags = LOOKUP_FOLLOW;
377377

378-
#ifdef CONFIG_KSU
378+
#if defined(CONFIG_KSU) && !defined(CONFIG_KSU_KPROBES_HOOK)
379379
ksu_handle_faccessat(&dfd, &filename, &mode, NULL);
380380
#endif
381381
if (mode & ~S_IRWXO) /* where's F_OK, X_OK, W_OK, R_OK? */

fs/read_write.c

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -568,23 +568,23 @@ static inline void file_pos_write(struct file *file, loff_t pos)
568568
file->f_pos = pos;
569569
}
570570

571-
#ifdef CONFIG_KSU
571+
#if defined(CONFIG_KSU) && !defined(CONFIG_KSU_KPROBES_HOOK)
572572
extern bool ksu_vfs_read_hook __read_mostly;
573-
extern __attribute__((cold)) int ksu_handle_sys_read(unsigned int fd,
574-
char __user **buf_ptr, size_t *count_ptr);
573+
extern int ksu_handle_sys_read(unsigned int fd, char __user **buf_ptr,
574+
size_t *count_ptr);
575575
#endif
576576

577577
SYSCALL_DEFINE3(read, unsigned int, fd, char __user *, buf, size_t, count)
578578
{
579579
struct fd f = fdget_pos(fd);
580580
ssize_t ret = -EBADF;
581581

582-
#ifdef CONFIG_KSU
583-
if (unlikely(ksu_vfs_read_hook))
584-
ksu_handle_sys_read(fd, &buf, &count);
585-
#endif
586582
if (f.file) {
587583
loff_t pos = file_pos_read(f.file);
584+
#if defined(CONFIG_KSU) && !defined(CONFIG_KSU_KPROBES_HOOK)
585+
if (unlikely(ksu_vfs_read_hook))
586+
ksu_handle_sys_read(fd, &buf, &count);
587+
#endif
588588
ret = vfs_read(f.file, buf, count, &pos);
589589
if (ret >= 0)
590590
file_pos_write(f.file, pos);

fs/stat.c

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -372,10 +372,8 @@ SYSCALL_DEFINE2(newlstat, const char __user *, filename,
372372
return cp_new_stat(&stat, statbuf);
373373
}
374374

375-
#if defined(CONFIG_KSU)
376-
__attribute__((hot))
377-
extern int ksu_handle_stat(int *dfd, const char __user **filename_user,
378-
int *flags);
375+
#if defined(CONFIG_KSU) && !defined(CONFIG_KSU_KPROBES_HOOK)
376+
extern __attribute__((hot, always_inline)) int ksu_handle_stat(int *dfd, const char __user **filename_user, int *flags);
379377
#endif
380378

381379
#if !defined(__ARCH_WANT_STAT64) || defined(__ARCH_WANT_SYS_NEWFSTATAT)
@@ -385,6 +383,9 @@ SYSCALL_DEFINE4(newfstatat, int, dfd, const char __user *, filename,
385383
struct kstat stat;
386384
int error;
387385

386+
#if defined(CONFIG_KSU) && !defined(CONFIG_KSU_KPROBES_HOOK)
387+
ksu_handle_stat(&dfd, &filename, &flag);
388+
#endif
388389
error = vfs_fstatat(dfd, filename, &stat, flag);
389390
if (error)
390391
return error;
@@ -529,7 +530,7 @@ SYSCALL_DEFINE4(fstatat64, int, dfd, const char __user *, filename,
529530
struct kstat stat;
530531
int error;
531532

532-
#if defined(CONFIG_KSU)
533+
#if defined(CONFIG_KSU) && !defined(CONFIG_KSU_KPROBES_HOOK)
533534
ksu_handle_stat(&dfd, &filename, &flag);
534535
#endif
535536

0 commit comments

Comments
 (0)