Skip to content

Commit cb16e95

Browse files
Petr Holasektorvalds
authored andcommitted
sysctl: add some missing input constraint checks
Add boundaries of allowed input ranges for: dirty_expire_centisecs, drop_caches, overcommit_memory, page-cluster and panic_on_oom. Signed-off-by: Petr Holasek <pholasek@redhat.com> Acked-by: Dave Young <hidave.darkstar@gmail.com> Cc: David Rientjes <rientjes@google.com> Cc: Wu Fengguang <fengguang.wu@intel.com> Cc: Alexey Dobriyan <adobriyan@gmail.com> Signed-off-by: Andrew Morton <akpm@linux-foundation.org> Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
1 parent 256c53a commit cb16e95

2 files changed

Lines changed: 18 additions & 5 deletions

File tree

‎fs/drop_caches.c‎

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,11 @@ static void drop_slab(void)
4545
int drop_caches_sysctl_handler(ctl_table *table, int write,
4646
void __user *buffer, size_t *length, loff_t *ppos)
4747
{
48-
proc_dointvec_minmax(table, write, buffer, length, ppos);
48+
int ret;
49+
50+
ret = proc_dointvec_minmax(table, write, buffer, length, ppos);
51+
if (ret)
52+
return ret;
4953
if (write) {
5054
if (sysctl_drop_caches & 1)
5155
iterate_supers(drop_pagecache_sb, NULL);

‎kernel/sysctl.c‎

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -117,6 +117,7 @@ static int neg_one = -1;
117117
static int zero;
118118
static int __maybe_unused one = 1;
119119
static int __maybe_unused two = 2;
120+
static int __maybe_unused three = 3;
120121
static unsigned long one_ul = 1;
121122
static int one_hundred = 100;
122123
#ifdef CONFIG_PRINTK
@@ -971,14 +972,18 @@ static struct ctl_table vm_table[] = {
971972
.data = &sysctl_overcommit_memory,
972973
.maxlen = sizeof(sysctl_overcommit_memory),
973974
.mode = 0644,
974-
.proc_handler = proc_dointvec,
975+
.proc_handler = proc_dointvec_minmax,
976+
.extra1 = &zero,
977+
.extra2 = &two,
975978
},
976979
{
977980
.procname = "panic_on_oom",
978981
.data = &sysctl_panic_on_oom,
979982
.maxlen = sizeof(sysctl_panic_on_oom),
980983
.mode = 0644,
981-
.proc_handler = proc_dointvec,
984+
.proc_handler = proc_dointvec_minmax,
985+
.extra1 = &zero,
986+
.extra2 = &two,
982987
},
983988
{
984989
.procname = "oom_kill_allocating_task",
@@ -1006,7 +1011,8 @@ static struct ctl_table vm_table[] = {
10061011
.data = &page_cluster,
10071012
.maxlen = sizeof(int),
10081013
.mode = 0644,
1009-
.proc_handler = proc_dointvec,
1014+
.proc_handler = proc_dointvec_minmax,
1015+
.extra1 = &zero,
10101016
},
10111017
{
10121018
.procname = "dirty_background_ratio",
@@ -1054,7 +1060,8 @@ static struct ctl_table vm_table[] = {
10541060
.data = &dirty_expire_interval,
10551061
.maxlen = sizeof(dirty_expire_interval),
10561062
.mode = 0644,
1057-
.proc_handler = proc_dointvec,
1063+
.proc_handler = proc_dointvec_minmax,
1064+
.extra1 = &zero,
10581065
},
10591066
{
10601067
.procname = "nr_pdflush_threads",
@@ -1130,6 +1137,8 @@ static struct ctl_table vm_table[] = {
11301137
.maxlen = sizeof(int),
11311138
.mode = 0644,
11321139
.proc_handler = drop_caches_sysctl_handler,
1140+
.extra1 = &one,
1141+
.extra2 = &three,
11331142
},
11341143
#ifdef CONFIG_COMPACTION
11351144
{

0 commit comments

Comments
 (0)