* [PATCH] oom: fix integer overflow of points in oom_badness
@ 2011-10-31 8:14 Frantisek Hrbata
2011-10-31 15:28 ` Oleg Nesterov
` (2 more replies)
0 siblings, 3 replies; 11+ messages in thread
From: Frantisek Hrbata @ 2011-10-31 8:14 UTC (permalink / raw)
To: rientjes
Cc: linux-mm, linux-kernel, akpm, kosaki.motohiro, oleg, minchan.kim,
stable, eteo, pmatouse
An integer overflow will happen on 64bit archs if task's sum of rss, swapents
and nr_ptes exceeds (2^31)/1000 value. This was introduced by commit
f755a04 oom: use pte pages in OOM score
where the oom score computation was divided into several steps and it's no
longer computed as one expression in unsigned long(rss, swapents, nr_pte are
unsigned long), where the result value assigned to points(int) is in
range(1..1000). So there could be an int overflow while computing
176 points *= 1000;
and points may have negative value. Meaning the oom score for a mem hog task
will be one.
196 if (points <= 0)
197 return 1;
For example:
[ 3366] 0 3366 35390480 24303939 5 0 0 oom01
Out of memory: Kill process 3366 (oom01) score 1 or sacrifice child
Here the oom1 process consumes more than 24303939(rss)*4096~=92GB physical
memory, but it's oom score is one.
In this situation the mem hog task is skipped and oom killer kills another and
most probably innocent task with oom score greater than one.
This patch puts the computation of points back in one expression, so the int
overflow will not happen.
My understanding is that we may just change the type of points variable from int
to long and keep the current imho clearer(better readable) computation. There
should not be an overflow on 32bit and there is a plenty of space for 64bit.
If you like this solution better I will post the patch as v2.
Signed-off-by: Frantisek Hrbata <fhrbata@redhat.com>
---
mm/oom_kill.c | 6 ++----
1 files changed, 2 insertions(+), 4 deletions(-)
diff --git a/mm/oom_kill.c b/mm/oom_kill.c
index 626303b..d029e9b 100644
--- a/mm/oom_kill.c
+++ b/mm/oom_kill.c
@@ -192,11 +192,9 @@ unsigned int oom_badness(struct task_struct *p, struct mem_cgroup *mem,
* The baseline for the badness score is the proportion of RAM that each
* task's rss, pagetable and swap space use.
*/
- points = get_mm_rss(p->mm) + p->mm->nr_ptes;
- points += get_mm_counter(p->mm, MM_SWAPENTS);
+ points = (int)((get_mm_rss(p->mm) + get_mm_counter(p->mm, MM_SWAPENTS) +
+ p->mm->nr_ptes) * 1000UL / totalpages);
- points *= 1000;
- points /= totalpages;
task_unlock(p);
/*
--
1.7.6.4
--
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/ .
Fight unfair telecom internet charges in Canada: sign http://stopthemeter.ca/
Don't email: <a href=mailto:"dont@kvack.org"> email@kvack.org </a>
^ permalink raw reply related [flat|nested] 11+ messages in thread
* Re: [PATCH v2] oom: fix integer overflow of points in oom_badness
2011-10-31 15:56 ` [PATCH v2] " Frantisek Hrbata
@ 2011-10-31 14:18 ` KOSAKI Motohiro
2011-10-31 17:42 ` Oleg Nesterov
2011-10-31 18:22 ` David Rientjes
2 siblings, 0 replies; 11+ messages in thread
From: KOSAKI Motohiro @ 2011-10-31 14:18 UTC (permalink / raw)
To: fhrbata
Cc: rientjes, linux-mm, linux-kernel, akpm, oleg, minchan.kim, stable,
eteo, pmatouse
(10/31/2011 11:56 AM), Frantisek Hrbata wrote:
> An integer overflow will happen on 64bit archs if task's sum of rss, swapents
> and nr_ptes exceeds (2^31)/1000 value. This was introduced by commit
>
> f755a04 oom: use pte pages in OOM score
>
> where the oom score computation was divided into several steps and it's no
> longer computed as one expression in unsigned long(rss, swapents, nr_pte are
> unsigned long), where the result value assigned to points(int) is in
> range(1..1000). So there could be an int overflow while computing
>
> 176 points *= 1000;
>
> and points may have negative value. Meaning the oom score for a mem hog task
> will be one.
>
> 196 if (points <= 0)
> 197 return 1;
>
> For example:
> [ 3366] 0 3366 35390480 24303939 5 0 0 oom01
> Out of memory: Kill process 3366 (oom01) score 1 or sacrifice child
>
> Here the oom1 process consumes more than 24303939(rss)*4096~=92GB physical
> memory, but it's oom score is one.
>
> In this situation the mem hog task is skipped and oom killer kills another and
> most probably innocent task with oom score greater than one.
>
> The points variable should be of type long instead of int to prevent the int
> overflow.
>
> Signed-off-by: Frantisek Hrbata <fhrbata@redhat.com>
> ---
> mm/oom_kill.c | 2 +-
> 1 files changed, 1 insertions(+), 1 deletions(-)
>
> diff --git a/mm/oom_kill.c b/mm/oom_kill.c
> index 626303b..e9a1785 100644
> --- a/mm/oom_kill.c
> +++ b/mm/oom_kill.c
> @@ -162,7 +162,7 @@ static bool oom_unkillable_task(struct task_struct *p,
> unsigned int oom_badness(struct task_struct *p, struct mem_cgroup *mem,
> const nodemask_t *nodemask, unsigned long totalpages)
> {
> - int points;
> + long points;
>
> if (oom_unkillable_task(p, mem, nodemask))
> return 0;
Good catch.
Acked-by: KOSAKI Motohiro <kosaki.motohiro@jp.fujitsu.com>
--
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/ .
Fight unfair telecom internet charges in Canada: sign http://stopthemeter.ca/
Don't email: <a href=mailto:"dont@kvack.org"> email@kvack.org </a>
^ permalink raw reply [flat|nested] 11+ messages in thread
* Re: [PATCH] oom: fix integer overflow of points in oom_badness
2011-10-31 8:14 [PATCH] oom: fix integer overflow of points in oom_badness Frantisek Hrbata
@ 2011-10-31 15:28 ` Oleg Nesterov
2011-10-31 15:49 ` Frantisek Hrbata
2011-10-31 15:56 ` [PATCH v2] " Frantisek Hrbata
2011-12-02 17:45 ` [PATCH v2 RESEND] " Frantisek Hrbata
2 siblings, 1 reply; 11+ messages in thread
From: Oleg Nesterov @ 2011-10-31 15:28 UTC (permalink / raw)
To: Frantisek Hrbata
Cc: rientjes, linux-mm, linux-kernel, akpm, kosaki.motohiro,
minchan.kim, stable, eteo, pmatouse
On 10/31, Frantisek Hrbata wrote:
>
> My understanding is that we may just change the type of points variable from int
> to long and keep the current imho clearer(better readable) computation. There
> should not be an overflow on 32bit and there is a plenty of space for 64bit.
> If you like this solution better I will post the patch as v2.
Up to maintainer, but personally I think the simple s/int/long/ looks better.
Everything like get_mm_*/nr_ptes returns long.
Anyway good catch. Imho stable needs the fix too.
Cosmetic nit,
> - points = get_mm_rss(p->mm) + p->mm->nr_ptes;
> - points += get_mm_counter(p->mm, MM_SWAPENTS);
> + points = (int)((get_mm_rss(p->mm) + get_mm_counter(p->mm, MM_SWAPENTS) +
^^^^^
Why do we need the explicit typecast? It buys nothing and looks a bit confusing.
And, if you prefer "int", perhaps something like
- points *= 1000;
- points /= totalpages;
+ /* avoid the possible overflow */
+ points = points * 1000L / totalpages;
looks a bit more readable with the same effect. But I won't insist, this is
up to you and David.
Oleg.
--
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/ .
Fight unfair telecom internet charges in Canada: sign http://stopthemeter.ca/
Don't email: <a href=mailto:"dont@kvack.org"> email@kvack.org </a>
^ permalink raw reply [flat|nested] 11+ messages in thread
* Re: [PATCH] oom: fix integer overflow of points in oom_badness
2011-10-31 15:28 ` Oleg Nesterov
@ 2011-10-31 15:49 ` Frantisek Hrbata
0 siblings, 0 replies; 11+ messages in thread
From: Frantisek Hrbata @ 2011-10-31 15:49 UTC (permalink / raw)
To: Oleg Nesterov
Cc: rientjes, linux-mm, linux-kernel, akpm, kosaki.motohiro,
minchan.kim, stable, eteo, pmatouse
On Mon, Oct 31, 2011 at 04:28:33PM +0100, Oleg Nesterov wrote:
> On 10/31, Frantisek Hrbata wrote:
> >
> > My understanding is that we may just change the type of points variable from int
> > to long and keep the current imho clearer(better readable) computation. There
> > should not be an overflow on 32bit and there is a plenty of space for 64bit.
> > If you like this solution better I will post the patch as v2.
>
> Up to maintainer, but personally I think the simple s/int/long/ looks better.
> Everything like get_mm_*/nr_ptes returns long.
Agreed. I will post v2 with the int => long change.
>
> Anyway good catch. Imho stable needs the fix too.
>
> Cosmetic nit,
>
> > - points = get_mm_rss(p->mm) + p->mm->nr_ptes;
> > - points += get_mm_counter(p->mm, MM_SWAPENTS);
> > + points = (int)((get_mm_rss(p->mm) + get_mm_counter(p->mm, MM_SWAPENTS) +
> ^^^^^
>
> Why do we need the explicit typecast? It buys nothing and looks a bit confusing.
You are right, it's not needed. I just wanted to make the cast more visible, but
some kind of comment would be probably better here.
>
> And, if you prefer "int", perhaps something like
>
> - points *= 1000;
> - points /= totalpages;
> + /* avoid the possible overflow */
> + points = points * 1000L / totalpages;
>
> looks a bit more readable with the same effect. But I won't insist, this is
> up to you and David.
Sure, this looks much better than the one line expression in the patch I sent.
If David or others decide to not go with the int=>long change I think we should
use this.
>
> Oleg.
>
Many thanks Oleg.
--
Frantisek Hrbata
--
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/ .
Fight unfair telecom internet charges in Canada: sign http://stopthemeter.ca/
Don't email: <a href=mailto:"dont@kvack.org"> email@kvack.org </a>
^ permalink raw reply [flat|nested] 11+ messages in thread
* [PATCH v2] oom: fix integer overflow of points in oom_badness
2011-10-31 8:14 [PATCH] oom: fix integer overflow of points in oom_badness Frantisek Hrbata
2011-10-31 15:28 ` Oleg Nesterov
@ 2011-10-31 15:56 ` Frantisek Hrbata
2011-10-31 14:18 ` KOSAKI Motohiro
` (2 more replies)
2011-12-02 17:45 ` [PATCH v2 RESEND] " Frantisek Hrbata
2 siblings, 3 replies; 11+ messages in thread
From: Frantisek Hrbata @ 2011-10-31 15:56 UTC (permalink / raw)
To: rientjes
Cc: linux-mm, linux-kernel, akpm, kosaki.motohiro, oleg, minchan.kim,
stable, eteo, pmatouse
An integer overflow will happen on 64bit archs if task's sum of rss, swapents
and nr_ptes exceeds (2^31)/1000 value. This was introduced by commit
f755a04 oom: use pte pages in OOM score
where the oom score computation was divided into several steps and it's no
longer computed as one expression in unsigned long(rss, swapents, nr_pte are
unsigned long), where the result value assigned to points(int) is in
range(1..1000). So there could be an int overflow while computing
176 points *= 1000;
and points may have negative value. Meaning the oom score for a mem hog task
will be one.
196 if (points <= 0)
197 return 1;
For example:
[ 3366] 0 3366 35390480 24303939 5 0 0 oom01
Out of memory: Kill process 3366 (oom01) score 1 or sacrifice child
Here the oom1 process consumes more than 24303939(rss)*4096~=92GB physical
memory, but it's oom score is one.
In this situation the mem hog task is skipped and oom killer kills another and
most probably innocent task with oom score greater than one.
The points variable should be of type long instead of int to prevent the int
overflow.
Signed-off-by: Frantisek Hrbata <fhrbata@redhat.com>
---
mm/oom_kill.c | 2 +-
1 files changed, 1 insertions(+), 1 deletions(-)
diff --git a/mm/oom_kill.c b/mm/oom_kill.c
index 626303b..e9a1785 100644
--- a/mm/oom_kill.c
+++ b/mm/oom_kill.c
@@ -162,7 +162,7 @@ static bool oom_unkillable_task(struct task_struct *p,
unsigned int oom_badness(struct task_struct *p, struct mem_cgroup *mem,
const nodemask_t *nodemask, unsigned long totalpages)
{
- int points;
+ long points;
if (oom_unkillable_task(p, mem, nodemask))
return 0;
--
1.7.6.4
--
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/ .
Fight unfair telecom internet charges in Canada: sign http://stopthemeter.ca/
Don't email: <a href=mailto:"dont@kvack.org"> email@kvack.org </a>
^ permalink raw reply related [flat|nested] 11+ messages in thread
* Re: [PATCH v2] oom: fix integer overflow of points in oom_badness
2011-10-31 15:56 ` [PATCH v2] " Frantisek Hrbata
2011-10-31 14:18 ` KOSAKI Motohiro
@ 2011-10-31 17:42 ` Oleg Nesterov
2011-10-31 18:22 ` David Rientjes
2 siblings, 0 replies; 11+ messages in thread
From: Oleg Nesterov @ 2011-10-31 17:42 UTC (permalink / raw)
To: Frantisek Hrbata
Cc: rientjes, linux-mm, linux-kernel, akpm, kosaki.motohiro,
minchan.kim, stable, eteo, pmatouse
On 10/31, Frantisek Hrbata wrote:
>
> unsigned int oom_badness(struct task_struct *p, struct mem_cgroup *mem,
> const nodemask_t *nodemask, unsigned long totalpages)
> {
> - int points;
> + long points;
Good catch. Imho this is the stable material.
Acked-by: Oleg Nesterov <oleg@redhat.com>
--
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/ .
Fight unfair telecom internet charges in Canada: sign http://stopthemeter.ca/
Don't email: <a href=mailto:"dont@kvack.org"> email@kvack.org </a>
^ permalink raw reply [flat|nested] 11+ messages in thread
* Re: [PATCH v2] oom: fix integer overflow of points in oom_badness
2011-10-31 15:56 ` [PATCH v2] " Frantisek Hrbata
2011-10-31 14:18 ` KOSAKI Motohiro
2011-10-31 17:42 ` Oleg Nesterov
@ 2011-10-31 18:22 ` David Rientjes
2 siblings, 0 replies; 11+ messages in thread
From: David Rientjes @ 2011-10-31 18:22 UTC (permalink / raw)
To: Frantisek Hrbata
Cc: linux-mm, linux-kernel, Andrew Morton, KOSAKI Motohiro,
Oleg Nesterov, Minchan Kim, stable, eteo, pmatouse
On Mon, 31 Oct 2011, Frantisek Hrbata wrote:
> An integer overflow will happen on 64bit archs if task's sum of rss, swapents
> and nr_ptes exceeds (2^31)/1000 value. This was introduced by commit
>
> f755a04 oom: use pte pages in OOM score
>
This commit was introduced in 2.6.39 but also backported to stable since
2.6.36, so presumably we'd need to mark this for stable as well going back
that far.
> where the oom score computation was divided into several steps and it's no
> longer computed as one expression in unsigned long(rss, swapents, nr_pte are
> unsigned long), where the result value assigned to points(int) is in
> range(1..1000). So there could be an int overflow while computing
>
> 176 points *= 1000;
>
> and points may have negative value. Meaning the oom score for a mem hog task
> will be one.
>
> 196 if (points <= 0)
> 197 return 1;
>
> For example:
> [ 3366] 0 3366 35390480 24303939 5 0 0 oom01
> Out of memory: Kill process 3366 (oom01) score 1 or sacrifice child
>
> Here the oom1 process consumes more than 24303939(rss)*4096~=92GB physical
> memory, but it's oom score is one.
>
> In this situation the mem hog task is skipped and oom killer kills another and
> most probably innocent task with oom score greater than one.
>
> The points variable should be of type long instead of int to prevent the int
> overflow.
>
> Signed-off-by: Frantisek Hrbata <fhrbata@redhat.com>
Acked-by: David Rientjes <rientjes@google.com>
Cc: stable@kernel.org [2.6.36+]
--
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/ .
Fight unfair telecom internet charges in Canada: sign http://stopthemeter.ca/
Don't email: <a href=mailto:"dont@kvack.org"> email@kvack.org </a>
^ permalink raw reply [flat|nested] 11+ messages in thread
* [PATCH v2 RESEND] oom: fix integer overflow of points in oom_badness
2011-10-31 8:14 [PATCH] oom: fix integer overflow of points in oom_badness Frantisek Hrbata
2011-10-31 15:28 ` Oleg Nesterov
2011-10-31 15:56 ` [PATCH v2] " Frantisek Hrbata
@ 2011-12-02 17:45 ` Frantisek Hrbata
2011-12-02 19:00 ` Greg KH
2011-12-08 3:44 ` David Rientjes
2 siblings, 2 replies; 11+ messages in thread
From: Frantisek Hrbata @ 2011-12-02 17:45 UTC (permalink / raw)
To: rientjes
Cc: linux-mm, linux-kernel, akpm, kosaki.motohiro, oleg, minchan.kim,
stable, eteo, pmatouse, gregkh
An integer overflow will happen on 64bit archs if task's sum of rss, swapents
and nr_ptes exceeds (2^31)/1000 value. This was introduced by commit
f755a04 oom: use pte pages in OOM score
where the oom score computation was divided into several steps and it's no
longer computed as one expression in unsigned long(rss, swapents, nr_pte are
unsigned long), where the result value assigned to points(int) is in
range(1..1000). So there could be an int overflow while computing
176 points *= 1000;
and points may have negative value. Meaning the oom score for a mem hog task
will be one.
196 if (points <= 0)
197 return 1;
For example:
[ 3366] 0 3366 35390480 24303939 5 0 0 oom01
Out of memory: Kill process 3366 (oom01) score 1 or sacrifice child
Here the oom1 process consumes more than 24303939(rss)*4096~=92GB physical
memory, but it's oom score is one.
In this situation the mem hog task is skipped and oom killer kills another and
most probably innocent task with oom score greater than one.
The points variable should be of type long instead of int to prevent the int
overflow.
Signed-off-by: Frantisek Hrbata <fhrbata@redhat.com>
Acked-by: KOSAKI Motohiro <kosaki.motohiro@jp.fujitsu.com>
Acked-by: Oleg Nesterov <oleg@redhat.com>
Acked-by: David Rientjes <rientjes@google.com>
Cc: stable@kernel.org [2.6.36+]
---
mm/oom_kill.c | 2 +-
1 files changed, 1 insertions(+), 1 deletions(-)
diff --git a/mm/oom_kill.c b/mm/oom_kill.c
index 626303b..e9a1785 100644
--- a/mm/oom_kill.c
+++ b/mm/oom_kill.c
@@ -162,7 +162,7 @@ static bool oom_unkillable_task(struct task_struct *p,
unsigned int oom_badness(struct task_struct *p, struct mem_cgroup *mem,
const nodemask_t *nodemask, unsigned long totalpages)
{
- int points;
+ long points;
if (oom_unkillable_task(p, mem, nodemask))
return 0;
--
1.7.6.4
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/
--
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/ .
Fight unfair telecom internet charges in Canada: sign http://stopthemeter.ca/
Don't email: <a href=mailto:"dont@kvack.org"> email@kvack.org </a>
^ permalink raw reply related [flat|nested] 11+ messages in thread
* Re: [PATCH v2 RESEND] oom: fix integer overflow of points in oom_badness
2011-12-02 17:45 ` [PATCH v2 RESEND] " Frantisek Hrbata
@ 2011-12-02 19:00 ` Greg KH
2011-12-02 20:46 ` Frantisek Hrbata
2011-12-08 3:44 ` David Rientjes
1 sibling, 1 reply; 11+ messages in thread
From: Greg KH @ 2011-12-02 19:00 UTC (permalink / raw)
To: Frantisek Hrbata
Cc: rientjes, linux-mm, linux-kernel, akpm, kosaki.motohiro, oleg,
minchan.kim, stable, eteo, pmatouse
On Fri, Dec 02, 2011 at 06:45:27PM +0100, Frantisek Hrbata wrote:
> An integer overflow will happen on 64bit archs if task's sum of rss, swapents
> and nr_ptes exceeds (2^31)/1000 value. This was introduced by commit
>
> f755a04 oom: use pte pages in OOM score
>
> where the oom score computation was divided into several steps and it's no
> longer computed as one expression in unsigned long(rss, swapents, nr_pte are
> unsigned long), where the result value assigned to points(int) is in
> range(1..1000). So there could be an int overflow while computing
>
> 176 points *= 1000;
>
> and points may have negative value. Meaning the oom score for a mem hog task
> will be one.
>
> 196 if (points <= 0)
> 197 return 1;
>
> For example:
> [ 3366] 0 3366 35390480 24303939 5 0 0 oom01
> Out of memory: Kill process 3366 (oom01) score 1 or sacrifice child
>
> Here the oom1 process consumes more than 24303939(rss)*4096~=92GB physical
> memory, but it's oom score is one.
>
> In this situation the mem hog task is skipped and oom killer kills another and
> most probably innocent task with oom score greater than one.
>
> The points variable should be of type long instead of int to prevent the int
> overflow.
>
> Signed-off-by: Frantisek Hrbata <fhrbata@redhat.com>
> Acked-by: KOSAKI Motohiro <kosaki.motohiro@jp.fujitsu.com>
> Acked-by: Oleg Nesterov <oleg@redhat.com>
> Acked-by: David Rientjes <rientjes@google.com>
> Cc: stable@kernel.org [2.6.36+]
For what it's worth, the stable address has changed to
stable@vger.kernel.org so you might want to fix that up in future
submissions.
I still catch patches that are tagged with this marking, but you will
not end up posting stuff to the list this way :)
thanks,
greg k-h
--
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/ .
Fight unfair telecom internet charges in Canada: sign http://stopthemeter.ca/
Don't email: <a href=mailto:"dont@kvack.org"> email@kvack.org </a>
^ permalink raw reply [flat|nested] 11+ messages in thread
* Re: [PATCH v2 RESEND] oom: fix integer overflow of points in oom_badness
2011-12-02 19:00 ` Greg KH
@ 2011-12-02 20:46 ` Frantisek Hrbata
0 siblings, 0 replies; 11+ messages in thread
From: Frantisek Hrbata @ 2011-12-02 20:46 UTC (permalink / raw)
To: Greg KH
Cc: rientjes, linux-mm, linux-kernel, akpm, kosaki.motohiro, oleg,
minchan.kim, stable, eteo, pmatouse
On Fri, Dec 02, 2011 at 11:00:19AM -0800, Greg KH wrote:
> On Fri, Dec 02, 2011 at 06:45:27PM +0100, Frantisek Hrbata wrote:
> > An integer overflow will happen on 64bit archs if task's sum of rss, swapents
> > and nr_ptes exceeds (2^31)/1000 value. This was introduced by commit
> >
> > f755a04 oom: use pte pages in OOM score
> >
> > where the oom score computation was divided into several steps and it's no
> > longer computed as one expression in unsigned long(rss, swapents, nr_pte are
> > unsigned long), where the result value assigned to points(int) is in
> > range(1..1000). So there could be an int overflow while computing
> >
> > 176 points *= 1000;
> >
> > and points may have negative value. Meaning the oom score for a mem hog task
> > will be one.
> >
> > 196 if (points <= 0)
> > 197 return 1;
> >
> > For example:
> > [ 3366] 0 3366 35390480 24303939 5 0 0 oom01
> > Out of memory: Kill process 3366 (oom01) score 1 or sacrifice child
> >
> > Here the oom1 process consumes more than 24303939(rss)*4096~=92GB physical
> > memory, but it's oom score is one.
> >
> > In this situation the mem hog task is skipped and oom killer kills another and
> > most probably innocent task with oom score greater than one.
> >
> > The points variable should be of type long instead of int to prevent the int
> > overflow.
> >
> > Signed-off-by: Frantisek Hrbata <fhrbata@redhat.com>
> > Acked-by: KOSAKI Motohiro <kosaki.motohiro@jp.fujitsu.com>
> > Acked-by: Oleg Nesterov <oleg@redhat.com>
> > Acked-by: David Rientjes <rientjes@google.com>
> > Cc: stable@kernel.org [2.6.36+]
>
> For what it's worth, the stable address has changed to
> stable@vger.kernel.org so you might want to fix that up in future
> submissions.
I was not aware of this change.
>
> I still catch patches that are tagged with this marking, but you will
> not end up posting stuff to the list this way :)
Duly noted :)
>
> thanks,
Thanks Greg!
>
> greg k-h
--
Frantisek Hrbata
--
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/ .
Fight unfair telecom internet charges in Canada: sign http://stopthemeter.ca/
Don't email: <a href=mailto:"dont@kvack.org"> email@kvack.org </a>
^ permalink raw reply [flat|nested] 11+ messages in thread
* Re: [PATCH v2 RESEND] oom: fix integer overflow of points in oom_badness
2011-12-02 17:45 ` [PATCH v2 RESEND] " Frantisek Hrbata
2011-12-02 19:00 ` Greg KH
@ 2011-12-08 3:44 ` David Rientjes
1 sibling, 0 replies; 11+ messages in thread
From: David Rientjes @ 2011-12-08 3:44 UTC (permalink / raw)
To: Andrew Morton, Frantisek Hrbata
Cc: linux-mm, linux-kernel, kosaki.motohiro, oleg, minchan.kim,
stable, eteo, pmatouse, Greg Kroah-Hartman
On Fri, 2 Dec 2011, Frantisek Hrbata wrote:
> An integer overflow will happen on 64bit archs if task's sum of rss, swapents
> and nr_ptes exceeds (2^31)/1000 value. This was introduced by commit
>
> f755a04 oom: use pte pages in OOM score
>
> where the oom score computation was divided into several steps and it's no
> longer computed as one expression in unsigned long(rss, swapents, nr_pte are
> unsigned long), where the result value assigned to points(int) is in
> range(1..1000). So there could be an int overflow while computing
>
> 176 points *= 1000;
>
> and points may have negative value. Meaning the oom score for a mem hog task
> will be one.
>
> 196 if (points <= 0)
> 197 return 1;
>
> For example:
> [ 3366] 0 3366 35390480 24303939 5 0 0 oom01
> Out of memory: Kill process 3366 (oom01) score 1 or sacrifice child
>
> Here the oom1 process consumes more than 24303939(rss)*4096~=92GB physical
> memory, but it's oom score is one.
>
> In this situation the mem hog task is skipped and oom killer kills another and
> most probably innocent task with oom score greater than one.
>
> The points variable should be of type long instead of int to prevent the int
> overflow.
>
> Signed-off-by: Frantisek Hrbata <fhrbata@redhat.com>
> Acked-by: KOSAKI Motohiro <kosaki.motohiro@jp.fujitsu.com>
> Acked-by: Oleg Nesterov <oleg@redhat.com>
> Acked-by: David Rientjes <rientjes@google.com>
> Cc: stable@kernel.org [2.6.36+]
Andrew, this looks like 3.2-rc5 material.
> ---
> mm/oom_kill.c | 2 +-
> 1 files changed, 1 insertions(+), 1 deletions(-)
>
> diff --git a/mm/oom_kill.c b/mm/oom_kill.c
> index 626303b..e9a1785 100644
> --- a/mm/oom_kill.c
> +++ b/mm/oom_kill.c
> @@ -162,7 +162,7 @@ static bool oom_unkillable_task(struct task_struct *p,
> unsigned int oom_badness(struct task_struct *p, struct mem_cgroup *mem,
> const nodemask_t *nodemask, unsigned long totalpages)
> {
> - int points;
> + long points;
>
> if (oom_unkillable_task(p, mem, nodemask))
> return 0;
--
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/ .
Fight unfair telecom internet charges in Canada: sign http://stopthemeter.ca/
Don't email: <a href=mailto:"dont@kvack.org"> email@kvack.org </a>
^ permalink raw reply [flat|nested] 11+ messages in thread
end of thread, other threads:[~2011-12-08 3:45 UTC | newest]
Thread overview: 11+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2011-10-31 8:14 [PATCH] oom: fix integer overflow of points in oom_badness Frantisek Hrbata
2011-10-31 15:28 ` Oleg Nesterov
2011-10-31 15:49 ` Frantisek Hrbata
2011-10-31 15:56 ` [PATCH v2] " Frantisek Hrbata
2011-10-31 14:18 ` KOSAKI Motohiro
2011-10-31 17:42 ` Oleg Nesterov
2011-10-31 18:22 ` David Rientjes
2011-12-02 17:45 ` [PATCH v2 RESEND] " Frantisek Hrbata
2011-12-02 19:00 ` Greg KH
2011-12-02 20:46 ` Frantisek Hrbata
2011-12-08 3:44 ` David Rientjes
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).