public inbox for linux-ext4@vger.kernel.org
 help / color / mirror / Atom feed
From: Eric Biggers <ebiggers@kernel.org>
To: "Norbert Kamiński" <norbert.kaminski@infogain.com>
Cc: tytso@mit.edu, adilger.kernel@dilger.ca,
	linux-ext4@vger.kernel.org, linux-kernel@vger.kernel.org,
	syzbot+aeb14e2539ffb6d21130@syzkaller.appspotmail.com
Subject: Re: [PATCH] fs/ext4: Prevent encryption/decryption of unaligned blocks in aes_encrypt
Date: Thu, 20 Jun 2024 21:00:49 -0700	[thread overview]
Message-ID: <20240621040049.GA4362@sol.localdomain> (raw)
In-Reply-To: <20240613134825.53238-1-norbert.kaminski@infogain.com>

On Thu, Jun 13, 2024 at 03:48:25PM +0200, Norbert Kamiński wrote:
> syzbot is reporting an uninitialized value in aes_encrypt(). The block
> cipher expects the bytes to encrypt or decrypt to be a multiple of the
> cipher’s block size. However, when ext4_write_begin() is called and new
> folios are allocated, they might not be aligned to the required block
> size.

While the length of file content blocks does need to be a multiple of
FSCRYPT_CONTENTS_ALIGNMENT bytes, this has nothing to do with the syzbot report
that this patch is trying to fix, and this is always the case in ext4 anyway.

> diff --git a/fs/ext4/inode.c b/fs/ext4/inode.c
> index 4bae9ccf5fe0..965f790a9d36 100644
> --- a/fs/ext4/inode.c
> +++ b/fs/ext4/inode.c
> @@ -1156,6 +1156,9 @@ static int ext4_write_begin(struct file *file, struct address_space *mapping,
>  	 * the folio (if needed) without using GFP_NOFS.
>  	 */
>  retry_grab:
> +	if (IS_ENABLED(CONFIG_FS_ENCRYPTION))
> +		mapping_set_gfp_mask(mapping,
> +				     mapping_gfp_mask(mapping) | __GFP_ZERO);
>  	folio = __filemap_get_folio(mapping, index, FGP_WRITEBEGIN,
>  					mapping_gfp_mask(mapping));
>  	if (IS_ERR(folio))
> @@ -2882,6 +2885,9 @@ static int ext4_da_write_begin(struct file *file, struct address_space *mapping,
>  	}
>  
>  retry:
> +	if (IS_ENABLED(CONFIG_FS_ENCRYPTION))
> +		mapping_set_gfp_mask(mapping,
> +				     mapping_gfp_mask(mapping) | __GFP_ZERO);

No, it's not acceptable to force all pagecache pages to be zeroized in ext4
without opting into init_on_alloc.  This is also the wrong place to set the
mapping's gfp_mask, as the mapping has already been activated.

What actually needs to be done is root-cause this bug and fix the underlying
cause.  It looks like somehow data got marked as valid in the pagecache without
being initialized, which is never supposed to happen.

- Eric

      reply	other threads:[~2024-06-21  4:00 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-06-13 13:48 [PATCH] fs/ext4: Prevent encryption/decryption of unaligned blocks in aes_encrypt Norbert Kamiński
2024-06-21  4:00 ` 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=20240621040049.GA4362@sol.localdomain \
    --to=ebiggers@kernel.org \
    --cc=adilger.kernel@dilger.ca \
    --cc=linux-ext4@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=norbert.kaminski@infogain.com \
    --cc=syzbot+aeb14e2539ffb6d21130@syzkaller.appspotmail.com \
    --cc=tytso@mit.edu \
    /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