From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 3E0E6C433F5 for ; Wed, 19 Jan 2022 06:58:57 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1350228AbiASG6y (ORCPT ); Wed, 19 Jan 2022 01:58:54 -0500 Received: from helcar.hmeau.com ([216.24.177.18]:59680 "EHLO fornost.hmeau.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1345647AbiASG6x (ORCPT ); Wed, 19 Jan 2022 01:58:53 -0500 Received: from gwarestrin.arnor.me.apana.org.au ([192.168.103.7]) by fornost.hmeau.com with smtp (Exim 4.92 #5 (Debian)) id 1nA4vY-0008Th-0i; Wed, 19 Jan 2022 17:58:41 +1100 Received: by gwarestrin.arnor.me.apana.org.au (sSMTP sendmail emulation); Wed, 19 Jan 2022 17:58:40 +1100 Date: Wed, 19 Jan 2022 17:58:40 +1100 From: Herbert Xu To: Corentin Labbe Cc: davem@davemloft.net, linux-arm-kernel@lists.infradead.org, netdev@vger.kernel.org, linux-kernel@vger.kernel.org, Linux Crypto Mailing List Subject: [PATCH] crypto: authenc - Fix sleep in atomic context in decrypt_tail Message-ID: References: MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: Precedence: bulk List-ID: X-Mailing-List: linux-crypto@vger.kernel.org On Tue, Jan 18, 2022 at 08:52:53AM +0100, Corentin Labbe wrote: > > With my patch, I got: > [ 38.515668] BUG: sleeping function called from invalid context at crypto/skcipher.c:482 > [ 38.523708] in_atomic(): 1, irqs_disabled(): 0, non_block: 0, pid: 84, name: 1c15000.crypto- > [ 38.532176] preempt_count: 200, expected: 0 > [ 38.536381] CPU: 6 PID: 84 Comm: 1c15000.crypto- Not tainted 5.16.0-next-20220115-00124-g13473e8fac33-dirty #116 > [ 38.546551] Hardware name: Allwinner A83t board > [ 38.551100] unwind_backtrace from show_stack+0x10/0x14 > [ 38.556358] show_stack from dump_stack_lvl+0x40/0x4c > [ 38.561428] dump_stack_lvl from __might_resched+0x118/0x154 > [ 38.567107] __might_resched from skcipher_walk_virt+0xe8/0xec > [ 38.572955] skcipher_walk_virt from crypto_cbc_decrypt+0x2c/0x170 > [ 38.579147] crypto_cbc_decrypt from crypto_skcipher_decrypt+0x38/0x5c > [ 38.585680] crypto_skcipher_decrypt from authenc_verify_ahash_done+0x18/0x34 > [ 38.592825] authenc_verify_ahash_done from crypto_finalize_request+0x6c/0xe4 > [ 38.599974] crypto_finalize_request from sun8i_ss_hash_run+0x73c/0xb98 > [ 38.606602] sun8i_ss_hash_run from crypto_pump_work+0x1a8/0x330 > [ 38.612616] crypto_pump_work from kthread_worker_fn+0xa8/0x1c4 > [ 38.618550] kthread_worker_fn from kthread+0xf0/0x110 > [ 38.623701] kthread from ret_from_fork+0x14/0x2c > [ 38.628414] Exception stack(0xc2247fb0 to 0xc2247ff8) > [ 38.633468] 7fa0: 00000000 00000000 00000000 00000000 > [ 38.641640] 7fc0: 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000 > [ 38.649809] 7fe0:i 00000000 00000000 00000000 00000000 00000013 00000000 > > This is when testing hmac(sha1) on my crypto driver sun8i-ss and crypto testing authenc(hmac-sha1-sun8i-ss,cbc(aes-generic)). > > Do you have any idea to better fix my issue ? This backtrace is caused by a bug in authenc: ---8<--- The function crypto_authenc_decrypt_tail discards its flags argument and always relies on the flags from the original request when starting its sub-request. This is clearly wrong as it may cause the SLEEPABLE flag to be set when it shouldn't. Fixes: 92d95ba91772 ("crypto: authenc - Convert to new AEAD interface") Reported-by: Corentin Labbe Signed-off-by: Herbert Xu diff --git a/crypto/authenc.c b/crypto/authenc.c index 670bf1a01d00..17f674a7cdff 100644 --- a/crypto/authenc.c +++ b/crypto/authenc.c @@ -253,7 +253,7 @@ static int crypto_authenc_decrypt_tail(struct aead_request *req, dst = scatterwalk_ffwd(areq_ctx->dst, req->dst, req->assoclen); skcipher_request_set_tfm(skreq, ctx->enc); - skcipher_request_set_callback(skreq, aead_request_flags(req), + skcipher_request_set_callback(skreq, flags, req->base.complete, req->base.data); skcipher_request_set_crypt(skreq, src, dst, req->cryptlen - authsize, req->iv); -- Email: Herbert Xu Home Page: http://gondor.apana.org.au/~herbert/ PGP Key: http://gondor.apana.org.au/~herbert/pubkey.txt From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id C61E2C433EF for ; Wed, 19 Jan 2022 07:00:45 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:In-Reply-To:MIME-Version:References: Message-ID:Subject:Cc:To:From:Date:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=Gl6ZCCknF9LvC2ApLwRShXPBnPlUqfZQ8c2isdXwG4A=; b=eHk7V3a5q6/cGV n8RaT54kTT3DjqMN73bZQoI5pVm90Hbh4UFw4U35wwp37suYiCvZkrJbl8Xx1Yu7jPPSVxvWTF007 SZY0CzOp7mtmSX8HU9LOVUNoJNjbUKRPz6SqquhPtk8b2K40RTgiTaQvp3h2fv/yzzduS6w1H9btI F0zvMSYP5iI3ZSC4uuz63Jq069mbn/PLM3+TADJwY/GIO4Sz3iO/vLq2g5wn7h+ZiFbPLSzYLN2dq hgwwZdHz6FfvxddOBtT5GnxlfKMqtynpOte9tEsAcdnS7TK9U8CPguFxJirPDohA/orxASpsC1qFY 01BQ+UAKBY3BDoI9dxdw==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1nA4vr-0042pk-6B; Wed, 19 Jan 2022 06:58:59 +0000 Received: from helcar.hmeau.com ([216.24.177.18] helo=fornost.hmeau.com) by bombadil.infradead.org with esmtps (Exim 4.94.2 #2 (Red Hat Linux)) id 1nA4vm-0042p1-8J for linux-arm-kernel@lists.infradead.org; Wed, 19 Jan 2022 06:58:57 +0000 Received: from gwarestrin.arnor.me.apana.org.au ([192.168.103.7]) by fornost.hmeau.com with smtp (Exim 4.92 #5 (Debian)) id 1nA4vY-0008Th-0i; Wed, 19 Jan 2022 17:58:41 +1100 Received: by gwarestrin.arnor.me.apana.org.au (sSMTP sendmail emulation); Wed, 19 Jan 2022 17:58:40 +1100 Date: Wed, 19 Jan 2022 17:58:40 +1100 From: Herbert Xu To: Corentin Labbe Cc: davem@davemloft.net, linux-arm-kernel@lists.infradead.org, netdev@vger.kernel.org, linux-kernel@vger.kernel.org, Linux Crypto Mailing List Subject: [PATCH] crypto: authenc - Fix sleep in atomic context in decrypt_tail Message-ID: References: MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20220118_225855_309839_998A4B1D X-CRM114-Status: GOOD ( 13.97 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org On Tue, Jan 18, 2022 at 08:52:53AM +0100, Corentin Labbe wrote: > > With my patch, I got: > [ 38.515668] BUG: sleeping function called from invalid context at crypto/skcipher.c:482 > [ 38.523708] in_atomic(): 1, irqs_disabled(): 0, non_block: 0, pid: 84, name: 1c15000.crypto- > [ 38.532176] preempt_count: 200, expected: 0 > [ 38.536381] CPU: 6 PID: 84 Comm: 1c15000.crypto- Not tainted 5.16.0-next-20220115-00124-g13473e8fac33-dirty #116 > [ 38.546551] Hardware name: Allwinner A83t board > [ 38.551100] unwind_backtrace from show_stack+0x10/0x14 > [ 38.556358] show_stack from dump_stack_lvl+0x40/0x4c > [ 38.561428] dump_stack_lvl from __might_resched+0x118/0x154 > [ 38.567107] __might_resched from skcipher_walk_virt+0xe8/0xec > [ 38.572955] skcipher_walk_virt from crypto_cbc_decrypt+0x2c/0x170 > [ 38.579147] crypto_cbc_decrypt from crypto_skcipher_decrypt+0x38/0x5c > [ 38.585680] crypto_skcipher_decrypt from authenc_verify_ahash_done+0x18/0x34 > [ 38.592825] authenc_verify_ahash_done from crypto_finalize_request+0x6c/0xe4 > [ 38.599974] crypto_finalize_request from sun8i_ss_hash_run+0x73c/0xb98 > [ 38.606602] sun8i_ss_hash_run from crypto_pump_work+0x1a8/0x330 > [ 38.612616] crypto_pump_work from kthread_worker_fn+0xa8/0x1c4 > [ 38.618550] kthread_worker_fn from kthread+0xf0/0x110 > [ 38.623701] kthread from ret_from_fork+0x14/0x2c > [ 38.628414] Exception stack(0xc2247fb0 to 0xc2247ff8) > [ 38.633468] 7fa0: 00000000 00000000 00000000 00000000 > [ 38.641640] 7fc0: 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000 > [ 38.649809] 7fe0:i 00000000 00000000 00000000 00000000 00000013 00000000 > > This is when testing hmac(sha1) on my crypto driver sun8i-ss and crypto testing authenc(hmac-sha1-sun8i-ss,cbc(aes-generic)). > > Do you have any idea to better fix my issue ? This backtrace is caused by a bug in authenc: ---8<--- The function crypto_authenc_decrypt_tail discards its flags argument and always relies on the flags from the original request when starting its sub-request. This is clearly wrong as it may cause the SLEEPABLE flag to be set when it shouldn't. Fixes: 92d95ba91772 ("crypto: authenc - Convert to new AEAD interface") Reported-by: Corentin Labbe Signed-off-by: Herbert Xu diff --git a/crypto/authenc.c b/crypto/authenc.c index 670bf1a01d00..17f674a7cdff 100644 --- a/crypto/authenc.c +++ b/crypto/authenc.c @@ -253,7 +253,7 @@ static int crypto_authenc_decrypt_tail(struct aead_request *req, dst = scatterwalk_ffwd(areq_ctx->dst, req->dst, req->assoclen); skcipher_request_set_tfm(skreq, ctx->enc); - skcipher_request_set_callback(skreq, aead_request_flags(req), + skcipher_request_set_callback(skreq, flags, req->base.complete, req->base.data); skcipher_request_set_crypt(skreq, src, dst, req->cryptlen - authsize, req->iv); -- Email: Herbert Xu Home Page: http://gondor.apana.org.au/~herbert/ PGP Key: http://gondor.apana.org.au/~herbert/pubkey.txt _______________________________________________ linux-arm-kernel mailing list linux-arm-kernel@lists.infradead.org http://lists.infradead.org/mailman/listinfo/linux-arm-kernel