Skip to content

Commit

Permalink
bpf: pull before calling skb_postpull_rcsum()
Browse files Browse the repository at this point in the history
Anand hit a BUG() when pulling off headers on egress to a SW tunnel.
We get to skb_checksum_help() with an invalid checksum offset
(commit d7ea0d9 ("net: remove two BUG() from skb_checksum_help()")
converted those BUGs to WARN_ONs()).
He points out oddness in how skb_postpull_rcsum() gets used.
Indeed looks like we should pull before "postpull", otherwise
the CHECKSUM_PARTIAL fixup from skb_postpull_rcsum() will not
be able to do its job:

	if (skb->ip_summed == CHECKSUM_PARTIAL &&
	    skb_checksum_start_offset(skb) < 0)
		skb->ip_summed = CHECKSUM_NONE;

Reported-by: Anand Parthasarathy <anpartha@meta.com>
Fixes: 6578171 ("bpf: add bpf_skb_change_proto helper")
Signed-off-by: Jakub Kicinski <kuba@kernel.org>
Acked-by: Stanislav Fomichev <sdf@google.com>
Link: https://lore.kernel.org/r/20221220004701.402165-1-kuba@kernel.org
Signed-off-by: Martin KaFai Lau <martin.lau@kernel.org>
  • Loading branch information
kuba-moo authored and Martin KaFai Lau committed Dec 20, 2022
1 parent cc07482 commit 54c3f1a
Showing 1 changed file with 5 additions and 2 deletions.
7 changes: 5 additions & 2 deletions net/core/filter.c
Original file line number Diff line number Diff line change
Expand Up @@ -3180,15 +3180,18 @@ static int bpf_skb_generic_push(struct sk_buff *skb, u32 off, u32 len)

static int bpf_skb_generic_pop(struct sk_buff *skb, u32 off, u32 len)
{
void *old_data;

/* skb_ensure_writable() is not needed here, as we're
* already working on an uncloned skb.
*/
if (unlikely(!pskb_may_pull(skb, off + len)))
return -ENOMEM;

skb_postpull_rcsum(skb, skb->data + off, len);
memmove(skb->data + len, skb->data, off);
old_data = skb->data;
__skb_pull(skb, len);
skb_postpull_rcsum(skb, old_data + off, len);
memmove(skb->data, old_data, off);

return 0;
}
Expand Down

0 comments on commit 54c3f1a

Please sign in to comment.