History

bridge: simplify ip_mc_check_igmp() and ipv6_mc_check_mld() calls

This patch refactors ip_mc_check_igmp(), ipv6_mc_check_mld() and their callers (more precisely, the Linux bridge) to not rely on the skb_trimmed parameter anymore. An skb with its tail trimmed to the IP packet length was initially introduced for the following three reasons: 1) To be able to verify the ICMPv6 checksum. 2) To be able to distinguish the version of an IGMP or MLD query. They are distinguishable only by their size. 3) To avoid parsing data for an IGMPv3 or MLDv2 report that is beyond the IP packet but still within the skb. The first case still uses a cloned and potentially trimmed skb to verfiy. However, there is no need to propagate it to the caller. For the second and third case explicit IP packet length checks were added. This hopefully makes ip_mc_check_igmp() and ipv6_mc_check_mld() easier to read and verfiy, as well as easier to use.

Linus Lüssing committed 7 years ago

Commit ba5ea611 parent 6679cf08 files · +70 −72Browse files

Showing the changes to include/linux (3 of 8 files). Show all

Unified · Split

3 files
  1. include/linux/igmp.h +10 −1
  2. include/linux/ip.h +5 −0
  3. include/linux/ipv6.h +6 −0
include/linux/igmp.h+10−1
@@ -18,6 +18,7 @@ · 17 unmodified lines
1818 #include <linux/skbuff.h>
1919 #include <linux/timer.h>
2020 #include <linux/in.h>
21+#include <linux/ip.h>
2122 #include <linux/refcount.h>
2223 #include <uapi/linux/igmp.h>
2324
@@ -106,6 +107,14 @@ struct ip_mc_list { · 82 unmodified lines
106107 #define IGMPV3_QQIC(value) IGMPV3_EXP(0x80, 4, 3, value)
107108 #define IGMPV3_MRC(value) IGMPV3_EXP(0x80, 4, 3, value)
108109
110+static inline int ip_mc_may_pull(struct sk_buff *skb, unsigned int len)
111+{
112+ if (skb_transport_offset(skb) + ip_transport_len(skb) < len)
113+ return -EINVAL;
114+
115+ return pskb_may_pull(skb, len);
116+}
117+
109118 extern int ip_check_mc_rcu(struct in_device *dev, __be32 mc_addr, __be32 src_addr, u8 proto);
110119 extern int igmp_rcv(struct sk_buff *);
111120 extern int ip_mc_join_group(struct sock *sk, struct ip_mreqn *imr);
@@ -130,6 +139,6 @@ extern void ip_mc_unmap(struct in_device *); · 18 unmodified lines
130139 extern void ip_mc_remap(struct in_device *);
131140 extern void ip_mc_dec_group(struct in_device *in_dev, __be32 addr);
132141 extern void ip_mc_inc_group(struct in_device *in_dev, __be32 addr);
133−int ip_mc_check_igmp(struct sk_buff *skb, struct sk_buff **skb_trimmed);
142+int ip_mc_check_igmp(struct sk_buff *skb);
134143
135144 #endif
include/linux/ip.h+5−0
@@ -34,4 +34,9 @@ static inline struct iphdr *ipip_hdr(const struct sk_buff *skb) · 33 unmodified lines
3434 {
3535 return (struct iphdr *)skb_transport_header(skb);
3636 }
37+
38+static inline unsigned int ip_transport_len(const struct sk_buff *skb)
39+{
40+ return ntohs(ip_hdr(skb)->tot_len) - skb_network_header_len(skb);
41+}
3742 #endif /* _LINUX_IP_H */
include/linux/ipv6.h+6−0
@@ -104,6 +104,12 @@ static inline struct ipv6hdr *ipipv6_hdr(const struct sk_buff *skb) · 103 unmodified lines
104104 return (struct ipv6hdr *)skb_transport_header(skb);
105105 }
106106
107+static inline unsigned int ipv6_transport_len(const struct sk_buff *skb)
108+{
109+ return ntohs(ipv6_hdr(skb)->payload_len) + sizeof(struct ipv6hdr) -
110+ skb_network_header_len(skb);
111+}
112+
107113 /*
108114 This structure contains results of exthdrs parsing
109115 as offsets from skb->nh.

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t