Commit abc10f8
atm: lec: fix use-after-free in sock_def_readable()
[ Upstream commit 9228148 ]
A race condition exists between lec_atm_close() setting priv->lecd
to NULL and concurrent access to priv->lecd in send_to_lecd(),
lec_handle_bridge(), and lec_atm_send(). When the socket is freed
via RCU while another thread is still using it, a use-after-free
occurs in sock_def_readable() when accessing the socket's wait queue.
The root cause is that lec_atm_close() clears priv->lecd without
any synchronization, while callers dereference priv->lecd without
any protection against concurrent teardown.
Fix this by converting priv->lecd to an RCU-protected pointer:
- Mark priv->lecd as __rcu in lec.h
- Use rcu_assign_pointer() in lec_atm_close() and lecd_attach()
for safe pointer assignment
- Use rcu_access_pointer() for NULL checks that do not dereference
the pointer in lec_start_xmit(), lec_push(), send_to_lecd() and
lecd_attach()
- Use rcu_read_lock/rcu_dereference/rcu_read_unlock in send_to_lecd(),
lec_handle_bridge() and lec_atm_send() to safely access lecd
- Use rcu_assign_pointer() followed by synchronize_rcu() in
lec_atm_close() to ensure all readers have completed before
proceeding. This is safe since lec_atm_close() is called from
vcc_release() which holds lock_sock(), a sleeping lock.
- Remove the manual sk_receive_queue drain from lec_atm_close()
since vcc_destroy_socket() already drains it after lec_atm_close()
returns.
v2: Switch from spinlock + sock_hold/put approach to RCU to properly
fix the race. The v1 spinlock approach had two issues pointed out
by Eric Dumazet:
1. priv->lecd was still accessed directly after releasing the
lock instead of using a local copy.
2. The spinlock did not prevent packets being queued after
lec_atm_close() drains sk_receive_queue since timer and
workqueue paths bypass netif_stop_queue().
Note: Syzbot patch testing was attempted but the test VM terminated
unexpectedly with "Connection to localhost closed by remote host",
likely due to a QEMU AHCI emulation issue unrelated to this fix.
Compile testing with "make W=1 net/atm/lec.o" passes cleanly.
Reported-by: syzbot+f50072212ab792c86925@syzkaller.appspotmail.com
Closes: https://syzkaller.appspot.com/bug?extid=f50072212ab792c86925
Link: https://lore.kernel.org/all/20260309093614.502094-1-kartikey406@gmail.com/T/ [v1]
Signed-off-by: Deepanshu Kartikey <kartikey406@gmail.com>
Reviewed-by: Eric Dumazet <edumazet@google.com>
Link: https://patch.msgid.link/20260309155908.508768-1-kartikey406@gmail.com
Signed-off-by: Jakub Kicinski <kuba@kernel.org>
Signed-off-by: Sasha Levin <sashal@kernel.org>1 parent c8dc23c commit abc10f8
2 files changed
Lines changed: 48 additions & 26 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
154 | 154 | | |
155 | 155 | | |
156 | 156 | | |
157 | | - | |
158 | | - | |
159 | | - | |
160 | | - | |
| 157 | + | |
| 158 | + | |
| 159 | + | |
| 160 | + | |
| 161 | + | |
| 162 | + | |
| 163 | + | |
| 164 | + | |
| 165 | + | |
| 166 | + | |
| 167 | + | |
| 168 | + | |
| 169 | + | |
161 | 170 | | |
162 | 171 | | |
163 | 172 | | |
| |||
216 | 225 | | |
217 | 226 | | |
218 | 227 | | |
219 | | - | |
| 228 | + | |
220 | 229 | | |
221 | 230 | | |
222 | 231 | | |
| |||
449 | 458 | | |
450 | 459 | | |
451 | 460 | | |
452 | | - | |
453 | | - | |
454 | | - | |
455 | | - | |
| 461 | + | |
| 462 | + | |
| 463 | + | |
| 464 | + | |
| 465 | + | |
| 466 | + | |
| 467 | + | |
| 468 | + | |
| 469 | + | |
| 470 | + | |
| 471 | + | |
| 472 | + | |
| 473 | + | |
456 | 474 | | |
457 | 475 | | |
458 | 476 | | |
| |||
468 | 486 | | |
469 | 487 | | |
470 | 488 | | |
471 | | - | |
472 | 489 | | |
473 | 490 | | |
474 | 491 | | |
475 | | - | |
| 492 | + | |
| 493 | + | |
476 | 494 | | |
477 | 495 | | |
478 | 496 | | |
479 | 497 | | |
480 | 498 | | |
481 | | - | |
482 | | - | |
483 | | - | |
484 | | - | |
485 | | - | |
486 | | - | |
487 | | - | |
488 | 499 | | |
489 | 500 | | |
490 | 501 | | |
| |||
510 | 521 | | |
511 | 522 | | |
512 | 523 | | |
| 524 | + | |
513 | 525 | | |
514 | 526 | | |
515 | 527 | | |
516 | 528 | | |
517 | | - | |
| 529 | + | |
518 | 530 | | |
| 531 | + | |
519 | 532 | | |
520 | 533 | | |
521 | 534 | | |
| |||
532 | 545 | | |
533 | 546 | | |
534 | 547 | | |
535 | | - | |
536 | | - | |
| 548 | + | |
| 549 | + | |
| 550 | + | |
| 551 | + | |
| 552 | + | |
| 553 | + | |
| 554 | + | |
| 555 | + | |
| 556 | + | |
| 557 | + | |
537 | 558 | | |
538 | 559 | | |
539 | 560 | | |
540 | 561 | | |
541 | 562 | | |
542 | | - | |
| 563 | + | |
543 | 564 | | |
544 | 565 | | |
545 | 566 | | |
546 | 567 | | |
| 568 | + | |
547 | 569 | | |
548 | 570 | | |
549 | 571 | | |
| |||
618 | 640 | | |
619 | 641 | | |
620 | 642 | | |
621 | | - | |
| 643 | + | |
622 | 644 | | |
623 | 645 | | |
624 | 646 | | |
| |||
753 | 775 | | |
754 | 776 | | |
755 | 777 | | |
756 | | - | |
| 778 | + | |
757 | 779 | | |
758 | 780 | | |
759 | 781 | | |
760 | 782 | | |
761 | | - | |
| 783 | + | |
762 | 784 | | |
763 | 785 | | |
764 | 786 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
91 | 91 | | |
92 | 92 | | |
93 | 93 | | |
94 | | - | |
| 94 | + | |
95 | 95 | | |
96 | 96 | | |
97 | 97 | | |
| |||
0 commit comments