Skip to content

Commit a2dd43b

Browse files
Prem Karatericvh
authored andcommitted
fs/9p: Fix invalid mount options/args
Without this fix, if any invalid mount options/args are passed while mouting the 9p fs, no error (-EINVAL) is returned and default arg value is assigned. This fix returns -EINVAL when an invalid arguement is found while parsing mount options. Signed-off-by: Prem Karat <prem.karat@linux.vnet.ibm.com> Signed-off-by: Aneesh Kumar K.V <aneesh.kumar@linux.vnet.ibm.com> Signed-off-by: Eric Van Hensbergen <ericvh@gmail.com>
1 parent fd2421f commit a2dd43b

1 file changed

Lines changed: 34 additions & 9 deletions

File tree

‎fs/9p/v9fs.c‎

Lines changed: 34 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,25 @@ static const match_table_t tokens = {
7878
{Opt_err, NULL}
7979
};
8080

81+
/* Interpret mount options for cache mode */
82+
static int get_cache_mode(char *s)
83+
{
84+
int version = -EINVAL;
85+
86+
if (!strcmp(s, "loose")) {
87+
version = CACHE_LOOSE;
88+
P9_DPRINTK(P9_DEBUG_9P, "Cache mode: loose\n");
89+
} else if (!strcmp(s, "fscache")) {
90+
version = CACHE_FSCACHE;
91+
P9_DPRINTK(P9_DEBUG_9P, "Cache mode: fscache\n");
92+
} else if (!strcmp(s, "none")) {
93+
version = CACHE_NONE;
94+
P9_DPRINTK(P9_DEBUG_9P, "Cache mode: none\n");
95+
} else
96+
printk(KERN_INFO "9p: Unknown Cache mode %s.\n", s);
97+
return version;
98+
}
99+
81100
/**
82101
* v9fs_parse_options - parse mount options into session structure
83102
* @v9ses: existing v9fs session information
@@ -97,7 +116,7 @@ static int v9fs_parse_options(struct v9fs_session_info *v9ses, char *opts)
97116
/* setup defaults */
98117
v9ses->afid = ~0;
99118
v9ses->debug = 0;
100-
v9ses->cache = 0;
119+
v9ses->cache = CACHE_NONE;
101120
#ifdef CONFIG_9P_FSCACHE
102121
v9ses->cachetag = NULL;
103122
#endif
@@ -171,13 +190,13 @@ static int v9fs_parse_options(struct v9fs_session_info *v9ses, char *opts)
171190
"problem allocating copy of cache arg\n");
172191
goto free_and_return;
173192
}
193+
ret = get_cache_mode(s);
194+
if (ret == -EINVAL) {
195+
kfree(s);
196+
goto free_and_return;
197+
}
174198

175-
if (strcmp(s, "loose") == 0)
176-
v9ses->cache = CACHE_LOOSE;
177-
else if (strcmp(s, "fscache") == 0)
178-
v9ses->cache = CACHE_FSCACHE;
179-
else
180-
v9ses->cache = CACHE_NONE;
199+
v9ses->cache = ret;
181200
kfree(s);
182201
break;
183202

@@ -200,9 +219,15 @@ static int v9fs_parse_options(struct v9fs_session_info *v9ses, char *opts)
200219
} else {
201220
v9ses->flags |= V9FS_ACCESS_SINGLE;
202221
v9ses->uid = simple_strtoul(s, &e, 10);
203-
if (*e != '\0')
204-
v9ses->uid = ~0;
222+
if (*e != '\0') {
223+
ret = -EINVAL;
224+
printk(KERN_INFO "9p: Unknown access "
225+
"argument %s.\n", s);
226+
kfree(s);
227+
goto free_and_return;
228+
}
205229
}
230+
206231
kfree(s);
207232
break;
208233

0 commit comments

Comments
 (0)