Commit f75a280
xfrm: destroy xfrm_state synchronously on net exit path
xfrm_state_put() moves struct xfrm_state to the GC list
and schedules the GC work to clean it up. On net exit call
path, xfrm_state_flush() is called to clean up and
xfrm_flush_gc() is called to wait for the GC work to complete
before exit.
However, this doesn't work because one of the ->destructor(),
ipcomp_destroy(), schedules the same GC work again inside
the GC work. It is hard to wait for such a nested async
callback. This is also why syzbot still reports the following
warning:
WARNING: CPU: 1 PID: 33 at net/ipv6/xfrm6_tunnel.c:351 xfrm6_tunnel_net_exit+0x2cb/0x500 net/ipv6/xfrm6_tunnel.c:351
...
ops_exit_list.isra.0+0xb0/0x160 net/core/net_namespace.c:153
cleanup_net+0x51d/0xb10 net/core/net_namespace.c:551
process_one_work+0xd0c/0x1ce0 kernel/workqueue.c:2153
worker_thread+0x143/0x14a0 kernel/workqueue.c:2296
kthread+0x357/0x430 kernel/kthread.c:246
ret_from_fork+0x3a/0x50 arch/x86/entry/entry_64.S:352
In fact, it is perfectly fine to bypass GC and destroy xfrm_state
synchronously on net exit call path, because it is in process context
and doesn't need a work struct to do any blocking work.
This patch introduces xfrm_state_put_sync() which simply bypasses
GC, and lets its callers to decide whether to use this synchronous
version. On net exit path, xfrm_state_fini() and
xfrm6_tunnel_net_exit() use it. And, as ipcomp_destroy() itself is
blocking, it can use xfrm_state_put_sync() directly too.
Also rename xfrm_state_gc_destroy() to ___xfrm_state_destroy() to
reflect this change.
Fixes: b48c05a ("xfrm: Fix warning in xfrm6_tunnel_net_exit.")
Reported-and-tested-by: syzbot+e9aebef558e3ed673934@syzkaller.appspotmail.com
Cc: Steffen Klassert <steffen.klassert@secunet.com>
Signed-off-by: Cong Wang <xiyou.wangcong@gmail.com>
Signed-off-by: Steffen Klassert <steffen.klassert@secunet.com>1 parent 09db512 commit f75a280
File tree
5 files changed
+31
-17
lines changed- include/net
- net
- ipv6
- key
- xfrm
5 files changed
+31
-17
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
853 | 853 | | |
854 | 854 | | |
855 | 855 | | |
856 | | - | |
| 856 | + | |
857 | 857 | | |
858 | 858 | | |
859 | 859 | | |
| |||
863 | 863 | | |
864 | 864 | | |
865 | 865 | | |
866 | | - | |
| 866 | + | |
| 867 | + | |
| 868 | + | |
| 869 | + | |
| 870 | + | |
| 871 | + | |
| 872 | + | |
867 | 873 | | |
868 | 874 | | |
869 | 875 | | |
| |||
1590 | 1596 | | |
1591 | 1597 | | |
1592 | 1598 | | |
1593 | | - | |
| 1599 | + | |
1594 | 1600 | | |
1595 | 1601 | | |
1596 | 1602 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
344 | 344 | | |
345 | 345 | | |
346 | 346 | | |
347 | | - | |
348 | 347 | | |
| 348 | + | |
349 | 349 | | |
350 | 350 | | |
351 | 351 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1783 | 1783 | | |
1784 | 1784 | | |
1785 | 1785 | | |
1786 | | - | |
| 1786 | + | |
1787 | 1787 | | |
1788 | 1788 | | |
1789 | 1789 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
432 | 432 | | |
433 | 433 | | |
434 | 434 | | |
435 | | - | |
| 435 | + | |
436 | 436 | | |
437 | 437 | | |
438 | 438 | | |
| |||
474 | 474 | | |
475 | 475 | | |
476 | 476 | | |
477 | | - | |
| 477 | + | |
478 | 478 | | |
479 | 479 | | |
480 | 480 | | |
| |||
598 | 598 | | |
599 | 599 | | |
600 | 600 | | |
601 | | - | |
| 601 | + | |
602 | 602 | | |
603 | 603 | | |
604 | 604 | | |
605 | | - | |
606 | | - | |
607 | | - | |
608 | | - | |
| 605 | + | |
| 606 | + | |
| 607 | + | |
| 608 | + | |
| 609 | + | |
| 610 | + | |
| 611 | + | |
| 612 | + | |
| 613 | + | |
609 | 614 | | |
610 | 615 | | |
611 | 616 | | |
| |||
708 | 713 | | |
709 | 714 | | |
710 | 715 | | |
711 | | - | |
| 716 | + | |
712 | 717 | | |
713 | 718 | | |
714 | 719 | | |
| |||
730 | 735 | | |
731 | 736 | | |
732 | 737 | | |
733 | | - | |
| 738 | + | |
| 739 | + | |
| 740 | + | |
| 741 | + | |
734 | 742 | | |
735 | 743 | | |
736 | 744 | | |
| |||
2215 | 2223 | | |
2216 | 2224 | | |
2217 | 2225 | | |
2218 | | - | |
| 2226 | + | |
2219 | 2227 | | |
2220 | 2228 | | |
2221 | 2229 | | |
| |||
2375 | 2383 | | |
2376 | 2384 | | |
2377 | 2385 | | |
2378 | | - | |
2379 | 2386 | | |
| 2387 | + | |
2380 | 2388 | | |
2381 | 2389 | | |
2382 | 2390 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1932 | 1932 | | |
1933 | 1933 | | |
1934 | 1934 | | |
1935 | | - | |
| 1935 | + | |
1936 | 1936 | | |
1937 | 1937 | | |
1938 | 1938 | | |
| |||
0 commit comments