nilfs2: treat missing sufile header block as metadata corruption

Patch series "nilfs2: prevent unexpected ENOENT propagation".

This series fixes potential issues where the result code -ENOENT, which is
returned internally when a metadata file operation encouters a hole block,
is exposed to user space without being properly handled.

Several issues with the same cause leading to hangs or WARN_ON check
failures have been reported by syzbot and fixed each time in the past. 
This collectively fixes the missing -ENOENT conversions that do not cause
stability issues and are not covered by syzbot.


This patch (of 5):

The sufile, a metadata file that holds metadata for segment management,
has statistical information in its first block, but if reading this block
fails, it receives the internal code -ENOENT and returns it unchanged to
the callers.

To prevent this -ENOENT from being propagated to system calls, if reading
the header block fails, return -EIO (or -EINVAL depending on the context)
instead.

Link: https://lkml.kernel.org/r/20240821154627.11848-1-konishi.ryusuke@gmail.com
Link: https://lkml.kernel.org/r/20240821154627.11848-2-konishi.ryusuke@gmail.com
Signed-off-by: Ryusuke Konishi <konishi.ryusuke@gmail.com>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
This commit is contained in:
Ryusuke Konishi 2024-08-22 00:46:23 +09:00 committed by Andrew Morton
parent 105ae044d6
commit 62e6e78417

View File

@ -79,10 +79,17 @@ nilfs_sufile_block_get_segment_usage(const struct inode *sufile, __u64 segnum,
NILFS_MDT(sufile)->mi_entry_size;
}
static inline int nilfs_sufile_get_header_block(struct inode *sufile,
struct buffer_head **bhp)
static int nilfs_sufile_get_header_block(struct inode *sufile,
struct buffer_head **bhp)
{
return nilfs_mdt_get_block(sufile, 0, 0, NULL, bhp);
int err = nilfs_mdt_get_block(sufile, 0, 0, NULL, bhp);
if (unlikely(err == -ENOENT)) {
nilfs_error(sufile->i_sb,
"missing header block in segment usage metadata");
err = -EIO;
}
return err;
}
static inline int
@ -1237,9 +1244,15 @@ int nilfs_sufile_read(struct super_block *sb, size_t susize,
if (err)
goto failed;
err = nilfs_sufile_get_header_block(sufile, &header_bh);
if (err)
err = nilfs_mdt_get_block(sufile, 0, 0, NULL, &header_bh);
if (unlikely(err)) {
if (err == -ENOENT) {
nilfs_err(sb,
"missing header block in segment usage metadata");
err = -EINVAL;
}
goto failed;
}
sui = NILFS_SUI(sufile);
kaddr = kmap_local_page(header_bh->b_page);