Received: by 2002:a05:6a10:16a7:0:0:0:0 with SMTP id gp39csp3186804pxb; Mon, 9 Nov 2020 05:08:29 -0800 (PST) X-Google-Smtp-Source: ABdhPJyEpTevOJCjHNynynwauSKcg/sqOBFc0C/IZvQfbq2klDY3wgnjR3Yq+nyOxq3rq8SVC2RI X-Received: by 2002:aa7:d84a:: with SMTP id f10mr15495388eds.163.1604927309199; Mon, 09 Nov 2020 05:08:29 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1604927309; cv=none; d=google.com; s=arc-20160816; b=ELlsxbGM9GstLphHHGKDIGu6F0J5UNxmIf2s0iyeFRji5DSxKTfvQ/wrETTb248wBA WZxpYLlJtJqwQwQw5oH0WsFP4GxtP2ws+He+OU2BZAWR8TqopMyD0rWAdCbfov6Mfo/c 1kMtvciWzTFH/T++R9SnYQ+KiXxJT1OZV/m6AG8ziD26mO3+nTKsU+vQDI7nE6pKRu8q tg/U0ENNsyflAOJ08ocYTsqdjsXrkPg2b/IpF2OmlY9Gpijm6LI9EjOTVuS66ZuR6B0j nr0iHsBpQgDYAZsZPs5fRi79jOdWj5dJAevEGtmoLI5ACLAZoQJo4RxT4dgeqSR8Jurv ywoA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=lwri66EMafGtWUgdZC0kDgTMkDSK9kMBSDzAyGTCX0U=; b=Z0uIdYNI/+rHzyym13SulsgogPFiO42c/qCy/l7WY9e3I2sRr5odpO6fD2/ZHtJ/iB 3zQyoJCSHYdjVIkKrKFTVTMU+xWuOI8rXfKtEFU+ttsT5BytSt9syxE6s7VWneOoI9Am WWD3ZSxFEq411KMoT+f70rKQZspxNwwH4DHojusrR+L/u+t8mm1bKMXLGcLwIhMhdWHs Lso9oZHGAUM7x1QknY9CkavN1hiWWJ7zYqyKBceeh26ynZTxIH9XW1nBVZXfkSP5UgRU +NCpzbLEsrtCg8NlBoR5+cUb2JI5jx3nzb7XpIRjaPRCpBLe4AD4qVyn7koI6J+r81hb SC7A== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b="OcnP8Yo/"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id bo13si7282137ejb.463.2020.11.09.05.08.03; Mon, 09 Nov 2020 05:08:29 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b="OcnP8Yo/"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1730892AbgKINFb (ORCPT + 99 others); Mon, 9 Nov 2020 08:05:31 -0500 Received: from mail.kernel.org ([198.145.29.99]:57258 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1730695AbgKINEH (ORCPT ); Mon, 9 Nov 2020 08:04:07 -0500 Received: from localhost (83-86-74-64.cable.dynamic.v4.ziggo.nl [83.86.74.64]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id 26D7E20684; Mon, 9 Nov 2020 13:04:05 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1604927046; bh=B2kdkp/pbFTnaieAmmqhyuvGqEExh0llZokM/87xdhc=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=OcnP8Yo/1NmGK+L+wgiSXIf1TULgp3LnTflC1IKhFeCL3ynG7eYkaR8qxTWDh524V KZy4Dx1UeX/7uZoMz4VQmI4IQeBGBj3knnVdVMjo2LoLSaK+HxgmjojccDx4Eslltk rUHyXxoPuQhSggyv4tQOcYIi7ZOuzStv0XCdA4dQ= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, syzbot+6ea1f7a8df64596ef4d7@syzkaller.appspotmail.com, syzbot+e9cc557752ab126c1b99@syzkaller.appspotmail.com, Jon Maloy , Hoang Huu Le , "David S. Miller" Subject: [PATCH 4.9 093/117] tipc: fix use-after-free in tipc_bcast_get_mode Date: Mon, 9 Nov 2020 13:55:19 +0100 Message-Id: <20201109125030.111782654@linuxfoundation.org> X-Mailer: git-send-email 2.29.2 In-Reply-To: <20201109125025.630721781@linuxfoundation.org> References: <20201109125025.630721781@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Hoang Huu Le commit fdeba99b1e58ecd18c2940c453e19e4ef20ff591 upstream. Syzbot has reported those issues as: ================================================================== BUG: KASAN: use-after-free in tipc_bcast_get_mode+0x3ab/0x400 net/tipc/bcast.c:759 Read of size 1 at addr ffff88805e6b3571 by task kworker/0:6/3850 CPU: 0 PID: 3850 Comm: kworker/0:6 Not tainted 5.8.0-rc7-syzkaller #0 Hardware name: Google Google Compute Engine/Google Compute Engine, BIOS Google 01/01/2011 Workqueue: events tipc_net_finalize_work Thread 1's call trace: [...] kfree+0x103/0x2c0 mm/slab.c:3757 <- bcbase releasing tipc_bcast_stop+0x1b0/0x2f0 net/tipc/bcast.c:721 tipc_exit_net+0x24/0x270 net/tipc/core.c:112 [...] Thread 2's call trace: [...] tipc_bcast_get_mode+0x3ab/0x400 net/tipc/bcast.c:759 <- bcbase has already been freed by Thread 1 tipc_node_broadcast+0x9e/0xcc0 net/tipc/node.c:1744 tipc_nametbl_publish+0x60b/0x970 net/tipc/name_table.c:752 tipc_net_finalize net/tipc/net.c:141 [inline] tipc_net_finalize+0x1fa/0x310 net/tipc/net.c:131 tipc_net_finalize_work+0x55/0x80 net/tipc/net.c:150 [...] ================================================================== BUG: KASAN: use-after-free in tipc_named_reinit+0xef/0x290 net/tipc/name_distr.c:344 Read of size 8 at addr ffff888052ab2000 by task kworker/0:13/30628 CPU: 0 PID: 30628 Comm: kworker/0:13 Not tainted 5.8.0-syzkaller #0 Hardware name: Google Google Compute Engine/Google Compute Engine, BIOS Google 01/01/2011 Workqueue: events tipc_net_finalize_work Call Trace: __dump_stack lib/dump_stack.c:77 [inline] dump_stack+0x1f0/0x31e lib/dump_stack.c:118 print_address_description+0x66/0x5a0 mm/kasan/report.c:383 __kasan_report mm/kasan/report.c:513 [inline] kasan_report+0x132/0x1d0 mm/kasan/report.c:530 tipc_named_reinit+0xef/0x290 net/tipc/name_distr.c:344 tipc_net_finalize+0x85/0xe0 net/tipc/net.c:138 tipc_net_finalize_work+0x50/0x70 net/tipc/net.c:150 process_one_work+0x789/0xfc0 kernel/workqueue.c:2269 worker_thread+0xaa4/0x1460 kernel/workqueue.c:2415 kthread+0x37e/0x3a0 drivers/block/aoe/aoecmd.c:1234 ret_from_fork+0x1f/0x30 arch/x86/entry/entry_64.S:293 [...] Freed by task 14058: save_stack mm/kasan/common.c:48 [inline] set_track mm/kasan/common.c:56 [inline] kasan_set_free_info mm/kasan/common.c:316 [inline] __kasan_slab_free+0x114/0x170 mm/kasan/common.c:455 __cache_free mm/slab.c:3426 [inline] kfree+0x10a/0x220 mm/slab.c:3757 tipc_exit_net+0x29/0x50 net/tipc/core.c:113 ops_exit_list net/core/net_namespace.c:186 [inline] cleanup_net+0x708/0xba0 net/core/net_namespace.c:603 process_one_work+0x789/0xfc0 kernel/workqueue.c:2269 worker_thread+0xaa4/0x1460 kernel/workqueue.c:2415 kthread+0x37e/0x3a0 drivers/block/aoe/aoecmd.c:1234 ret_from_fork+0x1f/0x30 arch/x86/entry/entry_64.S:293 Fix it by calling flush_scheduled_work() to make sure the tipc_net_finalize_work() stopped before releasing bcbase object. Reported-by: syzbot+6ea1f7a8df64596ef4d7@syzkaller.appspotmail.com Reported-by: syzbot+e9cc557752ab126c1b99@syzkaller.appspotmail.com Acked-by: Jon Maloy Signed-off-by: Hoang Huu Le Signed-off-by: David S. Miller Signed-off-by: Greg Kroah-Hartman --- net/tipc/core.c | 5 +++++ 1 file changed, 5 insertions(+) --- a/net/tipc/core.c +++ b/net/tipc/core.c @@ -89,6 +89,11 @@ out_sk_rht: static void __net_exit tipc_exit_net(struct net *net) { tipc_net_stop(net); + + /* Make sure the tipc_net_finalize_work stopped + * before releasing the resources. + */ + flush_scheduled_work(); tipc_bcast_stop(net); tipc_nametbl_stop(net); tipc_sk_rht_destroy(net);