]> Cypherpunks repositories - gostls13.git/commit
[release-branch.go1.25] os: avoid escape from Root via ReadDir or Readdir
authorDamien Neil <dneil@google.com>
Thu, 26 Feb 2026 17:54:33 +0000 (09:54 -0800)
committerCherry Mui <cherryyz@google.com>
Fri, 27 Feb 2026 21:46:29 +0000 (13:46 -0800)
commit4091800393d254befde3770fd16f51200ebd5a3d
treec77b2a3602b6d2113c836e604fcf1e64350f0a0c
parent0ee4ab4c3f4f02ed9edee4e2479ced7177d5b03b
[release-branch.go1.25] os: avoid escape from Root via ReadDir or Readdir

When reading the contents of a directory using
File.ReadDir or File.Readdir, the os.FileInfo was
populated on Unix platforms using lstat.
This lstat call is vulnerable to a TOCTOU race
and could escape the root.

For example:
  - Open the directory "dir" within a Root.
    This directory contains a file named "file".
  - Use File.ReadDir to list the contents of "dir",
    receiving a os.DirEntry for "dir/file".
  - Replace "dir" with a symlink to "/etc".
  - Use DirEntry.Info to retrieve the FileInfo for "dir/file".
    This FileInfo contains information on "/etc/file" instead.

This escape permits identifying the presence or absence of
files outside a Root, as well as retreiving stat metadata
(size, mode, modification time, etc.) for files outside a Root.

This escape does not permit reading or writing to files
outside a Root.

For #77827
Fixes #77833
Fixes CVE-2026-27139

Change-Id: I40004f830c588e516aff8ee593d630d36a6a6964
Reviewed-on: https://go-review.googlesource.com/c/go/+/749480
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
Reviewed-by: Nicholas Husin <husin@google.com>
Reviewed-by: Nicholas Husin <nsh@golang.org>
Auto-Submit: Damien Neil <dneil@google.com>
(cherry picked from commit 657ed934e85dc575aad51356c4b437961e7c1313)
Reviewed-on: https://go-review.googlesource.com/c/go/+/749920
14 files changed:
src/internal/poll/fstatat_unix.go [new file with mode: 0644]
src/os/dir_darwin.go
src/os/dir_unix.go
src/os/export_test.go
src/os/file.go
src/os/file_unix.go
src/os/os_test.go
src/os/os_unix_test.go
src/os/root_test.go
src/os/root_unix.go
src/os/stat.go
src/os/statat.go [new file with mode: 0644]
src/os/statat_other.go [new file with mode: 0644]
src/os/statat_unix.go [new file with mode: 0644]