In drivers/net/ns83820.c::ns83820_init_one() we dynamically allocate
memory via alloc_etherdev(). We then call PRIV() on the returned storage
which is 'return netdev_priv()'. netdev_priv() takes the pointer it is
passed and adds 'ALIGN(sizeof(struct net_device), NETDEV_ALIGN)' to it and
returns it. Then we test the resulting pointer for NULL, which it is
unlikely to be at this point, and later dereference it. This will go bad
if alloc_etherdev() actually returned NULL.
This patch reworks the code slightly so that we test for a NULL pointer
(and return -ENOMEM) directly after calling alloc_etherdev().
Signed-off-by: Jesper Juhl <redacted>
---
ns83820.c | 5 ++---
1 file changed, 2 insertions(+), 3 deletions(-)
Compile tested only. I have no way to test this for real.
On Mon, Jan 17, 2011 at 09:24:57PM +0100, Jesper Juhl wrote:
In drivers/net/ns83820.c::ns83820_init_one() we dynamically allocate
memory via alloc_etherdev(). We then call PRIV() on the returned storage
which is 'return netdev_priv()'. netdev_priv() takes the pointer it is
passed and adds 'ALIGN(sizeof(struct net_device), NETDEV_ALIGN)' to it and
returns it. Then we test the resulting pointer for NULL, which it is
unlikely to be at this point, and later dereference it. This will go bad
if alloc_etherdev() actually returned NULL.
This patch reworks the code slightly so that we test for a NULL pointer
(and return -ENOMEM) directly after calling alloc_etherdev().
Signed-off-by: Jesper Juhl <redacted>
Yeah, the previous code was a little bit ugly.
Good catch!
quoted hunk
--- ns83820.c | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) Compile tested only. I have no way to test this for real.
From: Benjamin LaHaise <bcrl@kvack.org> Date: 2011-01-18 16:42:07
On Mon, Jan 17, 2011 at 09:24:57PM +0100, Jesper Juhl wrote:
In drivers/net/ns83820.c::ns83820_init_one() we dynamically allocate
memory via alloc_etherdev(). We then call PRIV() on the returned storage
which is 'return netdev_priv()'. netdev_priv() takes the pointer it is
passed and adds 'ALIGN(sizeof(struct net_device), NETDEV_ALIGN)' to it and
returns it. Then we test the resulting pointer for NULL, which it is
unlikely to be at this point, and later dereference it. This will go bad
if alloc_etherdev() actually returned NULL.
This patch reworks the code slightly so that we test for a NULL pointer
(and return -ENOMEM) directly after calling alloc_etherdev().
Looks good.
-ben
Signed-off-by: Benjamin LaHaise <bcrl@kvack.org>
quoted hunk
Signed-off-by: Jesper Juhl <redacted>
---
ns83820.c | 5 ++---
1 file changed, 2 insertions(+), 3 deletions(-)
Compile tested only. I have no way to test this for real.
From: David Miller <davem@davemloft.net> Date: 2011-01-19 00:13:59
From: Benjamin LaHaise <bcrl@kvack.org>
Date: Tue, 18 Jan 2011 11:42:00 -0500
On Mon, Jan 17, 2011 at 09:24:57PM +0100, Jesper Juhl wrote:
quoted
In drivers/net/ns83820.c::ns83820_init_one() we dynamically allocate
memory via alloc_etherdev(). We then call PRIV() on the returned storage
which is 'return netdev_priv()'. netdev_priv() takes the pointer it is
passed and adds 'ALIGN(sizeof(struct net_device), NETDEV_ALIGN)' to it and
returns it. Then we test the resulting pointer for NULL, which it is
unlikely to be at this point, and later dereference it. This will go bad
if alloc_etherdev() actually returned NULL.
This patch reworks the code slightly so that we test for a NULL pointer
(and return -ENOMEM) directly after calling alloc_etherdev().
Looks good.
-ben
Signed-off-by: Benjamin LaHaise <bcrl@kvack.org>