aboutsummaryrefslogtreecommitdiffstats
path: root/net
diff options
context:
space:
mode:
authorEric W. Biederman <ebiederm@xmission.com>2007-09-17 14:53:39 -0400
committerDavid S. Miller <davem@sunset.davemloft.net>2007-10-10 19:49:08 -0400
commite730c15519d09ea528b4d2f1103681fa5937c0e6 (patch)
treec117294523f4d004fb1d740610b6403e5744cdfc /net
parent6d34b1c27a72d5d1c73c567b2f6b1fde316e0eae (diff)
[NET]: Make packet reception network namespace safe
This patch modifies every packet receive function registered with dev_add_pack() to drop packets if they are not from the initial network namespace. This should ensure that the various network stacks do not receive packets in a anything but the initial network namespace until the code has been converted and is ready for them. Signed-off-by: Eric W. Biederman <ebiederm@xmission.com> Signed-off-by: David S. Miller <davem@davemloft.net>
Diffstat (limited to 'net')
-rw-r--r--net/8021q/vlan_dev.c5
-rw-r--r--net/appletalk/aarp.c3
-rw-r--r--net/appletalk/ddp.c6
-rw-r--r--net/ax25/ax25_in.c5
-rw-r--r--net/bridge/br_stp_bpdu.c4
-rw-r--r--net/decnet/dn_route.c3
-rw-r--r--net/econet/af_econet.c3
-rw-r--r--net/ipv4/arp.c3
-rw-r--r--net/ipv4/ip_input.c3
-rw-r--r--net/ipv4/ipconfig.c6
-rw-r--r--net/ipv6/ip6_input.c5
-rw-r--r--net/ipx/af_ipx.c3
-rw-r--r--net/irda/irlap_frame.c3
-rw-r--r--net/llc/llc_input.c4
-rw-r--r--net/packet/af_packet.c9
-rw-r--r--net/tipc/eth_media.c6
-rw-r--r--net/x25/x25_dev.c3
17 files changed, 74 insertions, 0 deletions
diff --git a/net/8021q/vlan_dev.c b/net/8021q/vlan_dev.c
index 328759c32d61..6644e8f5f199 100644
--- a/net/8021q/vlan_dev.c
+++ b/net/8021q/vlan_dev.c
@@ -122,6 +122,11 @@ int vlan_skb_recv(struct sk_buff *skb, struct net_device *dev,
122 unsigned short vlan_TCI; 122 unsigned short vlan_TCI;
123 __be16 proto; 123 __be16 proto;
124 124
125 if (dev->nd_net != &init_net) {
126 kfree_skb(skb);
127 return -1;
128 }
129
125 if ((skb = skb_share_check(skb, GFP_ATOMIC)) == NULL) 130 if ((skb = skb_share_check(skb, GFP_ATOMIC)) == NULL)
126 return -1; 131 return -1;
127 132
diff --git a/net/appletalk/aarp.c b/net/appletalk/aarp.c
index 80b54148460f..9267f4818795 100644
--- a/net/appletalk/aarp.c
+++ b/net/appletalk/aarp.c
@@ -713,6 +713,9 @@ static int aarp_rcv(struct sk_buff *skb, struct net_device *dev,
713 struct atalk_addr sa, *ma, da; 713 struct atalk_addr sa, *ma, da;
714 struct atalk_iface *ifa; 714 struct atalk_iface *ifa;
715 715
716 if (dev->nd_net != &init_net)
717 goto out0;
718
716 /* We only do Ethernet SNAP AARP. */ 719 /* We only do Ethernet SNAP AARP. */
717 if (dev->type != ARPHRD_ETHER) 720 if (dev->type != ARPHRD_ETHER)
718 goto out0; 721 goto out0;
diff --git a/net/appletalk/ddp.c b/net/appletalk/ddp.c
index fd1d52f09707..c1f1367cad48 100644
--- a/net/appletalk/ddp.c
+++ b/net/appletalk/ddp.c
@@ -1403,6 +1403,9 @@ static int atalk_rcv(struct sk_buff *skb, struct net_device *dev,
1403 int origlen; 1403 int origlen;
1404 __u16 len_hops; 1404 __u16 len_hops;
1405 1405
1406 if (dev->nd_net != &init_net)
1407 goto freeit;
1408
1406 /* Don't mangle buffer if shared */ 1409 /* Don't mangle buffer if shared */
1407 if (!(skb = skb_share_check(skb, GFP_ATOMIC))) 1410 if (!(skb = skb_share_check(skb, GFP_ATOMIC)))
1408 goto out; 1411 goto out;
@@ -1488,6 +1491,9 @@ freeit:
1488static int ltalk_rcv(struct sk_buff *skb, struct net_device *dev, 1491static int ltalk_rcv(struct sk_buff *skb, struct net_device *dev,
1489 struct packet_type *pt, struct net_device *orig_dev) 1492 struct packet_type *pt, struct net_device *orig_dev)
1490{ 1493{
1494 if (dev->nd_net != &init_net)
1495 goto freeit;
1496
1491 /* Expand any short form frames */ 1497 /* Expand any short form frames */
1492 if (skb_mac_header(skb)[2] == 1) { 1498 if (skb_mac_header(skb)[2] == 1) {
1493 struct ddpehdr *ddp; 1499 struct ddpehdr *ddp;
diff --git a/net/ax25/ax25_in.c b/net/ax25/ax25_in.c
index 0ddaff0df217..3b7d1720c2ee 100644
--- a/net/ax25/ax25_in.c
+++ b/net/ax25/ax25_in.c
@@ -451,6 +451,11 @@ int ax25_kiss_rcv(struct sk_buff *skb, struct net_device *dev,
451 skb->sk = NULL; /* Initially we don't know who it's for */ 451 skb->sk = NULL; /* Initially we don't know who it's for */
452 skb->destructor = NULL; /* Who initializes this, dammit?! */ 452 skb->destructor = NULL; /* Who initializes this, dammit?! */
453 453
454 if (dev->nd_net != &init_net) {
455 kfree_skb(skb);
456 return 0;
457 }
458
454 if ((*skb->data & 0x0F) != 0) { 459 if ((*skb->data & 0x0F) != 0) {
455 kfree_skb(skb); /* Not a KISS data frame */ 460 kfree_skb(skb); /* Not a KISS data frame */
456 return 0; 461 return 0;
diff --git a/net/bridge/br_stp_bpdu.c b/net/bridge/br_stp_bpdu.c
index 14f0c888eecc..0edbd2a1c3f3 100644
--- a/net/bridge/br_stp_bpdu.c
+++ b/net/bridge/br_stp_bpdu.c
@@ -17,6 +17,7 @@
17#include <linux/netfilter_bridge.h> 17#include <linux/netfilter_bridge.h>
18#include <linux/etherdevice.h> 18#include <linux/etherdevice.h>
19#include <linux/llc.h> 19#include <linux/llc.h>
20#include <net/net_namespace.h>
20#include <net/llc.h> 21#include <net/llc.h>
21#include <net/llc_pdu.h> 22#include <net/llc_pdu.h>
22#include <asm/unaligned.h> 23#include <asm/unaligned.h>
@@ -141,6 +142,9 @@ int br_stp_rcv(struct sk_buff *skb, struct net_device *dev,
141 struct net_bridge *br; 142 struct net_bridge *br;
142 const unsigned char *buf; 143 const unsigned char *buf;
143 144
145 if (dev->nd_net != &init_net)
146 goto err;
147
144 if (!p) 148 if (!p)
145 goto err; 149 goto err;
146 150
diff --git a/net/decnet/dn_route.c b/net/decnet/dn_route.c
index 4cfea9563d2a..580e786d0c38 100644
--- a/net/decnet/dn_route.c
+++ b/net/decnet/dn_route.c
@@ -584,6 +584,9 @@ int dn_route_rcv(struct sk_buff *skb, struct net_device *dev, struct packet_type
584 struct dn_dev *dn = (struct dn_dev *)dev->dn_ptr; 584 struct dn_dev *dn = (struct dn_dev *)dev->dn_ptr;
585 unsigned char padlen = 0; 585 unsigned char padlen = 0;
586 586
587 if (dev->nd_net != &init_net)
588 goto dump_it;
589
587 if (dn == NULL) 590 if (dn == NULL)
588 goto dump_it; 591 goto dump_it;
589 592
diff --git a/net/econet/af_econet.c b/net/econet/af_econet.c
index a2429dbcb86e..7de3006af206 100644
--- a/net/econet/af_econet.c
+++ b/net/econet/af_econet.c
@@ -1065,6 +1065,9 @@ static int econet_rcv(struct sk_buff *skb, struct net_device *dev, struct packet
1065 struct sock *sk; 1065 struct sock *sk;
1066 struct ec_device *edev = dev->ec_ptr; 1066 struct ec_device *edev = dev->ec_ptr;
1067 1067
1068 if (dev->nd_net != &init_net)
1069 goto drop;
1070
1068 if (skb->pkt_type == PACKET_OTHERHOST) 1071 if (skb->pkt_type == PACKET_OTHERHOST)
1069 goto drop; 1072 goto drop;
1070 1073
diff --git a/net/ipv4/arp.c b/net/ipv4/arp.c
index 78dd3443016c..bde129708e22 100644
--- a/net/ipv4/arp.c
+++ b/net/ipv4/arp.c
@@ -932,6 +932,9 @@ static int arp_rcv(struct sk_buff *skb, struct net_device *dev,
932{ 932{
933 struct arphdr *arp; 933 struct arphdr *arp;
934 934
935 if (dev->nd_net != &init_net)
936 goto freeskb;
937
935 /* ARP header, plus 2 device addresses, plus 2 IP addresses. */ 938 /* ARP header, plus 2 device addresses, plus 2 IP addresses. */
936 if (!pskb_may_pull(skb, (sizeof(struct arphdr) + 939 if (!pskb_may_pull(skb, (sizeof(struct arphdr) +
937 (2 * dev->addr_len) + 940 (2 * dev->addr_len) +
diff --git a/net/ipv4/ip_input.c b/net/ipv4/ip_input.c
index 97069399d864..41d8964591e7 100644
--- a/net/ipv4/ip_input.c
+++ b/net/ipv4/ip_input.c
@@ -382,6 +382,9 @@ int ip_rcv(struct sk_buff *skb, struct net_device *dev, struct packet_type *pt,
382 struct iphdr *iph; 382 struct iphdr *iph;
383 u32 len; 383 u32 len;
384 384
385 if (dev->nd_net != &init_net)
386 goto drop;
387
385 /* When the interface is in promisc. mode, drop all the crap 388 /* When the interface is in promisc. mode, drop all the crap
386 * that it receives, do not try to analyse it. 389 * that it receives, do not try to analyse it.
387 */ 390 */
diff --git a/net/ipv4/ipconfig.c b/net/ipv4/ipconfig.c
index 5ae4849878a3..08ff623371f0 100644
--- a/net/ipv4/ipconfig.c
+++ b/net/ipv4/ipconfig.c
@@ -426,6 +426,9 @@ ic_rarp_recv(struct sk_buff *skb, struct net_device *dev, struct packet_type *pt
426 unsigned char *sha, *tha; /* s for "source", t for "target" */ 426 unsigned char *sha, *tha; /* s for "source", t for "target" */
427 struct ic_device *d; 427 struct ic_device *d;
428 428
429 if (dev->nd_net != &init_net)
430 goto drop;
431
429 if ((skb = skb_share_check(skb, GFP_ATOMIC)) == NULL) 432 if ((skb = skb_share_check(skb, GFP_ATOMIC)) == NULL)
430 return NET_RX_DROP; 433 return NET_RX_DROP;
431 434
@@ -835,6 +838,9 @@ static int __init ic_bootp_recv(struct sk_buff *skb, struct net_device *dev, str
835 struct ic_device *d; 838 struct ic_device *d;
836 int len, ext_len; 839 int len, ext_len;
837 840
841 if (dev->nd_net != &init_net)
842 goto drop;
843
838 /* Perform verifications before taking the lock. */ 844 /* Perform verifications before taking the lock. */
839 if (skb->pkt_type == PACKET_OTHERHOST) 845 if (skb->pkt_type == PACKET_OTHERHOST)
840 goto drop; 846 goto drop;
diff --git a/net/ipv6/ip6_input.c b/net/ipv6/ip6_input.c
index 30a5cb1b203e..7d18cac3f110 100644
--- a/net/ipv6/ip6_input.c
+++ b/net/ipv6/ip6_input.c
@@ -61,6 +61,11 @@ int ipv6_rcv(struct sk_buff *skb, struct net_device *dev, struct packet_type *pt
61 u32 pkt_len; 61 u32 pkt_len;
62 struct inet6_dev *idev; 62 struct inet6_dev *idev;
63 63
64 if (dev->nd_net != &init_net) {
65 kfree_skb(skb);
66 return 0;
67 }
68
64 if (skb->pkt_type == PACKET_OTHERHOST) { 69 if (skb->pkt_type == PACKET_OTHERHOST) {
65 kfree_skb(skb); 70 kfree_skb(skb);
66 return 0; 71 return 0;
diff --git a/net/ipx/af_ipx.c b/net/ipx/af_ipx.c
index ee28babad227..f7b4d383c609 100644
--- a/net/ipx/af_ipx.c
+++ b/net/ipx/af_ipx.c
@@ -1647,6 +1647,9 @@ static int ipx_rcv(struct sk_buff *skb, struct net_device *dev, struct packet_ty
1647 u16 ipx_pktsize; 1647 u16 ipx_pktsize;
1648 int rc = 0; 1648 int rc = 0;
1649 1649
1650 if (dev->nd_net != &init_net)
1651 goto drop;
1652
1650 /* Not ours */ 1653 /* Not ours */
1651 if (skb->pkt_type == PACKET_OTHERHOST) 1654 if (skb->pkt_type == PACKET_OTHERHOST)
1652 goto drop; 1655 goto drop;
diff --git a/net/irda/irlap_frame.c b/net/irda/irlap_frame.c
index 25a3444a9234..77ac27e81161 100644
--- a/net/irda/irlap_frame.c
+++ b/net/irda/irlap_frame.c
@@ -1326,6 +1326,9 @@ int irlap_driver_rcv(struct sk_buff *skb, struct net_device *dev,
1326 int command; 1326 int command;
1327 __u8 control; 1327 __u8 control;
1328 1328
1329 if (dev->nd_net != &init_net)
1330 goto out;
1331
1329 /* FIXME: should we get our own field? */ 1332 /* FIXME: should we get our own field? */
1330 self = (struct irlap_cb *) dev->atalk_ptr; 1333 self = (struct irlap_cb *) dev->atalk_ptr;
1331 1334
diff --git a/net/llc/llc_input.c b/net/llc/llc_input.c
index 099ed8fec145..c40c9b2a345a 100644
--- a/net/llc/llc_input.c
+++ b/net/llc/llc_input.c
@@ -12,6 +12,7 @@
12 * See the GNU General Public License for more details. 12 * See the GNU General Public License for more details.
13 */ 13 */
14#include <linux/netdevice.h> 14#include <linux/netdevice.h>
15#include <net/net_namespace.h>
15#include <net/llc.h> 16#include <net/llc.h>
16#include <net/llc_pdu.h> 17#include <net/llc_pdu.h>
17#include <net/llc_sap.h> 18#include <net/llc_sap.h>
@@ -145,6 +146,9 @@ int llc_rcv(struct sk_buff *skb, struct net_device *dev,
145 int (*rcv)(struct sk_buff *, struct net_device *, 146 int (*rcv)(struct sk_buff *, struct net_device *,
146 struct packet_type *, struct net_device *); 147 struct packet_type *, struct net_device *);
147 148
149 if (dev->nd_net != &init_net)
150 goto drop;
151
148 /* 152 /*
149 * When the interface is in promisc. mode, drop all the crap that it 153 * When the interface is in promisc. mode, drop all the crap that it
150 * receives, do not try to analyse it. 154 * receives, do not try to analyse it.
diff --git a/net/packet/af_packet.c b/net/packet/af_packet.c
index 766b5faaed21..cae1ee4f2ad6 100644
--- a/net/packet/af_packet.c
+++ b/net/packet/af_packet.c
@@ -252,6 +252,9 @@ static int packet_rcv_spkt(struct sk_buff *skb, struct net_device *dev, struct
252 struct sock *sk; 252 struct sock *sk;
253 struct sockaddr_pkt *spkt; 253 struct sockaddr_pkt *spkt;
254 254
255 if (dev->nd_net != &init_net)
256 goto out;
257
255 /* 258 /*
256 * When we registered the protocol we saved the socket in the data 259 * When we registered the protocol we saved the socket in the data
257 * field for just this event. 260 * field for just this event.
@@ -452,6 +455,9 @@ static int packet_rcv(struct sk_buff *skb, struct net_device *dev, struct packet
452 int skb_len = skb->len; 455 int skb_len = skb->len;
453 unsigned int snaplen, res; 456 unsigned int snaplen, res;
454 457
458 if (dev->nd_net != &init_net)
459 goto drop;
460
455 if (skb->pkt_type == PACKET_LOOPBACK) 461 if (skb->pkt_type == PACKET_LOOPBACK)
456 goto drop; 462 goto drop;
457 463
@@ -568,6 +574,9 @@ static int tpacket_rcv(struct sk_buff *skb, struct net_device *dev, struct packe
568 struct sk_buff *copy_skb = NULL; 574 struct sk_buff *copy_skb = NULL;
569 struct timeval tv; 575 struct timeval tv;
570 576
577 if (dev->nd_net != &init_net)
578 goto drop;
579
571 if (skb->pkt_type == PACKET_LOOPBACK) 580 if (skb->pkt_type == PACKET_LOOPBACK)
572 goto drop; 581 goto drop;
573 582
diff --git a/net/tipc/eth_media.c b/net/tipc/eth_media.c
index 711ca4b1f051..d2ed23704189 100644
--- a/net/tipc/eth_media.c
+++ b/net/tipc/eth_media.c
@@ -38,6 +38,7 @@
38#include <net/tipc/tipc_bearer.h> 38#include <net/tipc/tipc_bearer.h>
39#include <net/tipc/tipc_msg.h> 39#include <net/tipc/tipc_msg.h>
40#include <linux/netdevice.h> 40#include <linux/netdevice.h>
41#include <net/net_namespace.h>
41 42
42#define MAX_ETH_BEARERS 2 43#define MAX_ETH_BEARERS 2
43#define ETH_LINK_PRIORITY TIPC_DEF_LINK_PRI 44#define ETH_LINK_PRIORITY TIPC_DEF_LINK_PRI
@@ -100,6 +101,11 @@ static int recv_msg(struct sk_buff *buf, struct net_device *dev,
100 struct eth_bearer *eb_ptr = (struct eth_bearer *)pt->af_packet_priv; 101 struct eth_bearer *eb_ptr = (struct eth_bearer *)pt->af_packet_priv;
101 u32 size; 102 u32 size;
102 103
104 if (dev->nd_net != &init_net) {
105 kfree_skb(buf);
106 return 0;
107 }
108
103 if (likely(eb_ptr->bearer)) { 109 if (likely(eb_ptr->bearer)) {
104 if (likely(buf->pkt_type <= PACKET_BROADCAST)) { 110 if (likely(buf->pkt_type <= PACKET_BROADCAST)) {
105 size = msg_size((struct tipc_msg *)buf->data); 111 size = msg_size((struct tipc_msg *)buf->data);
diff --git a/net/x25/x25_dev.c b/net/x25/x25_dev.c
index 848a6b6f90a6..f0679d283110 100644
--- a/net/x25/x25_dev.c
+++ b/net/x25/x25_dev.c
@@ -95,6 +95,9 @@ int x25_lapb_receive_frame(struct sk_buff *skb, struct net_device *dev,
95 struct sk_buff *nskb; 95 struct sk_buff *nskb;
96 struct x25_neigh *nb; 96 struct x25_neigh *nb;
97 97
98 if (dev->nd_net != &init_net)
99 goto drop;
100
98 nskb = skb_copy(skb, GFP_ATOMIC); 101 nskb = skb_copy(skb, GFP_ATOMIC);
99 if (!nskb) 102 if (!nskb)
100 goto drop; 103 goto drop;