linux-mm.kvack.org archive mirror
 help / color / mirror / Atom feed
* [RFC] mm: prevent set a value less than 0 to min_free_kbytes
@ 2014-01-08  8:42 Han Pingtian
  2014-01-08  9:40 ` Michal Hocko
  2014-01-09  2:26 ` David Rientjes
  0 siblings, 2 replies; 3+ messages in thread
From: Han Pingtian @ 2014-01-08  8:42 UTC (permalink / raw)
  To: linux-kernel
  Cc: Mel Gorman, Andrew Morton, linux-mm, Michal Hocko, Dave Hansen,
	David Rientjes

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.

Signed-off-by: Han Pingtian <hanpt@linux.vnet.ibm.com>
---
 mm/page_alloc.c |    7 ++++++-
 1 files changed, 6 insertions(+), 1 deletions(-)

diff --git a/mm/page_alloc.c b/mm/page_alloc.c
index 77937e0..a9dcfd8 100644
--- a/mm/page_alloc.c
+++ b/mm/page_alloc.c
@@ -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();
-- 
1.7.7.6

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

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [RFC] mm: prevent set a value less than 0 to min_free_kbytes
  2014-01-08  8:42 [RFC] mm: prevent set a value less than 0 to min_free_kbytes Han Pingtian
@ 2014-01-08  9:40 ` Michal Hocko
  2014-01-09  2:26 ` David Rientjes
  1 sibling, 0 replies; 3+ messages in thread
From: Michal Hocko @ 2014-01-08  9:40 UTC (permalink / raw)
  To: linux-kernel, Mel Gorman, Andrew Morton, linux-mm, Dave Hansen,
	David Rientjes

On Wed 08-01-14 16:42:42, Han Pingtian wrote:
> 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.

> Signed-off-by: Han Pingtian <hanpt@linux.vnet.ibm.com>

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
Acked-by: Michal Hocko <mhocko@suse.cz>

> ---
>  mm/page_alloc.c |    7 ++++++-
>  1 files changed, 6 insertions(+), 1 deletions(-)
> 
> diff --git a/mm/page_alloc.c b/mm/page_alloc.c
> index 77937e0..a9dcfd8 100644
> --- a/mm/page_alloc.c
> +++ b/mm/page_alloc.c
> @@ -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();
> -- 
> 1.7.7.6
> 

-- 
Michal Hocko
SUSE Labs

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

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [RFC] mm: prevent set a value less than 0 to min_free_kbytes
  2014-01-08  8:42 [RFC] mm: prevent set a value less than 0 to min_free_kbytes Han Pingtian
  2014-01-08  9:40 ` Michal Hocko
@ 2014-01-09  2:26 ` David Rientjes
  1 sibling, 0 replies; 3+ messages in thread
From: David Rientjes @ 2014-01-09  2:26 UTC (permalink / raw)
  To: Han Pingtian
  Cc: linux-kernel, Mel Gorman, Andrew Morton, linux-mm, Michal Hocko,
	Dave Hansen

On Wed, 8 Jan 2014, Han Pingtian wrote:

> 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.
> 
> Signed-off-by: Han Pingtian <hanpt@linux.vnet.ibm.com>

Acked-by: David Rientjes <rientjes@google.com>

Nice catch!

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

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2014-01-09  2:26 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2014-01-08  8:42 [RFC] mm: prevent set a value less than 0 to min_free_kbytes Han Pingtian
2014-01-08  9:40 ` Michal Hocko
2014-01-09  2:26 ` David Rientjes

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox