Commit 4b592ef
committed
gh-143988: Fix re-entrant mutation crashes in socket sendmsg/recvmsg_into via __buffer__
Fix crashes in socket.sendmsg() and socket.recvmsg_into() that could
occur if buffer sequences are mutated re-entrantly during argument
parsing via __buffer__ protocol callbacks.
The vulnerability occurs because:
1. PySequence_Fast() returns the original list object when the input
is already a list (not a copy)
2. During iteration, PyObject_GetBuffer() triggers __buffer__
callbacks which may clear the list
3. Subsequent iterations access invalid memory (heap OOB read)
The fix replaces PySequence_Fast() with PySequence_Tuple() which
always creates a new tuple, ensuring the sequence cannot be mutated
during iteration.
This addresses two vulnerabilities related to gh-143637:
- sendmsg() argument 1 (data buffers) - via __buffer__
- recvmsg_into() argument 1 (buffers) - via __buffer__1 parent 63cc125 commit 4b592ef
File tree
3 files changed
+81
-10
lines changed- Lib/test
- Misc/NEWS.d/next/Security
- Modules
3 files changed
+81
-10
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
7491 | 7491 | | |
7492 | 7492 | | |
7493 | 7493 | | |
| 7494 | + | |
| 7495 | + | |
| 7496 | + | |
| 7497 | + | |
| 7498 | + | |
| 7499 | + | |
| 7500 | + | |
| 7501 | + | |
| 7502 | + | |
| 7503 | + | |
| 7504 | + | |
| 7505 | + | |
| 7506 | + | |
| 7507 | + | |
| 7508 | + | |
| 7509 | + | |
| 7510 | + | |
| 7511 | + | |
| 7512 | + | |
| 7513 | + | |
| 7514 | + | |
| 7515 | + | |
| 7516 | + | |
| 7517 | + | |
| 7518 | + | |
| 7519 | + | |
| 7520 | + | |
| 7521 | + | |
| 7522 | + | |
| 7523 | + | |
| 7524 | + | |
| 7525 | + | |
| 7526 | + | |
| 7527 | + | |
| 7528 | + | |
| 7529 | + | |
| 7530 | + | |
| 7531 | + | |
| 7532 | + | |
| 7533 | + | |
| 7534 | + | |
| 7535 | + | |
| 7536 | + | |
| 7537 | + | |
| 7538 | + | |
| 7539 | + | |
| 7540 | + | |
| 7541 | + | |
| 7542 | + | |
| 7543 | + | |
| 7544 | + | |
| 7545 | + | |
| 7546 | + | |
| 7547 | + | |
| 7548 | + | |
| 7549 | + | |
| 7550 | + | |
| 7551 | + | |
| 7552 | + | |
| 7553 | + | |
| 7554 | + | |
| 7555 | + | |
| 7556 | + | |
| 7557 | + | |
| 7558 | + | |
| 7559 | + | |
7494 | 7560 | | |
7495 | 7561 | | |
7496 | 7562 | | |
| |||
Lines changed: 3 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
4527 | 4527 | | |
4528 | 4528 | | |
4529 | 4529 | | |
4530 | | - | |
4531 | | - | |
4532 | | - | |
| 4530 | + | |
| 4531 | + | |
| 4532 | + | |
| 4533 | + | |
4533 | 4534 | | |
4534 | | - | |
| 4535 | + | |
| 4536 | + | |
4535 | 4537 | | |
4536 | 4538 | | |
4537 | 4539 | | |
| |||
4545 | 4547 | | |
4546 | 4548 | | |
4547 | 4549 | | |
4548 | | - | |
| 4550 | + | |
4549 | 4551 | | |
4550 | 4552 | | |
4551 | 4553 | | |
| |||
4854 | 4856 | | |
4855 | 4857 | | |
4856 | 4858 | | |
4857 | | - | |
4858 | | - | |
4859 | | - | |
| 4859 | + | |
4860 | 4860 | | |
| 4861 | + | |
| 4862 | + | |
4861 | 4863 | | |
4862 | 4864 | | |
4863 | 4865 | | |
4864 | | - | |
| 4866 | + | |
4865 | 4867 | | |
4866 | 4868 | | |
4867 | 4869 | | |
| |||
4883 | 4885 | | |
4884 | 4886 | | |
4885 | 4887 | | |
4886 | | - | |
| 4888 | + | |
4887 | 4889 | | |
4888 | 4890 | | |
4889 | 4891 | | |
| |||
0 commit comments