All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] tools/libxc: Initialise parameters in map_p2m_list() for error paths
@ 2016-01-07 14:55 Andrew Cooper
  2016-01-07 15:04 ` Wei Liu
                   ` (2 more replies)
  0 siblings, 3 replies; 7+ messages in thread
From: Andrew Cooper @ 2016-01-07 14:55 UTC (permalink / raw)
  To: Xen-devel
  Cc: Juergen Gross, Andrew Cooper, Ian Jackson, Ian Campbell, Wei Liu

c/s 7bf7458 "libxc: support of linear p2m list for migration of
pv-domains" breaks compilation on CentOS 7 because of 'ptes' being
possibly uninitialised after the 'err:' label.

The migration will fail early for conditions which would cause the for()
loop not to run, but the compiler doesn't know this.

Initialise the parameters to safe default to make the function more
robust.

Signed-off-by: Andrew Cooper <andrew.cooper3@citrix.com>
---
CC: Ian Campbell <Ian.Campbell@citrix.com>
CC: Ian Jackson <Ian.Jackson@eu.citrix.com>
CC: Wei Liu <wei.liu2@citrix.com>
CC: Juergen Gross <jgross@suse.com>
---
 tools/libxc/xc_sr_save_x86_pv.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/tools/libxc/xc_sr_save_x86_pv.c b/tools/libxc/xc_sr_save_x86_pv.c
index 4deb58f..ab4bbe0 100644
--- a/tools/libxc/xc_sr_save_x86_pv.c
+++ b/tools/libxc/xc_sr_save_x86_pv.c
@@ -316,9 +316,9 @@ static int map_p2m_list(struct xc_sr_context *ctx, uint64_t p2m_cr3)
     xc_interface *xch = ctx->xch;
     xen_vaddr_t p2m_vaddr, p2m_end, mask, off;
     xen_pfn_t p2m_mfn, mfn, saved_mfn, max_pfn;
-    uint64_t *ptes;
+    uint64_t *ptes = NULL;
     xen_pfn_t *mfns;
-    unsigned fpp, n_pages, level, shift, idx_start, idx_end, idx, saved_idx;
+    unsigned fpp, n_pages = 0, level, shift, idx_start, idx_end, idx, saved_idx;
     int rc = -1;
 
     p2m_mfn = cr3_to_mfn(ctx, p2m_cr3);
-- 
2.1.4

^ permalink raw reply related	[flat|nested] 7+ messages in thread

* Re: [PATCH] tools/libxc: Initialise parameters in map_p2m_list() for error paths
  2016-01-07 14:55 [PATCH] tools/libxc: Initialise parameters in map_p2m_list() for error paths Andrew Cooper
@ 2016-01-07 15:04 ` Wei Liu
  2016-01-07 15:06 ` Ian Campbell
  2016-01-07 15:06 ` Juergen Gross
  2 siblings, 0 replies; 7+ messages in thread
From: Wei Liu @ 2016-01-07 15:04 UTC (permalink / raw)
  To: Andrew Cooper
  Cc: Juergen Gross, Wei Liu, Ian Jackson, Ian Campbell, Xen-devel

On Thu, Jan 07, 2016 at 02:55:30PM +0000, Andrew Cooper wrote:
> c/s 7bf7458 "libxc: support of linear p2m list for migration of
> pv-domains" breaks compilation on CentOS 7 because of 'ptes' being
> possibly uninitialised after the 'err:' label.
> 
> The migration will fail early for conditions which would cause the for()
> loop not to run, but the compiler doesn't know this.
> 
> Initialise the parameters to safe default to make the function more
> robust.
> 
> Signed-off-by: Andrew Cooper <andrew.cooper3@citrix.com>

Acked-by: Wei Liu <wei.liu2@citrix.com>

> ---
> CC: Ian Campbell <Ian.Campbell@citrix.com>
> CC: Ian Jackson <Ian.Jackson@eu.citrix.com>
> CC: Wei Liu <wei.liu2@citrix.com>
> CC: Juergen Gross <jgross@suse.com>
> ---
>  tools/libxc/xc_sr_save_x86_pv.c | 4 ++--
>  1 file changed, 2 insertions(+), 2 deletions(-)
> 
> diff --git a/tools/libxc/xc_sr_save_x86_pv.c b/tools/libxc/xc_sr_save_x86_pv.c
> index 4deb58f..ab4bbe0 100644
> --- a/tools/libxc/xc_sr_save_x86_pv.c
> +++ b/tools/libxc/xc_sr_save_x86_pv.c
> @@ -316,9 +316,9 @@ static int map_p2m_list(struct xc_sr_context *ctx, uint64_t p2m_cr3)
>      xc_interface *xch = ctx->xch;
>      xen_vaddr_t p2m_vaddr, p2m_end, mask, off;
>      xen_pfn_t p2m_mfn, mfn, saved_mfn, max_pfn;
> -    uint64_t *ptes;
> +    uint64_t *ptes = NULL;
>      xen_pfn_t *mfns;
> -    unsigned fpp, n_pages, level, shift, idx_start, idx_end, idx, saved_idx;
> +    unsigned fpp, n_pages = 0, level, shift, idx_start, idx_end, idx, saved_idx;
>      int rc = -1;
>  
>      p2m_mfn = cr3_to_mfn(ctx, p2m_cr3);
> -- 
> 2.1.4
> 

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: [PATCH] tools/libxc: Initialise parameters in map_p2m_list() for error paths
  2016-01-07 14:55 [PATCH] tools/libxc: Initialise parameters in map_p2m_list() for error paths Andrew Cooper
  2016-01-07 15:04 ` Wei Liu
