]> git.hungrycats.org Git - linux/commitdiff
selinux: switch two allocations to use kzalloc_objs()
authorStephen Smalley <stephen.smalley.work@gmail.com>
Wed, 29 Apr 2026 19:18:40 +0000 (15:18 -0400)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Wed, 2 Sep 2026 12:31:47 +0000 (14:31 +0200)
[ Upstream commit cf6a513f1937581eb012a217b29817e025a1a0ef ]

These were the only two allocations in the policy loading logic
that were not already using kzalloc_objs() for the policy
data structures. Fix these to be consistent with the rest and
to protect against ill-formed policy.

Signed-off-by: Stephen Smalley <stephen.smalley.work@gmail.com>
Signed-off-by: Paul Moore <paul@paul-moore.com>
Signed-off-by: Sasha Levin <sashal@kernel.org>
security/selinux/ss/conditional.c

index db30462ed6a32f252a85ae71d3058285a51e1821..280dc57df8d39c8d58825abc5a84f5730aa53d08 100644 (file)
@@ -165,7 +165,7 @@ void cond_policydb_destroy(struct policydb *p)
 int cond_init_bool_indexes(struct policydb *p)
 {
        kfree(p->bool_val_to_struct);
-       p->bool_val_to_struct = kmalloc_array(
+       p->bool_val_to_struct = kcalloc(
                p->p_bools.nprim, sizeof(*p->bool_val_to_struct), GFP_KERNEL);
        if (!p->bool_val_to_struct)
                return -ENOMEM;
@@ -706,9 +706,8 @@ static int duplicate_policydb_bools(struct policydb *newdb,
        struct cond_bool_datum **cond_bool_array;
        int rc;
 
-       cond_bool_array = kmalloc_array(orig->p_bools.nprim,
-                                       sizeof(*orig->bool_val_to_struct),
-                                       GFP_KERNEL);
+       cond_bool_array = kcalloc(orig->p_bools.nprim,
+                                 sizeof(*orig->bool_val_to_struct), GFP_KERNEL);
        if (!cond_bool_array)
                return -ENOMEM;