Skip to content

Commit

Permalink
kernel: Fix compatibility with old and 32bit programs
Browse files Browse the repository at this point in the history
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.

Signed-off-by: hamjin <[email protected]>
  • Loading branch information
hamjin committed Sep 22, 2024
1 parent ac20b76 commit c228c23
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 0 deletions.
4 changes: 4 additions & 0 deletions kernel/arch.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,10 @@
#define PRCTL_SYMBOL "__arm64_sys_prctl"
#define SYS_READ_SYMBOL "__arm64_sys_read"
#define SYS_NEWFSTATAT_SYMBOL "__arm64_sys_newfstatat"
#define SYS_FSTATAT64_SYMBOL "__arm64_sys_fstatat64"
#define SYS_FACCESSAT_SYMBOL "__arm64_sys_faccessat"
#define SYS_EXECVE_SYMBOL "__arm64_sys_execve"
#define SYS_EXECVE_COMPAT_SYMBOL "__arm64_compat_sys_execve"

#elif defined(__x86_64__)

Expand All @@ -42,8 +44,10 @@
#define PRCTL_SYMBOL "__x64_sys_prctl"
#define SYS_READ_SYMBOL "__x64_sys_read"
#define SYS_NEWFSTATAT_SYMBOL "__x64_sys_newfstatat"
#define SYS_FSTATAT64_SYMBOL "__x64_sys_fstatat64"
#define SYS_FACCESSAT_SYMBOL "__x64_sys_faccessat"
#define SYS_EXECVE_SYMBOL "__x64_sys_execve"
#define SYS_EXECVE_COMPAT_SYMBOL "__x64_compat_sys_execve"

#else
#error "Unsupported arch"
Expand Down
16 changes: 16 additions & 0 deletions kernel/sucompat.c
Original file line number Diff line number Diff line change
Expand Up @@ -232,11 +232,21 @@ static struct kprobe newfstatat_kp = {
.pre_handler = sys_newfstatat_handler_pre,
};

static struct kprobe fstatat64_kp = {
.symbol_name = SYS_FSTATAT64_SYMBOL,
.pre_handler = sys_newfstatat_handler_pre,
};

static struct kprobe execve_kp = {
.symbol_name = SYS_EXECVE_SYMBOL,
.pre_handler = sys_execve_handler_pre,
};

static struct kprobe execve_compat_kp = {
.symbol_name = SYS_EXECVE_COMPAT_SYMBOL,
.pre_handler = sys_execve_handler_pre,
};

static int pts_unix98_lookup_pre(struct kprobe *p, struct pt_regs *regs)
{
struct inode *inode;
Expand All @@ -260,8 +270,12 @@ void ksu_sucompat_init()
int ret;
ret = register_kprobe(&execve_kp);
pr_info("sucompat: execve_kp: %d\n", ret);
ret = register_kprobe(&execve_compat_kp);
pr_info("sucompat: execve_compat_kp: %d\n", ret);
ret = register_kprobe(&newfstatat_kp);
pr_info("sucompat: newfstatat_kp: %d\n", ret);
ret = register_kprobe(&fstatat64_kp);
pr_info("sucompat: fstatat64_kp: %d\n", ret);
ret = register_kprobe(&faccessat_kp);
pr_info("sucompat: faccessat_kp: %d\n", ret);
ret = register_kprobe(&pts_unix98_lookup_kp);
Expand All @@ -273,7 +287,9 @@ void ksu_sucompat_exit()
{
#ifdef CONFIG_KPROBES
unregister_kprobe(&execve_kp);
unregister_kprobe(&execve_compat_kp);
unregister_kprobe(&newfstatat_kp);
unregister_kprobe(&fstatat64_kp);
unregister_kprobe(&faccessat_kp);
unregister_kprobe(&pts_unix98_lookup_kp);
#endif
Expand Down

0 comments on commit c228c23

Please sign in to comment.