@ 2016-01-07 15:06 ` Ian Campbell
  2016-01-07 15:19   ` Juergen Gross
  2016-01-07 15:24   ` Andrew Cooper
  2016-01-07 15:06 ` Juergen Gross
  2 siblings, 2 replies; 7+ messages in thread
From: Ian Campbell @ 2016-01-07 15:06 UTC (permalink / raw)
  To: Andrew Cooper, Xen-devel; +Cc: Juergen Gross, Wei Liu, Ian Jackson

On Thu, 2016-01-07 at 14:55 +0000, Andrew Cooper wrote:
> c/s 7bf7458 "libxc: support of linear p2m list for migration of
> pv-domains" breaks compilation on CentOS 7 because of 'ptes' being
> possibly uninitialised after the 'err:' label.
> 
> The migration will fail early for conditions which would cause the for()
> loop not to run, but the compiler doesn't know this.

Isn't the issue the malloc goto err path before the loop? Looks like that
should have the error behaviour from the earlier half of the function
rather than the latter.

There might also be a path if ctx->x86_pv.levels == 0, in which case the
loop will never run, that's the sort of thing which could be checked (or
even perhaps asserted) on entry to the function.

> Initialise the parameters to safe default to make the function more
> robust.
> 
> Signed-off-by: Andrew Cooper <andrew.cooper3@citrix.com>
> ---
> CC: Ian Campbell <Ian.Campbell@citrix.com>
> CC: Ian Jackson <Ian.Jackson@eu.citrix.com>
> CC: Wei Liu <wei.liu2@citrix.com>
> CC: Juergen Gross <jgross@suse.com>
> ---
>  tools/libxc/xc_sr_save_x86_pv.c | 4 ++--
>  1 file changed, 2 insertions(+), 2 deletions(-)
> 
> diff --git a/tools/libxc/xc_sr_save_x86_pv.c
> b/tools/libxc/xc_sr_save_x86_pv.c
> index 4deb58f..ab4bbe0 100644
> --- a/tools/libxc/xc_sr_save_x86_pv.c
> +++ b/tools/libxc/xc_sr_save_x86_pv.c
> @@ -316,9 +316,9 @@ static int map_p2m_list(struct xc_sr_context *ctx,
> uint64_t p2m_cr3)
>      xc_interface *xch = ctx->xch;
>      xen_vaddr_t p2m_vaddr, p2m_end, mask, off;
>      xen_pfn_t p2m_mfn, mfn, saved_mfn, max_pfn;
> -    uint64_t *ptes;
> +    uint64_t *ptes = NULL;
>      xen_pfn_t *mfns;
> -    unsigned fpp, n_pages, level, shift, idx_start, idx_end, idx,
> saved_idx;
> +    unsigned fpp, n_pages = 0, level, shift, idx_start, idx_end, idx,
> saved_idx;
>      int rc = -1;
>  
>      p2m_mfn = cr3_to_mfn(ctx, p2m_cr3);

_______________________________________________
Xen-devel mailing list
Xen-devel@lists.xen.org
http://lists.xen.org/xen-devel

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: [PATCH] tools/libxc: Initialise parameters in map_p2m_list() for error paths
  2016-01-07 14:55 [PATCH] tools/libxc: Initialise parameters in map_p2m_list() for error paths Andrew Cooper
  2016-01-07 15:04 ` Wei Liu
  2016-01-07 15:06 ` Ian Campbell
