Pablo Neira Ayuso
24cea96770
netfilter: nf_tables: flush pending destroy work before exit_net release
...
Similar to 2c9f0293280e ("netfilter: nf_tables: flush pending destroy
work before netlink notifier") to address a race between exit_net and
the destroy workqueue.
The trace below shows an element to be released via destroy workqueue
while exit_net path (triggered via module removal) has already released
the set that is used in such transaction.
[ 1360.547789] BUG: KASAN: slab-use-after-free in nf_tables_trans_destroy_work+0x3f5/0x590 [nf_tables]
[ 1360.547861] Read of size 8 at addr ffff888140500cc0 by task kworker/4:1/152465
[ 1360.547870] CPU: 4 PID: 152465 Comm: kworker/4:1 Not tainted 6.8.0+ #359
[ 1360.547882] Workqueue: events nf_tables_trans_destroy_work [nf_tables]
[ 1360.547984] Call Trace:
[ 1360.547991] <TASK>
[ 1360.547998] dump_stack_lvl+0x53/0x70
[ 1360.548014] print_report+0xc4/0x610
[ 1360.548026] ? __virt_addr_valid+0xba/0x160
[ 1360.548040] ? __pfx__raw_spin_lock_irqsave+0x10/0x10
[ 1360.548054] ? nf_tables_trans_destroy_work+0x3f5/0x590 [nf_tables]
[ 1360.548176] kasan_report+0xae/0xe0
[ 1360.548189] ? nf_tables_trans_destroy_work+0x3f5/0x590 [nf_tables]
[ 1360.548312] nf_tables_trans_destroy_work+0x3f5/0x590 [nf_tables]
[ 1360.548447] ? __pfx_nf_tables_trans_destroy_work+0x10/0x10 [nf_tables]
[ 1360.548577] ? _raw_spin_unlock_irq+0x18/0x30
[ 1360.548591] process_one_work+0x2f1/0x670
[ 1360.548610] worker_thread+0x4d3/0x760
[ 1360.548627] ? __pfx_worker_thread+0x10/0x10
[ 1360.548640] kthread+0x16b/0x1b0
[ 1360.548653] ? __pfx_kthread+0x10/0x10
[ 1360.548665] ret_from_fork+0x2f/0x50
[ 1360.548679] ? __pfx_kthread+0x10/0x10
[ 1360.548690] ret_from_fork_asm+0x1a/0x30
[ 1360.548707] </TASK>
[ 1360.548719] Allocated by task 192061:
[ 1360.548726] kasan_save_stack+0x20/0x40
[ 1360.548739] kasan_save_track+0x14/0x30
[ 1360.548750] __kasan_kmalloc+0x8f/0xa0
[ 1360.548760] __kmalloc_node+0x1f1/0x450
[ 1360.548771] nf_tables_newset+0x10c7/0x1b50 [nf_tables]
[ 1360.548883] nfnetlink_rcv_batch+0xbc4/0xdc0 [nfnetlink]
[ 1360.548909] nfnetlink_rcv+0x1a8/0x1e0 [nfnetlink]
[ 1360.548927] netlink_unicast+0x367/0x4f0
[ 1360.548935] netlink_sendmsg+0x34b/0x610
[ 1360.548944] ____sys_sendmsg+0x4d4/0x510
[ 1360.548953] ___sys_sendmsg+0xc9/0x120
[ 1360.548961] __sys_sendmsg+0xbe/0x140
[ 1360.548971] do_syscall_64+0x55/0x120
[ 1360.548982] entry_SYSCALL_64_after_hwframe+0x55/0x5d
[ 1360.548994] Freed by task 192222:
[ 1360.548999] kasan_save_stack+0x20/0x40
[ 1360.549009] kasan_save_track+0x14/0x30
[ 1360.549019] kasan_save_free_info+0x3b/0x60
[ 1360.549028] poison_slab_object+0x100/0x180
[ 1360.549036] __kasan_slab_free+0x14/0x30
[ 1360.549042] kfree+0xb6/0x260
[ 1360.549049] __nft_release_table+0x473/0x6a0 [nf_tables]
[ 1360.549131] nf_tables_exit_net+0x170/0x240 [nf_tables]
[ 1360.549221] ops_exit_list+0x50/0xa0
[ 1360.549229] free_exit_list+0x101/0x140
[ 1360.549236] unregister_pernet_operations+0x107/0x160
[ 1360.549245] unregister_pernet_subsys+0x1c/0x30
[ 1360.549254] nf_tables_module_exit+0x43/0x80 [nf_tables]
[ 1360.549345] __do_sys_delete_module+0x253/0x370
[ 1360.549352] do_syscall_64+0x55/0x120
[ 1360.549360] entry_SYSCALL_64_after_hwframe+0x55/0x5d
(gdb) list *__nft_release_table+0x473
0x1e033 is in __nft_release_table (net/netfilter/nf_tables_api.c:11354).
11349 list_for_each_entry_safe(flowtable, nf, &table->flowtables, list) {
11350 list_del(&flowtable->list);
11351 nft_use_dec(&table->use);
11352 nf_tables_flowtable_destroy(flowtable);
11353 }
11354 list_for_each_entry_safe(set, ns, &table->sets, list) {
11355 list_del(&set->list);
11356 nft_use_dec(&table->use);
11357 if (set->flags & (NFT_SET_MAP | NFT_SET_OBJECT))
11358 nft_map_deactivate(&ctx, set);
(gdb)
[ 1360.549372] Last potentially related work creation:
[ 1360.549376] kasan_save_stack+0x20/0x40
[ 1360.549384] __kasan_record_aux_stack+0x9b/0xb0
[ 1360.549392] __queue_work+0x3fb/0x780
[ 1360.549399] queue_work_on+0x4f/0x60
[ 1360.549407] nft_rhash_remove+0x33b/0x340 [nf_tables]
[ 1360.549516] nf_tables_commit+0x1c6a/0x2620 [nf_tables]
[ 1360.549625] nfnetlink_rcv_batch+0x728/0xdc0 [nfnetlink]
[ 1360.549647] nfnetlink_rcv+0x1a8/0x1e0 [nfnetlink]
[ 1360.549671] netlink_unicast+0x367/0x4f0
[ 1360.549680] netlink_sendmsg+0x34b/0x610
[ 1360.549690] ____sys_sendmsg+0x4d4/0x510
[ 1360.549697] ___sys_sendmsg+0xc9/0x120
[ 1360.549706] __sys_sendmsg+0xbe/0x140
[ 1360.549715] do_syscall_64+0x55/0x120
[ 1360.549725] entry_SYSCALL_64_after_hwframe+0x55/0x5d
Fixes: 0935d5588400 ("netfilter: nf_tables: asynchronous release")
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
2024-04-04 11:34:42 +02:00
..
2024-02-08 12:09:23 +01:00
2024-01-29 15:43:20 +01:00
2023-10-18 10:26:43 +02:00
2024-01-29 15:43:21 +01:00
2024-01-10 10:52:28 +01:00
2024-01-24 16:21:01 -08:00
2024-01-29 15:43:20 +01:00
2022-02-04 06:30:28 +01:00
2024-01-31 20:40:56 -08:00
2023-11-08 13:52:32 +01:00
2024-02-29 14:24:56 -08:00
2023-02-22 00:28:47 +01:00
2024-02-21 11:57:11 +01:00
2023-09-13 21:57:50 +02:00
2022-09-20 23:50:03 +02:00
2024-03-07 03:10:35 +01:00
2022-08-11 16:50:49 +02:00
2023-10-10 16:34:28 +02:00
2022-09-07 15:55:23 +02:00
2023-10-24 13:16:30 +02:00
2022-01-11 10:41:44 +01:00
2024-02-08 12:10:18 +01:00
2023-03-08 14:25:41 +01:00
2022-07-11 16:25:15 +02:00
2023-07-27 13:45:51 +02:00
2023-07-05 14:42:15 +02:00
2021-06-18 14:47:43 +02:00
2022-11-30 23:01:20 +01:00
2024-01-31 23:13:57 +01:00
2024-01-31 23:07:04 +01:00
2023-02-01 12:18:51 +01:00
2023-11-08 13:52:32 +01:00
2022-08-11 16:50:25 +02:00
2022-02-04 06:30:28 +01:00
2023-06-26 17:18:48 +02:00
2023-08-15 15:26:17 -07:00
2022-07-11 16:25:15 +02:00
2022-02-04 06:30:28 +01:00
2022-06-21 10:50:41 +02:00
2024-02-22 00:14:54 +01:00
2023-02-03 09:31:24 +00:00
2023-06-15 22:19:41 -07:00
2023-07-31 09:11:24 +01:00
2022-07-11 16:25:14 +02:00
2021-08-30 01:51:36 +02:00
2024-01-17 12:02:48 +01:00
2024-02-21 11:57:11 +01:00
2022-09-07 16:46:04 +02:00
2024-01-31 20:40:56 -08:00
2024-02-15 00:20:00 +01:00
2022-09-07 16:46:04 +02:00
2022-11-18 02:15:15 +01:00
2022-09-07 16:46:04 +02:00
2022-05-13 18:56:27 +02:00
2024-01-03 11:17:17 +01:00
2023-10-30 14:36:57 -07:00
2023-11-08 16:40:30 +01:00
2022-09-07 16:46:04 +02:00
2024-02-21 12:03:22 +01:00
2024-03-01 08:42:31 +00:00
2024-04-04 11:34:42 +02:00
2024-01-10 10:52:28 +01:00
2023-07-31 09:11:24 +01:00
2023-10-18 10:26:43 +02:00
2021-05-29 01:04:53 +02:00
2022-07-11 16:25:15 +02:00
2022-06-17 23:31:20 +02:00
2023-04-21 11:34:14 -07:00
2024-01-17 12:02:47 +01:00
2023-11-08 13:52:32 +01:00
2024-02-21 12:03:22 +01:00
2023-06-08 04:00:02 +02:00
2023-06-26 12:59:18 -07:00
2023-11-14 16:16:21 +01:00
2024-01-24 19:50:21 +01:00
2023-11-08 13:52:32 +01:00
2021-05-29 01:04:54 +02:00
2023-07-31 09:11:24 +01:00
2024-02-28 23:52:55 +01:00
2022-11-15 10:46:34 +01:00
2022-11-15 10:53:17 +01:00
2023-05-03 13:49:08 +02:00
2024-03-11 19:53:15 -07:00
2022-11-15 10:46:34 +01:00
2023-12-06 17:15:43 +01:00
2023-12-06 17:15:42 +01:00
2022-03-20 00:29:47 +01:00
2022-03-20 00:29:47 +01:00
2023-12-06 17:15:42 +01:00
2024-02-15 00:20:00 +01:00
2023-11-08 13:52:32 +01:00
2023-06-26 08:05:57 +02:00
2024-01-03 11:17:17 +01:00
2023-10-12 10:28:45 +02:00
2023-03-01 17:23:23 +01:00
2024-01-24 20:01:16 +01:00
2022-11-15 10:46:34 +01:00
2024-01-10 10:52:28 +01:00
2023-07-27 13:45:51 +02:00
2023-11-14 16:16:21 +01:00
2024-01-24 20:02:40 +01:00
2022-11-15 10:46:34 +01:00
2023-07-05 14:42:15 +02:00
2024-02-21 11:57:11 +01:00
2023-10-12 10:28:45 +02:00
2022-11-15 10:46:34 +01:00
2023-03-01 17:23:23 +01:00
2023-06-26 08:05:57 +02:00
2023-07-27 13:45:51 +02:00
2022-03-20 00:29:46 +01:00
2022-03-20 00:29:46 +01:00
2023-06-26 08:05:57 +02:00
2024-01-24 20:02:40 +01:00
2023-10-24 13:37:46 +02:00
2024-02-08 12:10:19 +01:00
2024-02-21 11:57:11 +01:00
2021-05-29 01:04:27 +02:00
2024-03-21 00:21:54 +01:00
2024-02-21 11:57:11 +01:00
2024-02-08 12:10:19 +01:00
2024-01-24 20:02:40 +01:00
2024-01-24 20:02:40 +01:00
2024-01-24 20:02:40 +01:00
2024-01-31 23:07:04 +01:00
2024-01-24 20:02:40 +01:00
2024-02-21 12:03:22 +01:00
2024-02-21 12:03:22 +01:00
2021-06-01 23:53:51 +02:00
2021-08-17 00:45:07 +02:00
2022-07-11 16:40:45 +02:00
2022-11-18 15:21:00 +01:00
2022-07-11 16:25:15 +02:00
2022-07-11 16:40:45 +02:00
2022-01-22 08:33:37 +02:00
2023-03-17 15:16:33 +01:00
2023-05-25 12:16:27 +01:00
2023-02-22 21:25:23 -08:00
2021-05-29 01:04:52 +02:00
2021-09-21 03:46:56 +02:00
2021-09-21 03:46:56 +02:00
2023-06-20 22:43:42 +02:00
2023-12-06 17:52:15 +01:00
2024-01-17 12:02:48 +01:00
2022-09-07 16:46:03 +02:00
2023-11-08 13:53:36 +01:00
2023-03-22 21:48:59 +01:00
2023-08-22 15:13:21 +02:00
2023-08-30 17:34:01 +02:00
2021-05-03 23:02:44 +02:00
2023-07-29 18:13:41 +01:00
2022-10-11 17:42:58 -06:00
2022-07-11 16:40:45 +02:00
2023-03-22 21:48:59 +01:00
2022-07-21 00:56:00 +02:00
2023-08-30 17:34:01 +02:00