Commit 14e526a
Anandu Krishnan E
FROMLIST: misc: fastrpc: Add reference counting for fastrpc_user structure
Add reference counting using kref to the fastrpc_user structure to
prevent use-after-free issues when contexts are freed from workqueue
after device release.
The issue occurs when fastrpc_device_release() frees the user structure
while invoke contexts are still pending in the workqueue. When the
workqueue later calls fastrpc_context_free(), it attempts to access
buf->fl->cctx in fastrpc_buf_free(), leading to a use-after-free:
pc : fastrpc_buf_free+0x38/0x80 [fastrpc]
lr : fastrpc_context_free+0xa8/0x1b0 [fastrpc]
...
fastrpc_context_free+0xa8/0x1b0 [fastrpc]
fastrpc_context_put_wq+0x78/0xa0 [fastrpc]
process_one_work+0x180/0x450
worker_thread+0x26c/0x388
Implement proper reference counting to fix this:
- Initialize kref in fastrpc_device_open()
- Take a reference in fastrpc_context_alloc() for each context
- Release the reference in fastrpc_context_free() when context is freed
- Release the initial reference in fastrpc_device_release()
This ensures the user structure remains valid as long as there are
contexts holding references to it, preventing the race condition.
Link: https://lore.kernel.org/all/20260226151121.818852-1-anandu.e@oss.qualcomm.com/
Signed-off-by: Anandu Krishnan E <anandu.e@oss.qualcomm.com>1 parent 1cefa86 commit 14e526a
1 file changed
Lines changed: 31 additions & 4 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
327 | 327 | | |
328 | 328 | | |
329 | 329 | | |
| 330 | + | |
| 331 | + | |
330 | 332 | | |
331 | 333 | | |
332 | 334 | | |
| |||
495 | 497 | | |
496 | 498 | | |
497 | 499 | | |
| 500 | + | |
| 501 | + | |
| 502 | + | |
| 503 | + | |
| 504 | + | |
| 505 | + | |
| 506 | + | |
| 507 | + | |
| 508 | + | |
| 509 | + | |
| 510 | + | |
| 511 | + | |
| 512 | + | |
| 513 | + | |
| 514 | + | |
| 515 | + | |
| 516 | + | |
| 517 | + | |
| 518 | + | |
498 | 519 | | |
499 | 520 | | |
500 | 521 | | |
501 | 522 | | |
| 523 | + | |
502 | 524 | | |
503 | 525 | | |
504 | 526 | | |
505 | 527 | | |
506 | 528 | | |
| 529 | + | |
507 | 530 | | |
508 | 531 | | |
509 | 532 | | |
| |||
519 | 542 | | |
520 | 543 | | |
521 | 544 | | |
| 545 | + | |
| 546 | + | |
522 | 547 | | |
523 | 548 | | |
524 | 549 | | |
| |||
628 | 653 | | |
629 | 654 | | |
630 | 655 | | |
| 656 | + | |
| 657 | + | |
631 | 658 | | |
632 | 659 | | |
633 | 660 | | |
| |||
658 | 685 | | |
659 | 686 | | |
660 | 687 | | |
| 688 | + | |
661 | 689 | | |
662 | 690 | | |
663 | 691 | | |
| |||
1675 | 1703 | | |
1676 | 1704 | | |
1677 | 1705 | | |
1678 | | - | |
1679 | | - | |
1680 | | - | |
1681 | | - | |
1682 | 1706 | | |
| 1707 | + | |
| 1708 | + | |
1683 | 1709 | | |
1684 | 1710 | | |
1685 | 1711 | | |
| |||
1723 | 1749 | | |
1724 | 1750 | | |
1725 | 1751 | | |
| 1752 | + | |
1726 | 1753 | | |
1727 | 1754 | | |
1728 | 1755 | | |
| |||
0 commit comments