Commit 0517374
can: isotp: fix race between isotp_sendsmg() and isotp_release()
As discussed with Dae R. Jeong and Hillf Danton here [1] the sendmsg()
function in isotp.c might get into a race condition when restoring the
former tx.state from the old_state.
Remove the old_state concept and implement proper locking for the
ISOTP_IDLE transitions in isotp_sendmsg(), inspired by a
simplification idea from Hillf Danton.
Introduce a new tx.state ISOTP_SHUTDOWN and use the same locking
mechanism from isotp_release() which resolves a potential race between
isotp_sendsmg() and isotp_release().
[1] https://lore.kernel.org/linux-can/ZB%2F93xJxq%2FBUqAgG@dragonet
v1: https://lore.kernel.org/all/20230331102114.15164-1-socketcan@hartkopp.net
v2: https://lore.kernel.org/all/20230331123600.3550-1-socketcan@hartkopp.net
take care of signal interrupts for wait_event_interruptible() in
isotp_release()
v3: https://lore.kernel.org/all/20230331130654.9886-1-socketcan@hartkopp.net
take care of signal interrupts for wait_event_interruptible() in
isotp_sendmsg() in the wait_tx_done case
v4: https://lore.kernel.org/all/20230331131935.21465-1-socketcan@hartkopp.net
take care of signal interrupts for wait_event_interruptible() in
isotp_sendmsg() in ALL cases
Cc: Dae R. Jeong <threeearcat@gmail.com>
Cc: Hillf Danton <hdanton@sina.com>
Signed-off-by: Oliver Hartkopp <socketcan@hartkopp.net>
Fixes: 4f027cb ("can: isotp: split tx timer into transmission and timeout")
Link: https://lore.kernel.org/all/20230331131935.21465-1-socketcan@hartkopp.net
Cc: stable@vger.kernel.org
[mkl: rephrase commit message]
Signed-off-by: Marc Kleine-Budde <mkl@pengutronix.de>1 parent 79e19fa commit 0517374
1 file changed
+31
-24
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
119 | 119 | | |
120 | 120 | | |
121 | 121 | | |
122 | | - | |
| 122 | + | |
| 123 | + | |
123 | 124 | | |
124 | 125 | | |
125 | 126 | | |
| |||
880 | 881 | | |
881 | 882 | | |
882 | 883 | | |
883 | | - | |
884 | | - | |
| 884 | + | |
| 885 | + | |
885 | 886 | | |
886 | 887 | | |
887 | 888 | | |
| |||
918 | 919 | | |
919 | 920 | | |
920 | 921 | | |
921 | | - | |
922 | 922 | | |
923 | 923 | | |
924 | 924 | | |
| |||
928 | 928 | | |
929 | 929 | | |
930 | 930 | | |
931 | | - | |
| 931 | + | |
932 | 932 | | |
933 | 933 | | |
| 934 | + | |
934 | 935 | | |
935 | | - | |
936 | | - | |
937 | | - | |
938 | | - | |
939 | | - | |
940 | | - | |
| 936 | + | |
| 937 | + | |
941 | 938 | | |
942 | | - | |
943 | | - | |
944 | | - | |
945 | | - | |
| 939 | + | |
| 940 | + | |
| 941 | + | |
| 942 | + | |
946 | 943 | | |
947 | | - | |
| 944 | + | |
| 945 | + | |
| 946 | + | |
| 947 | + | |
| 948 | + | |
948 | 949 | | |
949 | 950 | | |
950 | 951 | | |
| |||
1074 | 1075 | | |
1075 | 1076 | | |
1076 | 1077 | | |
1077 | | - | |
| 1078 | + | |
| 1079 | + | |
| 1080 | + | |
1078 | 1081 | | |
1079 | 1082 | | |
1080 | 1083 | | |
1081 | 1084 | | |
1082 | 1085 | | |
1083 | 1086 | | |
1084 | 1087 | | |
| 1088 | + | |
| 1089 | + | |
| 1090 | + | |
| 1091 | + | |
| 1092 | + | |
1085 | 1093 | | |
1086 | 1094 | | |
1087 | | - | |
1088 | | - | |
1089 | | - | |
1090 | | - | |
1091 | | - | |
| 1095 | + | |
| 1096 | + | |
1092 | 1097 | | |
1093 | 1098 | | |
1094 | 1099 | | |
| |||
1150 | 1155 | | |
1151 | 1156 | | |
1152 | 1157 | | |
1153 | | - | |
| 1158 | + | |
| 1159 | + | |
| 1160 | + | |
1154 | 1161 | | |
1155 | 1162 | | |
1156 | | - | |
| 1163 | + | |
1157 | 1164 | | |
1158 | 1165 | | |
1159 | 1166 | | |
| |||
0 commit comments