Skip to contentSkip to conversation

Context Mounts and Unsupported Contexts: kernel

RFC PATCH In review Cory Olmo 2 participants 4 messages Aug 15, 2006 – Aug 16, 2006 SELinux security module

lore
Share & tools
lore

Cory Olmo

author
#0 lore raw

RFC PATCH 1/3 Context Mounts and Unsupported Contexts: kernel

This patch modifies selinux_sb_copy_data() so that it will only take an option after seeing a ',' if it hasn't seen a quote or if the quotes are matched. When it does take the option, if the option is an selinux option then it calls a new function take_selinux_option(). This new function will strip the quotes and replace the previously used comma separator with a '|'. try_context_mount() was modified to look for the '|' as the separator instead of ','.

 linux-2.6.17/security/selinux/hooks.c |   36 +++++++++++++++++++++++++++++++++---
 1 file changed, 33 insertions(+), 3 deletions(-)
linux-2.6.17.i686/security/selinux/hooks.c +33 -3
index 93bc2df..378d90c 100644
@@ -398,7 +398,7 @@ static int try_context_mount(struct supe
 		/* Standard string-based options. */
 		char *p, *options = data;
 
-		while ((p = strsep(&options, ",")) != NULL) {
+		while ((p = strsep(&options, "|")) != NULL) {
 			int token;
 			substring_t args[MAX_OPT_ARGS];
 
@@ -1949,11 +1949,34 @@ static inline void take_option(char **to
 	*to += len;
 }
 
+static inline void take_selinux_option(char **to, char *from, int *first, 
+		                       int len)
+{
+	int current_size = 0;
+
+	if (!*first) {
+		**to = '|';
+		*to += 1;
+	}
+	else
+		*first = 0;
+
+	while (current_size < len) {
+		if (*from != '"') {
+			**to = *from;
+			*to += 1;
+		}
+		from += 1;
+		current_size += 1;
+	}
+}
+
 static int selinux_sb_copy_data(struct file_system_type *type, void *orig, void *copy)
 {
 	int fnosec, fsec, rc = 0;
 	char *in_save, *in_curr, *in_end;
 	char *sec_curr, *nosec_save, *nosec;
+	int open_quote = 0;
 
 	in_curr = orig;
 	sec_curr = copy;
@@ -1975,11 +1998,18 @@ static int selinux_sb_copy_data(struct f
 	in_save = in_end = orig;
 
 	do {
-		if (*in_end == ',' || *in_end == '\0') {
+		if (*in_end == '"') {
+			if (open_quote == 0)
+				open_quote -= 1;
+			else
+				open_quote += 1;
+		}
+		if (((*in_end == ',') && (open_quote == 0)) ||
+				*in_end == '\0') {
 			int len = in_end - in_curr;
 
 			if (selinux_option(in_curr, len))
-				take_option(&sec_curr, in_curr, &fsec, len);
+				take_selinux_option(&sec_curr, in_curr, &fsec, len);
 			else
 				take_option(&nosec, in_curr, &fnosec, len);
 
#1 lore raw
Quoted 3 lines · Cory Olmo

This patch modifies selinux_sb_copy_data() so that it will only take an option after seeing a ',' if it hasn't seen a quote or if the quotes are matched.

Why?

Signature · 7 lines
James Morris
<[email protected]>

--
This message was distributed to subscribers of the selinux mailing list.
If you no longer wish to subscribe, send mail to [email protected] with
the words "unsubscribe selinux" without quotes as the message.
author
#2 lore raw
Quoted 10 lines · On Tue, 15 Aug 2006 15:21:48 -0400 James Morris <[email protected]> wrote:
Quoted 1 line · Cory Olmo

This patch modifies selinux_sb_copy_data() so that it will only take

an

Quoted 1 line

option after seeing a ',' if it hasn't seen a quote or if the quotes

are

Quoted 1 line

matched.

Why?

Sorry the wording was poor on this one. The goal is to allow the context portion of the option data to contain commas. To do that I went with quoting the context. In order for the quoted context to be taken as a single option, selinux_sb_copy_data() needed to know when it had seen an opening quote and be able to hold off on taking the option until it had seen the closing quote.

This patch modifies selinux_sb_copy_data() to mark a flag value when it runs across a '"'. This flag value is consulted each time a comma is encountered. If the flag indicates that the current option has an embedded quote it will move on to the next character. If the flag indicates that there is either a matched set of quotes or no quotes at all then the option can be taken. If the option happens to be an selinux option then the new routine take_selinux_option() is called. take_selinux_option() will copy the option to the previously allocated selinux data page. While it is doing the copying it will skip any quotes present in the option so the data page contains only the raw unquoted context. The previously used comma separator between options in the selinux data page is also replaced with a '|' character which allows try_context_mount() to properly extract whole context option strings as well.

Quoted 5 lines
Signature · 3 lines
-- 
James Morris
<[email protected]>

--
This message was distributed to subscribers of the selinux mailing list. If you no longer wish to subscribe, send mail to [email protected] with the words "unsubscribe selinux" without quotes as the message.

#3 lore raw
Quoted 8 lines · Cory Olmo
Quoted 1 line

Why?

Sorry the wording was poor on this one. The goal is to allow the context portion of the option data to contain commas. To do that I went with quoting the context. In order for the quoted context to be taken as a single option, selinux_sb_copy_data() needed to know when it had seen an opening quote and be able to hold off on taking the option until it had seen the closing quote.

Thanks for the explanation.

Patches which are destined for upstream need, clear, concise descriptions which can be understood by general kernel developers. I suggest also adding examples of the contexts to your description.

- James

Signature · 7 lines
James Morris
<[email protected]>

--
This message was distributed to subscribers of the selinux mailing list.
If you no longer wish to subscribe, send mail to [email protected] with
the words "unsubscribe selinux" without quotes as the message.