Skip to content

nilfs2: harden dsync recovery and readdir

Jake Labelle linux-nilfs 2 versions – In review

Get series with b4
b4 am [email protected]

Versions newest first · linked by author and title

  1. v2 Latest2 patches 6 repliesIn review
  2. v12 patches 2 repliesSuperseded

Changes in v2 from the cover letter

- Patch 1: also accept S_ISDIR/S_ISLNK (not just S_ISREG), wrap the check in likely(), return -EINVAL instead of -EIO.
- Patch 2: hoist nilfs_chunk_size(inode) into a local chunk_size variable; expanded the comment on why chunk-aligned offsets are already trustworthy without a chain walk.

Patches in v2 No applies recorded yet

#Subject and filesSizeRepliesApplied
1/2nilfs2: reject non-regular inodes in dsync recoveryfs/nilfs2/recovery.c+17 -00 replies
2/2nilfs2: validate directory position after llseek in readdirfs/nilfs2/dir.c+34 -04 replies

Reviews trailers per patch

None of the 2 patches has a Reviewed-by or Acked-by.

PatchClaude Mythos 5
SeriesCo-Authored-By
1/2Co-Authored-By
2/2Co-Authored-By

Trailers given in replies are filled; those carried in the patches from earlier versions are outlined with dashes.

Read the v2 thread

Cover letter [PATCH v2 0/2] nilfs2: harden dsync recovery and readdir

Hi Ryusuke,

Sorry for the late reply, busy getting the flu 😄. I've put your review comments from v1 into the changes below.

While reviewing fs/nilfs2 I found two robustness issues with corrupted (or malformed) filesystem images, both dating back to the initial merge of nilfs2:

Patch 1: roll-forward recovery replays dsync logs without checking that the designated inode is one of the types that actually have a bmap. A log entry naming some other inode type leads nilfs_get_block() to an uninitialized bmap and an indirect call through uninitialized memory. With the patch, mount of such an image fails cleanly with -EINVAL.

Patch 2: nilfs_readdir() parses the directory folio at whatever offset llseek left in ctx->pos, without snapping it onto an entry boundary the way ext2's ext2_validate_entry() does. dir_emit() can then emit bytes from a bogus entry, reading past the end of the folio.

Both patches were tested against current mainline (arm64): each issue reproduces before and is resolved after, and a mount/list/create/write/ fsync/remount/read-back pass shows normal operation unaffected. This was initially reported through [email protected]; per Greg K.H. and Ryusuke Konishi it is being resubmitted here for normal public review. Reproducers (small Python scripts that generate the images) are available on request.

These patches were developed with AI assistance (Anthropic Claude) and manually reviewed and tested.

Changes in v2 (per Ryusuke Konishi's review of v1):
- Patch 1: also accept S_ISDIR/S_ISLNK (not just S_ISREG), wrap the check in likely(), return -EINVAL instead of -EIO.
- Patch 2: hoist nilfs_chunk_size(inode) into a local chunk_size variable; expanded the comment on why chunk-aligned offsets are already trustworthy without a chain walk.

Jake Labelle (2):
nilfs2: reject non-regular inodes in dsync recovery
nilfs2: validate directory position after llseek in readdir

 fs/nilfs2/dir.c      | 33 +++++++++++++++++++++++++++++++++
 fs/nilfs2/recovery.c | 17 +++++++++++++++++
 2 files changed, 50 insertions(+)
Signature · 1 line
2.43.0