Skip to content

Commit cdaac8e

Browse files
konisakpm00
authored andcommitted
nilfs2: fix WARNING in mark_buffer_dirty due to discarded buffer reuse
A syzbot stress test using a corrupted disk image reported that mark_buffer_dirty() called from __nilfs_mark_inode_dirty() or nilfs_palloc_commit_alloc_entry() may output a kernel warning, and can panic if the kernel is booted with panic_on_warn. This is because nilfs2 keeps buffer pointers in local structures for some metadata and reuses them, but such buffers may be forcibly discarded by nilfs_clear_dirty_page() in some critical situations. This issue is reported to appear after commit 28a65b4 ("nilfs2: do not write dirty data after degenerating to read-only"), but the issue has potentially existed before. Fix this issue by checking the uptodate flag when attempting to reuse an internally held buffer, and reloading the metadata instead of reusing the buffer if the flag was lost. Link: https://lkml.kernel.org/r/[email protected] Signed-off-by: Ryusuke Konishi <[email protected]> Reported-by: [email protected] Closes: https://lkml.kernel.org/r/[email protected] Fixes: 8c26c4e ("nilfs2: fix issue with flush kernel thread after remount in RO mode because of driver's internal error or metadata corruption") Tested-by: Ryusuke Konishi <[email protected]> Cc: <[email protected]> # 3.10+ Signed-off-by: Andrew Morton <[email protected]>
1 parent 198430f commit cdaac8e

File tree

2 files changed

+7
-3
lines changed

2 files changed

+7
-3
lines changed

fs/nilfs2/alloc.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -205,7 +205,8 @@ static int nilfs_palloc_get_block(struct inode *inode, unsigned long blkoff,
205205
int ret;
206206

207207
spin_lock(lock);
208-
if (prev->bh && blkoff == prev->blkoff) {
208+
if (prev->bh && blkoff == prev->blkoff &&
209+
likely(buffer_uptodate(prev->bh))) {
209210
get_bh(prev->bh);
210211
*bhp = prev->bh;
211212
spin_unlock(lock);

fs/nilfs2/inode.c

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1025,7 +1025,7 @@ int nilfs_load_inode_block(struct inode *inode, struct buffer_head **pbh)
10251025
int err;
10261026

10271027
spin_lock(&nilfs->ns_inode_lock);
1028-
if (ii->i_bh == NULL) {
1028+
if (ii->i_bh == NULL || unlikely(!buffer_uptodate(ii->i_bh))) {
10291029
spin_unlock(&nilfs->ns_inode_lock);
10301030
err = nilfs_ifile_get_inode_block(ii->i_root->ifile,
10311031
inode->i_ino, pbh);
@@ -1034,7 +1034,10 @@ int nilfs_load_inode_block(struct inode *inode, struct buffer_head **pbh)
10341034
spin_lock(&nilfs->ns_inode_lock);
10351035
if (ii->i_bh == NULL)
10361036
ii->i_bh = *pbh;
1037-
else {
1037+
else if (unlikely(!buffer_uptodate(ii->i_bh))) {
1038+
__brelse(ii->i_bh);
1039+
ii->i_bh = *pbh;
1040+
} else {
10381041
brelse(*pbh);
10391042
*pbh = ii->i_bh;
10401043
}

0 commit comments

Comments
 (0)