Received: by 2002:a25:8b91:0:0:0:0:0 with SMTP id j17csp1050290ybl; Fri, 10 Jan 2020 11:10:57 -0800 (PST) X-Google-Smtp-Source: APXvYqyIkeqf95KCdJGu9XbDTyLfCydWaWk084HHBbkxcjKy74tK3ZlG7wnCMk+LWbOLiIH5UBvv X-Received: by 2002:aca:4ad1:: with SMTP id x200mr3276841oia.104.1578683457110; Fri, 10 Jan 2020 11:10:57 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1578683457; cv=none; d=google.com; s=arc-20160816; b=hj8SO9mwiNBFVdotSALO05/bWGdOa4vfyXl51/MQK3CnvBzoW6RK/LaAdnkxHtm2XI 4sCFnsK17Kgmr8flUKpPV9lVamA5kvzr9byKuvsc+vaom9WoD9EThDtNVnPlvuc399mI 68ZN6eik7QTreplAtakdi2LyKJYk396asCcN9qGF2cooQ0BAfHcMuLuPMYrl/8jLAN27 h1guGuPgaiEZSFAgRcXO5jCv0J5tJUvjNVTKmVn+dtntSoPgEIBHyWKygwPO4P406tR3 fEcSby3kH7kGK+d09YiJfAA00LkHVzIxpaz8u9Vl8wko6PCACkYB3FHPZpHt/g76MdpD zk7w== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:dkim-signature; bh=Kcu1M9u0fKXhYde93cLWMfS1bu+/Sqpq3Xxjg8yPfgE=; b=qcUXpdjUmf7amefahsr2k/7t3X9mVFOmVXltPyBOaCzIZqr4ijx22R/Id0XrJwDAzk a0lpXtTbSNHB4rZhIqG5JykEoxFTBTn5VvettZCdfgVXXdS/Uo1E0XQ3hWpFxl4AF76f S0CidO4Mou+pL6HSfSfZTDmjuN0jvkFKoA3aQl9W9WvnDE7IYs+S4AvyIZl4Q3tVs0+O 9144E1RJxYBkZy6shRaCgS0OH1q7oho9G49ZlT6KF6i9l4hpdJYVtFa+h8iZVHb7Pggr AxxJ0UmQd7j3ezJk5uMG4bkvqgqRRYSeWe7HRLdFK5415NY2eQJQd1tpT73cixcukwrv U6Cw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b="uTvla9/R"; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id u188si1665692oia.80.2020.01.10.11.10.22; Fri, 10 Jan 2020 11:10:57 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b="uTvla9/R"; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728118AbgAJTJ2 (ORCPT + 99 others); Fri, 10 Jan 2020 14:09:28 -0500 Received: from mail-oi1-f195.google.com ([209.85.167.195]:42288 "EHLO mail-oi1-f195.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727448AbgAJTJ2 (ORCPT ); Fri, 10 Jan 2020 14:09:28 -0500 Received: by mail-oi1-f195.google.com with SMTP id 18so2781974oin.9; Fri, 10 Jan 2020 11:09:27 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=Kcu1M9u0fKXhYde93cLWMfS1bu+/Sqpq3Xxjg8yPfgE=; b=uTvla9/RwAC4Gb1XeGvMf1m8nX3xtJMrNX2pzSpoHpiPGrTkPvyiO0DlRqI8OoeiU3 e/yyUpsRaz/3i9KGgA4vqZyc/YeB0spWAiXa8n6BluiGRkHkjo9oWkNGz+OgC512X7nU sEVcsS6tyctLAY4EgetnFy4VzY0vMot7qSPD17Mv5G4f11XIiEthXlEizIErEomXL8BA lctYm9S+SwMptnfiD9BK9QP8wjSO+nKTeG4afHLpc1//TA9SmdC804IGalwd2l5Q2MC4 IXmPqMrxoi04u/w3E7UObSi8clvspX/u+tyw84nhbVIBFQXCfzBFjSuQIX9mYMyGzZBE BZPg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=Kcu1M9u0fKXhYde93cLWMfS1bu+/Sqpq3Xxjg8yPfgE=; b=nD9XM/dYjjsiWoHvnWx4krqxuKBoqDLcniFdPdTq6a4ynpFktWKPcqeCjvhvdBmkcG 7UYQQO0l38QkwM+VIMlRKMX0A9I9NtqoCR8DE9aSzKkhmxJHxMo4EG4ya+1OMfeYYyDD v+Yya1HFeCrWgQSrA/E8edODPOgtHNWvPDeCMmbG3odPxaGq/d0PPtDTMOCZ4DUQdNAF LgiUE2zlE+N24UgLOfZdt/+CUip82iDqwNDwpysBHE4AfJBgP7IneHqmjWsZ+mssFKzO jA0Umw5t6f0ICgBHltcRZeKsh9U4xYUwFvCnLgV+ATa9hSFCJAcl4uY/j0eXFAG3YWaB pGig== X-Gm-Message-State: APjAAAUsLOLXixmIH2lLMAA2tJ/hlJi2qe3p1wr4qrH9PM3A1Zzb4pWn AtPiCdhpNf5KLQEq6OUJPM/VnKlYvkT+GG78jaA= X-Received: by 2002:aca:1011:: with SMTP id 17mr3502147oiq.72.1578683367302; Fri, 10 Jan 2020 11:09:27 -0800 (PST) MIME-Version: 1.0 References: <000000000000f744e0059bcd8216@google.com> In-Reply-To: <000000000000f744e0059bcd8216@google.com> From: Cong Wang Date: Fri, 10 Jan 2020 11:09:16 -0800 Message-ID: Subject: Re: KASAN: use-after-free Read in bitmap_port_ext_cleanup To: syzbot Cc: Arvid Brodin , coreteam@netfilter.org, David Miller , florent.fourcot@wifirst.fr, Florian Westphal , jeremy@azazel.net, Johannes Berg , kadlec@netfilter.org, LKML , Linux Kernel Network Developers , NetFilter , Pablo Neira Ayuso , syzkaller-bugs Content-Type: text/plain; charset="UTF-8" Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Fri, Jan 10, 2020 at 10:44 AM syzbot wrote: > > Hello, > > syzbot found the following crash on: > > HEAD commit: b07f636f Merge tag 'tpmdd-next-20200108' of git://git.infr.. > git tree: upstream > console output: https://syzkaller.appspot.com/x/log.txt?x=16c03259e00000 > kernel config: https://syzkaller.appspot.com/x/.config?x=18698c0c240ba616 > dashboard link: https://syzkaller.appspot.com/bug?extid=4c3cc6dbe7259dbf9054 > compiler: gcc (GCC) 9.0.0 20181231 (experimental) > userspace arch: i386 > syz repro: https://syzkaller.appspot.com/x/repro.syz?x=10c365c6e00000 > C reproducer: https://syzkaller.appspot.com/x/repro.c?x=117df9e1e00000 > > The bug was bisected to: > > commit b9a1e627405d68d475a3c1f35e685ccfb5bbe668 > Author: Cong Wang > Date: Thu Jul 4 00:21:13 2019 +0000 > > hsr: implement dellink to clean up resources > > bisection log: https://syzkaller.appspot.com/x/bisect.txt?x=118759e1e00000 > final crash: https://syzkaller.appspot.com/x/report.txt?x=138759e1e00000 > console output: https://syzkaller.appspot.com/x/log.txt?x=158759e1e00000 > > IMPORTANT: if you fix the bug, please add the following tag to the commit: > Reported-by: syzbot+4c3cc6dbe7259dbf9054@syzkaller.appspotmail.com > Fixes: b9a1e627405d ("hsr: implement dellink to clean up resources") > > ================================================================== > BUG: KASAN: use-after-free in test_bit > include/asm-generic/bitops/instrumented-non-atomic.h:110 [inline] > BUG: KASAN: use-after-free in bitmap_port_ext_cleanup+0xe6/0x2a0 > net/netfilter/ipset/ip_set_bitmap_gen.h:51 > Read of size 8 at addr ffff8880a87a47c0 by task syz-executor559/9563 > > CPU: 0 PID: 9563 Comm: syz-executor559 Not tainted 5.5.0-rc5-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 > check_memory_region_inline mm/kasan/generic.c:185 [inline] > check_memory_region+0x134/0x1a0 mm/kasan/generic.c:192 > __kasan_check_read+0x11/0x20 mm/kasan/common.c:95 > test_bit include/asm-generic/bitops/instrumented-non-atomic.h:110 [inline] > bitmap_port_ext_cleanup+0xe6/0x2a0 map->members is freed by ip_set_free() right before using it in mtype_ext_cleanup() again. So I think probably we just have to move it down: diff --git a/net/netfilter/ipset/ip_set_bitmap_gen.h b/net/netfilter/ipset/ip_set_bitmap_gen.h index 1abd6f0dc227..077a2cb65fcb 100644 --- a/net/netfilter/ipset/ip_set_bitmap_gen.h +++ b/net/netfilter/ipset/ip_set_bitmap_gen.h @@ -60,9 +60,9 @@ mtype_destroy(struct ip_set *set) if (SET_WITH_TIMEOUT(set)) del_timer_sync(&map->gc); - ip_set_free(map->members); if (set->dsize && set->extensions & IPSET_EXT_DESTROY) mtype_ext_cleanup(set); + ip_set_free(map->members); ip_set_free(map); set->data = NULL; Thanks.