From patchwork Sat Jun 9 14:00:05 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tetsuo Handa X-Patchwork-Id: 10455885 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 918B2601F7 for ; Sat, 9 Jun 2018 14:01:10 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 76824223A6 for ; Sat, 9 Jun 2018 14:01:10 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 6810E223B2; Sat, 9 Jun 2018 14:01:10 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-7.9 required=2.0 tests=BAYES_00, MAILING_LIST_MULTI, RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id A8213223A6 for ; Sat, 9 Jun 2018 14:01:09 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753175AbeFIOBI (ORCPT ); Sat, 9 Jun 2018 10:01:08 -0400 Received: from www262.sakura.ne.jp ([202.181.97.72]:38770 "EHLO www262.sakura.ne.jp" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1753062AbeFIOBH (ORCPT ); Sat, 9 Jun 2018 10:01:07 -0400 Received: from fsav402.sakura.ne.jp (fsav402.sakura.ne.jp [133.242.250.101]) by www262.sakura.ne.jp (8.15.2/8.15.2) with ESMTP id w59E0BIc067745; Sat, 9 Jun 2018 23:00:11 +0900 (JST) (envelope-from penguin-kernel@i-love.sakura.ne.jp) Received: from www262.sakura.ne.jp (202.181.97.72) by fsav402.sakura.ne.jp (F-Secure/fsigk_smtp/530/fsav402.sakura.ne.jp); Sat, 09 Jun 2018 23:00:11 +0900 (JST) X-Virus-Status: clean(F-Secure/fsigk_smtp/530/fsav402.sakura.ne.jp) Received: from [192.168.1.8] (softbank126074194044.bbtec.net [126.74.194.44]) (authenticated bits=0) by www262.sakura.ne.jp (8.15.2/8.15.2) with ESMTPSA id w59E06c1067715 (version=TLSv1.2 cipher=DHE-RSA-AES256-SHA bits=256 verify=NO); Sat, 9 Jun 2018 23:00:11 +0900 (JST) (envelope-from penguin-kernel@i-love.sakura.ne.jp) Subject: [PATCH] bdi: Fix another oops in wb_workfn() From: Tetsuo Handa To: Dmitry Vyukov Cc: Jens Axboe , Jan Kara , syzbot , syzkaller-bugs , linux-fsdevel , LKML , Al Viro , Tejun Heo , Dave Chinner , linux-block@vger.kernel.org, Linus Torvalds References: <95865cab-e12f-d45b-b6e3-465b624862ba@i-love.sakura.ne.jp> <201806080231.w582VIRn021009@www262.sakura.ne.jp> <2b437c6f-3e10-3d83-bdf3-82075d3eaa1a@i-love.sakura.ne.jp> Message-ID: <3cf4b0e3-31b6-8cdc-7c1e-15ba575a7879@i-love.sakura.ne.jp> Date: Sat, 9 Jun 2018 23:00:05 +0900 User-Agent: Mozilla/5.0 (Windows NT 6.3; WOW64; rv:52.0) Gecko/20100101 Thunderbird/52.8.0 MIME-Version: 1.0 In-Reply-To: <2b437c6f-3e10-3d83-bdf3-82075d3eaa1a@i-love.sakura.ne.jp> Content-Language: en-US Sender: linux-block-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-block@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP From 014c4149f2e24cd26b278b32d5dfda056eecf093 Mon Sep 17 00:00:00 2001 From: Tetsuo Handa Date: Sat, 9 Jun 2018 22:47:52 +0900 Subject: [PATCH] bdi: Fix another oops in wb_workfn() syzbot is reporting NULL pointer dereference at wb_workfn() [1] due to wb->bdi->dev being NULL. And Dmitry confirmed that wb->state was WB_shutting_down after wb->bdi->dev became NULL. This indicates that unregister_bdi() failed to call wb_shutdown() on one of wb objects. Since cgwb_bdi_unregister() from bdi_unregister() cannot call wb_shutdown() on wb objects which have already passed list_del_rcu() in wb_shutdown(), cgwb_bdi_unregister() from bdi_unregister() can return and set wb->bdi->dev to NULL before such wb objects enter final round of wb_workfn() via mod_delayed_work()/flush_delayed_work(). Since WB_registered is already cleared by wb_shutdown(), only wb_shutdown() can schedule for final round of wb_workfn(). Since concurrent calls to wb_shutdown() on the same wb object is safe because of WB_shutting_down state, I think that wb_shutdown() can safely keep a wb object in the bdi->wb_list until that wb object leaves final round of wb_workfn(). Thus, make wb_shutdown() call list_del_rcu() after flush_delayed_work(). [1] https://syzkaller.appspot.com/bug?id=e0818ccb7e46190b3f1038b0c794299208ed4206 Signed-off-by: Tetsuo Handa Reported-by: syzbot Cc: Dmitry Vyukov Cc: Tejun Heo Cc: Jan Kara Cc: Jens Axboe --- mm/backing-dev.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/mm/backing-dev.c b/mm/backing-dev.c index 347cc83..bef4b25 100644 --- a/mm/backing-dev.c +++ b/mm/backing-dev.c @@ -370,7 +370,6 @@ static void wb_shutdown(struct bdi_writeback *wb) set_bit(WB_shutting_down, &wb->state); spin_unlock_bh(&wb->work_lock); - cgwb_remove_from_bdi_list(wb); /* * Drain work list and shutdown the delayed_work. !WB_registered * tells wb_workfn() that @wb is dying and its work_list needs to @@ -379,6 +378,7 @@ static void wb_shutdown(struct bdi_writeback *wb) mod_delayed_work(bdi_wq, &wb->dwork, 0); flush_delayed_work(&wb->dwork); WARN_ON(!list_empty(&wb->work_list)); + cgwb_remove_from_bdi_list(wb); /* * Make sure bit gets cleared after shutdown is finished. Matches with * the barrier provided by test_and_clear_bit() above.