tools/libxc: Initialise parameters in map_p2m_list() for error paths
PATCH 1/1 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.
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.
---
CC: Ian Campbell <[email protected]>
CC: Ian Jackson <[email protected]>
CC: Wei Liu <[email protected]>
CC: Juergen Gross <[email protected]>
--- tools/libxc/xc_sr_save_x86_pv.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
tools/libxc/xc_sr_save_x86_pv.c +2 -2
@@ -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);
Signature · 1 line
2.1.4
Quoted 11 lines · Andrew Cooper
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 <[email protected]>
Quoted 28 lines
---
CC: Ian Campbell <[email protected]>
CC: Ian Jackson <[email protected]>
CC: Wei Liu <[email protected]>
CC: Juergen Gross <[email protected]>--- tools/libxc/xc_sr_save_x86_pv.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)tools/libxc/xc_sr_save_x86_pv.c +2
-2@@ -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);Signature · 1 line
2.1.4
Quoted 6 lines · Andrew Cooper
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.
Quoted 30 lines
Initialise the parameters to safe default to make the function more robust.
Signed-off-by Andrew Cooper <[email protected]>---
CC: Ian Campbell <[email protected]>
CC: Ian Jackson <[email protected]>
CC: Wei Liu <[email protected]>
CC: Juergen Gross <[email protected]>
---
tools/libxc/xc_sr_save_x86_pv.c | 4 ++--1 file changed, 2 insertions(+), 2 deletions(-)tools/libxc/xc_sr_save_x86_pv.c +2
-2@@ -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;
Quoted 3 lines
int rc = -1;
p2m_mfn =cr3_to_mfn(ctx, p2m_cr3);
_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xen.org/xen-devel
Quoted 11 lines · Ian Campbell
Quoted 6 lines · Andrew Cooper
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.
Quoted 3 lines
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
Quoted 10 lines · Ian Campbell
Quoted 6 lines · Andrew Cooper
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.
Quoted 4 lines
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.
Quoted 23 lines · Andrew Cooper
Quoted 5 lines · Ian Campbell
Quoted 4 lines · Andrew Cooper
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.
Quoted 7 lines
Quoted 3 lines
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.
Quoted 6 lines
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.
Quoted 3 lines
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).
Quoted 1 line
All that is needed is an adjustment to the commit message IMO:
I can live with this.
Quoted 4 lines
---8<---
tools/libxc: Initialise parameters inmap_p2m_list()for error paths
Quoted 9 lines
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 <[email protected]>
_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xen.org/xen-devel
Quoted 11 lines · Andrew Cooper
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 <[email protected]>
Thanks for catching this.
Juergen
Quoted 26 lines
---
CC: Ian Campbell <[email protected]>
CC: Ian Jackson <[email protected]>
CC: Wei Liu <[email protected]>
CC: Juergen Gross <[email protected]>--- tools/libxc/xc_sr_save_x86_pv.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)tools/libxc/xc_sr_save_x86_pv.c +2
-2@@ -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);