You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Windows: std::fs::read_link trusts reparse point offsets without bounds checking #164827
A-filesystemArea: `std::fs`C-enhancementCategory: An issue proposing an enhancement or a PR with one.O-windowsOperating system: WindowsT-libsRelevant to the library team, which will review and decide on the PR/issue.
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.
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.
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).
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.
A-filesystemArea: `std::fs`C-enhancementCategory: An issue proposing an enhancement or a PR with one.O-windowsOperating system: WindowsT-libsRelevant to the library team, which will review and decide on the PR/issue.
Activity
ds84182 commentedon Oct 24, 2026
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.
maxdexh commentedon Oct 24, 2026
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).
ChrisDenton commentedon Oct 24, 2026
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.
sahenjp commentedon Oct 25, 2026
Sorry, I've updated the issue description.
Rollup merge of rust-lang#164884 - sahenjp:windows-readlink-bounds-ch…
Unrolled build for #164884 in rollup 164894