Skip to content

gh-143637: Fix re-entrant mutation of ancillary data in socket.sendmsg()#143892

Merged
vstinner merged 21 commits intopython:mainfrom
priyanshu2282-cyber:fix-sendmsg-reentrant-cmsg
Feb 13, 2026
Merged

gh-143637: Fix re-entrant mutation of ancillary data in socket.sendmsg()#143892
vstinner merged 21 commits intopython:mainfrom
priyanshu2282-cyber:fix-sendmsg-reentrant-cmsg

Conversation

@priyanshu2282-cyber
Copy link
Contributor

@priyanshu2282-cyber priyanshu2282-cyber commented Jan 15, 2026

Fix a crash in socket.sendmsg() caused by re-entrant mutation of ancillary data during argument parsing.
Hold a strong reference to each ancillary item while parsing to avoid use-after-free, and added a regression test.

@priyanshu2282-cyber
Copy link
Contributor Author

Hi, this PR fixes an internal correctness issue in socket.sendmsg().
Would it be appropriate to add the skip news label?

@picnixz
Copy link
Member

picnixz commented Jan 17, 2026

No. It remains uaerfacing. In general, every bug fix should be announced if it can be seen only with pure python code and the public API

@bedevere-app
Copy link

bedevere-app bot commented Jan 17, 2026

A Python core developer has requested some changes be made to your pull request before we can consider merging it. If you could please address their requests along with any other requests in other reviews from core developers that would be appreciated.

Once you have made the requested changes, please leave a comment on this pull request containing the phrase I have made the requested changes; please review again. I will then notify any core developers who have left a review that you're ready for them to take another look at this pull request.

@priyanshu2282-cyber
Copy link
Contributor Author

Thanks for guiding, I have added the news entry.

@priyanshu2282-cyber
Copy link
Contributor Author

I have made the requested changes; please review again.

@bedevere-app
Copy link

bedevere-app bot commented Jan 17, 2026

Thanks for making the requested changes!

@picnixz: please review the changes made to this pull request.

@bedevere-app bedevere-app bot requested a review from picnixz January 17, 2026 09:40
Copy link
Member

@vstinner vstinner left a comment

Choose a reason for hiding this comment

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

I ran the test on unmodified Python, it does crash as expected:

test_sendmsg_reentrant_ancillary_mutation (test.test_socket.GeneralModuleTests.test_sendmsg_reentrant_ancillary_mutation) ...
Fatal Python error: Segmentation fault

Co-authored-by: Victor Stinner <vstinner@python.org>
@vstinner vstinner dismissed picnixz’s stale review January 21, 2026 13:32

picnixz's review has been addressed.

@vstinner
Copy link
Member

"All required checks pass" failed with:

Error: The template is not valid. .github/workflows/build.yml (Line: 720, Col: 24): Error reading JToken from JsonReader. Path '', line 0, position 0.

I'm not sure what's going on. Let me try to update this branch, maybe it will magically fix thei ssue?

Copy link
Member

@vstinner vstinner left a comment

Choose a reason for hiding this comment

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

LGTM.

@picnixz: Do you want to double check this PR?

Co-authored-by: Bénédikt Tran <10796600+picnixz@users.noreply.github.com>
@priyanshu2282-cyber
Copy link
Contributor Author

@vstinner @picnixz Is this PR needs any further changes from my side happy to adjust if required.

@vstinner vstinner merged commit 82b92e3 into python:main Feb 13, 2026
47 checks passed
@vstinner vstinner added needs backport to 3.13 bugs and security fixes needs backport to 3.14 bugs and security fixes labels Feb 13, 2026
@miss-islington-app
Copy link

Thanks @priyanshu2282-cyber for the PR, and @vstinner for merging it 🌮🎉.. I'm working now to backport this PR to: 3.13.
🐍🍒⛏🤖

@miss-islington-app
Copy link

Thanks @priyanshu2282-cyber for the PR, and @vstinner for merging it 🌮🎉.. I'm working now to backport this PR to: 3.14.
🐍🍒⛏🤖

miss-islington pushed a commit to miss-islington/cpython that referenced this pull request Feb 13, 2026
…sendmsg() (pythonGH-143892)

(cherry picked from commit 82b92e3)

Co-authored-by: Priyanshu Singh <priyanshu2282@gmail.com>
Co-authored-by: blurb-it[bot] <43283697+blurb-it[bot]@users.noreply.github.com>
Co-authored-by: Victor Stinner <vstinner@python.org>
Co-authored-by: Bénédikt Tran <10796600+picnixz@users.noreply.github.com>
miss-islington pushed a commit to miss-islington/cpython that referenced this pull request Feb 13, 2026
…sendmsg() (pythonGH-143892)

(cherry picked from commit 82b92e3)

Co-authored-by: Priyanshu Singh <priyanshu2282@gmail.com>
Co-authored-by: blurb-it[bot] <43283697+blurb-it[bot]@users.noreply.github.com>
Co-authored-by: Victor Stinner <vstinner@python.org>
Co-authored-by: Bénédikt Tran <10796600+picnixz@users.noreply.github.com>
@bedevere-app
Copy link

bedevere-app bot commented Feb 13, 2026

GH-144785 is a backport of this pull request to the 3.13 branch.

@bedevere-app bedevere-app bot removed the needs backport to 3.13 bugs and security fixes label Feb 13, 2026
@bedevere-app
Copy link

bedevere-app bot commented Feb 13, 2026

GH-144786 is a backport of this pull request to the 3.14 branch.

@bedevere-app bedevere-app bot removed the needs backport to 3.14 bugs and security fixes label Feb 13, 2026
@vstinner
Copy link
Member

Merged, thanks for your fix.

vstinner added a commit that referenced this pull request Feb 13, 2026
….sendmsg() (GH-143892) (#144785)

gh-143637: Fix re-entrant mutation of ancillary data in socket.sendmsg() (GH-143892)
(cherry picked from commit 82b92e3)

Co-authored-by: Priyanshu Singh <priyanshu2282@gmail.com>
Co-authored-by: blurb-it[bot] <43283697+blurb-it[bot]@users.noreply.github.com>
Co-authored-by: Victor Stinner <vstinner@python.org>
Co-authored-by: Bénédikt Tran <10796600+picnixz@users.noreply.github.com>
@priyanshu2282-cyber
Copy link
Contributor Author

Thanks for the review and guidance.

@priyanshu2282-cyber priyanshu2282-cyber deleted the fix-sendmsg-reentrant-cmsg branch February 13, 2026 16:40
vstinner added a commit that referenced this pull request Feb 14, 2026
….sendmsg() (GH-143892) (#144786)

gh-143637: Fix re-entrant mutation of ancillary data in socket.sendmsg() (GH-143892)
(cherry picked from commit 82b92e3)

Co-authored-by: Priyanshu Singh <priyanshu2282@gmail.com>
Co-authored-by: blurb-it[bot] <43283697+blurb-it[bot]@users.noreply.github.com>
Co-authored-by: Victor Stinner <vstinner@python.org>
Co-authored-by: Bénédikt Tran <10796600+picnixz@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants