Received: by 2002:a05:6a10:f347:0:0:0:0 with SMTP id d7csp138815pxu; Wed, 25 Nov 2020 15:32:19 -0800 (PST) X-Google-Smtp-Source: ABdhPJxWCiB0wM9tew2G5sl1NEW9LhkxpCWlVT9WcaQYSIlTRbEwNhULa1GS4Tadh+aoppulFGAm X-Received: by 2002:a50:fc85:: with SMTP id f5mr35747edq.225.1606347138963; Wed, 25 Nov 2020 15:32:18 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1606347138; cv=none; d=google.com; s=arc-20160816; b=YEpR8jdC1P7EKA76QGu71tBt/H2TIBJ70i2CwQ+aiWhjpFfw0GCAM6DzkfKiydemXo aWedySzXeFwKseu9XdpP1frFp/94QmHeASxb99Q29snBtecljzfrTLWa5+MOI1v3546q YIk1hl6mYP5uqa9UfYojKOO2IWW7D0bIPi1fIVi7IR2W4bw1J02n5FPr5f+OLXE7voY1 LcH4i3h/v4Xf7zsmh1va3ob7y53YUkTOMn+k92aYX5cyZu54yuMZQOgyLYjUSJXYklpx VDFEKffjk2g2zCAHI/ymwQVn22B0BHvb5dauNtfh6k9awaS2UO33zDxtXvZA1/DIj/00 nMqw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:in-reply-to:content-disposition:mime-version :references:message-id:subject:cc:to:from:date:dkim-signature; bh=9lUMIC11/zz2uEr/DoH6JbU2GShptGuMHjJqsG/QpYw=; b=tdLYB8PlOJTXwp6nyYWR/yWa6XlGRQiqYIEz04O3WXGrllypVKe6P7XHsg8rijE5Hl pgLZbPPw9yshBbPQWP61Xx+onmQZkXl+/I/Khzr4PiEWC3LK5FQPgn7F5AflugQ89OhG bAvn8gRwSJkRtf2evvjgUQdxOid1AUTTpFXhhKZ0jUSddUG5MqNA2lsEu+brqrhC8thj b7yQuK731Z2RuVRQGgpBLxEgE0IyWRmxoNYzYJWe00jnpo0Gwy2SP0AnKsZSc0owG3Zl 5PFarDPrcd8Uuked519b5NJx3leXQf1ZOA5JoYgsjvaqsE4VGZsa/H1oUjyc64n3dP5g 8hwg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=VY5RPIIy; spf=pass (google.com: domain of linux-ext4-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-ext4-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id d20si2082532eds.29.2020.11.25.15.31.55; Wed, 25 Nov 2020 15:32:18 -0800 (PST) Received-SPF: pass (google.com: domain of linux-ext4-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=VY5RPIIy; spf=pass (google.com: domain of linux-ext4-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-ext4-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1732743AbgKYWPI (ORCPT + 99 others); Wed, 25 Nov 2020 17:15:08 -0500 Received: from mail.kernel.org ([198.145.29.99]:49484 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1730465AbgKYWPG (ORCPT ); Wed, 25 Nov 2020 17:15:06 -0500 Received: from sol.localdomain (172-10-235-113.lightspeed.sntcca.sbcglobal.net [172.10.235.113]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id 676AD206D9; Wed, 25 Nov 2020 22:15:05 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1606342505; bh=//mTbDz2JjRGYIh1GwXxXW8kmqk4YvkDaY1/++XJIn0=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=VY5RPIIyvrFY4c/vetEDGaxUA9jOSaakmSVQw0Q1OasRAiZUBJ/F7aSPHVJNJV4i6 t408rVBospirzyiG4A0Bz0x10gjsY8A9wASMrrtC8rHc++m/VZ5sLatmlHd/f6CjyS /z2CHKSoNg4dCcDvPeFPMis8mAMTCtEVPIDia/1Q= Date: Wed, 25 Nov 2020 14:15:03 -0800 From: Eric Biggers To: Satya Tangirala Cc: "Theodore Y . Ts'o" , Jaegeuk Kim , Chao Yu , Jens Axboe , "Darrick J . Wong" , linux-kernel@vger.kernel.org, linux-fscrypt@vger.kernel.org, linux-f2fs-devel@lists.sourceforge.net, linux-xfs@vger.kernel.org, linux-block@vger.kernel.org, linux-ext4@vger.kernel.org Subject: Re: [PATCH v7 1/8] block: ensure bios are not split in middle of crypto data unit Message-ID: References: <20201117140708.1068688-1-satyat@google.com> <20201117140708.1068688-2-satyat@google.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20201117140708.1068688-2-satyat@google.com> Precedence: bulk List-ID: X-Mailing-List: linux-ext4@vger.kernel.org On Tue, Nov 17, 2020 at 02:07:01PM +0000, Satya Tangirala wrote: > @@ -275,11 +331,24 @@ static struct bio *blk_bio_segment_split(struct request_queue *q, > bvprvp = &bvprv; > } > > + /* > + * The input bio's number of sectors is assumed to be aligned to > + * bio_sectors_alignment. If that's the case, then this function should > + * ensure that aligned_segs == nsegs and aligned_sectors == sectors if > + * the bio is not going to be split. > + */ > + WARN_ON(aligned_segs != nsegs || aligned_sectors != sectors); > *segs = nsegs; > return NULL; > split: > - *segs = nsegs; > - return bio_split(bio, sectors, GFP_NOIO, bs); > + *segs = aligned_segs; > + if (WARN_ON(aligned_sectors == 0)) > + goto err; > + return bio_split(bio, aligned_sectors, GFP_NOIO, bs); > +err: > + bio->bi_status = BLK_STS_IOERR; > + bio_endio(bio); > + return bio; > } [...] > diff --git a/block/blk-mq.c b/block/blk-mq.c > index 55bcee5dc032..de5c97ab8e5a 100644 > --- a/block/blk-mq.c > +++ b/block/blk-mq.c > @@ -2161,6 +2161,9 @@ blk_qc_t blk_mq_submit_bio(struct bio *bio) > blk_queue_bounce(q, &bio); > __blk_queue_split(&bio, &nr_segs); > > + if (bio->bi_status != BLK_STS_OK) > + goto queue_exit; > + Note that as soon as bio_endio() is called, the bio may be freed. So accessing the bio after that is not correct. - Eric