Skip to content

Windows: std::fs::read_link trusts reparse point offsets without bounds checking #164827

Closed

Description

@sahenjp

Overview

In Windows, std::fs::read_link takes SubstituteNameOffset and SubstituteNameLength from a reparse point and uses them directly to build slices, without checking them against the actual size of the data.

These fields are byte counts, but the code divides them by 2 and uses the result as element offsets and lengths. If they contain invalid values, the code could end up reading past the end of the buffer.

Verification Results

I tried setting invalid values on Windows Server 2022, but NTFS rejected the requests in the scenarios I tested, so I wasn't able to trigger an out-of-bounds access.

Proposal

It might be a good idea to check that the offset and length actually fit within the retrieved data before we create the slice.

Activity

  1. added
    needs-triage
    on Oct 24, 2026
  2. ds84182 commented on Oct 24, 2026

    @ds84182

    I don't necessarily think this needs to be addressed as returning malformed data would be a bug in the filesystem driver. The kernel also uses reparse points when opening files, so this would lead to major issues elsewhere.

    If it's possible to get malformed data without modifying the kernel by loading a custom written driver or directly modifying the data on the disk it would be an issue for a lot more than just Rust programs.

  3. maxdexh commented on Oct 24, 2026

    @maxdexh
    Member

    So this may theoretically go wrong when a user installs some other (perhaps 3rd party proprietary) file system driver (that is buggy)?

    I'd agree this is not a security issue, but I still think a check here would be nice to have. Such checks will hardly make a perf difference considering the surrounding syscalls.

    If you want to submit a PR, please make sure to follow our LLM Policy (in case you are using one), and note that issue bodies and PR descriptions originally written by an LLM violate it.
    Your PR will have to be reviewed by someone familiar with this code in particular (at first glance, the function appears quite chaotic and the buffer logic poorly documented).

  4. added
    O-windows
    C-enhancement
    T-libs
    A-filesystem
    and removed
    needs-triage
    on Oct 24, 2026
  5. ChrisDenton commented on Oct 24, 2026

    @ChrisDenton
    Member

    So this may theoretically go wrong when a user installs some other (perhaps 3rd party proprietary) file system driver (that is buggy)?

    I would doubt it. Reparse points are implemented as a "filter" on top of filesystems, not by filesystem themselves (well, except they need somewhere to store the metadata). Both junction points and symlinks are built-in reparse types so we can trust them. I mean, if someone can show an attack I'd be interested but surprised.

    That said, there's no harm in bounds checking to be doubly sure.

  6. sahenjp commented on Oct 25, 2026

    @sahenjp
    ContributorAuthor

    Sorry, I've updated the issue description.

  7. added a commit that references this issue on Oct 25, 2026
    d4ca4bf
  8. added a commit that references this issue on Oct 25, 2026
    20d50d2
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-filesystemC-enhancementO-windowsT-libs

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions