diff options
author | Eric Dumazet <edumazet@google.com> | 2012-09-21 20:08:29 -0400 |
---|---|---|
committer | David S. Miller <davem@davemloft.net> | 2012-09-22 15:35:05 -0400 |
commit | ab43ed8b7490cb387782423ecf74aeee7237e591 (patch) | |
tree | 5c2083ad85142b2385669ba9fc01061de24debc8 /net/ipv4 | |
parent | 9913b8c8f05b0aad97432900fa3b2cdfd557eeb5 (diff) |
ipv4: raw: fix icmp_filter()
icmp_filter() should not modify its input, or else its caller
would need to recompute ip_hdr() if skb->head is reallocated.
Use skb_header_pointer() instead of pskb_may_pull() and
change the prototype to make clear both sk and skb are const.
Signed-off-by: Eric Dumazet <edumazet@google.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
Diffstat (limited to 'net/ipv4')
-rw-r--r-- | net/ipv4/raw.c | 14 |
1 files changed, 8 insertions, 6 deletions
diff --git a/net/ipv4/raw.c b/net/ipv4/raw.c index ff0f071969ea..d23c6571ba1c 100644 --- a/net/ipv4/raw.c +++ b/net/ipv4/raw.c | |||
@@ -131,18 +131,20 @@ found: | |||
131 | * 0 - deliver | 131 | * 0 - deliver |
132 | * 1 - block | 132 | * 1 - block |
133 | */ | 133 | */ |
134 | static __inline__ int icmp_filter(struct sock *sk, struct sk_buff *skb) | 134 | static int icmp_filter(const struct sock *sk, const struct sk_buff *skb) |
135 | { | 135 | { |
136 | int type; | 136 | struct icmphdr _hdr; |
137 | const struct icmphdr *hdr; | ||
137 | 138 | ||
138 | if (!pskb_may_pull(skb, sizeof(struct icmphdr))) | 139 | hdr = skb_header_pointer(skb, skb_transport_offset(skb), |
140 | sizeof(_hdr), &_hdr); | ||
141 | if (!hdr) | ||
139 | return 1; | 142 | return 1; |
140 | 143 | ||
141 | type = icmp_hdr(skb)->type; | 144 | if (hdr->type < 32) { |
142 | if (type < 32) { | ||
143 | __u32 data = raw_sk(sk)->filter.data; | 145 | __u32 data = raw_sk(sk)->filter.data; |
144 | 146 | ||
145 | return ((1 << type) & data) != 0; | 147 | return ((1U << hdr->type) & data) != 0; |
146 | } | 148 | } |
147 | 149 | ||
148 | /* Do not block unknown ICMP types */ | 150 | /* Do not block unknown ICMP types */ |