Received: by 2002:a25:e7d8:0:0:0:0:0 with SMTP id e207csp360045ybh; Thu, 12 Mar 2020 03:26:33 -0700 (PDT) X-Google-Smtp-Source: ADFU+vuf/AB4XlGADOkSSrbWsvQhkSi18DKPVZlKInEQre19wWHqbsy9OzU1/795cbJsI/6/sxeA X-Received: by 2002:a9d:2a83:: with SMTP id e3mr6223320otb.280.1584008792889; Thu, 12 Mar 2020 03:26:32 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1584008792; cv=none; d=google.com; s=arc-20160816; b=cA2UQI5doTo2NbpiJDnBYOv0oq6eUIxNJHO893krPj3CI1JNBR7dy/gRhwVrlsm+Sy IUT5dSsH0nmqsyVVstcZwayFqpAvxOypyf16TYtGF6w9X1bFkCyfsoD+fpU2JwD+S+1r JBLPmsJQsoS8BHFFvKvAGfpWn+SBCJDzdTmlWGeoq9eOr/tQz8XpBmbqPCPCNSQ2+yBN E2QEtGqwamMj/pzO1r/lHAeednsTMkKE08DcA0nIATmNkmlvYP2rnpBKoF6s1MmEZ2Ji 97Qljrocs49ijDRccf+cii2yhmZrMjxY4nk2F65Cr6WhNTNFfe7G52at5qe/khzJUlh2 Odhg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:message-id:date:content-transfer-encoding :content-id:mime-version:subject:cc:to:references:in-reply-to:from :organization:dkim-signature; bh=mOBS2wli+ub8UNg/a0qe1B6uGroDbB2RmIKqhZCROdo=; b=h66omDGe2cnMOvH9pmWJpuzQKfkCksaiP5ExWOwuF9VJ63P8O/XKlVfO/XaDgLUN0E 4UHfjnP2XzqgNvFSl7lXfFeJ5OjnrGUL6cHblnwep9cVN/lQqcIGv40A4ktRtSq/tigt EPyfJw5PXzEMN1s6DdDL7HT5HMYtXG4EinAVcUxJ1xOgL2i1q5z6/EOvBAYpRTlCxh1i ur2/9vzy8zAU4r4tbPIJeZtFP4aeWQGihxSWdi/hztPdcO4wo/g6VMzSILSBmZxQFyxK D6oxbRDpJ8S9sF+YfwK9VL2zskA5Me0LcsxEzzh9+UPhFHROhoohj9MjT/0VmQeCjIm8 S2HA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=N16BGhWS; spf=pass (google.com: best guess record for domain of linux-ext4-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-ext4-owner@vger.kernel.org; dmarc=pass (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 t71si1911788oif.84.2020.03.12.03.26.21; Thu, 12 Mar 2020 03:26:32 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-ext4-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=N16BGhWS; spf=pass (google.com: best guess record for domain of linux-ext4-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-ext4-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726669AbgCLK0U (ORCPT + 99 others); Thu, 12 Mar 2020 06:26:20 -0400 Received: from us-smtp-delivery-1.mimecast.com ([205.139.110.120]:43721 "EHLO us-smtp-1.mimecast.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1726591AbgCLK0U (ORCPT ); Thu, 12 Mar 2020 06:26:20 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1584008779; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=mOBS2wli+ub8UNg/a0qe1B6uGroDbB2RmIKqhZCROdo=; b=N16BGhWSowpR9+KhhiEOua05ybl4WeD8bC5LDzPJAM4KRkbz6LGi43srWXJNO7t5GJ4eQw WYf56snqYF8vCMpbVh9sCx6dqStijmMI7sxui0DjkvhKP7b/PLfyvh3LuNPLRJcGjHmtuk hY3mawBc7gof1ONBT/INPt5NIuwfmsY= Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-118-DhXxdGWqOnSZkj73jKhAyg-1; Thu, 12 Mar 2020 06:26:15 -0400 X-MC-Unique: DhXxdGWqOnSZkj73jKhAyg-1 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 mimecast-mx01.redhat.com (Postfix) with ESMTPS id 9FBEDDB62; Thu, 12 Mar 2020 10:26:13 +0000 (UTC) Received: from warthog.procyon.org.uk (ovpn-120-182.rdu2.redhat.com [10.10.120.182]) by smtp.corp.redhat.com (Postfix) with ESMTP id 508BD10013A1; Thu, 12 Mar 2020 10:26:11 +0000 (UTC) Organization: Red Hat UK Ltd. Registered Address: Red Hat UK Ltd, Amberley Place, 107-111 Peascod Street, Windsor, Berkshire, SI4 1TE, United Kingdom. Registered in England and Wales under Company Registration No. 3798903 From: David Howells In-Reply-To: <1015227.1584007677@warthog.procyon.org.uk> References: <1015227.1584007677@warthog.procyon.org.uk> <969260.1584004779@warthog.procyon.org.uk> To: clm@fb.com, josef@toxicpanda.com, dsterba@suse.com Cc: dhowells@redhat.com, mbobrowski@mbobrowski.org, darrick.wong@oracle.com, jack@suse.cz, hch@lst.de, linux-ext4@vger.kernel.org, linux-xfs@vger.kernel.org, linux-btrfs@vger.kernel.org, linux-fsdevel@vger.kernel.org Subject: btrfs may be broken too - Re: Is ext4_dio_read_iter() broken? MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-ID: <1016627.1584008770.1@warthog.procyon.org.uk> Content-Transfer-Encoding: quoted-printable Date: Thu, 12 Mar 2020 10:26:10 +0000 Message-ID: <1016628.1584008770@warthog.procyon.org.uk> X-Scanned-By: MIMEDefang 2.84 on 10.5.11.22 Sender: linux-ext4-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-ext4@vger.kernel.org David Howells wrote: > > Is ext4_dio_read_iter() broken? It calls: > > = > > file_accessed(iocb->ki_filp); > > = > > at the end of the function - but surely iocb should be expected to hav= e been > > freed when iocb->ki_complete() was called? > = > I think it's actually worse than that. You also can't call > inode_unlock_shared(inode) because you no longer own a ref on the inode = since > ->ki_complete() is expected to call fput() on iocb->ki_filp. > = > Yes, you own a shared lock on it, but unless somewhere along the > fput-dput-iput chain the inode lock is taken exclusively, the inode can = be > freed whilst you're still holding the lock. > = > Oh - and ext4_dax_read_iter() is also similarly broken. > = > And xfs_file_dio_aio_read() appears to be broken as it touches the inode= after > calling iomap_dio_rw() to unlock it. Seems btrfs_file_write_iter() is also broken: if (iocb->ki_flags & IOCB_DIRECT) { num_written =3D __btrfs_direct_write(iocb, from); } else { num_written =3D btrfs_buffered_write(iocb, from); if (num_written > 0) iocb->ki_pos =3D pos + num_written; if (clean_page) pagecache_isize_extended(inode, oldsize, i_size_read(inode)); } inode_unlock(inode); But if __btrfs_direct_write() returned -EIOCBQUEUED then inode may have be= en deallocated by the point it's calling inode_unlock(). Holding the lock is= not a preventative measure that I can see. David