Skip to content

TOCTOU: File deletion followed by file creation #17153

Open

Description

@estebank

What it does

Detect when a file is being deleted and then the same file path is used to create a new file. This is a classic source of Time Of Check, Time Of Use bugs.

Advantage

The recommended code deletes and recreates an empty file in a single syscall, meaning that the act of creation acts as the check, avoiding TOCTOU bugs.

Drawbacks

No response

Example

We should detect when an argument to std::fs::remove_file is used later to create a File:

    let path = "foo";
    fs::remove_file(path)?;
    fs::File::create(path)?;

We should detect when string literals are used too:

    fs::remove_file("foo")?;
    fs::File::create("foo")?;

Could be written as:

    let _ = fs::OpenOptions::new()
        .write(true)
        .create_new(true)
        .open(path)?;

Comparison with existing lints

No response

Additional Context

This is the cause for CVE 2026-35355 in uutils: https://corrode.dev/blog/bugs-rust-wont-catch/#case-study-cve-2026-35355

uutils/coreutils@b5bbabc#diff-bcf6f1535f9c0064879a5dc2d41d760d17217f2767b52f972c595e28ab5c2d72R825-R840

Activity

  1. added
    A-lint
    on Jun 4, 2026
  2. added 2 commits that reference this issue on Aug 18, 2026
  3. added 2 commits that reference this issue on Aug 19, 2026
  4. added a commit that references this issue on Aug 19, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-lint

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions