From: torvalds@transmeta.com (Linus Torvalds)
To: linux-kernel@vger.kernel.org
Subject: Re: [PATCH] vfs_read/vfs_write small bug fix (2.5.29)
Date: Mon, 29 Jul 2002 20:11:03 +0000 (UTC) [thread overview]
Message-ID: <ai47gn$1dh$1@penguin.transmeta.com> (raw)
In-Reply-To: 200207291825.g6TIPj026021@eng2.beaverton.ibm.com
In article <200207291825.g6TIPj026021@eng2.beaverton.ibm.com>,
Badari Pulavarty <pbadari@us.ibm.com> wrote:
>
>Here is a patch to fix small bug in for vfs_read/vfs_write.
Hmm. The patch is bogus, but that's not your fault, looking at the code
the patch is no more bogus than the existing code already is.
The fact is, the test for a negative "pos" should not be in
vfs_read/write at all, since it can only happen for pread/pwrite.
And pread/pwrite do not even _take_ a "loff_t" argument, they take a
"off_t", and yet we've just happily claiming they do a loff_t, which
means that they shouldn't work at all unless by pure changce user space
happens to put a zero in memory in the right place.
Cristoph, I think you're the one that did this re-org. I think the code
is wrong, and the right fix is something along these lines (untested,
you get brownie-points for testing against some standards test).
Linus
----
===== fs/read_write.c 1.12 vs edited =====
--- 1.12/fs/read_write.c Sat Jul 27 08:21:19 2002
+++ edited/fs/read_write.c Mon Jul 29 12:51:09 2002
@@ -185,8 +185,6 @@
return -EBADF;
if (!file->f_op || !file->f_op->read)
return -EINVAL;
- if (pos < 0)
- return -EINVAL;
ret = locks_verify_area(FLOCK_VERIFY_READ, inode, file, *pos, count);
if (!ret) {
@@ -210,8 +208,6 @@
return -EBADF;
if (!file->f_op || !file->f_op->write)
return -EINVAL;
- if (pos < 0)
- return -EINVAL;
ret = locks_verify_area(FLOCK_VERIFY_WRITE, inode, file, *pos, count);
if (!ret) {
@@ -255,14 +251,18 @@
}
asmlinkage ssize_t sys_pread(unsigned int fd, char *buf,
- size_t count, loff_t pos)
+ size_t count, off_t pos)
{
struct file *file;
ssize_t ret = -EBADF;
+ if (pos < 0)
+ return -EINVAL;
+
file = fget(fd);
if (file) {
- ret = vfs_read(file, buf, count, &pos);
+ loff_t lpos = pos;
+ ret = vfs_read(file, buf, count, &lpos);
fput(file);
}
@@ -270,14 +270,18 @@
}
asmlinkage ssize_t sys_pwrite(unsigned int fd, const char *buf,
- size_t count, loff_t pos)
+ size_t count, off_t pos)
{
struct file *file;
ssize_t ret = -EBADF;
+ if (pos < 0)
+ return -EINVAL;
+
file = fget(fd);
if (file) {
- ret = vfs_write(file, buf, count, &pos);
+ loff_t lpos = pos;
+ ret = vfs_write(file, buf, count, &lpos);
fput(file);
}
next prev parent reply other threads:[~2002-07-29 20:08 UTC|newest]
Thread overview: 8+ messages / expand[flat|nested] mbox.gz Atom feed top
2002-07-29 18:25 [PATCH] vfs_read/vfs_write small bug fix (2.5.29) Badari Pulavarty
2002-07-29 19:02 ` Paul Larson
2002-07-29 20:11 ` Linus Torvalds [this message]
2002-07-29 21:06 ` Paul Larson
2002-07-29 21:22 ` Linus Torvalds
2002-07-29 22:06 ` Paul Larson
2002-07-29 22:17 ` Linus Torvalds
2002-07-30 7:37 ` Andreas Schwab
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='ai47gn$1dh$1@penguin.transmeta.com' \
--to=torvalds@transmeta.com \
--cc=linux-kernel@vger.kernel.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