Skip to content

Research: Possible bug while scanning unlinked dirents #14

@twiggler

Description

@twiggler

Introduction

  1. Each node in Jffs2 has multiple versions.
  2. Unlinking an inode is accomplished by setting the ino of the corresponding dirent nodes to zero.
  3. When mounting, we do a linear scan if the nodes on the jffs filesystem.
  4. We associate a list of version of a dirent with (parent inode, filename of the dirent).
  5. When we encounter a dirent version with ino=0, we remove all versions of that dirent and consider the file lost & found.

Potential problem

I have been unable to find a guarantee that the nodes are ordered by version on disk, especially after a garbage collection cycle or wear leveling operations.

Consider the following layout on disk, where the latest version comes first


entry1          (dirent version=2 ino=0)     # Unlink
entry2          (dirent version=1 ino=3)     # Hardlink

Here, we first delete all versions of the dirent (there are none), but then erroneously recreate the mapping when we scan entry2.
The recreation is invalid because the version of the node (1) is older than the most recent one (2).

Reproduction

I have not been able to reproduce it because it is yet unclear how to force the ordering of nodes.
This report is solely based on code inspection.

Possible solution

Instead of deleting all dirents, keep the entry with ino=0 and prune later on.

***Uknown* ****: Can there be new versions of a dirent after an unlink operation?

Metadata

Metadata

Assignees

Labels

bugSomething isn't working

Type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions