Received: by 2002:a05:6a10:16a7:0:0:0:0 with SMTP id gp39csp3201341pxb; Mon, 9 Nov 2020 05:28:31 -0800 (PST) X-Google-Smtp-Source: ABdhPJyDYu0mUf2XLgH2fNUeZ7LiCoPpJbal9O5d9o7A/iB6KpDIC4aPqUwoPs4B0qlX00jLxKI0 X-Received: by 2002:a17:906:fcdb:: with SMTP id qx27mr15249780ejb.470.1604928510822; Mon, 09 Nov 2020 05:28:30 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1604928510; cv=none; d=google.com; s=arc-20160816; b=uU3MnChnH1OR6G8Z8j8+IBJU3v3dfobnm7CHbzryB5MI95+u36+cyilet43wXaZFsG O13Zpe9V8aN6OQfe5EKV/x4f9mkxlZea/yQNy3iWD8s45vH5hhLDrqNZLeVs79PuQv2M iQu8OpCXPdMcKBRtp3+6oYtkLi3Ih0HecUzPECfHTlUL3gdafB+RDyBilk6nmC7Ye4L3 c5Vm56ZkzUifxOA9ETsqIvmuFOkMhNXHJ3SSag8AmVG8pXycbCHlynXkC+WJgu9Z8dBi dgA9AkeuWRx9EZPxyq5H4P8nnYyZ73610X3Q7Rdr+f0OCD/gnnnvmWXCf1HFkAB5aXVk 7wPA== 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=IkSGndWUjm4ms6eFXfyMfJGAbDr11YucUHtZIy3gpvo=; b=WkJm29Lu0/xRWHOoQMEzNEdByLwS0rJwjDFC0PvlytOwaGm/bGbU9mk0vdPPPrLTTZ oTPHs6PCn/MXMdBdA7zxMxzm/YCtF1wUIuYlrAgmkzpen2u36Q4w3U+XVTw1s+CFPOhy 7Jx6veho6TBcm/PpLYAVYrW2S2J5rBj3kVm/r3LZqTYRLuYDlSZ+DiXeom32JZPfRgsg Qsps46liTDiS3wAl8MaXIHGQ8wynJCmwbVRLSzNTBpyh4SXxNlDosmWa3KBrHu05uIr4 ec/HPIeKeMta4qAAwDnjT2Z+GXfa7EEe/HO4AtarKtYduvkdWZv41tEPgvFl3a4Mk3cF MOeA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=XU32G8ZV; 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 d12si8283315ejj.33.2020.11.09.05.28.07; Mon, 09 Nov 2020 05:28:30 -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=XU32G8ZV; 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 S1732964AbgKIN03 (ORCPT + 99 others); Mon, 9 Nov 2020 08:26:29 -0500 Received: from mail.kernel.org ([198.145.29.99]:43374 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2387471AbgKINQX (ORCPT ); Mon, 9 Nov 2020 08:16:23 -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 0C67820867; Mon, 9 Nov 2020 13:16:21 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1604927782; bh=BsbV5R37S5LXtLNYFMZNRwSyrlFcm5wsHKLJ+6cqMg0=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=XU32G8ZVS4N697KGVIZo/BkRX9Ac89kG51oUlFqhcNZGsJWZNurAaNEzcUOsLFYIj ud/Km2zTSWvcKCyt19UfOZb+I4Ss53MnBfAC8OHy/Blx12Sl/mMA24RuP1KQZ9V3ad ztOSUkh2m1gTbEIRm2LnX1FmvJFXj/T6aH1W4FLI= 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 5.9 002/133] tipc: fix use-after-free in tipc_bcast_get_mode Date: Mon, 9 Nov 2020 13:54:24 +0100 Message-Id: <20201109125030.833538977@linuxfoundation.org> X-Mailer: git-send-email 2.29.2 In-Reply-To: <20201109125030.706496283@linuxfoundation.org> References: <20201109125030.706496283@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 @@ -109,6 +109,11 @@ static void __net_exit tipc_exit_net(str { tipc_detach_loopback(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);