Commit 78c18ed
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 78c18ed
File tree
3 files changed
+103
-10
lines changed- Lib/test
- Misc/NEWS.d/next/Security
- Modules
3 files changed
+103
-10
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
| 20 | + | |
| 21 | + | |
| 22 | + | |
| 23 | + | |
| 24 | + | |
| 25 | + | |
| 26 | + | |
| 27 | + | |
| 28 | + | |
| 29 | + | |
| 30 | + | |
| 31 | + | |
| 32 | + | |
| 33 | + | |
| 34 | + | |
| 35 | + | |
| 36 | + | |
| 37 | + | |
| 38 | + | |
| 39 | + | |
| 40 | + | |
| 41 | + | |
| 42 | + | |
| 43 | + | |
| 44 | + | |
| 45 | + | |
| 46 | + | |
| 47 | + | |
| 48 | + | |
| 49 | + | |
| 50 | + | |
| 51 | + | |
| 52 | + | |
| 53 | + | |
| 54 | + | |
| 55 | + | |
| 56 | + | |
| 57 | + | |
| 58 | + | |
| 59 | + | |
| 60 | + | |
| 61 | + | |
| 62 | + | |
| 63 | + | |
| 64 | + | |
| 65 | + | |
| 66 | + | |
| 67 | + | |
| 68 | + | |
| 69 | + | |
| 70 | + | |
| 71 | + | |
| 72 | + | |
| 73 | + | |
| 74 | + | |
| 75 | + | |
| 76 | + | |
| 77 | + | |
| 78 | + | |
| 79 | + | |
| 80 | + | |
| 81 | + | |
| 82 | + | |
| 83 | + | |
| 84 | + | |
| 85 | + | |
| 86 | + | |
| 87 | + | |
| 88 | + | |
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