Received: by 2002:a05:6902:102b:0:0:0:0 with SMTP id x11csp2625075ybt; Tue, 16 Jun 2020 10:37:19 -0700 (PDT) X-Google-Smtp-Source: ABdhPJw6UWB9xK8a1GL8BdA1skXsU19gI5IT2nttawJIhP1PvIF9jiFaw0QpCDdI2YX5xopI1y5E X-Received: by 2002:a50:cd17:: with SMTP id z23mr3531211edi.326.1592329039802; Tue, 16 Jun 2020 10:37:19 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1592329039; cv=none; d=google.com; s=arc-20160816; b=nxMgj7Rb0Aq19BIjpfZUq/h0cCSCHL3qVzbr0NxA+8EKpBGKDgQh4x5jHNKA8/Xl2h oWPu+drwiLB0rOzCh8rrqIWYpBoxoGy3TbI/RrXHMK5h8hxCWy+zkYEzYiGiHRLiyV4/ PM8agD5wbAym58shFpBbdc918DRBr9XddtCgX+WVxNKyKdY4sCgnVkNjEwxDvzFIAZZK WuP9PynD7gDAhD4K5gRNePl/CHi/Nb1ceRetVgoGVfZ/2Lp2rYIsZL5R7XKgkDDZ5/z7 p+/XP4+G2E5kkvvCIvxO7Noe7zk6SbBHO/kVD6+Ac+cvWxj7XjdKVDTq6BLgfSJxZioK 7E8A== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:in-reply-to:content-disposition :mime-version:references:message-id:subject:cc:to:from:date :dkim-signature; bh=G2Nl5aHSooiiZFkmVJWvKRYuBPiU/0XIyvyn2/Rrfl0=; b=yOBhfuC/uejrHHKS2+D116jrPrM/3r5PSVgYBv/uOUp3rKCwOUl0JrrcfgqaNPTSkt cDBiyOAm25KMouqLWy3BUc2uFfs3Irqvc7iuK2p6KIANHmnnMt1X3Ac/yvkVvASRv1U7 qYP+dCCE+KNxh68ZsoESNeEQM4skx3j2pQXVXE6VF35k89ticzxlUf9S8QpfQtgXId+i mTEk5R/DLapFCA0r5uepN4qjBuWrPh6ZL/gbIIVFCjswo0gynpdT1SKoPUurhfvl7Uzk o4gfviibyRbBhwFAcMwuQWDHnUbJQ/8sYlLgz3EYho60WxTzxVziWsXNQd2GxrZgxBsA Rr8Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=pcMIyzy7; spf=pass (google.com: domain of linux-crypto-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-crypto-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id d5si11812913ejw.224.2020.06.16.10.36.47; Tue, 16 Jun 2020 10:37:19 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-crypto-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=pcMIyzy7; spf=pass (google.com: domain of linux-crypto-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-crypto-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1730411AbgFPRgW (ORCPT + 99 others); Tue, 16 Jun 2020 13:36:22 -0400 Received: from mail.kernel.org ([198.145.29.99]:50100 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729113AbgFPRgW (ORCPT ); Tue, 16 Jun 2020 13:36:22 -0400 Received: from gmail.com (unknown [104.132.1.76]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id 71CD52078D; Tue, 16 Jun 2020 17:36:21 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1592328981; bh=nOOOW65oSsiGI9JHZ8r9JSIVhwhnVyVo7lW/X1wgbkY=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=pcMIyzy76eQ6NWbIJFiv9deGEHOkhopgx105LCk9GLPsso5fB2vYzvHJbaylXq2of ABqk7+wJ/RfTOL4ifLg6pZiGKkbO8eJRcxjIhKsia2xPOkkUrBNt2uc4BnKqHa0a0w /BFMLqJWCB0wj/7nuI1QDu6PRV4uk+lSDukO0ClE= Date: Tue, 16 Jun 2020 10:36:20 -0700 From: Eric Biggers To: Mikulas Patocka Cc: Herbert Xu , Mike Snitzer , linux-kernel@vger.kernel.org, dm-devel@redhat.com, linux-crypto@vger.kernel.org, "David S. Miller" , Milan Broz Subject: Re: [dm-devel] [PATCH 1/4] crypto: introduce CRYPTO_ALG_ALLOCATES_MEMORY Message-ID: <20200616173620.GA207319@gmail.com> References: <20200610010450.GA6449@gondor.apana.org.au> <20200610121106.GA23137@gondor.apana.org.au> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: Sender: linux-crypto-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-crypto@vger.kernel.org On Tue, Jun 16, 2020 at 11:01:31AM -0400, Mikulas Patocka wrote: > Introduce a new flag CRYPTO_ALG_ALLOCATES_MEMORY and modify dm-crypt, so > that it uses only drivers without this flag. > > If the flag is set, then the crypto driver allocates memory in its request > routine. Such drivers are not suitable for disk encryption because > GFP_ATOMIC allocation can fail anytime (causing random I/O errors) and > GFP_KERNEL allocation can recurse into the block layer, causing a > deadlock. > > Signed-off-by: Mikulas Patocka > > Index: linux-2.6/include/linux/crypto.h > =================================================================== > --- linux-2.6.orig/include/linux/crypto.h > +++ linux-2.6/include/linux/crypto.h > @@ -97,9 +97,15 @@ > #define CRYPTO_ALG_OPTIONAL_KEY 0x00004000 > > /* > + * The driver is allocating emmory in its encrypt or decrypt callback, > + * so it should not be used to encrypt block devices. > + */ "is allocating emmory" => "may allocate memory" "so it should not be used to encrypt block devices" => "so it shouldn't be used in cases where memory allocation failures aren't acceptable, such as during block device encryption". Also, which types of algorithms does this flag apply to? E.g. if it applies to hash algorithms too, it's not sufficient to say "encrypt or decrypt callback". How about: /* * The driver may allocate memory during request processing, so it shouldn't be * used in cases where memory allocation failures aren't acceptable, such as * during block device encryption. */ > +#define CRYPTO_ALG_ALLOCATES_MEMORY 0x00008000 > + > +/* > * Don't trigger module loading > */ > -#define CRYPTO_NOLOAD 0x00008000 > +#define CRYPTO_NOLOAD 0x00010000 > > /* > * Transform masks and values (for crt_flags). > Index: linux-2.6/drivers/md/dm-crypt.c > =================================================================== This would better belong as two separate patches: one to introduce CRYPTO_ALG_ALLOCATES_MEMORY, and one to make dm-crypt use it. > --- linux-2.6.orig/drivers/md/dm-crypt.c > +++ linux-2.6/drivers/md/dm-crypt.c > @@ -419,7 +419,7 @@ static int crypt_iv_lmk_ctr(struct crypt > return -EINVAL; > } > > - lmk->hash_tfm = crypto_alloc_shash("md5", 0, 0); > + lmk->hash_tfm = crypto_alloc_shash("md5", 0, CRYPTO_ALG_ALLOCATES_MEMORY); > if (IS_ERR(lmk->hash_tfm)) { > ti->error = "Error initializing LMK hash"; > return PTR_ERR(lmk->hash_tfm); > @@ -581,7 +581,7 @@ static int crypt_iv_tcw_ctr(struct crypt > return -EINVAL; > } > > - tcw->crc32_tfm = crypto_alloc_shash("crc32", 0, 0); > + tcw->crc32_tfm = crypto_alloc_shash("crc32", 0, CRYPTO_ALG_ALLOCATES_MEMORY); > if (IS_ERR(tcw->crc32_tfm)) { > ti->error = "Error initializing CRC32 in TCW"; > return PTR_ERR(tcw->crc32_tfm); > @@ -768,7 +768,7 @@ static int crypt_iv_elephant_ctr(struct > struct iv_elephant_private *elephant = &cc->iv_gen_private.elephant; > int r; > > - elephant->tfm = crypto_alloc_skcipher("ecb(aes)", 0, 0); > + elephant->tfm = crypto_alloc_skcipher("ecb(aes)", 0, CRYPTO_ALG_ALLOCATES_MEMORY); > if (IS_ERR(elephant->tfm)) { > r = PTR_ERR(elephant->tfm); > elephant->tfm = NULL; > @@ -2088,7 +2088,7 @@ static int crypt_alloc_tfms_skcipher(str > return -ENOMEM; > > for (i = 0; i < cc->tfms_count; i++) { > - cc->cipher_tfm.tfms[i] = crypto_alloc_skcipher(ciphermode, 0, 0); > + cc->cipher_tfm.tfms[i] = crypto_alloc_skcipher(ciphermode, 0, CRYPTO_ALG_ALLOCATES_MEMORY); Despite the recent relaxation in rules, the preferred length of a line is still 80 columns. - Eric