Skip to contentSkip to conversation

Add support for quoted mount options

PATCH In review Karel Zak 2 participants 4 messages Mar 19, 2007 – Mar 20, 2007

Subsystems (2)
lore
Share & tools
lore

Karel Zak

author
#0 lore raw

PATCH 1/1 Add support for quoted mount options

The patch avoid the collision between commas in security contexts and the delimiter between mount options.

Try:

	mount.nfs foo://mnt/bar /mnt/bar -o context=\"aaa,bbb,ccc\",ro
---
 utils/mount/mount.c    |   24 ++++++++++++++++++------
 utils/mount/nfsmount.c |   44 +++++++++++++++++++++++++++++++++++---------
 2 files changed, 53 insertions(+), 15 deletions(-)
utils/mount/mount.c +18 -6
index 55d60aa..592bc7d 100644
@@ -256,18 +256,30 @@ static void parse_opts (const char *options, int *flags, char **extra_opts)
 {
 	if (options != NULL) {
 		char *opts = xstrdup(options);
-		char *opt;
-		int len = strlen(opts) + 20;
+		char *opt, *p;
+		int len = strlen(opts);
+		int open_quote = 0;
 
 		*extra_opts = xmalloc(len);
 		**extra_opts = '\0';
 
-		for (opt = strtok(opts, ","); opt; opt = strtok(NULL, ","))
-			parse_opt(opt, flags, *extra_opts, len);
-
+		for (p=opts, opt=NULL; p && *p; p++) {
+			if (!opt)
+				opt = p;		/* begin of the option item */
+			if (*p == '"')
+				open_quote ^= 1;	/* reverse the status */
+			if (open_quote)
+				continue;		/* still in a quoted block */
+			if (*p == ',')
+				*p = '\0';		/* terminate the option item */
+			/* end of option item or last item */
+			if (*p == '\0' || *(p+1) == '\0') {
+				parse_opt(opt, flags, *extra_opts, len);
+				opt = NULL;
+			}
+		}
 		free(opts);
 	}
-
 }
 
 static void mount_error(char *node)
utils/mount/nfsmount.c +35 -9

64 lines not on this page · raw message

Signature · 10 lines
1.4.4.2

-------------------------------------------------------------------------
Take Surveys. Earn Cash. Influence the Future of IT
Join SourceForge.net's Techsay panel and you'll get the chance to share your
opinions on IT & business topics through brief surveys-and earn cash
http://www.techsay.com/default.php?page=join.php&p=sourceforge&CID=DEVDEV
_______________________________________________
NFS maillist  -  [email protected]
https://lists.sourceforge.net/lists/listinfo/nfs
#1 lore raw
Quoted 5 lines · On Monday March 19, [email protected] wrote:

The patch avoid the collision between commas in security contexts and the delimiter between mount options.

Try:

	mount.nfs foo://mnt/bar /mnt/bar -o context=\"aaa,bbb,ccc\",ro

Hmmm..... I'm feeling a bit uncomfortable about this. Lots of code (well, some at least) relies on 'hasmntopt' which does simple parsing of the option string looking for commas. If we allow commas to be embedded in options, that code can potentially get confused.

Also, this code does not allow a double-quote to appear in the context string. You can have two (or 4 or any even number) but not one. Could that ever be a problem?

What exactly is this context string anyway? Current kernels don't seem to use it at all. Presumably the code to use it is still in
development? Is it some sort of security token? How often would it
have commas? How often would it have double-quote? Would it be possible to use a different character than ',' - maybe ':' ???

If it has to have commas, I would much rather use some other encoding, e.g.
\054
=2c
%2c
\c
:Comma: :-)

But if we can avoid commas altogether, that would be best. Can the context string even need to have a space in it? That would be rather awkward to put in /etc/fstab etc I think.

NeilBrown

-------------------------------------------------------------------------
Take Surveys. Earn Cash. Influence the Future of IT
Join SourceForge.net's Techsay panel and you'll get the chance to share your opinions on IT & business topics through brief surveys-and earn cash
http://www.techsay.com/default.php?page=join.php&p=sourceforge&CID=DEVDEV
_______________________________________________
NFS maillist - [email protected]
https://lists.sourceforge.net/lists/listinfo/nfs

author
#2 lore raw
Quoted 3 lines · Neil Brown
Quoted 2 lines · On Monday March 19, [email protected] wrote:

The patch avoid the collision between commas in security contexts and the delimiter between mount options.

The patch has been already sent by Steve Dickson and we already talked about it few weeks ago. There was problem with some extra space allocated for extra_opts. This version of the patch is more clean from nfs-utils point of view.

Quoted 9 lines
Quoted 2 lines

Try:

	mount.nfs foo://mnt/bar /mnt/bar -o context=\"aaa,bbb,ccc\",ro

Hmmm..... I'm feeling a bit uncomfortable about this. Lots of code (well, some at least) relies on 'hasmntopt' which does simple parsing of the option string looking for commas. If we allow commas to be embedded in options, that code can potentially get confused.

Quoted 3 lines

Also, this code does not allow a double-quote to appear in the context string. You can have two (or 4 or any even number) but not one. Could that ever be a problem?

