From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-5.6 required=3.0 tests=DKIMWL_WL_HIGH,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI, SIGNED_OFF_BY,SPF_PASS,UNPARSEABLE_RELAY,URIBL_BLOCKED,USER_AGENT_MUTT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 33D9DC282C8 for ; Mon, 28 Jan 2019 16:43:08 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 0590120879 for ; Mon, 28 Jan 2019 16:43:08 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=oracle.com header.i=@oracle.com header.b="fGwtACLF" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2389235AbfA1QnG (ORCPT ); Mon, 28 Jan 2019 11:43:06 -0500 Received: from userp2130.oracle.com ([156.151.31.86]:53200 "EHLO userp2130.oracle.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2389024AbfA1QXc (ORCPT ); Mon, 28 Jan 2019 11:23:32 -0500 Received: from pps.filterd (userp2130.oracle.com [127.0.0.1]) by userp2130.oracle.com (8.16.0.22/8.16.0.22) with SMTP id x0SGInug087556; Mon, 28 Jan 2019 16:22:35 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=oracle.com; h=date : from : to : cc : subject : message-id : references : mime-version : content-type : in-reply-to; s=corp-2018-07-02; bh=U6X3VyYu4/15v55KfCA9mAuCiXbHZ6v6q8XaQjJtszA=; b=fGwtACLF9QRud7pCsWZz7CTxJjpXTYzYJwXTkzA5JDMe6TIHr6nPK1Z0v+c+gt9OkjIG uZqS9g3OWRHSmiIGQ+9MdTlkD6Pl7LbHRvMzWkNYTtjosy3vjuvPJDPqU1YM9qDywFI9 JtImhsYZllqsx5ZuwXKtet6kB/LxklfbfG0zFAlcOnxnrGiMJO9ufOMgsEypFgcZonNF CiJxjBd6j0/87kzUuEJ53h/EbdNSN4B5cApD5nhxpCj1pw7sHPkjjidyu0H36QPunZJd 1/5SAnVvvc/7xlHyOCo3649llsKNjXeV9AhXjQT6BqB5cU4YYtzEk4IHJp8XTqNarbwE LA== Received: from userv0022.oracle.com (userv0022.oracle.com [156.151.31.74]) by userp2130.oracle.com with ESMTP id 2q8eyu757r-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Mon, 28 Jan 2019 16:22:34 +0000 Received: from aserv0121.oracle.com (aserv0121.oracle.com [141.146.126.235]) by userv0022.oracle.com (8.14.4/8.14.4) with ESMTP id x0SGMXV1003819 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Mon, 28 Jan 2019 16:22:34 GMT Received: from abhmp0010.oracle.com (abhmp0010.oracle.com [141.146.116.16]) by aserv0121.oracle.com (8.14.4/8.13.8) with ESMTP id x0SGMXPJ002786; Mon, 28 Jan 2019 16:22:33 GMT Received: from localhost (/67.169.218.210) by default (Oracle Beehive Gateway v4.0) with ESMTP ; Mon, 28 Jan 2019 08:22:33 -0800 Date: Mon, 28 Jan 2019 08:22:33 -0800 From: "Darrick J. Wong" To: Dave Chinner Cc: Christoph Hellwig , linux-xfs@vger.kernel.org, linux-fsdevel@vger.kernel.org, Chandan Rajendra Subject: Re: [PATCH] iomap: fix a use after free in iomap_dio_rw Message-ID: <20190128162233.GF4368@magnolia> References: <20190117075707.8640-1-hch@lst.de> <20190117212658.GD6173@dastard> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20190117212658.GD6173@dastard> User-Agent: Mutt/1.9.4 (2018-02-28) X-Proofpoint-Virus-Version: vendor=nai engine=5900 definitions=9150 signatures=668682 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 suspectscore=2 malwarescore=0 phishscore=0 bulkscore=0 spamscore=0 mlxscore=0 mlxlogscore=587 adultscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.0.1-1810050000 definitions=main-1901280123 Sender: linux-fsdevel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-fsdevel@vger.kernel.org On Fri, Jan 18, 2019 at 08:26:58AM +1100, Dave Chinner wrote: > On Thu, Jan 17, 2019 at 08:57:07AM +0100, Christoph Hellwig wrote: > > Introduce a local wait_for_completion variable to avoid an access to the > > potentially freed dio struture after dropping the last reference count. > > > > Also use the chance to document the completion behavior to make the > > refcounting clear to the reader of the code. > > > > Fixes: ff6a9292e6 ("iomap: implement direct I/O") > > Reported-by: Chandan Rajendra > > Reported-by: Darrick J. Wong > > Signed-off-by: Christoph Hellwig > > Tested-by: Chandan Rajendra > > Tested-by: Darrick J. Wong > > --- > > fs/iomap.c | 28 +++++++++++++++++++++------- > > 1 file changed, 21 insertions(+), 7 deletions(-) > > Looks good, minor comment cleanup needed, though. maybe Darrick can > do it on commit? > > Reviewed-by: Dave Chinner > > > @@ -1925,8 +1925,24 @@ iomap_dio_rw(struct kiocb *iocb, struct iov_iter *iter, > > if (dio->flags & IOMAP_DIO_WRITE_FUA) > > dio->flags &= ~IOMAP_DIO_NEED_SYNC; > > > > + /* > > + * We are about to drop our additional submission reference, which > > + * might be the last reference to the dio. There are three three > > + * different ways we can progress here: > > + * > > + * (a) If this is the last reference we will always complete and free > > + * the dio ourselves. right here. > > s/ right here.// Fixed. Reviewed-by: Darrick J. Wong --D > -Dave. > -- > Dave Chinner > david@fromorbit.com