@ 2016-01-07 15:06 ` Juergen Gross
  2 siblings, 0 replies; 7+ messages in thread
From: Juergen Gross @ 2016-01-07 15:06 UTC (permalink / raw)
  To: Andrew Cooper, Xen-devel; +Cc: Wei Liu, Ian Jackson, Ian Campbell

On 07/01/16 15:55, Andrew Cooper wrote:
> c/s 7bf7458 "libxc: support of linear p2m list for migration of
> pv-domains" breaks compilation on CentOS 7 because of 'ptes' being
> possibly uninitialised after the 'err:' label.
> 
> The migration will fail early for conditions which would cause the for()
> loop not to run, but the compiler doesn't know this.
> 
> Initialise the parameters to safe default to make the function more
> robust.
> 
> Signed-off-by: Andrew Cooper <andrew.cooper3@citrix.com>

Acked-by: Juergen Gross <jgross@suse.com>

Thanks for catching this.

Juergen

> ---
> CC: Ian Campbell <Ian.Campbell@citrix.com>
> CC: Ian Jackson <Ian.Jackson@eu.citrix.com>
> CC: Wei Liu <wei.liu2@citrix.com>
> CC: Juergen Gross <jgross@suse.com>
> ---
>  tools/libxc/xc_sr_save_x86_pv.c | 4 ++--
>  1 file changed, 2 insertions(+), 2 deletions(-)
> 
> diff --git a/tools/libxc/xc_sr_save_x86_pv.c b/tools/libxc/xc_sr_save_x86_pv.c
> index 4deb58f..ab4bbe0 100644
> --- a/tools/libxc/xc_sr_save_x86_pv.c
> +++ b/tools/libxc/xc_sr_save_x86_pv.c
> @@ -316,9 +316,9 @@ static int map_p2m_list(struct xc_sr_context *ctx, uint64_t p2m_cr3)
>      xc_interface *xch = ctx->xch;
>      xen_vaddr_t p2m_vaddr, p2m_end, mask, off;
>      xen_pfn_t p2m_mfn, mfn, saved_mfn, max_pfn;
> -    uint64_t *ptes;
> +    uint64_t *ptes = NULL;
>      xen_pfn_t *mfns;
> -    unsigned fpp, n_pages, level, shift, idx_start, idx_end, idx, saved_idx;
> +    unsigned fpp, n_pages = 0, level, shift, idx_start, idx_end, idx, saved_idx;
>      int rc = -1;
>  
>      p2m_mfn = cr3_to_mfn(ctx, p2m_cr3);
> 

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: [PATCH] tools/libxc: Initialise parameters in map_p2m_list() for error paths
  2016-01-07 15:06 ` Ian Campbell
@ 2016-01-07 15:19   ` Juergen Gross
  2016-01-07 15:24   ` Andrew Cooper
  1 sibling, 0 replies; 7+ messages in thread
From: Juergen Gross @ 2016-01-07 15:19 UTC (permalink / raw)
  To: Ian Campbell, Andrew Cooper, Xen-devel; +Cc: Wei Liu, Ian Jackson

On 07/01/16 16:06, Ian Campbell wrote:
> On Thu, 2016-01-07 at 14:55 +0000, Andrew Cooper wrote:
>> c/s 7bf7458 "libxc: support of linear p2m list for migration of
>> pv-domains" breaks compilation on CentOS 7 because of 'ptes' being
>> possibly uninitialised after the 'err:' label.
>>
>> The migration will fail early for conditions which would cause the for()
>> loop not to run, but the compiler doesn't know this.
> 
> Isn't the issue the malloc goto err path before the loop? Looks like that
> should have the error behaviour from the earlier half of the function
> rather than the latter.

Yes to both. OTOH with Andrew's patch the code behaves correctly.

> There might also be a path if ctx->x86_pv.levels == 0, in which case the
> loop will never run, that's the sort of thing which could be checked (or
> even perhaps asserted) on entry to the function.

As there is no function vector involved between setting levels and
consuming it I doubt this makes really sense.


Juergen

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: [PATCH] tools/libxc: Initialise parameters in map_p2m_list() for error paths
  2016-01-07 15:06 ` Ian Campbell
  2016-01-07 15:19   ` Juergen Gross
@ 2016-01-07 15:24   ` Andrew Cooper
  2016-01-07 15:35     ` Ian Campbell
  1 sibling, 1 reply; 7+ messages in thread
From: Andrew Cooper @ 2016-01-07 15:24 UTC (permalink / raw)
  To: Ian Campbell, Xen-devel; +Cc: Juergen Gross, Wei Liu, Ian Jackson

