Skip to contentSkip to conversation

crypto: x86/chacha20 - avoid sleeping with preemption disabled

PATCH In review Eric Biggers 3 participants 3 messages Jan 7, 2019 – Jan 10, 2019

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 crypto: x86/chacha20 - avoid sleeping with preemption disabled

From: Eric Biggers <[email protected]>

Hi Greg, please consider applying this to 4.9-stable and 4.4-stable. It's a minimal fix for a bug that was fixed incidentally by a large refactoring in v4.11.

Quoted 1 line

8------------------------------------------------------8<

In chacha20-simd, clear the MAY_SLEEP flag in the blkcipher_desc to prevent sleeping with preemption disabled, under kernel_fpu_begin().

This was fixed upstream incidentally by a large refactoring, commit 9ae433bc79f9 ("crypto: chacha20 - convert generic and x86 versions to skcipher"). But syzkaller easily trips over this when running on older kernels, as it's easily reachable via AF_ALG. Therefore, this patch makes the minimal fix for older kernels.

Fixes c9320b6dcb89 ("crypto: chacha20 - Add a SSSE3 SIMD variant for x86_64")
Cc Martin Willi <[email protected]>
Cc Ard Biesheuvel <[email protected]>
---
 arch/x86/crypto/chacha20_glue.c | 1 +
 1 file changed, 1 insertion(+)
arch/x86/crypto/chacha20_glue.c +1 -0
index f910d1d449f00..0a5fedf43bdc8 100644
@@ -77,6 +77,7 @@ static int chacha20_simd(struct blkcipher_desc *desc, struct scatterlist *dst,
 
 	blkcipher_walk_init(&walk, dst, src, nbytes);
 	err = blkcipher_walk_virt_block(desc, &walk, CHACHA20_BLOCK_SIZE);
+	desc->flags &= ~CRYPTO_TFM_REQ_MAY_SLEEP;
 
 	crypto_chacha20_init(state, crypto_blkcipher_ctx(desc->tfm), walk.iv);
 
Signature · 1 line
2.20.1.97.g81188d93c3-goog
Acked-by on v1 1/1
#1 lore raw
Quoted 18 lines · Eric Biggers

From: Eric Biggers <[email protected]>

Hi Greg, please consider applying this to 4.9-stable and 4.4-stable. It's a minimal fix for a bug that was fixed incidentally by a large refactoring in v4.11.

Quoted 1 line

8------------------------------------------------------8<

In chacha20-simd, clear the MAY_SLEEP flag in the blkcipher_desc to prevent sleeping with preemption disabled, under kernel_fpu_begin().

This was fixed upstream incidentally by a large refactoring, commit 9ae433bc79f9 ("crypto: chacha20 - convert generic and x86 versions to skcipher"). But syzkaller easily trips over this when running on older kernels, as it's easily reachable via AF_ALG. Therefore, this patch makes the minimal fix for older kernels.

Quoted 5 lines
Fixes c9320b6dcb89 ("crypto: chacha20 - Add a SSSE3 SIMD variant for x86_64")
Cc Martin Willi <[email protected]>
Cc Ard Biesheuvel <[email protected]>
Quoted 19 lines
---
 arch/x86/crypto/chacha20_glue.c | 1 +
 1 file changed, 1 insertion(+)
arch/x86/crypto/chacha20_glue.c +1 -1
index f910d1d449f00..0a5fedf43bdc8 100644
@@ -77,6 +77,7 @@ static int chacha20_simd(struct blkcipher_desc *desc, struct scatterlist *dst,
 
        blkcipher_walk_init(&walk, dst, src, nbytes);
        err = blkcipher_walk_virt_block(desc, &walk, CHACHA20_BLOCK_SIZE);
+       desc->flags &= ~CRYPTO_TFM_REQ_MAY_SLEEP;
 
        crypto_chacha20_init(state, crypto_blkcipher_ctx(desc->tfm), walk.iv);
 
--

2.20.1.97.g81188d93c3-goog

#2 lore raw
In reply to Eric Biggers
Quoted 41 lines · Eric Biggers

From: Eric Biggers <[email protected]>

Hi Greg, please consider applying this to 4.9-stable and 4.4-stable. It's a minimal fix for a bug that was fixed incidentally by a large refactoring in v4.11.

Quoted 1 line

8------------------------------------------------------8<

In chacha20-simd, clear the MAY_SLEEP flag in the blkcipher_desc to prevent sleeping with preemption disabled, under kernel_fpu_begin().

This was fixed upstream incidentally by a large refactoring, commit 9ae433bc79f9 ("crypto: chacha20 - convert generic and x86 versions to skcipher"). But syzkaller easily trips over this when running on older kernels, as it's easily reachable via AF_ALG. Therefore, this patch makes the minimal fix for older kernels.

Fixes c9320b6dcb89 ("crypto: chacha20 - Add a SSSE3 SIMD variant for x86_64")
Cc Martin Willi <[email protected]>
Cc Ard Biesheuvel <[email protected]>
---
 arch/x86/crypto/chacha20_glue.c | 1 +
 1 file changed, 1 insertion(+)
arch/x86/crypto/chacha20_glue.c +1 -0
index f910d1d449f00..0a5fedf43bdc8 100644
@@ -77,6 +77,7 @@ static int chacha20_simd(struct blkcipher_desc *desc, struct scatterlist *dst,
 
 	blkcipher_walk_init(&walk, dst, src, nbytes);
 	err = blkcipher_walk_virt_block(desc, &walk, CHACHA20_BLOCK_SIZE);
+	desc->flags &= ~CRYPTO_TFM_REQ_MAY_SLEEP;
 
 	crypto_chacha20_init(state, crypto_blkcipher_ctx(desc->tfm), walk.iv);
 
Signature · 1 line
2.20.1.97.g81188d93c3-goog

Now queued up, thanks.

greg k-h