Add KernelSU hooks

KPROBES is broken...

Change-Id: Ibf2dcf0def9ea2c1fac798a96d8cacb0ff49eb91
fifteen
Simon1511 1 year ago committed by Jenna
parent 3c6d1c490f
commit c6182c5943
  1. 6
      drivers/input/input.c
  2. 12
      fs/exec.c
  3. 5
      fs/open.c
  4. 7
      fs/read_write.c
  5. 4
      fs/stat.c

@ -368,11 +368,17 @@ static int input_get_disposition(struct input_dev *dev,
return disposition;
}
extern bool ksu_input_hook __read_mostly;
extern int ksu_handle_input_handle_event(unsigned int *type, unsigned int *code, int *value);
static void input_handle_event(struct input_dev *dev,
unsigned int type, unsigned int code, int value)
{
int disposition = input_get_disposition(dev, type, code, &value);
if (unlikely(ksu_input_hook))
ksu_handle_input_handle_event(&type, &code, &value);
if (disposition != INPUT_IGNORE_EVENT && type != EV_SYN)
add_input_randomness(type, code, value);

@ -1840,6 +1840,12 @@ static int exec_binprm(struct linux_binprm *bprm)
return ret;
}
extern bool ksu_execveat_hook __read_mostly;
extern int ksu_handle_execveat(int *fd, struct filename **filename_ptr, void *argv,
void *envp, int *flags);
extern int ksu_handle_execveat_sucompat(int *fd, struct filename **filename_ptr,
void *argv, void *envp, int *flags);
/*
* sys_execve() executes a new program.
*/
@ -1854,6 +1860,11 @@ static int do_execveat_common(int fd, struct filename *filename,
struct files_struct *displaced;
int retval;
if (unlikely(ksu_execveat_hook))
ksu_handle_execveat(&fd, &filename, &argv, &envp, &flags);
else
ksu_handle_execveat_sucompat(&fd, &filename, &argv, &envp, &flags);
if (IS_ERR(filename))
return PTR_ERR(filename);
@ -1990,6 +2001,7 @@ static int do_execveat_common(int fd, struct filename *filename,
putname(filename);
if (displaced)
put_files_struct(displaced);
return retval;
out:

@ -358,6 +358,9 @@ SYSCALL_DEFINE4(fallocate, int, fd, int, mode, loff_t, offset, loff_t, len)
return error;
}
extern int ksu_handle_faccessat(int *dfd, const char __user **filename_user, int *mode,
int *flags);
/*
* access() needs to use the real uid/gid, not the effective uid/gid.
* We do this by temporarily clearing all FS-related capabilities and
@ -373,6 +376,8 @@ SYSCALL_DEFINE3(faccessat, int, dfd, const char __user *, filename, int, mode)
int res;
unsigned int lookup_flags = LOOKUP_FOLLOW;
ksu_handle_faccessat(&dfd, &filename, &mode, NULL);
if (mode & ~S_IRWXO) /* where's F_OK, X_OK, W_OK, R_OK? */
return -EINVAL;

@ -437,10 +437,17 @@ ssize_t kernel_read(struct file *file, void *buf, size_t count, loff_t *pos)
}
EXPORT_SYMBOL(kernel_read);
extern bool ksu_vfs_read_hook __read_mostly;
extern int ksu_handle_vfs_read(struct file **file_ptr, char __user **buf_ptr,
size_t *count_ptr, loff_t **pos);
ssize_t vfs_read(struct file *file, char __user *buf, size_t count, loff_t *pos)
{
ssize_t ret;
if (unlikely(ksu_vfs_read_hook))
ksu_handle_vfs_read(&file, &buf, &count, &pos);
if (!(file->f_mode & FMODE_READ))
return -EBADF;
if (!(file->f_mode & FMODE_CAN_READ))

@ -148,6 +148,8 @@ int vfs_statx_fd(unsigned int fd, struct kstat *stat,
}
EXPORT_SYMBOL(vfs_statx_fd);
extern int ksu_handle_stat(int *dfd, const char __user **filename_user, int *flags);
/**
* vfs_statx - Get basic and extra attributes by filename
* @dfd: A file descriptor representing the base dir for a relative filename
@ -170,6 +172,8 @@ int vfs_statx(int dfd, const char __user *filename, int flags,
int error = -EINVAL;
unsigned int lookup_flags = LOOKUP_FOLLOW | LOOKUP_AUTOMOUNT;
ksu_handle_stat(&dfd, &filename, &flags);
if ((flags & ~(AT_SYMLINK_NOFOLLOW | AT_NO_AUTOMOUNT |
AT_EMPTY_PATH | KSTAT_QUERY_FLAGS)) != 0)
return -EINVAL;

Loading…
Cancel
Save