linux-ext4.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Theodore Ts'o <tytso@mit.edu>
To: Dmitry Monakhov <dmonakhov@openvz.org>
Cc: linux-ext4@vger.kernel.org, cmm@us.ibm.com
Subject: Re: [PATCH 2/2] ext4: fix potential use after free issue while fsresize
Date: Tue, 25 Nov 2014 13:27:22 -0500	[thread overview]
Message-ID: <20141125182722.GE11648@thunk.org> (raw)
In-Reply-To: <1415958040-4393-2-git-send-email-dmonakhov@openvz.org>

On Fri, Nov 14, 2014 at 01:40:40PM +0400, Dmitry Monakhov wrote:
> We need some sort of synchronization while updating ->s_group_desc because there
> are a lot of users which can access old ->s_group_desc array after it was released.
> It is reasonable to use lightweight seqcount_t here instead of RCU.
> 
> Signed-off-by: Dmitry Monakhov <dmonakhov@openvz.org>

I'm curious --- under what circumstances did you manage to hit this,
or was this something that you noticed?

> +	do {
> +		seq = read_seqcount_begin(&sbi->s_group_desc_seq);
> +		gd_bh = sbi->s_group_desc[group_desc];
> +	} while (unlikely(read_seqcount_retry(&sbi->s_group_desc_seq, seq)));

The problem is that s_group_desc is allocated using ext4_kvmalloc(),
which means it's possible that it was allocated using vmalloc().
Which means that it is possible (although unlikely) that the old
s_group_desc address could become invalidated after the call to
ext4_kvfree(o_group_desc).

This will only happen on 32-bit platforms if we get unlucky and the
kmap region gets recycled right after the vfree(); but we would only
see the bug in practice if the memory gets kfree'ed gets reused
immeidately afterwards, and we've been living with this with ext3 for
a long time.  Don't get me wrong; I'm not saying we should ignore this
bug, since I certainly agree with you that it is truly a bug.  But if
we are going to fix it, we should probably fix it all the way, which I
suspect means we may have to use RCU here.

OTOH, if you are hitting this in live production workloads, then we
can do the partial fix now, and then fix it all the way up later.  Is
the RCU mechanism really going to be that ugly?  It's not like we are
resizing all the time, so we don't need to worry about it being
heavyweight from a performance point of view, no?

	    	   	       	     	- Ted

  reply	other threads:[~2014-11-25 18:27 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2014-11-14  9:40 [PATCH 1/2] ext4: cleanup GFP flags inside resize path V2 Dmitry Monakhov
2014-11-14  9:40 ` [PATCH 2/2] ext4: fix potential use after free issue while fsresize Dmitry Monakhov
2014-11-25 18:27   ` Theodore Ts'o [this message]
2014-11-27 13:06     ` Dmitry Monakhov
2014-11-24 12:55 ` [PATCH 1/2] ext4: cleanup GFP flags inside resize path V2 Dmitry Monakhov
2014-11-25 18:08 ` Theodore Ts'o
  -- strict thread matches above, loose matches on Subject: below --
2014-11-09 16:37 [PATCH 1/2] ext4: cleanup GFP flags inside resize path Dmitry Monakhov
2014-11-09 16:37 ` [PATCH 2/2] ext4: fix potential use after free issue while fsresize Dmitry Monakhov

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=20141125182722.GE11648@thunk.org \
    --to=tytso@mit.edu \
    --cc=cmm@us.ibm.com \
    --cc=dmonakhov@openvz.org \
    --cc=linux-ext4@vger.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;
as well as URLs for NNTP newsgroup(s).