[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [PATCH 11/13] libxl: split logic to parse user provided CPUID features


  • To: Roger Pau Monne <roger.pau@xxxxxxxxxx>
  • From: Jan Beulich <jbeulich@xxxxxxxx>
  • Date: Thu, 6 Jul 2023 13:09:19 +0200
  • Arc-authentication-results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=suse.com; dmarc=pass action=none header.from=suse.com; dkim=pass header.d=suse.com; arc=none
  • Arc-message-signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=1EDqj7iwfxfnLB0x6opR63ESaVOE0wZE6U9/F73SJw8=; b=VPEdw1Ya9YM/kGFNP4wjW7+b23h53Rd8iHQyBc1omaBx1f0CFJ63FyWFIy1ZoRByxbR+e6ixax1+2cw6Y3+HCTLSHX84nfn/5w454ienAsaIdyFtN+FsPsIIQhebOP9R8KUQl5X2XtldpYa+jjg5snafMoUi3R4r17Tz6DJH+uP5XBHsaRPzQpl/aCHf3MqdIvhv4elgQAkPtsfJSz23OVxfUY4QMqk9uUXt/cW2/HsDGpismmJojXviQk5WyCTZ96GJhmQMga+YlsKdTsM0n0pxDHZpal7iXQmgNSxGQXNx2qtzqUl15ogqVU9sKjYIiy9Kou1jxCop9dXp/MgH0g==
  • Arc-seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=n/fKdRH17+eC4Sad4U+DuECg7Jn3K1u0ef1a2ta/GVbNzHvqxxSMMGvkd4/D2oWy+ohj4SBdqVCr07nnRPYkxm+lbNVzHcLK5wYDo9Eyn78ZjSWRdMB9mA+IXP+fDPRfVNTE6xcDtlbRLqRDcjoObd8Ve2qohLcZX+zMF4aC8RCG85N/+kiSBwkrYhJXG98BECo9sCW2qTk+VuND4aBkCG8aw+XCdwKZCBWeK8JJ1qifC36qts79ri+SOm6VWVgweWYHd9SgiQOSTPYdq+77XvhppXRN1LrQku1tQLUBzzvMIy3T930SYtGnAMLIo5J1kE9/NmG6ZVNbHOBi7Zg54A==
  • Authentication-results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=suse.com;
  • Cc: Wei Liu <wl@xxxxxxx>, Anthony PERARD <anthony.perard@xxxxxxxxxx>, Juergen Gross <jgross@xxxxxxxx>, xen-devel@xxxxxxxxxxxxxxxxxxxx
  • Delivery-date: Thu, 06 Jul 2023 11:09:31 +0000
  • List-id: Xen developer discussion <xen-devel.lists.xenproject.org>

On 16.06.2023 15:10, Roger Pau Monne wrote:
> --- a/tools/libs/light/libxl_cpuid.c
> +++ b/tools/libs/light/libxl_cpuid.c
> @@ -88,6 +88,66 @@ static struct xc_xend_cpuid 
> *cpuid_find_match(libxl_cpuid_policy *policy,
>      return *list + i;
>  }
>  
> +static int cpuid_add(libxl_cpuid_policy *policy, const struct cpuid_flags 
> *flag,
> +                     const char *val)
> +{
> +    struct xc_xend_cpuid *entry = cpuid_find_match(policy, flag->leaf,
> +                                                   flag->subleaf);
> +    unsigned long num;
> +    char flags[33], *resstr, *endptr;
> +    unsigned int i;
> +
> +    resstr = entry->policy[flag->reg - 1];
> +    num = strtoull(val, &endptr, 0);
> +    flags[flag->length] = 0;
> +    if (endptr != val) {
> +        /* if this was a valid number, write the binary form into the string 
> */
> +        for (i = 0; i < flag->length; i++) {
> +            flags[flag->length - 1 - i] = "01"[!!(num & (1 << i))];

I expect you've left this as is because you really only want to move code
here? At the very least the UB should be eliminated imo, by using 1u in
the shift. Even better might be "01"[(num >> i) & 1]. And of course using
strtoull() when num is unsigned long is a little fishy as well ...

Jan



 


Rackspace

Lists.xenproject.org is hosted with RackSpace, monitoring our
servers 24x7x365 and backed by RackSpace's Fanatical Support®.