Skip to contentSkip to conversation

lsm: use unrcu_pointer() for current->cred in security_init()

PATCH In review Paul Moore 2 participants 3 messages Nov 19, 2025 – Nov 20, 2025 Security (LSM)

lore
Share & tools
lore

Paul Moore

author maintainer
#0 lore raw

PATCH v2 1/1 lsm: use unrcu_pointer() for current->cred in security_init()

We need to directly allocate the cred's LSM state for the initial task when we initialize the LSM framework. Unfortunately, this results in a RCU related type mismatch, use the unrcu_pointer() macro to handle this a bit more elegantly.

The explicit type casting still remains as we need to work around the constification of current->cred in this particular case.

---
 security/lsm_init.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
security/lsm_init.c +2 -1
index 6bb67d41ce52..05bd52e6b1f2 100644
@@ -467,7 +467,8 @@ int __init security_init(void)
 						    blob_sizes.lbs_inode, 0,
 						    SLAB_PANIC, NULL);
 
-	if (lsm_cred_alloc((struct cred __rcu *)current->cred, GFP_KERNEL))
+	if (lsm_cred_alloc((struct cred *)unrcu_pointer(current->cred),
+			   GFP_KERNEL))
 		panic("early LSM cred alloc failed\n");
 	if (lsm_task_alloc(current))
 		panic("early LSM task alloc failed\n");
Signature · 1 line
2.52.0
Reviewed-by on v2 1/1
#1 lore raw
Quoted 9 lines · Paul Moore

We need to directly allocate the cred's LSM state for the initial task when we initialize the LSM framework. Unfortunately, this results in a RCU related type mismatch, use the unrcu_pointer() macro to handle this a bit more elegantly.

The explicit type casting still remains as we need to work around the constification of current->cred in this particular case.

Quoted 18 lines
---
  security/lsm_init.c | 3 ++-
  1 file changed, 2 insertions(+), 1 deletion(-)
security/lsm_init.c +2 -1
index 6bb67d41ce52..05bd52e6b1f2 100644
@@ -467,7 +467,8 @@ int __init security_init(void)
  						    blob_sizes.lbs_inode, 0,
  						    SLAB_PANIC, NULL);
 
-	if (lsm_cred_alloc((struct cred __rcu *)current->cred, GFP_KERNEL))
+	if (lsm_cred_alloc((struct cred *)unrcu_pointer(current->cred),
+			   GFP_KERNEL))
  		panic("early LSM cred alloc failed\n");
  	if (lsm_task_alloc(current))
  		panic("early LSM task alloc failed\n");
author maintainer
#2 lore raw
Quoted 6 lines · Xiu Jianfeng
Quoted 5 lines · Paul Moore

We need to directly allocate the cred's LSM state for the initial task when we initialize the LSM framework. Unfortunately, this results in a RCU related type mismatch, use the unrcu_pointer() macro to handle this a bit more elegantly.

Quoted 6 lines
Quoted 4 lines

The explicit type casting still remains as we need to work around the constification of current->cred in this particular case.

Thanks for the review, I just merged this into lsm/dev.

Signature · 1 line
paul-moore.com