8000 mount: overlayfs options cannot have odd number of double quotes (") · Issue #3537 · util-linux/util-linux · GitHub
[go: up one dir, main page]

Skip to content
8000

mount: overlayfs options cannot have odd number of double quotes (") #3537

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
peesock opened this issue Apr 19, 2025 · 3 comments
Open

mount: overlayfs options cannot have odd number of double quotes (") #3537

peesock opened this issue Apr 19, 2025 · 3 comments

Comments

@peesock
Copy link
peesock commented Apr 19, 2025

To reproduce:

$ mkdir test
$ cd test
$ mkdir 'low"er' upper work overlay
$ mount -t overlay overlay -o lowerdir='low"er',upperdir=upper,workdir=work,userxattr overlay
mount: /home/user/test/overlay: wrong fs type, bad option, bad superblock on overlay, missing codepage or helper program, or other error.
       dmesg(1) may have more information after failed mount system call.

Dmesg (and strace) show that the lowerdir option was not provided. If upperdir uses the path with a quote, then that option is shown not to be provided.

Trying to escape the quotes with sequences like lowerdir='low\"er' and lowerdir='"low\"er"' does not work.

With an even number of quotes, it works:

$ mkdir 'low"e"r2'
$ mount -t overlay overlay -o lowerdir='low"e"r2',upperdir=upper,workdir=work,userxattr overlay
$ mountpoint overlay
overlay is a mountpoint

Using the mount() syscall however works fine.

@echoechoin
Copy link
Contributor

ul_optstr_next will not function correctly if the option string contains a quotation mark, as the open_quote flag will be set. If open_quote is True, ul_optstr_next will mistakenly interpret the text following the quotation mark as being enclosed in quotes. I am unsure how to resolve this issue.

int ul_optstr_next(char **optstr, char **name, size_t *namesz,
		   char **value, size_t *valsz)
{
		...
		if (!start)
			start = p;		/* beginning of the option item */
		if (*p == '"')
			open_quote ^= 1;	/* reverse the status */
		...

@karelzak
Copy link
Collaborator

The code supports a quotation mark to suppress the interpretation of other characters in the string. For example, you can use it for option names as well.

I believe the correct solution is to support escaping the quotation mark. It's already supported for a comma.

Something like:

diff --git a/lib/strutils.c b/lib/strutils.c
index 0cf0da96b..8dc7f2513 100644
--- a/lib/strutils.c
+++ b/lib/strutils.c
@@ -1235,7 +1235,7 @@ int ul_optstr_next(char **optstr, char **name, size_t *namesz,
                        return -EINVAL;
                if (!start)
                        start = p;              /* beginning of the option item */
-               if (*p == '"')
+               if (*p == '"' && (p == optstr0 || *(p - 1) != '\\'))
                        open_quote ^= 1;        /* reverse the status */
                if (open_quote)
                        continue;               /* still in quoted block */
@@ -1480,7 +1480,8 @@ int main(int argc, char *argv[])
                                "       %1$s --stralnumcmp <str> <str>\n"
                                "       %1$s --cstrcasecmp <str> <str>\n"
                                "       %1$s --normalize <str>\n"
-                               "       %1$s --strto{s,u}{16,32,64} <str>\n",
+                               "       %1$s --strto{s,u}{16,32,64} <str>\n"
+                               "       %1$s --optstr <str>\n",
                                argv[0]);
                exit(EXIT_FAILURE);
        }

The patch also adds --optstr to ./test_strutils help output. You can try to play with it without the mount. Just

make test_strutils
./test_strutils --optstr 'foo="bar"'

The problem is that the caller needs to care about the escape, as ul_optstr_next() is just a parser. See f6c29ef for more details.

@karelzak
Copy link
Collaborator

Do you want to prepare a patch?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants
0