diff options
Diffstat (limited to 'kernel/sysctl.c')
-rw-r--r-- | kernel/sysctl.c | 43 |
1 files changed, 42 insertions, 1 deletions
diff --git a/kernel/sysctl.c b/kernel/sysctl.c index 14f30b4a1b64..3fb1405f3f8c 100644 --- a/kernel/sysctl.c +++ b/kernel/sysctl.c | |||
@@ -67,6 +67,8 @@ | |||
67 | #include <linux/bpf.h> | 67 | #include <linux/bpf.h> |
68 | #include <linux/mount.h> | 68 | #include <linux/mount.h> |
69 | 69 | ||
70 | #include "../lib/kstrtox.h" | ||
71 | |||
70 | #include <linux/uaccess.h> | 72 | #include <linux/uaccess.h> |
71 | #include <asm/processor.h> | 73 | #include <asm/processor.h> |
72 | 74 | ||
@@ -127,6 +129,7 @@ static int __maybe_unused one = 1; | |||
127 | static int __maybe_unused two = 2; | 129 | static int __maybe_unused two = 2; |
128 | static int __maybe_unused four = 4; | 130 | static int __maybe_unused four = 4; |
129 | static unsigned long one_ul = 1; | 131 | static unsigned long one_ul = 1; |
132 | static unsigned long long_max = LONG_MAX; | ||
130 | static int one_hundred = 100; | 133 | static int one_hundred = 100; |
131 | static int one_thousand = 1000; | 134 | static int one_thousand = 1000; |
132 | #ifdef CONFIG_PRINTK | 135 | #ifdef CONFIG_PRINTK |
@@ -1747,6 +1750,8 @@ static struct ctl_table fs_table[] = { | |||
1747 | .maxlen = sizeof(files_stat.max_files), | 1750 | .maxlen = sizeof(files_stat.max_files), |
1748 | .mode = 0644, | 1751 | .mode = 0644, |
1749 | .proc_handler = proc_doulongvec_minmax, | 1752 | .proc_handler = proc_doulongvec_minmax, |
1753 | .extra1 = &zero, | ||
1754 | .extra2 = &long_max, | ||
1750 | }, | 1755 | }, |
1751 | { | 1756 | { |
1752 | .procname = "nr_open", | 1757 | .procname = "nr_open", |
@@ -2117,6 +2122,41 @@ static void proc_skip_char(char **buf, size_t *size, const char v) | |||
2117 | } | 2122 | } |
2118 | } | 2123 | } |
2119 | 2124 | ||
2125 | /** | ||
2126 | * strtoul_lenient - parse an ASCII formatted integer from a buffer and only | ||
2127 | * fail on overflow | ||
2128 | * | ||
2129 | * @cp: kernel buffer containing the string to parse | ||
2130 | * @endp: pointer to store the trailing characters | ||
2131 | * @base: the base to use | ||
2132 | * @res: where the parsed integer will be stored | ||
2133 | * | ||
2134 | * In case of success 0 is returned and @res will contain the parsed integer, | ||
2135 | * @endp will hold any trailing characters. | ||
2136 | * This function will fail the parse on overflow. If there wasn't an overflow | ||
2137 | * the function will defer the decision what characters count as invalid to the | ||
2138 | * caller. | ||
2139 | */ | ||
2140 | static int strtoul_lenient(const char *cp, char **endp, unsigned int base, | ||
2141 | unsigned long *res) | ||
2142 | { | ||
2143 | unsigned long long result; | ||
2144 | unsigned int rv; | ||
2145 | |||
2146 | cp = _parse_integer_fixup_radix(cp, &base); | ||
2147 | rv = _parse_integer(cp, base, &result); | ||
2148 | if ((rv & KSTRTOX_OVERFLOW) || (result != (unsigned long)result)) | ||
2149 | return -ERANGE; | ||
2150 | |||
2151 | cp += rv; | ||
2152 | |||
2153 | if (endp) | ||
2154 | *endp = (char *)cp; | ||
2155 | |||
2156 | *res = (unsigned long)result; | ||
2157 | return 0; | ||
2158 | } | ||
2159 | |||
2120 | #define TMPBUFLEN 22 | 2160 | #define TMPBUFLEN 22 |
2121 | /** | 2161 | /** |
2122 | * proc_get_long - reads an ASCII formatted integer from a user buffer | 2162 | * proc_get_long - reads an ASCII formatted integer from a user buffer |
@@ -2160,7 +2200,8 @@ static int proc_get_long(char **buf, size_t *size, | |||
2160 | if (!isdigit(*p)) | 2200 | if (!isdigit(*p)) |
2161 | return -EINVAL; | 2201 | return -EINVAL; |
2162 | 2202 | ||
2163 | *val = simple_strtoul(p, &p, 0); | 2203 | if (strtoul_lenient(p, &p, 0, val)) |
2204 | return -EINVAL; | ||
2164 | 2205 | ||
2165 | len = p - tmp; | 2206 | len = p - tmp; |
2166 | 2207 | ||