8000 libmount: accept '\' as escape for options separator · util-linux/util-linux@f6c29ef · GitHub
[go: up one dir, main page]

Skip to content

Commit f6c29ef

Browse files
committed
libmount: accept '\' as escape for options separator
The libmount library can accept any characters as an option value when the value is quoted (e.g., foo="b,a,r"). However, overlayfs users have been using '\' as an escape character (e.g., lowerdir=foo\,bar). Although this escaping mechanism was never officially supported by libmount/mount, it worked for the old mount(2) API because it kept the options string unparsed for the mount(2) syscall. The introduction of the new mount API, which utilizes fsconfig(2) per option, has brought attention to this issue. This patch addresses the problem by introducing official support for '\' as an escape character for options separator. Suggested-by: Miklos Szeredi <miklos@szeredi.hu> References: https://lore.kernel.org/all/CAOQ4uxhgUSPkYAV8SJu-SFszkJcVO3-M4DXf46nJUtXODrPk2g@mail.gmail.com/T/#ma8e6cfc1ce7229abc089e03eed99b23b90d701e5 Signed-off-by: Karel Zak <kzak@redhat.com>
1 parent 556dac8 commit f6c29ef

File tree

2 files changed

+16
-4
lines changed

2 files changed

+16
-4
lines changed

lib/strutils.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1225,7 +1225,7 @@ int ul_optstr_next(char **optstr, char **name, size_t *namesz,
12251225
continue; /* still in quoted block */
12261226
if (!sep && p > start && *p == '=')
12271227
sep = p; /* name and value separator */
1228-
if (*p == ',')
1228+
if (*p == ',' && (p == optstr0 || *(p - 1) != '\\'))
12291229
stop = p; /* terminate the option item */
12301230
else if (*(p + 1) == '\0')
12311231
stop = p + 1; /* end of optstr */

libmount/src/hook_mount.c

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@
4545

4646
#include "mountP.h"
4747
#include "fileutils.h" /* statx() fallback */
48+
#include "strutils.h"
4849
#include "mount-api-utils.h"
4950
#include "linux_version.h"
5051

@@ -149,12 +150,23 @@ static inline int fsconfig_set_value(
149150
const char *name, const char *value)
150151
{
151152
int rc;
153+
char *p = NULL;
152154

153-
DBG(HOOK, ul_debugobj(hs, " fsconfig(name=%s,value=%s)", name,
155+
if (value && strstr(value, "\\,")) {
156+
p = strdup(value);
157+
if (!p)
158+
return -EINVAL;
159+
160+
strrem(p, '\\');
161+
value = p;
162+
}
163+
164+
DBG(HOOK, ul_debugobj(hs, " fsconfig(name=\"%s\" value=\"%s\")", name,
154165
value ? : ""));
155-
if (value)
166+
if (value) {
156167
rc = fsconfig(fd, FSCONFIG_SET_STRING, name, value, 0);
157-
else
168+
free(p);
169+
} else
158170
rc = fsconfig(fd, FSCONFIG_SET_FLAG, name, NULL, 0);
159171

160172
set_syscall_status(cxt, "fsconfig", rc == 0);

0 commit comments

Comments
 (0)
0