From mboxrd@z Thu Jan 1 00:00:00 1970 From: Jiri Pirko Subject: Re: [PATCH net-2.6] netns: assign NULL after pernet memory is freed Date: Mon, 26 Apr 2010 15:30:20 +0200 Message-ID: <20100426133020.GE2941@psychotron.lab.eng.brq.redhat.com> References: <20100426111806.GB2941@psychotron.lab.eng.brq.redhat.com> <20100426120716.GD2941@psychotron.lab.eng.brq.redhat.com> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Cc: davem@davemloft.net, ebiederm@xmission.com To: netdev@vger.kernel.org Return-path: Received: from mx1.redhat.com ([209.132.183.28]:19097 "EHLO mx1.redhat.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1750961Ab0DZNaX (ORCPT ); Mon, 26 Apr 2010 09:30:23 -0400 Content-Disposition: inline In-Reply-To: <20100426120716.GD2941@psychotron.lab.eng.brq.redhat.com> Sender: netdev-owner@vger.kernel.org List-ID: Mon, Apr 26, 2010 at 02:07:17PM CEST, jpirko@redhat.com wrote: >Mon, Apr 26, 2010 at 01:18:07PM CEST, jpirko@redhat.com wrote: >>This is needed to let know appropriate code (driver) know that pernet memory >>chunk was freed already. For example when driver has also registered netdev >>notifier, it can be called after memory is freed which could eventually lead >>to panic. Also a null check should be present in these notifiers. >> >>For example, previously, when drivers were responsible for pernet memory >>allocation/freeing, in pppoe this assign was done in pppoe_exit_net() right >>after pernet memory was freed. The check in notifier stayed (in pppoe_flush_dev >>called from pppoe_device_event) but makes no sense now without this patch. > >Hmm, thinking about this, since the life of pernet memories is directly connected >with the life of net, as described by Eric, this should not be needed. So please >scrach this one too. Sorry. > >Anyway, I'm still wondering how to prevent netdev_notifiers from using this when >net is gone. Going to do more research, I'm probably missing something. Right, it becomes part of init_ns then. So this looks good then. One thing I can still imagine what may cause problem, since netdev_notifier is registered before register_pernet_device, the notifier can be called in between. So I think this should be reordered, am I right? Thanks Jirka > > >> >>I already know about several notifiers where the check should be present, >>patches will follow up. >> >>Signed-off-by: Jiri Pirko >> >>diff --git a/net/core/net_namespace.c b/net/core/net_namespace.c >>index bd8c471..29f622c 100644 >>--- a/net/core/net_namespace.c >>+++ b/net/core/net_namespace.c >>@@ -51,6 +51,7 @@ static void ops_free(const struct pernet_operations *ops, struct net *net) >> if (ops->id && ops->size) { >> int id = *ops->id; >> kfree(net_generic(net, id)); >>+ net_assign_generic(net, id, NULL); >> } >> } >>