From patchwork Tue Feb 16 17:57:44 2010 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alexey Dobriyan X-Patchwork-Id: 45553 X-Patchwork-Delegate: davem@davemloft.net Return-Path: X-Original-To: patchwork-incoming@ozlabs.org Delivered-To: patchwork-incoming@ozlabs.org Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by ozlabs.org (Postfix) with ESMTP id 058D1B7D61 for ; Wed, 17 Feb 2010 04:57:54 +1100 (EST) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S933168Ab0BPR5r (ORCPT ); Tue, 16 Feb 2010 12:57:47 -0500 Received: from mail-fx0-f215.google.com ([209.85.220.215]:57685 "EHLO mail-fx0-f215.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S933164Ab0BPR5q (ORCPT ); Tue, 16 Feb 2010 12:57:46 -0500 Received: by fxm7 with SMTP id 7so7493795fxm.28 for ; Tue, 16 Feb 2010 09:57:45 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=domainkey-signature:received:received:date:from:to:cc:subject :message-id:mime-version:content-type:content-disposition:user-agent; bh=iHynecQ7x6VRI1pg2cY1icqzxR/au/bBsnIZ9zvqkvY=; b=Phc7Dl2begeqWCgXbQAueWLOxLCA/Hi3qniaaUj84K9oIfiUfA+YMwBk1q8ta6fsMq VufN5CZdtcWD3xdS4TpCausK8c/cABHIEX4jb5+3qy12izMpUQWNCxdRS0J88CuDoZw/ FRHrrmDEc/H7aDKLXJOkrkGaBU9aPRVhOaaxA= DomainKey-Signature: a=rsa-sha1; c=nofws; d=gmail.com; s=gamma; h=date:from:to:cc:subject:message-id:mime-version:content-type :content-disposition:user-agent; b=jIGi00To+7gG/8YBUbgG9HpALJjESGULcq5InZ4G3V//uLE03tPI+EJTL5W1QKIC8k np26X2T01Re0NTXK1Di+xKjS/BXbiteudF60stD04wp6gZQyFC/MbL9ML/KIDW/Iu5Dv ViJk3+qITvPEbaNKX9+RiFLFbU7mw1pgN8G1E= Received: by 10.223.97.219 with SMTP id m27mr1223059fan.16.1266343065224; Tue, 16 Feb 2010 09:57:45 -0800 (PST) Received: from x200 ([93.85.100.143]) by mx.google.com with ESMTPS id 21sm150362fkx.25.2010.02.16.09.57.42 (version=TLSv1/SSLv3 cipher=RC4-MD5); Tue, 16 Feb 2010 09:57:43 -0800 (PST) Date: Tue, 16 Feb 2010 19:57:44 +0200 From: Alexey Dobriyan To: davem@davemloft.net Cc: netdev@vger.kernel.org, security@kernel.org Subject: [PATCH] gre: fix netns vs proto registration ordering Message-ID: <20100216175744.GA4685@x200> MIME-Version: 1.0 Content-Disposition: inline User-Agent: Mutt/1.5.20 (2009-06-14) Sender: netdev-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org GRE protocol receive hook can be called right after protocol addition is done. If netns stuff is not yet initialized, we're going to oops in net_generic(). This is remotely oopsable if ip_gre is compiled as module and packet comes at unfortunate moment of module loading. Signed-off-by: Alexey Dobriyan --- net/ipv4/ip_gre.c | 19 ++++++++++--------- 1 file changed, 10 insertions(+), 9 deletions(-) -- To unsubscribe from this list: send the line "unsubscribe netdev" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html --- a/net/ipv4/ip_gre.c +++ b/net/ipv4/ip_gre.c @@ -1665,14 +1665,15 @@ static int __init ipgre_init(void) printk(KERN_INFO "GRE over IPv4 tunneling driver\n"); - if (inet_add_protocol(&ipgre_protocol, IPPROTO_GRE) < 0) { - printk(KERN_INFO "ipgre init: can't add protocol\n"); - return -EAGAIN; - } - err = register_pernet_device(&ipgre_net_ops); if (err < 0) - goto gen_device_failed; + return err; + + err = inet_add_protocol(&ipgre_protocol, IPPROTO_GRE); + if (err < 0) { + printk(KERN_INFO "ipgre init: can't add protocol\n"); + goto add_proto_failed; + } err = rtnl_link_register(&ipgre_link_ops); if (err < 0) @@ -1688,9 +1689,9 @@ out: tap_ops_failed: rtnl_link_unregister(&ipgre_link_ops); rtnl_link_failed: - unregister_pernet_device(&ipgre_net_ops); -gen_device_failed: inet_del_protocol(&ipgre_protocol, IPPROTO_GRE); +add_proto_failed: + unregister_pernet_device(&ipgre_net_ops); goto out; } @@ -1698,9 +1699,9 @@ static void __exit ipgre_fini(void) { rtnl_link_unregister(&ipgre_tap_ops); rtnl_link_unregister(&ipgre_link_ops); - unregister_pernet_device(&ipgre_net_ops); if (inet_del_protocol(&ipgre_protocol, IPPROTO_GRE) < 0) printk(KERN_INFO "ipgre close: can't remove protocol\n"); + unregister_pernet_device(&ipgre_net_ops); } module_init(ipgre_init);