Commit eb0782b
ima: fix deadlock when traversing "ima_default_rules".
The current IMA ruleset is identified by the variable "ima_rules"
that default to "&ima_default_rules". When loading a custom policy
for the first time, the variable is updated to "&ima_policy_rules"
instead. That update isn't RCU-safe, and deadlocks are possible.
Indeed, some functions like ima_match_policy() may loop indefinitely
when traversing "ima_default_rules" with list_for_each_entry_rcu().
When iterating over the default ruleset back to head, if the list
head is "ima_default_rules", and "ima_rules" have been updated to
"&ima_policy_rules", the loop condition (&entry->list != ima_rules)
stays always true, traversing won't terminate, causing a soft lockup
and RCU stalls.
Introduce a temporary value for "ima_rules" when iterating over
the ruleset to avoid the deadlocks.
Signed-off-by: liqiong <liqiong@nfschina.com>
Reviewed-by: THOBY Simon <Simon.THOBY@viveris.fr>
Fixes: 38d859f ("IMA: policy can now be updated multiple times")
Reported-by: kernel test robot <lkp@intel.com> (Fix sparse: incompatible types in comparison expression.)
Signed-off-by: Mimi Zohar <zohar@linux.ibm.com>1 parent 6880fa6 commit eb0782b
1 file changed
Lines changed: 18 additions & 9 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
228 | 228 | | |
229 | 229 | | |
230 | 230 | | |
231 | | - | |
| 231 | + | |
232 | 232 | | |
233 | 233 | | |
234 | 234 | | |
| |||
675 | 675 | | |
676 | 676 | | |
677 | 677 | | |
| 678 | + | |
678 | 679 | | |
679 | 680 | | |
680 | 681 | | |
681 | 682 | | |
682 | 683 | | |
683 | | - | |
| 684 | + | |
| 685 | + | |
684 | 686 | | |
685 | 687 | | |
686 | 688 | | |
| |||
741 | 743 | | |
742 | 744 | | |
743 | 745 | | |
| 746 | + | |
744 | 747 | | |
745 | 748 | | |
746 | | - | |
| 749 | + | |
| 750 | + | |
747 | 751 | | |
748 | 752 | | |
749 | 753 | | |
| |||
968 | 972 | | |
969 | 973 | | |
970 | 974 | | |
971 | | - | |
| 975 | + | |
972 | 976 | | |
973 | | - | |
974 | 977 | | |
| 978 | + | |
975 | 979 | | |
976 | 980 | | |
977 | 981 | | |
| |||
1061 | 1065 | | |
1062 | 1066 | | |
1063 | 1067 | | |
1064 | | - | |
| 1068 | + | |
1065 | 1069 | | |
1066 | 1070 | | |
1067 | 1071 | | |
| |||
1768 | 1772 | | |
1769 | 1773 | | |
1770 | 1774 | | |
| 1775 | + | |
1771 | 1776 | | |
1772 | 1777 | | |
1773 | | - | |
| 1778 | + | |
| 1779 | + | |
1774 | 1780 | | |
1775 | 1781 | | |
1776 | 1782 | | |
| |||
1789 | 1795 | | |
1790 | 1796 | | |
1791 | 1797 | | |
1792 | | - | |
| 1798 | + | |
| 1799 | + | |
1793 | 1800 | | |
1794 | 1801 | | |
1795 | 1802 | | |
| |||
2014 | 2021 | | |
2015 | 2022 | | |
2016 | 2023 | | |
| 2024 | + | |
2017 | 2025 | | |
2018 | 2026 | | |
2019 | 2027 | | |
2020 | 2028 | | |
2021 | 2029 | | |
2022 | 2030 | | |
2023 | 2031 | | |
2024 | | - | |
| 2032 | + | |
| 2033 | + | |
2025 | 2034 | | |
2026 | 2035 | | |
2027 | 2036 | | |
| |||
0 commit comments