Skip to content

Commit

Permalink
kmsan: handle crypto_cipher_encrypt_one()/crypto_cipher_decrypt_one()
Browse files Browse the repository at this point in the history
These functions touch memory one block at a time. Because they're often
implemented in assembly, we just unpoison the output blocks and check
the inputs.
  • Loading branch information
ramosian-glider committed Jun 7, 2018
1 parent 9963e65 commit 1df6c1f
Showing 1 changed file with 5 additions and 0 deletions.
5 changes: 5 additions & 0 deletions include/linux/crypto.h
Expand Up @@ -19,6 +19,7 @@

#include <linux/atomic.h>
#include <linux/kernel.h>
#include <linux/kmsan-checks.h>
#include <linux/list.h>
#include <linux/bug.h>
#include <linux/slab.h>
Expand Down Expand Up @@ -1570,11 +1571,13 @@ static inline int crypto_cipher_setkey(struct crypto_cipher *tfm,
* Invoke the encryption operation of one block. The caller must ensure that
* the plaintext and ciphertext buffers are at least one block in size.
*/
// TODO(glider): do we need to unpoison other *_encrypt_* functions?
static inline void crypto_cipher_encrypt_one(struct crypto_cipher *tfm,
u8 *dst, const u8 *src)
{
crypto_cipher_crt(tfm)->cit_encrypt_one(crypto_cipher_tfm(tfm),
dst, src);
kmsan_unpoison_shadow(dst, crypto_cipher_tfm(tfm)->__crt_alg->cra_blocksize);
}

/**
Expand All @@ -1586,9 +1589,11 @@ static inline void crypto_cipher_encrypt_one(struct crypto_cipher *tfm,
* Invoke the decryption operation of one block. The caller must ensure that
* the plaintext and ciphertext buffers are at least one block in size.
*/
// TODO(glider): do we need to check other *_decrypt_* functions?
static inline void crypto_cipher_decrypt_one(struct crypto_cipher *tfm,
u8 *dst, const u8 *src)
{
kmsan_check_memory(src, crypto_cipher_tfm(tfm)->__crt_alg->cra_blocksize);
crypto_cipher_crt(tfm)->cit_decrypt_one(crypto_cipher_tfm(tfm),
dst, src);
}
Expand Down

0 comments on commit 1df6c1f

Please sign in to comment.