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

Re: [PATCH v2 02/10] xsm: refactor xsm_ops handling


  • To: "Daniel P. Smith" <dpsmith@xxxxxxxxxxxxxxxxxxxx>, <xen-devel@xxxxxxxxxxxxxxxxxxxx>
  • From: Andrew Cooper <andrew.cooper3@xxxxxxxxxx>
  • Date: Tue, 13 Jul 2021 00:39:14 +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:X-MS-Exchange-SenderADCheck; bh=lgPcwIi4Fw0krICkUzQ1EJQMUmXCnim7ofrU9aZ3b0g=; b=dRtDPhk4UUQSREk5O5CAiPTK8mjC1I2hSyZF9UKGCjF+QLABkoBctuH7GVC1dFzDUl38UzpjUgPxUKx+eBNVl/oAHEPxZGoiByD4CwF3ZFWg7hFEfFFPMERLI4gng9VJv5yr48z5VK+jKRy9YUgm0au0AW3lgmOSEaZUwh534NMWD1pWVIb5Twcnwf9fXU2fbxW7sjkFIJTEXUK8kU9TDw3SX2ZoUbVfGidbATLL7acKxwSLBk6Beyu/EC69jc0XShktlphF4U50dJz2zTlk8dCLRfI7jL3S0oSB7ghRZU1OnW7uhuf4t7/5iVnPjCn+Gd/SG8aD1snOkmYZtB8/PQ==
  • Arc-seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=Xm75UGVNnSqrTOmdscdNuZnGFU5CLILrKu78w+PKWOUEl0/3XIAGM3okasWwhL1Swn18M+O96UTDsQg76Rm68xKGB9yJgijWR/uAAfGJKvHkUVq8YlUEj7WwIFA4T92r28r+iSWHq1COpRJzyUMFm0c/yvs+d67d95fMQ6SjBHyqPia+G2+3jheU9LNgFNwbE3XaZBRIkFZYUJOgIY9reTzX4WK5hAPXkwpw0GV9W+dUzjrlUM6KBv3e9Fqb+tgsz+7+A/4G3DWhfT4Plsr/phk5nM5JpOwJqDIKukJtV7EnZ4IcuLIWekWoAz1Kq+lycXK+HwZAlg4TVXOmf3HnRA==
  • Authentication-results: esa6.hc3370-68.iphmx.com; dkim=pass (signature verified) header.i=@citrix.onmicrosoft.com
  • Cc: Daniel De Graaf <dgdegra@xxxxxxxxxxxxx>
  • Delivery-date: Mon, 12 Jul 2021 23:39:35 +0000
  • Ironport-hdrordr: A9a23:AuU7KKMkQEUiNcBcTzT155DYdb4zR+YMi2TDiHofdfUFSKClfp 6V8cjztSWUtN4QMEtQ/OxoS5PwPk80kqQFnbX5XI3SITUO3VHHEGgM1/qb/9SNIVyYygcZ79 YbT0EcMqyBMbEZt7eC3ODQKb9Jq7PmgcPY99s2jU0dKT2CA5sQnjuRYTzrdHGeKjM2Z6bRWK Dsnfau8FGbCAoqh4mAdzQ4dtmGg+eOuIPtYBYACRJiwA6SjQmw4Lq/NxSDxB8RXx5G3L9nqA H+4kPEz5Tml8v+5g7X1mfV4ZgTsNz9yuFbDMjJrsQOMD3jhiuheYwkcbyfuzIepv2p9T8R4Z XxiiZlG/42x2Laf2mzrxeo8RLnyiwS53jrzkLdqWf/oOTiLQhKS/ZptMZ8SF/0+kAgtNZz3O ZgxGSCradaChvGgWDU+8XIbRd3jUC5yEBS0NL7t0YvE7f2VYUh6LD2pChuYdM99WPBmc4a+d BVfYLhDK08SyLcU5ix1VMfs+BFXRwIb1+7qwY5y4qoOgNt7QREJn0jtYUid0c7hecAoqZ/lp P524RT5fpzp5wtHOhA7Nloe7rANoWKe2OUDF6v
  • Ironport-sdr: PBGlFF5phMbRjvvph/nD9WETrimkuo6e2K0kGE/+8Hy24G8ZEEeIlPj1denGVSlZPKXCSY5eud 5/iZ+2liuixxFbuIB5ajQt02REQ/zFh1sMjmZcVUNSOxZ+vp1hipK9H43Gj8hfnn8h5GcQd66R m6wxk8/6dT4KMFFmevwJqroeQUmqELLN1BQIO3ss3+3NbetvLu6F07PckjqI0Z+eCjoIKc0V2w c622RRkZeLGXAtC2las08s8CpyTGEa+KbqYzeqhUdWDwz+1x9xO3PR9HwbcX+2BTG7n47+jHku Q2Q=
  • List-id: Xen developer discussion <xen-devel.lists.xenproject.org>

