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

Re: [PATCH v4 07/11] xsm: decouple xsm header inclusion selection


  • To: "Daniel P. Smith" <dpsmith@xxxxxxxxxxxxxxxxxxxx>, <xen-devel@xxxxxxxxxxxxxxxxxxxx>
  • From: Andrew Cooper <andrew.cooper3@xxxxxxxxxx>
  • Date: Mon, 6 Sep 2021 19:47:43 +0100
  • Arc-authentication-results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=citrix.com; dmarc=pass action=none header.from=citrix.com; dkim=pass header.d=citrix.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; bh=e4AQjytToAgMKCwoiUEbPXNarq36A5NlNm1hQZ3oCF4=; b=kaEut+8XyJVY9pgOb4iHnBOwttBa0umwAIzZ0SzgRV4SNdVU4xe+Ilec6Fc1rh/wVISRSXn4anfxrdtB0kRpwbqRD0OUZp31wyXt+DlQJXPfwV6IGXKRhwoJLAATlNJWf2dHLa/bWJmr2SiOB/ODT6s42fwnoFHXbO7ZQAVQ0Iz5ggNVU5TUD1UxfHSVXQtdhStx73WXAFE72N/DudbQZK4N0h1aUmAqe6CdVWHoSG/4uOBkUbtMFNj6U+YM6HnsiRQzIQzY1QYnZqcsSfSQZdNLRo2IQhx2mQyfVoKVsQs2ZQHUHcj0o3hDGSJ3HWriiOwSzsv3C8Hssoy6WjMpxQ==
  • Arc-seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=CBKZzdLwZtsB+VXBUp2mxSzyT6moFjPoWyL4WCfVs0n2ntpJe1w9x+Zx8bmXfCUasUiIPXnDqd/ECk3wsYoF4t5n9o/JGxXObv6ri+b/+7DcXaZscSFyyNGNsVjN1admH4bG1n5IZHIbY83Xz2SL3pN4H6J1IYABTTAq/95NSFuqOnsjv/ZSaPWJylLQcMFN/QZPNltDywJ4TBPYxrnucVpADbCBjdUoSwPKzrjdeUhdEj9tKCagi07dLIlrryAZ89EunokQwW3EBz7EaKTDU7Rlpp73dyrc8S3nQuy9F9fOjUsqw/Mbh/IGdMmhP++ho0SZa7UaqGT5BgOV1QLWsg==
  • Authentication-results: esa2.hc3370-68.iphmx.com; dkim=pass (signature verified) header.i=@citrix.onmicrosoft.com
  • Cc: Daniel De Graaf <dgdegra@xxxxxxxxxxxxx>
  • Delivery-date: Mon, 06 Sep 2021 18:48:15 +0000
  • Ironport-hdrordr: A9a23:krThmqrv7lTshhETEpBGsAQaV5u7L9V00zEX/kB9WHVpm5Oj+P xGzc526farslsssREb+OxpOMG7MBbhHO1OkPYs1NCZLXXbUQqTXfxfBO7ZrQEIdBeOjtK1uZ 0QFJSWTeeAd2SS7vyKkDVQcexQueVvmZrA7Yy1rwYPPHJXguNbnmNE426gYzxLrWJ9dPwE/f Snl6h6TnabCA8qhpPRPAh6YwGPnayHqLvWJTo9QzI34giHij2lrJb8Dhijxx8bFxdC260r/2 TpmxHwovzLiYD19jbsk0voq7hGktrozdVOQOSKl8guMz3pziKlfp5oVbGutC085Muv9FEput /RpApIBbU+11rhOkWO5Tf90Qjp1zgjr1fk1F+jmHPm5ff0QTorYvAxzb5xQ1/80Q4Nrdt82K VE0yayrJxMFy7Nmyz7+pzhSwxqvlDcmwtjrccjy1hkFacOYr5YqoISuGlPFo0bIS784Ic7VM FzEcDn4upMe1/yVQGZgoBW+q3vYp0PJGbCfqBb0fbllwS+3UoJgXfw/fZv3Uvpr/kGOt55D+ etCNUgqFgBdL5RUUtHPpZ1fSKAMB26ffv9ChPhHb3ZLtByB5vske+93Fxn3pDhRHQ3pKFC76 gpFmko7FIPRw==
  • Ironport-sdr: AJXT4rlBSSGvZOOwuOBvuo4L/XXCjH0iB/CLg+0YhgkIHdyZY3o1gHnF7eu8qJCMNB/i9+9TNi HWUy60jzdt5mqsHpu+gAK6OloYu9Wt4aok1lFoZq6xmkU+v6ueyV/1V4UyAyCYloEpQfh3BHKj V9VQGid+3UGlX02V2svaAw1Wty4JfBZVXUXHQ88m6kcKWgxhBtCeWf0nZnXQeSoVneDG14yZmf TqRWTfYXEqjO5jt31PaKcxoxcBgDc4CzDE7pCJjEPYaRzmxyMQRcXYXo7hEdKmsLm3wHi+yGdb zHyNJK98xOp4tw/N/Sp/wbx3
  • List-id: Xen developer discussion <xen-devel.lists.xenproject.org>

