1
0
Fork 0
remarkable-linux/fs/nilfs2
Andreas Rohner 45a99f1f78 nilfs2: fix race condition that causes file system corruption
commit 31ccb1f7ba upstream.

There is a race condition between nilfs_dirty_inode() and
nilfs_set_file_dirty().

When a file is opened, nilfs_dirty_inode() is called to update the
access timestamp in the inode.  It calls __nilfs_mark_inode_dirty() in a
separate transaction.  __nilfs_mark_inode_dirty() caches the ifile
buffer_head in the i_bh field of the inode info structure and marks it
as dirty.

After some data was written to the file in another transaction, the
function nilfs_set_file_dirty() is called, which adds the inode to the
ns_dirty_files list.

Then the segment construction calls nilfs_segctor_collect_dirty_files(),
which goes through the ns_dirty_files list and checks the i_bh field.
If there is a cached buffer_head in i_bh it is not marked as dirty
again.

Since nilfs_dirty_inode() and nilfs_set_file_dirty() use separate
transactions, it is possible that a segment construction that writes out
the ifile occurs in-between the two.  If this happens the inode is not
on the ns_dirty_files list, but its ifile block is still marked as dirty
and written out.

In the next segment construction, the data for the file is written out
and nilfs_bmap_propagate() updates the b-tree.  Eventually the bmap root
is written into the i_bh block, which is not dirty, because it was
written out in another segment construction.

As a result the bmap update can be lost, which leads to file system
corruption.  Either the virtual block address points to an unallocated
DAT block, or the DAT entry will be reused for something different.

The error can remain undetected for a long time.  A typical error
message would be one of the "bad btree" errors or a warning that a DAT
entry could not be found.

This bug can be reproduced reliably by a simple benchmark that creates
and overwrites millions of 4k files.

Link: http://lkml.kernel.org/r/1509367935-3086-2-git-send-email-konishi.ryusuke@lab.ntt.co.jp
Signed-off-by: Andreas Rohner <andreas.rohner@gmx.net>
Signed-off-by: Ryusuke Konishi <konishi.ryusuke@lab.ntt.co.jp>
Tested-by: Andreas Rohner <andreas.rohner@gmx.net>
Tested-by: Ryusuke Konishi <konishi.ryusuke@lab.ntt.co.jp>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
2017-11-30 08:39:03 +00:00
..
Kconfig fs/nilfs2: remove depends on CONFIG_EXPERIMENTAL 2013-01-11 11:39:04 -08:00
Makefile nilfs2: integrate sysfs support into driver 2014-08-08 15:57:21 -07:00
alloc.c nilfs2: replace nilfs_warning() with nilfs_msg() 2016-08-02 19:35:18 -04:00
alloc.h nilfs2: avoid bare use of 'unsigned' 2016-05-23 17:04:14 -07:00
bmap.c nilfs2: hide function name argument from nilfs_error() 2016-08-02 19:35:16 -04:00
bmap.h nilfs2: move ioctl interface and disk layout to uapi separately 2016-08-02 19:35:21 -04:00
btnode.c fs: add i_blocksize() 2017-06-14 15:06:00 +02:00
btnode.h fs: have submit_bh users pass in op and flags separately 2016-06-07 13:41:38 -06:00
btree.c nilfs2: emit error message when I/O error is detected 2016-08-02 19:35:19 -04:00
btree.h nilfs2: move ioctl interface and disk layout to uapi separately 2016-08-02 19:35:21 -04:00
cpfile.c nilfs2: move ioctl interface and disk layout to uapi separately 2016-08-02 19:35:21 -04:00
cpfile.h nilfs2: move ioctl interface and disk layout to uapi separately 2016-08-02 19:35:21 -04:00
dat.c nilfs2: reduce bare use of printk() with nilfs_msg() 2016-08-02 19:35:17 -04:00
dat.h nilfs2: move ioctl interface and disk layout to uapi separately 2016-08-02 19:35:21 -04:00
dir.c fs: Replace CURRENT_TIME with current_time() for inode timestamps 2016-09-27 21:06:21 -04:00
direct.c nilfs2: reduce bare use of printk() with nilfs_msg() 2016-08-02 19:35:17 -04:00
direct.h nilfs2: move ioctl interface and disk layout to uapi separately 2016-08-02 19:35:21 -04:00
export.h nilfs2: replace __attribute__((packed)) with __packed 2016-05-23 17:04:14 -07:00
file.c nilfs2: clean up old e-mail addresses 2016-05-23 17:04:14 -07:00
gcinode.c nilfs2: emit error message when I/O error is detected 2016-08-02 19:35:19 -04:00
ifile.c nilfs2: replace nilfs_warning() with nilfs_msg() 2016-08-02 19:35:18 -04:00
ifile.h nilfs2: move ioctl interface and disk layout to uapi separately 2016-08-02 19:35:21 -04:00
inode.c fs: add i_blocksize() 2017-06-14 15:06:00 +02:00
ioctl.c fs: Replace CURRENT_TIME with current_time() for inode timestamps 2016-09-27 21:06:21 -04:00
mdt.c fs: add i_blocksize() 2017-06-14 15:06:00 +02:00
mdt.h nilfs2: avoid bare use of 'unsigned' 2016-05-23 17:04:14 -07:00
namei.c Merge remote-tracking branch 'ovl/rename2' into for-linus 2016-10-10 23:02:51 -04:00
nilfs.h nilfs2: move ioctl interface and disk layout to uapi separately 2016-08-02 19:35:21 -04:00
page.c nilfs2: use BIT() macro 2016-08-02 19:35:21 -04:00
page.h nilfs2: avoid bare use of 'unsigned' 2016-05-23 17:04:14 -07:00
recovery.c nilfs2: reduce bare use of printk() with nilfs_msg() 2016-08-02 19:35:17 -04:00
segbuf.c nilfs2: reduce bare use of printk() with nilfs_msg() 2016-08-02 19:35:17 -04:00
segbuf.h nilfs2: avoid bare use of 'unsigned' 2016-05-23 17:04:14 -07:00
segment.c nilfs2: fix race condition that causes file system corruption 2017-11-30 08:39:03 +00:00
segment.h nilfs2: move ioctl interface and disk layout to uapi separately 2016-08-02 19:35:21 -04:00
sufile.c nilfs2: move ioctl interface and disk layout to uapi separately 2016-08-02 19:35:21 -04:00
sufile.h nilfs2: move ioctl interface and disk layout to uapi separately 2016-08-02 19:35:21 -04:00
super.c nilfs2: refactor parser of snapshot mount option 2016-08-02 19:35:20 -04:00
sysfs.c nilfs2: fix misuse of a semaphore in sysfs code 2016-08-02 19:35:20 -04:00
sysfs.h nilfs2: clean trailing semicolons in macros 2016-05-23 17:04:14 -07:00
the_nilfs.c nilfs2: reduce bare use of printk() with nilfs_msg() 2016-08-02 19:35:17 -04:00
the_nilfs.h nilfs2: fix misuse of a semaphore in sysfs code 2016-08-02 19:35:20 -04:00