On Wed, Jun 14, 2023 at 09:02:56AM +0200, Jan Beulich wrote:
> This in particular allows to drop a dead assignment to "ptes" from near
> the end of the function.
>
> Coverity ID: 1532314
> Fixes: bd7a29c3d0b9 ("tools/libs/ctrl: fix xc_core_arch_map_p2m() to support
> linear p2m table")
> Signed-off-by: Jan Beulich <[email protected]>
> ---
> v2: Much bigger change to limit the scope of "ptes" and other variables.
The change of scope of all variables isn't too hard to review with
--word-diff option and they all look fine.
> --- a/tools/libs/guest/xg_core_x86.c
> +++ b/tools/libs/guest/xg_core_x86.c
> @@ -169,18 +169,21 @@ xc_core_arch_map_p2m_list_rw(xc_interfac
> if ( !mfns )
> {
> ERROR("Cannot allocate memory for array of %u mfns", idx);
> + out_unmap:
> + munmap(ptes, n_pages * PAGE_SIZE);
> goto out;
> }
>
I guess it's not that great to have the label out_unmap in the middle of
the for loop (at least it's near the beginning), but at least that mean
that the mapping need to be gone once out of the loop. So if someone
edit the for loop and introduce a `goto out` instead of `goto out_unmap`
there's just a potential leak rather than potential use-after-free or
double-free, so I guess that better.
So:
Acked-by: Anthony PERARD <[email protected]>
Cheers,
--
Anthony PERARD