Skip to contentSkip to conversation

mm: prevent set a value less than 0 to min_free_kbytes

RFC In review Han Pingtian 3 participants 3 messages Jan 8, 2014 – Jan 9, 2014

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

RFC 1/1 mm: prevent set 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.

---
 mm/page_alloc.c |    7 ++++++-
 1 files changed, 6 insertions(+), 1 deletions(-)
mm/page_alloc.c +6 -1
index 77937e0..a9dcfd8 100644
@@ -5692,7 +5692,12 @@ module_init(init_per_zone_wmark_min)
 int min_free_kbytes_sysctl_handler(ctl_table *table, int write,
 	void __user *buffer, size_t *length, loff_t *ppos)
 {
-	proc_dointvec(table, write, buffer, length, ppos);
+	int rc;
+
+	rc = proc_dointvec_minmax(table, write, buffer, length, ppos);
+	if (rc)
+		return rc;
+
 	if (write) {
 		user_min_free_kbytes = min_free_kbytes;
 		setup_per_zone_wmarks();
Signature · 7 lines
1.7.7.6

--
To unsubscribe, send a message with 'unsubscribe linux-mm' in
the body to [email protected].  For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>
Acked-by on v1 1/1
#1 lore raw
Quoted 3 lines · Han Pingtian

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.

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.

Quoted 1 line

That being said I do not think this will fix any real world problem but just for sake of correctness

After changelog is updated feel free to add my

Quoted 25 lines
---
 mm/page_alloc.c |    7 ++++++-
 1 files changed, 6 insertions(+), 1 deletions(-)
mm/page_alloc.c +6 -1
index 77937e0..a9dcfd8 100644
@@ -5692,7 +5692,12 @@ module_init(init_per_zone_wmark_min)
 int min_free_kbytes_sysctl_handler(ctl_table *table, int write,
 	void __user *buffer, size_t *length, loff_t *ppos)
 {
-	proc_dointvec(table, write, buffer, length, ppos);
+	int rc;
+
+	rc = proc_dointvec_minmax(table, write, buffer, length, ppos);
+	if (rc)
+		return rc;
+
 	if (write) {
 		user_min_free_kbytes = min_free_kbytes;
 		setup_per_zone_wmarks();
Signature · 1 line
1.7.7.6
Signature · 8 lines
Michal Hocko
SUSE Labs

--
To unsubscribe, send a message with 'unsubscribe linux-mm' in
the body to [email protected].  For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>
Acked-by on v1 1/1
#2 lore raw
In reply to Han Pingtian
Quoted 5 lines · Han Pingtian

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.

Nice catch!

--
To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to [email protected]. For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>