All of lore.kernel.org
 help / color / mirror / Atom feed
From: Andreas Dilger <adilger@dilger.ca>
To: Barret Rhoden <brho@google.com>
Cc: Theodore Ts'o <tytso@mit.edu>,
	syzbot+f584efa0ac7213c226b7@syzkaller.appspotmail.com,
	Jan Kara <jack@suse.cz>,
	stable@vger.kernel.org, linux-ext4 <linux-ext4@vger.kernel.org>,
	open list <linux-kernel@vger.kernel.org>
Subject: Re: [PATCH v2] ext4: fix use-after-free race with debug_want_extra_isize
Date: Thu, 18 Apr 2019 13:00:48 -0600	[thread overview]
Message-ID: <06E7E8DE-FA81-4764-B069-885C7963084E@dilger.ca> (raw)
In-Reply-To: <20190418155937.164947-1-brho@google.com>

[-- Attachment #1: Type: text/plain, Size: 3904 bytes --]

On Apr 18, 2019, at 9:59 AM, Barret Rhoden <brho@google.com> wrote:
> 
> When remounting with debug_want_extra_isize, we were not performing the
> same checks that we do during a normal mount.  That allowed us to set a
> value for s_want_extra_isize that reached outside the s_inode_size.
> 
> Reported-by: syzbot+f584efa0ac7213c226b7@syzkaller.appspotmail.com
> Reviewed-by: Jan Kara <jack@suse.cz>
> Signed-off-by: Barret Rhoden <brho@google.com>
> Cc: stable@vger.kernel.org # 4.14.111

Reviewed-by: Andreas Dilger <adilger@dilger.ca>

> ---
> 
> - Updated tags
> 
> Thanks for the review!
> 
> fs/ext4/super.c | 58 +++++++++++++++++++++++++++++--------------------
> 1 file changed, 34 insertions(+), 24 deletions(-)
> 
> diff --git a/fs/ext4/super.c b/fs/ext4/super.c
> index 6ed4eb81e674..184944d4d8d1 100644
> --- a/fs/ext4/super.c
> +++ b/fs/ext4/super.c
> @@ -3513,6 +3513,37 @@ int ext4_calculate_overhead(struct super_block *sb)
> 	return 0;
> }
> 
> +static void ext4_clamp_want_extra_isize(struct super_block *sb)
> +{
> +	struct ext4_sb_info *sbi = EXT4_SB(sb);
> +	struct ext4_super_block *es = sbi->s_es;
> +
> +	/* determine the minimum size of new large inodes, if present */
> +	if (sbi->s_inode_size > EXT4_GOOD_OLD_INODE_SIZE &&
> +	    sbi->s_want_extra_isize == 0) {
> +		sbi->s_want_extra_isize = sizeof(struct ext4_inode) -
> +						     EXT4_GOOD_OLD_INODE_SIZE;
> +		if (ext4_has_feature_extra_isize(sb)) {
> +			if (sbi->s_want_extra_isize <
> +			    le16_to_cpu(es->s_want_extra_isize))
> +				sbi->s_want_extra_isize =
> +					le16_to_cpu(es->s_want_extra_isize);
> +			if (sbi->s_want_extra_isize <
> +			    le16_to_cpu(es->s_min_extra_isize))
> +				sbi->s_want_extra_isize =
> +					le16_to_cpu(es->s_min_extra_isize);
> +		}
> +	}
> +	/* Check if enough inode space is available */
> +	if (EXT4_GOOD_OLD_INODE_SIZE + sbi->s_want_extra_isize >
> +							sbi->s_inode_size) {
> +		sbi->s_want_extra_isize = sizeof(struct ext4_inode) -
> +						       EXT4_GOOD_OLD_INODE_SIZE;
> +		ext4_msg(sb, KERN_INFO,
> +			 "required extra inode space not available");
> +	}
> +}
> +
> static void ext4_set_resv_clusters(struct super_block *sb)
> {
> 	ext4_fsblk_t resv_clusters;
> @@ -4387,30 +4418,7 @@ static int ext4_fill_super(struct super_block *sb, void *data, int silent)
> 	} else if (ret)
> 		goto failed_mount4a;
> 
> -	/* determine the minimum size of new large inodes, if present */
> -	if (sbi->s_inode_size > EXT4_GOOD_OLD_INODE_SIZE &&
> -	    sbi->s_want_extra_isize == 0) {
> -		sbi->s_want_extra_isize = sizeof(struct ext4_inode) -
> -						     EXT4_GOOD_OLD_INODE_SIZE;
> -		if (ext4_has_feature_extra_isize(sb)) {
> -			if (sbi->s_want_extra_isize <
> -			    le16_to_cpu(es->s_want_extra_isize))
> -				sbi->s_want_extra_isize =
> -					le16_to_cpu(es->s_want_extra_isize);
> -			if (sbi->s_want_extra_isize <
> -			    le16_to_cpu(es->s_min_extra_isize))
> -				sbi->s_want_extra_isize =
> -					le16_to_cpu(es->s_min_extra_isize);
> -		}
> -	}
> -	/* Check if enough inode space is available */
> -	if (EXT4_GOOD_OLD_INODE_SIZE + sbi->s_want_extra_isize >
> -							sbi->s_inode_size) {
> -		sbi->s_want_extra_isize = sizeof(struct ext4_inode) -
> -						       EXT4_GOOD_OLD_INODE_SIZE;
> -		ext4_msg(sb, KERN_INFO, "required extra inode space not"
> -			 "available");
> -	}
> +	ext4_clamp_want_extra_isize(sb);
> 
> 	ext4_set_resv_clusters(sb);
> 
> @@ -5194,6 +5202,8 @@ static int ext4_remount(struct super_block *sb, int *flags, char *data)
> 		goto restore_opts;
> 	}
> 
> +	ext4_clamp_want_extra_isize(sb);
> +
> 	if ((old_opts.s_mount_opt & EXT4_MOUNT_JOURNAL_CHECKSUM) ^
> 	    test_opt(sb, JOURNAL_CHECKSUM)) {
> 		ext4_msg(sb, KERN_ERR, "changing journal_checksum "
> --
> 2.21.0.392.gf8f6787159e-goog
> 


Cheers, Andreas






[-- Attachment #2: Message signed with OpenPGP --]
[-- Type: application/pgp-signature, Size: 873 bytes --]

  reply	other threads:[~2019-04-18 19:00 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-04-15 21:19 [PATCH] ext4: fix use-after-free race with debug_want_extra_isize Barret Rhoden
2019-04-18 11:55 ` Jan Kara
2019-04-18 15:59 ` [PATCH v2] " Barret Rhoden
2019-04-18 19:00   ` Andreas Dilger [this message]
2019-04-25 15:57   ` Theodore Ts'o

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=06E7E8DE-FA81-4764-B069-885C7963084E@dilger.ca \
    --to=adilger@dilger.ca \
    --cc=brho@google.com \
    --cc=jack@suse.cz \
    --cc=linux-ext4@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=stable@vger.kernel.org \
    --cc=syzbot+f584efa0ac7213c226b7@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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.