Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

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>

authored by

Prem Karat and committed by
Eric Van Hensbergen
a2dd43bb fd2421f5

+34 -9
+34 -9
fs/9p/v9fs.c
··· 78 78 {Opt_err, NULL} 79 79 }; 80 80 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 + 81 100 /** 82 101 * v9fs_parse_options - parse mount options into session structure 83 102 * @v9ses: existing v9fs session information ··· 116 97 /* setup defaults */ 117 98 v9ses->afid = ~0; 118 99 v9ses->debug = 0; 119 - v9ses->cache = 0; 100 + v9ses->cache = CACHE_NONE; 120 101 #ifdef CONFIG_9P_FSCACHE 121 102 v9ses->cachetag = NULL; 122 103 #endif ··· 190 171 "problem allocating copy of cache arg\n"); 191 172 goto free_and_return; 192 173 } 174 + ret = get_cache_mode(s); 175 + if (ret == -EINVAL) { 176 + kfree(s); 177 + goto free_and_return; 178 + } 193 179 194 - if (strcmp(s, "loose") == 0) 195 - v9ses->cache = CACHE_LOOSE; 196 - else if (strcmp(s, "fscache") == 0) 197 - v9ses->cache = CACHE_FSCACHE; 198 - else 199 - v9ses->cache = CACHE_NONE; 180 + v9ses->cache = ret; 200 181 kfree(s); 201 182 break; 202 183 ··· 219 200 } else { 220 201 v9ses->flags |= V9FS_ACCESS_SINGLE; 221 202 v9ses->uid = simple_strtoul(s, &e, 10); 222 - if (*e != '\0') 223 - v9ses->uid = ~0; 203 + if (*e != '\0') { 204 + ret = -EINVAL; 205 + printk(KERN_INFO "9p: Unknown access " 206 + "argument %s.\n", s); 207 + kfree(s); 208 + goto free_and_return; 209 + } 224 210 } 211 + 225 212 kfree(s); 226 213 break; 227 214