Skip to content

Commit 6662df3

Browse files
committed
crypto: Stop using NLA_PUT*().
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>
1 parent b21dddb commit 6662df3

8 files changed

Lines changed: 38 additions & 38 deletions

File tree

‎crypto/ablkcipher.c‎

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -397,9 +397,9 @@ static int crypto_ablkcipher_report(struct sk_buff *skb, struct crypto_alg *alg)
397397
rblkcipher.max_keysize = alg->cra_ablkcipher.max_keysize;
398398
rblkcipher.ivsize = alg->cra_ablkcipher.ivsize;
399399

400-
NLA_PUT(skb, CRYPTOCFGA_REPORT_BLKCIPHER,
401-
sizeof(struct crypto_report_blkcipher), &rblkcipher);
402-
400+
if (nla_put(skb, CRYPTOCFGA_REPORT_BLKCIPHER,
401+
sizeof(struct crypto_report_blkcipher), &rblkcipher))
402+
goto nla_put_failure;
403403
return 0;
404404

405405
nla_put_failure:
@@ -478,9 +478,9 @@ static int crypto_givcipher_report(struct sk_buff *skb, struct crypto_alg *alg)
478478
rblkcipher.max_keysize = alg->cra_ablkcipher.max_keysize;
479479
rblkcipher.ivsize = alg->cra_ablkcipher.ivsize;
480480

481-
NLA_PUT(skb, CRYPTOCFGA_REPORT_BLKCIPHER,
482-
sizeof(struct crypto_report_blkcipher), &rblkcipher);
483-
481+
if (nla_put(skb, CRYPTOCFGA_REPORT_BLKCIPHER,
482+
sizeof(struct crypto_report_blkcipher), &rblkcipher))
483+
goto nla_put_failure;
484484
return 0;
485485

486486
nla_put_failure:

‎crypto/aead.c‎

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -125,9 +125,9 @@ static int crypto_aead_report(struct sk_buff *skb, struct crypto_alg *alg)
125125
raead.maxauthsize = aead->maxauthsize;
126126
raead.ivsize = aead->ivsize;
127127

128-
NLA_PUT(skb, CRYPTOCFGA_REPORT_AEAD,
129-
sizeof(struct crypto_report_aead), &raead);
130-
128+
if (nla_put(skb, CRYPTOCFGA_REPORT_AEAD,
129+
sizeof(struct crypto_report_aead), &raead))
130+
goto nla_put_failure;
131131
return 0;
132132

133133
nla_put_failure:
@@ -210,9 +210,9 @@ static int crypto_nivaead_report(struct sk_buff *skb, struct crypto_alg *alg)
210210
raead.maxauthsize = aead->maxauthsize;
211211
raead.ivsize = aead->ivsize;
212212

213-
NLA_PUT(skb, CRYPTOCFGA_REPORT_AEAD,
214-
sizeof(struct crypto_report_aead), &raead);
215-
213+
if (nla_put(skb, CRYPTOCFGA_REPORT_AEAD,
214+
sizeof(struct crypto_report_aead), &raead))
215+
goto nla_put_failure;
216216
return 0;
217217

218218
nla_put_failure:

‎crypto/ahash.c‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -409,9 +409,9 @@ static int crypto_ahash_report(struct sk_buff *skb, struct crypto_alg *alg)
409409
rhash.blocksize = alg->cra_blocksize;
410410
rhash.digestsize = __crypto_hash_alg_common(alg)->digestsize;
411411

412-
NLA_PUT(skb, CRYPTOCFGA_REPORT_HASH,
413-
sizeof(struct crypto_report_hash), &rhash);
414-
412+
if (nla_put(skb, CRYPTOCFGA_REPORT_HASH,
413+
sizeof(struct crypto_report_hash), &rhash))
414+
goto nla_put_failure;
415415
return 0;
416416

417417
nla_put_failure:

‎crypto/blkcipher.c‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -508,9 +508,9 @@ static int crypto_blkcipher_report(struct sk_buff *skb, struct crypto_alg *alg)
508508
rblkcipher.max_keysize = alg->cra_blkcipher.max_keysize;
509509
rblkcipher.ivsize = alg->cra_blkcipher.ivsize;
510510

511-
NLA_PUT(skb, CRYPTOCFGA_REPORT_BLKCIPHER,
512-
sizeof(struct crypto_report_blkcipher), &rblkcipher);
513-
511+
if (nla_put(skb, CRYPTOCFGA_REPORT_BLKCIPHER,
512+
sizeof(struct crypto_report_blkcipher), &rblkcipher))
513+
goto nla_put_failure;
514514
return 0;
515515

516516
nla_put_failure:

