All of lore.kernel.org
 help / color / mirror / Atom feed
From: Stephen Smalley <sds@tycho.nsa.gov>
To: Daniel De Graaf <dgdegra@tycho.nsa.gov>, selinux@tycho.nsa.gov
Cc: xen-devel@lists.xenproject.org
Subject: Re: [PATCH 3/4] checkpolicy: add output for Xen policy version support
Date: Thu, 12 Mar 2015 13:43:05 -0400	[thread overview]
Message-ID: <5501D029.7030003@tycho.nsa.gov> (raw)
In-Reply-To: <1426180350-16259-4-git-send-email-dgdegra@tycho.nsa.gov>

On 03/12/2015 01:12 PM, Daniel De Graaf wrote:
> When invoked as "checkpolicy -t Xen -V", report the range of supported
> versions for the Xen policy instead of the supported versions for the
> SELinux policy.
> 
> This also changes the default maximum policy version to depend on the
> policy type, so that running "checkpolicy -t Xen" without -c does not
> fail due to the Xen policy having a different maximum version number.

There is a bit of wrinkle here with regard to splitting the Xen and
SELinux policy version number space that I'm afraid I didn't think about
earlier.  You'll find that there are various tests of policyvers >= some
version in the policydb_read code path and the policydb_write code path
to decide whether or not to read or write the corresponding fields or
structures, and none of that logic currently checks the target_platform.

Also, certain language features in the source policy language have been
documented to depend on specific policy version numbers, so reusing the
same version numbers for Xen and SELinux to mean different things could
be confusing to users.

So on second thought, I'd suggest that you update Xen to support the
latest upstream policy version just so you can fully support all of the
language features and just define a new version for this change (i.e.
policy 30).  Sorry!

