Received: by 2002:ac0:a581:0:0:0:0:0 with SMTP id m1-v6csp2974154imm; Sun, 1 Jul 2018 09:29:33 -0700 (PDT) X-Google-Smtp-Source: AAOMgpcmBG91Z+02PhSb6k0qeg+FIKKEavoz2SzA4sP6QX7/z3OYqapJZzLlfg66aEnxlROZM1k4 X-Received: by 2002:a17:902:7888:: with SMTP id q8-v6mr17565469pll.79.1530462573892; Sun, 01 Jul 2018 09:29:33 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1530462573; cv=none; d=google.com; s=arc-20160816; b=Xd2i8b5ZHw/9qs06qAOHAUAd0Wks4D+2FggXQM/2sgk7vhTqr7MIciLqr9+GZv5dd0 dmKmA28U/qy9g1v2Fq9LLBwlyLd2823IaKhSFZFcr8Ay4qCYWpnibM/q5Kk68JtwH6YH Irx/nNm8Qc0JfLPKWHlqvsifNIeOF56JYdDddlBZTGSO5NddwWEuybEEkfHlu14o6bte w7CK4ddGK57UExY8RFq7NrhBR6WMk67jh5+T4m4Q2J/pw5OEUmZEiA66GiUtbE29auj2 6S9h7HYGXeBNcoQ8etBg2PXKVt6Q/smb6YyoTcXosA2R2m9G9XYY6tTGN0jCSYe2w3m3 gdGg== 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=fIGbQzv4FiaH946t0xa6CBA1NCBY2RHCM+1mgUFsCGk=; b=0mVs9UNbifRfwRhdyK14JpmlUgw1tAmA1FkXWjqQtjmN0u7YQqJCTpIL6QWwNzH0ax Z9K8zD0eCo0dWBwA5noxZMdWHQGgl2/QEH2aIltUBa/DA0bTpODTUAF+o8F+lvSbnuyo sDUlYCA6vLbPk5ehccl+Hcr4coQI1OkZHprK1t0YWF6Eg7kfgtfQvhMDtujXXhvTAPKz 3CUa54KbsFtRyRvFkNiDUcDbnHxNcZRi+JVghcCW6A8wqiO5Q59bAMQb6qROVBF9DdC1 UNU08G0N/MxaijIyRFJFvi1z6n6aP4ADh+ff3a50bRrTGFzfqJJCHcB3cdjwVDuf1XJc GZFA== 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 a23-v6si13665803plm.305.2018.07.01.09.29.19; Sun, 01 Jul 2018 09:29:33 -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 S965650AbeGAQ2W (ORCPT + 99 others); Sun, 1 Jul 2018 12:28:22 -0400 Received: from mail.linuxfoundation.org ([140.211.169.12]:34292 "EHLO mail.linuxfoundation.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1030205AbeGAQ2T (ORCPT ); Sun, 1 Jul 2018 12:28:19 -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 8D0B392B; Sun, 1 Jul 2018 16:28:18 +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.9 090/101] rbd: flush rbd_dev->watch_dwork after watch is unregistered Date: Sun, 1 Jul 2018 18:22:16 +0200 Message-Id: <20180701160800.757849825@linuxfoundation.org> X-Mailer: git-send-email 2.18.0 In-Reply-To: <20180701160757.138608453@linuxfoundation.org> References: <20180701160757.138608453@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.9-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 @@ -3900,7 +3900,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); @@ -3918,6 +3917,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); }