‎crypto/crypto_user.c‎

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -77,9 +77,9 @@ static int crypto_report_cipher(struct sk_buff *skb, struct crypto_alg *alg)
7777
rcipher.min_keysize = alg->cra_cipher.cia_min_keysize;
7878
rcipher.max_keysize = alg->cra_cipher.cia_max_keysize;
7979

80-
NLA_PUT(skb, CRYPTOCFGA_REPORT_CIPHER,
81-
sizeof(struct crypto_report_cipher), &rcipher);
82-
80+
if (nla_put(skb, CRYPTOCFGA_REPORT_CIPHER,
81+
sizeof(struct crypto_report_cipher), &rcipher))
82+
goto nla_put_failure;
8383
return 0;
8484

8585
nla_put_failure:
@@ -92,9 +92,9 @@ static int crypto_report_comp(struct sk_buff *skb, struct crypto_alg *alg)
9292

9393
snprintf(rcomp.type, CRYPTO_MAX_ALG_NAME, "%s", "compression");
9494

95-
NLA_PUT(skb, CRYPTOCFGA_REPORT_COMPRESS,
96-
sizeof(struct crypto_report_comp), &rcomp);
97-
95+
if (nla_put(skb, CRYPTOCFGA_REPORT_COMPRESS,
96+
sizeof(struct crypto_report_comp), &rcomp))
97+
goto nla_put_failure;
9898
return 0;
9999

100100
nla_put_failure:
@@ -113,16 +113,16 @@ static int crypto_report_one(struct crypto_alg *alg,
113113
ualg->cru_flags = alg->cra_flags;
114114
ualg->cru_refcnt = atomic_read(&alg->cra_refcnt);
115115

116-
NLA_PUT_U32(skb, CRYPTOCFGA_PRIORITY_VAL, alg->cra_priority);
117-
116+
if (nla_put_u32(skb, CRYPTOCFGA_PRIORITY_VAL, alg->cra_priority))
117+
goto nla_put_failure;
118118
if (alg->cra_flags & CRYPTO_ALG_LARVAL) {
119119
struct crypto_report_larval rl;
120120

121121
snprintf(rl.type, CRYPTO_MAX_ALG_NAME, "%s", "larval");
122122

123-
NLA_PUT(skb, CRYPTOCFGA_REPORT_LARVAL,
124-
sizeof(struct crypto_report_larval), &rl);
125-
123+
if (nla_put(skb, CRYPTOCFGA_REPORT_LARVAL,
124+
sizeof(struct crypto_report_larval), &rl))
125+
goto nla_put_failure;
126126
goto out;
127127
}
128128

‎crypto/pcompress.c‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -55,9 +55,9 @@ static int crypto_pcomp_report(struct sk_buff *skb, struct crypto_alg *alg)
5555

5656
snprintf(rpcomp.type, CRYPTO_MAX_ALG_NAME, "%s", "pcomp");
5757

58-
NLA_PUT(skb, CRYPTOCFGA_REPORT_COMPRESS,
59-
sizeof(struct crypto_report_comp), &rpcomp);
60-
58+
if (nla_put(skb, CRYPTOCFGA_REPORT_COMPRESS,
59+
sizeof(struct crypto_report_comp), &rpcomp))
60+
goto nla_put_failure;
6161
return 0;
6262

6363
nla_put_failure:

‎crypto/rng.c‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -69,9 +69,9 @@ static int crypto_rng_report(struct sk_buff *skb, struct crypto_alg *alg)
6969

7070
rrng.seedsize = alg->cra_rng.seedsize;
7171

72-
NLA_PUT(skb, CRYPTOCFGA_REPORT_RNG,
73-
sizeof(struct crypto_report_rng), &rrng);
74-
72+
if (nla_put(skb, CRYPTOCFGA_REPORT_RNG,
73+
sizeof(struct crypto_report_rng), &rrng))
74+
goto nla_put_failure;
7575
return 0;
7676

7777
nla_put_failure:

‎crypto/shash.c‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -534,9 +534,9 @@ static int crypto_shash_report(struct sk_buff *skb, struct crypto_alg *alg)
534534
rhash.blocksize = alg->cra_blocksize;
535535
rhash.digestsize = salg->digestsize;
536536

537-
NLA_PUT(skb, CRYPTOCFGA_REPORT_HASH,
538-
sizeof(struct crypto_report_hash), &rhash);
539-
537+
if (nla_put(skb, CRYPTOCFGA_REPORT_HASH,
538+
sizeof(struct crypto_report_hash), &rhash))
539+
goto nla_put_failure;
540540
return 0;
541541

542542
nla_put_failure:

0 commit comments

Comments
 (0)