Skip to content

Commit 62e6e78

Browse files
konisakpm00
authored andcommitted
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/[email protected] Link: https://lkml.kernel.org/r/[email protected] Signed-off-by: Ryusuke Konishi <[email protected]> Signed-off-by: Andrew Morton <[email protected]>
1 parent 105ae04 commit 62e6e78

File tree

1 file changed

+18
-5
lines changed

1 file changed

+18
-5
lines changed

fs/nilfs2/sufile.c

Lines changed: 18 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -79,10 +79,17 @@ nilfs_sufile_block_get_segment_usage(const struct inode *sufile, __u64 segnum,
7979
NILFS_MDT(sufile)->mi_entry_size;
8080
}
8181

82-
static inline int nilfs_sufile_get_header_block(struct inode *sufile,
83-
struct buffer_head **bhp)
82+
static int nilfs_sufile_get_header_block(struct inode *sufile,
83+
struct buffer_head **bhp)
8484
{
85-
return nilfs_mdt_get_block(sufile, 0, 0, NULL, bhp);
85+
int err = nilfs_mdt_get_block(sufile, 0, 0, NULL, bhp);
86+
87+
if (unlikely(err == -ENOENT)) {
88+
nilfs_error(sufile->i_sb,
89+
"missing header block in segment usage metadata");
90+
err = -EIO;
91+
}
92+
return err;
8693
}
8794

8895
static inline int
@@ -1237,9 +1244,15 @@ int nilfs_sufile_read(struct super_block *sb, size_t susize,
12371244
if (err)
12381245
goto failed;
12391246

1240-
err = nilfs_sufile_get_header_block(sufile, &header_bh);
1241-
if (err)
1247+
err = nilfs_mdt_get_block(sufile, 0, 0, NULL, &header_bh);
1248+
if (unlikely(err)) {
1249+
if (err == -ENOENT) {
1250+
nilfs_err(sb,
1251+
"missing header block in segment usage metadata");
1252+
err = -EINVAL;
1253+
}
12421254
goto failed;
1255+
}
12431256

12441257
sui = NILFS_SUI(sufile);
12451258
kaddr = kmap_local_page(header_bh->b_page);

0 commit comments

Comments
 (0)