Skip to content

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

Merged
jentfoo merged 2 commits intobranch/v14from
jent/recursiveChownFix-v14
Oct 10, 2023
Merged

[v14] utils.RecursiveChown: Fix for Privilege Escalation due to following symlinks#33248
jentfoo merged 2 commits intobranch/v14from
jent/recursiveChownFix-v14

Conversation

@jentfoo
Copy link
Copy Markdown
Contributor

@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
@github-actions github-actions Bot requested a review from jimbishopp October 10, 2023 18:41
@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
@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.

4 participants