Received: by 2002:ad5:474a:0:0:0:0:0 with SMTP id i10csp3469430imu; Sun, 11 Nov 2018 15:49:42 -0800 (PST) X-Google-Smtp-Source: AJdET5doe+7tNJkbHcMZ7C5Zdm10duxIegvh1CaG23OSrqkinx4oUTUBM9vxrDDux4dZdhP/CJcn X-Received: by 2002:a63:5357:: with SMTP id t23-v6mr15735380pgl.40.1541980182409; Sun, 11 Nov 2018 15:49:42 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1541980182; cv=none; d=google.com; s=arc-20160816; b=sxsPgqcJLAOtx/8abqUDv/UviMvYHXjjwx1lRfUJJkigcl0G0S0n2GUY0x4kw0dCWv F0uoUyWIHItyxjCkA3LOttO5qk5slj3VpzHNrJ59DCuNM50Bc+Pzw+VsoKTGIpBVusBo CMhyFo7F+ngbhriaU0gc/TWtBlhvmTS8gK9cJ/CECXRxs2DLNlRJGceK/PNvj9KXXBSz tEw29sw+TfeeThgdut+185iNMwdwzNofkaimoXfVNyCmE0wzNW73OvUYrTd7nQD65XDx VeUMGyvqh+JVXP6N77k13Hg3q2+Tk6iCurNCNLcUPSktf97MXvdFtu1LkJlXn5CGsdx5 u+AQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=oTxzBfIcMh+imB8wTw7q1ORn9eT+rw1t9HAUvlA2i0Q=; b=R3uYohuQD5P8IbHTzvNR9E3d0/O/7XAgItwTuRWtQILQKlGLMHIMDQRfW9ri0KeyeE ydHeBxDqtBYXCKPK6eI2OMheFgQqe5tjB5HD1LAFYgHFtg3QVQp3BqvO/4xmWClMY3Oy TDk8RiCgWmEcF7yE9ZpuD10wsbcMloV5URKiblDfbfsJO6ILRda03VrM0O62wb3rS75H 8D2TMNdT2VprqJTWkSqsMXNgCxTSTo6MGq4xQ0TnJaYWOQA8LkzqM8RGRb2DlQy6UB/W qbH02b6fvxf8OEgtJlHjYf0Qg4oiqbgd4Jt0d5af9Nl+zrTrw/I6JjBo7Mye1+mXDF2w Bv6g== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=ZJVk3ceE; 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 q5si9078614pgk.46.2018.11.11.15.49.27; Sun, 11 Nov 2018 15:49:42 -0800 (PST) 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; dkim=pass header.i=@kernel.org header.s=default header.b=ZJVk3ceE; 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 S1733279AbeKLJj0 (ORCPT + 99 others); Mon, 12 Nov 2018 04:39:26 -0500 Received: from mail.kernel.org ([198.145.29.99]:38784 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1733041AbeKLISl (ORCPT ); Mon, 12 Nov 2018 03:18:41 -0500 Received: from localhost (unknown [206.108.79.134]) (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 B1E3022504; Sun, 11 Nov 2018 22:28:44 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1541975324; bh=AgZjdC4bikvZCPm2iSj9epp2orUz3RnM7DYXWl9pGvI=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=ZJVk3ceEImvQcEcd3ugX4NTtmQSPeDRxBLc7uai/2POyx7gT0oDW6Uo20oXdwyJ6c JQTDJe1t3OMZmJoafAVl+h2YNmf+CwoptkEeLHcFMZEmIgyXchfmpnsIhJOqrJZ+WP sweNnp2EiwjOA/VMGBI3lSVC7wvxZBy6pMWwHybY= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Jeff Mahoney , David Sterba Subject: [PATCH 4.19 330/361] btrfs: fix error handling in btrfs_dev_replace_start Date: Sun, 11 Nov 2018 14:21:17 -0800 Message-Id: <20181111221659.823633335@linuxfoundation.org> X-Mailer: git-send-email 2.19.1 In-Reply-To: <20181111221619.915519183@linuxfoundation.org> References: <20181111221619.915519183@linuxfoundation.org> User-Agent: quilt/0.65 X-stable: review MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 4.19-stable review patch. If anyone has any objections, please let me know. ------------------ From: Jeff Mahoney commit 5c06147128fbbdf7a84232c5f0d808f53153defe upstream. When we fail to start a transaction in btrfs_dev_replace_start, we leave dev_replace->replace_start set to STARTED but clear ->srcdev and ->tgtdev. Later, that can result in an Oops in btrfs_dev_replace_progress when having state set to STARTED or SUSPENDED implies that ->srcdev is valid. Also fix error handling when the state is already STARTED or SUSPENDED while starting. That, too, will clear ->srcdev and ->tgtdev even though it doesn't own them. This should be an impossible case to hit since we should be protected by the BTRFS_FS_EXCL_OP bit being set. Let's add an ASSERT there while we're at it. Fixes: e93c89c1aaaaa (Btrfs: add new sources for device replace code) CC: stable@vger.kernel.org # 4.4+ Signed-off-by: Jeff Mahoney Reviewed-by: David Sterba Signed-off-by: David Sterba Signed-off-by: Greg Kroah-Hartman --- fs/btrfs/dev-replace.c | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) --- a/fs/btrfs/dev-replace.c +++ b/fs/btrfs/dev-replace.c @@ -440,6 +440,7 @@ int btrfs_dev_replace_start(struct btrfs break; case BTRFS_IOCTL_DEV_REPLACE_STATE_STARTED: case BTRFS_IOCTL_DEV_REPLACE_STATE_SUSPENDED: + ASSERT(0); ret = BTRFS_IOCTL_DEV_REPLACE_RESULT_ALREADY_STARTED; goto leave; } @@ -482,6 +483,10 @@ int btrfs_dev_replace_start(struct btrfs if (IS_ERR(trans)) { ret = PTR_ERR(trans); btrfs_dev_replace_write_lock(dev_replace); + dev_replace->replace_state = + BTRFS_IOCTL_DEV_REPLACE_STATE_NEVER_STARTED; + dev_replace->srcdev = NULL; + dev_replace->tgtdev = NULL; goto leave; } @@ -503,8 +508,6 @@ int btrfs_dev_replace_start(struct btrfs return ret; leave: - dev_replace->srcdev = NULL; - dev_replace->tgtdev = NULL; btrfs_dev_replace_write_unlock(dev_replace); btrfs_destroy_dev_replace_tgtdev(tgt_device); return ret;