From: Ian Campbell <Ian.Campbell@citrix.com>
To: Ian Jackson <Ian.Jackson@eu.citrix.com>
Cc: Roger Pau Monne <roger.pau@citrix.com>,
Marek Marczykowski <marmarek@invisiblethingslab.com>,
"xen-devel@lists.xen.org" <xen-devel@lists.xen.org>
Subject: Re: [PATCH RESEND] libxl: Avoid realloc(, 0) when libxl__xs_directory returns empty list
Date: Tue, 12 Nov 2013 17:31:25 +0000 [thread overview]
Message-ID: <1384277485.10204.107.camel@kazak.uk.xensource.com> (raw)
In-Reply-To: <21122.25647.129932.90020@mariner.uk.xensource.com>
On Tue, 2013-11-12 at 17:23 +0000, Ian Jackson wrote:
> Ian Jackson writes ("Re: [Xen-devel] xl network-attach SEGV in 4.2 and 4.1"):
> > Thanks for pointing this out. The root cause is the expectation that
> > libxl__xs_directory won't return a non-null list but set *nb to 0.
> >
> > I found some occurrences of this bug in (xen-unstable) staging.
> > See patch below, which should probably go into 4.1 and 4.2.
>
> Ping.
I could have sworn this went in...
>
> Ian.
>
> From ea275c0e29299a2399aa7814116d68bfdaeb21c1 Mon Sep 17 00:00:00 2001
> From: Ian Jackson <ian.jackson@eu.citrix.com>
> Date: Thu, 18 Apr 2013 16:27:46 +0100
> Subject: [PATCH] libxl: Avoid realloc(,0) when libxl__xs_directory returns
> empty list
> MIME-Version: 1.0
> Content-Type: text/plain; charset=UTF-8
> Content-Transfer-Encoding: 8bit
>
> If the named path is a leaf node, libxl__xs_directory can succeed,
> returning non-null, but set *nb to 0.
>
> In three places in libxl this may result in a zero size argument being
> passed to malloc() or realloc(), which is not adviseable.
I thought it was strictly speaking fine, but I can see why it would be
best to avoid.
> Signed-off-by: Ian Jackson <Ian.Jackson@eu.citrix.com>
> Acked-by: Roger Pau Monné <roger.pau@citrix.com>
Acked-by: Ian Campbell <ian.campbell@citrix.com>
> ---
> tools/libxl/libxl.c | 6 +++---
> 1 file changed, 3 insertions(+), 3 deletions(-)
>
> diff --git a/tools/libxl/libxl.c b/tools/libxl/libxl.c
> index 0f0f56c..887e0ca 100644
> --- a/tools/libxl/libxl.c
> +++ b/tools/libxl/libxl.c
> @@ -1864,7 +1864,7 @@ libxl_device_vtpm *libxl_device_vtpm_list(libxl_ctx *ctx, uint32_t domid, int *n
>
> fe_path = libxl__sprintf(gc, "%s/device/vtpm", libxl__xs_get_dompath(gc, domid));
> dir = libxl__xs_directory(gc, XBT_NULL, fe_path, &ndirs);
> - if(dir) {
> + if (dir && ndirs) {
> vtpms = malloc(sizeof(*vtpms) * ndirs);
> libxl_device_vtpm* vtpm;
> libxl_device_vtpm* end = vtpms + ndirs;
> @@ -2371,7 +2371,7 @@ static int libxl__append_disk_list_of_type(libxl__gc *gc,
> be_path = libxl__sprintf(gc, "%s/backend/%s/%d",
> libxl__xs_get_dompath(gc, 0), type, domid);
> dir = libxl__xs_directory(gc, XBT_NULL, be_path, &n);
> - if (dir) {
> + if (dir && n) {
> libxl_device_disk *tmp;
> tmp = realloc(*disks, sizeof (libxl_device_disk) * (*ndisks + n));
> if (tmp == NULL)
> @@ -3060,7 +3060,7 @@ static int libxl__append_nic_list_of_type(libxl__gc *gc,
> be_path = libxl__sprintf(gc, "%s/backend/%s/%d",
> libxl__xs_get_dompath(gc, 0), type, domid);
> dir = libxl__xs_directory(gc, XBT_NULL, be_path, &n);
> - if (dir) {
> + if (dir && n) {
> libxl_device_nic *tmp;
> tmp = realloc(*nics, sizeof (libxl_device_nic) * (*nnics + n));
> if (tmp == NULL)
_______________________________________________
Xen-devel mailing list
Xen-devel@lists.xen.org
http://lists.xen.org/xen-devel
next prev parent reply other threads:[~2013-11-12 17:31 UTC|newest]
Thread overview: 11+ messages / expand[flat|nested] mbox.gz Atom feed top
2013-04-17 2:49 xl network-attach SEGV in 4.2 and 4.1 Marek Marczykowski
2013-04-17 8:43 ` Ian Campbell
2013-04-18 16:01 ` Ian Jackson
2013-04-18 16:46 ` xl network-attach SEGV in 4.2 and 4.1 [and 1 more messages] Ian Jackson
2013-04-19 7:12 ` Jan Beulich
2013-04-22 9:49 ` Ian Jackson
2013-04-18 18:58 ` xl network-attach SEGV in 4.2 and 4.1 Roger Pau Monné
2013-11-12 17:23 ` [PATCH RESEND] libxl: Avoid realloc(, 0) when libxl__xs_directory returns empty list Ian Jackson
2013-11-12 17:31 ` Ian Campbell [this message]
2013-11-12 17:57 ` Ian Jackson
2013-11-25 13:55 ` Ian Jackson
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=1384277485.10204.107.camel@kazak.uk.xensource.com \
--to=ian.campbell@citrix.com \
--cc=Ian.Jackson@eu.citrix.com \
--cc=marmarek@invisiblethingslab.com \
--cc=roger.pau@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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).