]> www.infradead.org Git - users/jedix/linux-maple.git/commit
ext4: fix bh->b_state corruption
authorJan Kara <jack@suse.com>
Fri, 19 Feb 2016 05:18:25 +0000 (00:18 -0500)
committerChuck Anderson <chuck.anderson@oracle.com>
Thu, 26 May 2016 22:45:50 +0000 (15:45 -0700)
commit174a056951dbd5110dfcf6a0c474dc802318823f
treed164e9649504ca60f7a03dd0a114a5eb5db3a6cb
parent5f187344963c1878901b6482e14ca53d4cb73b05
ext4: fix bh->b_state corruption

Orabug: 23331022

[ Upstream commit ed8ad83808f009ade97ebbf6519bc3a97fefbc0c ]

ext4 can update bh->b_state non-atomically in _ext4_get_block() and
ext4_da_get_block_prep(). Usually this is fine since bh is just a
temporary storage for mapping information on stack but in some cases it
can be fully living bh attached to a page. In such case non-atomic
update of bh->b_state can race with an atomic update which then gets
lost. Usually when we are mapping bh and thus updating bh->b_state
non-atomically, nobody else touches the bh and so things work out fine
but there is one case to especially worry about: ext4_finish_bio() uses
BH_Uptodate_Lock on the first bh in the page to synchronize handling of
PageWriteback state. So when blocksize < pagesize, we can be atomically
modifying bh->b_state of a buffer that actually isn't under IO and thus
can race e.g. with delalloc trying to map that buffer. The result is
that we can mistakenly set / clear BH_Uptodate_Lock bit resulting in the
corruption of PageWriteback state or missed unlock of BH_Uptodate_Lock.

Fix the problem by always updating bh->b_state bits atomically.

CC: stable@vger.kernel.org
Reported-by: Nikolay Borisov <kernel@kyup.com>
Signed-off-by: Jan Kara <jack@suse.cz>
Signed-off-by: Theodore Ts'o <tytso@mit.edu>
Signed-off-by: Sasha Levin <sasha.levin@oracle.com>
(cherry picked from commit a7635d6a0849007d2192bc02c038cc1b9d91b274)

Signed-off-by: Dan Duval <dan.duval@oracle.com>
fs/ext4/inode.c