From: "Randy.Dunlap" <rddunlap@osdl.org>
To: Jonathan Brassow <brassow@sistina.com>
Cc: linux-kernel@vger.kernel.org
Subject: Re: garbage in /proc/partitions (kernel 2.4.20)
Date: Mon, 5 May 2003 10:06:20 -0700 [thread overview]
Message-ID: <20030505100620.4dccbc9b.rddunlap@osdl.org> (raw)
In-Reply-To: <CC0FB215-7F1A-11D7-86A4-000393B0089A@sistina.com>
On Mon, 5 May 2003 11:58:30 -0500 Jonathan Brassow <brassow@sistina.com> wrote:
| There is garbage in the /proc/partions "file" when the partition
| information exceeds the page size. It is a problem that lies in the
| interaction between linux/fs/seq_file.c:seq_read() and the
| seq_operations defined in linux/drivers/block/genhd.c.
|
| I believe that the offending is in the following section of seq_read():
| /* we need at least one record in buffer */
| while (1) {
| pos = m->index;
| p = m->op->start(m, &pos);
| err = PTR_ERR(p);
| if (!p || IS_ERR(p))
| break;
| err = m->op->show(m, p);
| if (err)
| break;
| if (m->count < m->size)
| goto Fill;
| m->op->stop(m, p);
| kfree(m->buf);
| m->buf = kmalloc(m->size <<= 1, GFP_KERNEL);
| if (!m->buf)
| goto Enomem;
| }
|
| What seems to happen is that the partition information does not fit in
| m-buf, so 2x the amount of memory is allocated. However, "count"
| doesn't seem to be reset, so really, there is still only one page to
| use instead of two (count points to the end of the first page). Again
| we malloc more space - this time 4 pages worth. Count is still not
| reset, but now we have 2 pages worth of space to use and the operations
| succeed. When the buffer is copied to user space, we have a whole
| bunch of garbage, followed by the correct information.
|
| On the surface, it would appear that the right thing to do is set
| "count" to zero at the end of the while loop.
| diff -urN linux-2.4.20/fs/seq_file.c linux-2.4.20-patched/fs/seq_file.c
| --- linux-2.4.20/fs/seq_file.c Sat Nov 17 20:16:22 2001
| +++ linux-2.4.20-patched/fs/seq_file.c Fri May 2 14:16:41 2003
| @@ -94,6 +94,7 @@
| m->buf = kmalloc(m->size <<= 1, GFP_KERNEL);
| if (!m->buf)
| goto Enomem;
| + m->count = 0;
| }
| m->op->stop(m, p);
| goto Done;
|
Correct patch is already in 2.4.21-rc1 (and likely before -rc1).
--
~Randy
prev parent reply other threads:[~2003-05-05 16:58 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2003-05-05 16:58 Jonathan Brassow
2003-05-05 17:06 ` Randy.Dunlap [this message]
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=20030505100620.4dccbc9b.rddunlap@osdl.org \
--to=rddunlap@osdl.org \
--cc=brassow@sistina.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
all inboxes | Powered by JetHome®