pread and pwrite
I'm running some tests from LTP, which tests pread and pwrite. It look like pread/pwrite doesn't do any check, if they are called with 'buf =NULL' or 'offset < 0', and no error is return.
If I look in glibc in sysdeps/generic/pread.c it look like this:
ssize_t__libc_pread (int fd, void *buf, size_t nbytes, off_t offset) {
if (nbytes == 0)
return 0;
if (fd < 0)
{
__set_errno (EBADF);
return -1;
}
if (buf == NULL || offset < 0)
{
__set_errno (EINVAL);
return -1;
} __set_errno (ENOSYS);
return -1;
}
Here there is some checking for sane values and a proper error value is return.
I guess this routine is replaced, if we have the syscall implemented with the sysdeps/unix/sysv/linux/mips/pread.c file.
Here there is no check for sane values, is there any reason why ? The same thing goes for pwrite.
/Carsten
--
_ _ ____ ___ Carsten Langgaard Mailto:[email protected] |\ /|||___)(___ MIPS Denmark Direct: +45 4486 5527 | \/ ||| ____) Lautrupvang 4B Switch: +45 4486 5555 TECHNOLOGIES 2750 Ballerup Fax...: +45 4486 5556 Denmark http://www.mips.com
Quoted 10 lines · Ralf Baechle
Quoted 7 lines · Carsten Langgaard
Here there is some checking for sane values and a proper error value is return.
I guess this routine is replaced, if we have the syscall implemented with thesysdeps/unix/sysv/linux/mips/pread.cfile.
Here there is no check for sane values, is there any reason why ? The same thing goes for pwrite.
Quoted 2 lines
The kernel does it's own error checking. No need to duplicate that in userspace.
The kernel doesn't do this a proper check then.
The pread/pwrite parameters is also convert in glibc, the 'offset' is convert from a 'long' to a 'long long', but it isn't sign extended. So when pread is call with offset -1, then kernel won't see it as -1.
Quoted 2 lines
Ralf
--
_ _ ____ ___ Carsten Langgaard Mailto:[email protected] |\ /|||___)(___ MIPS Denmark Direct: +45 4486 5527 | \/ ||| ____) Lautrupvang 4B Switch: +45 4486 5555 TECHNOLOGIES 2750 Ballerup Fax...: +45 4486 5556 Denmark http://www.mips.com
Quoted 22 lines · H. J. Lu
Quoted 12 lines · Carsten Langgaard
Quoted 10 lines · Ralf Baechle
Quoted 7 lines · Carsten Langgaard
Here there is some checking for sane values and a proper error value is return.
I guess this routine is replaced, if we have the syscall implemented with thesysdeps/unix/sysv/linux/mips/pread.cfile.
Here there is no check for sane values, is there any reason why ? The same thing goes for pwrite.Quoted 8 lines
Quoted 2 lines
The kernel does it's own error checking. No need to duplicate that in userspace.
The kernel doesn't do this a proper check then.
The pread/pwrite parameters is also convert in glibc, the 'offset' is convert from a 'long' to a 'long long', but it isn't sign extended. So when pread is call with offset -1, then kernel won't see it as -1.
Quoted 5 lines
Please check it out:
http://sources.redhat.com/ml/libc-alpha/2002-07/msg00188.html
H.J.
So the same issue has been raised today on the glibc list, amazing. I guess the problem has existed quite some time.
But it look like the patch will fix the problem. Do you know if the patch has been committed and which version of glibc will it then be fixed in ?
Thanks,
/Carsten
Quoted 7 lines · Carsten Langgaard
Here there is some checking for sane values and a proper error value is return.
I guess this routine is replaced, if we have the syscall implemented with thesysdeps/unix/sysv/linux/mips/pread.cfile.
Here there is no check for sane values, is there any reason why ? The same thing goes for pwrite.
The kernel does it's own error checking. No need to duplicate that in userspace.
Ralf
Quoted 12 lines · Carsten Langgaard
Quoted 10 lines · Ralf Baechle
Quoted 7 lines · Carsten Langgaard
Here there is some checking for sane values and a proper error value is return.
I guess this routine is replaced, if we have the syscall implemented with thesysdeps/unix/sysv/linux/mips/pread.cfile.
Here there is no check for sane values, is there any reason why ? The same thing goes for pwrite.
Quoted 8 lines
Quoted 2 lines
The kernel does it's own error checking. No need to duplicate that in userspace.
The kernel doesn't do this a proper check then.
The pread/pwrite parameters is also convert in glibc, the 'offset' is convert from a 'long' to a 'long long', but it isn't sign extended. So when pread is call with offset -1, then kernel won't see it as -1.
Please check it out:
http://sources.redhat.com/ml/libc-alpha/2002-07/msg00188.html
H.J.