]> git.proxmox.com Git - mirror_ubuntu-bionic-kernel.git/commitdiff
crypto: Stop using NLA_PUT*().
authorDavid S. Miller <davem@davemloft.net>
Mon, 2 Apr 2012 00:19:05 +0000 (20:19 -0400)
committerDavid S. Miller <davem@davemloft.net>
Mon, 2 Apr 2012 08:33:42 +0000 (04:33 -0400)
These macros contain a hidden goto, and are thus extremely error
prone and make code hard to audit.

Signed-off-by: David S. Miller <davem@davemloft.net>
crypto/ablkcipher.c
crypto/aead.c
crypto/ahash.c
crypto/blkcipher.c
crypto/crypto_user.c
crypto/pcompress.c
crypto/rng.c
crypto/shash.c

index a0f768c1d9aa75fdb94a70dba711e175d8f66c9f..c22374bf9f1efbd6de631f149e03aeae5116164d 100644 (file)
@@ -397,9 +397,9 @@ static int crypto_ablkcipher_report(struct sk_buff *skb, struct crypto_alg *alg)
        rblkcipher.max_keysize = alg->cra_ablkcipher.max_keysize;
        rblkcipher.ivsize = alg->cra_ablkcipher.ivsize;
 
-       NLA_PUT(skb, CRYPTOCFGA_REPORT_BLKCIPHER,
-               sizeof(struct crypto_report_blkcipher), &rblkcipher);
-
+       if (nla_put(skb, CRYPTOCFGA_REPORT_BLKCIPHER,
+                   sizeof(struct crypto_report_blkcipher), &rblkcipher))
+               goto nla_put_failure;
        return 0;
 
 nla_put_failure:
@@ -478,9 +478,9 @@ static int crypto_givcipher_report(struct sk_buff *skb, struct crypto_alg *alg)
        rblkcipher.max_keysize = alg->cra_ablkcipher.max_keysize;
        rblkcipher.ivsize = alg->cra_ablkcipher.ivsize;
 
-       NLA_PUT(skb, CRYPTOCFGA_REPORT_BLKCIPHER,
-               sizeof(struct crypto_report_blkcipher), &rblkcipher);
-
+       if (nla_put(skb, CRYPTOCFGA_REPORT_BLKCIPHER,
+                   sizeof(struct crypto_report_blkcipher), &rblkcipher))
+               goto nla_put_failure;
        return 0;
 
 nla_put_failure:
index 04add3dca6fe44dfc242e89a36741c56786327fa..c772b9c79ee72999b1a47e39508716f2d3a53128 100644 (file)
@@ -125,9 +125,9 @@ static int crypto_aead_report(struct sk_buff *skb, struct crypto_alg *alg)
        raead.maxauthsize = aead->maxauthsize;
        raead.ivsize = aead->ivsize;
 
-       NLA_PUT(skb, CRYPTOCFGA_REPORT_AEAD,
-               sizeof(struct crypto_report_aead), &raead);
-
+       if (nla_put(skb, CRYPTOCFGA_REPORT_AEAD,
+                   sizeof(struct crypto_report_aead), &raead))
+               goto nla_put_failure;
        return 0;
 
 nla_put_failure:
@@ -210,9 +210,9 @@ static int crypto_nivaead_report(struct sk_buff *skb, struct crypto_alg *alg)
        raead.maxauthsize = aead->maxauthsize;
        raead.ivsize = aead->ivsize;
 
-       NLA_PUT(skb, CRYPTOCFGA_REPORT_AEAD,
-               sizeof(struct crypto_report_aead), &raead);
-
+       if (nla_put(skb, CRYPTOCFGA_REPORT_AEAD,
+                   sizeof(struct crypto_report_aead), &raead))
+               goto nla_put_failure;
        return 0;
 
 nla_put_failure:
index 33bc9b62e9ae5dde4a977c00293efc2ca2998a71..3887856c2dd68490736eb17bca5d01eae9837aa0 100644 (file)
@@ -409,9 +409,9 @@ static int crypto_ahash_report(struct sk_buff *skb, struct crypto_alg *alg)
        rhash.blocksize = alg->cra_blocksize;
        rhash.digestsize = __crypto_hash_alg_common(alg)->digestsize;
 
-       NLA_PUT(skb, CRYPTOCFGA_REPORT_HASH,
-               sizeof(struct crypto_report_hash), &rhash);
-
+       if (nla_put(skb, CRYPTOCFGA_REPORT_HASH,
+                   sizeof(struct crypto_report_hash), &rhash))
+               goto nla_put_failure;
        return 0;
 
 nla_put_failure:
index 4dd80c725498a3bb48cd9f4c961baced47f9cc6c..a8d85a1d670e14dd388a1a38c03f25b80f61436e 100644 (file)
@@ -508,9 +508,9 @@ static int crypto_blkcipher_report(struct sk_buff *skb, struct crypto_alg *alg)
        rblkcipher.max_keysize = alg->cra_blkcipher.max_keysize;
        rblkcipher.ivsize = alg->cra_blkcipher.ivsize;
 