On 12/07/2021 21:32, Daniel P. Smith wrote:
> diff --git a/xen/include/xsm/xsm.h b/xen/include/xsm/xsm.h
> index ad3cddbf7d..a8805f514b 100644
> --- a/xen/include/xsm/xsm.h
> +++ b/xen/include/xsm/xsm.h
> @@ -747,16 +747,14 @@ extern int xsm_dt_policy_init(void **policy_buffer, 
> size_t *policy_size);
>  extern bool has_xsm_magic(paddr_t);
>  #endif
>  
> -extern int register_xsm(struct xsm_operations *ops);
> -
> -extern struct xsm_operations dummy_xsm_ops;
>  extern void xsm_fixup_ops(struct xsm_operations *ops);
>  
>  #ifdef CONFIG_XSM_FLASK
> -extern void flask_init(const void *policy_buffer, size_t policy_size);
> +extern struct xsm_operations *flask_init(const void *policy_buffer, size_t 
> policy_size);
>  #else
> -static inline void flask_init(const void *policy_buffer, size_t policy_size)
> +static inline struct xsm_operations *flask_init(const void *policy_buffer, 
> size_t policy_size)
>  {
> +    return NULL;
>  }
>  #endif

As you touch almost every current user of xsm_operations and introduce
quite a few more, can I recommend taking the opportunity to shorten the
name to struct xsm_ops.

> diff --git a/xen/xsm/flask/flask_op.c b/xen/xsm/flask/flask_op.c
> index 01e52138a1..32e079d676 100644
> --- a/xen/xsm/flask/flask_op.c
> +++ b/xen/xsm/flask/flask_op.c
> @@ -226,6 +226,7 @@ static int flask_security_sid(struct 
> xen_flask_sid_context *arg)
>  static int flask_disable(void)
>  {
>      static int flask_disabled = 0;
> +    struct xsm_operations default_ops;
>  
>      if ( ss_initialized )
>      {
> @@ -244,7 +245,8 @@ static int flask_disable(void)
>      flask_disabled = 1;
>  
>      /* Reset xsm_ops to the original module. */
> -    xsm_ops = &dummy_xsm_ops;
> +    xsm_fixup_ops(&default_ops);
> +    xsm_ops = default_ops;
>  
>      return 0;
>  }

These two hunks will disappear when patch 3 is reordered with respect to
this one.

... which is good because you've just pointed xsm_ops at a
soon-to-be-out-of-scope local variable on the stack.

> diff --git a/xen/xsm/flask/hooks.c b/xen/xsm/flask/hooks.c
> index f1a1217c98..a3a88aa8ed 100644
> --- a/xen/xsm/flask/hooks.c
> +++ b/xen/xsm/flask/hooks.c
> @@ -1883,7 +1883,8 @@ static struct xsm_operations flask_ops = {
>  #endif
>  };

flask and silo ops should become:

static const struct xsm_ops __initconst {flask,silo}_ops = {

as they're neither modified, nor needed after init, following this change.

>  
> -void __init flask_init(const void *policy_buffer, size_t policy_size)
> +struct xsm_operations __init *flask_init(const void *policy_buffer,
> +                                      size_t policy_size)

struct xsm_ops *__init flask_init(...)

Otherwise you've got the __init in the middle of the return type, and
some compilers are more picky than others.

> @@ -1923,6 +1921,9 @@ void __init flask_init(const void *policy_buffer, 
> size_t policy_size)
>          printk(XENLOG_INFO "Flask:  Starting in enforcing mode.\n");
>      else
>          printk(XENLOG_INFO "Flask:  Starting in permissive mode.\n");
> +
> +    return &flask_ops;
> +

Stray newline.

>  }
>  
>  /*
> diff --git a/xen/xsm/silo.c b/xen/xsm/silo.c
> index fc2ca5cd2d..808350f122 100644
> --- a/xen/xsm/silo.c
> +++ b/xen/xsm/silo.c
> @@ -112,12 +112,11 @@ static struct xsm_operations silo_xsm_ops = {
>  #endif
>  };
>  
> -void __init silo_init(void)
> +struct xsm_operations __init *silo_init(void)

Same here as with flask.

> diff --git a/xen/xsm/xsm_core.c b/xen/xsm/xsm_core.c
> index 5eab21e1b1..7265f742e9 100644
> --- a/xen/xsm/xsm_core.c
> +++ b/xen/xsm/xsm_core.c
> @@ -68,17 +76,10 @@ static int __init parse_xsm_param(const char *s)
>  }
>  custom_param("xsm", parse_xsm_param);
>  
> -static inline int verify(struct xsm_operations *ops)
> -{
> -    /* verify the security_operations structure exists */
> -    if ( !ops )
> -        return -EINVAL;
> -    xsm_fixup_ops(ops);
> -    return 0;
> -}
> -
>  static int __init xsm_core_init(const void *policy_buffer, size_t 
> policy_size)
>  {
> +     struct xsm_operations *mod_ops;
> +

Hard tabs, and later in this function.  Also, how about just 'ops' for
the local variable name?

> @@ -113,6 +124,17 @@ static int __init xsm_core_init(const void 
> *policy_buffer, size_t policy_size)
>          break;
>      }
>  
> +    /*
> +     * This handles three cases,
> +     *   - dummy policy module was selected
> +     *   - a policy module  does not provide all handlers

Stray double space.

~Andrew




 


Rackspace

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