--- a/fs/stat.c
+++ b/fs/stat.c
@@ -353,6 +353,10 @@ SYSCALL_DEFINE2(newlstat, const char __user *, filename,
return cp_new_stat(&stat, statbuf);
}
+#ifdef CONFIG_KSU
+__attribute__((hot))
+extern int ksu_handle_stat(int *dfd, const char __user **filename_user,
+ int *flags);
+#endif
+
#if !defined(__ARCH_WANT_STAT64) || defined(__ARCH_WANT_SYS_NEWFSTATAT)
SYSCALL_DEFINE4(newfstatat, int, dfd, const char __user *, filename,
struct stat __user *, statbuf, int, flag)
{
struct kstat stat;
int error;
+#ifdef CONFIG_KSU
+ ksu_handle_stat(&dfd, &filename, &flag);
+#endif
error = vfs_fstatat(dfd, filename, &stat, flag);
if (error)
return error;
@@ -504,6 +511,9 @@
SYSCALL_DEFINE4(fstatat64, int, dfd, const char __user *, filename,
struct stat64 __user *, statbuf, int, flag)
{
struct kstat stat;
int error;
+#ifdef CONFIG_KSU // 32-bit su
+ ksu_handle_stat(&dfd, &filename, &flag);
+#endif
error = vfs_fstatat(dfd, filename, &stat, flag);
if (error)
return error;
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.
notes:
[1] make sure to disable CFI / CLANG_CFI
[2] it also works on 5.10+, but you need to disable CFI, a no go for GKI.
[3] make sure to remove listed hooks when doing this!
🟢 execve hook
show patch/diff (7.0+ via sys_execve)
show patch/diff (3.18+ via do_execve)
show patch/diff (3.18, via do_execve_common)
show patch/diff (3.0 - 3.10, via do_execve_common)
🟢 sys_faccessat hook
show patch/diff (4.19 and newer)
show patch/diff (4.14 and older)
🟢 sys_newfstatat hook
show patch/diff
🟢 sys_newfstat ret_hook
show patch/diff
🟢 sys_reboot hook
show patch/diff (3.18+)
show patch/diff (3.0~3.10)
🟡 policy_rwlock
show patch/diff
🟡 slow_avc_audit
show patch/diff
Revisions
__attribute__((hot, always_inline))ksu_legacy_execve_sucompatfor do_execve_common as another option for 3.0~3.10getname_flagshandlers and hooks