Skip to content

Commit 2f012f2

Browse files
konisakpm00
authored andcommitted
nilfs2: fix incomplete buffer cleanup in nilfs_btnode_abort_change_key()
A syzbot fault injection test reported that nilfs_btnode_create_block, a helper function that allocates a new node block for b-trees, causes a kernel BUG for disk images where the file system block size is smaller than the page size. This was due to unexpected flags on the newly allocated buffer head, and it turned out to be because the buffer flags were not cleared by nilfs_btnode_abort_change_key() after an error occurred during a b-tree update operation and the buffer was later reused in that state. Fix this issue by using nilfs_btnode_delete() to abandon the unused preallocated buffer in nilfs_btnode_abort_change_key(). Link: https://lkml.kernel.org/r/20230513102428.10223-1-konishi.ryusuke@gmail.com Signed-off-by: Ryusuke Konishi <konishi.ryusuke@gmail.com> Reported-by: syzbot+b0a35a5c1f7e846d3b09@syzkaller.appspotmail.com Closes: https://lkml.kernel.org/r/000000000000d1d6c205ebc4d512@google.com Tested-by: Ryusuke Konishi <konishi.ryusuke@gmail.com> Cc: <stable@vger.kernel.org> Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
1 parent 8b817fd commit 2f012f2

1 file changed

Lines changed: 10 additions & 2 deletions

File tree

fs/nilfs2/btnode.c

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -285,6 +285,14 @@ void nilfs_btnode_abort_change_key(struct address_space *btnc,
285285
if (nbh == NULL) { /* blocksize == pagesize */
286286
xa_erase_irq(&btnc->i_pages, newkey);
287287
unlock_page(ctxt->bh->b_page);
288-
} else
289-
brelse(nbh);
288+
} else {
289+
/*
290+
* When canceling a buffer that a prepare operation has
291+
* allocated to copy a node block to another location, use
292+
* nilfs_btnode_delete() to initialize and release the buffer
293+
* so that the buffer flags will not be in an inconsistent
294+
* state when it is reallocated.
295+
*/
296+
nilfs_btnode_delete(nbh);
297+
}
290298
}

0 commit comments

Comments
 (0)