Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

mm: prevent setting of a value less than 0 to min_free_kbytes

If echo -1 > /proc/vm/sys/min_free_kbytes, the system will hang. Changing
proc_dointvec() to proc_dointvec_minmax() in the
min_free_kbytes_sysctl_handler() can prevent this to happen.

mhocko said:

: You can still do echo $BIG_VALUE > /proc/vm/sys/min_free_kbytes and make
: your machine unusable but I agree that proc_dointvec_minmax is more
: suitable here as we already have:
:
: .proc_handler = min_free_kbytes_sysctl_handler,
: .extra1 = &zero,
:
: It used to work properly but then 6fce56ec91b5 ("sysctl: Remove references
: to ctl_name and strategy from the generic sysctl table") has removed
: sysctl_intvec strategy and so extra1 is ignored.

Signed-off-by: Han Pingtian <hanpt@linux.vnet.ibm.com>
Acked-by: Michal Hocko <mhocko@suse.cz>
Acked-by: David Rientjes <rientjes@google.com>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>

authored by

Han Pingtian and committed by
Linus Torvalds
da8c757b cc81717e

+6 -1
+6 -1
mm/page_alloc.c
··· 5754 5754 int min_free_kbytes_sysctl_handler(ctl_table *table, int write, 5755 5755 void __user *buffer, size_t *length, loff_t *ppos) 5756 5756 { 5757 - proc_dointvec(table, write, buffer, length, ppos); 5757 + int rc; 5758 + 5759 + rc = proc_dointvec_minmax(table, write, buffer, length, ppos); 5760 + if (rc) 5761 + return rc; 5762 + 5758 5763 if (write) { 5759 5764 user_min_free_kbytes = min_free_kbytes; 5760 5765 setup_per_zone_wmarks();