Skip to content

Commit

Permalink
net: don't call update_pmtu unconditionally
Browse files Browse the repository at this point in the history
Some dst_ops (e.g. md_dst_ops)) doesn't set this handler. It may result to:
"BUG: unable to handle kernel NULL pointer dereference at           (null)"

Let's add a helper to check if update_pmtu is available before calling it.

Fixes: 52a589d ("geneve: update skb dst pmtu on tx path")
Fixes: a93bf0f ("vxlan: update skb dst pmtu on tx path")
CC: Roman Kapl <[email protected]>
CC: Xin Long <[email protected]>
Signed-off-by: Nicolas Dichtel <[email protected]>
Signed-off-by: David S. Miller <[email protected]>
  • Loading branch information
NicolasDichtel authored and davem330 committed Jan 25, 2018
1 parent 4ee806d commit f15ca72
Show file tree
Hide file tree
Showing 9 changed files with 20 additions and 18 deletions.
3 changes: 1 addition & 2 deletions drivers/infiniband/ulp/ipoib/ipoib_cm.c
Original file line number Diff line number Diff line change
Expand Up @@ -1456,8 +1456,7 @@ void ipoib_cm_skb_too_long(struct net_device *dev, struct sk_buff *skb,
struct ipoib_dev_priv *priv = ipoib_priv(dev);
int e = skb_queue_empty(&priv->cm.skb_queue);

if (skb_dst(skb))
skb_dst(skb)->ops->update_pmtu(skb_dst(skb), NULL, skb, mtu);
skb_dst_update_pmtu(skb, mtu);

skb_queue_tail(&priv->cm.skb_queue, skb);
if (e)
Expand Down
4 changes: 2 additions & 2 deletions drivers/net/geneve.c
Original file line number Diff line number Diff line change
Expand Up @@ -829,7 +829,7 @@ static int geneve_xmit_skb(struct sk_buff *skb, struct net_device *dev,
int mtu = dst_mtu(&rt->dst) - sizeof(struct iphdr) -
GENEVE_BASE_HLEN - info->options_len - 14;

skb_dst(skb)->ops->update_pmtu(skb_dst(skb), NULL, skb, mtu);
skb_dst_update_pmtu(skb, mtu);
}

sport = udp_flow_src_port(geneve->net, skb, 1, USHRT_MAX, true);
Expand Down Expand Up @@ -875,7 +875,7 @@ static int geneve6_xmit_skb(struct sk_buff *skb, struct net_device *dev,
int mtu = dst_mtu(dst) - sizeof(struct ipv6hdr) -
GENEVE_BASE_HLEN - info->options_len - 14;

skb_dst(skb)->ops->update_pmtu(skb_dst(skb), NULL, skb, mtu);
skb_dst_update_pmtu(skb, mtu);
}

sport = udp_flow_src_port(geneve->net, skb, 1, USHRT_MAX, true);
Expand Down
6 changes: 2 additions & 4 deletions drivers/net/vxlan.c
Original file line number Diff line number Diff line change
Expand Up @@ -2158,8 +2158,7 @@ static void vxlan_xmit_one(struct sk_buff *skb, struct net_device *dev,
if (skb_dst(skb)) {
int mtu = dst_mtu(ndst) - VXLAN_HEADROOM;

skb_dst(skb)->ops->update_pmtu(skb_dst(skb), NULL,
skb, mtu);
skb_dst_update_pmtu(skb, mtu);
}

tos = ip_tunnel_ecn_encap(tos, old_iph, skb);
Expand Down Expand Up @@ -2200,8 +2199,7 @@ static void vxlan_xmit_one(struct sk_buff *skb, struct net_device *dev,
if (skb_dst(skb)) {
int mtu = dst_mtu(ndst) - VXLAN6_HEADROOM;

skb_dst(skb)->ops->update_pmtu(skb_dst(skb), NULL,
skb, mtu);
skb_dst_update_pmtu(skb, mtu);
}

tos = ip_tunnel_ecn_encap(tos, old_iph, skb);
Expand Down
8 changes: 8 additions & 0 deletions include/net/dst.h
Original file line number Diff line number Diff line change
Expand Up @@ -521,4 +521,12 @@ static inline struct xfrm_state *dst_xfrm(const struct dst_entry *dst)
}
#endif

static inline void skb_dst_update_pmtu(struct sk_buff *skb, u32 mtu)
{
struct dst_entry *dst = skb_dst(skb);

if (dst && dst->ops->update_pmtu)
dst->ops->update_pmtu(dst, NULL, skb, mtu);
}

#endif /* _NET_DST_H */
3 changes: 1 addition & 2 deletions net/ipv4/ip_tunnel.c
Original file line number Diff line number Diff line change
Expand Up @@ -520,8 +520,7 @@ static int tnl_update_pmtu(struct net_device *dev, struct sk_buff *skb,
else
mtu = skb_dst(skb) ? dst_mtu(skb_dst(skb)) : dev->mtu;

if (skb_dst(skb))
skb_dst(skb)->ops->update_pmtu(skb_dst(skb), NULL, skb, mtu);
skb_dst_update_pmtu(skb, mtu);

if (skb->protocol == htons(ETH_P_IP)) {
if (!skb_is_gso(skb) &&
Expand Down
2 changes: 1 addition & 1 deletion net/ipv4/ip_vti.c
Original file line number Diff line number Diff line change
Expand Up @@ -200,7 +200,7 @@ static netdev_tx_t vti_xmit(struct sk_buff *skb, struct net_device *dev,

mtu = dst_mtu(dst);
if (skb->len > mtu) {
skb_dst(skb)->ops->update_pmtu(skb_dst(skb), NULL, skb, mtu);
skb_dst_update_pmtu(skb, mtu);
if (skb->protocol == htons(ETH_P_IP)) {
icmp_send(skb, ICMP_DEST_UNREACH, ICMP_FRAG_NEEDED,
htonl(mtu));
Expand Down
6 changes: 2 additions & 4 deletions net/ipv6/ip6_tunnel.c
Original file line number Diff line number Diff line change
Expand Up @@ -642,8 +642,7 @@ ip4ip6_err(struct sk_buff *skb, struct inet6_skb_parm *opt,
if (rel_info > dst_mtu(skb_dst(skb2)))
goto out;

skb_dst(skb2)->ops->update_pmtu(skb_dst(skb2), NULL, skb2,
rel_info);
skb_dst_update_pmtu(skb2, rel_info);
}

icmp_send(skb2, rel_type, rel_code, htonl(rel_info));
Expand Down Expand Up @@ -1131,8 +1130,7 @@ int ip6_tnl_xmit(struct sk_buff *skb, struct net_device *dev, __u8 dsfield,
mtu = 576;
}

if (skb_dst(skb) && !t->parms.collect_md)
skb_dst(skb)->ops->update_pmtu(skb_dst(skb), NULL, skb, mtu);
skb_dst_update_pmtu(skb, mtu);
if (skb->len - t->tun_hlen - eth_hlen > mtu && !skb_is_gso(skb)) {
*pmtu = mtu;
err = -EMSGSIZE;
Expand Down
2 changes: 1 addition & 1 deletion net/ipv6/ip6_vti.c
Original file line number Diff line number Diff line change
Expand Up @@ -483,7 +483,7 @@ vti6_xmit(struct sk_buff *skb, struct net_device *dev, struct flowi *fl)

mtu = dst_mtu(dst);
if (!skb->ignore_df && skb->len > mtu) {
skb_dst(skb)->ops->update_pmtu(dst, NULL, skb, mtu);
skb_dst_update_pmtu(skb, mtu);

if (skb->protocol == htons(ETH_P_IPV6)) {
if (mtu < IPV6_MIN_MTU)
Expand Down
4 changes: 2 additions & 2 deletions net/ipv6/sit.c
Original file line number Diff line number Diff line change
Expand Up @@ -934,8 +934,8 @@ static netdev_tx_t ipip6_tunnel_xmit(struct sk_buff *skb,
df = 0;
}

if (tunnel->parms.iph.daddr && skb_dst(skb))
skb_dst(skb)->ops->update_pmtu(skb_dst(skb), NULL, skb, mtu);
if (tunnel->parms.iph.daddr)
skb_dst_update_pmtu(skb, mtu);

if (skb->len > mtu && !skb_is_gso(skb)) {
icmpv6_send(skb, ICMPV6_PKT_TOOBIG, 0, mtu);
Expand Down

0 comments on commit f15ca72

Please sign in to comment.