Received: by 10.223.185.116 with SMTP id b49csp1082448wrg; Wed, 21 Feb 2018 11:48:13 -0800 (PST) X-Google-Smtp-Source: AH8x2261dPmGwmxNyJ7i/kNpOf1WLNlYI3HGizjZEpAd6eeU94mQvBdFpg2eISJvRGoaiRpf18ro X-Received: by 2002:a17:902:1a2:: with SMTP id b31-v6mr3963464plb.28.1519242493248; Wed, 21 Feb 2018 11:48:13 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1519242493; cv=none; d=google.com; s=arc-20160816; b=N1g/VhCyH8XluOGMoAnVcFpPDX7LJ6AOGFhYv3r1p859JFdhzLPIgxcw7TqelFYEDD 7SuoBFxziirbrpfkOxDgTxPPUocL92v2CEHKUR0pR2tQr+3MGkDoAWlA4h0itHS/Jijp W8YHHge4EcmRHazZWGsuZ5x+rHjliIVmxYzlplEIH/9x5jfMpyL+boTy3iYtaVsTwr9i xCqBxu/4/ZGVVMme/dD5bK1mCtKZXR/e92aimUqT6bXXN9uxszOqt3yOj/gvhmY80D3I AT8IO7mzEpasWZ8PMmxnQ+1Zmq3xjnBdDth8rDX0SSS2eKfAaKJ2f/h5FB5FQBVAjy4K euAA== 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=hadewxZHm/0fGiSNmT3kTEWm9B9N2OMB8dxu7i8Srf8=; b=Z6/4xXnXJ4fmALfr6iKr4pePMuLA+lgHA+lSBy4B3hVBz+IttuDsOoI3On/W+gMSuQ ZwlPe1JQgL58ZMACpkpsb5ujah2oj4YPsGiIyCPSEHQI2zJug8afeBUgly2eT5WV4Onq TjTv31a2ME2puPPoxx7f5/KHIHHAs9bQq1Uf32v5zGyoQcnClmdp6adyHST5YtHJqBmU lhYETp9OQbchXk65+HDymCq+NGoboV5ngYrhiFmQ3B8t2s1/zMNt5rWyMczQL3Rxddr2 3HKrTT32j80ZvIkbAWkYv0vSAOipn52XQqnXtnSvh1WWXJ1JB76QZYBhCn8pbPgb1gHg +HWA== 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 x4si57466pfb.281.2018.02.21.11.47.59; Wed, 21 Feb 2018 11:48:13 -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 S965728AbeBUNNW (ORCPT + 99 others); Wed, 21 Feb 2018 08:13:22 -0500 Received: from mail.linuxfoundation.org ([140.211.169.12]:46002 "EHLO mail.linuxfoundation.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1753216AbeBUNNQ (ORCPT ); Wed, 21 Feb 2018 08:13:16 -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 C58A510BD; Wed, 21 Feb 2018 13:13:15 +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.15 134/163] dm: correctly handle chained bios in dec_pending() Date: Wed, 21 Feb 2018 13:49:23 +0100 Message-Id: <20180221124537.599868211@linuxfoundation.org> X-Mailer: git-send-email 2.16.2 In-Reply-To: <20180221124529.931834518@linuxfoundation.org> References: <20180221124529.931834518@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.15-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 @@ -817,7 +817,8 @@ static void dec_pending(struct dm_io *io queue_io(md, bio); } else { /* done with normal IO or empty flush */ - bio->bi_status = io_error; + if (io_error) + bio->bi_status = io_error; bio_endio(bio); } }