Commit b1246b8
authored
* Add termination-race UAF reproduction test case
_NOTE: this is a heisenbug reproduction test, and is expected to fail,
but only intermittently, until the underlying issue is fixed._
Includes a script for looping the test under CDB to facilitate detection
and debugging of the intermittent use-after condition as well as
running with page heap enabled to increase likelihood of reproduction.
usage (from admin powershell for page heap):
```
.\tests\test_under_cdb.ps1 -MaxIterations 100 -EnablePageHeap -TestName "*VerifyCompositeTerminationRaceRepro*"
```
Post crash, check `./Out/cdb-dumps/` for log and dump files.
Issue may exhibit as an UAF/AV in production or testing.
* Fix concurrent termination race in XTaskQueue
Addresses heap corruption and access violations when multiple threads
concurrently terminate task queues or invoke nested Terminate() calls
during termination callback processing.
Root Cause:
The termination list (m_terminationList) and pending termination list
(m_pendingTerminationList) were accessed concurrently without proper
synchronization, leading to two critical races:
1. Nested Terminate Race: When a termination callback invokes
XTaskQueueTerminate on another queue, SignalTerminations() would
iterate the list while concurrent modifications occurred, causing
iterator corruption and heap violations.
2. Concurrent ScheduleTermination Race: Multiple threads calling
ScheduleTermination simultaneously would corrupt the lockless queue's
internal state, manifesting as access violations in vector operations.
Changes:
- Added m_terminationLock mutex to TaskQueuePortImpl to serialize all
termination list operations
- Refactored SignalTerminations() to collect entries under lock, then
process callbacks outside the iteration to prevent nested races
- Added AddRef/Release around termination callbacks to prevent UAF if
callback releases the queue
- Protected all m_terminationList and m_pendingTerminationList accesses:
PrepareTermination, CancelTermination, Terminate, ResumeTermination,
ResumePort, ScheduleTermination
- Added TerminationListEmpty() helper for thread-safe empty checks
- Enhanced XTaskQueueTerminate documentation to clarify queue independence
and wait parameter semantics
Testing:
- Stress test with page heap successfully reproduced heap corruption before
fix, clean execution after fix
- Full test suite passes (81/81 tests)
* Fix test bug in VerifyGlobalQueueTermination
Test was not blocking waiting for queue to finish termination, so failed the following `XTaskQueueUninitialize` due to outstanding async work.
1 parent fcbe2e6 commit b1246b8
5 files changed
Lines changed: 502 additions & 36 deletions
File tree
- Include
- Source/Task
- Tests
- UnitTests/Tests
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
185 | 185 | | |
186 | 186 | | |
187 | 187 | | |
| 188 | + | |
| 189 | + | |
| 190 | + | |
| 191 | + | |
| 192 | + | |
| 193 | + | |
| 194 | + | |
| 195 | + | |
| 196 | + | |
| 197 | + | |
| 198 | + | |
| 199 | + | |
| 200 | + | |
| 201 | + | |
| 202 | + | |
| 203 | + | |
| 204 | + | |
| 205 | + | |
| 206 | + | |
| 207 | + | |
| 208 | + | |
188 | 209 | | |
189 | 210 | | |
190 | 211 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
518 | 518 | | |
519 | 519 | | |
520 | 520 | | |
521 | | - | |
| 521 | + | |
| 522 | + | |
| 523 | + | |
| 524 | + | |
522 | 525 | | |
523 | 526 | | |
524 | 527 | | |
| |||
540 | 543 | | |
541 | 544 | | |
542 | 545 | | |
| 546 | + | |
543 | 547 | | |
544 | 548 | | |
545 | 549 | | |
| |||
565 | 569 | | |
566 | 570 | | |
567 | 571 | | |
| 572 | + | |
568 | 573 | | |
569 | 574 | | |
570 | 575 | | |
| |||
687 | 692 | | |
688 | 693 | | |
689 | 694 | | |
690 | | - | |
| 695 | + | |
691 | 696 | | |
692 | 697 | | |
693 | 698 | | |
| |||
749 | 754 | | |
750 | 755 | | |
751 | 756 | | |
752 | | - | |
| 757 | + | |
753 | 758 | | |
754 | 759 | | |
755 | 760 | | |
| |||
825 | 830 | | |
826 | 831 | | |
827 | 832 | | |
828 | | - | |
829 | | - | |
| 833 | + | |
| 834 | + | |
| 835 | + | |
830 | 836 | | |
831 | | - | |
| 837 | + | |
| 838 | + | |
832 | 839 | | |
833 | | - | |
834 | | - | |
835 | | - | |
836 | | - | |
837 | | - | |
838 | | - | |
| 840 | + | |
| 841 | + | |
| 842 | + | |
| 843 | + | |
| 844 | + | |
839 | 845 | | |
840 | | - | |
841 | | - | |
| 846 | + | |
| 847 | + | |
| 848 | + | |
| 849 | + | |
| 850 | + | |
| 851 | + | |
| 852 | + | |
| 853 | + | |
| 854 | + | |
| 855 | + | |
| 856 | + | |
| 857 | + | |
842 | 858 | | |
843 | 859 | | |
844 | 860 | | |
| |||
872 | 888 | | |
873 | 889 | | |
874 | 890 | | |
875 | | - | |
876 | | - | |
877 | | - | |
878 | | - | |
879 | 891 | | |
880 | | - | |
881 | | - | |
882 | | - | |
| 892 | + | |
| 893 | + | |
| 894 | + | |
883 | 895 | | |
884 | | - | |
885 | | - | |
886 | | - | |
| 896 | + | |
| 897 | + | |
| 898 | + | |
| 899 | + | |
| 900 | + | |
| 901 | + | |
| 902 | + | |
| 903 | + | |
| 904 | + | |
| 905 | + | |
887 | 906 | | |
888 | 907 | | |
889 | 908 | | |
| |||
1199 | 1218 | | |
1200 | 1219 | | |
1201 | 1220 | | |
1202 | | - | |
| 1221 | + | |
| 1222 | + | |
| 1223 | + | |
| 1224 | + | |
| 1225 | + | |
1203 | 1226 | | |
1204 | | - | |
| 1227 | + | |
| 1228 | + | |
1205 | 1229 | | |
1206 | | - | |
1207 | | - | |
| 1230 | + | |
| 1231 | + | |
| 1232 | + | |
| 1233 | + | |
| 1234 | + | |
| 1235 | + | |
| 1236 | + | |
| 1237 | + | |
| 1238 | + | |
| 1239 | + | |
| 1240 | + | |
| 1241 | + | |
| 1242 | + | |
| 1243 | + | |
| 1244 | + | |
| 1245 | + | |
| 1246 | + | |
| 1247 | + | |
| 1248 | + | |
| 1249 | + | |
| 1250 | + | |
| 1251 | + | |
| 1252 | + | |
| 1253 | + | |
| 1254 | + | |
| 1255 | + | |
| 1256 | + | |
1208 | 1257 | | |
1209 | | - | |
1210 | | - | |
1211 | 1258 | | |
1212 | | - | |
1213 | | - | |
1214 | | - | |
| 1259 | + | |
| 1260 | + | |
1215 | 1261 | | |
1216 | 1262 | | |
1217 | 1263 | | |
| |||
1225 | 1271 | | |
1226 | 1272 | | |
1227 | 1273 | | |
1228 | | - | |
1229 | | - | |
| 1274 | + | |
| 1275 | + | |
| 1276 | + | |
| 1277 | + | |
| 1278 | + | |
1230 | 1279 | | |
1231 | 1280 | | |
1232 | 1281 | | |
| |||
1236 | 1285 | | |
1237 | 1286 | | |
1238 | 1287 | | |
| 1288 | + | |
| 1289 | + | |
| 1290 | + | |
| 1291 | + | |
| 1292 | + | |
| 1293 | + | |
1239 | 1294 | | |
1240 | 1295 | | |
1241 | 1296 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
262 | 262 | | |
263 | 263 | | |
264 | 264 | | |
| 265 | + | |
265 | 266 | | |
266 | 267 | | |
267 | 268 | | |
| |||
312 | 313 | | |
313 | 314 | | |
314 | 315 | | |
| 316 | + | |
315 | 317 | | |
316 | 318 | | |
317 | 319 | | |
| |||
0 commit comments