Skip to content

Commit ffcfb8d

Browse files
acmeldavem330
authored andcommitted
Subject: [PATCH] appletalk: Fix skb leak when ipddp interface is not loaded
And also do a better job of returning proper NET_{RX,XMIT}_ values. Based on a patch and suggestions by Mark Smith. This fixes CVE-2009-2903 Reported-by: Mark Smith <lk-netdev@lk-netdev.nosense.org> Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com> Signed-off-by: David S. Miller <davem@davemloft.net>
1 parent 8ba69ba commit ffcfb8d

3 files changed

Lines changed: 36 additions & 30 deletions

File tree

‎drivers/net/appletalk/ipddp.c‎

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -177,8 +177,7 @@ static netdev_tx_t ipddp_xmit(struct sk_buff *skb, struct net_device *dev)
177177
dev->stats.tx_packets++;
178178
dev->stats.tx_bytes += skb->len;
179179

180-
if(aarp_send_ddp(rt->dev, skb, &rt->at, NULL) < 0)
181-
dev_kfree_skb(skb);
180+
aarp_send_ddp(rt->dev, skb, &rt->at, NULL);
182181

183182
spin_unlock(&ipddp_route_lock);
184183

‎net/appletalk/aarp.c‎

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -599,7 +599,7 @@ int aarp_send_ddp(struct net_device *dev, struct sk_buff *skb,
599599

600600
/* Non ELAP we cannot do. */
601601
if (dev->type != ARPHRD_ETHER)
602-
return -1;
602+
goto free_it;
603603

604604
skb->dev = dev;
605605
skb->protocol = htons(ETH_P_ATALK);
@@ -634,7 +634,7 @@ int aarp_send_ddp(struct net_device *dev, struct sk_buff *skb,
634634
if (!a) {
635635
/* Whoops slipped... good job it's an unreliable protocol 8) */
636636
write_unlock_bh(&aarp_lock);
637-
return -1;
637+
goto free_it;
638638
}
639639

640640
/* Set up the queue */
@@ -663,15 +663,21 @@ int aarp_send_ddp(struct net_device *dev, struct sk_buff *skb,
663663
write_unlock_bh(&aarp_lock);
664664

665665
/* Tell the ddp layer we have taken over for this frame. */
666-
return 0;
666+
goto sent;
667667

668668
sendit:
669669
if (skb->sk)
670670
skb->priority = skb->sk->sk_priority;
671-
dev_queue_xmit(skb);
671+
if (dev_queue_xmit(skb))
672+
goto drop;
672673
sent:
673-
return 1;
674+
return NET_XMIT_SUCCESS;
675+
free_it:
676+
kfree_skb(skb);
677+
drop:
678+
return NET_XMIT_DROP;
674679
}
680+
EXPORT_SYMBOL(aarp_send_ddp);
675681

676682
/*
677683
* An entry in the aarp unresolved queue has become resolved. Send

‎net/appletalk/ddp.c‎

Lines changed: 24 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1270,8 +1270,10 @@ static int handle_ip_over_ddp(struct sk_buff *skb)
12701270
struct net_device_stats *stats;
12711271

12721272
/* This needs to be able to handle ipddp"N" devices */
1273-
if (!dev)
1274-
return -ENODEV;
1273+
if (!dev) {
1274+
kfree_skb(skb);
1275+
return NET_RX_DROP;
1276+
}
12751277

12761278
skb->protocol = htons(ETH_P_IP);
12771279
skb_pull(skb, 13);
@@ -1281,18 +1283,16 @@ static int handle_ip_over_ddp(struct sk_buff *skb)
12811283
stats = netdev_priv(dev);
12821284
stats->rx_packets++;
12831285
stats->rx_bytes += skb->len + 13;
1284-
netif_rx(skb); /* Send the SKB up to a higher place. */
1285-
return 0;
1286+
return netif_rx(skb); /* Send the SKB up to a higher place. */
12861287
}
12871288
#else
12881289
/* make it easy for gcc to optimize this test out, i.e. kill the code */
12891290
#define is_ip_over_ddp(skb) 0
12901291
#define handle_ip_over_ddp(skb) 0
12911292
#endif
12921293

1293-
static void atalk_route_packet(struct sk_buff *skb, struct net_device *dev,
1294-
struct ddpehdr *ddp, __u16 len_hops,
1295-
int origlen)
1294+
static int atalk_route_packet(struct sk_buff *skb, struct net_device *dev,
1295+
struct ddpehdr *ddp, __u16 len_hops, int origlen)
12961296
{
12971297
struct atalk_route *rt;
12981298
struct atalk_addr ta;
@@ -1359,8 +1359,6 @@ static void atalk_route_packet(struct sk_buff *skb, struct net_device *dev,
13591359
/* 22 bytes - 12 ether, 2 len, 3 802.2 5 snap */
13601360
struct sk_buff *nskb = skb_realloc_headroom(skb, 32);
13611361
kfree_skb(skb);
1362-
if (!nskb)
1363-
goto out;
13641362
skb = nskb;
13651363
} else
13661364
skb = skb_unshare(skb, GFP_ATOMIC);
@@ -1369,12 +1367,16 @@ static void atalk_route_packet(struct sk_buff *skb, struct net_device *dev,
13691367
* If the buffer didn't vanish into the lack of space bitbucket we can
13701368
* send it.
13711369
*/
1372-
if (skb && aarp_send_ddp(rt->dev, skb, &ta, NULL) == -1)
1373-
goto free_it;
1374-
out:
1375-
return;
1370+
if (skb == NULL)
1371+
goto drop;
1372+
1373+
if (aarp_send_ddp(rt->dev, skb, &ta, NULL) == NET_XMIT_DROP)
1374+
return NET_RX_DROP;
1375+
return NET_XMIT_SUCCESS;
13761376
free_it:
13771377
kfree_skb(skb);
1378+
drop:
1379+
return NET_RX_DROP;
13781380
}
13791381

13801382
/**
@@ -1448,8 +1450,7 @@ static int atalk_rcv(struct sk_buff *skb, struct net_device *dev,
14481450
/* Not ours, so we route the packet via the correct
14491451
* AppleTalk iface
14501452
*/
1451-
atalk_route_packet(skb, dev, ddp, len_hops, origlen);
1452-
return NET_RX_SUCCESS;
1453+
return atalk_route_packet(skb, dev, ddp, len_hops, origlen);
14531454
}
14541455

14551456
/* if IP over DDP is not selected this code will be optimized out */
@@ -1655,10 +1656,10 @@ static int atalk_sendmsg(struct kiocb *iocb, struct socket *sock, struct msghdr
16551656
if (skb2) {
16561657
loopback = 1;
16571658
SOCK_DEBUG(sk, "SK %p: send out(copy).\n", sk);
1658-
if (aarp_send_ddp(dev, skb2,
1659-
&usat->sat_addr, NULL) == -1)
1660-
kfree_skb(skb2);
1661-
/* else queued/sent above in the aarp queue */
1659+
/*
1660+
* If it fails it is queued/sent above in the aarp queue
1661+
*/
1662+
aarp_send_ddp(dev, skb2, &usat->sat_addr, NULL);
16621663
}
16631664
}
16641665

@@ -1688,9 +1689,10 @@ static int atalk_sendmsg(struct kiocb *iocb, struct socket *sock, struct msghdr
16881689
usat = &gsat;
16891690
}
16901691

1691-
if (aarp_send_ddp(dev, skb, &usat->sat_addr, NULL) == -1)
1692-
kfree_skb(skb);
1693-
/* else queued/sent above in the aarp queue */
1692+
/*
1693+
* If it fails it is queued/sent above in the aarp queue
1694+
*/
1695+
aarp_send_ddp(dev, skb, &usat->sat_addr, NULL);
16941696
}
16951697
SOCK_DEBUG(sk, "SK %p: Done write (%Zd).\n", sk, len);
16961698

@@ -1868,7 +1870,6 @@ static struct packet_type ppptalk_packet_type __read_mostly = {
18681870
static unsigned char ddp_snap_id[] = { 0x08, 0x00, 0x07, 0x80, 0x9B };
18691871

18701872
/* Export symbols for use by drivers when AppleTalk is a module */
1871-
EXPORT_SYMBOL(aarp_send_ddp);
18721873
EXPORT_SYMBOL(atrtr_get_dev);
18731874
EXPORT_SYMBOL(atalk_find_dev_addr);
18741875

0 commit comments

Comments
 (0)