All of lore.kernel.org
 help / color / mirror / Atom feed
* [BUG]memblock: fix overflow of array index
@ 2012-04-25  8:30 ` Peter Teoh
  0 siblings, 0 replies; 16+ messages in thread
From: Peter Teoh @ 2012-04-25  8:30 UTC (permalink / raw)
  To: linux-kernel
  Cc: Tejun Heo, H. Peter Anvin, Andrew Morton, Ingo Molnar, linux-mm

Fixing the mismatch in signed and unsigned type assignment, which
potentially can lead to integer overflow bug.

Thanks.

Reviewed-by: Minchan Kim <minchan@kernel.org>
Signed-off-by: Peter Teoh <htmldeveloper@gmail.com>

diff --git a/mm/memblock.c b/mm/memblock.c
index a44eab3..2c621c5 100644
--- a/mm/memblock.c
+++ b/mm/memblock.c
@@ -553,8 +553,8 @@ void __init_memblock __next_free_mem_range(u64
*idx, int nid,
 {
      struct memblock_type *mem = &memblock.memory;
      struct memblock_type *rsv = &memblock.reserved;
-       int mi = *idx & 0xffffffff;
-       int ri = *idx >> 32;
+       unsigned int mi = *idx & 0xffffffff;
+       unsigned int ri = *idx >> 32;

      for ( ; mi < mem->cnt; mi++) {
              struct memblock_region *m = &mem->regions[mi];



--
Regards,
Peter Teoh

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

* [BUG]memblock: fix overflow of array index
@ 2012-04-25  8:30 ` Peter Teoh
  0 siblings, 0 replies; 16+ messages in thread
From: Peter Teoh @ 2012-04-25  8:30 UTC (permalink / raw)
  To: linux-kernel
  Cc: Tejun Heo, H. Peter Anvin, Andrew Morton, Ingo Molnar, linux-mm

Fixing the mismatch in signed and unsigned type assignment, which
potentially can lead to integer overflow bug.

Thanks.

Reviewed-by: Minchan Kim <minchan@kernel.org>
Signed-off-by: Peter Teoh <htmldeveloper@gmail.com>

