Skip to content

Commit bb1ae0a

Browse files
ebiggersgregkh
authored andcommitted
crypto: pcbc - remove bogus memcpy()s with src == dest
commit 251b7ae upstream. The memcpy()s in the PCBC implementation use walk->iv as both the source and destination, which has undefined behavior. These memcpy()'s are actually unneeded, because walk->iv is already used to hold the previous plaintext block XOR'd with the previous ciphertext block. Thus, walk->iv is already updated to its final value. So remove the broken and unnecessary memcpy()s. Fixes: 91652be ("[CRYPTO] pcbc: Add Propagated CBC template") Cc: <stable@vger.kernel.org> # v2.6.21+ Cc: David Howells <dhowells@redhat.com> Signed-off-by: Eric Biggers <ebiggers@google.com> Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au> Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
1 parent c0bfdac commit bb1ae0a

1 file changed

Lines changed: 4 additions & 10 deletions

File tree

‎crypto/pcbc.c‎

Lines changed: 4 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ static int crypto_pcbc_encrypt_segment(struct skcipher_request *req,
5151
unsigned int nbytes = walk->nbytes;
5252
u8 *src = walk->src.virt.addr;
5353
u8 *dst = walk->dst.virt.addr;
54-
u8 *iv = walk->iv;
54+
u8 * const iv = walk->iv;
5555

5656
do {
5757
crypto_xor(iv, src, bsize);
@@ -72,7 +72,7 @@ static int crypto_pcbc_encrypt_inplace(struct skcipher_request *req,
7272
int bsize = crypto_cipher_blocksize(tfm);
7373
unsigned int nbytes = walk->nbytes;
7474
u8 *src = walk->src.virt.addr;
75-
u8 *iv = walk->iv;
75+
u8 * const iv = walk->iv;
7676
u8 tmpbuf[MAX_CIPHER_BLOCKSIZE];
7777

7878
do {
@@ -84,8 +84,6 @@ static int crypto_pcbc_encrypt_inplace(struct skcipher_request *req,
8484
src += bsize;
8585
} while ((nbytes -= bsize) >= bsize);
8686

87-
memcpy(walk->iv, iv, bsize);
88-
8987
return nbytes;
9088
}
9189

@@ -121,7 +119,7 @@ static int crypto_pcbc_decrypt_segment(struct skcipher_request *req,
121119
unsigned int nbytes = walk->nbytes;
122120
u8 *src = walk->src.virt.addr;
123121
u8 *dst = walk->dst.virt.addr;
124-
u8 *iv = walk->iv;
122+
u8 * const iv = walk->iv;
125123

126124
do {
127125
crypto_cipher_decrypt_one(tfm, dst, src);
@@ -132,8 +130,6 @@ static int crypto_pcbc_decrypt_segment(struct skcipher_request *req,
132130
dst += bsize;
133131
} while ((nbytes -= bsize) >= bsize);
134132

135-
memcpy(walk->iv, iv, bsize);
136-
137133
return nbytes;
138134
}
139135

@@ -144,7 +140,7 @@ static int crypto_pcbc_decrypt_inplace(struct skcipher_request *req,
144140
int bsize = crypto_cipher_blocksize(tfm);
145141
unsigned int nbytes = walk->nbytes;
146142
u8 *src = walk->src.virt.addr;
147-
u8 *iv = walk->iv;
143+
u8 * const iv = walk->iv;
148144
u8 tmpbuf[MAX_CIPHER_BLOCKSIZE] __aligned(__alignof__(u32));
149145

150146
do {
@@ -156,8 +152,6 @@ static int crypto_pcbc_decrypt_inplace(struct skcipher_request *req,
156152
src += bsize;
157153
} while ((nbytes -= bsize) >= bsize);
158154

159-
memcpy(walk->iv, iv, bsize);
160-
161155
return nbytes;
162156
}
163157

0 commit comments

Comments
 (0)