Merge tag 'pstore-v5.1-rc1' of git://git.kernel.org/pub/scm/linux/kernel/git/kees...
[linux-2.6-microblaze.git] / kernel / sysctl.c
index 7578e21..3fb1405 100644 (file)
@@ -67,6 +67,8 @@
 #include <linux/bpf.h>
 #include <linux/mount.h>
 
+#include "../lib/kstrtox.h"
+
 #include <linux/uaccess.h>
 #include <asm/processor.h>
 
@@ -127,6 +129,7 @@ static int __maybe_unused one = 1;
 static int __maybe_unused two = 2;
 static int __maybe_unused four = 4;
 static unsigned long one_ul = 1;
+static unsigned long long_max = LONG_MAX;
 static int one_hundred = 100;
 static int one_thousand = 1000;
 #ifdef CONFIG_PRINTK
@@ -472,6 +475,17 @@ static struct ctl_table kern_table[] = {
                .extra1         = &one,
        },
 #endif
+#if defined(CONFIG_ENERGY_MODEL) && defined(CONFIG_CPU_FREQ_GOV_SCHEDUTIL)
+       {
+               .procname       = "sched_energy_aware",
+               .data           = &sysctl_sched_energy_aware,
+               .maxlen         = sizeof(unsigned int),
+               .mode           = 0644,
+               .proc_handler   = sched_energy_aware_handler,
+               .extra1         = &zero,
+               .extra2         = &one,
+       },
+#endif
 #ifdef CONFIG_PROVE_LOCKING
        {
                .procname       = "prove_locking",
@@ -1460,7 +1474,7 @@ static struct ctl_table vm_table[] = {
                .data           = &sysctl_extfrag_threshold,
                .maxlen         = sizeof(int),
                .mode           = 0644,
-               .proc_handler   = sysctl_extfrag_handler,
+               .proc_handler   = proc_dointvec_minmax,
                .extra1         = &min_extfrag_threshold,
                .extra2         = &max_extfrag_threshold,
        },
@@ -1736,6 +1750,8 @@ static struct ctl_table fs_table[] = {
                .maxlen         = sizeof(files_stat.max_files),
                .mode           = 0644,
                .proc_handler   = proc_doulongvec_minmax,
+               .extra1         = &zero,
+               .extra2         = &long_max,
        },
        {
                .procname       = "nr_open",
@@ -2106,6 +2122,41 @@ static void proc_skip_char(char **buf, size_t *size, const char v)
        }
 }
 
+/**
+ * strtoul_lenient - parse an ASCII formatted integer from a buffer and only
+ *                   fail on overflow
+ *
+ * @cp: kernel buffer containing the string to parse
+ * @endp: pointer to store the trailing characters
+ * @base: the base to use
+ * @res: where the parsed integer will be stored
+ *
+ * In case of success 0 is returned and @res will contain the parsed integer,
+ * @endp will hold any trailing characters.
+ * This function will fail the parse on overflow. If there wasn't an overflow
+ * the function will defer the decision what characters count as invalid to the
+ * caller.
+ */
+static int strtoul_lenient(const char *cp, char **endp, unsigned int base,
+                          unsigned long *res)
+{
+       unsigned long long result;
+       unsigned int rv;
+
+       cp = _parse_integer_fixup_radix(cp, &base);
+       rv = _parse_integer(cp, base, &result);
+       if ((rv & KSTRTOX_OVERFLOW) || (result != (unsigned long)result))
+               return -ERANGE;
+
+       cp += rv;
+
+       if (endp)
+               *endp = (char *)cp;
+
+       *res = (unsigned long)result;
+       return 0;
+}
+
 #define TMPBUFLEN 22
 /**
  * proc_get_long - reads an ASCII formatted integer from a user buffer
@@ -2149,7 +2200,8 @@ static int proc_get_long(char **buf, size_t *size,
        if (!isdigit(*p))
                return -EINVAL;
 
-       *val = simple_strtoul(p, &p, 0);
+       if (strtoul_lenient(p, &p, 0, val))
+               return -EINVAL;
 
        len = p - tmp;