Linux-FSCrypt Archive on lore.kernel.org
 help / color / Atom feed
From: Eric Biggers <ebiggers@kernel.org>
To: linux-fscrypt@vger.kernel.org
Cc: linux-fsdevel@vger.kernel.org,
	Satya Tangirala <satyat@google.com>,
	Dave Chinner <david@fromorbit.com>
Subject: Re: [PATCH] fscrypt: don't load ->i_crypt_info before it's known to be valid
Date: Thu, 30 Jul 2020 14:28:14 -0700
Message-ID: <20200730212814.GB1074@sol.localdomain> (raw)
In-Reply-To: <20200727174158.121456-1-ebiggers@kernel.org>

On Mon, Jul 27, 2020 at 10:41:58AM -0700, Eric Biggers wrote:
> From: Eric Biggers <ebiggers@google.com>
> 
> In fscrypt_set_bio_crypt_ctx(), ->i_crypt_info isn't known to be
> non-NULL until we check fscrypt_inode_uses_inline_crypto().  So, load
> ->i_crypt_info after the check rather than before.  This makes no
> difference currently, but it prevents people from introducing bugs where
> the pointer is dereferenced when it may be NULL.
> 
> Suggested-by: Dave Chinner <david@fromorbit.com>
> Cc: Satya Tangirala <satyat@google.com>
> Signed-off-by: Eric Biggers <ebiggers@google.com>
> ---
>  fs/crypto/inline_crypt.c | 3 ++-
>  1 file changed, 2 insertions(+), 1 deletion(-)
> 
> diff --git a/fs/crypto/inline_crypt.c b/fs/crypto/inline_crypt.c
> index dfb06375099ae..b6b8574caa13c 100644
> --- a/fs/crypto/inline_crypt.c
> +++ b/fs/crypto/inline_crypt.c
> @@ -244,11 +244,12 @@ static void fscrypt_generate_dun(const struct fscrypt_info *ci, u64 lblk_num,
>  void fscrypt_set_bio_crypt_ctx(struct bio *bio, const struct inode *inode,
>  			       u64 first_lblk, gfp_t gfp_mask)
>  {
> -	const struct fscrypt_info *ci = inode->i_crypt_info;
> +	const struct fscrypt_info *ci;
>  	u64 dun[BLK_CRYPTO_DUN_ARRAY_SIZE];
>  
>  	if (!fscrypt_inode_uses_inline_crypto(inode))
>  		return;
> +	ci = inode->i_crypt_info;
>  
>  	fscrypt_generate_dun(ci, first_lblk, dun);
>  	bio_crypt_set_ctx(bio, &ci->ci_enc_key.blk_key->base, dun, gfp_mask);

Applied to fscrypt.git#master for 5.9.

- Eric

      reply index

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-07-27 17:41 Eric Biggers
2020-07-30 21:28 ` Eric Biggers [this message]

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=20200730212814.GB1074@sol.localdomain \
    --to=ebiggers@kernel.org \
    --cc=david@fromorbit.com \
    --cc=linux-fscrypt@vger.kernel.org \
    --cc=linux-fsdevel@vger.kernel.org \
    --cc=satyat@google.com \
    /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

Linux-FSCrypt Archive on lore.kernel.org

Archives are clonable:
	git clone --mirror https://lkml.kernel.org/linux-fscrypt/0 linux-fscrypt/git/0.git

	# If you have public-inbox 1.1+ installed, you may
	# initialize and index your mirror using the following commands:
	public-inbox-init -V2 linux-fscrypt linux-fscrypt/ https://lkml.kernel.org/linux-fscrypt \
		linux-fscrypt@vger.kernel.org
	public-inbox-index linux-fscrypt

Example config snippet for mirrors

Newsgroup available over NNTP:
	nntp://nntp.lore.kernel.org/org.kernel.vger.linux-fscrypt


AGPL code for this site: git clone https://public-inbox.org/public-inbox.git