lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  linux-cve-announce  PHC 
Open Source and information security mailing list archives
 
Hash Suite: Windows password security audit tool. GUI, reports in PDF.
[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <ZGz9k3jnVqiO20a2@redhat.com>
Date:   Tue, 23 May 2023 13:53:23 -0400
From:   Mike Snitzer <snitzer@...nel.org>
To:     Duoming Zhou <duoming@....edu.cn>
Cc:     linux-kernel@...r.kernel.org, agk@...hat.com, dm-devel@...hat.com,
        Ignat Korchagin <ignat@...udflare.com>
Subject: Re: dm crypt: fix sleep-in-atomic-context bug in
 kcryptd_crypt_tasklet

On Tue, May 23 2023 at  3:58P -0400,
Duoming Zhou <duoming@....edu.cn> wrote:

> In order to improve the IO performance of the dm-crypt
> implementation, the commit 39d42fa96ba1 ("dm crypt:
> add flags to optionally bypass kcryptd workqueues")
> adds tasklet to do the crypto operations.
> 
> The tasklet callback function kcryptd_crypt_tasklet()
> calls kcryptd_crypt() which is an original workqueue
> callback function that may sleep. As a result, the
> sleep-in-atomic-context bug may happen. The process
> is shown below.
> 
>    (atomic context)
> kcryptd_crypt_tasklet()
>   kcryptd_crypt()
>     kcryptd_crypt_write_convert()
>       wait_for_completion() //may sleep
> 
> The wait_for_completion() is a function that may sleep.
> In order to mitigate the bug, this patch changes
> wait_for_completion() to try_wait_for_completion().
> 
> Fixes: 39d42fa96ba1 ("dm crypt: add flags to optionally bypass kcryptd workqueues")
> Signed-off-by: Duoming Zhou <duoming@....edu.cn>
> ---
>  drivers/md/dm-crypt.c | 3 ++-
>  1 file changed, 2 insertions(+), 1 deletion(-)
> 
> diff --git a/drivers/md/dm-crypt.c b/drivers/md/dm-crypt.c
> index 8b47b913ee8..5e2b2463d87 100644
> --- a/drivers/md/dm-crypt.c
> +++ b/drivers/md/dm-crypt.c
> @@ -2085,7 +2085,8 @@ static void kcryptd_crypt_write_convert(struct dm_crypt_io *io)
>  	crypt_finished = atomic_dec_and_test(&ctx->cc_pending);
>  	if (!crypt_finished && kcryptd_crypt_write_inline(cc, ctx)) {
>  		/* Wait for completion signaled by kcryptd_async_done() */
> -		wait_for_completion(&ctx->restart);
> +		while (!try_wait_for_completion(&ctx->restart))
> +			;
>  		crypt_finished = 1;
>  	}
>  
> -- 
> 2.17.1
> 

Cc'ing Ignat for closer review.

But wasn't this already addressed with this commit?:
8abec36d1274 dm crypt: do not wait for backlogged crypto request completion in softirq

Mike

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