From: Jeremy Fitzhardinge <jeremy@goop.org>
To: "Jun Zhu (Intern)" <Jun.Zhu@citrix.com>
Cc: "xen-devel@lists.xensource.com" <xen-devel@lists.xensource.com>
Subject: Re: A bug in Xenbus driver
Date: Wed, 25 Aug 2010 12:11:27 -0700 [thread overview]
Message-ID: <4C756ADF.1000207@goop.org> (raw)
In-Reply-To: <433DDF91DFB08148BAD3FDB6FDDA314C9F35F3BB47@LONPMAILBOX01.citrite.net>
On 08/25/2010 11:57 AM, Jun Zhu (Intern) wrote:
> Hi all,
>
> I think this is a serious bug, existing in the pvops 2.6.31.13 (also existing in linux 2.6.35);
>
> In the xenbus driver (drivers/xen/xenfs/xenbus.c), the function of xenbus_file_read has a section of source code like this:
> if (ret != sz) {
> if (i == 0)
> i = -EFAULT;
> goto out;
> }
> /* Clear out buffer if it has been consumed */
> if (rb->cons == rb->len) {
> list_del(&rb->list);
> kfree(rb);
> if (list_empty(&u->read_buffers))
> break;
> rb = list_entry(u->read_buffers.next,
> struct read_buffer, list);
> }
> It should be like this:
> // if (ret != sz) {
> if (ret != 0) {
> if (i == 0)
> i = -EFAULT;
> goto out;
> }
> This bug makes the read_buffer not be cleared most of the time. If the xenstore client uses PTHREAD to create a thread to receive reply message, the problem will incur. The new thread can not read what it wants to read, since the list is not empty.
>
> I found this problem from the xenstore client xs_watch function. xs_watch creates the new thread on demand. So I recommend that in the function of read_message(xen/tools/xenstore/xs.c), if using thread to receive message, in the case of read fault, it should signal to the listener and print out the error.
I don't follow your description of the problem. The full context of the
code in question is this:
ret = copy_to_user(ubuf + i, &rb->msg[rb->cons], sz);
i += sz - ret;
rb->cons += sz - ret;
if (ret != sz) {
if (i == 0)
i = -EFAULT;
goto out;
}
copy_to_user returns the number of uncopied bytes, so if ret != sz, then
some part of the data was not copied due to a memory fault problem.
Changing the test to "ret != 0" means that it will return a partial
result (at the end of a page, for example) without reporting an error,
and discarding the uncopied data.
If you're hitting the "ret != sz" case often, then I think there's some
problem with the memory you're passing into read() (either the buffer
itself, or the size argument).
Thanks,
J
next prev parent reply other threads:[~2010-08-25 19:11 UTC|newest]
Thread overview: 8+ messages / expand[flat|nested] mbox.gz Atom feed top
2010-08-25 18:57 A bug in Xenbus driver Jun Zhu (Intern)
2010-08-25 19:11 ` Jeremy Fitzhardinge [this message]
2010-08-25 19:15 ` Jeremy Fitzhardinge
2010-08-25 19:19 ` Jeremy Fitzhardinge
2010-08-26 8:25 ` Jun Zhu (Intern)
2010-08-26 16:34 ` Jeremy Fitzhardinge
2010-08-27 11:03 ` Jun Zhu (Intern)
2010-08-27 12:38 ` Jun Zhu (Intern)
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=4C756ADF.1000207@goop.org \
--to=jeremy@goop.org \
--cc=Jun.Zhu@citrix.com \
--cc=xen-devel@lists.xensource.com \
/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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.