Skip to content

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
Co-authored-by: Victor Stinner <vstinner@python.org>
priyanshu2282-cyber and others added 2 commits January 20, 2026 17:43
Co-authored-by: Victor Stinner <vstinner@python.org>
class GeneralModuleTests(unittest.TestCase):

@unittest.skipUnless(hasattr(socket.socket, "sendmsg"),"sendmsg not supported")
def test_sendmsg_reentrant_ancillary_mutation(self):
Copy link
Member

Choose a reason for hiding this comment

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

New tests are added at the end of the class (GeneralModuleTests).

Copy link
Contributor Author

Choose a reason for hiding this comment

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

done, I have put the test at the end.

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?

controllen = controllen_last = 0;
while (ncmsgbufs < ncmsgs) {
size_t bufsize, space;
PyObject *item = PyTuple_GET_ITEM(cmsg_fast, ncmsgbufs);
Copy link
Member

Choose a reason for hiding this comment

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

Why did we need a temporary variable here?

Copy link
Member

Choose a reason for hiding this comment

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

IMO it makes the code more readable and so the change is worth it.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

If we storeit in a temporary variable that makes the call clearer and avoids repeating a long expression, happy to keep it in a single line without temporary variable if needed.

Copy link
Member

Choose a reason for hiding this comment

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

I would prefer reducing the diff but ok for the temporary variable.

Copy link
Member

Choose a reason for hiding this comment

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

I would prefer reducing the diff but ok for the temporary variable.

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

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants