From mboxrd@z Thu Jan 1 00:00:00 1970 From: Tyler Hicks Subject: Re: [PATCH net-next] net: gro: properly remove skb from list Date: Thu, 12 Jul 2018 16:54:16 +0000 Message-ID: <20180712165415.GA16049@sec> References: <20180712072459.8800-1-bhole_prashant_q7@lab.ntt.co.jp> Mime-Version: 1.0 Content-Type: multipart/signed; micalg=pgp-sha512; protocol="application/pgp-signature"; boundary="XsQoSWH+UP9D9v3l" Cc: "David S . Miller" , Jesper Dangaard Brouer , netdev@vger.kernel.org To: Prashant Bhole Return-path: Received: from youngberry.canonical.com ([91.189.89.112]:47317 "EHLO youngberry.canonical.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726775AbeGLREr (ORCPT ); Thu, 12 Jul 2018 13:04:47 -0400 Content-Disposition: inline In-Reply-To: <20180712072459.8800-1-bhole_prashant_q7@lab.ntt.co.jp> Sender: netdev-owner@vger.kernel.org List-ID: --XsQoSWH+UP9D9v3l Content-Type: text/plain; charset=us-ascii Content-Disposition: inline Content-Transfer-Encoding: quoted-printable On 2018-07-12 16:24:59, Prashant Bhole wrote: > Following crash occurs in validate_xmit_skb_list() when same skb is > iterated multiple times in the loop and consume_skb() is called. >=20 > The root cause is calling list_del_init(&skb->list) and not clearing > skb->next in d4546c2509b1. list_del_init(&skb->list) sets skb->next > to point to skb itself. skb->next needs to be cleared because other > parts of network stack uses another kind of SKB lists. > validate_xmit_skb_list() uses such list. >=20 > A similar type of bugfix was reported by Jesper Dangaard Brouer. > https://patchwork.ozlabs.org/patch/942541/ >=20 > This patch clears skb->next and changes list_del_init() to list_del() > so that list->prev will maintain the list poison. >=20 > [ 148.185511] =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D > [ 148.187865] BUG: KASAN: use-after-free in validate_xmit_skb_list+0x4b/= 0xa0 > [ 148.190158] Read of size 8 at addr ffff8801e52eefc0 by task swapper/1/0 > [ 148.192940] > [ 148.193642] CPU: 1 PID: 0 Comm: swapper/1 Not tainted 4.18.0-rc3+ #25 > [ 148.195423] Hardware name: QEMU Standard PC (i440FX + PIIX, 1996), BIO= S ?-20180531_142017-buildhw-08.phx2.fedoraproject.org-1.fc28 04/01/2014 > [ 148.199129] Call Trace: > [ 148.200565] > [ 148.201911] dump_stack+0xc6/0x14c > [ 148.203572] ? dump_stack_print_info.cold.1+0x2f/0x2f > [ 148.205083] ? kmsg_dump_rewind_nolock+0x59/0x59 > [ 148.206307] ? validate_xmit_skb+0x2c6/0x560 > [ 148.207432] ? debug_show_held_locks+0x30/0x30 > [ 148.208571] ? validate_xmit_skb_list+0x4b/0xa0 > [ 148.211144] print_address_description+0x6c/0x23c > [ 148.212601] ? validate_xmit_skb_list+0x4b/0xa0 > [ 148.213782] kasan_report.cold.6+0x241/0x2fd > [ 148.214958] validate_xmit_skb_list+0x4b/0xa0 > [ 148.216494] sch_direct_xmit+0x1b0/0x680 > [ 148.217601] ? dev_watchdog+0x4e0/0x4e0 > [ 148.218675] ? do_raw_spin_trylock+0x10/0x120 > [ 148.219818] ? do_raw_spin_lock+0xe0/0xe0 > [ 148.221032] __dev_queue_xmit+0x1167/0x1810 > [ 148.222155] ? sched_clock+0x5/0x10 > [...] >=20 > [ 148.474257] Allocated by task 0: > [ 148.475363] kasan_kmalloc+0xbf/0xe0 > [ 148.476503] kmem_cache_alloc+0xb4/0x1b0 > [ 148.477654] __build_skb+0x91/0x250 > [ 148.478677] build_skb+0x67/0x180 > [ 148.479657] e1000_clean_rx_irq+0x542/0x8a0 > [ 148.480757] e1000_clean+0x652/0xd10 > [ 148.481772] net_rx_action+0x4ea/0xc20 > [ 148.482808] __do_softirq+0x1f9/0x574 > [ 148.483831] > [ 148.484575] Freed by task 0: > [ 148.485504] __kasan_slab_free+0x12e/0x180 > [ 148.486589] kmem_cache_free+0xb4/0x240 > [ 148.487634] kfree_skbmem+0xed/0x150 > [ 148.488648] consume_skb+0x146/0x250 > [ 148.489665] validate_xmit_skb+0x2b7/0x560 > [ 148.490754] validate_xmit_skb_list+0x70/0xa0 > [ 148.491897] sch_direct_xmit+0x1b0/0x680 > [ 148.493949] __dev_queue_xmit+0x1167/0x1810 > [ 148.495103] br_dev_queue_push_xmit+0xce/0x250 > [ 148.496196] br_forward_finish+0x276/0x280 > [ 148.497234] __br_forward+0x44f/0x520 > [ 148.498260] br_forward+0x19f/0x1b0 > [ 148.499264] br_handle_frame_finish+0x65e/0x980 > [ 148.500398] NF_HOOK.constprop.10+0x290/0x2a0 > [ 148.501522] br_handle_frame+0x417/0x640 > [ 148.502582] __netif_receive_skb_core+0xaac/0x18f0 > [ 148.503753] __netif_receive_skb_one_core+0x98/0x120 > [ 148.504958] netif_receive_skb_internal+0xe3/0x330 > [ 148.506154] napi_gro_complete+0x190/0x2a0 > [ 148.507243] dev_gro_receive+0x9f7/0x1100 > [ 148.508316] napi_gro_receive+0xcb/0x260 > [ 148.509387] e1000_clean_rx_irq+0x2fc/0x8a0 > [ 148.510501] e1000_clean+0x652/0xd10 > [ 148.511523] net_rx_action+0x4ea/0xc20 > [ 148.512566] __do_softirq+0x1f9/0x574 > [ 148.513598] > [ 148.514346] The buggy address belongs to the object at ffff8801e52eefc0 > [ 148.514346] which belongs to the cache skbuff_head_cache of size 232 > [ 148.517047] The buggy address is located 0 bytes inside of > [ 148.517047] 232-byte region [ffff8801e52eefc0, ffff8801e52ef0a8) > [ 148.519549] The buggy address belongs to the page: > [ 148.520726] page:ffffea000794bb00 count:1 mapcount:0 mapping:ffff88010= 6f4dfc0 index:0xffff8801e52ee840 compound_mapcount: 0 > [ 148.524325] flags: 0x17ffffc0008100(slab|head) > [ 148.525481] raw: 0017ffffc0008100 ffff880106b938d0 ffff880106b938d0 ff= ff880106f4dfc0 > [ 148.527503] raw: ffff8801e52ee840 0000000000190011 00000001ffffffff 00= 00000000000000 > [ 148.529547] page dumped because: kasan: bad access detected >=20 > Fixes: d4546c2509b1 ("net: Convert GRO SKB handling to list_head.") > Signed-off-by: Prashant Bhole > Reported-by: Tyler Hicks Thanks for the fix! I have verified that it fixes the crash that I was seeing. Tested-by: Tyler Hicks Your analysis of the problem makes sense. I feel like a helper function to properly remove an skb from list_head and NULL the next pointer, in the GRO code, before passing it on to something else that uses the hand-rolled linked list implementation could help with maintainability. That's just a suggestion - this patch looks good to me: Reviewed-by: Tyler Hicks Tyler > --- > net/core/dev.c | 6 ++++-- > 1 file changed, 4 insertions(+), 2 deletions(-) >=20 > diff --git a/net/core/dev.c b/net/core/dev.c > index d13cddcac41f..08c41941f912 100644 > --- a/net/core/dev.c > +++ b/net/core/dev.c > @@ -5169,7 +5169,8 @@ static void __napi_gro_flush_chain(struct napi_stru= ct *napi, u32 index, > list_for_each_entry_safe_reverse(skb, p, head, list) { > if (flush_old && NAPI_GRO_CB(skb)->age =3D=3D jiffies) > return; > - list_del_init(&skb->list); > + list_del(&skb->list); > + skb->next =3D NULL; > napi_gro_complete(skb); > napi->gro_count--; > napi->gro_hash[index].count--; > @@ -5350,7 +5351,8 @@ static enum gro_result dev_gro_receive(struct napi_= struct *napi, struct sk_buff > ret =3D NAPI_GRO_CB(skb)->free ? GRO_MERGED_FREE : GRO_MERGED; > =20 > if (pp) { > - list_del_init(&pp->list); > + list_del(&pp->list); > + pp->next =3D NULL; > napi_gro_complete(pp); > napi->gro_count--; > napi->gro_hash[hash].count--; > --=20 > 2.17.1 >=20 >=20 --XsQoSWH+UP9D9v3l Content-Type: application/pgp-signature; name="signature.asc" -----BEGIN PGP SIGNATURE----- Version: GnuPG v1 iQIcBAEBCgAGBQJbR4e3AAoJENaSAD2qAscKkcEP/A2S12vDOSApDC1PJIGdwyrn adAKWYlUa+XvYo2HfhuT88P1sq21NWe4SJjtqICVyMDft5q++oqV9GVnC6PE7nMS IqCl/TwNy1DUOMb3roTZeB8ZzOQ8s89lddjgkiNefewh7xpg44LP59cuO+ox6jgw OZaQyjWWFSSM4DyS4/SmVjgCQAujZ7ghMoe1GgNIoHPTVaoSItdPMaR7PZOtCBzo +HNnhW3fZyxKNrE0skYB6aJMzO66qPVCB43/N2LuOQXSv9taJt0BR89lKd6Ytnf7 3jo7UTkmVS5b4nvZQnYXKrlNLwJ6JwS0haBjYpc/m/VkTSddQ5rNdfCAqqp2AUGC Fpf5qxaFxFEwOLCQpXklbR4TWjEl81C3skd9HZXiJAR2lIG8cESxWZUXpAiV2uZE TZoOECjsMY795qtomKy/aX4LJYrjAUar+vLAv2ttrNicuuGkTvlFpwE4ccAnKIIL Rdvv9J3L9LH4Bf+F5U5rEKenv552JsJVwW2SzdRCzMCmDVBofZ7rVa1NNrVazVK7 +hSTyybNuQeMBRs7ABBn5GvoPPje1XMvxV9jlvaDzYxnjbPkDQWB8Q4eneKf2bM/ G4W6gfojo8RQlveYp7mqcFomuwKx60wT4+RXCJ0Ihmcr058N+6h4sNuiZYZsk0Hk zlmiH00Z0ylzTPYJRvQw =M7NU -----END PGP SIGNATURE----- --XsQoSWH+UP9D9v3l--