aboutsummaryrefslogtreecommitdiffstats
path: root/kernel/sched
diff options
context:
space:
mode:
authorNamhyung Kim <namhyung.kim@lge.com>2012-08-16 04:03:24 -0400
committerIngo Molnar <mingo@kernel.org>2012-09-04 08:31:32 -0400
commit201c373e8e4823700d3160d5c28e1ab18fd1193e (patch)
treef871b6f429e195cdf37dd0582d64813f220057a0 /kernel/sched
parentc751134ef8b070070d5f06348286b29d86424677 (diff)
sched/debug: Limit sd->*_idx range on sysctl
Various sd->*_idx's are used for refering the rq's load average table when selecting a cpu to run. However they can be set to any number with sysctl knobs so that it can crash the kernel if something bad is given. Fix it by limiting them into the actual range. Signed-off-by: Namhyung Kim <namhyung@kernel.org> Signed-off-by: Peter Zijlstra <a.p.zijlstra@chello.nl> Link: http://lkml.kernel.org/r/1345104204-8317-1-git-send-email-namhyung@kernel.org Signed-off-by: Ingo Molnar <mingo@kernel.org>
Diffstat (limited to 'kernel/sched')
-rw-r--r--kernel/sched/core.c35
1 files changed, 22 insertions, 13 deletions
diff --git a/kernel/sched/core.c b/kernel/sched/core.c
index ae66229238a0..ec0f2b81b81c 100644
--- a/kernel/sched/core.c
+++ b/kernel/sched/core.c
@@ -4896,16 +4896,25 @@ static void sd_free_ctl_entry(struct ctl_table **tablep)
4896 *tablep = NULL; 4896 *tablep = NULL;
4897} 4897}
4898 4898
4899static int min_load_idx = 0;
4900static int max_load_idx = CPU_LOAD_IDX_MAX;
4901
4899static void 4902static void
4900set_table_entry(struct ctl_table *entry, 4903set_table_entry(struct ctl_table *entry,
4901 const char *procname, void *data, int maxlen, 4904 const char *procname, void *data, int maxlen,
4902 umode_t mode, proc_handler *proc_handler) 4905 umode_t mode, proc_handler *proc_handler,
4906 bool load_idx)
4903{ 4907{
4904 entry->procname = procname; 4908 entry->procname = procname;
4905 entry->data = data; 4909 entry->data = data;
4906 entry->maxlen = maxlen; 4910 entry->maxlen = maxlen;
4907 entry->mode = mode; 4911 entry->mode = mode;
4908 entry->proc_handler = proc_handler; 4912 entry->proc_handler = proc_handler;
4913
4914 if (load_idx) {
4915 entry->extra1 = &min_load_idx;
4916 entry->extra2 = &max_load_idx;
4917 }
4909} 4918}
4910 4919
4911static struct ctl_table * 4920static struct ctl_table *
@@ -4917,30 +4926,30 @@ sd_alloc_ctl_domain_table(struct sched_domain *sd)
4917 return NULL; 4926 return NULL;
4918 4927
4919 set_table_entry(&table[0], "min_interval", &sd->min_interval, 4928 set_table_entry(&table[0], "min_interval", &sd->min_interval,
4920 sizeof(long), 0644, proc_doulongvec_minmax); 4929 sizeof(long), 0644, proc_doulongvec_minmax, false);
4921 set_table_entry(&table[1], "max_interval", &sd->max_interval, 4930 set_table_entry(&table[1], "max_interval", &sd->max_interval,
4922 sizeof(long), 0644, proc_doulongvec_minmax); 4931 sizeof(long), 0644, proc_doulongvec_minmax, false);
4923 set_table_entry(&table[2], "busy_idx", &sd->busy_idx, 4932 set_table_entry(&table[2], "busy_idx", &sd->busy_idx,
4924 sizeof(int), 0644, proc_dointvec_minmax); 4933 sizeof(int), 0644, proc_dointvec_minmax, true);
4925 set_table_entry(&table[3], "idle_idx", &sd->idle_idx, 4934 set_table_entry(&table[3], "idle_idx", &sd->idle_idx,
4926 sizeof(int), 0644, proc_dointvec_minmax); 4935 sizeof(int), 0644, proc_dointvec_minmax, true);
4927 set_table_entry(&table[4], "newidle_idx", &sd->newidle_idx, 4936 set_table_entry(&table[4], "newidle_idx", &sd->newidle_idx,
4928 sizeof(int), 0644, proc_dointvec_minmax); 4937 sizeof(int), 0644, proc_dointvec_minmax, true);
4929 set_table_entry(&table[5], "wake_idx", &sd->wake_idx, 4938 set_table_entry(&table[5], "wake_idx", &sd->wake_idx,
4930 sizeof(int), 0644, proc_dointvec_minmax); 4939 sizeof(int), 0644, proc_dointvec_minmax, true);
4931 set_table_entry(&table[6], "forkexec_idx", &sd->forkexec_idx, 4940 set_table_entry(&table[6], "forkexec_idx", &sd->forkexec_idx,
4932 sizeof(int), 0644, proc_dointvec_minmax); 4941 sizeof(int), 0644, proc_dointvec_minmax, true);
4933 set_table_entry(&table[7], "busy_factor", &sd->busy_factor, 4942 set_table_entry(&table[7], "busy_factor", &sd->busy_factor,
4934 sizeof(int), 0644, proc_dointvec_minmax); 4943 sizeof(int), 0644, proc_dointvec_minmax, false);
4935 set_table_entry(&table[8], "imbalance_pct", &sd->imbalance_pct, 4944 set_table_entry(&table[8], "imbalance_pct", &sd->imbalance_pct,
4936 sizeof(int), 0644, proc_dointvec_minmax); 4945 sizeof(int), 0644, proc_dointvec_minmax, false);
4937 set_table_entry(&table[9], "cache_nice_tries", 4946 set_table_entry(&table[9], "cache_nice_tries",
4938 &sd->cache_nice_tries, 4947 &sd->cache_nice_tries,
4939 sizeof(int), 0644, proc_dointvec_minmax); 4948 sizeof(int), 0644, proc_dointvec_minmax, false);
4940 set_table_entry(&table[10], "flags", &sd->flags, 4949 set_table_entry(&table[10], "flags", &sd->flags,
4941 sizeof(int), 0644, proc_dointvec_minmax); 4950 sizeof(int), 0644, proc_dointvec_minmax, false);
4942 set_table_entry(&table[11], "name", sd->name, 4951 set_table_entry(&table[11], "name", sd->name,
4943 CORENAME_MAX_SIZE, 0444, proc_dostring); 4952 CORENAME_MAX_SIZE, 0444, proc_dostring, false);
4944 /* &table[12] is terminator */ 4953 /* &table[12] is terminator */
4945 4954
4946 return table; 4955 return table;