Repository navigation
Commit c1228dd
committed
[smart][lwp] validate IPC object ownership in syscalls
Fix #11960
A user-supplied handle is a raw pointer, and the operation syscalls used to
forward it to rt_sem_*/rt_mutex_*/rt_event_*/rt_mb_*/rt_mq_*/rt_timer_*
directly. A forged object placed in a user mapping page (type field set to
the expected class, pointers aimed at arbitrary kernel memory) therefore
reached the kernel IPC implementation; RT_ASSERT(type) only checks the
value the attacker wrote.
Add lwp_user_object_get(): the handle must be a kernel address registered
in the calling LWP's user-object AVL, its rt_object_get_type() must match
the expected class, and a reference is taken on success. The reference is
released with lwp_user_object_put() when the syscall finishes, including
all error paths. lwp_ref_count now counts both LWP ownership and in-flight
syscall references, so an object is destroyed only when the last of them
is gone; when a delete races with a blocking operation, the kernel object
survives until the operation returns, then _object_destroy() runs.
Cover sem_take/release, mutex_take/release, event_send/recv, mb_send,
mb_send_wait, mb_recv, mq_send/urgent/recv and timer start/stop/control.
The whole family is fixed rather than only mailbox because all of them
share the same unchecked-handle pattern and the same object lifetime.
create validates through lwp_user_object_add(). delete goes through
lwp_user_object_delete(), which now resumes the threads blocked on the
object with RT_ERROR before the handle is detached, so RT_WAITING_FOREVER
waiters return from their syscall instead of hanging forever. The kernel
object itself is still destroyed only when the last reference is gone.
sys_rt_timer_control() no longer forwards the raw user arg pointer either:
GET_TIME/GET_REMAIN_TIME/GET_STATE/GET_PARM copy the result out with
lwp_put_to_user(), SET_TIME copies the tick in with lwp_get_from_user(),
SET_PARM passes the value through, and SET_FUNC, GET_FUNC, and unknown
commands are rejected with -EINVAL instead of dereferencing user memory or
exposing kernel function addresses.
Non-blocking review follow-ups (BernardXiong):
- Reject RT_TIMER_CTRL_GET_FUNC with -EINVAL like SET_FUNC while keeping
GET_PARM unchanged.
- Document the remaining constraints directly in lwp_user_object_delete()
next to _object_wakeup_waiters(): force-kill/process-exit paths do not
return to lwp_user_object_put(), and a concurrent thread that finished
lwp_user_object_get() before queuing on suspend_thread can miss the
delete wakeup and stay blocked holding its reference; no per-thread
reference tracking framework is introduced.1 parent 95e82ec commit c1228dd
3 files changed
Lines changed: 459 additions & 44 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
529 | 529 | | |
530 | 530 | | |
531 | 531 | | |
| 532 | + | |
| 533 | + | |
| 534 | + | |
| 535 | + | |
| 536 | + | |
| 537 | + | |
| 538 | + | |
| 539 | + | |
| 540 | + | |
| 541 | + | |
| 542 | + | |
| 543 | + | |
| 544 | + | |
| 545 | + | |
| 546 | + | |
| 547 | + | |
| 548 | + | |
| 549 | + | |
| 550 | + | |
| 551 | + | |
| 552 | + | |
| 553 | + | |
| 554 | + | |
| 555 | + | |
| 556 | + | |
| 557 | + | |
| 558 | + | |
| 559 | + | |
| 560 | + | |
| 561 | + | |
| 562 | + | |
| 563 | + | |
| 564 | + | |
| 565 | + | |
| 566 | + | |
| 567 | + | |
| 568 | + | |
| 569 | + | |
| 570 | + | |
| 571 | + | |
| 572 | + | |
| 573 | + | |
| 574 | + | |
| 575 | + | |
| 576 | + | |
| 577 | + | |
| 578 | + | |
| 579 | + | |
| 580 | + | |
| 581 | + | |
| 582 | + | |
| 583 | + | |
| 584 | + | |
| 585 | + | |
| 586 | + | |
| 587 | + | |
| 588 | + | |
| 589 | + | |
| 590 | + | |
| 591 | + | |
| 592 | + | |
| 593 | + | |
| 594 | + | |
| 595 | + | |
| 596 | + | |
| 597 | + | |
| 598 | + | |
| 599 | + | |
| 600 | + | |
| 601 | + | |
| 602 | + | |
| 603 | + | |
| 604 | + | |
| 605 | + | |
| 606 | + | |
| 607 | + | |
| 608 | + | |
| 609 | + | |
| 610 | + | |
| 611 | + | |
| 612 | + | |
| 613 | + | |
| 614 | + | |
| 615 | + | |
| 616 | + | |
| 617 | + | |
| 618 | + | |
| 619 | + | |
| 620 | + | |
| 621 | + | |
| 622 | + | |
| 623 | + | |
| 624 | + | |
| 625 | + | |
| 626 | + | |
| 627 | + | |
| 628 | + | |
| 629 | + | |
| 630 | + | |
| 631 | + | |
| 632 | + | |
| 633 | + | |
| 634 | + | |
| 635 | + | |
| 636 | + | |
| 637 | + | |
| 638 | + | |
| 639 | + | |
| 640 | + | |
| 641 | + | |
| 642 | + | |
| 643 | + | |
| 644 | + | |
| 645 | + | |
| 646 | + | |
| 647 | + | |
| 648 | + | |
| 649 | + | |
| 650 | + | |
| 651 | + | |
| 652 | + | |
| 653 | + | |
532 | 654 | | |
533 | 655 | | |
534 | 656 | | |
| |||
547 | 669 | | |
548 | 670 | | |
549 | 671 | | |
550 | | - | |
551 | | - | |
| 672 | + | |
552 | 673 | | |
553 | 674 | | |
554 | | - | |
555 | | - | |
556 | | - | |
557 | | - | |
558 | | - | |
559 | | - | |
560 | | - | |
561 | | - | |
562 | | - | |
563 | | - | |
564 | | - | |
565 | | - | |
566 | | - | |
567 | | - | |
568 | | - | |
569 | | - | |
570 | | - | |
571 | | - | |
572 | | - | |
573 | | - | |
574 | | - | |
575 | | - | |
576 | | - | |
577 | | - | |
578 | | - | |
579 | | - | |
580 | | - | |
| 675 | + | |
581 | 676 | | |
582 | 677 | | |
583 | 678 | | |
| 679 | + | |
584 | 680 | | |
585 | 681 | | |
586 | 682 | | |
| |||
606 | 702 | | |
607 | 703 | | |
608 | 704 | | |
| 705 | + | |
| 706 | + | |
| 707 | + | |
| 708 | + | |
| 709 | + | |
| 710 | + | |
| 711 | + | |
| 712 | + | |
| 713 | + | |
| 714 | + | |
| 715 | + | |
| 716 | + | |
| 717 | + | |
| 718 | + | |
| 719 | + | |
609 | 720 | | |
610 | 721 | | |
611 | 722 | | |
612 | 723 | | |
613 | 724 | | |
614 | 725 | | |
| 726 | + | |
| 727 | + | |
| 728 | + | |
| 729 | + | |
| 730 | + | |
| 731 | + | |
| 732 | + | |
| 733 | + | |
| 734 | + | |
| 735 | + | |
| 736 | + | |
| 737 | + | |
| 738 | + | |
| 739 | + | |
| 740 | + | |
| 741 | + | |
| 742 | + | |
| 743 | + | |
| 744 | + | |
| 745 | + | |
| 746 | + | |
| 747 | + | |
| 748 | + | |
| 749 | + | |
| 750 | + | |
| 751 | + | |
| 752 | + | |
| 753 | + | |
| 754 | + | |
| 755 | + | |
| 756 | + | |
| 757 | + | |
| 758 | + | |
| 759 | + | |
| 760 | + | |
| 761 | + | |
| 762 | + | |
| 763 | + | |
| 764 | + | |
| 765 | + | |
| 766 | + | |
| 767 | + | |
| 768 | + | |
| 769 | + | |
| 770 | + | |
| 771 | + | |
| 772 | + | |
| 773 | + | |
| 774 | + | |
| 775 | + | |
| 776 | + | |
| 777 | + | |
| 778 | + | |
| 779 | + | |
| 780 | + | |
| 781 | + | |
| 782 | + | |
| 783 | + | |
| 784 | + | |
615 | 785 | | |
616 | 786 | | |
617 | 787 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
101 | 101 | | |
102 | 102 | | |
103 | 103 | | |
| 104 | + | |
| 105 | + | |
104 | 106 | | |
105 | 107 | | |
106 | 108 | | |
| |||
0 commit comments