On 07/01/16 15:06, Ian Campbell wrote:
> On Thu, 2016-01-07 at 14:55 +0000, Andrew Cooper wrote:
>> c/s 7bf7458 "libxc: support of linear p2m list for migration of
>> pv-domains" breaks compilation on CentOS 7 because of 'ptes' being
>> possibly uninitialised after the 'err:' label.
>>
>> The migration will fail early for conditions which would cause the for()
>> loop not to run, but the compiler doesn't know this.
> Isn't the issue the malloc goto err path before the loop? Looks like that
> should have the error behaviour from the earlier half of the function
> rather than the latter.

So it is - I missed that one when looking the options.

>
> There might also be a path if ctx->x86_pv.levels == 0, in which case the
> loop will never run, that's the sort of thing which could be checked (or
> even perhaps asserted) on entry to the function.

I don't think asserting details like this is a scalable options.  Also,
it doesn't help the compilation error if someone ends up disabling
assert() by playing with NDEBUG.

All that is needed is an adjustment to the commit message IMO:

---8<---
tools/libxc: Initialise parameters in map_p2m_list() for error paths

c/s 7bf7458 "libxc: support of linear p2m list for migration of
pv-domains" breaks compilation on CentOS 7 because of 'ptes' being
possibly uninitialised after the 'err:' label.

Indeed, the malloc() failure path would end using 'ptes' while
uninitialised.  Initialise the parameters to safe defaults.

Signed-off-by: Andrew Cooper <andrew.cooper3@citrix.com>

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: [PATCH] tools/libxc: Initialise parameters in map_p2m_list() for error paths
  2016-01-07 15:24   ` Andrew Cooper
@ 2016-01-07 15:35     ` Ian Campbell
  0 siblings, 0 replies; 7+ messages in thread
From: Ian Campbell @ 2016-01-07 15:35 UTC (permalink / raw)
  To: Andrew Cooper, Xen-devel; +Cc: Juergen Gross, Wei Liu, Ian Jackson

On Thu, 2016-01-07 at 15:24 +0000, Andrew Cooper wrote:
> On 07/01/16 15:06, Ian Campbell wrote:
> > On Thu, 2016-01-07 at 14:55 +0000, Andrew Cooper wrote:
> > > c/s 7bf7458 "libxc: support of linear p2m list for migration of
> > > pv-domains" breaks compilation on CentOS 7 because of 'ptes' being
> > > possibly uninitialised after the 'err:' label.
> > > 
> > > The migration will fail early for conditions which would cause the
> > > for()
> > > loop not to run, but the compiler doesn't know this.
> > Isn't the issue the malloc goto err path before the loop? Looks like
> > that
> > should have the error behaviour from the earlier half of the function
> > rather than the latter.
> 
> So it is - I missed that one when looking the options.
> 
> > 
> > There might also be a path if ctx->x86_pv.levels == 0, in which case
> > the
> > loop will never run, that's the sort of thing which could be checked
> > (or
> > even perhaps asserted) on entry to the function.
> 
> I don't think asserting details like this is a scalable options.  Also,
> it doesn't help the compilation error if someone ends up disabling
> assert() by playing with NDEBUG.

It could be an error return instead (which is what I meant to suggest
without the parenthetical).

> All that is needed is an adjustment to the commit message IMO:

I can live with this.

> 
> ---8<---
> tools/libxc: Initialise parameters in map_p2m_list() for error paths
> 
> c/s 7bf7458 "libxc: support of linear p2m list for migration of
> pv-domains" breaks compilation on CentOS 7 because of 'ptes' being
> possibly uninitialised after the 'err:' label.
> 
> Indeed, the malloc() failure path would end using 'ptes' while
> uninitialised.  Initialise the parameters to safe defaults.
> 
> Signed-off-by: Andrew Cooper <andrew.cooper3@citrix.com>
> 

_______________________________________________
Xen-devel mailing list
Xen-devel@lists.xen.org
http://lists.xen.org/xen-devel

^ permalink raw reply	[flat|nested] 7+ messages in thread

end of thread, other threads:[~2016-01-07 15:35 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2016-01-07 14:55 [PATCH] tools/libxc: Initialise parameters in map_p2m_list() for error paths Andrew Cooper
2016-01-07 15:04 ` Wei Liu
2016-01-07 15:06 ` Ian Campbell
2016-01-07 15:19   ` Juergen Gross
2016-01-07 15:24   ` Andrew Cooper
2016-01-07 15:35     ` Ian Campbell
2016-01-07 15:06 ` Juergen Gross

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.