]> git.ipfire.org Git - thirdparty/linux.git/commitdiff
lsm: use unrcu_pointer() for current->cred in security_init()
authorPaul Moore <paul@paul-moore.com>
Wed, 19 Nov 2025 00:18:10 +0000 (19:18 -0500)
committerPaul Moore <paul@paul-moore.com>
Wed, 19 Nov 2025 15:32:06 +0000 (10:32 -0500)
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.

Reviewed-by: Xiu Jianfeng <xiujianfeng@huawei.com>
Signed-off-by: Paul Moore <paul@paul-moore.com>
security/lsm_init.c

index 6bb67d41ce52bb116a401474832c2afaa64fbf25..05bd52e6b1f25d4e534cda3b057dfb23565b4c9f 100644 (file)
@@ -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");