Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

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>

authored by

Ryusuke Konishi and committed by
Andrew Morton
62e6e784 105ae044

+18 -5
+18 -5
fs/nilfs2/sufile.c
··· 79 79 NILFS_MDT(sufile)->mi_entry_size; 80 80 } 81 81 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) 84 84 { 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; 86 93 } 87 94 88 95 static inline int ··· 1244 1237 if (err) 1245 1238 goto failed; 1246 1239 1247 - err = nilfs_sufile_get_header_block(sufile, &header_bh); 1248 - if (err) 1240 + err = nilfs_mdt_get_block(sufile, 0, 0, NULL, &header_bh); 1241 + if (unlikely(err)) { 1242 + if (err == -ENOENT) { 1243 + nilfs_err(sb, 1244 + "missing header block in segment usage metadata"); 1245 + err = -EINVAL; 1246 + } 1249 1247 goto failed; 1248 + } 1250 1249 1251 1250 sui = NILFS_SUI(sufile); 1252 1251 kaddr = kmap_local_page(header_bh->b_page);