Skip to content

Commit ff7b915

Browse files
WangYuliopsiff
authored andcommitted
IEE: cred: Enhance credential cache initialization with SLAB_NO_MERGE
Improve the credential subsystem initialization in cred_init() by adding dedicated cache allocation flags and enhancing code structure. Key changes: *Add SLAB_NO_MERGE flag to all credential cache allocations to prevent cache merging and ensure dedicated memory pools. *Restructure conditional logic for better code readability and maintainability. *Enhance RCU jar cache creation with improved formatting and documentation. *Update informational log message to reflect the use of dedicated caches. *Add comprehensive comments explaining the purpose of independent cache creation. This change ensures that credential-related memory allocations use dedicated SLAB caches, which can improve security isolation and debugging capabilities while maintaining backward compatibility with existing configurations. The SLAB_NO_MERGE flag prevents the kernel from merging these caches with others, providing better memory layout control and potentially improved security characteristics for credential handling. Tested-by: Jun Zhan <[email protected]> Co-developed-by: Jun Zhan <[email protected]> Signed-off-by: Jun Zhan <[email protected]> Signed-off-by: WangYuli <[email protected]>
1 parent a3a9df9 commit ff7b915

File tree

1 file changed

+18
-8
lines changed

1 file changed

+18
-8
lines changed

kernel/cred.c

Lines changed: 18 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -733,21 +733,31 @@ void __init cred_init(void)
733733
{
734734
#ifdef CONFIG_CREDP
735735
if (haoc_enabled){
736+
// 为IEE配置创建独立的缓存,使用SLAB_NO_MERGE确保不会合并
736737
cred_jar = kmem_cache_create("cred_jar", sizeof(struct cred), 0,
737-
SLAB_HWCACHE_ALIGN|SLAB_PANIC|SLAB_ACCOUNT|SLAB_RED_ZONE, NULL);
738+
SLAB_HWCACHE_ALIGN|SLAB_PANIC|SLAB_ACCOUNT|SLAB_RED_ZONE|SLAB_NO_MERGE,
739+
NULL);
738740

739-
rcu_jar = kmem_cache_create("rcu_jar", sizeof(struct rcu_head) + sizeof(struct cred *), 0,
740-
SLAB_HWCACHE_ALIGN|SLAB_PANIC|SLAB_ACCOUNT, NULL);
741-
// Map init_cred
741+
// RCU缓存也创建为独立缓存
742+
rcu_jar = kmem_cache_create("rcu_jar",
743+
sizeof(struct rcu_head) + sizeof(struct cred *), 0,
744+
SLAB_HWCACHE_ALIGN|SLAB_PANIC|SLAB_ACCOUNT|SLAB_NO_MERGE,
745+
NULL);
746+
747+
// 初始化init_cred的RCU部分
742748
iee_set_cred_rcu(&init_cred, kmem_cache_zalloc(rcu_jar, GFP_KERNEL));
743749
*(struct cred **)(((struct rcu_head *)(init_cred.rcu.func)) + 1) = &init_cred;
744-
pr_info("HAOC: CONFIG_CREDP enabled.");
745-
} else
750+
751+
pr_info("HAOC: CONFIG_CREDP enabled with dedicated caches.");
752+
} else {
746753
cred_jar = kmem_cache_create("cred_jar", sizeof(struct cred), 0,
747-
SLAB_HWCACHE_ALIGN|SLAB_PANIC|SLAB_ACCOUNT, NULL);
754+
SLAB_HWCACHE_ALIGN|SLAB_PANIC|SLAB_ACCOUNT|SLAB_NO_MERGE,
755+
NULL);
756+
}
748757
#else
749758
cred_jar = kmem_cache_create("cred_jar", sizeof(struct cred), 0,
750-
SLAB_HWCACHE_ALIGN|SLAB_PANIC|SLAB_ACCOUNT, NULL);
759+
SLAB_HWCACHE_ALIGN|SLAB_PANIC|SLAB_ACCOUNT|SLAB_NO_MERGE,
760+
NULL);
751761
#endif
752762
}
753763

0 commit comments

Comments
 (0)