> 
> Signed-off-by: Daniel De Graaf <dgdegra@tycho.nsa.gov>
> ---
>  checkpolicy/checkpolicy.c                  | 59 ++++++++++++++++++++++--------
>  libsepol/include/sepol/policydb/policydb.h |  9 +++--
>  2 files changed, 49 insertions(+), 19 deletions(-)
> 
> diff --git a/checkpolicy/checkpolicy.c b/checkpolicy/checkpolicy.c
> index 61a2e89..e836bcb 100644
> --- a/checkpolicy/checkpolicy.c
> +++ b/checkpolicy/checkpolicy.c
> @@ -99,7 +99,7 @@ static int handle_unknown = SEPOL_DENY_UNKNOWN;
>  static const char *txtfile = "policy.conf";
>  static const char *binfile = "policy";
>  
> -unsigned int policyvers = POLICYDB_VERSION_MAX;
> +unsigned int policyvers = 0;
>  
>  void usage(char *progname)
>  {
> @@ -466,17 +466,7 @@ int main(int argc, char **argv)
>  					usage(argv[0]);
>  					exit(1);
>  				}
> -				if (n < POLICYDB_VERSION_MIN
> -				    || n > POLICYDB_VERSION_MAX) {
> -					fprintf(stderr,
> -						"policyvers value %ld not in range %d-%d\n",
> -						n, POLICYDB_VERSION_MIN,
> -						POLICYDB_VERSION_MAX);
> -					usage(argv[0]);
> -					exit(1);
> -				}
> -				if (policyvers != n)
> -					policyvers = n;
> +				policyvers = n;
>  				break;
>  			}
>  		case 'h':
> @@ -485,10 +475,47 @@ int main(int argc, char **argv)
>  		}
>  	}
>  
> -	if (show_version) {
> -		printf("%d (compatibility range %d-%d)\n", policyvers,
> -		       POLICYDB_VERSION_MAX, POLICYDB_VERSION_MIN);
> -		exit(0);
> +	switch (target) {
> +	case SEPOL_TARGET_SELINUX:
> +		if (policyvers == 0) {
> +			policyvers = POLICYDB_VERSION_MAX;
> +		} else if (policyvers < POLICYDB_VERSION_MIN
> +				|| policyvers > POLICYDB_VERSION_MAX) {
> +			fprintf(stderr,
> +				"policyvers value %d not in range %d-%d\n",
> +				policyvers, POLICYDB_VERSION_MIN,
> +				POLICYDB_VERSION_MAX);
> +				usage(argv[0]);
> +				exit(1);
> +		}
> +		if (show_version) {
> +			printf("%d (compatibility range %d-%d)\n", policyvers,
> +				   POLICYDB_VERSION_MAX, POLICYDB_VERSION_MIN);
> +			exit(0);
> +		}
> +		break;
> +	case SEPOL_TARGET_XEN:
> +		if (policyvers == 0) {
> +			policyvers = POLICYDB_XEN_VERSION_MAX;
> +		} else if (policyvers < POLICYDB_XEN_VERSION_MIN
> +				|| policyvers > POLICYDB_XEN_VERSION_MAX) {
> +			fprintf(stderr,
> +				"policyvers value %d not in range %d-%d\n",
> +				policyvers, POLICYDB_XEN_VERSION_MIN,
> +				POLICYDB_XEN_VERSION_MAX);
> +				usage(argv[0]);
> +				exit(1);
> +		}
> +		if (show_version) {
> +			printf("Xen policy compatibility range: %d %d\n",
> +				POLICYDB_XEN_VERSION_MIN,
> +				POLICYDB_XEN_VERSION_MAX);
> +			exit(0);
> +		}
> +		break;
> +	default:
> +		usage(argv[0]);
> +		exit(1);
>  	}
>  
>  	if (optind != argc) {
> diff --git a/libsepol/include/sepol/policydb/policydb.h b/libsepol/include/sepol/policydb/policydb.h
> index d574d4b..8150765 100644
> --- a/libsepol/include/sepol/policydb/policydb.h
> +++ b/libsepol/include/sepol/policydb/policydb.h
> @@ -691,13 +691,16 @@ extern int policydb_set_target_platform(policydb_t *p, int platform);
>  #define POLICYDB_VERSION_DEFAULT_TYPE	28
>  #define POLICYDB_VERSION_CONSTRAINT_NAMES	29
>  
> -#define POLICYDB_XEN_VERSION_BASE   24
> -#define POLICYDB_XEN_VERSION_AARCH  25
> -
>  /* Range of policy versions we understand*/
>  #define POLICYDB_VERSION_MIN	POLICYDB_VERSION_BASE
>  #define POLICYDB_VERSION_MAX	POLICYDB_VERSION_CONSTRAINT_NAMES
>  
> +#define POLICYDB_XEN_VERSION_BASE   24
> +#define POLICYDB_XEN_VERSION_AARCH  25
> +
> +#define POLICYDB_XEN_VERSION_MIN	POLICYDB_XEN_VERSION_BASE
> +#define POLICYDB_XEN_VERSION_MAX	POLICYDB_XEN_VERSION_AARCH
> +
>  /* Module versions and specific changes*/
>  #define MOD_POLICYDB_VERSION_BASE		4
>  #define MOD_POLICYDB_VERSION_VALIDATETRANS	5
> 

  reply	other threads:[~2015-03-12 17:43 UTC|newest]

Thread overview: 19+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-03-12 17:12 [PATCH 0/4] Xen/FLASK policy updates for device contexts Daniel De Graaf
2015-03-12 17:12 ` [PATCH 1/4] Expand Xen IOMEMCON to 64 bits Daniel De Graaf
2015-03-12 17:12   ` Daniel De Graaf
2015-03-12 17:34   ` [Xen-devel] " Julien Grall
2015-03-12 17:34     ` Julien Grall
2015-03-12 17:12 ` [PATCH 2/4] Add device tree ocontext nodes to Xen policy Daniel De Graaf
2015-03-12 17:12   ` Daniel De Graaf
2015-03-12 17:27   ` [Xen-devel] " Julien Grall
2015-03-12 17:27     ` Julien Grall
2015-03-12 17:32     ` [Xen-devel] " Daniel De Graaf
2015-03-12 17:32       ` Daniel De Graaf
2015-03-12 18:04       ` [Xen-devel] " Julien Grall
2015-03-12 18:04         ` Julien Grall
2015-03-12 17:12 ` [PATCH 3/4] checkpolicy: add output for Xen policy version support Daniel De Graaf
2015-03-12 17:12   ` Daniel De Graaf
2015-03-12 17:43   ` Stephen Smalley [this message]
2015-03-12 17:43   ` Stephen Smalley
2015-03-12 17:12 ` [PATCH 4/4] checkpolicy: Expand allowed character set in paths Daniel De Graaf
2015-03-12 17:12   ` Daniel De Graaf

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=5501D029.7030003@tycho.nsa.gov \
    --to=sds@tycho.nsa.gov \
    --cc=dgdegra@tycho.nsa.gov \
    --cc=selinux@tycho.nsa.gov \
    --cc=xen-devel@lists.xenproject.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.