From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 22B4113E409; Wed, 19 Jun 2024 13:28:45 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1718803725; cv=none; b=WPCgfn1CIzKSp1RJL45WxxYM0/bgqTcT6dWvquY4NVtxz6Pg55bFYK9tWkWyN5h8QNs99gqgKyOs7N+J5CGWWZl/GpSLwCDYa7K/dcUSgZOahNFMqzcxBzrgLM+7fOQqhMgdgxH5fEM5kleGWD4gvdVdXFcYqwrnH2TFwZd18Bg= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1718803725; c=relaxed/simple; bh=2Zjw+wXT1tkJbBawKLC2XYUGJOk1g9cVuijasova+UQ=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=iFSIfTh96D72AGKytfX1BF9qRdCiEDTF7E4Jc27le1L3KuB72XYAHHgMKuNCowBOsieX+iZPZ8rO0B8FeUqFNh1HKJ78F3nph7DuKxTlG5ckKto8iYcWQaT6sDnQMSFz+njpI9TYVY2c7NH4++RGK1bOBJy6R09lBRMzQkjEqFg= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.b=TAkd89T8; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.b="TAkd89T8" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 9EAC2C2BBFC; Wed, 19 Jun 2024 13:28:44 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1718803725; bh=2Zjw+wXT1tkJbBawKLC2XYUGJOk1g9cVuijasova+UQ=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=TAkd89T841CCFvWuQ2/1UaeMdJN+CJxDdW1dj9WWbqZ4dXnTeqSFxBI1Z22NeZxiR qIq6GMht7Y9nicvw/+LJKmKInQQTkJ7unnGJ0MgmFClcGa62A82Zrr5AhDBNbwL0i4 e/MNXDc0g1Ul+fSFFICkrKzk5Df7WRKPlOnYwifE= From: Greg Kroah-Hartman To: stable@vger.kernel.org Cc: Greg Kroah-Hartman , patches@lists.linux.dev, Ryusuke Konishi , syzbot+c8166c541d3971bf6c87@syzkaller.appspotmail.com, Andrew Morton , Sasha Levin Subject: [PATCH 6.1 083/217] nilfs2: fix nilfs_empty_dir() misjudgment and long loop on I/O errors Date: Wed, 19 Jun 2024 14:55:26 +0200 Message-ID: <20240619125559.891470904@linuxfoundation.org> X-Mailer: git-send-email 2.45.2 In-Reply-To: <20240619125556.491243678@linuxfoundation.org> References: <20240619125556.491243678@linuxfoundation.org> User-Agent: quilt/0.67 X-stable: review X-Patchwork-Hint: ignore Precedence: bulk X-Mailing-List: stable@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit 6.1-stable review patch. If anyone has any objections, please let me know. ------------------ From: Ryusuke Konishi [ Upstream commit 7373a51e7998b508af7136530f3a997b286ce81c ] The error handling in nilfs_empty_dir() when a directory folio/page read fails is incorrect, as in the old ext2 implementation, and if the folio/page cannot be read or nilfs_check_folio() fails, it will falsely determine the directory as empty and corrupt the file system. In addition, since nilfs_empty_dir() does not immediately return on a failed folio/page read, but continues to loop, this can cause a long loop with I/O if i_size of the directory's inode is also corrupted, causing the log writer thread to wait and hang, as reported by syzbot. Fix these issues by making nilfs_empty_dir() immediately return a false value (0) if it fails to get a directory folio/page. Link: https://lkml.kernel.org/r/20240604134255.7165-1-konishi.ryusuke@gmail.com Signed-off-by: Ryusuke Konishi Reported-by: syzbot+c8166c541d3971bf6c87@syzkaller.appspotmail.com Closes: https://syzkaller.appspot.com/bug?extid=c8166c541d3971bf6c87 Fixes: 2ba466d74ed7 ("nilfs2: directory entry operations") Tested-by: Ryusuke Konishi Cc: Signed-off-by: Andrew Morton Signed-off-by: Sasha Levin --- fs/nilfs2/dir.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/fs/nilfs2/dir.c b/fs/nilfs2/dir.c index 4911f09eb68b0..e9668e455a35e 100644 --- a/fs/nilfs2/dir.c +++ b/fs/nilfs2/dir.c @@ -627,7 +627,7 @@ int nilfs_empty_dir(struct inode *inode) kaddr = nilfs_get_page(inode, i, &page); if (IS_ERR(kaddr)) - continue; + return 0; de = (struct nilfs_dir_entry *)kaddr; kaddr += nilfs_last_byte(inode, i) - NILFS_DIR_REC_LEN(1); -- 2.43.0