Commit 5f50d79
virtio-net: fix the race between refill work and close
[ Upstream commit 5a15912 ]
We try using cancel_delayed_work_sync() to prevent the work from
enabling NAPI. This is insufficient since we don't disable the source
of the refill work scheduling. This means an NAPI poll callback after
cancel_delayed_work_sync() can schedule the refill work then can
re-enable the NAPI that leads to use-after-free [1].
Since the work can enable NAPI, we can't simply disable NAPI before
calling cancel_delayed_work_sync(). So fix this by introducing a
dedicated boolean to control whether or not the work could be
scheduled from NAPI.
[1]
==================================================================
BUG: KASAN: use-after-free in refill_work+0x43/0xd4
Read of size 2 at addr ffff88810562c92e by task kworker/2:1/42
CPU: 2 PID: 42 Comm: kworker/2:1 Not tainted 5.19.0-rc1+ torvalds#480
Hardware name: QEMU Standard PC (Q35 + ICH9, 2009), BIOS rel-1.16.0-0-gd239552ce722-prebuilt.qemu.org 04/01/2014
Workqueue: events refill_work
Call Trace:
<TASK>
dump_stack_lvl+0x34/0x44
print_report.cold+0xbb/0x6ac
? _printk+0xad/0xde
? refill_work+0x43/0xd4
kasan_report+0xa8/0x130
? refill_work+0x43/0xd4
refill_work+0x43/0xd4
process_one_work+0x43d/0x780
worker_thread+0x2a0/0x6f0
? process_one_work+0x780/0x780
kthread+0x167/0x1a0
? kthread_exit+0x50/0x50
ret_from_fork+0x22/0x30
</TASK>
...
Fixes: b2baed6 ("virtio_net: set/cancel work on ndo_open/ndo_stop")
Signed-off-by: Jason Wang <[email protected]>
Acked-by: Michael S. Tsirkin <[email protected]>
Reviewed-by: Xuan Zhuo <[email protected]>
Signed-off-by: David S. Miller <[email protected]>
Signed-off-by: Sasha Levin <[email protected]>1 parent c7b9244 commit 5f50d79
1 file changed
+34
-3
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
213 | 213 | | |
214 | 214 | | |
215 | 215 | | |
216 | | - | |
| 216 | + | |
217 | 217 | | |
218 | 218 | | |
| 219 | + | |
| 220 | + | |
| 221 | + | |
| 222 | + | |
| 223 | + | |
| 224 | + | |
219 | 225 | | |
220 | 226 | | |
221 | 227 | | |
| |||
319 | 325 | | |
320 | 326 | | |
321 | 327 | | |
| 328 | + | |
| 329 | + | |
| 330 | + | |
| 331 | + | |
| 332 | + | |
| 333 | + | |
| 334 | + | |
| 335 | + | |
| 336 | + | |
| 337 | + | |
| 338 | + | |
| 339 | + | |
| 340 | + | |
| 341 | + | |
322 | 342 | | |
323 | 343 | | |
324 | 344 | | |
| |||
1388 | 1408 | | |
1389 | 1409 | | |
1390 | 1410 | | |
1391 | | - | |
1392 | | - | |
| 1411 | + | |
| 1412 | + | |
| 1413 | + | |
| 1414 | + | |
| 1415 | + | |
| 1416 | + | |
1393 | 1417 | | |
1394 | 1418 | | |
1395 | 1419 | | |
| |||
1508 | 1532 | | |
1509 | 1533 | | |
1510 | 1534 | | |
| 1535 | + | |
| 1536 | + | |
1511 | 1537 | | |
1512 | 1538 | | |
1513 | 1539 | | |
| |||
1878 | 1904 | | |
1879 | 1905 | | |
1880 | 1906 | | |
| 1907 | + | |
| 1908 | + | |
1881 | 1909 | | |
1882 | 1910 | | |
1883 | 1911 | | |
| |||
2417 | 2445 | | |
2418 | 2446 | | |
2419 | 2447 | | |
| 2448 | + | |
| 2449 | + | |
2420 | 2450 | | |
2421 | 2451 | | |
2422 | 2452 | | |
| |||
3140 | 3170 | | |
3141 | 3171 | | |
3142 | 3172 | | |
| 3173 | + | |
3143 | 3174 | | |
3144 | 3175 | | |
3145 | 3176 | | |
| |||
0 commit comments