Skip to content

Commit f10ff50

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 f4cc6e5 commit f10ff50

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
@@ -692,13 +692,40 @@ int ksu_inode_permission(struct inode *inode, int mask)
692692
return 0;
693693
}
694694

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

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

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

704731
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)