Commit c7f7c37
committed
thermal/debugfs: Fix two locking issues with thermal zone debug
With the current thermal zone locking arrangement in the debugfs code,
user space can open the "mitigations" file for a thermal zone before
the zone's debugfs pointer is set which will result in a NULL pointer
dereference in tze_seq_start().
Moreover, thermal_debug_tz_remove() is not called under the thermal
zone lock, so it can run in parallel with the other functions accessing
the thermal zone's struct thermal_debugfs object. Then, it may clear
tz->debugfs after one of those functions has checked it and the
struct thermal_debugfs object may be freed prematurely.
To address the first problem, pass a pointer to the thermal zone's
struct thermal_debugfs object to debugfs_create_file() in
thermal_debug_tz_add() and make tze_seq_start(), tze_seq_next(),
tze_seq_stop(), and tze_seq_show() retrieve it from s->private
instead of a pointer to the thermal zone object. This will ensure
that tz_debugfs will be valid across the "mitigations" file accesses
until thermal_debugfs_remove_id() called by thermal_debug_tz_remove()
removes that file.
To address the second problem, use tz->lock in thermal_debug_tz_remove()
around the tz->debugfs value check (in case the same thermal zone is
removed at the same time in two different threads) and its reset to NULL.
Fixes: 7ef01f2 ("thermal/debugfs: Add thermal debugfs information for mitigation episodes")
Cc :6.8+ <[email protected]> # 6.8+
Signed-off-by: Rafael J. Wysocki <[email protected]>
Reviewed-by: Lukasz Luba <[email protected]>1 parent 72c1aff commit c7f7c37
1 file changed
+22
-12
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
139 | 139 | | |
140 | 140 | | |
141 | 141 | | |
| 142 | + | |
142 | 143 | | |
143 | 144 | | |
144 | 145 | | |
145 | 146 | | |
146 | 147 | | |
| 148 | + | |
147 | 149 | | |
148 | 150 | | |
149 | 151 | | |
| |||
716 | 718 | | |
717 | 719 | | |
718 | 720 | | |
719 | | - | |
720 | | - | |
| 721 | + | |
721 | 722 | | |
722 | 723 | | |
723 | 724 | | |
| |||
727 | 728 | | |
728 | 729 | | |
729 | 730 | | |
730 | | - | |
731 | | - | |
| 731 | + | |
732 | 732 | | |
733 | 733 | | |
734 | 734 | | |
735 | 735 | | |
736 | 736 | | |
737 | 737 | | |
738 | 738 | | |
739 | | - | |
740 | | - | |
| 739 | + | |
741 | 740 | | |
742 | 741 | | |
743 | 742 | | |
744 | 743 | | |
745 | 744 | | |
746 | 745 | | |
747 | | - | |
| 746 | + | |
| 747 | + | |
748 | 748 | | |
749 | 749 | | |
750 | 750 | | |
| |||
810 | 810 | | |
811 | 811 | | |
812 | 812 | | |
| 813 | + | |
| 814 | + | |
813 | 815 | | |
814 | 816 | | |
815 | 817 | | |
| |||
818 | 820 | | |
819 | 821 | | |
820 | 822 | | |
821 | | - | |
| 823 | + | |
| 824 | + | |
822 | 825 | | |
823 | 826 | | |
824 | 827 | | |
825 | 828 | | |
826 | 829 | | |
827 | 830 | | |
828 | | - | |
| 831 | + | |
829 | 832 | | |
830 | 833 | | |
831 | 834 | | |
832 | 835 | | |
833 | | - | |
| 836 | + | |
| 837 | + | |
| 838 | + | |
| 839 | + | |
| 840 | + | |
834 | 841 | | |
| 842 | + | |
| 843 | + | |
| 844 | + | |
| 845 | + | |
| 846 | + | |
835 | 847 | | |
836 | 848 | | |
837 | 849 | | |
| |||
844 | 856 | | |
845 | 857 | | |
846 | 858 | | |
847 | | - | |
848 | | - | |
849 | 859 | | |
850 | 860 | | |
851 | 861 | | |
| |||
0 commit comments