Skip to content

Commit

Permalink
ns83820: Avoid bad pointer deref in ns83820_init_one().
Browse files Browse the repository at this point in the history
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 <jj@chaosbits.net>
Signed-off-by: Benjamin LaHaise <bcrl@kvack.org>
Signed-off-by: David S. Miller <davem@davemloft.net>
  • Loading branch information
Jesper Juhl authored and David S. Miller committed Jan 19, 2011
1 parent 2fdc1c8 commit 1956cc5
Showing 1 changed file with 2 additions and 3 deletions.
5 changes: 2 additions & 3 deletions drivers/net/ns83820.c
Original file line number Diff line number Diff line change
Expand Up @@ -1988,12 +1988,11 @@ static int __devinit ns83820_init_one(struct pci_dev *pci_dev,
}

ndev = alloc_etherdev(sizeof(struct ns83820));
dev = PRIV(ndev);

err = -ENOMEM;
if (!dev)
if (!ndev)
goto out;

dev = PRIV(ndev);
dev->ndev = ndev;

spin_lock_init(&dev->rx_info.lock);
Expand Down

0 comments on commit 1956cc5

Please sign in to comment.