Skip to content

Commit b3f662c

Browse files
edumazetgregkh
authored andcommitted
sch_dsmark: fix invalid skb_cow() usage
[ Upstream commit aea92fb ] 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>
1 parent 98d20e5 commit b3f662c

1 file changed

Lines changed: 8 additions & 2 deletions

File tree

net/sched/sch_dsmark.c

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -200,17 +200,23 @@ static int dsmark_enqueue(struct sk_buff *skb, struct Qdisc *sch,
200200
pr_debug("%s(skb %p,sch %p,[qdisc %p])\n", __func__, skb, sch, p);
201201

202202
if (p->set_tc_index) {
203+
int wlen = skb_network_offset(skb);
204+
203205
switch (tc_skb_protocol(skb)) {
204206
case htons(ETH_P_IP):
205-
if (skb_cow_head(skb, sizeof(struct iphdr)))
207+
wlen += sizeof(struct iphdr);
208+
if (!pskb_may_pull(skb, wlen) ||
209+
skb_try_make_writable(skb, wlen))
206210
goto drop;
207211

208212
skb->tc_index = ipv4_get_dsfield(ip_hdr(skb))
209213
& ~INET_ECN_MASK;
210214
break;
211215

212216
case htons(ETH_P_IPV6):
213-
if (skb_cow_head(skb, sizeof(struct ipv6hdr)))
217+
wlen += sizeof(struct ipv6hdr);
218+
if (!pskb_may_pull(skb, wlen) ||
219+
skb_try_make_writable(skb, wlen))
214220
goto drop;
215221

216222
skb->tc_index = ipv6_get_dsfield(ipv6_hdr(skb))

0 commit comments

Comments
 (0)