Commit 5121197
kcm: close race conditions on sk_receive_queue
sk->sk_receive_queue is protected by skb queue lock, but for KCM
sockets its RX path takes mux->rx_lock to protect more than just
skb queue. However, kcm_recvmsg() still only grabs the skb queue
lock, so race conditions still exist.
We can teach kcm_recvmsg() to grab mux->rx_lock too but this would
introduce a potential performance regression as struct kcm_mux can
be shared by multiple KCM sockets.
So we have to enforce skb queue lock in requeue_rx_msgs() and handle
skb peek case carefully in kcm_wait_data(). Fortunately,
skb_recv_datagram() already handles it nicely and is widely used by
other sockets, we can just switch to skb_recv_datagram() after
getting rid of the unnecessary sock lock in kcm_recvmsg() and
kcm_splice_read(). Side note: SOCK_DONE is not used by KCM sockets,
so it is safe to get rid of this check too.
I ran the original syzbot reproducer for 30 min without seeing any
issue.
Fixes: ab7ac4e ("kcm: Kernel Connection Multiplexor module")
Reported-by: syzbot+278279efdd2730dd14bf@syzkaller.appspotmail.com
Reported-by: shaozhengchao <shaozhengchao@huawei.com>
Cc: Paolo Abeni <pabeni@redhat.com>
Cc: Tom Herbert <tom@herbertland.com>
Signed-off-by: Cong Wang <cong.wang@bytedance.com>
Link: https://lore.kernel.org/r/20221114005119.597905-1-xiyou.wangcong@gmail.com
Signed-off-by: Paolo Abeni <pabeni@redhat.com>1 parent 280c0f7 commit 5121197
1 file changed
+6
-52
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
222 | 222 | | |
223 | 223 | | |
224 | 224 | | |
225 | | - | |
| 225 | + | |
226 | 226 | | |
227 | 227 | | |
228 | 228 | | |
| |||
1085 | 1085 | | |
1086 | 1086 | | |
1087 | 1087 | | |
1088 | | - | |
1089 | | - | |
1090 | | - | |
1091 | | - | |
1092 | | - | |
1093 | | - | |
1094 | | - | |
1095 | | - | |
1096 | | - | |
1097 | | - | |
1098 | | - | |
1099 | | - | |
1100 | | - | |
1101 | | - | |
1102 | | - | |
1103 | | - | |
1104 | | - | |
1105 | | - | |
1106 | | - | |
1107 | | - | |
1108 | | - | |
1109 | | - | |
1110 | | - | |
1111 | | - | |
1112 | | - | |
1113 | | - | |
1114 | | - | |
1115 | | - | |
1116 | | - | |
1117 | | - | |
1118 | | - | |
1119 | 1088 | | |
1120 | 1089 | | |
1121 | 1090 | | |
1122 | 1091 | | |
1123 | 1092 | | |
1124 | 1093 | | |
1125 | | - | |
1126 | 1094 | | |
1127 | 1095 | | |
1128 | 1096 | | |
1129 | 1097 | | |
1130 | | - | |
1131 | | - | |
1132 | | - | |
1133 | | - | |
1134 | | - | |
| 1098 | + | |
1135 | 1099 | | |
1136 | 1100 | | |
1137 | 1101 | | |
| |||
1162 | 1126 | | |
1163 | 1127 | | |
1164 | 1128 | | |
1165 | | - | |
1166 | | - | |
1167 | 1129 | | |
1168 | 1130 | | |
1169 | 1131 | | |
1170 | 1132 | | |
1171 | | - | |
1172 | | - | |
| 1133 | + | |
1173 | 1134 | | |
1174 | 1135 | | |
1175 | 1136 | | |
| |||
1179 | 1140 | | |
1180 | 1141 | | |
1181 | 1142 | | |
1182 | | - | |
1183 | 1143 | | |
1184 | 1144 | | |
1185 | 1145 | | |
1186 | 1146 | | |
1187 | 1147 | | |
1188 | 1148 | | |
1189 | 1149 | | |
1190 | | - | |
1191 | | - | |
1192 | | - | |
1193 | | - | |
1194 | | - | |
| 1150 | + | |
1195 | 1151 | | |
1196 | 1152 | | |
1197 | 1153 | | |
| |||
1219 | 1175 | | |
1220 | 1176 | | |
1221 | 1177 | | |
1222 | | - | |
1223 | | - | |
| 1178 | + | |
1224 | 1179 | | |
1225 | 1180 | | |
1226 | 1181 | | |
1227 | | - | |
1228 | | - | |
| 1182 | + | |
1229 | 1183 | | |
1230 | 1184 | | |
1231 | 1185 | | |
| |||
0 commit comments