Commit 73af07de3e32b9ac328c3d1417258bb98a9b0a9b
Committed by
Linus Torvalds
1 parent
79da342c31
Exists in
master
and in
4 other branches
[CRYPTO] hmac: Fix error truncation by unlikely()
The error return values are truncated by unlikely so we need to save it first. Thanks to Kyle Moffett for spotting this. Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au> Signed-off-by: Linus Torvalds <torvalds@osdl.org>
Showing 1 changed file with 18 additions and 6 deletions Side-by-side Diff
crypto/hmac.c
... | ... | @@ -92,13 +92,17 @@ |
92 | 92 | struct hmac_ctx *ctx = align_ptr(ipad + bs * 2 + ds, sizeof(void *)); |
93 | 93 | struct hash_desc desc; |
94 | 94 | struct scatterlist tmp; |
95 | + int err; | |
95 | 96 | |
96 | 97 | desc.tfm = ctx->child; |
97 | 98 | desc.flags = pdesc->flags & CRYPTO_TFM_REQ_MAY_SLEEP; |
98 | 99 | sg_set_buf(&tmp, ipad, bs); |
99 | 100 | |
100 | - return unlikely(crypto_hash_init(&desc)) ?: | |
101 | - crypto_hash_update(&desc, &tmp, bs); | |
101 | + err = crypto_hash_init(&desc); | |
102 | + if (unlikely(err)) | |
103 | + return err; | |
104 | + | |
105 | + return crypto_hash_update(&desc, &tmp, bs); | |
102 | 106 | } |
103 | 107 | |
104 | 108 | static int hmac_update(struct hash_desc *pdesc, |
105 | 109 | |
... | ... | @@ -123,13 +127,17 @@ |
123 | 127 | struct hmac_ctx *ctx = align_ptr(digest + ds, sizeof(void *)); |
124 | 128 | struct hash_desc desc; |
125 | 129 | struct scatterlist tmp; |
130 | + int err; | |
126 | 131 | |
127 | 132 | desc.tfm = ctx->child; |
128 | 133 | desc.flags = pdesc->flags & CRYPTO_TFM_REQ_MAY_SLEEP; |
129 | 134 | sg_set_buf(&tmp, opad, bs + ds); |
130 | 135 | |
131 | - return unlikely(crypto_hash_final(&desc, digest)) ?: | |
132 | - crypto_hash_digest(&desc, &tmp, bs + ds, out); | |
136 | + err = crypto_hash_final(&desc, digest); | |
137 | + if (unlikely(err)) | |
138 | + return err; | |
139 | + | |
140 | + return crypto_hash_digest(&desc, &tmp, bs + ds, out); | |
133 | 141 | } |
134 | 142 | |
135 | 143 | static int hmac_digest(struct hash_desc *pdesc, struct scatterlist *sg, |
... | ... | @@ -145,6 +153,7 @@ |
145 | 153 | struct hash_desc desc; |
146 | 154 | struct scatterlist sg1[2]; |
147 | 155 | struct scatterlist sg2[1]; |
156 | + int err; | |
148 | 157 | |
149 | 158 | desc.tfm = ctx->child; |
150 | 159 | desc.flags = pdesc->flags & CRYPTO_TFM_REQ_MAY_SLEEP; |
... | ... | @@ -154,8 +163,11 @@ |
154 | 163 | sg1[1].length = 0; |
155 | 164 | sg_set_buf(sg2, opad, bs + ds); |
156 | 165 | |
157 | - return unlikely(crypto_hash_digest(&desc, sg1, nbytes + bs, digest)) ?: | |
158 | - crypto_hash_digest(&desc, sg2, bs + ds, out); | |
166 | + err = crypto_hash_digest(&desc, sg1, nbytes + bs, digest); | |
167 | + if (unlikely(err)) | |
168 | + return err; | |
169 | + | |
170 | + return crypto_hash_digest(&desc, sg2, bs + ds, out); | |
159 | 171 | } |
160 | 172 | |
161 | 173 | static int hmac_init_tfm(struct crypto_tfm *tfm) |