This is a note to let you know that I've just added the patch titled nilfs2: fix incomplete buffer cleanup in nilfs_btnode_abort_change_key() to the 6.1-stable tree which can be found at: http://www.kernel.org/git/?p=linux/kernel/git/stable/stable-queue.git;a=summary The filename of the patch is: nilfs2-fix-incomplete-buffer-cleanup-in-nilfs_btnode_abort_change_key.patch and it can be found in the queue-6.1 subdirectory. If you, or anyone else, feels it should not be added to the stable tree, please let <stable@xxxxxxxxxxxxxxx> know about it. >From 2f012f2baca140c488e43d27a374029c1e59098d Mon Sep 17 00:00:00 2001 From: Ryusuke Konishi <konishi.ryusuke@xxxxxxxxx> Date: Sat, 13 May 2023 19:24:28 +0900 Subject: nilfs2: fix incomplete buffer cleanup in nilfs_btnode_abort_change_key() From: Ryusuke Konishi <konishi.ryusuke@xxxxxxxxx> commit 2f012f2baca140c488e43d27a374029c1e59098d upstream. 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@xxxxxxxxx Signed-off-by: Ryusuke Konishi <konishi.ryusuke@xxxxxxxxx> Reported-by: syzbot+b0a35a5c1f7e846d3b09@xxxxxxxxxxxxxxxxxxxxxxxxx Closes: https://lkml.kernel.org/r/000000000000d1d6c205ebc4d512@xxxxxxxxxx Tested-by: Ryusuke Konishi <konishi.ryusuke@xxxxxxxxx> Cc: <stable@xxxxxxxxxxxxxxx> Signed-off-by: Andrew Morton <akpm@xxxxxxxxxxxxxxxxxxxx> Signed-off-by: Greg Kroah-Hartman <gregkh@xxxxxxxxxxxxxxxxxxx> --- fs/nilfs2/btnode.c | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) --- a/fs/nilfs2/btnode.c +++ b/fs/nilfs2/btnode.c @@ -285,6 +285,14 @@ void nilfs_btnode_abort_change_key(struc if (nbh == NULL) { /* blocksize == pagesize */ xa_erase_irq(&btnc->i_pages, newkey); unlock_page(ctxt->bh->b_page); - } else - brelse(nbh); + } else { + /* + * When canceling a buffer that a prepare operation has + * allocated to copy a node block to another location, use + * nilfs_btnode_delete() to initialize and release the buffer + * so that the buffer flags will not be in an inconsistent + * state when it is reallocated. + */ + nilfs_btnode_delete(nbh); + } } Patches currently in stable-queue which might be from konishi.ryusuke@xxxxxxxxx are queue-6.1/nilfs2-reject-devices-with-insufficient-block-count.patch queue-6.1/nilfs2-fix-incomplete-buffer-cleanup-in-nilfs_btnode_abort_change_key.patch queue-6.1/nilfs2-fix-possible-out-of-bounds-segment-allocation-in-resize-ioctl.patch