Return-Path: Received: from mx2.suse.de ([195.135.220.15]:46067 "EHLO mx2.suse.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751217AbeBTUKg (ORCPT ); Tue, 20 Feb 2018 15:10:36 -0500 From: NeilBrown To: gregkh@linuxfoundation.org, gmazyland@gmail.com, snitzer@redhat.com Date: Wed, 21 Feb 2018 07:10:28 +1100 Cc: stable@vger.kernel.org Subject: [PATCH - 4.9-stable] dm: correctly handle chained bios in dec_pending() In-Reply-To: <151914088385191@kroah.com> References: <151914088385191@kroah.com> Message-ID: <87fu5vjubv.fsf@notabene.neil.brown.name> MIME-Version: 1.0 Content-Type: multipart/signed; boundary="=-=-="; micalg=pgp-sha256; protocol="application/pgp-signature" Sender: stable-owner@vger.kernel.org List-ID: --=-=-= Content-Type: text/plain Content-Transfer-Encoding: quoted-printable 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 =2D>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 =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 c5522551122f..2ffe7db75acb 100644 =2D-- a/drivers/md/dm.c +++ b/drivers/md/dm.c @@ -809,7 +809,8 @@ static void dec_pending(struct dm_io *io, int error) } else { /* done with normal IO or empty flush */ trace_block_bio_complete(md->queue, bio, io_error); =2D bio->bi_error =3D io_error; + if (io_error) + bio->bi_error =3D io_error; bio_endio(bio); } } =2D-=20 2.14.0.rc0.dirty --=-=-= Content-Type: application/pgp-signature; name="signature.asc" -----BEGIN PGP SIGNATURE----- iQIzBAEBCAAdFiEEG8Yp69OQ2HB7X0l6Oeye3VZigbkFAlqMgLUACgkQOeye3VZi gblczA//cuGapWHmPY51v57yLrPJbirOJIELzCXONokMKMJkim1z6JV3MUvTvyuc yUBgQbcNOA/M5k9r+F3txknsS6qlMzySKKHTbJ0qCpmWjgkaw24K9zg15z+J6FY8 dzHBt3PPl9x4GJjeNobqj1dnVwDXZiIcrQrwQxklDhDFsvxTcL5TQ4pXVhpd3Qsg 8A3O0cD5LXblLZ7O6eDB/ZX31Fshm4mx3oN4HXbQ1j57rj5EUaqduGqwE1oEjxkY +wxO1NAcjbpKRCb8gdu7DEYljwuKpUAK5zXzSTW5kRAcN6dEMi3C006+6ElqVEUi oH0I0SuCCfQfeBawQ2XW7z2qVhtYeDDDK/zMv/EmtzCTDJswyAECGyLI244tcYgN kKr6RupDlgRJ9kP1j/4qnoqqJtqzDLUeRxA3tjd1n4oXjr5V4NL3GRh9ENfPz7Le flSfSdfCsksV5mgxqEy6vqyo3KughcuqpcKCc7gFOpsgjBUE00fTaS7J15jh1tTe FtkP+aVZxmPSw3bdyoADTWhCUeniJvMpKzg3/0YGZ0eBNbF2F3CWnuy8wKTHH5SV bTEBydgvMEf+sUWf7mLnLe6PpUmn6iqNn2bfBtpbcZKPP3Ehj/yTwwpz9Gqq+cjo EfiJiQdF/kn++RBNcdFsm3dxqxEHzXfv0f9RvpR7JFg5j8UAyDg= =FsxG -----END PGP SIGNATURE----- --=-=-=--