Received: by 10.223.185.116 with SMTP id b49csp766149wrg; Wed, 21 Feb 2018 06:37:01 -0800 (PST) X-Google-Smtp-Source: AH8x226KFEwAglQOyuJyOzZ4ELOtOeFXYAEkNbArsdPkeI2Q1zGZfWFHCez+AEz2HUOA+dUiI1bP X-Received: by 2002:a17:902:76c4:: with SMTP id j4-v6mr3440295plt.410.1519223821124; Wed, 21 Feb 2018 06:37:01 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1519223821; cv=none; d=google.com; s=arc-20160816; b=Ol5JKHD7JOWK/ULgmEG5yqslytLR3B5U1gssGVfwIbeqQx4OFak216o1ZlF41jcMJX bpSVuhTJQrc44jHUiOQvgSTXaySJVFKXzuWtrSFcbO1UYAF652eGdztaEu1vrDLqtFvl cKWEDtR1DsHURt8mWnIMpkepOh+wMQOaPao6M1X73qO31bFAnarMD0FS/r22Xqpe94z/ zJ3X3d6iseLdE8f5C9YRK0jC3CQU5eKaIKZ1tLgQeGT7FTY6M8GNAr8AFfHti9MOPVYb XrXIFN1WnLtPXCYohJ4GM3d6pLfGN7X/k2o9LpUx8I8S0AXb+KCJWwKhu8sjQkYiNPSn qudA== 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=LluB5H22ZRuAVRx41cnTKlXDww0NzfxAMOoVcDHYqfs=; b=zCYYuQr/TNlA0LP5ypaklwD0oMQDOMKWeUEZY0q+naRKHMdvabRmRmxMvM5I7wHUml 8QFYKy4brLtRZuaXAENbdmewVTvMHIg92WeYigwJZ8KAt/ZKeRlKCxEBNWICWKk52mF3 pf9X+tvykmbSKTvcZzqtKfkH1KYT+ToZByofj9xvQDnveztoLGMq4Qwg8hnQR7E9/YNx 4j4LRtD4vcMWg1ETroZZ9lQFoIf+2hTc+xKb2BsHc7mNOfpc1U2d7aWW9G5i0uzuU4ej BBMLgknHWBPwG9BadvgEfwDLDyUwwbDxhCpF7aXsr+r50VPmHp5xiLU49+0xFgeIzSuO 2N1A== 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 p25si10559442pfk.309.2018.02.21.06.36.45; Wed, 21 Feb 2018 06:37:01 -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; 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 S937768AbeBUOfm (ORCPT + 99 others); Wed, 21 Feb 2018 09:35:42 -0500 Received: from mail.linuxfoundation.org ([140.211.169.12]:34428 "EHLO mail.linuxfoundation.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S934271AbeBUMz1 (ORCPT ); Wed, 21 Feb 2018 07:55:27 -0500 Received: from localhost (LFbn-1-12258-90.w90-92.abo.wanadoo.fr [90.92.71.90]) by mail.linuxfoundation.org (Postfix) with ESMTPSA id 79DB51110; Wed, 21 Feb 2018 12:55:26 +0000 (UTC) From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, NeilBrown , Mike Snitzer Subject: [PATCH 4.9 33/77] dm: correctly handle chained bios in dec_pending() Date: Wed, 21 Feb 2018 13:48:42 +0100 Message-Id: <20180221124433.581232888@linuxfoundation.org> X-Mailer: git-send-email 2.16.2 In-Reply-To: <20180221124432.172390020@linuxfoundation.org> References: <20180221124432.172390020@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: NeilBrown commit 8dd601fa8317243be887458c49f6c29c2f3d719f upstream. dec_pending() is given an error status (possibly 0) to be recorded against a bio. It can be called several times on the one 'struct dm_io', and it is careful to only assign a non-zero error to io->status. However when it then assigned io->status to bio->bi_status, it is not careful and could overwrite a genuine error status with 0. This can happen when chained bios are in use. If a bio is chained beneath the bio that this dm_io is handling, the child bio might complete and set bio->bi_status before the dm_io completes. This has been possible since chained bios were introduced in 3.14, and has become a lot easier to trigger with commit 18a25da84354 ("dm: ensure bio submission follows a depth-first tree walk") as that commit caused dm to start using chained bios itself. A particular failure mode is that if a bio spans an 'error' target and a working target, the 'error' fragment will complete instantly and set the ->bi_status, and the other fragment will normally complete a little later, and will clear ->bi_status. The fix is simply to only assign io_error to bio->bi_status when io_error is not zero. Reported-and-tested-by: Milan Broz Cc: stable@vger.kernel.org (v3.14+) Signed-off-by: NeilBrown Signed-off-by: Mike Snitzer Signed-off-by: Greg Kroah-Hartman --- drivers/md/dm.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) --- a/drivers/md/dm.c +++ b/drivers/md/dm.c @@ -809,7 +809,8 @@ static void dec_pending(struct dm_io *io } else { /* done with normal IO or empty flush */ trace_block_bio_complete(md->queue, bio, io_error); - bio->bi_error = io_error; + if (io_error) + bio->bi_error = io_error; bio_endio(bio); } }