tools/libxc: Fix issues with libxc and Xen having different featureset lengths
authorAndrew Cooper <andrew.cooper3@citrix.com>
Thu, 29 Nov 2018 18:10:38 +0000 (18:10 +0000)
committerAndrew Cooper <andrew.cooper3@citrix.com>
Fri, 30 Nov 2018 14:21:12 +0000 (14:21 +0000)
commitc393b64dcee6684da25257b033148740cb6d7ff0
tree1067d0abd0d5d220ec66d6f99d83cd754ad4415e
parent89bfc1effdf1aaaaa10b7c9f3d584c8a431dcd65
tools/libxc: Fix issues with libxc and Xen having different featureset lengths

In almost all cases, Xen and libxc will agree on the featureset length,
because they are built from the same source.

However, there are circumstances (e.g. security hotfixes) where the featureset
gets longer and dom0 will, after installing updates, be running with an old
Xen but new libxc.  Despite writing the code with this scenario in mind, there
were some bugs.

First, xen-cpuid's get_featureset() erroneously allocates a buffer based on
Xen's featureset length, but records libxc's length, which may be longer.

In this situation, the hypercall bounce buffer code reads/writes the recorded
length, which is beyond the end of the allocated object, and a later free()
encounters corrupt heap metadata.  Fix this by recording the same length that
we allocate.

Secondly, get_cpuid_domain_info() has a related bug when the passed-in
featureset is a different length to libxc's.

A large amount of the libxc cpuid functionality depends on info->featureset
being as long as expected, and it is allocated appropriately.  However, in the
case that a shorter external featureset is passed in, the logic to check for
trailing nonzero bits may read off the end of it.  Rework the logic to use the
correct upper bound.

In addition, leave a comment next to the fields in struct cpuid_domain_info
explaining the relationship between the various lengths, and how to cope with
different lengths.

Signed-off-by: Andrew Cooper <andrew.cooper3@citrix.com>
Reviewed-by: Jan Beulich <jbeulich@suse.com>
Acked-by: Wei Liu <wei.liu2@citrix.com>
tools/libxc/xc_cpuid_x86.c
tools/misc/xen-cpuid.c