Skip to content

Commit c87b4ec

Browse files
tohojodavem330
authored andcommitted
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: Kevin Darbyshire-Bryant <kevin@darbyshire-bryant.me.uk> Signed-off-by: Toke Høiland-Jørgensen <toke@redhat.com> Signed-off-by: David S. Miller <davem@davemloft.net>
1 parent b2100cc commit c87b4ec

File tree

1 file changed

+11
-0
lines changed

1 file changed

+11
-0
lines changed

net/sched/sch_cake.c

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1517,16 +1517,27 @@ static unsigned int cake_drop(struct Qdisc *sch, struct sk_buff **to_free)
15171517

15181518
static u8 cake_handle_diffserv(struct sk_buff *skb, u16 wash)
15191519
{
1520+
int wlen = skb_network_offset(skb);
15201521
u8 dscp;
15211522

15221523
switch (tc_skb_protocol(skb)) {
15231524
case htons(ETH_P_IP):
1525+
wlen += sizeof(struct iphdr);
1526+
if (!pskb_may_pull(skb, wlen) ||
1527+
skb_try_make_writable(skb, wlen))
1528+
return 0;
1529+
15241530
dscp = ipv4_get_dsfield(ip_hdr(skb)) >> 2;
15251531
if (wash && dscp)
15261532
ipv4_change_dsfield(ip_hdr(skb), INET_ECN_MASK, 0);
15271533
return dscp;
15281534

15291535
case htons(ETH_P_IPV6):
1536+
wlen += sizeof(struct ipv6hdr);
1537+
if (!pskb_may_pull(skb, wlen) ||
1538+
skb_try_make_writable(skb, wlen))
1539+
return 0;
1540+
15301541
dscp = ipv6_get_dsfield(ipv6_hdr(skb)) >> 2;
15311542
if (wash && dscp)
15321543
ipv6_change_dsfield(ipv6_hdr(skb), INET_ECN_MASK, 0);

0 commit comments

Comments
 (0)