Commit c87b4ecd authored by Toke Høiland-Jørgensen's avatar Toke Høiland-Jørgensen Committed by David S. Miller

sch_cake: Make sure we can write the IP header before changing DSCP bits

There is not actually any guarantee that the IP headers are valid before we
access the DSCP bits of the packets. Fix this using the same approach taken
in sch_dsmark.
Reported-by: default avatarKevin Darbyshire-Bryant <kevin@darbyshire-bryant.me.uk>
Signed-off-by: default avatarToke Høiland-Jørgensen <toke@redhat.com>
Signed-off-by: default avatarDavid S. Miller <davem@davemloft.net>
parent b2100cc5
...@@ -1517,16 +1517,27 @@ static unsigned int cake_drop(struct Qdisc *sch, struct sk_buff **to_free) ...@@ -1517,16 +1517,27 @@ static unsigned int cake_drop(struct Qdisc *sch, struct sk_buff **to_free)
static u8 cake_handle_diffserv(struct sk_buff *skb, u16 wash) static u8 cake_handle_diffserv(struct sk_buff *skb, u16 wash)
{ {
int wlen = skb_network_offset(skb);
u8 dscp; u8 dscp;
switch (tc_skb_protocol(skb)) { switch (tc_skb_protocol(skb)) {
case htons(ETH_P_IP): case htons(ETH_P_IP):
wlen += sizeof(struct iphdr);
if (!pskb_may_pull(skb, wlen) ||
skb_try_make_writable(skb, wlen))
return 0;
dscp = ipv4_get_dsfield(ip_hdr(skb)) >> 2; dscp = ipv4_get_dsfield(ip_hdr(skb)) >> 2;
if (wash && dscp) if (wash && dscp)
ipv4_change_dsfield(ip_hdr(skb), INET_ECN_MASK, 0); ipv4_change_dsfield(ip_hdr(skb), INET_ECN_MASK, 0);
return dscp; return dscp;
case htons(ETH_P_IPV6): case htons(ETH_P_IPV6):
wlen += sizeof(struct ipv6hdr);
if (!pskb_may_pull(skb, wlen) ||
skb_try_make_writable(skb, wlen))
return 0;
dscp = ipv6_get_dsfield(ipv6_hdr(skb)) >> 2; dscp = ipv6_get_dsfield(ipv6_hdr(skb)) >> 2;
if (wash && dscp) if (wash && dscp)
ipv6_change_dsfield(ipv6_hdr(skb), INET_ECN_MASK, 0); ipv6_change_dsfield(ipv6_hdr(skb), INET_ECN_MASK, 0);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment