Skip to content

Commit 39935dc

Browse files
dougg3davem330
authored andcommitted
appletalk: Fix skb allocation size in loopback case
If a DDP broadcast packet is sent out to a non-gateway target, it is also looped back. There is a potential for the loopback device to have a longer hardware header length than the original target route's device, which can result in the skb not being created with enough room for the loopback device's hardware header. This patch fixes the issue by determining that a loopback will be necessary prior to allocating the skb, and if so, ensuring the skb has enough room. This was discovered while testing a new driver that creates a LocalTalk network interface (LTALK_HLEN = 1). It caused an skb_under_panic. Signed-off-by: Doug Brown <doug@schmorgal.com> Signed-off-by: David S. Miller <davem@davemloft.net>
1 parent 0c9fc2e commit 39935dc

1 file changed

Lines changed: 21 additions & 12 deletions

File tree

‎net/appletalk/ddp.c‎

Lines changed: 21 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1577,8 +1577,8 @@ static int atalk_sendmsg(struct socket *sock, struct msghdr *msg, size_t len)
15771577
struct sk_buff *skb;
15781578
struct net_device *dev;
15791579
struct ddpehdr *ddp;
1580-
int size;
1581-
struct atalk_route *rt;
1580+
int size, hard_header_len;
1581+
struct atalk_route *rt, *rt_lo = NULL;
15821582
int err;
15831583

15841584
if (flags & ~(MSG_DONTWAIT|MSG_CMSG_COMPAT))
@@ -1641,15 +1641,30 @@ static int atalk_sendmsg(struct socket *sock, struct msghdr *msg, size_t len)
16411641
SOCK_DEBUG(sk, "SK %p: Size needed %d, device %s\n",
16421642
sk, size, dev->name);
16431643

1644-
size += dev->hard_header_len;
1644+
hard_header_len = dev->hard_header_len;
1645+
/* Leave room for loopback hardware header if necessary */
1646+
if (usat->sat_addr.s_node == ATADDR_BCAST &&
1647+
(dev->flags & IFF_LOOPBACK || !(rt->flags & RTF_GATEWAY))) {
1648+
struct atalk_addr at_lo;
1649+
1650+
at_lo.s_node = 0;
1651+
at_lo.s_net = 0;
1652+
1653+
rt_lo = atrtr_find(&at_lo);
1654+
1655+
if (rt_lo && rt_lo->dev->hard_header_len > hard_header_len)
1656+
hard_header_len = rt_lo->dev->hard_header_len;
1657+
}
1658+
1659+
size += hard_header_len;
16451660
release_sock(sk);
16461661
skb = sock_alloc_send_skb(sk, size, (flags & MSG_DONTWAIT), &err);
16471662
lock_sock(sk);
16481663
if (!skb)
16491664
goto out;
16501665

16511666
skb_reserve(skb, ddp_dl->header_length);
1652-
skb_reserve(skb, dev->hard_header_len);
1667+
skb_reserve(skb, hard_header_len);
16531668
skb->dev = dev;
16541669

16551670
SOCK_DEBUG(sk, "SK %p: Begin build.\n", sk);
@@ -1700,18 +1715,12 @@ static int atalk_sendmsg(struct socket *sock, struct msghdr *msg, size_t len)
17001715
/* loop back */
17011716
skb_orphan(skb);
17021717
if (ddp->deh_dnode == ATADDR_BCAST) {
1703-
struct atalk_addr at_lo;
1704-
1705-
at_lo.s_node = 0;
1706-
at_lo.s_net = 0;
1707-
1708-
rt = atrtr_find(&at_lo);
1709-
if (!rt) {
1718+
if (!rt_lo) {
17101719
kfree_skb(skb);
17111720
err = -ENETUNREACH;
17121721
goto out;
17131722
}
1714-
dev = rt->dev;
1723+
dev = rt_lo->dev;
17151724
skb->dev = dev;
17161725
}
17171726
ddp_dl->request(ddp_dl, skb, dev->dev_addr);

0 commit comments

Comments
 (0)