Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[v14] utils.RecursiveChown: Fix for Privilege Escalation due to following symlinks #33248

Merged
merged 2 commits into from Oct 10, 2023

Conversation

jentfoo
Copy link
Member

@jentfoo jentfoo commented Oct 10, 2023

v14 OSS port for private security fix: https://github.com/gravitational/teleport-private/pull/1077

Backport for OSS master PR: #33244

Prior to this change a user could exploit Teleports privileged access to `chown` arbitrary files on the system.

This is due to the directory being changed first, allowing a small time window where a user can remove or rename the still `root` owned files with a symlink.  The added tests help show this issue in a more controlled way.

A switch to `os.Lchown` avoids the risk in following symlinks to files.  In addition, in order to remove the risk for hardlinks (notably on OSX with reduced hardlink protections), as well as risks with directory symlinks, the folder structure is inspected before any `chown` operation.  And then the files are updated before their parent directories.
None of these cases should expect a symlink that would need to be followed.
@jentfoo jentfoo self-assigned this Oct 10, 2023
@github-actions github-actions bot added audit-log Issues related to Teleports Audit Log backport size/md labels Oct 10, 2023
@jentfoo jentfoo added this pull request to the merge queue Oct 10, 2023
Merged via the queue into branch/v14 with commit 24418a0 Oct 10, 2023
23 checks passed
@jentfoo jentfoo deleted the jent/recursiveChownFix-v14 branch October 10, 2023 21:54
lsgunn-teleport pushed a commit that referenced this pull request Oct 11, 2023
…wing symlinks (#33248)

* utils.RecursiveChown: Harden against user access race conditions

Prior to this change a user could exploit Teleports privileged access to `chown` arbitrary files on the system.

This is due to the directory being changed first, allowing a small time window where a user can remove or rename the still `root` owned files with a symlink.  The added tests help show this issue in a more controlled way.

A switch to `os.Lchown` avoids the risk in following symlinks to files.  In addition, in order to remove the risk for hardlinks (notably on OSX with reduced hardlink protections), as well as risks with directory symlinks, the folder structure is inspected before any `chown` operation.  And then the files are updated before their parent directories.

* Update other instances of `os.Chown` to `os.Lchown`

None of these cases should expect a symlink that would need to be followed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
audit-log Issues related to Teleports Audit Log backport size/md
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants