From patchwork Sun May 27 02:21:25 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tetsuo Handa X-Patchwork-Id: 10429275 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 4605360362 for ; Sun, 27 May 2018 02:23:02 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 36FFF28B85 for ; Sun, 27 May 2018 02:23:02 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 2BA6F28B87; Sun, 27 May 2018 02:23:02 +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=unavailable 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 2F07E28CE1 for ; Sun, 27 May 2018 02:23:00 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1032572AbeE0CW4 (ORCPT ); Sat, 26 May 2018 22:22:56 -0400 Received: from www262.sakura.ne.jp ([202.181.97.72]:57850 "EHLO www262.sakura.ne.jp" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1032474AbeE0CWz (ORCPT ); Sat, 26 May 2018 22:22:55 -0400 Received: from fsav103.sakura.ne.jp (fsav103.sakura.ne.jp [27.133.134.230]) by www262.sakura.ne.jp (8.14.5/8.14.5) with ESMTP id w4R2LPX5043474; Sun, 27 May 2018 11:21:25 +0900 (JST) (envelope-from penguin-kernel@I-love.SAKURA.ne.jp) Received: from www262.sakura.ne.jp (202.181.97.72) by fsav103.sakura.ne.jp (F-Secure/fsigk_smtp/530/fsav103.sakura.ne.jp); Sun, 27 May 2018 11:21:25 +0900 (JST) X-Virus-Status: clean(F-Secure/fsigk_smtp/530/fsav103.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.14.5/8.14.5) with ESMTP id w4R2LPiE043471 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=NO); Sun, 27 May 2018 11:21:25 +0900 (JST) (envelope-from penguin-kernel@I-love.SAKURA.ne.jp) Subject: [PATCH] bdi: Fix another oops in wb_workfn() To: syzbot , syzkaller-bugs@googlegroups.com, jack@suse.cz Cc: linux-fsdevel@vger.kernel.org, linux-kernel@vger.kernel.org, viro@zeniv.linux.org.uk, axboe@kernel.dk, tj@kernel.org, david@fromorbit.com, linux-block@vger.kernel.org References: <000000000000cbd959056d1851ca@google.com> <0c7c5dea-7312-8a59-9d1b-5467f69719bf@I-love.SAKURA.ne.jp> From: Tetsuo Handa Message-ID: <314ae2e0-c873-04ce-9cd5-fe2acadaee26@I-love.SAKURA.ne.jp> Date: Sun, 27 May 2018 11:21:25 +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: <0c7c5dea-7312-8a59-9d1b-5467f69719bf@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 8a8222698163d1fe180258566e9a3ff43f54fcd9 Mon Sep 17 00:00:00 2001 From: Tetsuo Handa Date: Sun, 27 May 2018 11:08:20 +0900 Subject: [PATCH] bdi: Fix another oops in wb_workfn() syzbot is still hitting NULL pointer dereference at wb_workfn() [1]. This might be because we overlooked that delayed_work_timer_fn() does not check WB_registered before calling __queue_work() while mod_delayed_work() does not wait for already started delayed_work_timer_fn() because it uses del_timer() rather than del_timer_sync(). Make wb_shutdown() be careful about wb_wakeup_delayed() path. [1] https://syzkaller.appspot.com/bug?id=e0818ccb7e46190b3f1038b0c794299208ed4206 Signed-off-by: Tetsuo Handa Reported-by: syzbot Cc: Tejun Heo Cc: Dave Chinner Cc: Jan Kara Cc: Jens Axboe --- mm/backing-dev.c | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/mm/backing-dev.c b/mm/backing-dev.c index 7441bd9..31e1d7e 100644 --- a/mm/backing-dev.c +++ b/mm/backing-dev.c @@ -372,11 +372,24 @@ static void wb_shutdown(struct bdi_writeback *wb) cgwb_remove_from_bdi_list(wb); /* + * mod_delayed_work() is not appropriate here, for + * delayed_work_timer_fn() from wb_wakeup_delayed() does not check + * WB_registered before calling __queue_work(). + */ + del_timer_sync(&wb->dwork.timer); + /* + * Clear WORK_STRUCT_PENDING_BIT in order to make sure that next + * queue_delayed_work() actually enqueues this work to the tail, for + * wb_wakeup_delayed() already set WORK_STRUCT_PENDING_BIT before + * scheduling delayed_work_timer_fn(). + */ + cancel_delayed_work_sync(&wb->dwork); + /* * Drain work list and shutdown the delayed_work. !WB_registered * tells wb_workfn() that @wb is dying and its work_list needs to * be drained no matter what. */ - mod_delayed_work(bdi_wq, &wb->dwork, 0); + queue_delayed_work(bdi_wq, &wb->dwork, 0); flush_delayed_work(&wb->dwork); WARN_ON(!list_empty(&wb->work_list)); /*