diff --git a/mm/memblock.c b/mm/memblock.c
index a44eab3..2c621c5 100644
--- a/mm/memblock.c
+++ b/mm/memblock.c
@@ -553,8 +553,8 @@ void __init_memblock __next_free_mem_range(u64
*idx, int nid,
 {
      struct memblock_type *mem = &memblock.memory;
      struct memblock_type *rsv = &memblock.reserved;
-       int mi = *idx & 0xffffffff;
-       int ri = *idx >> 32;
+       unsigned int mi = *idx & 0xffffffff;
+       unsigned int ri = *idx >> 32;

      for ( ; mi < mem->cnt; mi++) {
              struct memblock_region *m = &mem->regions[mi];



--
Regards,
Peter Teoh

--
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] 16+ messages in thread

* Re: [BUG]memblock: fix overflow of array index
  2012-04-25  8:30 ` Peter Teoh
@ 2012-04-25 22:28   ` Tejun Heo
  -1 siblings, 0 replies; 16+ messages in thread
From: Tejun Heo @ 2012-04-25 22:28 UTC (permalink / raw)
  To: Peter Teoh
  Cc: linux-kernel, H. Peter Anvin, Andrew Morton, Ingo Molnar, linux-mm

On Wed, Apr 25, 2012 at 04:30:19PM +0800, Peter Teoh wrote:
> Fixing the mismatch in signed and unsigned type assignment, which
> potentially can lead to integer overflow bug.
> 
> Thanks.
> 
> Reviewed-by: Minchan Kim <minchan@kernel.org>
> Signed-off-by: Peter Teoh <htmldeveloper@gmail.com>

All indexes in memblock are integers.  Changing that particular one to
unsigned int doesn't fix anything.  I think it just makes things more
confusing.  If there ever are cases w/ more then 2G memblocks, we're
going for 64bit not unsigned.

Thanks.

-- 
tejun

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

* Re: [BUG]memblock: fix overflow of array index
@ 2012-04-25 22:28   ` Tejun Heo
  0 siblings, 0 replies; 16+ messages in thread
From: Tejun Heo @ 2012-04-25 22:28 UTC (permalink / raw)
  To: Peter Teoh
  Cc: linux-kernel, H. Peter Anvin, Andrew Morton, Ingo Molnar, linux-mm

On Wed, Apr 25, 2012 at 04:30:19PM +0800, Peter Teoh wrote:
> Fixing the mismatch in signed and unsigned type assignment, which
> potentially can lead to integer overflow bug.
> 
> Thanks.
> 
> Reviewed-by: Minchan Kim <minchan@kernel.org>
> Signed-off-by: Peter Teoh <htmldeveloper@gmail.com>

All indexes in memblock are integers.  Changing that particular one to
unsigned int doesn't fix anything.  I think it just makes things more
confusing.  If there ever are cases w/ more then 2G memblocks, we're
going for 64bit not unsigned.

Thanks.

-- 
tejun

--
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] 16+ messages in thread

* Re: [BUG]memblock: fix overflow of array index
  2012-04-25 22:28   ` Tejun Heo
@ 2012-04-25 22:29     ` H. Peter Anvin
  -1 siblings, 0 replies; 16+ messages in thread
From: H. Peter Anvin @ 2012-04-25 22:29 UTC (permalink / raw)
  To: Tejun Heo; +Cc: Peter Teoh, linux-kernel, Andrew Morton, Ingo Molnar, linux-mm

On 04/25/2012 03:28 PM, Tejun Heo wrote:
> 
> All indexes in memblock are integers.  Changing that particular one to
> unsigned int doesn't fix anything.  I think it just makes things more
> confusing.  If there ever are cases w/ more then 2G memblocks, we're
> going for 64bit not unsigned.
> 

I would expect there to be plenty of memblocks larger than 2G?

	-hpa



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

* Re: [BUG]memblock: fix overflow of array index
@ 2012-04-25 22:29     ` H. Peter Anvin
  0 siblings, 0 replies; 16+ messages in thread
From: H. Peter Anvin @ 2012-04-25 22:29 UTC (permalink / raw)
  To: Tejun Heo; +Cc: Peter Teoh, linux-kernel, Andrew Morton, Ingo Molnar, linux-mm

On 04/25/2012 03:28 PM, Tejun Heo wrote:
> 
> All indexes in memblock are integers.  Changing that particular one to
> unsigned int doesn't fix anything.  I think it just makes things more
> confusing.  If there ever are cases w/ more then 2G memblocks, we're
> going for 64bit not unsigned.
> 

I would expect there to be plenty of memblocks larger than 2G?

	-hpa


--
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] 16+ messages in thread

* Re: [BUG]memblock: fix overflow of array index
  2012-04-25 22:29     ` H. Peter Anvin
@ 2012-04-25 22:31       ` David Miller
  -1 siblings, 0 replies; 16+ messages in thread
From: David Miller @ 2012-04-25 22:31 UTC (permalink / raw)
  To: hpa; +Cc: tj, htmldeveloper, linux-kernel, akpm, mingo, linux-mm

From: "H. Peter Anvin" <hpa@linux.intel.com>
Date: Wed, 25 Apr 2012 15:29:31 -0700

> On 04/25/2012 03:28 PM, Tejun Heo wrote:
>> 
>> All indexes in memblock are integers.  Changing that particular one to
>> unsigned int doesn't fix anything.  I think it just makes things more
>> confusing.  If there ever are cases w/ more then 2G memblocks, we're
>> going for 64bit not unsigned.
>> 
> 
> I would expect there to be plenty of memblocks larger than 2G?

Yes, but not the array indexes into those memblock entries, which is
what this patch is about.

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

* Re: [BUG]memblock: fix overflow of array index
@ 2012-04-25 22:31       ` David Miller
  0 siblings, 0 replies; 16+ messages in thread
From: David Miller @ 2012-04-25 22:31 UTC (permalink / raw)
  To: hpa; +Cc: tj, htmldeveloper, linux-kernel, akpm, mingo, linux-mm

From: "H. Peter Anvin" <hpa@linux.intel.com>
Date: Wed, 25 Apr 2012 15:29:31 -0700

> On 04/25/2012 03:28 PM, Tejun Heo wrote:
>> 
>> All indexes in memblock are integers.  Changing that particular one to
>> unsigned int doesn't fix anything.  I think it just makes things more
>> confusing.  If there ever are cases w/ more then 2G memblocks, we're
>> going for 64bit not unsigned.
>> 
> 
> I would expect there to be plenty of memblocks larger than 2G?

Yes, but not the array indexes into those memblock entries, which is
what this patch is about.

--
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] 16+ messages in thread

* Re: [BUG]memblock: fix overflow of array index
  2012-04-25 22:31       ` David Miller
@ 2012-04-25 22:42         ` H. Peter Anvin
  -1 siblings, 0 replies; 16+ messages in thread
From: H. Peter Anvin @ 2012-04-25 22:42 UTC (permalink / raw)
  To: David Miller; +Cc: tj, htmldeveloper, linux-kernel, akpm, mingo, linux-mm

On 04/25/2012 03:31 PM, David Miller wrote:
> From: "H. Peter Anvin" <hpa@linux.intel.com>
> Date: Wed, 25 Apr 2012 15:29:31 -0700
> 
>> On 04/25/2012 03:28 PM, Tejun Heo wrote:
>>>
>>> All indexes in memblock are integers.  Changing that particular one to
>>> unsigned int doesn't fix anything.  I think it just makes things more
>>> confusing.  If there ever are cases w/ more then 2G memblocks, we're
>>> going for 64bit not unsigned.
>>>
>>
>> I would expect there to be plenty of memblocks larger than 2G?
> 
> Yes, but not the array indexes into those memblock entries, which is
> what this patch is about.

OIC... more than 2^31 memblocks.

	-hpa


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

* Re: [BUG]memblock: fix overflow of array index
@ 2012-04-25 22:42         ` H. Peter Anvin
  0 siblings, 0 replies; 16+ messages in thread
From: H. Peter Anvin @ 2012-04-25 22:42 UTC (permalink / raw)
  To: David Miller; +Cc: tj, htmldeveloper, linux-kernel, akpm, mingo, linux-mm

On 04/25/2012 03:31 PM, David Miller wrote:
> From: "H. Peter Anvin" <hpa@linux.intel.com>
> Date: Wed, 25 Apr 2012 15:29:31 -0700
> 
>> On 04/25/2012 03:28 PM, Tejun Heo wrote:
>>>
>>> All indexes in memblock are integers.  Changing that particular one to
>>> unsigned int doesn't fix anything.  I think it just makes things more
>>> confusing.  If there ever are cases w/ more then 2G memblocks, we're
>>> going for 64bit not unsigned.
>>>
>>
>> I would expect there to be plenty of memblocks larger than 2G?
> 
> Yes, but not the array indexes into those memblock entries, which is
> what this patch is about.

OIC... more than 2^31 memblocks.

	-hpa

--
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] 16+ messages in thread

