All of lore.kernel.org
 help / color / mirror / Atom feed
From: Joshua Brindle <method@manicmethod.com>
To: Kohei KaiGai <kaigai@kaigai.gr.jp>
Cc: Kohei Kaigai <Kohei.Kaigai@EU.NEC.COM>,
	Eric Paris <eparis@redhat.com>,
	"selinux@tycho.nsa.gov" <selinux@tycho.nsa.gov>,
	"sds@tycho.nsa.gov" <sds@tycho.nsa.gov>
Subject: Re: [PATCH] selinux: revise /selinux/create to handle whitespace/multibytes correctly
Date: Sat, 16 Apr 2011 12:43:41 -0400	[thread overview]
Message-ID: <4DA9C73D.1000403@manicmethod.com> (raw)
In-Reply-To: <BANLkTi=Czi-Zh1s3YP+rG4KZr1uwoHUTXA@mail.gmail.com>

Kohei KaiGai wrote:
> This patch allows to accept percent-encoded object name as the forth
> argument of /selinux/create interface to avoid possible bugs when we
> supply an object name that includes whitespace or multibytes.

Why not use standard bash escaping instead of html entities?

>
> Although I could not test this patch on named TYPE_TRANSITION rules,
> but printk() messages for debugging seems to me the logic works correctly.
> I assume the libselinux provide the logic to encode object name, so it shall
> be applied transparently for the viewpoint of application.
>
> Signed-off-by: KaiGai Kohei<kohei.kaigai@eu.nec.com>
> ---
>   security/selinux/selinuxfs.c |   38 +++++++++++++++++++++++++++++++++++++-
>   1 files changed, 37 insertions(+), 1 deletions(-)
>
> diff --git a/security/selinux/selinuxfs.c b/security/selinux/selinuxfs.c
> index 973f5a4..4fde279 100644
> --- a/security/selinux/selinuxfs.c
> +++ b/security/selinux/selinuxfs.c
> @@ -28,6 +28,7 @@
>   #include<linux/percpu.h>
>   #include<linux/audit.h>
>   #include<linux/uaccess.h>
> +#include<linux/ctype.h>
>
>   /* selinuxfs pseudo filesystem for exporting the security policy API.
>      Based on the proc code and the fs/nfsd/nfsctl.c code. */
> @@ -750,6 +751,15 @@ out:
>   	return length;
>   }
>
> +static inline int hexcode_to_int(int code)
> +{
> +	if (code == '\0' || !isxdigit(code))
> +		return -1;
> +	if (isdigit(code))
> +		return code - '0';
> +	return tolower(code) - 'a' + 10;
> +}
> +
>   static ssize_t sel_write_create(struct file *file, char *buf, size_t size)
>   {
>   	char *scon = NULL, *tcon = NULL;
> @@ -784,8 +794,34 @@ static ssize_t sel_write_create(struct file
> *file, char *buf, size_t size)
>   	nargs = sscanf(buf, "%s %s %hu %s", scon, tcon,&tclass, namebuf);
>   	if (nargs<  3 || nargs>  4)
>   		goto out;
> -	if (nargs == 4)
> +	if (nargs == 4) {
> +		/*
> +		 * If and when the name of new object to be queried contains
> +		 * either whitespace or multibyte characters, they shall be
> +		 * encoded based on the percentage-encoding rule.
> +		 * If not encoded, the sscanf logic picks up only left-half
> +		 * of the supplied name; splitted by a whitespace unexpectedly.
> +		 */
> +		char   *r, *w;
> +		int	c1, c2;
> +
> +		r = w = namebuf;
> +		do {
> +			c1 = *r++;
> +			if (c1 == '+')
> +				c1 = ' ';
> +			else if (c1 == '%') {
> +				if ((c1 = hexcode_to_int(*r++))<  0)
> +					goto out;
> +				if ((c2 = hexcode_to_int(*r++))<  0)
> +					goto out;
> +				c1 = (c1<<  4) | c2;
> +			}
> +			*w++ = c1;
> +		} while (c1 != '\0');
> +
>   		objname = namebuf;
> +	}
>
>   	length = security_context_to_sid(scon, strlen(scon) + 1,&ssid);
>   	if (length)

--
This message was distributed to subscribers of the selinux mailing list.
If you no longer wish to subscribe, send mail to majordomo@tycho.nsa.gov with
the words "unsubscribe selinux" without quotes as the message.

  reply	other threads:[~2011-04-16 16:43 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2011-04-16 14:09 [PATCH] selinux: revise /selinux/create to handle whitespace/multibytes correctly Kohei KaiGai
2011-04-16 16:43 ` Joshua Brindle [this message]
2011-04-16 21:12   ` Kohei KaiGai
2011-04-17  2:24     ` Joshua Brindle
2011-04-17  7:18       ` Kohei KaiGai
2011-04-20 20:13 ` Eric Paris
2011-04-20 20:38   ` Kohei KaiGai
2011-05-03 14:10 ` Kohei KaiGai

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=4DA9C73D.1000403@manicmethod.com \
    --to=method@manicmethod.com \
    --cc=Kohei.Kaigai@EU.NEC.COM \
    --cc=eparis@redhat.com \
    --cc=kaigai@kaigai.gr.jp \
    --cc=sds@tycho.nsa.gov \
    --cc=selinux@tycho.nsa.gov \
    /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.