Skip to content

Commit 18a4bb3

Browse files
hamjinThereache
authored andcommitted
kernel: Fix compatibility with old and 32bit programs
In v0.9.3 and v0.9.4, we replaced `vfs_statx` and `do_execveat_common` with syscall hooks. But we missed `fstatat64` and `compat_execve` and break compatibility with old and 32bit programs. In NetHunter Terminal compat_execve is directly called, but `fstatat64` is called before it in JuiceSSH bash-4.2. So add these two hooks back to fix them. Rissu's note: "I still thinking about this comment tiann/KernelSU#2084 (comment), i'll drop it if this changed." Co-authored-by: hamjin <[email protected]> Signed-off-by: Rissu <[email protected]>
1 parent b376d0d commit 18a4bb3

File tree

2 files changed

+25
-2
lines changed

2 files changed

+25
-2
lines changed

drivers/kernelsu/arch.h

+9-1
Original file line numberDiff line numberDiff line change
@@ -22,14 +22,18 @@
2222
#define PRCTL_SYMBOL "__arm64_sys_prctl"
2323
#define SYS_READ_SYMBOL "__arm64_sys_read"
2424
#define SYS_NEWFSTATAT_SYMBOL "__arm64_sys_newfstatat"
25+
#define SYS_FSTATAT64_SYMBOL "__arm64_sys_fstatat64"
2526
#define SYS_FACCESSAT_SYMBOL "__arm64_sys_faccessat"
2627
#define SYS_EXECVE_SYMBOL "__arm64_sys_execve"
28+
#define SYS_EXECVE_COMPAT_SYMBOL "__arm64_compat_sys_execve"
2729
#else
2830
#define PRCTL_SYMBOL "sys_prctl"
2931
#define SYS_READ_SYMBOL "sys_read"
3032
#define SYS_NEWFSTATAT_SYMBOL "sys_newfstatat"
33+
#define SYS_FSTATAT64_SYMBOL "sys_fstatat64"
3134
#define SYS_FACCESSAT_SYMBOL "sys_faccessat"
3235
#define SYS_EXECVE_SYMBOL "sys_execve"
36+
#define SYS_EXECVE_COMPAT_SYMBOL "compat_sys_execve"
3337
#endif
3438

3539
#elif defined(__x86_64__)
@@ -51,14 +55,18 @@
5155
#define PRCTL_SYMBOL "__x64_sys_prctl"
5256
#define SYS_READ_SYMBOL "__x64_sys_read"
5357
#define SYS_NEWFSTATAT_SYMBOL "__x64_sys_newfstatat"
58+
#define SYS_FSTATAT64_SYMBOL "__x64_sys_fstatat64"
5459
#define SYS_FACCESSAT_SYMBOL "__x64_sys_faccessat"
5560
#define SYS_EXECVE_SYMBOL "__x64_sys_execve"
61+
#define SYS_EXECVE_COMPAT_SYMBOL "__x64_compat_sys_execve"
5662
#else
5763
#define PRCTL_SYMBOL "sys_prctl"
5864
#define SYS_READ_SYMBOL "sys_read"
5965
#define SYS_NEWFSTATAT_SYMBOL "sys_newfstatat"
66+
#define SYS_FSTATAT64_SYMBOL "sys_fstatat64"
6067
#define SYS_FACCESSAT_SYMBOL "sys_faccessat"
6168
#define SYS_EXECVE_SYMBOL "sys_execve"
69+
#define SYS_EXECVE_COMPAT_SYMBOL "compat_sys_execve"
6270
#endif
6371

6472
#else
@@ -89,4 +97,4 @@
8997
#define PT_REAL_REGS(regs) ((regs))
9098
#endif
9199

92-
#endif
100+
#endif

drivers/kernelsu/sucompat.c

+16-1
Original file line numberDiff line numberDiff line change
@@ -327,6 +327,11 @@ static struct kprobe newfstatat_kp = {
327327
};
328328
#endif
329329

330+
static struct kprobe fstatat64_kp = {
331+
.symbol_name = SYS_FSTATAT64_SYMBOL,
332+
.pre_handler = sys_newfstatat_handler_pre,
333+
};
334+
330335
#if 1
331336
static struct kprobe execve_kp = {
332337
.symbol_name = SYS_EXECVE_SYMBOL,
@@ -345,6 +350,11 @@ static struct kprobe execve_kp = {
345350
};
346351
#endif
347352

353+
static struct kprobe execve_compat_kp = {
354+
.symbol_name = SYS_EXECVE_COMPAT_SYMBOL,
355+
.pre_handler = sys_execve_handler_pre,
356+
};
357+
348358
static int pts_unix98_lookup_pre(struct kprobe *p, struct pt_regs *regs)
349359
{
350360
struct inode *inode;
@@ -372,8 +382,12 @@ void ksu_sucompat_init()
372382
int ret;
373383
ret = register_kprobe(&execve_kp);
374384
pr_info("sucompat: execve_kp: %d\n", ret);
385+
ret = register_kprobe(&execve_compat_kp);
386+
pr_info("sucompat: execve_compat_kp: %d\n", ret);
375387
ret = register_kprobe(&newfstatat_kp);
376388
pr_info("sucompat: newfstatat_kp: %d\n", ret);
389+
ret = register_kprobe(&fstatat64_kp);
390+
pr_info("sucompat: fstatat64_kp: %d\n", ret);
377391
ret = register_kprobe(&faccessat_kp);
378392
pr_info("sucompat: faccessat_kp: %d\n", ret);
379393
ret = register_kprobe(&pts_unix98_lookup_kp);
@@ -385,7 +399,9 @@ void ksu_sucompat_exit()
385399
{
386400
#ifdef KSU_HOOK_WITH_KPROBES
387401
unregister_kprobe(&execve_kp);
402+
unregister_kprobe(&execve_compat_kp);
388403
unregister_kprobe(&newfstatat_kp);
404+
unregister_kprobe(&fstatat64_kp);
389405
unregister_kprobe(&faccessat_kp);
390406
unregister_kprobe(&pts_unix98_lookup_kp);
391407
#endif
@@ -410,4 +426,3 @@ void ksu_susfs_enable_sus_su(void) {
410426
ksu_devpts_hook = true;
411427
}
412428
#endif // #ifdef CONFIG_KSU_SUSFS_SUS_SU
413-

0 commit comments

Comments
 (0)