Received: by 2002:ac0:a581:0:0:0:0:0 with SMTP id m1-v6csp2990466imm; Sun, 1 Jul 2018 09:50:52 -0700 (PDT) X-Google-Smtp-Source: ADUXVKJD7RykenewPMOGNu2+57UX4mcYE+tUfVZvPYQ2qxnyegaEfnXOwu1PKDck1J+MvWAFByR/ X-Received: by 2002:a17:902:b110:: with SMTP id q16-v6mr22693345plr.286.1530463852407; Sun, 01 Jul 2018 09:50:52 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1530463852; cv=none; d=google.com; s=arc-20160816; b=kaCs5oILA1+vfF4xxLS/VRy4CsMGImSGUM/Ss/SJJVXsWsaONCbD7Cljqdk+lldkG4 otyPi04GPsnKo8zyZFIuG5ajjbYJAFrk+sVxgjIFmEUAvxlI/c0/8OUULHqlJX/WN5Xy Y+B97QBKe4SMWKBQ0AveEzozIaN/2jxu7008M0fTy6E2DECoXf6jICUTqSpraWRJbT5H dFByHq1tcJic2L8S/mlqnYhdCAXiz+XQAALHMpRbNDHBlnuHDOWtBwezcZBwOiIKpCwY a7hvhqUK6jiW5j74Vj3IGIslaUZD5T5URbUpkj1R/zls68CWDvw58ivEtsnSs6srCnRa DeOQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:mime-version:user-agent:references :in-reply-to:message-id:date:subject:cc:to:from :arc-authentication-results; bh=Db4mY86mHgtdK9juU29epM6dAen5tfHgoiJdYjJzi1A=; b=wWKhXu6TY2gVn/TGMWZ4sGHzquKSXgjD1hZmPlWSyYYXi+hhuWo+UzIZiXAI4JLZ8H LzB4+5VA71P0UhFzUJOK1usYcyEFD/UY/cydn+JhBq6VM0ESttFrfO3xYhryakaxfPaP MXaNnrN5qDXntiAgEkEZCzhEyXrxOfsX+gzxSqVPqpWW2ibEqVTbJPsO4urz5AKIC17c BGf7XzsmE2bIq7ZzzgQ2djI9xb0IxqCRt8ohuqjjeV3p/6UhQSIZELGoH1V3JfgniTaE seOqoPlWjdRI8Eqfik9j3vRV++YWn6INy7HXgqa+RNYCtC5+NT1AWRiBmugybaSEhqxE 1cBQ== ARC-Authentication-Results: i=1; mx.google.com; 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 Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id h2-v6si9315048pfg.126.2018.07.01.09.50.38; Sun, 01 Jul 2018 09:50:52 -0700 (PDT) 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; 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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S933982AbeGAQsl (ORCPT + 99 others); Sun, 1 Jul 2018 12:48:41 -0400 Received: from mail.linuxfoundation.org ([140.211.169.12]:38558 "EHLO mail.linuxfoundation.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1032388AbeGAQqw (ORCPT ); Sun, 1 Jul 2018 12:46:52 -0400 Received: from localhost (LFbn-1-12247-202.w90-92.abo.wanadoo.fr [90.92.61.202]) by mail.linuxfoundation.org (Postfix) with ESMTPSA id DA56EA73; Sun, 1 Jul 2018 16:46:51 +0000 (UTC) From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Dongsheng Yang , Ilya Dryomov Subject: [PATCH 4.17 189/220] rbd: flush rbd_dev->watch_dwork after watch is unregistered Date: Sun, 1 Jul 2018 18:23:33 +0200 Message-Id: <20180701160916.097423160@linuxfoundation.org> X-Mailer: git-send-email 2.18.0 In-Reply-To: <20180701160908.272447118@linuxfoundation.org> References: <20180701160908.272447118@linuxfoundation.org> User-Agent: quilt/0.65 X-stable: review MIME-Version: 1.0 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 4.17-stable review patch. If anyone has any objections, please let me know. ------------------ From: Dongsheng Yang commit 23edca864951250af845a11da86bb3ea63522ed2 upstream. There is a problem if we are going to unmap a rbd device and the watch_dwork is going to queue delayed work for watch: unmap Thread watch Thread timer do_rbd_remove cancel_tasks_sync(rbd_dev) queue_delayed_work for watch destroy_workqueue(rbd_dev->task_wq) drain_workqueue(wq) destroy other resources in wq call_timer_fn __queue_work() Then the delayed work escape the cancel_tasks_sync() and destroy_workqueue() and we will get an user-after-free call trace: BUG: unable to handle kernel NULL pointer dereference at 0000000000000000 PGD 0 P4D 0 Oops: 0000 [#1] SMP PTI Modules linked in: CPU: 7 PID: 0 Comm: swapper/7 Tainted: G OE 4.17.0-rc6+ #13 Hardware name: Red Hat KVM, BIOS 0.5.1 01/01/2011 RIP: 0010:__queue_work+0x6a/0x3b0 RSP: 0018:ffff9427df1c3e90 EFLAGS: 00010086 RAX: ffff9427deca8400 RBX: 0000000000000000 RCX: 0000000000000000 RDX: ffff9427deca8400 RSI: ffff9427df1c3e50 RDI: 0000000000000000 RBP: ffff942783e39e00 R08: ffff9427deca8400 R09: ffff9427df1c3f00 R10: 0000000000000004 R11: 0000000000000005 R12: ffff9427cfb85970 R13: 0000000000002000 R14: 000000000001eca0 R15: 0000000000000007 FS: 0000000000000000(0000) GS:ffff9427df1c0000(0000) knlGS:0000000000000000 CS: 0010 DS: 0000 ES: 0000 CR0: 0000000080050033 CR2: 0000000000000000 CR3: 00000004c900a005 CR4: 00000000000206e0 Call Trace: ? __queue_work+0x3b0/0x3b0 call_timer_fn+0x2d/0x130 run_timer_softirq+0x16e/0x430 ? tick_sched_timer+0x37/0x70 __do_softirq+0xd2/0x280 irq_exit+0xd5/0xe0 smp_apic_timer_interrupt+0x6c/0x130 apic_timer_interrupt+0xf/0x20 [ Move rbd_dev->watch_dwork cancellation so that rbd_reregister_watch() either bails out early because the watch is UNREGISTERED at that point or just gets cancelled. ] Cc: stable@vger.kernel.org Fixes: 99d1694310df ("rbd: retry watch re-registration periodically") Signed-off-by: Dongsheng Yang Reviewed-by: Ilya Dryomov Signed-off-by: Ilya Dryomov Signed-off-by: Greg Kroah-Hartman --- drivers/block/rbd.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) --- a/drivers/block/rbd.c +++ b/drivers/block/rbd.c @@ -3397,7 +3397,6 @@ static void cancel_tasks_sync(struct rbd { dout("%s rbd_dev %p\n", __func__, rbd_dev); - cancel_delayed_work_sync(&rbd_dev->watch_dwork); cancel_work_sync(&rbd_dev->acquired_lock_work); cancel_work_sync(&rbd_dev->released_lock_work); cancel_delayed_work_sync(&rbd_dev->lock_dwork); @@ -3415,6 +3414,7 @@ static void rbd_unregister_watch(struct rbd_dev->watch_state = RBD_WATCH_STATE_UNREGISTERED; mutex_unlock(&rbd_dev->watch_mutex); + cancel_delayed_work_sync(&rbd_dev->watch_dwork); ceph_osdc_flush_notifies(&rbd_dev->rbd_client->client->osdc); }