public inbox for linux-crypto@vger.kernel.org
 help / color / mirror / Atom feed
From: Mikulas Patocka <mpatocka@redhat.com>
To: Eric Biggers <ebiggers@kernel.org>
Cc: Giovanni Cabiddu <giovanni.cabiddu@intel.com>,
	Fiona Trahe <fiona.trahe@intel.com>,
	herbert@gondor.apana.org.au, horia.geanta@nxp.com,
	pankaj.gupta@nxp.com, gaurav.jain@nxp.com, heinzm@redhat.com,
	snitzer@kernel.org, linux-kernel@vger.kernel.org,
	qat-linux@intel.com, iuliana.prodan@nxp.com, dm-devel@redhat.com,
	meenakshi.aggarwal@nxp.com, linux-crypto@vger.kernel.org,
	davem@davemloft.net, agk@redhat.com, V.Sethi@nxp.com
Subject: Re: [dm-devel] [PATCH 1/3] dm integrity: do not filter algos with CRYPTO_ALG_ALLOCATES_MEMORY
Date: Fri, 7 Jul 2023 12:25:42 +0200 (CEST)	[thread overview]
Message-ID: <6388bd2-8342-d08-5b4b-7a37e8f8b323@redhat.com> (raw)
In-Reply-To: <20230705201205.GA866@sol.localdomain>

Hi

If you allocate memory in crypto processing in dm-integrity, you risk the 
low-memory deadlock when swapping to dm-integrity.

I.e. the machine runs out of memory, it needs to swap out pages to free 
some memory, the swap-out bio goes to dm-integrity and dm-integrity calls 
the crypto API and tries to allocate more memory => deadlock.



On Wed, 5 Jul 2023, Eric Biggers wrote:

> On Wed, Jul 05, 2023 at 05:40:07PM +0100, Giovanni Cabiddu wrote:
> > The flag CRYPTO_ALG_ALLOCATES_MEMORY indicates that an algorithm might
> > allocate memory in the datapath and therefore sleep.
> > Dm-integrity is filtering out implementations of skcipher algorithms
> > that have this flag set. However, in the same function it does
> > allocations with GFP_KERNEL.

It's OK to use GFP_KERNEL in the device mapper target constructor (because 
at this point there is no I/O going to the device). But it's not OK to use 
it for individual bio processing.

> Which function is the above referring to?  The actual encryption/decryption
> happens in crypt_journal(), and I don't see any memory allocations there.
> 
> > As dm-integrity is re-entrant and capable of handling sleeps that could
> > occur during allocations with GFP_KERNEL, then it is also capable of
> > using skcipher algorithm implementations that have
> > CRYPTO_ALG_ALLOCATES_MEMORY set.
> > 
> > Remove the filtering of skcipher implementations with the flag
> > CRYPTO_ALG_ALLOCATES_MEMORY set.
> 
> What about the use of CRYPTO_ALG_ALLOCATES_MEMORY in get_mac()?
> 
> > 
> > Suggested-by: Herbert Xu <herbert@gondor.apana.org.au>
> > Link: https://lore.kernel.org/linux-crypto/ZILvtASXQKLG43y9@gondor.apana.org.au/
> > Signed-off-by: Giovanni Cabiddu <giovanni.cabiddu@intel.com>
> > Reviewed-by: Fiona Trahe <fiona.trahe@intel.com>
> 
> This needs:
> 
>     Fixes: a7a10bce8a04 ("dm integrity: don't use drivers that have CRYPTO_ALG_ALLOCATES_MEMORY")
>     Cc: stable@vger.kernel.org
> 
> But, are you 100% sure the explanation in commit a7a10bce8a04 was incorrect?
> 
> - Eric

Mikulas


  parent reply	other threads:[~2023-07-07 10:26 UTC|newest]

Thread overview: 14+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-07-05 16:40 [PATCH 0/3] crypto: adjust meaning of CRYPTO_ALG_ALLOCATES_MEMORY Giovanni Cabiddu
2023-07-05 16:40 ` [PATCH 1/3] dm integrity: do not filter algos with CRYPTO_ALG_ALLOCATES_MEMORY Giovanni Cabiddu
2023-07-05 20:12   ` Eric Biggers
2023-07-05 20:57     ` Giovanni Cabiddu
2023-07-05 21:57       ` Herbert Xu
2024-02-07  6:22         ` Meenakshi Aggarwal
2025-02-18  8:37           ` Herbert Xu
2025-02-20 10:18             ` Meenakshi Aggarwal
2024-07-04 10:39         ` Horia Geanta
2023-07-07 10:25     ` Mikulas Patocka [this message]
2023-07-05 16:40 ` [PATCH 2/3] crypto: api - adjust meaning of CRYPTO_ALG_ALLOCATES_MEMORY Giovanni Cabiddu
2023-07-05 20:18   ` Eric Biggers
2023-07-07 10:41     ` [dm-devel] " Mikulas Patocka
2023-07-05 16:40 ` [PATCH 3/3] crypto: qat - remove CRYPTO_ALG_ALLOCATES_MEMORY flag Giovanni Cabiddu

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=6388bd2-8342-d08-5b4b-7a37e8f8b323@redhat.com \
    --to=mpatocka@redhat.com \
    --cc=V.Sethi@nxp.com \
    --cc=agk@redhat.com \
    --cc=davem@davemloft.net \
    --cc=dm-devel@redhat.com \
    --cc=ebiggers@kernel.org \
    --cc=fiona.trahe@intel.com \
    --cc=gaurav.jain@nxp.com \
    --cc=giovanni.cabiddu@intel.com \
    --cc=heinzm@redhat.com \
    --cc=herbert@gondor.apana.org.au \
    --cc=horia.geanta@nxp.com \
    --cc=iuliana.prodan@nxp.com \
    --cc=linux-crypto@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=meenakshi.aggarwal@nxp.com \
    --cc=pankaj.gupta@nxp.com \
    --cc=qat-linux@intel.com \
    --cc=snitzer@kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox