Received: by 2002:ac0:b08d:0:0:0:0:0 with SMTP id l13csp1888103imc; Fri, 22 Feb 2019 13:10:53 -0800 (PST) X-Google-Smtp-Source: AHgI3Ia1jmKOngKVQRfl/Q1hhs3qz918+ANpZgD+sEkzG9++CCEKxfmb/mxWhWLOCHoiWfwVzjBr X-Received: by 2002:a63:a11:: with SMTP id 17mr1924921pgk.310.1550869853401; Fri, 22 Feb 2019 13:10:53 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1550869853; cv=none; d=google.com; s=arc-20160816; b=PC7YqFD1hBv9T53gomcOFE1EubLX//Ph01j7umw8x7kiV+P0QMbYd7C3mzxVuAvbkV O71ekVgmUcbZStMKv09vm49302ZEd+PnZ0Y0753ziu8Qa3X5xyUfFKnyT2PSg3Hio0gY kuDxUz9CJ54aILxHndqABzoeisbtEZo+oQjDMlLYeJ7QHrjo4IElDrnlW4ehvuN8cfIN hJIb6N2BJ1gz//9zdiq+liPVfGVownGM7YC8LP6q3k+xTFPrdh/kvMr39/pJd2myYxKg zy6zkAKW9uZwEZrKy1+GLbFph8oeyxULC9FlV+uuQDY0EGtGiBct4HgHs00CR906DV4t UNzQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:user-agent:in-reply-to :content-disposition:mime-version:references:message-id:subject:cc :to:from:date; bh=3pyVmpQqIUYWF6PX35ktvjrVdVwqlO+hP5J/wrypL9o=; b=SJC/EdtnSIz8aaKDnVgNMO1ynXbpHr9q+BztcehqyxKLeMb9Yq1sTjvIH4oaXE9ptA R+pbYzX66Iw6E+KqZfk3YF/LdPCBGrFI8LW5hQzF3HODY7TgeVZ2Xvg44Q9Vk7PbL9MO oqZKf3biSZ0dZPP9JlgdRnZKjT/UC0LHxaYF/xSKaWq12FHNzVXWHPtWKcYgXt7kXD+3 43sJmCDwKKclkqsCW+rfmHGxb3PDdC2F+MsqsQ0KDJtQvB6AU8qJTBdWCWSxYwNUP9Zr q+sR3zlb5yJBK1z57q/d1JIvDLL5sN7JJ3OOBOMiOxfdhFCtBrq4GXCuFoFOqoXSC2RG +FAg== 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; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=redhat.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id t71si2185537pfa.244.2019.02.22.13.10.37; Fri, 22 Feb 2019 13:10:53 -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; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=redhat.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726620AbfBVVKL (ORCPT + 99 others); Fri, 22 Feb 2019 16:10:11 -0500 Received: from mx1.redhat.com ([209.132.183.28]:37454 "EHLO mx1.redhat.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725821AbfBVVKL (ORCPT ); Fri, 22 Feb 2019 16:10:11 -0500 Received: from smtp.corp.redhat.com (int-mx07.intmail.prod.int.phx2.redhat.com [10.5.11.22]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 10207C01BC86; Fri, 22 Feb 2019 21:10:11 +0000 (UTC) Received: from localhost (unknown [10.18.25.174]) by smtp.corp.redhat.com (Postfix) with ESMTPS id BBEF51001E9E; Fri, 22 Feb 2019 21:10:07 +0000 (UTC) Date: Fri, 22 Feb 2019 16:10:06 -0500 From: Mike Snitzer To: NeilBrown Cc: Jens Axboe , linux-block@vger.kernel.org, device-mapper development , Milan Broz , Linux Kernel Mailing List Subject: Re: block: be more careful about status in __bio_chain_endio Message-ID: <20190222211006.GA10987@redhat.com> References: <70cda2a3-f246-d45b-f600-1f9d15ba22ff@gmail.com> <87eflmpqkb.fsf@notabene.neil.brown.name> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <87eflmpqkb.fsf@notabene.neil.brown.name> User-Agent: Mutt/1.5.21 (2010-09-15) X-Scanned-By: MIMEDefang 2.84 on 10.5.11.22 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.31]); Fri, 22 Feb 2019 21:10:11 +0000 (UTC) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Thu, Feb 15 2018 at 4:09am -0500, NeilBrown wrote: > > 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 > --- > 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 > --- a/block/bio.c > +++ b/block/bio.c > @@ -312,7 +312,7 @@ static struct bio *__bio_chain_endio(struct bio *bio) > { > struct bio *parent = bio->bi_private; > > - if (!parent->bi_status) > + if (bio->bi_status) > parent->bi_status = bio->bi_status; > bio_put(bio); > return parent; > -- > 2.14.0.rc0.dirty > Reviewed-by: Mike Snitzer Jens, this one slipped through the crack just over a year ago. It is available in patchwork here: https://patchwork.kernel.org/patch/10220727/