Skip to content

gh-160297: Fix tarfile setting attributes through a hard link fallback - #160298

Open
gpshead wants to merge 1 commit into
python:mainfrom
gpshead:scanfix-tarfile-y0h1y0er
Open

gpshead wants to merge 1 commit into
python:mainfrom
gpshead:scanfix-tarfile-y0h1y0er

Conversation

@gpshead

@gpshead gpshead commented Oct 22, 2026 •

Copy link
Copy Markdown
Member

When a hard link member's target is missing, makelink_with_filter() extracts a copy of the referenced member instead. If that member is a symlink, _extract_member() went on to apply the hard link's owner, mode and mtime with calls that follow the symlink, so they could land on a file outside the destination with the 'tar' and 'fully_trusted' filters. Attribute setting is now skipped when a hard link member ended up as a symlink; the nested extraction has already applied the symlink member's own attributes without following it. A hard link extracted as a copy of a regular file still gets the hard link's attributes, as before.

Fixes #160297

ANT-2026-Y0H1Y0ER

…allback

When a hard link member is extracted as a copy of a symlink member, do
not apply the hard link's owner, mode and mtime to the symlink's target.

ANT-2026-Y0H1Y0ER
@gpshead gpshead added needs backport to 3.11 only security fixes needs backport to 3.12 only security fixes needs backport to 3.13 only security fixes needs backport to 3.14 bugs and security fixes needs backport to 3.15 bugs and security fixes labels Oct 22, 2026
@gpshead gpshead self-assigned this Oct 22, 2026
@gpshead
gpshead requested a review from JelleZijlstra October 22, 2026 18:34
@gpshead
gpshead marked this pull request as ready for review October 22, 2026 18:35
@gpshead
gpshead requested a review from ethanfurman as a code owner October 22, 2026 18:35

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please add the CVE.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I put up a GHSA for assignment. We don't need to wait for that to fix things though.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@gpshead, JFYI you can accept the GHSA yourself (add [ACCEPTED] to the title), which will trigger assignment of a CVE. To wait even less, since the bot runs on an hourly cron, you can trigger a run in python/psrt-ghsa-bot, to get one almost instantly.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I ran the steps, and CVE-2026-116125 was assigned.

@gpshead gpshead added the sprint label Oct 23, 2026
@github-project-automation github-project-automation Bot moved this to Todo in Sprint Oct 23, 2026
@gpshead gpshead moved this from Todo to In Progress in Sprint Oct 25, 2026
@gpshead gpshead removed the sprint label Oct 25, 2026
@gpshead gpshead removed this from Sprint Oct 25, 2026

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I ran the steps, and CVE-2026-116125 was assigned.

@@ -0,0 +1,4 @@
Fix :meth:`tarfile.TarFile.extractall` and :meth:`tarfile.TarFile.extract`

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
Fix :meth:`tarfile.TarFile.extractall` and :meth:`tarfile.TarFile.extract`
.. cve: CVE-2026-116125
Fix :meth:`tarfile.TarFile.extractall` and :meth:`tarfile.TarFile.extract`

@StanFromIreland StanFromIreland left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry, properly reviewing this now I don't think this is a type-security issue (more so a correctness issue). As documented, tarfile.tar_filter:

This filter does not check link targets (TarInfo.linkname). It allows benign cases (like links to /dev/null), but it also allows links (symbolic and hard) to arbitrary files on the filesystem, potentially granting unintended access to these files.

Because of that, a single hard link member with linkname ../flag already creates a hard link to the outside file and applies the member's mode, mtime and owner to it. The PR's two-member fallback route reaches nothing the filter does not already permit directly. The data filter, which is the documented to refuse to extract links (hard or soft) that link to absolute paths, or ones that link outside the destination, already rejects this fallback with LinkFallbackError, and fully_trusted is trusted by definition, so no documented security boundary is crossed under any built-in filter.

@bedevere-app

bedevere-app Bot commented Oct 25, 2026

Copy link
Copy Markdown

When you're done making the requested changes, leave the comment: I have made the requested changes; please review again.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

awaiting changes needs backport to 3.11 only security fixes needs backport to 3.12 only security fixes needs backport to 3.13 only security fixes needs backport to 3.14 bugs and security fixes needs backport to 3.15 bugs and security fixes

Projects

None yet

Development

Successfully merging this pull request may close these issues.

tarfile applies a hard link member's attributes through a symlink extracted in its place

2 participants