direct-io: Fix negative return from dio read beyond eof
Subsystems (2)
Jan Kara
reviewerPATCH 1/1 direct-io: Fix negative return from dio read beyond eof
Assume a filesystem with 4KB blocks. When a file has size 1000 bytes and we issue direct IO read at offset 1024, blockdev_direct_IO() reads the tail of the last block and the logic for handling short DIO reads in dio_complete() results in a return value -24 (1000 - 1024) which obviously confuses userspace.
Fix the problem by bailing out early once we sample i_size and can reliably check that direct IO read starts beyond i_size.
--- fs/direct-io.c | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-)
Avi, this patch fixes the issue for me.
Honza
fs/direct-io.c +9 -1
@@ -1163,6 +1163,15 @@ do_blockdev_direct_IO(struct kiocb *iocb, struct inode *inode, } } +/* Once we sampled i_size check for reads beyond EOF */ + dio->i_size =i_size_read (inode); +if (iov_iter_rw (iter) ==READ && offset >= dio->i_size) { +if (dio->flags &DIO_LOCKING ) +mutex_unlock (&inode->i_mutex); +kmem_cache_free (dio_cache, dio); + goto out; + } +/* * For file extending writes updating i_size before data writeouts * complete can expose uninitialized blocks in dumb filesystems.
@@ -1216,7 +1225,6 @@ do_blockdev_direct_IO(struct kiocb *iocb, struct inode *inode, sdio.next_block_for_io =-1 ; dio->iocb = iocb; - dio->i_size =i_size_read (inode);spin_lock_init (&dio->bio_lock); dio->refcount =1 ;
Signature · 1 line
2.1.4
Jan Kara
reviewerQuoted 14 lines · Jan Kara
Assume a filesystem with 4KB blocks. When a file has size 1000 bytes and we issue direct IO read at offset 1024,
blockdev_direct_IO()reads the tail of the last block and the logic for handling short DIO reads indio_complete()results in a return value -24 (1000 - 1024) which obviously confuses userspace.Fix the problem by bailing out early once we sample
i_sizeand can reliably check that direct IO read starts beyondi_size.Reported-by Avi Kivity <[email protected]>Fixes 9fe55eea7e4b444bafc42fa0000cc2d1d2847275CC Steven Whitehouse <[email protected]>Signed-off-by Jan Kara <[email protected]>
Quoted 5 lines
--- fs/direct-io.c | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-)Avi, this patch fixes the issue for me.
Jens, can you pick up this fix please? Thanks!
Honza
Quoted 35 lines
fs/direct-io.c +9
-1@@ -1163,6 +1163,15 @@ do_blockdev_direct_IO(struct kiocb *iocb, struct inode *inode, } } +/* Once we sampled i_size check for reads beyond EOF */ + dio->i_size =i_size_read (inode); +if (iov_iter_rw (iter) ==READ && offset >= dio->i_size) { +if (dio->flags &DIO_LOCKING ) +mutex_unlock (&inode->i_mutex); +kmem_cache_free (dio_cache, dio); + goto out; + } +/* * For file extending writes updating i_size before data writeouts * complete can expose uninitialized blocks in dumb filesystems. @@ -1216,7 +1225,6 @@ do_blockdev_direct_IO(struct kiocb *iocb, struct inode *inode, sdio.next_block_for_io =-1 ; dio->iocb = iocb; - dio->i_size =i_size_read (inode);spin_lock_init (&dio->bio_lock); dio->refcount =1 ;Signature · 6 lines
2.1.4 -- To unsubscribe from this list: send the line "unsubscribe linux-fsdevel" in the body of a message to [email protected] More majordomo info at http://vger.kernel.org/majordomo-info.html
Signature · 2 lines
Jan Kara <[email protected]> SUSE Labs, CR
Quoted 19 lines · Jan Kara
Quoted 18 lines · Jan Kara
Assume a filesystem with 4KB blocks. When a file has size 1000 bytes and we issue direct IO read at offset 1024,
blockdev_direct_IO()reads the tail of the last block and the logic for handling short DIO reads indio_complete()results in a return value -24 (1000 - 1024) which obviously confuses userspace.Fix the problem by bailing out early once we sample
i_sizeand can reliably check that direct IO read starts beyondi_size.Reported-by Avi Kivity <[email protected]>Fixes 9fe55eea7e4b444bafc42fa0000cc2d1d2847275CC Steven Whitehouse <[email protected]>Signed-off-by Jan Kara <[email protected]>--- fs/direct-io.c | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-)
Quoted 3 lines
Quoted 1 line
Avi, this patch fixes the issue for me.
Jens, can you pick up this fix please? Thanks!
Yup, added for 4.4, thanks!
Signature · 1 line
Jens Axboe
Quoted 6 lines · Jan Kara
Assume a filesystem with 4KB blocks. When a file has size 1000 bytes and we issue direct IO read at offset 1024,
blockdev_direct_IO()reads the tail of the last block and the logic for handling short DIO reads indio_complete()results in a return value -24 (1000 - 1024) which obviously confuses userspace.
Quoted 6 lines
Fix the problem by bailing out early once we sample
i_sizeand can reliably check that direct IO read starts beyondi_size.Reported-by Avi Kivity <[email protected]>Fixes 9fe55eea7e4b444bafc42fa0000cc2d1d2847275
While this patch made it into upstream, it did not appear in 4.3.4. Did it slip through the proverbial cracks? Can it be queued for 4.3.5?
Quoted 38 lines
CC Steven Whitehouse <[email protected]>Signed-off-by Jan Kara <[email protected]>--- fs/direct-io.c | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-)Avi, this patch fixes the issue for me.
Honza
fs/direct-io.c +9
-1@@ -1163,6 +1163,15 @@ do_blockdev_direct_IO(struct kiocb *iocb, struct inode *inode, } } +/* Once we sampled i_size check for reads beyond EOF */ + dio->i_size =i_size_read (inode); +if (iov_iter_rw (iter) ==READ && offset >= dio->i_size) { +if (dio->flags &DIO_LOCKING ) +mutex_unlock (&inode->i_mutex); +kmem_cache_free (dio_cache, dio); + goto out; + } +/* * For file extending writes updating i_size before data writeouts * complete can expose uninitialized blocks in dumb filesystems. @@ -1216,7 +1225,6 @@ do_blockdev_direct_IO(struct kiocb *iocb, struct inode *inode, sdio.next_block_for_io =-1 ; dio->iocb = iocb; - dio->i_size =i_size_read (inode);spin_lock_init (&dio->bio_lock); dio->refcount =1 ;
Quoted 10 lines · Avi Kivity
Quoted 9 lines · Jan Kara
Assume a filesystem with 4KB blocks. When a file has size 1000 bytes and we issue direct IO read at offset 1024,
blockdev_direct_IO()reads the tail of the last block and the logic for handling short DIO reads indio_complete()results in a return value -24 (1000 - 1024) which obviously confuses userspace.Fix the problem by bailing out early once we sample
i_sizeand can reliably check that direct IO read starts beyondi_size.
Quoted 6 lines
Quoted 3 lines
Reported-by Avi Kivity <[email protected]>Fixes 9fe55eea7e4b444bafc42fa0000cc2d1d2847275While this patch made it into upstream, it did not appear in 4.3.4. Did it slip through the proverbial cracks? Can it be queued for 4.3.5?
There are over 400 patches right now in my queue that haven't made it into a 4.3.x kernel. These are in the queue, in good company :)
I'll go dig these out as I guess people care about them more than others...
thanks,
greg k-h
Quoted 11 lines · Greg KH
Quoted 10 lines · Avi Kivity
Quoted 9 lines · Jan Kara
Assume a filesystem with 4KB blocks. When a file has size 1000 bytes and we issue direct IO read at offset 1024,
blockdev_direct_IO()reads the tail of the last block and the logic for handling short DIO reads indio_complete()results in a return value -24 (1000 - 1024) which obviously confuses userspace.Fix the problem by bailing out early once we sample
i_sizeand can reliably check that direct IO read starts beyondi_size.
Quoted 7 lines
Quoted 5 lines
Quoted 3 lines
Reported-by Avi Kivity <[email protected]>Fixes 9fe55eea7e4b444bafc42fa0000cc2d1d2847275While this patch made it into upstream, it did not appear in 4.3.4. Did it slip through the proverbial cracks? Can it be queued for 4.3.5?
There are over 400 patches right now in my queue that haven't made it into a 4.3.x kernel.
Many projects would consider 400 patches a major release, and here they are behind two dots...
Quoted 6 lines
These are in the queue, in good company :)
I'll go dig these out as I guess people care about them more than others...
Much appreciated.
Quoted 15 lines · Avi Kivity
Quoted 14 lines · Greg KH
Quoted 13 lines · Avi Kivity
Quoted 12 lines · Jan Kara
Assume a filesystem with 4KB blocks. When a file has size 1000 bytes and we issue direct IO read at offset 1024,
blockdev_direct_IO()reads the tail of the last block and the logic for handling short DIO reads indio_complete()results in a return value -24 (1000 - 1024) which obviously confuses userspace.Fix the problem by bailing out early once we sample
i_sizeand can reliably check that direct IO read starts beyondi_size.Reported-by Avi Kivity <[email protected]>Fixes 9fe55eea7e4b444bafc42fa0000cc2d1d2847275
Quoted 7 lines
Quoted 4 lines
Quoted 2 lines
While this patch made it into upstream, it did not appear in 4.3.4. Did it slip through the proverbial cracks? Can it be queued for 4.3.5?
There are over 400 patches right now in my queue that haven't made it into a 4.3.x kernel.
Many projects would consider 400 patches a major release, and here they are behind two dots...
Look at the percentages, it's just a tiny drop in the bucket compared to what is hitting Linus's tree :)
thanks,
greg k-h
Quoted 8 lines · Avi Kivity
Quoted 6 lines
These are in the queue, in good company :)
I'll go dig these out as I guess people care about them more than others...
Much appreciated.
Note, they didn't build on 3.14 so I had to revert both of them. If you could provide a fix for that release, that would be great.
thanks,
greg k-h
Quoted 9 lines · Greg KH
Quoted 7 lines · Avi Kivity
Quoted 6 lines
These are in the queue, in good company :)
I'll go dig these out as I guess people care about them more than others...
Much appreciated.
Note, they didn't build on 3.14
I think the regression was introduced post 14, let me check.
Quoted 1 line
so I had to revert both of them.
Both of what? There was only one patch. Or did you mean you drop this patch for 4.3.5?
Quoted 3 lines
If you
could provide a fix for that release, that would be great.
Quoted 4 lines · Avi Kivity
Quoted 3 lines · Greg KH
Quoted 2 lines · Avi Kivity
Quoted 2 lines
These are in the queue, in good company :)
Quoted 9 lines
Quoted 6 lines
Quoted 5 lines
Quoted 4 lines
I'll go dig these out as I guess people care about them more than others...
Much appreciated.
Note, they didn't build on 3.14
I think the regression was introduced post 14, let me check.
Actually it was introduced in 3.14-rc1. I could try a backport, but it would be better if someone who actually knows the code did this.
Quoted 4 lines · Avi Kivity
Quoted 3 lines · Greg KH
Quoted 2 lines · Avi Kivity
Quoted 2 lines
These are in the queue, in good company :)
Quoted 8 lines
Quoted 6 lines
Quoted 5 lines
Quoted 4 lines
I'll go dig these out as I guess people care about them more than others...
Much appreciated.
Note, they didn't build on 3.14
I think the regression was introduced post 14, let me check.
Not according to the stable tag in the commit :)
Quoted 4 lines
Quoted 1 line
so I had to revert both of them.
Both of what? There was only one patch. Or did you mean you drop this patch for 4.3.5?
There was a follow-on fix for this patch as well, commit 2d4594acbf6d8f75a27f3578476b6a27d8b13ebb.
thanks,
greg k-h