Skip to content
This repository was archived by the owner on Oct 30, 2025. It is now read-only.

Commit ca22487

Browse files
committed
kernel: core_hook: fixup 32-on-64 compat detection via linux_binprm
I'll just post code comments as I'm too lazy. Maybe i'll do a writeup later blah blah /* * 32-on-64 compat detection * * notes: * bprm->buf provides the binary itself !! * https://unix.stackexchange.com/questions/106234/determine-if-a-specific-process-is-32-or-64-bit * buf[0] == 0x7f && buf[1] == 'E' && buf[2] == 'L' && buf[3] == 'F' * so as that said, we check ELF header, then we check 5th byte, 0x01 = 32-bit, 0x02 = 64 bit * we only check first execution of /data/adb/ksud and while ksu_execveat_hook is open! * */ Signed-off-by: backslashxx <[email protected]>
1 parent 3310984 commit ca22487

File tree

2 files changed

+27
-4
lines changed

2 files changed

+27
-4
lines changed

kernel/core_hook.c

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -693,13 +693,40 @@ int ksu_inode_permission(struct inode *inode, int mask)
693693
return 0;
694694
}
695695

696+
#ifdef CONFIG_COMPAT
697+
bool ksu_is_compat __read_mostly = false;
698+
#endif
699+
696700
int ksu_bprm_check(struct linux_binprm *bprm)
697701
{
698702
char *filename = (char *)bprm->filename;
699703

700704
if (likely(!ksu_execveat_hook))
701705
return 0;
702706

707+
/*
708+
* 32-on-64 compat detection
709+
*
710+
* notes:
711+
* bprm->buf provides the binary itself !!
712+
* https://unix.stackexchange.com/questions/106234/determine-if-a-specific-process-is-32-or-64-bit
713+
* buf[0] == 0x7f && buf[1] == 'E' && buf[2] == 'L' && buf[3] == 'F'
714+
* so as that said, we check ELF header, then we check 5th byte, 0x01 = 32-bit, 0x02 = 64 bit
715+
* we only check first execution of /data/adb/ksud and while ksu_execveat_hook is open!
716+
*
717+
*/
718+
#ifdef CONFIG_COMPAT
719+
static bool compat_check_done __read_mostly = false;
720+
if ( unlikely(!compat_check_done) && unlikely(!strcmp(filename, "/data/adb/ksud"))
721+
&& !memcmp(bprm->buf, "\x7f\x45\x4c\x46", 4) ) {
722+
if (bprm->buf[4] == 0x01 )
723+
ksu_is_compat = true;
724+
725+
pr_info("%s: %s ELF magic found! ksu_is_compat: %d \n", __func__, filename, ksu_is_compat);
726+
compat_check_done = true;
727+
}
728+
#endif
729+
703730
ksu_handle_pre_ksud(filename);
704731

705732
return 0;

kernel/ksud.c

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -64,10 +64,6 @@ bool ksu_input_hook __read_mostly = true;
6464

6565
u32 ksu_devpts_sid;
6666

67-
#ifdef CONFIG_COMPAT
68-
bool ksu_is_compat __read_mostly = false;
69-
#endif
70-
7167
void on_post_fs_data(void)
7268
{
7369
static bool done = false;

0 commit comments

Comments
 (0)