Skip to content

Commit

Permalink
mpls: In mpls_egress verify the packet length.
Browse files Browse the repository at this point in the history
Reobert Shearman noticed that mpls_egress is failing to verify that
the bytes to be examined are in fact present in the packet before
mpls_egress reads those bytes.

As suggested by David Miller reduce this to a single pskb_may_pull
call so that we don't do unnecessary work in the fast path.

Reported-by: Robert Shearman <rshearma@brocade.com>
Signed-off-by: "Eric W. Biederman" <ebiederm@xmission.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
  • Loading branch information
Eric W. Biederman authored and David S. Miller committed Mar 13, 2015
1 parent 2c29b23 commit 76fecd8
Showing 1 changed file with 16 additions and 1 deletion.
17 changes: 16 additions & 1 deletion net/mpls/af_mpls.c
Original file line number Diff line number Diff line change
Expand Up @@ -92,9 +92,24 @@ static bool mpls_egress(struct mpls_route *rt, struct sk_buff *skb,
* The strange cases if we choose to support them will require
* manual configuration.
*/
struct iphdr *hdr4 = ip_hdr(skb);
struct iphdr *hdr4;
bool success = true;

/* The IPv4 code below accesses through the IPv4 header
* checksum, which is 12 bytes into the packet.
* The IPv6 code below accesses through the IPv6 hop limit
* which is 8 bytes into the packet.
*
* For all supported cases there should always be at least 12
* bytes of packet data present. The IPv4 header is 20 bytes
* without options and the IPv6 header is always 40 bytes
* long.
*/
if (!pskb_may_pull(skb, 12))
return false;

/* Use ip_hdr to find the ip protocol version */
hdr4 = ip_hdr(skb);
if (hdr4->version == 4) {
skb->protocol = htons(ETH_P_IP);
csum_replace2(&hdr4->check,
Expand Down

0 comments on commit 76fecd8

Please sign in to comment.