Skip to content

Commit

Permalink
sch_dsmark: fix invalid skb_cow() usage
Browse files Browse the repository at this point in the history
[ Upstream commit aea92fb2e09e29653b023d4254ac9fbf94221538 ]

skb_cow(skb, sizeof(ip header)) is not very helpful in this context.

First we need to use pskb_may_pull() to make sure the ip header
is in skb linear part, then use skb_try_make_writable() to
address clones issues.

Fixes: 4c30719 ("[PKT_SCHED] dsmark: handle cloned and non-linear skb's")
Signed-off-by: Eric Dumazet <edumazet@google.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
Signed-off-by: Sasha Levin <alexander.levin@verizon.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Signed-off-by: Lee Jones <lee.jones@linaro.org>
Change-Id: I33bdf15c8ffc4cc109d8320c765bb7b8ecec92cc
  • Loading branch information
Eric Dumazet authored and Lee Jones committed Dec 9, 2020
1 parent 398615c commit 36a6b60
Showing 1 changed file with 8 additions and 2 deletions.
10 changes: 8 additions & 2 deletions net/sched/sch_dsmark.c
Original file line number Diff line number Diff line change
Expand Up @@ -197,17 +197,23 @@ static int dsmark_enqueue(struct sk_buff *skb, struct Qdisc *sch)
pr_debug("%s(skb %p,sch %p,[qdisc %p])\n", __func__, skb, sch, p);

if (p->set_tc_index) {
int wlen = skb_network_offset(skb);

switch (skb->protocol) {
case htons(ETH_P_IP):
if (skb_cow_head(skb, sizeof(struct iphdr)))
wlen += sizeof(struct iphdr);
if (!pskb_may_pull(skb, wlen) ||
skb_try_make_writable(skb, wlen))
goto drop;

skb->tc_index = ipv4_get_dsfield(ip_hdr(skb))
& ~INET_ECN_MASK;
break;

case htons(ETH_P_IPV6):
if (skb_cow_head(skb, sizeof(struct ipv6hdr)))
wlen += sizeof(struct ipv6hdr);
if (!pskb_may_pull(skb, wlen) ||
skb_try_make_writable(skb, wlen))
goto drop;

skb->tc_index = ipv6_get_dsfield(ipv6_hdr(skb))
Expand Down

0 comments on commit 36a6b60

Please sign in to comment.