KASAN: use-after-free Read in __nf_tables_abort

36 views
Skip to first unread message

syzbot

unread,
Jan 20, 2020, 6:37:10ā€ÆAM1/20/20
to core...@netfilter.org, da...@davemloft.net, f...@strlen.de, kad...@netfilter.org, linux-...@vger.kernel.org, net...@vger.kernel.org, netfilt...@vger.kernel.org, pa...@netfilter.org, syzkall...@googlegroups.com
Hello,

syzbot found the following crash on:

HEAD commit: def9d278 Linux 5.5-rc7
git tree: upstream
console output: https://syzkaller.appspot.com/x/log.txt?x=16d4e966e00000
kernel config: https://syzkaller.appspot.com/x/.config?x=cf8e288883e40aba
dashboard link: https://syzkaller.appspot.com/bug?extid=29125d208b3dae9a7019
compiler: gcc (GCC) 9.0.0 20181231 (experimental)
syz repro: https://syzkaller.appspot.com/x/repro.syz?x=12c78faee00000

IMPORTANT: if you fix the bug, please add the following tag to the commit:
Reported-by: syzbot+29125d...@syzkaller.appspotmail.com

==================================================================
BUG: KASAN: use-after-free in __list_del_entry_valid+0xd2/0xf5 lib/list_debug.c:42
Read of size 8 at addr ffff888096085408 by task syz-executor.0/9949

CPU: 0 PID: 9949 Comm: syz-executor.0 Not tainted 5.5.0-rc7-syzkaller #0
Hardware name: Google Google Compute Engine/Google Compute Engine, BIOS Google 01/01/2011
Call Trace:
__dump_stack lib/dump_stack.c:77 [inline]
dump_stack+0x197/0x210 lib/dump_stack.c:118
print_address_description.constprop.0.cold+0xd4/0x30b mm/kasan/report.c:374
__kasan_report.cold+0x1b/0x41 mm/kasan/report.c:506
kasan_report+0x12/0x20 mm/kasan/common.c:639
__asan_report_load8_noabort+0x14/0x20 mm/kasan/generic_report.c:135
__list_del_entry_valid+0xd2/0xf5 lib/list_debug.c:42
__list_del_entry include/linux/list.h:131 [inline]
list_del_rcu include/linux/rculist.h:148 [inline]
__nf_tables_abort+0x1e53/0x2a50 net/netfilter/nf_tables_api.c:7258
nf_tables_abort+0x17/0x30 net/netfilter/nf_tables_api.c:7373
nfnetlink_rcv_batch+0xa5d/0x17a0 net/netfilter/nfnetlink.c:494
nfnetlink_rcv_skb_batch net/netfilter/nfnetlink.c:543 [inline]
nfnetlink_rcv+0x3e7/0x460 net/netfilter/nfnetlink.c:561
netlink_unicast_kernel net/netlink/af_netlink.c:1302 [inline]
netlink_unicast+0x58c/0x7d0 net/netlink/af_netlink.c:1328
netlink_sendmsg+0x91c/0xea0 net/netlink/af_netlink.c:1917
sock_sendmsg_nosec net/socket.c:639 [inline]
sock_sendmsg+0xd7/0x130 net/socket.c:659
____sys_sendmsg+0x753/0x880 net/socket.c:2330
___sys_sendmsg+0x100/0x170 net/socket.c:2384
__sys_sendmsg+0x105/0x1d0 net/socket.c:2417
__do_sys_sendmsg net/socket.c:2426 [inline]
__se_sys_sendmsg net/socket.c:2424 [inline]
__x64_sys_sendmsg+0x78/0xb0 net/socket.c:2424
do_syscall_64+0xfa/0x790 arch/x86/entry/common.c:294
entry_SYSCALL_64_after_hwframe+0x49/0xbe
RIP: 0033:0x45b349
Code: ad b6 fb ff c3 66 2e 0f 1f 84 00 00 00 00 00 66 90 48 89 f8 48 89 f7 48 89 d6 48 89 ca 4d 89 c2 4d 89 c8 4c 8b 4c 24 08 0f 05 <48> 3d 01 f0 ff ff 0f 83 7b b6 fb ff c3 66 2e 0f 1f 84 00 00 00 00
RSP: 002b:00007f29992c7c78 EFLAGS: 00000246 ORIG_RAX: 000000000000002e
RAX: ffffffffffffffda RBX: 00007f29992c86d4 RCX: 000000000045b349
RDX: 0000000000000000 RSI: 0000000020000280 RDI: 0000000000000003
RBP: 000000000075bf20 R08: 0000000000000000 R09: 0000000000000000
R10: 0000000000000000 R11: 0000000000000246 R12: 00000000ffffffff
R13: 0000000000000917 R14: 00000000004ca810 R15: 000000000075bf2c

Allocated by task 9949:
save_stack+0x23/0x90 mm/kasan/common.c:72
set_track mm/kasan/common.c:80 [inline]
__kasan_kmalloc mm/kasan/common.c:513 [inline]
__kasan_kmalloc.constprop.0+0xcf/0xe0 mm/kasan/common.c:486
kasan_kmalloc+0x9/0x10 mm/kasan/common.c:527
kmem_cache_alloc_trace+0x158/0x790 mm/slab.c:3551
kmalloc include/linux/slab.h:556 [inline]
kzalloc include/linux/slab.h:670 [inline]
nf_tables_newtable+0xa4d/0x1510 net/netfilter/nf_tables_api.c:981
nfnetlink_rcv_batch+0xf42/0x17a0 net/netfilter/nfnetlink.c:433
nfnetlink_rcv_skb_batch net/netfilter/nfnetlink.c:543 [inline]
nfnetlink_rcv+0x3e7/0x460 net/netfilter/nfnetlink.c:561
netlink_unicast_kernel net/netlink/af_netlink.c:1302 [inline]
netlink_unicast+0x58c/0x7d0 net/netlink/af_netlink.c:1328
netlink_sendmsg+0x91c/0xea0 net/netlink/af_netlink.c:1917
sock_sendmsg_nosec net/socket.c:639 [inline]
sock_sendmsg+0xd7/0x130 net/socket.c:659
____sys_sendmsg+0x753/0x880 net/socket.c:2330
___sys_sendmsg+0x100/0x170 net/socket.c:2384
__sys_sendmsg+0x105/0x1d0 net/socket.c:2417
__do_sys_sendmsg net/socket.c:2426 [inline]
__se_sys_sendmsg net/socket.c:2424 [inline]
__x64_sys_sendmsg+0x78/0xb0 net/socket.c:2424
do_syscall_64+0xfa/0x790 arch/x86/entry/common.c:294
entry_SYSCALL_64_after_hwframe+0x49/0xbe

Freed by task 2840:
save_stack+0x23/0x90 mm/kasan/common.c:72
set_track mm/kasan/common.c:80 [inline]
kasan_set_free_info mm/kasan/common.c:335 [inline]
__kasan_slab_free+0x102/0x150 mm/kasan/common.c:474
kasan_slab_free+0xe/0x10 mm/kasan/common.c:483
__cache_free mm/slab.c:3426 [inline]
kfree+0x10a/0x2c0 mm/slab.c:3757
nf_tables_table_destroy.isra.0+0xef/0x150 net/netfilter/nf_tables_api.c:1160
nft_commit_release net/netfilter/nf_tables_api.c:6810 [inline]
nf_tables_trans_destroy_work+0x406/0x7c0 net/netfilter/nf_tables_api.c:6860
process_one_work+0x9af/0x1740 kernel/workqueue.c:2264
worker_thread+0x98/0xe40 kernel/workqueue.c:2410
kthread+0x361/0x430 kernel/kthread.c:255
ret_from_fork+0x24/0x30 arch/x86/entry/entry_64.S:352

The buggy address belongs to the object at ffff888096085400
which belongs to the cache kmalloc-512 of size 512
The buggy address is located 8 bytes inside of
512-byte region [ffff888096085400, ffff888096085600)
The buggy address belongs to the page:
page:ffffea0002582140 refcount:1 mapcount:0 mapping:ffff8880aa400a80 index:0x0
raw: 00fffe0000000200 ffffea0002402a88 ffffea000294a748 ffff8880aa400a80
raw: 0000000000000000 ffff888096085000 0000000100000004 0000000000000000
page dumped because: kasan: bad access detected

Memory state around the buggy address:
ffff888096085300: fc fc fc fc fc fc fc fc fc fc fc fc fc fc fc fc
ffff888096085380: fc fc fc fc fc fc fc fc fc fc fc fc fc fc fc fc
>ffff888096085400: fb fb fb fb fb fb fb fb fb fb fb fb fb fb fb fb
^
ffff888096085480: fb fb fb fb fb fb fb fb fb fb fb fb fb fb fb fb
ffff888096085500: fb fb fb fb fb fb fb fb fb fb fb fb fb fb fb fb
==================================================================


---
This bug is generated by a bot. It may contain errors.
See https://goo.gl/tpsmEJ for more information about syzbot.
syzbot engineers can be reached at syzk...@googlegroups.com.

syzbot will keep track of this bug report. See:
https://goo.gl/tpsmEJ#status for how to communicate with syzbot.
syzbot can test patches for this bug, for details see:
https://goo.gl/tpsmEJ#testing-patches

Dan Carpenter

unread,
Jan 21, 2020, 6:35:40ā€ÆAM1/21/20
to syzbot, pa...@netfilter.org, core...@netfilter.org, da...@davemloft.net, f...@strlen.de, kad...@netfilter.org, linux-...@vger.kernel.org, net...@vger.kernel.org, netfilt...@vger.kernel.org, syzkall...@googlegroups.com
I think I see the problem, but I'm not sure how you want to fix it...

net/netfilter/nf_tables_api.c
942 static int nf_tables_newtable(struct net *net, struct sock *nlsk,
943 struct sk_buff *skb, const struct nlmsghdr *nlh,
944 const struct nlattr * const nla[],
945 struct netlink_ext_ack *extack)
946 {
947 const struct nfgenmsg *nfmsg = nlmsg_data(nlh);
948 u8 genmask = nft_genmask_next(net);
949 int family = nfmsg->nfgen_family;
950 const struct nlattr *attr;
951 struct nft_table *table;
952 u32 flags = 0;
953 struct nft_ctx ctx;
954 int err;
955
956 lockdep_assert_held(&net->nft.commit_mutex);
957 attr = nla[NFTA_TABLE_NAME];
958 table = nft_table_lookup(net, attr, family, genmask);
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
This is looking up table in net->nft.tables

959 if (IS_ERR(table)) {
960 if (PTR_ERR(table) != -ENOENT)
961 return PTR_ERR(table);
962 } else {
963 if (nlh->nlmsg_flags & NLM_F_EXCL) {
964 NL_SET_BAD_ATTR(extack, attr);
965 return -EEXIST;
966 }
967 if (nlh->nlmsg_flags & NLM_F_REPLACE)
968 return -EOPNOTSUPP;
969
970 nft_ctx_init(&ctx, net, skb, nlh, family, table, NULL, nla);
971 return nf_tables_updtable(&ctx);
^^^^^^^^^^^^^^^^^^^^^^^
Then it adds it to &ctx->net->nft.commit_list

972 }
973
974 if (nla[NFTA_TABLE_FLAGS]) {
975 flags = ntohl(nla_get_be32(nla[NFTA_TABLE_FLAGS]));
976 if (flags & ~NFT_TABLE_F_DORMANT)
977 return -EINVAL;
978 }
979
980 err = -ENOMEM;
981 table = kzalloc(sizeof(*table), GFP_KERNEL);
982 if (table == NULL)
983 goto err_kzalloc;
984
985 table->name = nla_strdup(attr, GFP_KERNEL);
986 if (table->name == NULL)
987 goto err_strdup;
988
989 err = rhltable_init(&table->chains_ht, &nft_chain_ht_params);
990 if (err)
991 goto err_chain_ht;
992
993 INIT_LIST_HEAD(&table->chains);
994 INIT_LIST_HEAD(&table->sets);
995 INIT_LIST_HEAD(&table->objects);
996 INIT_LIST_HEAD(&table->flowtables);
997 table->family = family;
998 table->flags = flags;
999 table->handle = ++table_handle;
1000
1001 nft_ctx_init(&ctx, net, skb, nlh, family, table, NULL, nla);
1002 err = nft_trans_table_add(&ctx, NFT_MSG_NEWTABLE);
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
Added to ctx->net->nft.commit_list

1003 if (err < 0)
1004 goto err_trans;
1005
1006 list_add_tail_rcu(&table->list, &net->nft.tables);
^^^^^^^^^^^^^^^^
Added to net->nft.tables

1007 return 0;
1008 err_trans:
1009 rhltable_destroy(&table->chains_ht);
1010 err_chain_ht:
1011 kfree(table->name);
1012 err_strdup:
1013 kfree(table);

net/netfilter/nf_tables_api.c
6995 static void nf_tables_commit_release(struct net *net)
6996 {
6997 struct nft_trans *trans;
6998
6999 /* all side effects have to be made visible.
7000 * For example, if a chain named 'foo' has been deleted, a
7001 * new transaction must not find it anymore.
7002 *
7003 * Memory reclaim happens asynchronously from work queue
7004 * to prevent expensive synchronize_rcu() in commit phase.
7005 */
7006 if (list_empty(&net->nft.commit_list)) {
7007 mutex_unlock(&net->nft.commit_mutex);
7008 return;
7009 }
7010
7011 trans = list_last_entry(&net->nft.commit_list,
7012 struct nft_trans, list);
7013 get_net(trans->ctx.net);
7014 WARN_ON_ONCE(trans->put_net);
7015
7016 trans->put_net = true;
7017 spin_lock(&nf_tables_destroy_list_lock);
7018 list_splice_tail_init(&net->nft.commit_list, &nf_tables_destroy_list);
^^^^^^^^^^^^^^^^^^^^^ ^^^^^^^^^^^^^^^^^^^^^^
This starts the process of freeing everything from net->nft.commit_list,
but we need to delete it from the net->nft.tables list as well.

7019 spin_unlock(&nf_tables_destroy_list_lock);
7020
7021 mutex_unlock(&net->nft.commit_mutex);
7022
7023 schedule_work(&trans_destroy_work);
7024 }

regards,
dan carpenter

syzbot

unread,
Jan 21, 2020, 7:37:10ā€ÆAM1/21/20
to core...@netfilter.org, dan.ca...@oracle.com, da...@davemloft.net, f...@strlen.de, kad...@netfilter.org, linux-...@vger.kernel.org, net...@vger.kernel.org, netfilt...@vger.kernel.org, pa...@netfilter.org, syzkall...@googlegroups.com
syzbot has found a reproducer for the following crash on:

HEAD commit: d96d875e Merge tag 'fixes_for_v5.5-rc8' of git://git.kerne..
git tree: upstream
console output: https://syzkaller.appspot.com/x/log.txt?x=10cd81c9e00000
kernel config: https://syzkaller.appspot.com/x/.config?x=83c00afca9cf5153
dashboard link: https://syzkaller.appspot.com/bug?extid=29125d208b3dae9a7019
compiler: clang version 10.0.0 (https://github.com/llvm/llvm-project/ c2443155a0fb245c8f17f2c1c72b6ea391e86e81)
syz repro: https://syzkaller.appspot.com/x/repro.syz?x=1203f521e00000
C reproducer: https://syzkaller.appspot.com/x/repro.c?x=10a706a5e00000

IMPORTANT: if you fix the bug, please add the following tag to the commit:
Reported-by: syzbot+29125d...@syzkaller.appspotmail.com

==================================================================
BUG: KASAN: use-after-free in __list_del_entry_valid+0x2f/0x100 lib/list_debug.c:42
Read of size 8 at addr ffff888097973008 by task syz-executor694/8782

CPU: 1 PID: 8782 Comm: syz-executor694 Not tainted 5.5.0-rc7-syzkaller #0
Hardware name: Google Google Compute Engine/Google Compute Engine, BIOS Google 01/01/2011
Call Trace:
__dump_stack lib/dump_stack.c:77 [inline]
dump_stack+0x1fb/0x318 lib/dump_stack.c:118
print_address_description+0x74/0x5c0 mm/kasan/report.c:374
__kasan_report+0x149/0x1c0 mm/kasan/report.c:506
kasan_report+0x26/0x50 mm/kasan/common.c:639
__asan_report_load8_noabort+0x14/0x20 mm/kasan/generic_report.c:135
__list_del_entry_valid+0x2f/0x100 lib/list_debug.c:42
__list_del_entry include/linux/list.h:131 [inline]
list_del_rcu include/linux/rculist.h:148 [inline]
__nf_tables_abort+0x16d2/0x2e80 net/netfilter/nf_tables_api.c:7258
nf_tables_abort+0x15/0x30 net/netfilter/nf_tables_api.c:7373
nfnetlink_rcv_batch net/netfilter/nfnetlink.c:494 [inline]
nfnetlink_rcv_skb_batch net/netfilter/nfnetlink.c:543 [inline]
nfnetlink_rcv+0x1a88/0x1e50 net/netfilter/nfnetlink.c:561
netlink_unicast_kernel net/netlink/af_netlink.c:1302 [inline]
netlink_unicast+0x767/0x920 net/netlink/af_netlink.c:1328
netlink_sendmsg+0xa2c/0xd50 net/netlink/af_netlink.c:1917
sock_sendmsg_nosec net/socket.c:639 [inline]
sock_sendmsg net/socket.c:659 [inline]
____sys_sendmsg+0x4f7/0x7f0 net/socket.c:2330
___sys_sendmsg net/socket.c:2384 [inline]
__sys_sendmsg+0x1ed/0x290 net/socket.c:2417
__do_sys_sendmsg net/socket.c:2426 [inline]
__se_sys_sendmsg net/socket.c:2424 [inline]
__x64_sys_sendmsg+0x7f/0x90 net/socket.c:2424
do_syscall_64+0xf7/0x1c0 arch/x86/entry/common.c:294
entry_SYSCALL_64_after_hwframe+0x49/0xbe
RIP: 0033:0x4470c9
Code: e8 dc e6 ff ff 48 83 c4 18 c3 0f 1f 80 00 00 00 00 48 89 f8 48 89 f7 48 89 d6 48 89 ca 4d 89 c2 4d 89 c8 4c 8b 4c 24 08 0f 05 <48> 3d 01 f0 ff ff 0f 83 2b 06 fc ff c3 66 2e 0f 1f 84 00 00 00 00
RSP: 002b:00007ffb4f1fad98 EFLAGS: 00000246 ORIG_RAX: 000000000000002e
RAX: ffffffffffffffda RBX: 00000000006dcc28 RCX: 00000000004470c9
RDX: 0000000000000000 RSI: 0000000020000280 RDI: 0000000000000003
RBP: 00000000006dcc20 R08: 0000000000000000 R09: 0000000000000000
R10: 0000000000000000 R11: 0000000000000246 R12: 00000000006dcc2c
R13: 00000000200002c0 R14: 00000000004af6c8 R15: 0000000000000000

Allocated by task 8782:
save_stack mm/kasan/common.c:72 [inline]
set_track mm/kasan/common.c:80 [inline]
__kasan_kmalloc+0x118/0x1c0 mm/kasan/common.c:513
kasan_kmalloc+0x9/0x10 mm/kasan/common.c:527
kmem_cache_alloc_trace+0x221/0x2f0 mm/slab.c:3551
kmalloc include/linux/slab.h:556 [inline]
kzalloc include/linux/slab.h:670 [inline]
nf_tables_newtable+0x350/0x1b10 net/netfilter/nf_tables_api.c:981
nfnetlink_rcv_batch net/netfilter/nfnetlink.c:433 [inline]
nfnetlink_rcv_skb_batch net/netfilter/nfnetlink.c:543 [inline]
nfnetlink_rcv+0xecf/0x1e50 net/netfilter/nfnetlink.c:561
netlink_unicast_kernel net/netlink/af_netlink.c:1302 [inline]
netlink_unicast+0x767/0x920 net/netlink/af_netlink.c:1328
netlink_sendmsg+0xa2c/0xd50 net/netlink/af_netlink.c:1917
sock_sendmsg_nosec net/socket.c:639 [inline]
sock_sendmsg net/socket.c:659 [inline]
____sys_sendmsg+0x4f7/0x7f0 net/socket.c:2330
___sys_sendmsg net/socket.c:2384 [inline]
__sys_sendmsg+0x1ed/0x290 net/socket.c:2417
__do_sys_sendmsg net/socket.c:2426 [inline]
__se_sys_sendmsg net/socket.c:2424 [inline]
__x64_sys_sendmsg+0x7f/0x90 net/socket.c:2424
do_syscall_64+0xf7/0x1c0 arch/x86/entry/common.c:294
entry_SYSCALL_64_after_hwframe+0x49/0xbe

Freed by task 2679:
save_stack mm/kasan/common.c:72 [inline]
set_track mm/kasan/common.c:80 [inline]
kasan_set_free_info mm/kasan/common.c:335 [inline]
__kasan_slab_free+0x12e/0x1e0 mm/kasan/common.c:474
kasan_slab_free+0xe/0x10 mm/kasan/common.c:483
__cache_free mm/slab.c:3426 [inline]
kfree+0x10d/0x220 mm/slab.c:3757
nft_commit_release net/netfilter/nf_tables_api.c:2496 [inline]
nf_tables_trans_destroy_work+0x9b8/0xbb0 net/netfilter/nf_tables_api.c:6860
process_one_work+0x7f5/0x10d0 kernel/workqueue.c:2264
worker_thread+0xbbc/0x1630 kernel/workqueue.c:2410
kthread+0x332/0x350 kernel/kthread.c:255
ret_from_fork+0x24/0x30 arch/x86/entry/entry_64.S:352

The buggy address belongs to the object at ffff888097973000
which belongs to the cache kmalloc-512 of size 512
The buggy address is located 8 bytes inside of
512-byte region [ffff888097973000, ffff888097973200)
The buggy address belongs to the page:
page:ffffea00025e5cc0 refcount:1 mapcount:0 mapping:ffff8880aa800a80 index:0x0
raw: 00fffe0000000200 ffffea0002a53ac8 ffffea0002806848 ffff8880aa800a80
raw: 0000000000000000 ffff888097973000 0000000100000004 0000000000000000
page dumped because: kasan: bad access detected

Memory state around the buggy address:
ffff888097972f00: fc fc fc fc fc fc fc fc fc fc fc fc fc fc fc fc
ffff888097972f80: fc fc fc fc fc fc fc fc fc fc fc fc fc fc fc fc
>ffff888097973000: fb fb fb fb fb fb fb fb fb fb fb fb fb fb fb fb
^
ffff888097973080: fb fb fb fb fb fb fb fb fb fb fb fb fb fb fb fb
ffff888097973100: fb fb fb fb fb fb fb fb fb fb fb fb fb fb fb fb
==================================================================

syzbot

unread,
Jan 21, 2020, 4:50:02ā€ÆPM1/21/20
to core...@netfilter.org, dan.ca...@oracle.com, da...@davemloft.net, f...@strlen.de, kad...@netfilter.org, linux-...@vger.kernel.org, net...@vger.kernel.org, netfilt...@vger.kernel.org, pa...@netfilter.org, syzkall...@googlegroups.com
syzbot has bisected this bug to:

commit ec7470b834fe7b5d7eff11b6677f5d7fdf5e9a91
Author: Pablo Neira Ayuso <pa...@netfilter.org>
Date: Mon Jan 13 17:09:58 2020 +0000

netfilter: nf_tables: store transaction list locally while requesting module

bisection log: https://syzkaller.appspot.com/x/bisect.txt?x=14890721e00000
start commit: d96d875e Merge tag 'fixes_for_v5.5-rc8' of git://git.kerne..
git tree: upstream
final crash: https://syzkaller.appspot.com/x/report.txt?x=16890721e00000
console output: https://syzkaller.appspot.com/x/log.txt?x=12890721e00000
Reported-by: syzbot+29125d...@syzkaller.appspotmail.com
Fixes: ec7470b834fe ("netfilter: nf_tables: store transaction list locally while requesting module")

For information about bisection process see: https://goo.gl/tpsmEJ#bisection
Reply all
Reply to author
Forward
0 new messages