Received: by 10.223.185.116 with SMTP id b49csp1779038wrg; Thu, 15 Feb 2018 01:10:31 -0800 (PST) X-Google-Smtp-Source: AH8x224E9COnDSoRdMHspOtmXGjOEa1Q7ilW34yVfhs/4iMCwRIqFbA2x8qG1aTrxJAwl7ugebv5 X-Received: by 10.98.69.93 with SMTP id s90mr2020328pfa.31.1518685831300; Thu, 15 Feb 2018 01:10:31 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1518685831; cv=none; d=google.com; s=arc-20160816; b=sWtS+GKZPGjD/yIU4Jq6CGstZAjsPltyDLKdjHrVtTapsoLCkGMHwwfS9uX1vOOrJf flBSd5Tx64i/lSeuUlMt5+LNovEyR3CSXeKbum0BBT1h7CNu7VZ4GavN+BcqnMClas+B o1wWF/EP14vMf0s9mYERaKqn1Pltvu/CvNSGD7mIQM+4RBAGiGkgjeQXOv5q+QEKCraR su3JxBs6uvCXSgGtJxlPx0GMCvUgqSE6/V9rjMNVgReGqt8QxnhLwwPkadE7PkKAOvMK ip0PegiFiBSTeRjXfn6it8Vk8UH83GZB4y4Pi3Y19O4Bu2E4V12PXGPHpc3fNbr/Zseb v5Yw== 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:cc:references :in-reply-to:subject:cc:cc:date:to:from:arc-authentication-results; bh=fFiSJ6lTPaPKLrLVueDE6smRvn/o7zx7iFz9EFyhTBo=; b=hQmwr+gCKfzygXTwCFx8GgZweddO6dpNZ/br+Eslcftb0BfLUykoyfDm+u3RHwXXb1 4xjRRyL53uXtWwpWV26NT67KvdryT8BEQFWMyHB6/GRcljGuoXdziZIxilCmHAvknBqr OdP3ivlI0GqtUUdZJ7BzqEPeMZ2Gu4sNP2cWWiIZq/DLGhRqycs3QD2EV6PtVsfPfxUV AY7OsZOWRAi0sS8t5Nj0Pkw+TKb4sbXTuUrEmZmQ50MTaegIm1COyLtATS2FzjHQcfny ADd5G3OTVIIJnxDuspsStBdqe8X59j2tLUOBWaH+ZscpClMohCWXcZZqKVY3jasXWXqI l9MQ== 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 p125si3459809pfb.241.2018.02.15.01.10.16; Thu, 15 Feb 2018 01:10:31 -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 S1755191AbeBOJJg (ORCPT + 99 others); Thu, 15 Feb 2018 04:09:36 -0500 Received: from mx2.suse.de ([195.135.220.15]:34269 "EHLO mx2.suse.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1755069AbeBOJJd (ORCPT ); Thu, 15 Feb 2018 04:09:33 -0500 X-Virus-Scanned: by amavisd-new at test-mx.suse.de X-Amavis-Alert: BAD HEADER SECTION, Header field occurs more than once: "Cc" occurs 3 times Received: from relay2.suse.de (charybdis-ext.suse.de [195.135.220.254]) by mx2.suse.de (Postfix) with ESMTP id DD519AC9C; Thu, 15 Feb 2018 09:09:31 +0000 (UTC) From: NeilBrown To: Jens Axboe Date: Thu, 15 Feb 2018 20:09:24 +1100 Cc: Milan Broz , Mike Snitzer , device-mapper development Cc: Linux Kernel Mailing List Subject: [PATCH] block: be more careful about status in __bio_chain_endio In-Reply-To: <70cda2a3-f246-d45b-f600-1f9d15ba22ff@gmail.com> References: <70cda2a3-f246-d45b-f600-1f9d15ba22ff@gmail.com> cc: linux-block@vger.kernel.org Message-ID: <87eflmpqkb.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 If two bios are chained under the one parent (with bio_chain()) it is possible that one will succeed and the other will fail. __bio_chain_endio must ensure that the failure error status is reported for the whole, rather than the success. It currently tries to be careful, but this test is racy. If both children finish at the same time, they might both see that parent->bi_status as zero, and so will assign their own status. If the assignment to parent->bi_status by the successful bio happens last, the error status will be lost which can lead to silent data corruption. Instead, __bio_chain_endio should only assign a non-zero status to parent->bi_status. There is then no need to test the current value of parent->bi_status - a test that would be racy anyway. Note that this bug hasn't been seen in practice. It was only discovered by examination after a similar bug was found in dm.c Signed-off-by: NeilBrown =2D-- block/bio.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/block/bio.c b/block/bio.c index e1708db48258..ad77140edc6f 100644 =2D-- a/block/bio.c +++ b/block/bio.c @@ -312,7 +312,7 @@ static struct bio *__bio_chain_endio(struct bio *bio) { struct bio *parent =3D bio->bi_private; =20 =2D if (!parent->bi_status) + if (bio->bi_status) parent->bi_status =3D bio->bi_status; bio_put(bio); return parent; =2D-=20 2.14.0.rc0.dirty --=-=-= Content-Type: application/pgp-signature; name="signature.asc" -----BEGIN PGP SIGNATURE----- iQIzBAEBCAAdFiEEG8Yp69OQ2HB7X0l6Oeye3VZigbkFAlqFTkQACgkQOeye3VZi gbl38hAAuH2ehzZRqSUECPVbVybMgFyXH9hu3wZUFXmHTAgE0+qtBFdNzQezHDc5 QcjGXptF707jUFETG6v4mtGLRlRGTl6zZ++PSb8otV1ZNqAsLtO2XPpdezk7cwuz 4NpRrHSgUX2oxbsgmEWenx09SlDl2HrD7KFl9eXBY1zDNGvol8c9jV07FAeqr2dG u6FaYoquornB9NS2nC1GXOvOpbs2NWkvj04H3NWvh0rvk4vxTzcb2avB9Jw60MQ/ F2Y1V65ZrrnrGlqrfqxGWWJVu94N+mw9MPlGl+B+/6ObkPsFxKhTAUyoNQ+3yWnC fV3jDeVf2f4ZLKGbGb82NA1ZF7hJVqyf4ZRJNCf8A0Wlf3Lx0izpQE97wn2Qr4y8 b/Ha3ZPcb7k7aMW2xlU+966j4duczGSGncszRCUodhdOETHsK24GTRJHb8rEBDKp 9r4DSoEt/zj8wkWNluXAwow8OnIBI5WOkH5FoiZgdmGcTbaOl9dd5ZwVoEv425po vzqCqDJYAwIZ7PaLfgpfvrIhPXA/Hl6FwJv2PhJpilOViqhmaWxxXjl8BFL+Q5QL ISqW/3fmAi06YcKK82QQwBtlAGjvpbierPHAahu5s5Tor75LYRm36hmZ2DnQE61L /CgV5f0B1wB9TbOoJortlx7dKXol3zublH8p84+WlLZ15gBtnnw= =k8H1 -----END PGP SIGNATURE----- --=-=-=--