Skip to content

Commit 64baf3c

Browse files
herbertxdavem330
authored andcommitted
[CRYPTO]: Added CRYPTO_TFM_REQ_MAY_SLEEP flag
The crypto layer currently uses in_atomic() to determine whether it is allowed to sleep. This is incorrect since spin locks don't always cause in_atomic() to return true. Instead of that, this patch returns to an earlier idea of a per-tfm flag which determines whether sleeping is allowed. Unlike the earlier version, the default is to not allow sleeping. This ensures that no existing code can break. As usual, this flag may either be set through crypto_alloc_tfm(), or just before a specific crypto operation. Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au> Signed-off-by: David S. Miller <davem@davemloft.net>
1 parent fb4f10e commit 64baf3c

4 files changed

Lines changed: 5 additions & 6 deletions

File tree

‎crypto/api.c‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,8 @@ static inline struct crypto_alg *crypto_alg_mod_lookup(const char *name)
6666

6767
static int crypto_init_flags(struct crypto_tfm *tfm, u32 flags)
6868
{
69-
tfm->crt_flags = 0;
69+
tfm->crt_flags = flags & CRYPTO_TFM_REQ_MASK;
70+
flags &= ~CRYPTO_TFM_REQ_MASK;
7071

7172
switch (crypto_tfm_alg_type(tfm)) {
7273
case CRYPTO_ALG_TYPE_CIPHER:

‎crypto/cipher.c‎

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -377,11 +377,7 @@ static int nocrypt_iv(struct crypto_tfm *tfm,
377377
int crypto_init_cipher_flags(struct crypto_tfm *tfm, u32 flags)
378378
{
379379
u32 mode = flags & CRYPTO_TFM_MODE_MASK;
380-
381380
tfm->crt_cipher.cit_mode = mode ? mode : CRYPTO_TFM_MODE_ECB;
382-
if (flags & CRYPTO_TFM_REQ_WEAK_KEY)
383-
tfm->crt_flags = CRYPTO_TFM_REQ_WEAK_KEY;
384-
385381
return 0;
386382
}
387383

‎crypto/internal.h‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
#include <linux/interrupt.h>
1818
#include <linux/init.h>
1919
#include <linux/kernel.h>
20+
#include <linux/slab.h>
2021
#include <asm/kmap_types.h>
2122

2223
extern enum km_type crypto_km_types[];
@@ -38,7 +39,7 @@ static inline void crypto_kunmap(void *vaddr, int out)
3839

3940
static inline void crypto_yield(struct crypto_tfm *tfm)
4041
{
41-
if (!in_atomic())
42+
if (tfm->crt_flags & CRYPTO_TFM_REQ_MAY_SLEEP)
4243
cond_resched();
4344
}
4445

‎include/linux/crypto.h‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@
4545
#define CRYPTO_TFM_MODE_CTR 0x00000008
4646

4747
#define CRYPTO_TFM_REQ_WEAK_KEY 0x00000100
48+
#define CRYPTO_TFM_REQ_MAY_SLEEP 0x00000200
4849
#define CRYPTO_TFM_RES_WEAK_KEY 0x00100000
4950
#define CRYPTO_TFM_RES_BAD_KEY_LEN 0x00200000
5051
#define CRYPTO_TFM_RES_BAD_KEY_SCHED 0x00400000

0 commit comments

Comments
 (0)