Commit 2ac3a10
spi: tegra210-quad: Protect curr_xfer check in IRQ handler
[ Upstream commit edf9088 ]
Now that all other accesses to curr_xfer are done under the lock,
protect the curr_xfer NULL check in tegra_qspi_isr_thread() with the
spinlock. Without this protection, the following race can occur:
CPU0 (ISR thread) CPU1 (timeout path)
---------------- -------------------
if (!tqspi->curr_xfer)
// sees non-NULL
spin_lock()
tqspi->curr_xfer = NULL
spin_unlock()
handle_*_xfer()
spin_lock()
t = tqspi->curr_xfer // NULL!
... t->len ... // NULL dereference!
With this patch, all curr_xfer accesses are now properly synchronized.
Although all accesses to curr_xfer are done under the lock, in
tegra_qspi_isr_thread() it checks for NULL, releases the lock and
reacquires it later in handle_cpu_based_xfer()/handle_dma_based_xfer().
There is a potential for an update in between, which could cause a NULL
pointer dereference.
To handle this, add a NULL check inside the handlers after acquiring
the lock. This ensures that if the timeout path has already cleared
curr_xfer, the handler will safely return without dereferencing the
NULL pointer.
Fixes: b4e002d ("spi: tegra210-quad: Fix timeout handling")
Signed-off-by: Breno Leitao <[email protected]>
Tested-by: Jon Hunter <[email protected]>
Acked-by: Jon Hunter <[email protected]>
Acked-by: Thierry Reding <[email protected]>
Link: https://patch.msgid.link/[email protected]
Signed-off-by: Mark Brown <[email protected]>
Signed-off-by: Sasha Levin <[email protected]>1 parent d51554d commit 2ac3a10
1 file changed
Lines changed: 20 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1393 | 1393 | | |
1394 | 1394 | | |
1395 | 1395 | | |
| 1396 | + | |
| 1397 | + | |
| 1398 | + | |
| 1399 | + | |
| 1400 | + | |
1396 | 1401 | | |
1397 | 1402 | | |
1398 | 1403 | | |
| |||
1463 | 1468 | | |
1464 | 1469 | | |
1465 | 1470 | | |
| 1471 | + | |
| 1472 | + | |
| 1473 | + | |
| 1474 | + | |
| 1475 | + | |
1466 | 1476 | | |
1467 | 1477 | | |
1468 | 1478 | | |
| |||
1501 | 1511 | | |
1502 | 1512 | | |
1503 | 1513 | | |
| 1514 | + | |
1504 | 1515 | | |
1505 | 1516 | | |
1506 | 1517 | | |
| |||
1518 | 1529 | | |
1519 | 1530 | | |
1520 | 1531 | | |
| 1532 | + | |
1521 | 1533 | | |
| 1534 | + | |
1522 | 1535 | | |
1523 | 1536 | | |
1524 | 1537 | | |
| |||
1535 | 1548 | | |
1536 | 1549 | | |
1537 | 1550 | | |
| 1551 | + | |
1538 | 1552 | | |
| 1553 | + | |
| 1554 | + | |
| 1555 | + | |
| 1556 | + | |
| 1557 | + | |
| 1558 | + | |
1539 | 1559 | | |
1540 | 1560 | | |
1541 | 1561 | | |
| |||
0 commit comments