All of lore.kernel.org
 help / color / mirror / Atom feed
From: Ian Campbell <Ian.Campbell@citrix.com>
To: Wei Liu <wei.liu2@citrix.com>
Cc: xen-devel@lists.xen.org, ayush ruia <ayushruia@gmail.com>
Subject: Re: Possible bug in tools/libxl/libxl.c -- Variable passed by reference not set in one possible case
Date: Fri, 10 Oct 2014 12:30:30 +0100	[thread overview]
Message-ID: <1412940630.27111.10.camel@citrix.com> (raw)
In-Reply-To: <20141010105429.GA6945@zion.uk.xensource.com>

On Fri, 2014-10-10 at 11:54 +0100, Wei Liu wrote:
> On Fri, Oct 10, 2014 at 10:30:06AM +0100, Ian Campbell wrote:
> [...]
> > > 
> > > The way the callers use it prevents the issue you described from
> > > happening -- they only call this function when they can't read those
> > > values from xenstore -- if those values are already in xenstore this
> > > function won't get called.
> > 
> > At least the callers in libxl__get_free_memory_slack and
> > libxl__get_memory_target look to be racy with someone else writing these
> > nodes to me.
> > 
> 
>  libxl__fill_dom0_memory_info uses transaction already, that should
>  avoid race?

I don't think so.

The caller is:
	read target (perhaps in a transaction)
	if (!target)	
		***
		if ( call fill_dom0_memory(&target) < 0 ) /* uses a transaction */
			return
		use target
	}

If another process dives in at *** and writes target then
fill_dom0_memory will return 0 but not initialise target, but the caller
will still (potentially) use it.

Even if it somehow transpires that through some careful coding in the
caller the use target never actually happens because of some other
reason it way to opaque as it is currently written.

I think the initialisation of current_target_memkb to zero in 
libxl_set_memory_target might be masking the issue here, preventing the
caller from (legitimately) complaining about a variable which is used
without initialisation

> > libxl_set_memory_target is a bit unclear but the fact that it ends the
> > transaction right before it calls libxl__fill_dom0_memory_info seems
> > suspicious.
> > 
> 
> To avoid having a transaction inside another transaction?

I suppose that might have been what the author was thinking, bit it
means that help if you are relying on that transaction to provide
atomicity you lose.

Ian

  reply	other threads:[~2014-10-10 11:30 UTC|newest]

Thread overview: 14+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2014-10-10  1:07 Possible bug in tools/libxl/libxl.c -- Variable passed by reference not set in one possible case ayush ruia
2014-10-10  1:28 ` ayush ruia
2014-10-10  9:06   ` Wei Liu
2014-10-10  9:17     ` Ian Campbell
2014-10-10  9:24       ` Wei Liu
2014-10-10  9:30         ` Ian Campbell
2014-10-10 10:54           ` Wei Liu
2014-10-10 11:30             ` Ian Campbell [this message]
2014-10-10 12:43               ` ayush ruia
2014-10-10 13:58                 ` Wei Liu
2014-10-10 14:47                   ` ayush ruia
2014-10-10 15:27                     ` Ian Campbell
2014-10-10 16:41                       ` ayush ruia
2014-10-10 16:55                         ` Ian Campbell

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=1412940630.27111.10.camel@citrix.com \
    --to=ian.campbell@citrix.com \
    --cc=ayushruia@gmail.com \
    --cc=wei.liu2@citrix.com \
    --cc=xen-devel@lists.xen.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 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.