public inbox for linux-ext4@vger.kernel.org
 help / color / mirror / Atom feed
From: "Theodore Ts'o" <tytso@mit.edu>
To: Jan Kara <jack@suse.cz>
Cc: linux-ext4@vger.kernel.org, Dmitry Vyukov <dvyukov@google.com>,
	syzbot+4a03518df1e31b537066@syzkaller.appspotmail.com
Subject: Re: [PATCH] ext4: Fix data races when using cached status extents
Date: Wed, 3 May 2023 22:41:57 -0400	[thread overview]
Message-ID: <20230504024157.GB650928@mit.edu> (raw)
In-Reply-To: <20230503182128.14115-1-jack@suse.cz>

On Wed, May 03, 2023 at 08:21:28PM +0200, Jan Kara wrote:
> When using cached extent stored in extent status tree in tree->cache_es
> another process holding ei->i_es_lock for reading can be racing with us
> setting new value of tree->cache_es. If the compiler would decide to
> refetch tree->cache_es at an unfortunate moment, it could result in a
> bogus in_range() check. Fix the possible race by using READ_ONCE() when
> using tree->cache_es only under ei->i_es_lock for reading.
> 
> Reported-by: syzbot+4a03518df1e31b537066@syzkaller.appspotmail.com
> Link: https://lore.kernel.org/all/000000000000d3b33905fa0fd4a6@google.com
> Suggested-by: Dmitry Vyukov <dvyukov@google.com>
> Signed-off-by: Jan Kara <jack@suse.cz>

Don't we also need a WRITE_ONCE here?

diff --git a/fs/ext4/extents_status.c b/fs/ext4/extents_status.c
index 7bc221038c6c..4694582cf255 100644
--- a/fs/ext4/extents_status.c
+++ b/fs/ext4/extents_status.c
@@ -293,7 +293,7 @@ static void __es_find_extent_range(struct inode *inode,
 	}
 
 	if (es1 && matching_fn(es1)) {
-		tree->cache_es = es1;
+		WRITE_ONCE(tree->cache_es, es1);
 		es->es_lblk = es1->es_lblk;
 		es->es_len = es1->es_len;
 		es->es_pblk = es1->es_pblk;

					- Ted

  reply	other threads:[~2023-05-04  2:42 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-05-03 18:21 [PATCH] ext4: Fix data races when using cached status extents Jan Kara
2023-05-04  2:41 ` Theodore Ts'o [this message]
2023-05-04 10:50   ` Jan Kara

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=20230504024157.GB650928@mit.edu \
    --to=tytso@mit.edu \
    --cc=dvyukov@google.com \
    --cc=jack@suse.cz \
    --cc=linux-ext4@vger.kernel.org \
    --cc=syzbot+4a03518df1e31b537066@syzkaller.appspotmail.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
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