Linux XFS filesystem development
 help / color / mirror / Atom feed
From: David Howells <dhowells@redhat.com>
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?
Date: Thu, 12 Mar 2020 10:26:10 +0000	[thread overview]
Message-ID: <1016628.1584008770@warthog.procyon.org.uk> (raw)
In-Reply-To: <1015227.1584007677@warthog.procyon.org.uk>

David Howells <dhowells@redhat.com> 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 have 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 = __btrfs_direct_write(iocb, from);
	} else {
		num_written = btrfs_buffered_write(iocb, from);
		if (num_written > 0)
			iocb->ki_pos = 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 been
deallocated by the point it's calling inode_unlock().  Holding the lock is not
a preventative measure that I can see.

David


  reply	other threads:[~2020-03-12 10:26 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
     [not found] <969260.1584004779@warthog.procyon.org.uk>
2020-03-12 10:07 ` Is ext4_dio_read_iter() broken? - and xfs_file_dio_aio_read() David Howells
2020-03-12 10:26   ` David Howells [this message]
2020-03-12 10:42   ` Christoph Hellwig
2020-03-12 10:49     ` David Howells
2020-03-12 10:53       ` Christoph Hellwig

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1016628.1584008770@warthog.procyon.org.uk \
    --to=dhowells@redhat.com \
    --cc=clm@fb.com \
    --cc=darrick.wong@oracle.com \
    --cc=dsterba@suse.com \
    --cc=hch@lst.de \
    --cc=jack@suse.cz \
    --cc=josef@toxicpanda.com \
    --cc=linux-btrfs@vger.kernel.org \
    --cc=linux-ext4@vger.kernel.org \
    --cc=linux-fsdevel@vger.kernel.org \
    --cc=linux-xfs@vger.kernel.org \
    --cc=mbobrowski@mbobrowski.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox