Skip to content

Commit 4f05fe2

Browse files
authored
kernel:Add Huawei hisi check (#1545)
Use huawei_hisi_check.h to determine whether it is an old Huawei HiSilicon device. Solve: 1. Compatible with non-GKI Huawei HiSilicon devices 2. Solve different bugs in EMUI of different system versions 3. Does not affect other devices
1 parent 58416be commit 4f05fe2

File tree

4 files changed

+22
-19
lines changed

4 files changed

+22
-19
lines changed

kernel/core_hook.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -618,7 +618,7 @@ static int ksu_task_prctl(int option, unsigned long arg2, unsigned long arg3,
618618
return -ENOSYS;
619619
}
620620
// kernel 4.4 and 4.9
621-
#if LINUX_VERSION_CODE < KERNEL_VERSION(4, 10, 0)
621+
#if LINUX_VERSION_CODE < KERNEL_VERSION(4, 10, 0) || defined(CONFIG_IS_HW_HISI)
622622
static int ksu_key_permission(key_ref_t key_ref, const struct cred *cred,
623623
unsigned perm)
624624
{
@@ -651,7 +651,7 @@ static struct security_hook_list ksu_hooks[] = {
651651
LSM_HOOK_INIT(task_prctl, ksu_task_prctl),
652652
LSM_HOOK_INIT(inode_rename, ksu_inode_rename),
653653
LSM_HOOK_INIT(task_fix_setuid, ksu_task_fix_setuid),
654-
#if LINUX_VERSION_CODE < KERNEL_VERSION(4, 10, 0)
654+
#if LINUX_VERSION_CODE < KERNEL_VERSION(4, 10, 0) || defined(CONFIG_IS_HW_HISI)
655655
LSM_HOOK_INIT(key_permission, ksu_key_permission)
656656
#endif
657657
};

kernel/kernel_compat.c

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,9 @@
88
#endif
99
#include "linux/uaccess.h"
1010
#include "klog.h" // IWYU pragma: keep
11+
#include "kernel_compat.h" // Add check Huawei Device
1112

12-
#if LINUX_VERSION_CODE < KERNEL_VERSION(4, 10, 0)
13+
#if LINUX_VERSION_CODE < KERNEL_VERSION(4, 10, 0) || defined(CONFIG_IS_HW_HISI)
1314
#include "linux/key.h"
1415
#include "linux/errno.h"
1516
#include "linux/cred.h"
@@ -78,7 +79,7 @@ void ksu_android_ns_fs_check()
7879

7980
struct file *ksu_filp_open_compat(const char *filename, int flags, umode_t mode)
8081
{
81-
#if LINUX_VERSION_CODE < KERNEL_VERSION(4, 10, 0)
82+
#if LINUX_VERSION_CODE < KERNEL_VERSION(4, 10, 0) || defined(CONFIG_IS_HW_HISI)
8283
if (init_session_keyring != NULL && !current_cred()->session_keyring &&
8384
(current->flags & PF_WQ_WORKER)) {
8485
pr_info("installing init session keyring for older kernel\n");

kernel/kernel_compat.h

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,27 @@
44
#include "linux/fs.h"
55
#include "linux/key.h"
66
#include "linux/version.h"
7+
#include "ss/policydb.h"
8+
9+
/*
10+
* Adapt to Huawei HISI kernel without affecting other kernels ,
11+
* Huawei Hisi Kernel EBITMAP Enable or Disable Flag ,
12+
* From ss/ebitmap.h
13+
*/
14+
#if (LINUX_VERSION_CODE >= KERNEL_VERSION(4, 9, 0)) && \
15+
(LINUX_VERSION_CODE < KERNEL_VERSION(4, 10, 0)) || \
16+
(LINUX_VERSION_CODE >= KERNEL_VERSION(4, 14, 0)) && \
17+
(LINUX_VERSION_CODE < KERNEL_VERSION(4, 15, 0))
18+
#ifdef HISI_SELINUX_EBITMAP_RO
19+
#define CONFIG_IS_HW_HISI
20+
#endif
21+
#endif
722

823
extern long ksu_strncpy_from_user_nofault(char *dst,
924
const void __user *unsafe_addr,
1025
long count);
1126

12-
#if LINUX_VERSION_CODE < KERNEL_VERSION(4, 10, 0)
27+
#if LINUX_VERSION_CODE < KERNEL_VERSION(4, 10, 0) || defined(CONFIG_IS_HW_HISI)
1328
extern struct key *init_session_keyring;
1429
#endif
1530

kernel/selinux/sepolicy.c

Lines changed: 1 addition & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -6,23 +6,10 @@
66

77
#include "../klog.h" // IWYU pragma: keep
88
#include "ss/symtab.h"
9+
#include "../kernel_compat.h" // Add check Huawei Device
910

1011
#define KSU_SUPPORT_ADD_TYPE
1112

12-
/*
13-
* Adapt to Huawei HISI kernel without affecting other kernels ,
14-
* Huawei Hisi Kernel EBITMAP Enable or Disable Flag ,
15-
* From ss/ebitmap.h
16-
*/
17-
#if LINUX_VERSION_CODE >= KERNEL_VERSION(4, 9, 0) && \
18-
LINUX_VERSION_CODE < KERNEL_VERSION(4, 10, 0) || \
19-
LINUX_VERSION_CODE >= KERNEL_VERSION(4, 14, 0) && \
20-
LINUX_VERSION_CODE < KERNEL_VERSION(4, 15, 0)
21-
#ifdef HISI_SELINUX_EBITMAP_RO
22-
#define CONFIG_IS_HW_HISI
23-
#endif
24-
#endif
25-
2613
//////////////////////////////////////////////////////
2714
// Declaration
2815
//////////////////////////////////////////////////////

0 commit comments

Comments
 (0)