All of lore.kernel.org
 help / color / mirror / Atom feed
From: Julien Grall <julien.grall@linaro.org>
To: Daniel De Graaf <dgdegra@tycho.nsa.gov>, selinux@tycho.nsa.gov
Cc: xen-devel@lists.xenproject.org
Subject: Re: [Xen-devel] [PATCH 1/4] Expand Xen IOMEMCON to 64 bits
Date: Thu, 12 Mar 2015 17:34:12 +0000	[thread overview]
Message-ID: <5501CE14.5060800@linaro.org> (raw)
In-Reply-To: <1426180350-16259-2-git-send-email-dgdegra@tycho.nsa.gov>

Hi Daniel,

On 12/03/15 17:12, Daniel De Graaf wrote:
> diff --git a/libsepol/src/write.c b/libsepol/src/write.c
> index d03dc20..d98a5eb 100644
> --- a/libsepol/src/write.c
> +++ b/libsepol/src/write.c
> @@ -1252,13 +1252,24 @@ static int ocontext_write_xen(struct policydb_compat_info *info, policydb_t *p,
>  					return POLICYDB_ERROR;
>  				break;
>  			case OCON_XEN_IOMEM:
> -				buf[0] = c->u.iomem.low_iomem;
> -				buf[1] = c->u.iomem.high_iomem;
> -				for (j = 0; j < 2; j++)
> -					buf[j] = cpu_to_le32(buf[j]);
> -				items = put_entry(buf, sizeof(uint32_t), 2, fp);
> -				if (items != 2)
> -					return POLICYDB_ERROR;
> +				if (p->policyvers >= POLICYDB_XEN_VERSION_AARCH) {
> +					uint64_t b64[2];
> +					b64[0] = c->u.iomem.low_iomem;
> +					b64[1] = c->u.iomem.high_iomem;
> +					for (j = 0; j < 2; j++)
> +						b64[j] = cpu_to_le64(b64[j]);
> +					items = put_entry(b64, sizeof(uint64_t), 2, fp);
> +					if (items != 2)
> +						return POLICYDB_ERROR;
> +				} else {
> +					buf[0] = c->u.iomem.low_iomem;
> +					buf[1] = c->u.iomem.high_iomem;
> +					for (j = 0; j < 2; j++)
> +						buf[j] = cpu_to_le32(buf[j]);
> +					items = put_entry(buf, sizeof(uint32_t), 2, fp);
> +					if (items != 2)
> +						return POLICYDB_ERROR;

If low_iomem/high_iomem doesn't fit in an uint32_t it will be truncated
and therefore we may, by mistake, give access to wrong MMIO region.

Shouldn't we at least add a warning, if not throwing an error?

Regards,

-- 
Julien Grall

WARNING: multiple messages have this Message-ID (diff)
From: Julien Grall <julien.grall@linaro.org>
To: Daniel De Graaf <dgdegra@tycho.nsa.gov>, selinux@tycho.nsa.gov
Cc: xen-devel@lists.xenproject.org
Subject: Re: [PATCH 1/4] Expand Xen IOMEMCON to 64 bits
Date: Thu, 12 Mar 2015 17:34:12 +0000	[thread overview]
Message-ID: <5501CE14.5060800@linaro.org> (raw)
In-Reply-To: <1426180350-16259-2-git-send-email-dgdegra@tycho.nsa.gov>

Hi Daniel,

On 12/03/15 17:12, Daniel De Graaf wrote:
> diff --git a/libsepol/src/write.c b/libsepol/src/write.c
> index d03dc20..d98a5eb 100644
> --- a/libsepol/src/write.c
> +++ b/libsepol/src/write.c
> @@ -1252,13 +1252,24 @@ static int ocontext_write_xen(struct policydb_compat_info *info, policydb_t *p,
>  					return POLICYDB_ERROR;
>  				break;
>  			case OCON_XEN_IOMEM:
> -				buf[0] = c->u.iomem.low_iomem;
> -				buf[1] = c->u.iomem.high_iomem;
> -				for (j = 0; j < 2; j++)
> -					buf[j] = cpu_to_le32(buf[j]);
> -				items = put_entry(buf, sizeof(uint32_t), 2, fp);
> -				if (items != 2)
> -					return POLICYDB_ERROR;
> +				if (p->policyvers >= POLICYDB_XEN_VERSION_AARCH) {
> +					uint64_t b64[2];
> +					b64[0] = c->u.iomem.low_iomem;
> +					b64[1] = c->u.iomem.high_iomem;
> +					for (j = 0; j < 2; j++)
> +						b64[j] = cpu_to_le64(b64[j]);
> +					items = put_entry(b64, sizeof(uint64_t), 2, fp);
> +					if (items != 2)
> +						return POLICYDB_ERROR;
> +				} else {
> +					buf[0] = c->u.iomem.low_iomem;
> +					buf[1] = c->u.iomem.high_iomem;
> +					for (j = 0; j < 2; j++)
> +						buf[j] = cpu_to_le32(buf[j]);
> +					items = put_entry(buf, sizeof(uint32_t), 2, fp);
> +					if (items != 2)
> +						return POLICYDB_ERROR;

If low_iomem/high_iomem doesn't fit in an uint32_t it will be truncated
and therefore we may, by mistake, give access to wrong MMIO region.

Shouldn't we at least add a warning, if not throwing an error?

Regards,

-- 
Julien Grall

  reply	other threads:[~2015-03-12 17:34 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   ` Julien Grall [this message]
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
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=5501CE14.5060800@linaro.org \
    --to=julien.grall@linaro.org \
    --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.