* Re: sendfile -EOVERFLOW on AMD64
2004-05-19 10:58 ` Jakub Jelinek
@ 2004-05-19 11:01 ` Jan Kasprzak
2004-05-19 11:22 ` Nathan Scott
2004-05-19 11:13 ` Nathan Scott
` (2 subsequent siblings)
3 siblings, 1 reply; 11+ messages in thread
From: Jan Kasprzak @ 2004-05-19 11:01 UTC (permalink / raw)
To: Jakub Jelinek; +Cc: Andi Kleen, linux-kernel
Jakub Jelinek wrote:
: For XFS I'd expect this:
: STATIC ssize_t
: linvfs_sendfile(
: struct file *filp,
: loff_t *ppos,
: size_t count,
: read_actor_t actor,
: void *target)
: {
: vnode_t *vp = LINVFS_GET_VP(filp->f_dentry->d_inode);
: int error;
:
: VOP_SENDFILE(vp, filp, ppos, 0, count, actor, target, NULL, error);
: return error;
: }
:
: (note error is int, not ssize_t), but I don't see anything obvious
: for other filesystems.
:
Yes, XFS. I will look at it in the evening.
Thanks,
-Yenya
--
| Jan "Yenya" Kasprzak <kas at {fi.muni.cz - work | yenya.net - private}> |
| GPG: ID 1024/D3498839 Fingerprint 0D99A7FB206605D7 8B35FCDE05B18A5E |
| http://www.fi.muni.cz/~kas/ Czech Linux Homepage: http://www.linux.cz/ |
Any compiler or language that likes to hide things like memory allocations
behind your back just isn't a good choice for a kernel. --Linus Torvalds
^ permalink raw reply [flat|nested] 11+ messages in thread* Re: sendfile -EOVERFLOW on AMD64
2004-05-19 11:01 ` Jan Kasprzak
@ 2004-05-19 11:22 ` Nathan Scott
0 siblings, 0 replies; 11+ messages in thread
From: Nathan Scott @ 2004-05-19 11:22 UTC (permalink / raw)
To: Jan Kasprzak; +Cc: Jakub Jelinek, Andi Kleen, linux-kernel
On Wed, May 19, 2004 at 01:01:05PM +0200, Jan Kasprzak wrote:
> ...
> Yes, XFS. I will look at it in the evening.
>
> Thanks,
The only spot needing fixing is that one pointed out above; from
a quick look ssize_t seems to be used correctly in the rest of
the XFS sendfile code.
cheers.
--
Nathan
^ permalink raw reply [flat|nested] 11+ messages in thread
* Re: sendfile -EOVERFLOW on AMD64
2004-05-19 10:58 ` Jakub Jelinek
2004-05-19 11:01 ` Jan Kasprzak
@ 2004-05-19 11:13 ` Nathan Scott
2004-05-19 12:44 ` Andi Kleen
2004-05-19 19:48 ` Jan Kasprzak
3 siblings, 0 replies; 11+ messages in thread
From: Nathan Scott @ 2004-05-19 11:13 UTC (permalink / raw)
To: Jakub Jelinek; +Cc: Jan Kasprzak, Andi Kleen, linux-kernel
On Wed, May 19, 2004 at 06:58:06AM -0400, Jakub Jelinek wrote:
> ...
> (note error is int, not ssize_t), but I don't see anything obvious
> for other filesystems.
Thanks, I'll fix that up.
cheers.
--
Nathan
^ permalink raw reply [flat|nested] 11+ messages in thread
* Re: sendfile -EOVERFLOW on AMD64
2004-05-19 10:58 ` Jakub Jelinek
2004-05-19 11:01 ` Jan Kasprzak
2004-05-19 11:13 ` Nathan Scott
@ 2004-05-19 12:44 ` Andi Kleen
2004-05-19 12:50 ` Jakub Jelinek
2004-05-19 19:48 ` Jan Kasprzak
3 siblings, 1 reply; 11+ messages in thread
From: Andi Kleen @ 2004-05-19 12:44 UTC (permalink / raw)
To: Jakub Jelinek; +Cc: Jan Kasprzak, Andi Kleen, linux-kernel, akpm
> (note error is int, not ssize_t), but I don't see anything obvious
> for other filesystems.
sendfile64 on 32bit hosts seems to be quite fishy too.
It works with ssize_t, which is 32bit only, but there are no checks
that the transfered file is not >4GB. It would just wrap in this case.
It would be better to add such checks for 32bit hosts to sendfile64.
Or am I missing something?
-Andi
^ permalink raw reply [flat|nested] 11+ messages in thread
* Re: sendfile -EOVERFLOW on AMD64
2004-05-19 12:44 ` Andi Kleen
@ 2004-05-19 12:50 ` Jakub Jelinek
2004-05-19 12:57 ` Andi Kleen
0 siblings, 1 reply; 11+ messages in thread
From: Jakub Jelinek @ 2004-05-19 12:50 UTC (permalink / raw)
To: Andi Kleen; +Cc: Jan Kasprzak, linux-kernel, akpm
On Wed, May 19, 2004 at 02:44:27PM +0200, Andi Kleen wrote:
> > (note error is int, not ssize_t), but I don't see anything obvious
> > for other filesystems.
>
> sendfile64 on 32bit hosts seems to be quite fishy too.
>
> It works with ssize_t, which is 32bit only, but there are no checks
> that the transfered file is not >4GB. It would just wrap in this case.
> It would be better to add such checks for 32bit hosts to sendfile64.
>
> Or am I missing something?
The userland prototypes are:
extern ssize_t sendfile (int __out_fd, int __in_fd, off_t *__offset,
size_t __count) __THROW;
extern ssize_t sendfile64 (int __out_fd, int __in_fd, __off64_t *__offset,
size_t __count) __THROW;
Thus you really cannot transfer more than 4G-1 bytes in one call on 32-bit
arches.
Actually, already any counts >= 2GB-1 might be problematic, but we are
there on the same boat as with e.g. read(2). For read, POSIX says:
"If the value of nbyte is greater than {SSIZE_MAX}, the result is
implementation-defined."
so portable programs really shouldn't try to transfer more than that
in one go but the kernel certainly should try to handle sizes up to
SIZE_MAX-4096 or something like that.
Jakub
^ permalink raw reply [flat|nested] 11+ messages in thread* Re: sendfile -EOVERFLOW on AMD64
2004-05-19 12:50 ` Jakub Jelinek
@ 2004-05-19 12:57 ` Andi Kleen
0 siblings, 0 replies; 11+ messages in thread
From: Andi Kleen @ 2004-05-19 12:57 UTC (permalink / raw)
To: Jakub Jelinek; +Cc: Andi Kleen, Jan Kasprzak, linux-kernel, akpm
> The userland prototypes are:
> extern ssize_t sendfile (int __out_fd, int __in_fd, off_t *__offset,
> size_t __count) __THROW;
> extern ssize_t sendfile64 (int __out_fd, int __in_fd, __off64_t *__offset,
> size_t __count) __THROW;
> Thus you really cannot transfer more than 4G-1 bytes in one call on 32-bit
> arches.
True.
> Actually, already any counts >= 2GB-1 might be problematic, but we are
> there on the same boat as with e.g. read(2). For read, POSIX says:
> "If the value of nbyte is greater than {SSIZE_MAX}, the result is
> implementation-defined."
> so portable programs really shouldn't try to transfer more than that
> in one go but the kernel certainly should try to handle sizes up to
> SIZE_MAX-4096 or something like that.
Hmm, ssize_t is signed. If there are any if (ret < 0) checks in the
kernel it will fail too. So the real limit would be 0x7fffffff
Perhaps that should be enforced like this?
diff -u linux/fs/read_write.c-o linux/fs/read_write.c
--- linux/fs/read_write.c-o 2004-05-18 10:55:54.000000000 +0200
+++ linux/fs/read_write.c 2004-05-19 14:57:06.000000000 +0200
@@ -700,6 +700,9 @@
off_t off;
ssize_t ret;
+ if (sizeof(size_t) == 4 && (int)count < 0)
+ return -EOVERFLOW;
+
if (offset) {
if (unlikely(get_user(off, offset)))
return -EFAULT;
@@ -718,6 +721,9 @@
loff_t pos;
ssize_t ret;
+ if (sizeof(size_t) == 4 && (int)count < 0)
+ return -EOVERFLOW;
+
if (offset) {
if (unlikely(copy_from_user(&pos, offset, sizeof(loff_t))))
return -EFAULT;
-Andi
^ permalink raw reply [flat|nested] 11+ messages in thread
* Re: sendfile -EOVERFLOW on AMD64
2004-05-19 10:58 ` Jakub Jelinek
` (2 preceding siblings ...)
2004-05-19 12:44 ` Andi Kleen
@ 2004-05-19 19:48 ` Jan Kasprzak
3 siblings, 0 replies; 11+ messages in thread
From: Jan Kasprzak @ 2004-05-19 19:48 UTC (permalink / raw)
To: Jakub Jelinek; +Cc: Andi Kleen, linux-kernel
Jakub Jelinek wrote:
: int error;
:
: VOP_SENDFILE(vp, filp, ppos, 0, count, actor, target, NULL, error);
: return error;
: }
:
: (note error is int, not ssize_t), but I don't see anything obvious
: for other filesystems.
:
Yes, this fixed the problem - now I can sendfile() the whole
DVD image without problem. Thanks, and send both these fixes to Linus.
-Yenya
--
| Jan "Yenya" Kasprzak <kas at {fi.muni.cz - work | yenya.net - private}> |
| GPG: ID 1024/D3498839 Fingerprint 0D99A7FB206605D7 8B35FCDE05B18A5E |
| http://www.fi.muni.cz/~kas/ Czech Linux Homepage: http://www.linux.cz/ |
Any compiler or language that likes to hide things like memory allocations
behind your back just isn't a good choice for a kernel. --Linus Torvalds
^ permalink raw reply [flat|nested] 11+ messages in thread