Commit efd608f
x86/alternative: Fix race in try_get_desc()
I encountered some occasional crashes of poke_int3_handler() when
kprobes are set, while accessing desc->vec.
The text poke mechanism claims to have an RCU-like behavior, but it
does not appear that there is any quiescent state to ensure that
nobody holds reference to desc. As a result, the following race
appears to be possible, which can lead to memory corruption.
CPU0 CPU1
---- ----
text_poke_bp_batch()
-> smp_store_release(&bp_desc, &desc)
[ notice that desc is on
the stack ]
poke_int3_handler()
[ int3 might be kprobe's
so sync events are do not
help ]
-> try_get_desc(descp=&bp_desc)
desc = __READ_ONCE(bp_desc)
if (!desc) [false, success]
WRITE_ONCE(bp_desc, NULL);
atomic_dec_and_test(&desc.refs)
[ success, desc space on the stack
is being reused and might have
non-zero value. ]
arch_atomic_inc_not_zero(&desc->refs)
[ might succeed since desc points to
stack memory that was freed and might
be reused. ]
Fix this issue with small backportable patch. Instead of trying to
make RCU-like behavior for bp_desc, just eliminate the unnecessary
level of indirection of bp_desc, and hold the whole descriptor as a
global. Anyhow, there is only a single descriptor at any given
moment.
Fixes: 1f67624 ("x86/alternatives: Implement a better poke_int3_handler() completion scheme")
Signed-off-by: Nadav Amit <[email protected]>
Signed-off-by: Peter Zijlstra (Intel) <[email protected]>
Cc: [email protected]
Link: https://lkml.kernel.org/r/[email protected]1 parent e400ad8 commit efd608f
1 file changed
+23
-22
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1319 | 1319 | | |
1320 | 1320 | | |
1321 | 1321 | | |
1322 | | - | |
| 1322 | + | |
1323 | 1323 | | |
1324 | 1324 | | |
1325 | | - | |
| 1325 | + | |
1326 | 1326 | | |
1327 | | - | |
1328 | | - | |
| 1327 | + | |
1329 | 1328 | | |
1330 | | - | |
| 1329 | + | |
1331 | 1330 | | |
1332 | 1331 | | |
1333 | 1332 | | |
1334 | 1333 | | |
1335 | 1334 | | |
1336 | | - | |
| 1335 | + | |
1337 | 1336 | | |
| 1337 | + | |
| 1338 | + | |
1338 | 1339 | | |
1339 | 1340 | | |
1340 | 1341 | | |
| |||
1367 | 1368 | | |
1368 | 1369 | | |
1369 | 1370 | | |
1370 | | - | |
| 1371 | + | |
1371 | 1372 | | |
1372 | | - | |
| 1373 | + | |
1373 | 1374 | | |
1374 | | - | |
| 1375 | + | |
1375 | 1376 | | |
1376 | 1377 | | |
1377 | 1378 | | |
1378 | | - | |
| 1379 | + | |
1379 | 1380 | | |
1380 | 1381 | | |
1381 | 1382 | | |
| |||
1429 | 1430 | | |
1430 | 1431 | | |
1431 | 1432 | | |
1432 | | - | |
| 1433 | + | |
1433 | 1434 | | |
1434 | 1435 | | |
1435 | 1436 | | |
| |||
1460 | 1461 | | |
1461 | 1462 | | |
1462 | 1463 | | |
1463 | | - | |
1464 | | - | |
1465 | | - | |
1466 | | - | |
1467 | | - | |
1468 | 1464 | | |
1469 | 1465 | | |
1470 | 1466 | | |
1471 | 1467 | | |
1472 | 1468 | | |
1473 | 1469 | | |
1474 | | - | |
| 1470 | + | |
| 1471 | + | |
| 1472 | + | |
| 1473 | + | |
| 1474 | + | |
| 1475 | + | |
| 1476 | + | |
| 1477 | + | |
1475 | 1478 | | |
1476 | 1479 | | |
1477 | 1480 | | |
| |||
1559 | 1562 | | |
1560 | 1563 | | |
1561 | 1564 | | |
1562 | | - | |
1563 | | - | |
| 1565 | + | |
1564 | 1566 | | |
1565 | | - | |
1566 | | - | |
1567 | | - | |
| 1567 | + | |
| 1568 | + | |
1568 | 1569 | | |
1569 | 1570 | | |
1570 | 1571 | | |
| |||
0 commit comments