Commit f613e8b
net: add proper RCU protection to /proc/net/ptype
Yin Fengwei reported an RCU stall in ptype_seq_show() and provided
a patch.
Real issue is that ptype_seq_next() and ptype_seq_show() violate
RCU rules.
ptype_seq_show() runs under rcu_read_lock(), and reads pt->dev
to get device name without any barrier.
At the same time, concurrent writers can remove a packet_type structure
(which is correctly freed after an RCU grace period) and clear pt->dev
without an RCU grace period.
Define ptype_iter_state to carry a dev pointer along seq_net_private:
struct ptype_iter_state {
struct seq_net_private p;
struct net_device *dev; // added in this patch
};
We need to record the device pointer in ptype_get_idx() and
ptype_seq_next() so that ptype_seq_show() is safe against
concurrent pt->dev changes.
We also need to add full RCU protection in ptype_seq_next().
(Missing READ_ONCE() when reading list.next values)
Many thanks to Dong Chenchen for providing a repro.
Fixes: 1da177e ("Linux-2.6.12-rc2")
Fixes: 1d10f8a ("net-procfs: show net devices bound packet types")
Fixes: c353e89 ("net: introduce per netns packet chains")
Reported-by: Yin Fengwei <[email protected]>
Reported-by: Dong Chenchen <[email protected]>
Closes: https://lore.kernel.org/netdev/CANn89iKRRKPnWjJmb-_3a=sq+9h6DvTQM4DBZHT5ZRGPMzQaiA@mail.gmail.com/T/#m7b80b9fc9b9267f90e0b7aad557595f686f9c50d
Signed-off-by: Eric Dumazet <[email protected]>
Reviewed-by: Willem de Bruijn <[email protected]>
Tested-by: Yin Fengwei <[email protected]>
Link: https://patch.msgid.link/[email protected]
Signed-off-by: Jakub Kicinski <[email protected]>1 parent 7821154 commit f613e8b
1 file changed
Lines changed: 34 additions & 16 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
170 | 170 | | |
171 | 171 | | |
172 | 172 | | |
| 173 | + | |
| 174 | + | |
| 175 | + | |
| 176 | + | |
| 177 | + | |
173 | 178 | | |
174 | 179 | | |
| 180 | + | |
175 | 181 | | |
176 | 182 | | |
177 | 183 | | |
| |||
181 | 187 | | |
182 | 188 | | |
183 | 189 | | |
184 | | - | |
| 190 | + | |
| 191 | + | |
185 | 192 | | |
| 193 | + | |
186 | 194 | | |
187 | 195 | | |
188 | 196 | | |
189 | 197 | | |
| 198 | + | |
| 199 | + | |
190 | 200 | | |
191 | 201 | | |
192 | 202 | | |
| |||
218 | 228 | | |
219 | 229 | | |
220 | 230 | | |
| 231 | + | |
221 | 232 | | |
222 | 233 | | |
223 | 234 | | |
| |||
229 | 240 | | |
230 | 241 | | |
231 | 242 | | |
232 | | - | |
233 | | - | |
234 | | - | |
| 243 | + | |
| 244 | + | |
| 245 | + | |
| 246 | + | |
235 | 247 | | |
236 | 248 | | |
237 | | - | |
238 | 249 | | |
239 | | - | |
240 | | - | |
| 250 | + | |
| 251 | + | |
| 252 | + | |
241 | 253 | | |
242 | 254 | | |
243 | 255 | | |
244 | | - | |
| 256 | + | |
| 257 | + | |
245 | 258 | | |
246 | 259 | | |
247 | 260 | | |
| |||
252 | 265 | | |
253 | 266 | | |
254 | 267 | | |
255 | | - | |
| 268 | + | |
256 | 269 | | |
257 | 270 | | |
258 | 271 | | |
259 | 272 | | |
260 | 273 | | |
261 | | - | |
| 274 | + | |
262 | 275 | | |
263 | 276 | | |
264 | 277 | | |
265 | 278 | | |
266 | 279 | | |
267 | 280 | | |
268 | | - | |
| 281 | + | |
269 | 282 | | |
270 | 283 | | |
271 | 284 | | |
| |||
279 | 292 | | |
280 | 293 | | |
281 | 294 | | |
| 295 | + | |
282 | 296 | | |
| 297 | + | |
283 | 298 | | |
284 | | - | |
| 299 | + | |
285 | 300 | | |
286 | | - | |
287 | | - | |
| 301 | + | |
| 302 | + | |
| 303 | + | |
| 304 | + | |
| 305 | + | |
288 | 306 | | |
289 | 307 | | |
290 | 308 | | |
291 | 309 | | |
292 | 310 | | |
293 | 311 | | |
294 | | - | |
| 312 | + | |
295 | 313 | | |
296 | 314 | | |
297 | 315 | | |
| |||
315 | 333 | | |
316 | 334 | | |
317 | 335 | | |
318 | | - | |
| 336 | + | |
319 | 337 | | |
320 | 338 | | |
321 | 339 | | |
| |||
0 commit comments