diff options
Diffstat (limited to 'kernel')
-rw-r--r-- | kernel/sysctl.c | 551 | ||||
-rw-r--r-- | kernel/sysctl_binary.c | 1 |
2 files changed, 390 insertions, 162 deletions
diff --git a/kernel/sysctl.c b/kernel/sysctl.c index 8686b0f5fc12..bcfb79e94ec7 100644 --- a/kernel/sysctl.c +++ b/kernel/sysctl.c | |||
@@ -2040,8 +2040,132 @@ int proc_dostring(struct ctl_table *table, int write, | |||
2040 | buffer, lenp, ppos); | 2040 | buffer, lenp, ppos); |
2041 | } | 2041 | } |
2042 | 2042 | ||
2043 | static size_t proc_skip_spaces(char **buf) | ||
2044 | { | ||
2045 | size_t ret; | ||
2046 | char *tmp = skip_spaces(*buf); | ||
2047 | ret = tmp - *buf; | ||
2048 | *buf = tmp; | ||
2049 | return ret; | ||
2050 | } | ||
2051 | |||
2052 | static void proc_skip_char(char **buf, size_t *size, const char v) | ||
2053 | { | ||
2054 | while (*size) { | ||
2055 | if (**buf != v) | ||
2056 | break; | ||
2057 | (*size)--; | ||
2058 | (*buf)++; | ||
2059 | } | ||
2060 | } | ||
2061 | |||
2062 | #define TMPBUFLEN 22 | ||
2063 | /** | ||
2064 | * proc_get_long - reads an ASCII formated integer from a user buffer | ||
2065 | * | ||
2066 | * @buf - a kernel buffer | ||
2067 | * @size - size of the kernel buffer | ||
2068 | * @val - this is where the number will be stored | ||
2069 | * @neg - set to %TRUE if number is negative | ||
2070 | * @perm_tr - a vector which contains the allowed trailers | ||
2071 | * @perm_tr_len - size of the perm_tr vector | ||
2072 | * @tr - pointer to store the trailer character | ||
2073 | * | ||
2074 | * In case of success 0 is returned and buf and size are updated with | ||
2075 | * the amount of bytes read. If tr is non NULL and a trailing | ||
2076 | * character exist (size is non zero after returning from this | ||
2077 | * function) tr is updated with the trailing character. | ||
2078 | */ | ||
2079 | static int proc_get_long(char **buf, size_t *size, | ||
2080 | unsigned long *val, bool *neg, | ||
2081 | const char *perm_tr, unsigned perm_tr_len, char *tr) | ||
2082 | { | ||
2083 | int len; | ||
2084 | char *p, tmp[TMPBUFLEN]; | ||
2085 | |||
2086 | if (!*size) | ||
2087 | return -EINVAL; | ||
2088 | |||
2089 | len = *size; | ||
2090 | if (len > TMPBUFLEN - 1) | ||
2091 | len = TMPBUFLEN - 1; | ||
2092 | |||
2093 | memcpy(tmp, *buf, len); | ||
2094 | |||
2095 | tmp[len] = 0; | ||
2096 | p = tmp; | ||
2097 | if (*p == '-' && *size > 1) { | ||
2098 | *neg = true; | ||
2099 | p++; | ||
2100 | } else | ||
2101 | *neg = false; | ||
2102 | if (!isdigit(*p)) | ||
2103 | return -EINVAL; | ||
2104 | |||
2105 | *val = simple_strtoul(p, &p, 0); | ||
2106 | |||
2107 | len = p - tmp; | ||
2108 | |||
2109 | /* We don't know if the next char is whitespace thus we may accept | ||
2110 | * invalid integers (e.g. 1234...a) or two integers instead of one | ||
2111 | * (e.g. 123...1). So lets not allow such large numbers. */ | ||
2112 | if (len == TMPBUFLEN - 1) | ||
2113 | return -EINVAL; | ||
2114 | |||
2115 | if (len < *size && perm_tr_len && !memchr(perm_tr, *p, perm_tr_len)) | ||
2116 | return -EINVAL; | ||
2117 | |||
2118 | if (tr && (len < *size)) | ||
2119 | *tr = *p; | ||
2120 | |||
2121 | *buf += len; | ||
2122 | *size -= len; | ||
2123 | |||
2124 | return 0; | ||
2125 | } | ||
2126 | |||
2127 | /** | ||
2128 | * proc_put_long - coverts an integer to a decimal ASCII formated string | ||
2129 | * | ||
2130 | * @buf - the user buffer | ||
2131 | * @size - the size of the user buffer | ||
2132 | * @val - the integer to be converted | ||
2133 | * @neg - sign of the number, %TRUE for negative | ||
2134 | * | ||
2135 | * In case of success 0 is returned and buf and size are updated with | ||
2136 | * the amount of bytes read. | ||
2137 | */ | ||
2138 | static int proc_put_long(void __user **buf, size_t *size, unsigned long val, | ||
2139 | bool neg) | ||
2140 | { | ||
2141 | int len; | ||
2142 | char tmp[TMPBUFLEN], *p = tmp; | ||
2143 | |||
2144 | sprintf(p, "%s%lu", neg ? "-" : "", val); | ||
2145 | len = strlen(tmp); | ||
2146 | if (len > *size) | ||
2147 | len = *size; | ||
2148 | if (copy_to_user(*buf, tmp, len)) | ||
2149 | return -EFAULT; | ||
2150 | *size -= len; | ||
2151 | *buf += len; | ||
2152 | return 0; | ||
2153 | } | ||
2154 | #undef TMPBUFLEN | ||
2155 | |||
2156 | static int proc_put_char(void __user **buf, size_t *size, char c) | ||
2157 | { | ||
2158 | if (*size) { | ||
2159 | char __user **buffer = (char __user **)buf; | ||
2160 | if (put_user(c, *buffer)) | ||
2161 | return -EFAULT; | ||
2162 | (*size)--, (*buffer)++; | ||
2163 | *buf = *buffer; | ||
2164 | } | ||
2165 | return 0; | ||
2166 | } | ||
2043 | 2167 | ||
2044 | static int do_proc_dointvec_conv(int *negp, unsigned long *lvalp, | 2168 | static int do_proc_dointvec_conv(bool *negp, unsigned long *lvalp, |
2045 | int *valp, | 2169 | int *valp, |
2046 | int write, void *data) | 2170 | int write, void *data) |
2047 | { | 2171 | { |
@@ -2050,33 +2174,31 @@ static int do_proc_dointvec_conv(int *negp, unsigned long *lvalp, | |||
2050 | } else { | 2174 | } else { |
2051 | int val = *valp; | 2175 | int val = *valp; |
2052 | if (val < 0) { | 2176 | if (val < 0) { |
2053 | *negp = -1; | 2177 | *negp = true; |
2054 | *lvalp = (unsigned long)-val; | 2178 | *lvalp = (unsigned long)-val; |
2055 | } else { | 2179 | } else { |
2056 | *negp = 0; | 2180 | *negp = false; |
2057 | *lvalp = (unsigned long)val; | 2181 | *lvalp = (unsigned long)val; |
2058 | } | 2182 | } |
2059 | } | 2183 | } |
2060 | return 0; | 2184 | return 0; |
2061 | } | 2185 | } |
2062 | 2186 | ||
2187 | static const char proc_wspace_sep[] = { ' ', '\t', '\n' }; | ||
2188 | |||
2063 | static int __do_proc_dointvec(void *tbl_data, struct ctl_table *table, | 2189 | static int __do_proc_dointvec(void *tbl_data, struct ctl_table *table, |
2064 | int write, void __user *buffer, | 2190 | int write, void __user *buffer, |
2065 | size_t *lenp, loff_t *ppos, | 2191 | size_t *lenp, loff_t *ppos, |
2066 | int (*conv)(int *negp, unsigned long *lvalp, int *valp, | 2192 | int (*conv)(bool *negp, unsigned long *lvalp, int *valp, |
2067 | int write, void *data), | 2193 | int write, void *data), |
2068 | void *data) | 2194 | void *data) |
2069 | { | 2195 | { |
2070 | #define TMPBUFLEN 21 | 2196 | int *i, vleft, first = 1, err = 0; |
2071 | int *i, vleft, first = 1, neg; | 2197 | unsigned long page = 0; |
2072 | unsigned long lval; | 2198 | size_t left; |
2073 | size_t left, len; | 2199 | char *kbuf; |
2074 | 2200 | ||
2075 | char buf[TMPBUFLEN], *p; | 2201 | if (!tbl_data || !table->maxlen || !*lenp || (*ppos && !write)) { |
2076 | char __user *s = buffer; | ||
2077 | |||
2078 | if (!tbl_data || !table->maxlen || !*lenp || | ||
2079 | (*ppos && !write)) { | ||
2080 | *lenp = 0; | 2202 | *lenp = 0; |
2081 | return 0; | 2203 | return 0; |
2082 | } | 2204 | } |
@@ -2088,89 +2210,69 @@ static int __do_proc_dointvec(void *tbl_data, struct ctl_table *table, | |||
2088 | if (!conv) | 2210 | if (!conv) |
2089 | conv = do_proc_dointvec_conv; | 2211 | conv = do_proc_dointvec_conv; |
2090 | 2212 | ||
2213 | if (write) { | ||
2214 | if (left > PAGE_SIZE - 1) | ||
2215 | left = PAGE_SIZE - 1; | ||
2216 | page = __get_free_page(GFP_TEMPORARY); | ||
2217 | kbuf = (char *) page; | ||
2218 | if (!kbuf) | ||
2219 | return -ENOMEM; | ||
2220 | if (copy_from_user(kbuf, buffer, left)) { | ||
2221 | err = -EFAULT; | ||
2222 | goto free; | ||
2223 | } | ||
2224 | kbuf[left] = 0; | ||
2225 | } | ||
2226 | |||
2091 | for (; left && vleft--; i++, first=0) { | 2227 | for (; left && vleft--; i++, first=0) { |
2092 | if (write) { | 2228 | unsigned long lval; |
2093 | while (left) { | 2229 | bool neg; |
2094 | char c; | ||
2095 | if (get_user(c, s)) | ||
2096 | return -EFAULT; | ||
2097 | if (!isspace(c)) | ||
2098 | break; | ||
2099 | left--; | ||
2100 | s++; | ||
2101 | } | ||
2102 | if (!left) | ||
2103 | break; | ||
2104 | neg = 0; | ||
2105 | len = left; | ||
2106 | if (len > sizeof(buf) - 1) | ||
2107 | len = sizeof(buf) - 1; | ||
2108 | if (copy_from_user(buf, s, len)) | ||
2109 | return -EFAULT; | ||
2110 | buf[len] = 0; | ||
2111 | p = buf; | ||
2112 | if (*p == '-' && left > 1) { | ||
2113 | neg = 1; | ||
2114 | p++; | ||
2115 | } | ||
2116 | if (*p < '0' || *p > '9') | ||
2117 | break; | ||
2118 | 2230 | ||
2119 | lval = simple_strtoul(p, &p, 0); | 2231 | if (write) { |
2232 | left -= proc_skip_spaces(&kbuf); | ||
2120 | 2233 | ||
2121 | len = p-buf; | 2234 | err = proc_get_long(&kbuf, &left, &lval, &neg, |
2122 | if ((len < left) && *p && !isspace(*p)) | 2235 | proc_wspace_sep, |
2236 | sizeof(proc_wspace_sep), NULL); | ||
2237 | if (err) | ||
2123 | break; | 2238 | break; |
2124 | s += len; | 2239 | if (conv(&neg, &lval, i, 1, data)) { |
2125 | left -= len; | 2240 | err = -EINVAL; |
2126 | |||
2127 | if (conv(&neg, &lval, i, 1, data)) | ||
2128 | break; | 2241 | break; |
2242 | } | ||
2129 | } else { | 2243 | } else { |
2130 | p = buf; | 2244 | if (conv(&neg, &lval, i, 0, data)) { |
2245 | err = -EINVAL; | ||
2246 | break; | ||
2247 | } | ||
2131 | if (!first) | 2248 | if (!first) |
2132 | *p++ = '\t'; | 2249 | err = proc_put_char(&buffer, &left, '\t'); |
2133 | 2250 | if (err) | |
2134 | if (conv(&neg, &lval, i, 0, data)) | 2251 | break; |
2252 | err = proc_put_long(&buffer, &left, lval, neg); | ||
2253 | if (err) | ||
2135 | break; | 2254 | break; |
2136 | |||
2137 | sprintf(p, "%s%lu", neg ? "-" : "", lval); | ||
2138 | len = strlen(buf); | ||
2139 | if (len > left) | ||
2140 | len = left; | ||
2141 | if(copy_to_user(s, buf, len)) | ||
2142 | return -EFAULT; | ||
2143 | left -= len; | ||
2144 | s += len; | ||
2145 | } | 2255 | } |
2146 | } | 2256 | } |
2147 | 2257 | ||
2148 | if (!write && !first && left) { | 2258 | if (!write && !first && left && !err) |
2149 | if(put_user('\n', s)) | 2259 | err = proc_put_char(&buffer, &left, '\n'); |
2150 | return -EFAULT; | 2260 | if (write && !err) |
2151 | left--, s++; | 2261 | left -= proc_skip_spaces(&kbuf); |
2152 | } | 2262 | free: |
2153 | if (write) { | 2263 | if (write) { |
2154 | while (left) { | 2264 | free_page(page); |
2155 | char c; | 2265 | if (first) |
2156 | if (get_user(c, s++)) | 2266 | return err ? : -EINVAL; |
2157 | return -EFAULT; | ||
2158 | if (!isspace(c)) | ||
2159 | break; | ||
2160 | left--; | ||
2161 | } | ||
2162 | } | 2267 | } |
2163 | if (write && first) | ||
2164 | return -EINVAL; | ||
2165 | *lenp -= left; | 2268 | *lenp -= left; |
2166 | *ppos += *lenp; | 2269 | *ppos += *lenp; |
2167 | return 0; | 2270 | return err; |
2168 | #undef TMPBUFLEN | ||
2169 | } | 2271 | } |
2170 | 2272 | ||
2171 | static int do_proc_dointvec(struct ctl_table *table, int write, | 2273 | static int do_proc_dointvec(struct ctl_table *table, int write, |
2172 | void __user *buffer, size_t *lenp, loff_t *ppos, | 2274 | void __user *buffer, size_t *lenp, loff_t *ppos, |
2173 | int (*conv)(int *negp, unsigned long *lvalp, int *valp, | 2275 | int (*conv)(bool *negp, unsigned long *lvalp, int *valp, |
2174 | int write, void *data), | 2276 | int write, void *data), |
2175 | void *data) | 2277 | void *data) |
2176 | { | 2278 | { |
@@ -2238,8 +2340,8 @@ struct do_proc_dointvec_minmax_conv_param { | |||
2238 | int *max; | 2340 | int *max; |
2239 | }; | 2341 | }; |
2240 | 2342 | ||
2241 | static int do_proc_dointvec_minmax_conv(int *negp, unsigned long *lvalp, | 2343 | static int do_proc_dointvec_minmax_conv(bool *negp, unsigned long *lvalp, |
2242 | int *valp, | 2344 | int *valp, |
2243 | int write, void *data) | 2345 | int write, void *data) |
2244 | { | 2346 | { |
2245 | struct do_proc_dointvec_minmax_conv_param *param = data; | 2347 | struct do_proc_dointvec_minmax_conv_param *param = data; |
@@ -2252,10 +2354,10 @@ static int do_proc_dointvec_minmax_conv(int *negp, unsigned long *lvalp, | |||
2252 | } else { | 2354 | } else { |
2253 | int val = *valp; | 2355 | int val = *valp; |
2254 | if (val < 0) { | 2356 | if (val < 0) { |
2255 | *negp = -1; | 2357 | *negp = true; |
2256 | *lvalp = (unsigned long)-val; | 2358 | *lvalp = (unsigned long)-val; |
2257 | } else { | 2359 | } else { |
2258 | *negp = 0; | 2360 | *negp = false; |
2259 | *lvalp = (unsigned long)val; | 2361 | *lvalp = (unsigned long)val; |
2260 | } | 2362 | } |
2261 | } | 2363 | } |
@@ -2295,102 +2397,78 @@ static int __do_proc_doulongvec_minmax(void *data, struct ctl_table *table, int | |||
2295 | unsigned long convmul, | 2397 | unsigned long convmul, |
2296 | unsigned long convdiv) | 2398 | unsigned long convdiv) |
2297 | { | 2399 | { |
2298 | #define TMPBUFLEN 21 | 2400 | unsigned long *i, *min, *max; |
2299 | unsigned long *i, *min, *max, val; | 2401 | int vleft, first = 1, err = 0; |
2300 | int vleft, first=1, neg; | 2402 | unsigned long page = 0; |
2301 | size_t len, left; | 2403 | size_t left; |
2302 | char buf[TMPBUFLEN], *p; | 2404 | char *kbuf; |
2303 | char __user *s = buffer; | 2405 | |
2304 | 2406 | if (!data || !table->maxlen || !*lenp || (*ppos && !write)) { | |
2305 | if (!data || !table->maxlen || !*lenp || | ||
2306 | (*ppos && !write)) { | ||
2307 | *lenp = 0; | 2407 | *lenp = 0; |
2308 | return 0; | 2408 | return 0; |
2309 | } | 2409 | } |
2310 | 2410 | ||
2311 | i = (unsigned long *) data; | 2411 | i = (unsigned long *) data; |
2312 | min = (unsigned long *) table->extra1; | 2412 | min = (unsigned long *) table->extra1; |
2313 | max = (unsigned long *) table->extra2; | 2413 | max = (unsigned long *) table->extra2; |
2314 | vleft = table->maxlen / sizeof(unsigned long); | 2414 | vleft = table->maxlen / sizeof(unsigned long); |
2315 | left = *lenp; | 2415 | left = *lenp; |
2316 | 2416 | ||
2417 | if (write) { | ||
2418 | if (left > PAGE_SIZE - 1) | ||
2419 | left = PAGE_SIZE - 1; | ||
2420 | page = __get_free_page(GFP_TEMPORARY); | ||
2421 | kbuf = (char *) page; | ||
2422 | if (!kbuf) | ||
2423 | return -ENOMEM; | ||
2424 | if (copy_from_user(kbuf, buffer, left)) { | ||
2425 | err = -EFAULT; | ||
2426 | goto free; | ||
2427 | } | ||
2428 | kbuf[left] = 0; | ||
2429 | } | ||
2430 | |||
2317 | for (; left && vleft--; i++, min++, max++, first=0) { | 2431 | for (; left && vleft--; i++, min++, max++, first=0) { |
2432 | unsigned long val; | ||
2433 | |||
2318 | if (write) { | 2434 | if (write) { |
2319 | while (left) { | 2435 | bool neg; |
2320 | char c; | 2436 | |
2321 | if (get_user(c, s)) | 2437 | left -= proc_skip_spaces(&kbuf); |
2322 | return -EFAULT; | 2438 | |
2323 | if (!isspace(c)) | 2439 | err = proc_get_long(&kbuf, &left, &val, &neg, |
2324 | break; | 2440 | proc_wspace_sep, |
2325 | left--; | 2441 | sizeof(proc_wspace_sep), NULL); |
2326 | s++; | 2442 | if (err) |
2327 | } | ||
2328 | if (!left) | ||
2329 | break; | ||
2330 | neg = 0; | ||
2331 | len = left; | ||
2332 | if (len > TMPBUFLEN-1) | ||
2333 | len = TMPBUFLEN-1; | ||
2334 | if (copy_from_user(buf, s, len)) | ||
2335 | return -EFAULT; | ||
2336 | buf[len] = 0; | ||
2337 | p = buf; | ||
2338 | if (*p == '-' && left > 1) { | ||
2339 | neg = 1; | ||
2340 | p++; | ||
2341 | } | ||
2342 | if (*p < '0' || *p > '9') | ||
2343 | break; | ||
2344 | val = simple_strtoul(p, &p, 0) * convmul / convdiv ; | ||
2345 | len = p-buf; | ||
2346 | if ((len < left) && *p && !isspace(*p)) | ||
2347 | break; | 2443 | break; |
2348 | if (neg) | 2444 | if (neg) |
2349 | val = -val; | ||
2350 | s += len; | ||
2351 | left -= len; | ||
2352 | |||
2353 | if(neg) | ||
2354 | continue; | 2445 | continue; |
2355 | if ((min && val < *min) || (max && val > *max)) | 2446 | if ((min && val < *min) || (max && val > *max)) |
2356 | continue; | 2447 | continue; |
2357 | *i = val; | 2448 | *i = val; |
2358 | } else { | 2449 | } else { |
2359 | p = buf; | 2450 | val = convdiv * (*i) / convmul; |
2360 | if (!first) | 2451 | if (!first) |
2361 | *p++ = '\t'; | 2452 | err = proc_put_char(&buffer, &left, '\t'); |
2362 | sprintf(p, "%lu", convdiv * (*i) / convmul); | 2453 | err = proc_put_long(&buffer, &left, val, false); |
2363 | len = strlen(buf); | 2454 | if (err) |
2364 | if (len > left) | 2455 | break; |
2365 | len = left; | ||
2366 | if(copy_to_user(s, buf, len)) | ||
2367 | return -EFAULT; | ||
2368 | left -= len; | ||
2369 | s += len; | ||
2370 | } | 2456 | } |
2371 | } | 2457 | } |
2372 | 2458 | ||
2373 | if (!write && !first && left) { | 2459 | if (!write && !first && left && !err) |
2374 | if(put_user('\n', s)) | 2460 | err = proc_put_char(&buffer, &left, '\n'); |
2375 | return -EFAULT; | 2461 | if (write && !err) |
2376 | left--, s++; | 2462 | left -= proc_skip_spaces(&kbuf); |
2377 | } | 2463 | free: |
2378 | if (write) { | 2464 | if (write) { |
2379 | while (left) { | 2465 | free_page(page); |
2380 | char c; | 2466 | if (first) |
2381 | if (get_user(c, s++)) | 2467 | return err ? : -EINVAL; |
2382 | return -EFAULT; | ||
2383 | if (!isspace(c)) | ||
2384 | break; | ||
2385 | left--; | ||
2386 | } | ||
2387 | } | 2468 | } |
2388 | if (write && first) | ||
2389 | return -EINVAL; | ||
2390 | *lenp -= left; | 2469 | *lenp -= left; |
2391 | *ppos += *lenp; | 2470 | *ppos += *lenp; |
2392 | return 0; | 2471 | return err; |
2393 | #undef TMPBUFLEN | ||
2394 | } | 2472 | } |
2395 | 2473 | ||
2396 | static int do_proc_doulongvec_minmax(struct ctl_table *table, int write, | 2474 | static int do_proc_doulongvec_minmax(struct ctl_table *table, int write, |
@@ -2451,7 +2529,7 @@ int proc_doulongvec_ms_jiffies_minmax(struct ctl_table *table, int write, | |||
2451 | } | 2529 | } |
2452 | 2530 | ||
2453 | 2531 | ||
2454 | static int do_proc_dointvec_jiffies_conv(int *negp, unsigned long *lvalp, | 2532 | static int do_proc_dointvec_jiffies_conv(bool *negp, unsigned long *lvalp, |
2455 | int *valp, | 2533 | int *valp, |
2456 | int write, void *data) | 2534 | int write, void *data) |
2457 | { | 2535 | { |
@@ -2463,10 +2541,10 @@ static int do_proc_dointvec_jiffies_conv(int *negp, unsigned long *lvalp, | |||
2463 | int val = *valp; | 2541 | int val = *valp; |
2464 | unsigned long lval; | 2542 | unsigned long lval; |
2465 | if (val < 0) { | 2543 | if (val < 0) { |
2466 | *negp = -1; | 2544 | *negp = true; |
2467 | lval = (unsigned long)-val; | 2545 | lval = (unsigned long)-val; |
2468 | } else { | 2546 | } else { |
2469 | *negp = 0; | 2547 | *negp = false; |
2470 | lval = (unsigned long)val; | 2548 | lval = (unsigned long)val; |
2471 | } | 2549 | } |
2472 | *lvalp = lval / HZ; | 2550 | *lvalp = lval / HZ; |
@@ -2474,7 +2552,7 @@ static int do_proc_dointvec_jiffies_conv(int *negp, unsigned long *lvalp, | |||
2474 | return 0; | 2552 | return 0; |
2475 | } | 2553 | } |
2476 | 2554 | ||
2477 | static int do_proc_dointvec_userhz_jiffies_conv(int *negp, unsigned long *lvalp, | 2555 | static int do_proc_dointvec_userhz_jiffies_conv(bool *negp, unsigned long *lvalp, |
2478 | int *valp, | 2556 | int *valp, |
2479 | int write, void *data) | 2557 | int write, void *data) |
2480 | { | 2558 | { |
@@ -2486,10 +2564,10 @@ static int do_proc_dointvec_userhz_jiffies_conv(int *negp, unsigned long *lvalp, | |||
2486 | int val = *valp; | 2564 | int val = *valp; |
2487 | unsigned long lval; | 2565 | unsigned long lval; |
2488 | if (val < 0) { | 2566 | if (val < 0) { |
2489 | *negp = -1; | 2567 | *negp = true; |
2490 | lval = (unsigned long)-val; | 2568 | lval = (unsigned long)-val; |
2491 | } else { | 2569 | } else { |
2492 | *negp = 0; | 2570 | *negp = false; |
2493 | lval = (unsigned long)val; | 2571 | lval = (unsigned long)val; |
2494 | } | 2572 | } |
2495 | *lvalp = jiffies_to_clock_t(lval); | 2573 | *lvalp = jiffies_to_clock_t(lval); |
@@ -2497,7 +2575,7 @@ static int do_proc_dointvec_userhz_jiffies_conv(int *negp, unsigned long *lvalp, | |||
2497 | return 0; | 2575 | return 0; |
2498 | } | 2576 | } |
2499 | 2577 | ||
2500 | static int do_proc_dointvec_ms_jiffies_conv(int *negp, unsigned long *lvalp, | 2578 | static int do_proc_dointvec_ms_jiffies_conv(bool *negp, unsigned long *lvalp, |
2501 | int *valp, | 2579 | int *valp, |
2502 | int write, void *data) | 2580 | int write, void *data) |
2503 | { | 2581 | { |
@@ -2507,10 +2585,10 @@ static int do_proc_dointvec_ms_jiffies_conv(int *negp, unsigned long *lvalp, | |||
2507 | int val = *valp; | 2585 | int val = *valp; |
2508 | unsigned long lval; | 2586 | unsigned long lval; |
2509 | if (val < 0) { | 2587 | if (val < 0) { |
2510 | *negp = -1; | 2588 | *negp = true; |
2511 | lval = (unsigned long)-val; | 2589 | lval = (unsigned long)-val; |
2512 | } else { | 2590 | } else { |
2513 | *negp = 0; | 2591 | *negp = false; |
2514 | lval = (unsigned long)val; | 2592 | lval = (unsigned long)val; |
2515 | } | 2593 | } |
2516 | *lvalp = jiffies_to_msecs(lval); | 2594 | *lvalp = jiffies_to_msecs(lval); |
@@ -2607,6 +2685,157 @@ static int proc_do_cad_pid(struct ctl_table *table, int write, | |||
2607 | return 0; | 2685 | return 0; |
2608 | } | 2686 | } |
2609 | 2687 | ||
2688 | /** | ||
2689 | * proc_do_large_bitmap - read/write from/to a large bitmap | ||
2690 | * @table: the sysctl table | ||
2691 | * @write: %TRUE if this is a write to the sysctl file | ||
2692 | * @buffer: the user buffer | ||
2693 | * @lenp: the size of the user buffer | ||
2694 | * @ppos: file position | ||
2695 | * | ||
2696 | * The bitmap is stored at table->data and the bitmap length (in bits) | ||
2697 | * in table->maxlen. | ||
2698 | * | ||
2699 | * We use a range comma separated format (e.g. 1,3-4,10-10) so that | ||
2700 | * large bitmaps may be represented in a compact manner. Writing into | ||
2701 | * the file will clear the bitmap then update it with the given input. | ||
2702 | * | ||
2703 | * Returns 0 on success. | ||
2704 | */ | ||
2705 | int proc_do_large_bitmap(struct ctl_table *table, int write, | ||
2706 | void __user *buffer, size_t *lenp, loff_t *ppos) | ||
2707 | { | ||
2708 | int err = 0; | ||
2709 | bool first = 1; | ||
2710 | size_t left = *lenp; | ||
2711 | unsigned long bitmap_len = table->maxlen; | ||
2712 | unsigned long *bitmap = (unsigned long *) table->data; | ||
2713 | unsigned long *tmp_bitmap = NULL; | ||
2714 | char tr_a[] = { '-', ',', '\n' }, tr_b[] = { ',', '\n', 0 }, c; | ||
2715 | |||
2716 | if (!bitmap_len || !left || (*ppos && !write)) { | ||
2717 | *lenp = 0; | ||
2718 | return 0; | ||
2719 | } | ||
2720 | |||
2721 | if (write) { | ||
2722 | unsigned long page = 0; | ||
2723 | char *kbuf; | ||
2724 | |||
2725 | if (left > PAGE_SIZE - 1) | ||
2726 | left = PAGE_SIZE - 1; | ||
2727 | |||
2728 | page = __get_free_page(GFP_TEMPORARY); | ||
2729 | kbuf = (char *) page; | ||
2730 | if (!kbuf) | ||
2731 | return -ENOMEM; | ||
2732 | if (copy_from_user(kbuf, buffer, left)) { | ||
2733 | free_page(page); | ||
2734 | return -EFAULT; | ||
2735 | } | ||
2736 | kbuf[left] = 0; | ||
2737 | |||
2738 | tmp_bitmap = kzalloc(BITS_TO_LONGS(bitmap_len) * sizeof(unsigned long), | ||
2739 | GFP_KERNEL); | ||
2740 | if (!tmp_bitmap) { | ||
2741 | free_page(page); | ||
2742 | return -ENOMEM; | ||
2743 | } | ||
2744 | proc_skip_char(&kbuf, &left, '\n'); | ||
2745 | while (!err && left) { | ||
2746 | unsigned long val_a, val_b; | ||
2747 | bool neg; | ||
2748 | |||
2749 | err = proc_get_long(&kbuf, &left, &val_a, &neg, tr_a, | ||
2750 | sizeof(tr_a), &c); | ||
2751 | if (err) | ||
2752 | break; | ||
2753 | if (val_a >= bitmap_len || neg) { | ||
2754 | err = -EINVAL; | ||
2755 | break; | ||
2756 | } | ||
2757 | |||
2758 | val_b = val_a; | ||
2759 | if (left) { | ||
2760 | kbuf++; | ||
2761 | left--; | ||
2762 | } | ||
2763 | |||
2764 | if (c == '-') { | ||
2765 | err = proc_get_long(&kbuf, &left, &val_b, | ||
2766 | &neg, tr_b, sizeof(tr_b), | ||
2767 | &c); | ||
2768 | if (err) | ||
2769 | break; | ||
2770 | if (val_b >= bitmap_len || neg || | ||
2771 | val_a > val_b) { | ||
2772 | err = -EINVAL; | ||
2773 | break; | ||
2774 | } | ||
2775 | if (left) { | ||
2776 | kbuf++; | ||
2777 | left--; | ||
2778 | } | ||
2779 | } | ||
2780 | |||
2781 | while (val_a <= val_b) | ||
2782 | set_bit(val_a++, tmp_bitmap); | ||
2783 | |||
2784 | first = 0; | ||
2785 | proc_skip_char(&kbuf, &left, '\n'); | ||
2786 | } | ||
2787 | free_page(page); | ||
2788 | } else { | ||
2789 | unsigned long bit_a, bit_b = 0; | ||
2790 | |||
2791 | while (left) { | ||
2792 | bit_a = find_next_bit(bitmap, bitmap_len, bit_b); | ||
2793 | if (bit_a >= bitmap_len) | ||
2794 | break; | ||
2795 | bit_b = find_next_zero_bit(bitmap, bitmap_len, | ||
2796 | bit_a + 1) - 1; | ||
2797 | |||
2798 | if (!first) { | ||
2799 | err = proc_put_char(&buffer, &left, ','); | ||
2800 | if (err) | ||
2801 | break; | ||
2802 | } | ||
2803 | err = proc_put_long(&buffer, &left, bit_a, false); | ||
2804 | if (err) | ||
2805 | break; | ||
2806 | if (bit_a != bit_b) { | ||
2807 | err = proc_put_char(&buffer, &left, '-'); | ||
2808 | if (err) | ||
2809 | break; | ||
2810 | err = proc_put_long(&buffer, &left, bit_b, false); | ||
2811 | if (err) | ||
2812 | break; | ||
2813 | } | ||
2814 | |||
2815 | first = 0; bit_b++; | ||
2816 | } | ||
2817 | if (!err) | ||
2818 | err = proc_put_char(&buffer, &left, '\n'); | ||
2819 | } | ||
2820 | |||
2821 | if (!err) { | ||
2822 | if (write) { | ||
2823 | if (*ppos) | ||
2824 | bitmap_or(bitmap, bitmap, tmp_bitmap, bitmap_len); | ||
2825 | else | ||
2826 | memcpy(bitmap, tmp_bitmap, | ||
2827 | BITS_TO_LONGS(bitmap_len) * sizeof(unsigned long)); | ||
2828 | } | ||
2829 | kfree(tmp_bitmap); | ||
2830 | *lenp -= left; | ||
2831 | *ppos += *lenp; | ||
2832 | return 0; | ||
2833 | } else { | ||
2834 | kfree(tmp_bitmap); | ||
2835 | return err; | ||
2836 | } | ||
2837 | } | ||
2838 | |||
2610 | #else /* CONFIG_PROC_FS */ | 2839 | #else /* CONFIG_PROC_FS */ |
2611 | 2840 | ||
2612 | int proc_dostring(struct ctl_table *table, int write, | 2841 | int proc_dostring(struct ctl_table *table, int write, |
diff --git a/kernel/sysctl_binary.c b/kernel/sysctl_binary.c index 59030570f5ca..937d31dc8566 100644 --- a/kernel/sysctl_binary.c +++ b/kernel/sysctl_binary.c | |||
@@ -224,7 +224,6 @@ static const struct bin_table bin_net_ipv4_route_table[] = { | |||
224 | { CTL_INT, NET_IPV4_ROUTE_MTU_EXPIRES, "mtu_expires" }, | 224 | { CTL_INT, NET_IPV4_ROUTE_MTU_EXPIRES, "mtu_expires" }, |
225 | { CTL_INT, NET_IPV4_ROUTE_MIN_PMTU, "min_pmtu" }, | 225 | { CTL_INT, NET_IPV4_ROUTE_MIN_PMTU, "min_pmtu" }, |
226 | { CTL_INT, NET_IPV4_ROUTE_MIN_ADVMSS, "min_adv_mss" }, | 226 | { CTL_INT, NET_IPV4_ROUTE_MIN_ADVMSS, "min_adv_mss" }, |
227 | { CTL_INT, NET_IPV4_ROUTE_SECRET_INTERVAL, "secret_interval" }, | ||
228 | {} | 227 | {} |
229 | }; | 228 | }; |
230 | 229 | ||