* Re: [BUG]memblock: fix overflow of array index
  2012-04-25 22:28   ` Tejun Heo
@ 2012-04-26  0:50     ` Peter Teoh
  -1 siblings, 0 replies; 16+ messages in thread
From: Peter Teoh @ 2012-04-26  0:50 UTC (permalink / raw)
  To: Tejun Heo
  Cc: linux-kernel, H. Peter Anvin, Andrew Morton, Ingo Molnar, linux-mm

Thanks for the reply.   Just an educational question:  is it possible
to set one-byte per memblock?    And what is the minimum memblock
size?

Even if 2G memblock is a huge number, it still seemed like a bug to me
that there is no check on the maximum number (which is 2G) of this
variable (assuming signed int).   Software can always purposely push
that number up and the system can panic?

On Thu, Apr 26, 2012 at 6:28 AM, Tejun Heo <tj@kernel.org> wrote:
> On Wed, Apr 25, 2012 at 04:30:19PM +0800, Peter Teoh wrote:
>> Fixing the mismatch in signed and unsigned type assignment, which
>> potentially can lead to integer overflow bug.
>>
>> Thanks.
>>
>> Reviewed-by: Minchan Kim <minchan@kernel.org>
>> Signed-off-by: Peter Teoh <htmldeveloper@gmail.com>
>
> All indexes in memblock are integers.  Changing that particular one to
> unsigned int doesn't fix anything.  I think it just makes things more
> confusing.  If there ever are cases w/ more then 2G memblocks, we're
> going for 64bit not unsigned.
>
> Thanks.
>
> --
> tejun



-- 
Regards,
Peter Teoh

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

* Re: [BUG]memblock: fix overflow of array index
@ 2012-04-26  0:50     ` Peter Teoh
  0 siblings, 0 replies; 16+ messages in thread
From: Peter Teoh @ 2012-04-26  0:50 UTC (permalink / raw)
  To: Tejun Heo
  Cc: linux-kernel, H. Peter Anvin, Andrew Morton, Ingo Molnar, linux-mm

Thanks for the reply.   Just an educational question:  is it possible
to set one-byte per memblock?    And what is the minimum memblock
size?

Even if 2G memblock is a huge number, it still seemed like a bug to me
that there is no check on the maximum number (which is 2G) of this
variable (assuming signed int).   Software can always purposely push
that number up and the system can panic?

On Thu, Apr 26, 2012 at 6:28 AM, Tejun Heo <tj@kernel.org> wrote:
> On Wed, Apr 25, 2012 at 04:30:19PM +0800, Peter Teoh wrote:
>> Fixing the mismatch in signed and unsigned type assignment, which
>> potentially can lead to integer overflow bug.
>>
>> Thanks.
>>
>> Reviewed-by: Minchan Kim <minchan@kernel.org>
>> Signed-off-by: Peter Teoh <htmldeveloper@gmail.com>
>
> All indexes in memblock are integers.  Changing that particular one to
> unsigned int doesn't fix anything.  I think it just makes things more
> confusing.  If there ever are cases w/ more then 2G memblocks, we're
> going for 64bit not unsigned.
>
> Thanks.
>
> --
> tejun



-- 
Regards,
Peter Teoh

--
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] 16+ messages in thread

* Re: [BUG]memblock: fix overflow of array index
  2012-04-26  0:50     ` Peter Teoh
@ 2012-04-26  0:54       ` Yinghai Lu
  -1 siblings, 0 replies; 16+ messages in thread
From: Yinghai Lu @ 2012-04-26  0:54 UTC (permalink / raw)
  To: Peter Teoh
  Cc: Tejun Heo, linux-kernel, H. Peter Anvin, Andrew Morton,
	Ingo Molnar, linux-mm

On Wed, Apr 25, 2012 at 5:50 PM, Peter Teoh <htmldeveloper@gmail.com> wrote:
> Thanks for the reply.   Just an educational question:  is it possible
> to set one-byte per memblock?    And what is the minimum memblock
> size?

yes. 1 byte.

>
> Even if 2G memblock is a huge number, it still seemed like a bug to me
> that there is no check on the maximum number (which is 2G) of this
> variable (assuming signed int).   Software can always purposely push
> that number up and the system can panic?

before slab is ready? how?

Thanks

Yinghai

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

* Re: [BUG]memblock: fix overflow of array index
@ 2012-04-26  0:54       ` Yinghai Lu
  0 siblings, 0 replies; 16+ messages in thread
From: Yinghai Lu @ 2012-04-26  0:54 UTC (permalink / raw)
  To: Peter Teoh
  Cc: Tejun Heo, linux-kernel, H. Peter Anvin, Andrew Morton,
	Ingo Molnar, linux-mm

On Wed, Apr 25, 2012 at 5:50 PM, Peter Teoh <htmldeveloper@gmail.com> wrote:
> Thanks for the reply.   Just an educational question:  is it possible
> to set one-byte per memblock?    And what is the minimum memblock
> size?

yes. 1 byte.

>
> Even if 2G memblock is a huge number, it still seemed like a bug to me
> that there is no check on the maximum number (which is 2G) of this
> variable (assuming signed int).   Software can always purposely push
> that number up and the system can panic?

before slab is ready? how?

Thanks

Yinghai

--
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] 16+ messages in thread

* Re: [BUG]memblock: fix overflow of array index
  2012-04-26  0:50     ` Peter Teoh
@ 2012-04-26 15:01       ` Tejun Heo
  -1 siblings, 0 replies; 16+ messages in thread
From: Tejun Heo @ 2012-04-26 15:01 UTC (permalink / raw)
  To: Peter Teoh
  Cc: linux-kernel, H. Peter Anvin, Andrew Morton, Ingo Molnar, linux-mm

Hello,

On Thu, Apr 26, 2012 at 08:50:58AM +0800, Peter Teoh wrote:
> Thanks for the reply.   Just an educational question:  is it possible
> to set one-byte per memblock?    And what is the minimum memblock
> size?

1 byte.

> Even if 2G memblock is a huge number, it still seemed like a bug to me
> that there is no check on the maximum number (which is 2G) of this
> variable (assuming signed int).   Software can always purposely push
> that number up and the system can panic?

Yeah, if somebody messes the BIOS / firmware to oblivion.  I don't
really care at that point tho.  memblock is a boot time memory
allocator and it assumes BIOS / firmware isn't completely crazy.  It
uses contiguous tables to describe all the blocks, walks them
one-by-one for allocation and even compacts them.

Well before memblock fails from any of the above, the machine would be
failing miserably in firmware / BIOS.

Thanks.

-- 
tejun

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

* Re: [BUG]memblock: fix overflow of array index
@ 2012-04-26 15:01       ` Tejun Heo
  0 siblings, 0 replies; 16+ messages in thread
From: Tejun Heo @ 2012-04-26 15:01 UTC (permalink / raw)
  To: Peter Teoh
  Cc: linux-kernel, H. Peter Anvin, Andrew Morton, Ingo Molnar, linux-mm

Hello,

On Thu, Apr 26, 2012 at 08:50:58AM +0800, Peter Teoh wrote:
> Thanks for the reply.   Just an educational question:  is it possible
> to set one-byte per memblock?    And what is the minimum memblock
> size?

1 byte.

> Even if 2G memblock is a huge number, it still seemed like a bug to me
> that there is no check on the maximum number (which is 2G) of this
> variable (assuming signed int).   Software can always purposely push
> that number up and the system can panic?

Yeah, if somebody messes the BIOS / firmware to oblivion.  I don't
really care at that point tho.  memblock is a boot time memory
allocator and it assumes BIOS / firmware isn't completely crazy.  It
uses contiguous tables to describe all the blocks, walks them
one-by-one for allocation and even compacts them.

Well before memblock fails from any of the above, the machine would be
failing miserably in firmware / BIOS.

Thanks.

-- 
tejun

--
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] 16+ messages in thread

end of thread, other threads:[~2012-04-26 15:02 UTC | newest]

Thread overview: 16+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2012-04-25  8:30 [BUG]memblock: fix overflow of array index Peter Teoh
2012-04-25  8:30 ` Peter Teoh
2012-04-25 22:28 ` Tejun Heo
2012-04-25 22:28   ` Tejun Heo
2012-04-25 22:29   ` H. Peter Anvin
2012-04-25 22:29     ` H. Peter Anvin
2012-04-25 22:31     ` David Miller
2012-04-25 22:31       ` David Miller
2012-04-25 22:42       ` H. Peter Anvin
2012-04-25 22:42         ` H. Peter Anvin
2012-04-26  0:50   ` Peter Teoh
2012-04-26  0:50     ` Peter Teoh
2012-04-26  0:54     ` Yinghai Lu
2012-04-26  0:54       ` Yinghai Lu
2012-04-26 15:01     ` Tejun Heo
2012-04-26 15:01       ` Tejun Heo

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.