]> git.proxmox.com Git - mirror_ubuntu-jammy-kernel.git/blobdiff - net/netfilter/nf_conntrack_netlink.c
UBUNTU: SAUCE: LSM: Use lsmcontext in security_secid_to_secctx
[mirror_ubuntu-jammy-kernel.git] / net / netfilter / nf_conntrack_netlink.c
index de223234963dd65c90a5eb6f92d04fe1be0470d4..0c3e1a8aaf2b6368cd31ec605392c90e58a398db 100644 (file)
@@ -339,8 +339,7 @@ nla_put_failure:
 static int ctnetlink_dump_secctx(struct sk_buff *skb, const struct nf_conn *ct)
 {
        struct nlattr *nest_secctx;
-       int len, ret;
-       char *secctx;
+       int ret;
        struct lsmblob blob;
        struct lsmcontext context;
 
@@ -348,7 +347,7 @@ static int ctnetlink_dump_secctx(struct sk_buff *skb, const struct nf_conn *ct)
         * security_secid_to_secctx() will know which security module
         * to use to create the secctx.  */
        lsmblob_init(&blob, ct->secmark);
-       ret = security_secid_to_secctx(&blob, &secctx, &len);
+       ret = security_secid_to_secctx(&blob, &context);
        if (ret)
                return 0;
 
@@ -357,13 +356,12 @@ static int ctnetlink_dump_secctx(struct sk_buff *skb, const struct nf_conn *ct)
        if (!nest_secctx)
                goto nla_put_failure;
 
-       if (nla_put_string(skb, CTA_SECCTX_NAME, secctx))
+       if (nla_put_string(skb, CTA_SECCTX_NAME, context.context))
                goto nla_put_failure;
        nla_nest_end(skb, nest_secctx);
 
        ret = 0;
 nla_put_failure:
-       lsmcontext_init(&context, secctx, len, 0); /* scaffolding */
        security_release_secctx(&context);
        return ret;
 }
@@ -658,15 +656,15 @@ static inline int ctnetlink_secctx_size(const struct nf_conn *ct)
 #ifdef CONFIG_NF_CONNTRACK_SECMARK
        int len, ret;
        struct lsmblob blob;
+       struct lsmcontext context;
 
-       /* lsmblob_init() puts ct->secmark into all of the secids in blob.
-        * security_secid_to_secctx() will know which security module
-        * to use to create the secctx.  */
-       lsmblob_init(&blob, ct->secmark);
-       ret = security_secid_to_secctx(&blob, NULL, &len);
+       ret = security_secid_to_secctx(&blob, &context);
        if (ret)
                return 0;
 
+       len = context.len;
+       security_release_secctx(&context);
+
        return nla_total_size(0) /* CTA_SECCTX */
               + nla_total_size(sizeof(char) * len); /* CTA_SECCTX_NAME */
 #else