Received: by 10.223.185.116 with SMTP id b49csp1770051wrg; Thu, 15 Feb 2018 01:01:14 -0800 (PST) X-Google-Smtp-Source: AH8x227q6/+CeQmSDTjb7Q/6IgGScJZD1+AIBiUC109+uI/G7QIkBrwZ2PgDg9hsyGU7OWj3JaLV X-Received: by 10.98.8.86 with SMTP id c83mr1980804pfd.84.1518685274585; Thu, 15 Feb 2018 01:01:14 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1518685274; cv=none; d=google.com; s=arc-20160816; b=zZE1SwmGpC4T3dRuKfKA7GcWXyERVagBjj3Sgfez+7eCcXre4aGPuzyjyhTyhHsk/D WbmPm+19DlmYCiTCyp976VHnlccG7sGMbkYnv94MYidLYA+Sq6E9KdnDZ5TF+Xg9j4BT Io3lQhXQ/OI6CNQrcieASD0sDkC8U6G0yALVmU0UIoQHc5cV6SYUgEtZxEuGf0zFbME1 uR69PmqSdmCO5uWazUOl9aIakTVPu9TTPz7aKH+JMRFbH89eAYccwOUGkmbsVJiQoBww ONQEE+BXWKZVXC/xSybx2e41m0pNgUDj8hw+Kqmb8h3+a6DFUIBNzEZ3cbRbGGEdXUv7 MPdg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:mime-version:message-id:references :in-reply-to:subject:cc:date:to:from:arc-authentication-results; bh=zOvnBWSsUCVqjkxueidmnFMYXHacZFl0LdRe14yKDL8=; b=u75YBqx8ejO8U9VsSFdFLDgZSUFEnAk8PjHeA8DI3bb0q5GRGyiq59srW815Lv6g/x bpBkDV5ZgJTroknX2436qWau/U1NzO0GCQcOjOj4KDH5xEuTIqBCHbadmmKd4ybYB+dE wy7hqdFvQ1Sdv5LcLYsVCQlWUmJNzD/GJIi9/jYCfWoNfh7J2WCEEnSGaifgn5blm2Jz NF5Y24KHQ77Q2/tlWxptKsSgQkf3WaMYJUVLAR5tmBLcWhaKGoercF+EGJeFtn3ja5NL a3xHTKeb/KvD2KN460B3VFb5P6kslwgLnp/H8oWQuhhmGUQefH9lsN68wsW2vinXxyrr zETQ== 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 m24si4588877pfj.265.2018.02.15.01.00.59; Thu, 15 Feb 2018 01:01:14 -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 S1755113AbeBOJAX (ORCPT + 99 others); Thu, 15 Feb 2018 04:00:23 -0500 Received: from mx2.suse.de ([195.135.220.15]:33733 "EHLO mx2.suse.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1754825AbeBOJAW (ORCPT ); Thu, 15 Feb 2018 04:00:22 -0500 X-Virus-Scanned: by amavisd-new at test-mx.suse.de Received: from relay1.suse.de (charybdis-ext.suse.de [195.135.220.254]) by mx2.suse.de (Postfix) with ESMTP id 75A2FAC9C; Thu, 15 Feb 2018 09:00:21 +0000 (UTC) From: NeilBrown To: Milan Broz , Mike Snitzer , device-mapper development Date: Thu, 15 Feb 2018 20:00:15 +1100 Cc: Linux Kernel Mailing List Subject: [PATCH] dm: correctly handle chained bios in dec_pending() In-Reply-To: <70cda2a3-f246-d45b-f600-1f9d15ba22ff@gmail.com> References: <70cda2a3-f246-d45b-f600-1f9d15ba22ff@gmail.com> Message-ID: <87k1vepqzk.fsf@notabene.neil.brown.name> MIME-Version: 1.0 Content-Type: multipart/signed; boundary="=-=-="; micalg=pgp-sha256; protocol="application/pgp-signature" Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org --=-=-= Content-Type: text/plain Content-Transfer-Encoding: quoted-printable 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 zero. 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 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 =2D-- drivers/md/dm.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/drivers/md/dm.c b/drivers/md/dm.c index d6de00f367ef..68136806d365 100644 =2D-- a/drivers/md/dm.c +++ b/drivers/md/dm.c @@ -903,7 +903,8 @@ static void dec_pending(struct dm_io *io, blk_status_t = error) queue_io(md, bio); } else { /* done with normal IO or empty flush */ =2D bio->bi_status =3D io_error; + if (io_error) + bio->bi_status =3D io_error; bio_endio(bio); } } =2D-=20 2.14.0.rc0.dirty --=-=-= Content-Type: application/pgp-signature; name="signature.asc" -----BEGIN PGP SIGNATURE----- iQIzBAEBCAAdFiEEG8Yp69OQ2HB7X0l6Oeye3VZigbkFAlqFTB8ACgkQOeye3VZi gbnIWQ//boIh7VP4NRCJxy1CgFlcx8UHEALUBBvPBKUJ5GZdSy/SM2OiYHvnSUNI GZZx7P9Dp2F4KElFI4sIeXpfPketwHsX2DT/1kGH2H9lMV+v/8qqO2CcxSPTxshq 91W56zgEdbjcZX+Tcj2ZH4xeNtqkRHB/9RpZdF/TqYbU72Vog3o/UzXX8EIEFZ0s SWUVA9AI7mCQm4uYbzieY/uMaugZKxDQxgDosy9QNFhgMS6gVUB0L71naY4vANlR loc8J6ORoQPJ5sM7kYBX1Tyxgao1RYDFvF0SASlveamhb0ktxELC4O0alLLDgfv4 HXM6tuZLva0FmAhCDs+nWzp9KAB/dMgIUigvf9oXxfTl5cve/V8sLMMPmTq7vH5w b28H4cM/YYfTC4RRZagiVqn2EScoWqxKBBh8KXsjvE3nARLer0HPWGm5DMecTh3D E4/2GNjlp5zkFjPPaTbO8WU+yC/wABOaBrHid5piyQhaPpt9AL7xDtIW16LhfJaB snJcn4oRjcRROPk2Qb1FpiPkWrq0BYzBo5tOLgGbbQy6mnEDFtw1LB0+ZeS9T1hZ AX8bW2TW3ZL3m74yJRwlvisLTAvBTWmZTGwlzpkUw78dzoWOE/A3MkRjptByrToR ZFAfHXvAq4XWAvqmHEkBCFCx8gqhWm7s2KHpDx7+dzpN6vrK934= =WsZm -----END PGP SIGNATURE----- --=-=-=--