]> Git Repo - J-linux.git/commitdiff
selinux: Use struct_size() helper in kmalloc()
authorXiu Jianfeng <[email protected]>
Thu, 2 Dec 2021 07:35:33 +0000 (15:35 +0800)
committerPaul Moore <[email protected]>
Mon, 6 Dec 2021 02:58:32 +0000 (21:58 -0500)
Make use of struct_size() helper instead of an open-coded calculation.

Link: https://github.com/KSPP/linux/issues/160
Signed-off-by: Xiu Jianfeng <[email protected]>
Signed-off-by: Paul Moore <[email protected]>
security/selinux/ss/sidtab.c
security/selinux/xfrm.c

index 656d50b09f7629bc22b884bf4b1fea1039ca243c..293ec048af08c60f55c1a78f7e22faec2acd1290 100644 (file)
@@ -570,7 +570,7 @@ void sidtab_sid2str_put(struct sidtab *s, struct sidtab_entry *entry,
                goto out_unlock;
        }
 
-       cache = kmalloc(sizeof(struct sidtab_str_cache) + str_len, GFP_ATOMIC);
+       cache = kmalloc(struct_size(cache, str, str_len), GFP_ATOMIC);
        if (!cache)
                goto out_unlock;
 
index be83e5ce4469c68fc8758ec1cae0022fa0145b8a..90697317895fbf918be1884fa098e77ad021a2b7 100644 (file)
@@ -89,7 +89,7 @@ static int selinux_xfrm_alloc_user(struct xfrm_sec_ctx **ctxp,
        if (str_len >= PAGE_SIZE)
                return -ENOMEM;
 
-       ctx = kmalloc(sizeof(*ctx) + str_len + 1, gfp);
+       ctx = kmalloc(struct_size(ctx, ctx_str, str_len + 1), gfp);
        if (!ctx)
                return -ENOMEM;
 
@@ -360,7 +360,7 @@ int selinux_xfrm_state_alloc_acquire(struct xfrm_state *x,
        if (rc)
                return rc;
 
-       ctx = kmalloc(sizeof(*ctx) + str_len, GFP_ATOMIC);
+       ctx = kmalloc(struct_size(ctx, ctx_str, str_len), GFP_ATOMIC);
        if (!ctx) {
                rc = -ENOMEM;
                goto out;
This page took 0.058012 seconds and 4 git commands to generate.