From: Todd Inglett <tinglett@vnet.ibm.com>
To: Thomas Hood <jdthood@mail.com>
Cc: linux-kernel@vger.kernel.org
Subject: Re: proc_file_read() hack?
Date: Wed, 27 Mar 2002 12:26:39 -0600 [thread overview]
Message-ID: <3CA20EDF.7080402@vnet.ibm.com> (raw)
In-Reply-To: <20020323114004.92117.qmail@web10307.mail.yahoo.com> <3C9F69F4.3010908@vnet.ibm.com> <1017085557.5263.335.camel@thanatos>
[-- Attachment #1: Type: text/plain, Size: 2246 bytes --]
Thomas Hood wrote:
> Unfortunately, your method #3 conflicts with methods #0 through #2,
> which exhaust the range of possible values that may be returned
> in *start. Any value greater than buffer is regarded as being
> "within the buffer".
I guess I don't understand the conflict.
There is case #0 where start is NULL. In this case start is computed in
proc_file_read as page + *ppos so (unsigned long)start < PROC_BLOCK_SIZE
is NOT true and so start is used as before.
In case #1 (unsigned long)start < PROC_BLOCK_SIZE so it will grab the
data from page and use start as the length to copy as it did before.
And finally cases #2 and #3 are the same: use start as an explicit data
address. It doesn't matter whether this points into page or if it is
space provided by read_proc (which is why I suggested not even
mentioning a "case #3").
Did you get a chance to read the patch? I'll attach it again just in
case. Or is there a chance that start >= PROC_BLOCK_SIZE (but start <
page) in case #1? If that is true I am wondering how it could possibly
be correct since start will be used as a length which is greater than
the size of the page.
-todd
>
> Introducing method #1 was a bad idea because this hack made it
> impossible cleanly to implement what you suggest.
>
> --
> Thomas Hood
>
> On Mon, 2002-03-25 at 13:18, Todd Inglett wrote:
>
>>How about applying my trivial patch and then adding this to your nice
>>comment?
>>
>>3) Set *start = an address outside the buffer.
>> Put the data of the requested offset at *start.
>> Return the number of bytes of data placed there.
>> If this number is greater than zero and you
>> didn't signal eof and the reader is prepared to
>> take more data you will be called again with the
>> requested offset advanced by the number ob tyes
>> absorbed.
>>
>>The code should still work with the other cases now that the hack is
>>fixed. Of course, rather than add 3), it would be better to re-word 2)
>>(e.g. "Set *start = address of the buffer which may or may not be in the
>>given buffer.).
>>
>>There are cases where the data is available and need not be copied. My
>>code got simpler when I got rid of the need to copy my data around.
>>
[-- Attachment #2: fs-proc-generic.patch --]
[-- Type: text/plain, Size: 887 bytes --]
Index: fs/proc/generic.c
===================================================================
RCS file: /cvs/linuxppc64/linuxppc64_2_4/fs/proc/generic.c,v
retrieving revision 1.6
diff -u -r1.6 generic.c
--- fs/proc/generic.c 8 Oct 2001 19:19:59 -0000 1.6
+++ fs/proc/generic.c 22 Mar 2002 14:34:47 -0000
@@ -104,14 +104,14 @@
* return the bytes, and set `start' to the desired offset
* as an unsigned int. - Paul.Russell@rustcorp.com.au
*/
- n -= copy_to_user(buf, start < page ? page : start, n);
+ n -= copy_to_user(buf, (unsigned long)start < PROC_BLOCK_SIZE ? page : start, n);
if (n == 0) {
if (retval == 0)
retval = -EFAULT;
break;
}
- *ppos += start < page ? (long)start : n; /* Move down the file */
+ *ppos += (unsigned long)start < PROC_BLOCK_SIZE ? (long)start : n; /* Move down the file */
nbytes -= n;
buf += n;
retval += n;
next prev parent reply other threads:[~2002-03-27 18:38 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
2002-03-23 11:40 proc_file_read() hack? J.D. Hood
2002-03-25 18:18 ` Todd Inglett
2002-03-25 19:45 ` Thomas Hood
2002-03-27 18:26 ` Todd Inglett [this message]
2002-03-28 1:02 ` Thomas Hood
2002-03-28 15:29 ` Todd Inglett
-- strict thread matches above, loose matches on Subject: below --
2002-03-22 14:34 Todd Inglett
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=3CA20EDF.7080402@vnet.ibm.com \
--to=tinglett@vnet.ibm.com \
--cc=jdthood@mail.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