* Re: Is ext4_dio_read_iter() broken? - and xfs_file_dio_aio_read()
[not found] <969260.1584004779@warthog.procyon.org.uk>
@ 2020-03-12 10:07 ` David Howells
2020-03-12 10:26 ` btrfs may be broken too - Re: Is ext4_dio_read_iter() broken? David Howells
2020-03-12 10:42 ` Is ext4_dio_read_iter() broken? - and xfs_file_dio_aio_read() Christoph Hellwig
0 siblings, 2 replies; 5+ messages in thread
From: David Howells @ 2020-03-12 10:07 UTC (permalink / raw)
To: mbobrowski, darrick.wong
Cc: dhowells, jack, hch, linux-ext4, linux-xfs, linux-fsdevel
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.
David
^ permalink raw reply [flat|nested] 5+ messages in thread
* btrfs may be broken too - Re: Is ext4_dio_read_iter() broken?
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
2020-03-12 10:42 ` Is ext4_dio_read_iter() broken? - and xfs_file_dio_aio_read() Christoph Hellwig
1 sibling, 0 replies; 5+ messages in thread
From: David Howells @ 2020-03-12 10:26 UTC (permalink / raw)
To: clm, josef, dsterba
Cc: dhowells, mbobrowski, darrick.wong, jack, hch, linux-ext4,
linux-xfs, linux-btrfs, linux-fsdevel
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
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: Is ext4_dio_read_iter() broken? - and xfs_file_dio_aio_read()
2020-03-12 10:07 ` Is ext4_dio_read_iter() broken? - and xfs_file_dio_aio_read() David Howells
2020-03-12 10:26 ` btrfs may be broken too - Re: Is ext4_dio_read_iter() broken? David Howells
@ 2020-03-12 10:42 ` Christoph Hellwig
2020-03-12 10:49 ` David Howells
1 sibling, 1 reply; 5+ messages in thread
From: Christoph Hellwig @ 2020-03-12 10:42 UTC (permalink / raw)
To: David Howells
Cc: mbobrowski, darrick.wong, jack, hch, linux-ext4, linux-xfs,
linux-fsdevel
On Thu, Mar 12, 2020 at 10:07:57AM +0000, David Howells wrote:
> 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?
The iocb is refcounted and only completed when the refcount hits zero,
and an extra reference is held until the submission has completed.
Take a look at iocb_put().
> 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.
the file reference also hold an inode reference.
>
> 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.
In addition to that DAX never executes asynchronously.
> And xfs_file_dio_aio_read() appears to be broken as it touches the inode after
> calling iomap_dio_rw() to unlock it.
Same as above.
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: Is ext4_dio_read_iter() broken? - and xfs_file_dio_aio_read()
2020-03-12 10:42 ` Is ext4_dio_read_iter() broken? - and xfs_file_dio_aio_read() Christoph Hellwig
@ 2020-03-12 10:49 ` David Howells
2020-03-12 10:53 ` Christoph Hellwig
0 siblings, 1 reply; 5+ messages in thread
From: David Howells @ 2020-03-12 10:49 UTC (permalink / raw)
To: Christoph Hellwig
Cc: dhowells, mbobrowski, darrick.wong, jack, linux-ext4, linux-xfs,
linux-fsdevel
Christoph Hellwig <hch@lst.de> wrote:
> > > at the end of the function - but surely iocb should be expected to have
> > > been freed when iocb->ki_complete() was called?
>
> The iocb is refcounted and only completed when the refcount hits zero,
> and an extra reference is held until the submission has completed.
> Take a look at iocb_put().
Ah... This is in struct aio_kiocb and not struct kiocb - that's why I missed
it. Thanks.
David
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: Is ext4_dio_read_iter() broken? - and xfs_file_dio_aio_read()
2020-03-12 10:49 ` David Howells
@ 2020-03-12 10:53 ` Christoph Hellwig
0 siblings, 0 replies; 5+ messages in thread
From: Christoph Hellwig @ 2020-03-12 10:53 UTC (permalink / raw)
To: David Howells
Cc: Christoph Hellwig, mbobrowski, darrick.wong, jack, linux-ext4,
linux-xfs, linux-fsdevel
On Thu, Mar 12, 2020 at 10:49:40AM +0000, David Howells wrote:
> Christoph Hellwig <hch@lst.de> wrote:
>
> > > > at the end of the function - but surely iocb should be expected to have
> > > > been freed when iocb->ki_complete() was called?
> >
> > The iocb is refcounted and only completed when the refcount hits zero,
> > and an extra reference is held until the submission has completed.
> > Take a look at iocb_put().
>
> Ah... This is in struct aio_kiocb and not struct kiocb - that's why I missed
> it. Thanks.
That being said we have a few other spots using ->ki_complete for
asynchronous execution, which might not be as careful. As someone
having written one or two of those I have my doubts I got everthing
right and will audit those.
>
> David
---end quoted text---
^ permalink raw reply [flat|nested] 5+ messages in thread
end of thread, other threads:[~2020-03-12 10:53 UTC | newest]
Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
[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 ` btrfs may be broken too - Re: Is ext4_dio_read_iter() broken? David Howells
2020-03-12 10:42 ` Is ext4_dio_read_iter() broken? - and xfs_file_dio_aio_read() Christoph Hellwig
2020-03-12 10:49 ` David Howells
2020-03-12 10:53 ` Christoph Hellwig
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox