• Eric Biggers's avatar
    crypto: chacha20poly1305 - fix atomic sleep when using async algorithm · 16102fb9
    Eric Biggers authored
    commit 7545b6c2 upstream.
    
    Clear the CRYPTO_TFM_REQ_MAY_SLEEP flag when the chacha20poly1305
    operation is being continued from an async completion callback, since
    sleeping may not be allowed in that context.
    
    This is basically the same bug that was recently fixed in the xts and
    lrw templates.  But, it's always been broken in chacha20poly1305 too.
    This was found using syzkaller in combination with the updated crypto
    self-tests which actually test the MAY_SLEEP flag now.
    
    Reproducer:
    
        python -c 'import socket; socket.socket(socket.AF_ALG, 5, 0).bind(
        	       ("aead", "rfc7539(cryptd(chacha20-generic),poly1305-generic)"))'
    
    Kernel output:
    
        BUG: sleeping function called from invalid context at include/crypto/algapi.h:426
        in_atomic(): 1, irqs_disabled(): 0, pid: 1001, name: kworker/2:2
        [...]
        CPU: 2 PID: 1001 Comm: kworker/2:2 Not tainted 5.2.0-rc2 #5
        Hardware name: QEMU Standard PC...
    16102fb9
chacha20poly1305.c 19.6 KB