-       NLA_PUT(skb, CRYPTOCFGA_REPORT_BLKCIPHER,
-               sizeof(struct crypto_report_blkcipher), &rblkcipher);
-
+       if (nla_put(skb, CRYPTOCFGA_REPORT_BLKCIPHER,
+                   sizeof(struct crypto_report_blkcipher), &rblkcipher))
+               goto nla_put_failure;
        return 0;
 
 nla_put_failure:
index f76e42bcc6e7f4c213eef714761ee34630fbc483..84a5ac71ecb43acd4246e2e7dcd90c713c376a7c 100644 (file)
@@ -77,9 +77,9 @@ static int crypto_report_cipher(struct sk_buff *skb, struct crypto_alg *alg)
        rcipher.min_keysize = alg->cra_cipher.cia_min_keysize;
        rcipher.max_keysize = alg->cra_cipher.cia_max_keysize;
 
-       NLA_PUT(skb, CRYPTOCFGA_REPORT_CIPHER,
-               sizeof(struct crypto_report_cipher), &rcipher);
-
+       if (nla_put(skb, CRYPTOCFGA_REPORT_CIPHER,
+                   sizeof(struct crypto_report_cipher), &rcipher))
+               goto nla_put_failure;
        return 0;
 
 nla_put_failure:
@@ -92,9 +92,9 @@ static int crypto_report_comp(struct sk_buff *skb, struct crypto_alg *alg)
 
        snprintf(rcomp.type, CRYPTO_MAX_ALG_NAME, "%s", "compression");
 
-       NLA_PUT(skb, CRYPTOCFGA_REPORT_COMPRESS,
-               sizeof(struct crypto_report_comp), &rcomp);
-
+       if (nla_put(skb, CRYPTOCFGA_REPORT_COMPRESS,
+                   sizeof(struct crypto_report_comp), &rcomp))
+               goto nla_put_failure;
        return 0;
 
 nla_put_failure:
@@ -113,16 +113,16 @@ static int crypto_report_one(struct crypto_alg *alg,
        ualg->cru_flags = alg->cra_flags;
        ualg->cru_refcnt = atomic_read(&alg->cra_refcnt);
 
-       NLA_PUT_U32(skb, CRYPTOCFGA_PRIORITY_VAL, alg->cra_priority);
-
+       if (nla_put_u32(skb, CRYPTOCFGA_PRIORITY_VAL, alg->cra_priority))
+               goto nla_put_failure;
        if (alg->cra_flags & CRYPTO_ALG_LARVAL) {
                struct crypto_report_larval rl;
 
                snprintf(rl.type, CRYPTO_MAX_ALG_NAME, "%s", "larval");
 
-               NLA_PUT(skb, CRYPTOCFGA_REPORT_LARVAL,
-                       sizeof(struct crypto_report_larval), &rl);
-
+               if (nla_put(skb, CRYPTOCFGA_REPORT_LARVAL,
+                           sizeof(struct crypto_report_larval), &rl))
+                       goto nla_put_failure;
                goto out;
        }
 
index 2e458e5482d0c5708cbab83dddaad11215c28a0e..04e083ff5373528ae4cb19263cb340461827df16 100644 (file)
@@ -55,9 +55,9 @@ static int crypto_pcomp_report(struct sk_buff *skb, struct crypto_alg *alg)
 
        snprintf(rpcomp.type, CRYPTO_MAX_ALG_NAME, "%s", "pcomp");
 
-       NLA_PUT(skb, CRYPTOCFGA_REPORT_COMPRESS,
-               sizeof(struct crypto_report_comp), &rpcomp);
-
+       if (nla_put(skb, CRYPTOCFGA_REPORT_COMPRESS,
+                   sizeof(struct crypto_report_comp), &rpcomp))
+               goto nla_put_failure;
        return 0;
 
 nla_put_failure:
index 64f864fa8043740f50bc186e58a2ee37d8a1499a..f3b7894dec00ee5207642f7ff95cbf8ef6aaeb2f 100644 (file)
@@ -69,9 +69,9 @@ static int crypto_rng_report(struct sk_buff *skb, struct crypto_alg *alg)
 
        rrng.seedsize = alg->cra_rng.seedsize;
 
-       NLA_PUT(skb, CRYPTOCFGA_REPORT_RNG,
-               sizeof(struct crypto_report_rng), &rrng);
-
+       if (nla_put(skb, CRYPTOCFGA_REPORT_RNG,
+                   sizeof(struct crypto_report_rng), &rrng))
+               goto nla_put_failure;
        return 0;
 
 nla_put_failure:
index 21fc12e2378f17340d40f264af6deeab51f214d5..32067f47e6c7bfbeea673d039e7ad5bc2bf90492 100644 (file)
@@ -534,9 +534,9 @@ static int crypto_shash_report(struct sk_buff *skb, struct crypto_alg *alg)
        rhash.blocksize = alg->cra_blocksize;
        rhash.digestsize = salg->digestsize;
 
-       NLA_PUT(skb, CRYPTOCFGA_REPORT_HASH,
-               sizeof(struct crypto_report_hash), &rhash);
-
+       if (nla_put(skb, CRYPTOCFGA_REPORT_HASH,
+                   sizeof(struct crypto_report_hash), &rhash))
+               goto nla_put_failure;
        return 0;
 
 nla_put_failure: