Skip to content

Commit

Permalink
net: dont leave active on stack LIST_HEAD
Browse files Browse the repository at this point in the history
Eric W. Biderman and Michal Hocko reported various memory corruptions
that we suspected to be related to a LIST head located on stack, that
was manipulated after thread left function frame (and eventually exited,
so its stack was freed and reused).

Eric Dumazet suggested the problem was probably coming from commit
4434572 (net: factorize
sync-rcu call in unregister_netdevice_many)

This patch fixes __dev_close() and dev_close() to properly deinit their
respective LIST_HEAD(single) before exiting.

References: https://lkml.org/lkml/2011/2/16/304
References: https://lkml.org/lkml/2011/2/14/223

Reported-by: Michal Hocko <mhocko@suse.cz>
Tested-by: Michal Hocko <mhocko@suse.cz>
Reported-by: Eric W. Biderman <ebiderman@xmission.com>
Tested-by: Eric W. Biderman <ebiderman@xmission.com>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
Signed-off-by: Eric Dumazet <eric.dumazet@gmail.com>
CC: Ingo Molnar <mingo@elte.hu>
CC: Octavian Purdila <opurdila@ixiacom.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
  • Loading branch information
Linus Torvalds authored and David S. Miller committed Feb 18, 2011
1 parent 214f45c commit f87e6f4
Showing 1 changed file with 5 additions and 2 deletions.
7 changes: 5 additions & 2 deletions net/core/dev.c
Original file line number Diff line number Diff line change
Expand Up @@ -1280,10 +1280,13 @@ static int __dev_close_many(struct list_head *head)

static int __dev_close(struct net_device *dev)
{
int retval;
LIST_HEAD(single);

list_add(&dev->unreg_list, &single);
return __dev_close_many(&single);
retval = __dev_close_many(&single);
list_del(&single);
return retval;
}

int dev_close_many(struct list_head *head)
Expand Down Expand Up @@ -1325,7 +1328,7 @@ int dev_close(struct net_device *dev)

list_add(&dev->unreg_list, &single);
dev_close_many(&single);

list_del(&single);
return 0;
}
EXPORT_SYMBOL(dev_close);
Expand Down

0 comments on commit f87e6f4

Please sign in to comment.