On 03/09/2021 20:06, Daniel P. Smith wrote:
> diff --git a/xen/include/xsm/xsm-core.h b/xen/include/xsm/xsm-core.h
> new file mode 100644
> index 0000000000..4555e111dc
> --- /dev/null
> +++ b/xen/include/xsm/xsm-core.h
> @@ -0,0 +1,274 @@
> +/*
> + *  This file contains the XSM hook definitions for Xen.
> + *
> + *  This work is based on the LSM implementation in Linux 2.6.13.4.
> + *
> + *  Author:  George Coker, <gscoker@xxxxxxxxxxxxxx>
> + *
> + *  Contributors: Michael LeMay, <mdlemay@xxxxxxxxxxxxxx>
> + *
> + *  This program is free software; you can redistribute it and/or modify
> + *  it under the terms of the GNU General Public License version 2,
> + *  as published by the Free Software Foundation.
> + */
> +
> +#ifndef __XSM_CORE_H__
> +#define __XSM_CORE_H__
> +
> +#include <xen/sched.h>
> +#include <xen/multiboot.h>
> +
> +/* policy magic number (defined by XSM_MAGIC) */
> +typedef uint32_t xsm_magic_t;
> +
> +#ifdef CONFIG_XSM_FLASK
> +#define XSM_MAGIC 0xf97cff8c
> +#else
> +#define XSM_MAGIC 0x0
> +#endif

Eww.  I know you're only moving code, but this construct is broken
(right from XSM's introduction in c/s d046f361dc937), and creates a
fairly-severe bug.

It causes xsm_multiboot_policy_init() to malfunction and accept a module
which starts with 4 zeroes, rather than the flask magic number.  The one
caller is suitably guarded so this is only a latent bug right now, but I
don't think we could credibly security support the code without this
being fixed.  (Again - fine to add to the todo list.  I know there's
loads to do)

> +
> +/* These annotations are used by callers and in dummy.h to document the
> + * default actions of XSM hooks. They should be compiled out otherwise.
> + */

For the coding style patch, this should be

/*
 * These ...

> +#ifdef CONFIG_XSM
> +
> +#ifdef CONFIG_MULTIBOOT
> +int xsm_multiboot_init(unsigned long *module_map,
> +                       const multiboot_info_t *mbi);
> +int xsm_multiboot_policy_init(unsigned long *module_map,
> +                              const multiboot_info_t *mbi,
> +                              void **policy_buffer,
> +                              size_t *policy_size);
> +#endif
> +
> +#ifdef CONFIG_HAS_DEVICE_TREE
> +/*
> + * Initialize XSM
> + *
> + * On success, return 1 if using SILO mode else 0.
> + */
> +int xsm_dt_init(void);
> +int xsm_dt_policy_init(void **policy_buffer, size_t *policy_size);
> +bool has_xsm_magic(paddr_t);
> +#endif
> +
> +#ifdef CONFIG_XSM_FLASK
> +const struct xsm_ops *flask_init(const void *policy_buffer,
> +                                 size_t policy_size);
> +#else
> +static inline const struct xsm_ops *flask_init(const void *policy_buffer,
> +                                               size_t policy_size)
> +{
> +    return NULL;
> +}
> +#endif
> +
> +#ifdef CONFIG_XSM_SILO
> +const struct xsm_ops *silo_init(void);
> +#else
> +static const inline struct xsm_ops *silo_init(void)
> +{
> +    return NULL;
> +}
> +#endif
> +
> +#else /* CONFIG_XSM */
> +
> +#ifdef CONFIG_MULTIBOOT
> +static inline int xsm_multiboot_init(unsigned long *module_map,
> +                                     const multiboot_info_t *mbi)
> +{
> +    return 0;
> +}
> +#endif
> +
> +#ifdef CONFIG_HAS_DEVICE_TREE
> +static inline int xsm_dt_init(void)
> +{
> +    return 0;
> +}
> +
> +static inline bool has_xsm_magic(paddr_t start)
> +{
> +    return false;
> +}
> +#endif /* CONFIG_HAS_DEVICE_TREE */

Shouldn't this be an #ifndef CONFIG_HAS_DEVICE_TREE ?

And the answer is no because of the #else /* CONFIG_XSM */ higher up,
but it is incredibly deceptive to read.


I think this logic would be far easier to follow as:

#if IS_ENABLED(CONFIG_XSM) && IS_ENABLED(CONFIG_MULTIBOOT)
...
#else
...
#endif

etc.

rather than having two separate #ifdef CONFIG_MULTIBOOT blocks doing
opposite things due to the position of intermixed #ifdef CONFIG_XSM.

~Andrew




 


Rackspace

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