Fixed an error in the SukiSU integration of the Kirin 970 HarmonyOS2 kernel source code:

- Error: In the Kirin 970 HarmonyOS2 kernel source code, integrating SukiSU requires disabling the CONFIG_HKIP_SELINUX_PROT configuration option. Disabling this option will enable the use of flex_array. However, in the add_type and add_typeattribute_raw functions in kernel/selinux/sepolicy.c, if a Huawei HISI device is detected, ebitmap not flex_array is used, causing an error.

- Fix: Added conditional checks to the add_type and add_typeattribute_raw functions in kernel/selinux/sepolicy.c. Because the Kirin 970 EMUI10 kernel source code does not use flex_array, an option defined only in the EMUI10 kernel configuration is added to determine the kernel source code version.
This commit is contained in:
Natsume324
2025-10-01 13:31:43 +08:00
committed by ShirkNeko
parent 8943bab810
commit 3f4293e69a

View File

@@ -700,7 +700,7 @@ static bool add_type(struct policydb *db, const char *type_name, bool attr)
} }
return true; return true;
#elif defined(CONFIG_IS_HW_HISI) #elif defined(CONFIG_IS_HW_HISI) && defined(CONFIG_HISI_PMALLOC)
/* /*
* Huawei use type_attr_map and type_val_to_struct. * Huawei use type_attr_map and type_val_to_struct.
* And use ebitmap not flex_array. * And use ebitmap not flex_array.
@@ -832,8 +832,11 @@ static bool add_type(struct policydb *db, const char *type_name, bool attr)
if (old_fa) { if (old_fa) {
flex_array_free(old_fa); flex_array_free(old_fa);
} }
#if defined(CONFIG_IS_HW_HISI)
ebitmap_init(flex_array_get(db->type_attr_map_array, value - 1), HISI_SELINUX_EBITMAP_RO);
#else
ebitmap_init(flex_array_get(db->type_attr_map_array, value - 1)); ebitmap_init(flex_array_get(db->type_attr_map_array, value - 1));
#endif
ebitmap_set_bit(flex_array_get(db->type_attr_map_array, value - 1), ebitmap_set_bit(flex_array_get(db->type_attr_map_array, value - 1),
value - 1, 1); value - 1, 1);
@@ -900,15 +903,21 @@ static void add_typeattribute_raw(struct policydb *db, struct type_datum *type,
{ {
#if LINUX_VERSION_CODE >= KERNEL_VERSION(5, 1, 0) #if LINUX_VERSION_CODE >= KERNEL_VERSION(5, 1, 0)
struct ebitmap *sattr = &db->type_attr_map_array[type->value - 1]; struct ebitmap *sattr = &db->type_attr_map_array[type->value - 1];
#elif defined(CONFIG_IS_HW_HISI) #elif defined(CONFIG_IS_HW_HISI) && defined(CONFIG_HISI_PMALLOC)
/* /*
* HISI_SELINUX_EBITMAP_RO is Huawei's unique features. * HISI_SELINUX_EBITMAP_RO is Huawei's unique features.
*/ */
struct ebitmap *sattr = &db->type_attr_map[type->value - 1], struct ebitmap *sattr = &db->type_attr_map[type->value - 1],
HISI_SELINUX_EBITMAP_RO; HISI_SELINUX_EBITMAP_RO;
#else #else
#if defined(CONFIG_IS_HW_HISI)
struct ebitmap *sattr =
flex_array_get(db->type_attr_map_array, type->value - 1),
HISI_SELINUX_EBITMAP_RO;
#else
struct ebitmap *sattr = struct ebitmap *sattr =
flex_array_get(db->type_attr_map_array, type->value - 1); flex_array_get(db->type_attr_map_array, type->value - 1);
#endif
#endif #endif
ebitmap_set_bit(sattr, attr->value - 1, 1); ebitmap_set_bit(sattr, attr->value - 1, 1);