Skip to content

Commit feb91a0

Browse files
Daniel Borkmanndavem330
authored andcommitted
ipv6: mld: fix add_grhead skb_over_panic for devs with large MTUs
It has been reported that generating an MLD listener report on devices with large MTUs (e.g. 9000) and a high number of IPv6 addresses can trigger a skb_over_panic(): skbuff: skb_over_panic: text:ffffffff80612a5d len:3776 put:20 head:ffff88046d751000 data:ffff88046d751010 tail:0xed0 end:0xec0 dev:port1 ------------[ cut here ]------------ kernel BUG at net/core/skbuff.c:100! invalid opcode: 0000 [#1] SMP Modules linked in: ixgbe(O) CPU: 3 PID: 0 Comm: swapper/3 Tainted: G O 3.14.23+ #4 [...] Call Trace: <IRQ> [<ffffffff80578226>] ? skb_put+0x3a/0x3b [<ffffffff80612a5d>] ? add_grhead+0x45/0x8e [<ffffffff80612e3a>] ? add_grec+0x394/0x3d4 [<ffffffff80613222>] ? mld_ifc_timer_expire+0x195/0x20d [<ffffffff8061308d>] ? mld_dad_timer_expire+0x45/0x45 [<ffffffff80255b5d>] ? call_timer_fn.isra.29+0x12/0x68 [<ffffffff80255d16>] ? run_timer_softirq+0x163/0x182 [<ffffffff80250e6f>] ? __do_softirq+0xe0/0x21d [<ffffffff8025112b>] ? irq_exit+0x4e/0xd3 [<ffffffff802214bb>] ? smp_apic_timer_interrupt+0x3b/0x46 [<ffffffff8063f10a>] ? apic_timer_interrupt+0x6a/0x70 mld_newpack() skb allocations are usually requested with dev->mtu in size, since commit 72e09ad ("ipv6: avoid high order allocations") we have changed the limit in order to be less likely to fail. However, in MLD/IGMP code, we have some rather ugly AVAILABLE(skb) macros, which determine if we may end up doing an skb_put() for adding another record. To avoid possible fragmentation, we check the skb's tailroom as skb->dev->mtu - skb->len, which is a wrong assumption as the actual max allocation size can be much smaller. The IGMP case doesn't have this issue as commit 57e1ab6 ("igmp: refine skb allocations") stores the allocation size in the cb[]. Set a reserved_tailroom to make it fit into the MTU and use skb_availroom() helper instead. This also allows to get rid of igmp_skb_size(). Reported-by: Wei Liu <[email protected]> Fixes: 72e09ad ("ipv6: avoid high order allocations") Signed-off-by: Daniel Borkmann <[email protected]> Cc: Eric Dumazet <[email protected]> Cc: Hannes Frederic Sowa <[email protected]> Cc: David L Stevens <[email protected]> Acked-by: Eric Dumazet <[email protected]> Acked-by: Hannes Frederic Sowa <[email protected]> Signed-off-by: David S. Miller <[email protected]>
1 parent bb2bdeb commit feb91a0

File tree

2 files changed

+10
-10
lines changed

2 files changed

+10
-10
lines changed

net/ipv4/igmp.c

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -318,9 +318,7 @@ igmp_scount(struct ip_mc_list *pmc, int type, int gdeleted, int sdeleted)
318318
return scount;
319319
}
320320

321-
#define igmp_skb_size(skb) (*(unsigned int *)((skb)->cb))
322-
323-
static struct sk_buff *igmpv3_newpack(struct net_device *dev, int size)
321+
static struct sk_buff *igmpv3_newpack(struct net_device *dev, unsigned int mtu)
324322
{
325323
struct sk_buff *skb;
326324
struct rtable *rt;
@@ -330,6 +328,7 @@ static struct sk_buff *igmpv3_newpack(struct net_device *dev, int size)
330328
struct flowi4 fl4;
331329
int hlen = LL_RESERVED_SPACE(dev);
332330
int tlen = dev->needed_tailroom;
331+
unsigned int size = mtu;
333332

334333
while (1) {
335334
skb = alloc_skb(size + hlen + tlen,
@@ -341,7 +340,6 @@ static struct sk_buff *igmpv3_newpack(struct net_device *dev, int size)
341340
return NULL;
342341
}
343342
skb->priority = TC_PRIO_CONTROL;
344-
igmp_skb_size(skb) = size;
345343

346344
rt = ip_route_output_ports(net, &fl4, NULL, IGMPV3_ALL_MCR, 0,
347345
0, 0,
@@ -354,6 +352,8 @@ static struct sk_buff *igmpv3_newpack(struct net_device *dev, int size)
354352
skb_dst_set(skb, &rt->dst);
355353
skb->dev = dev;
356354

355+
skb->reserved_tailroom = skb_end_offset(skb) -
356+
min(mtu, skb_end_offset(skb));
357357
skb_reserve(skb, hlen);
358358

359359
skb_reset_network_header(skb);
@@ -423,8 +423,7 @@ static struct sk_buff *add_grhead(struct sk_buff *skb, struct ip_mc_list *pmc,
423423
return skb;
424424
}
425425

426-
#define AVAILABLE(skb) ((skb) ? ((skb)->dev ? igmp_skb_size(skb) - (skb)->len : \
427-
skb_tailroom(skb)) : 0)
426+
#define AVAILABLE(skb) ((skb) ? skb_availroom(skb) : 0)
428427

429428
static struct sk_buff *add_grec(struct sk_buff *skb, struct ip_mc_list *pmc,
430429
int type, int gdeleted, int sdeleted)

net/ipv6/mcast.c

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1550,7 +1550,7 @@ static void ip6_mc_hdr(struct sock *sk, struct sk_buff *skb,
15501550
hdr->daddr = *daddr;
15511551
}
15521552

1553-
static struct sk_buff *mld_newpack(struct inet6_dev *idev, int size)
1553+
static struct sk_buff *mld_newpack(struct inet6_dev *idev, unsigned int mtu)
15541554
{
15551555
struct net_device *dev = idev->dev;
15561556
struct net *net = dev_net(dev);
@@ -1561,13 +1561,13 @@ static struct sk_buff *mld_newpack(struct inet6_dev *idev, int size)
15611561
const struct in6_addr *saddr;
15621562
int hlen = LL_RESERVED_SPACE(dev);
15631563
int tlen = dev->needed_tailroom;
1564+
unsigned int size = mtu + hlen + tlen;
15641565
int err;
15651566
u8 ra[8] = { IPPROTO_ICMPV6, 0,
15661567
IPV6_TLV_ROUTERALERT, 2, 0, 0,
15671568
IPV6_TLV_PADN, 0 };
15681569

15691570
/* we assume size > sizeof(ra) here */
1570-
size += hlen + tlen;
15711571
/* limit our allocations to order-0 page */
15721572
size = min_t(int, size, SKB_MAX_ORDER(0, 0));
15731573
skb = sock_alloc_send_skb(sk, size, 1, &err);
@@ -1576,6 +1576,8 @@ static struct sk_buff *mld_newpack(struct inet6_dev *idev, int size)
15761576
return NULL;
15771577

15781578
skb->priority = TC_PRIO_CONTROL;
1579+
skb->reserved_tailroom = skb_end_offset(skb) -
1580+
min(mtu, skb_end_offset(skb));
15791581
skb_reserve(skb, hlen);
15801582

15811583
if (__ipv6_get_lladdr(idev, &addr_buf, IFA_F_TENTATIVE)) {
@@ -1690,8 +1692,7 @@ static struct sk_buff *add_grhead(struct sk_buff *skb, struct ifmcaddr6 *pmc,
16901692
return skb;
16911693
}
16921694

1693-
#define AVAILABLE(skb) ((skb) ? ((skb)->dev ? (skb)->dev->mtu - (skb)->len : \
1694-
skb_tailroom(skb)) : 0)
1695+
#define AVAILABLE(skb) ((skb) ? skb_availroom(skb) : 0)
16951696

16961697
static struct sk_buff *add_grec(struct sk_buff *skb, struct ifmcaddr6 *pmc,
16971698
int type, int gdeleted, int sdeleted, int crsend)

0 commit comments

Comments
 (0)