I don't think so. The linux kernel supports quotes *only* for SELinux contexts and there is not possible use any nested quotes or anything more creative. It's always something like:

    context="system_u:object_r:iso9660_t:s0:c1,c3,c4"

It's kernel who has care about exact format. We need to push the context string through mount.nfs to kernel only.

Quoted 3 lines

What exactly is this context string anyway? Current kernels don't seem to use it at all. Presumably the code to use it is still in
development? Is it some sort of security token?

That's already in Linus's tree, released in 2.6.19. See:

http://git.kernel.org/?p=linux/kernel/git/torvalds/linux-2.6.git;a=commitdiff;h=3528a95322b5c1ce882ab723f175a1845430cd89

Quoted 1 line

How often would it have commas?

Unfortunately often in Multi-Category Security (MCS) SELinux:

http://www.nsa.gov/selinux/list-archive/0609/17224.cfm

Quoted 2 lines

How often would it have double-quote? Would it be possible to use a different character than ',' - maybe ':' ???

No, the format is exact.

Quoted 1 line

But if we can avoid commas altogether, that would be best.

Probably to late... the format of selinux context string is generic, it's nothing specific for a mount process. There are libs, kernel and many utils that use this format.

Quoted 2 lines

Can the context string even need to have a space in it? That would be rather awkward to put in /etc/fstab etc I think.

IMHO it's always without a space (I hope selinux guys aren't on crack ;-)

Karel

Signature · 10 lines
 Karel Zak  <[email protected]>

-------------------------------------------------------------------------
Take Surveys. Earn Cash. Influence the Future of IT
Join SourceForge.net's Techsay panel and you'll get the chance to share your
opinions on IT & business topics through brief surveys-and earn cash
http://www.techsay.com/default.php?page=join.php&p=sourceforge&CID=DEVDEV
_______________________________________________
NFS maillist  -  [email protected]
https://lists.sourceforge.net/lists/listinfo/nfs
#3 lore raw
Quoted 9 lines · On Tuesday March 20, [email protected] wrote:
Quoted 3 lines · Neil Brown
Quoted 2 lines · On Monday March 19, [email protected] wrote:

The patch avoid the collision between commas in security contexts and the delimiter between mount options.

The patch has been already sent by Steve Dickson and we already talked about it few weeks ago. There was problem with some extra space allocated for extra_opts. This version of the patch is more clean from nfs-utils point of view.

Yes, the code is cleaner, thanks for that.

Quoted 14 lines
Quoted 10 lines
Quoted 3 lines

Try:

	mount.nfs foo://mnt/bar /mnt/bar -o context=\"aaa,bbb,ccc\",ro

Hmmm..... I'm feeling a bit uncomfortable about this. Lots of code (well, some at least) relies on 'hasmntopt' which does simple parsing of the option string looking for commas. If we allow commas to be embedded in options, that code can potentially get confused.

Quoted 3 lines

Also, this code does not allow a double-quote to appear in the context string. You can have two (or 4 or any even number) but not one. Could that ever be a problem?

Quoted 8 lines

I don't think so. The linux kernel supports quotes *only* for SELinux contexts and there is not possible use any nested quotes or anything more creative. It's always something like:

    context="system_u:object_r:iso9660_t:s0:c1,c3,c4"

It's kernel who has care about exact format. We need to push the context string through mount.nfs to kernel only.

Of course when it comes through mount.nfs all the kernel sees is

           system_u:object_r:iso9660_t:s0:c1,c3,c4
Quoted 8 lines
Quoted 4 lines

What exactly is this context string anyway? Current kernels don't seem to use it at all. Presumably the code to use it is still in
development? Is it some sort of security token?

That's already in Linus's tree, released in 2.6.19. See:

http://git.kernel.org/?p=linux/kernel/git/torvalds/linux-2.6.git;a=commitdiff;h=3528a95322b5c1ce882ab723f175a1845430cd89

That patch seems fairly separate to this issues as it is stripping quotes, and when the string comes via nfs, the quotes are already stripped.

However it does seem to imply a precedent that commas within mount options are to be accepted, and while I still that is a very dumb idea, it isn't something worth fighting very hard for.

If it gets widely used and becomes a problem, maybe hasmntopt with get "enhanced" to understand quotes ... though I suspect it would end up just being a hack in util-linux that no-one else would benefit from.

I don't suppose I could convince you to write a 'hasmntopt' replacement which works properly when there are quotes in the option list, and get it into glibc :-?

Quoted 6 lines
Quoted 2 lines

But if we can avoid commas altogether, that would be best.

Probably to late... the format of selinux context string is generic, it's nothing specific for a mount process. There are libs, kernel and many utils that use this format.

We could still quote commas as \054 when they appear in mount options, but I suspect I'm fighting a loosing battle.

I'll apply the patch.

NeilBrown

-------------------------------------------------------------------------
Take Surveys. Earn Cash. Influence the Future of IT
Join SourceForge.net's Techsay panel and you'll get the chance to share your opinions on IT & business topics through brief surveys-and earn cash
http://www.techsay.com/default.php?page=join.php&p=sourceforge&CID=DEVDEV
_______________________________________________
NFS maillist - [email protected]
https://lists.sourceforge.net/lists/listinfo/nfs