oom: fix integer overflow of points in oom_badness
Subsystems (2)
PATCH 1/1 oom: fix integer overflow of points in oom_badness
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.
--- mm/oom_kill.c | 6 ++---- 1 files changed, 2 insertions(+), 4 deletions(-)
mm/oom_kill.c +2 -4
@@ -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);/*
Signature · 8 lines
1.7.6.4 -- 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/ . Fight unfair telecom internet charges in Canada: sign http://stopthemeter.ca/ Don't email: <a href=mailto:"[email protected]"> [email protected] </a>
Quoted 5 lines · Frantisek Hrbata
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,
mm/oom_kill.c unsigned int oom_badness(struct task_struct *p, struct mem_cgroup *mem, · line 195
Quoted 3 lines
mm/oom_kill.c +1
-2- 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 [email protected]. 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:"[email protected]"> [email protected] </a>
Quoted 9 lines · Oleg Nesterov
Quoted 5 lines · Frantisek Hrbata
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.
Quoted 11 lines
Anyway good catch. Imho stable needs the fix too.
Cosmetic nit,
mm/oom_kill.c unsigned int oom_badness(struct task_struct *p, struct mem_cgroup *mem, · line 195
Quoted 3 lines
mm/oom_kill.c +1
-2- 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.
Quoted 10 lines
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.
Quoted 3 lines
Oleg.
Many thanks Oleg.
Signature · 8 lines
Frantisek Hrbata -- 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/ . Fight unfair telecom internet charges in Canada: sign http://stopthemeter.ca/ Don't email: <a href=mailto:"[email protected]"> [email protected] </a>
PATCH v2 1/1 oom: fix integer overflow of points in oom_badness
In reply to Frantisek HrbataAn 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.
--- mm/oom_kill.c | 2 +- 1 files changed, 1 insertions(+), 1 deletions(-)
mm/oom_kill.c +1 -1
@@ -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 ;
Signature · 8 lines
1.7.6.4 -- 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/ . Fight unfair telecom internet charges in Canada: sign http://stopthemeter.ca/ Don't email: <a href=mailto:"[email protected]"> [email protected] </a>
Quoted 41 lines · Frantisek Hrbata
An integer overflow will happen on 64bit archs if task's sum of rss, swapents and
nr_ptesexceeds (2^31)/1000 value. This was introduced by commitf755a04 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 computing176 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 childHere 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 <[email protected]>--- mm/oom_kill.c | 2 +- 1 files changed, 1 insertions(+), 1 deletions(-)mm/oom_kill.c +0
-0
mm/oom_kill.c static bool oom_unkillable_task(struct task_struct *p, · line 168
Quoted 8 lines
mm/oom_kill.c +1
-1@@ -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.
mm/oom_kill.c static bool oom_unkillable_task(struct task_struct *p, · line 165
Quoted 6 lines · Frantisek Hrbata
unsigned int oom_badness(struct
task_struct*p, structmem_cgroup*mem,mm/oom_kill.c +1
-1const nodemask_t *nodemask, unsigned long totalpages) { - int points; + long points;
Good catch. Imho this is the stable material.
--
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/ .
Fight unfair telecom internet charges in Canada: sign http://stopthemeter.ca/
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>
Quoted 5 lines · Frantisek Hrbata
An integer overflow will happen on 64bit archs if task's sum of rss, swapents and
nr_ptesexceeds (2^31)/1000 value. This was introduced by commitf755a04 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.
Quoted 20 lines
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 computing176 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 childHere the oom1 process consumes more than 24303939(rss)*4096~=92GB physical memory, but it's oom score is one.
Quoted 7 lines
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 <[email protected]>
--
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/ .
Fight unfair telecom internet charges in Canada: sign http://stopthemeter.ca/
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>
PATCH RESEND v2 1/1 oom: fix integer overflow of points in oom_badness
In reply to Frantisek HrbataAn 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.
--- mm/oom_kill.c | 2 +- 1 files changed, 1 insertions(+), 1 deletions(-)
mm/oom_kill.c +1 -1
@@ -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 ;
Signature · 14 lines
1.7.6.4 -- To unsubscribe from this list: send the line "unsubscribe linux-kernel" in the body of a message to [email protected] 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 [email protected]. 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:"[email protected]"> [email protected] </a>
Quoted 28 lines · Frantisek Hrbata
An integer overflow will happen on 64bit archs if task's sum of rss, swapents and
nr_ptesexceeds (2^31)/1000 value. This was introduced by commitf755a04 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 computing176 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 childHere 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.
Quoted 8 lines
The points variable should be of type long instead of int to prevent the int overflow.
Signed-off-by Frantisek Hrbata <[email protected]>Acked-by KOSAKI Motohiro <[email protected]>Acked-by Oleg Nesterov <[email protected]>Acked-by David Rientjes <[email protected]>Cc [email protected] [2.6.36+]
For what it's worth, the stable address has changed to [email protected] 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 [email protected]. 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:"[email protected]"> [email protected] </a>
Quoted 38 lines · Greg KH
Quoted 28 lines · Frantisek Hrbata
An integer overflow will happen on 64bit archs if task's sum of rss, swapents and
nr_ptesexceeds (2^31)/1000 value. This was introduced by commitf755a04 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 computing176 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 childHere 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.
Quoted 8 lines
The points variable should be of type long instead of int to prevent the int overflow.
Signed-off-by Frantisek Hrbata <[email protected]>Acked-by KOSAKI Motohiro <[email protected]>Acked-by Oleg Nesterov <[email protected]>Acked-by David Rientjes <[email protected]>Cc [email protected] [2.6.36+]
Quoted 3 lines
For what it's worth, the stable address has changed to [email protected] so you might want to fix that up in future submissions.
I was not aware of this change.
Quoted 3 lines
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 :)
Quoted 2 lines
thanks,
Thanks Greg!
Quoted 2 lines
greg k-h
Signature · 8 lines
Frantisek Hrbata -- 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/ . Fight unfair telecom internet charges in Canada: sign http://stopthemeter.ca/ Don't email: <a href=mailto:"[email protected]"> [email protected] </a>
David Rientjes
reviewerQuoted 28 lines · Frantisek Hrbata
An integer overflow will happen on 64bit archs if task's sum of rss, swapents and
nr_ptesexceeds (2^31)/1000 value. This was introduced by commitf755a04 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 computing176 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 childHere 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.
Quoted 8 lines
The points variable should be of type long instead of int to prevent the int overflow.
Signed-off-by Frantisek Hrbata <[email protected]>Acked-by KOSAKI Motohiro <[email protected]>Acked-by Oleg Nesterov <[email protected]>Acked-by David Rientjes <[email protected]>Cc [email protected] [2.6.36+]
Andrew, this looks like 3.2-rc5 material.
Quoted 9 lines
--- mm/oom_kill.c | 2 +- 1 files changed, 1 insertions(+), 1 deletions(-)mm/oom_kill.c +0
-0
mm/oom_kill.c static bool oom_unkillable_task(struct task_struct *p, · line 168
Quoted 8 lines
mm/oom_kill.c +1
-1@@ -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 [email protected]. 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:"[email protected]"> [email protected] </a>