Skip to content

Commit 3a7d163

Browse files
jsitnickiKernel Patches Daemon
authored andcommitted
bpf: Make bpf_skb_change_head helper metadata-safe
Although bpf_skb_change_head() doesn't move packet data after skb_push(), skb metadata still needs to be relocated. Use the dedicated helper to handle it. Signed-off-by: Jakub Sitnicki <[email protected]>
1 parent 944d2a8 commit 3a7d163

File tree

1 file changed

+3
-1
lines changed

1 file changed

+3
-1
lines changed

net/core/filter.c

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3882,6 +3882,7 @@ static const struct bpf_func_proto sk_skb_change_tail_proto = {
38823882
static inline int __bpf_skb_change_head(struct sk_buff *skb, u32 head_room,
38833883
u64 flags)
38843884
{
3885+
const u8 meta_len = skb_metadata_len(skb);
38853886
u32 max_len = BPF_SKB_MAX_LEN;
38863887
u32 new_len = skb->len + head_room;
38873888
int ret;
@@ -3890,7 +3891,7 @@ static inline int __bpf_skb_change_head(struct sk_buff *skb, u32 head_room,
38903891
new_len < skb->len))
38913892
return -EINVAL;
38923893

3893-
ret = skb_cow(skb, head_room);
3894+
ret = skb_cow(skb, meta_len + head_room);
38943895
if (likely(!ret)) {
38953896
/* Idea for this helper is that we currently only
38963897
* allow to expand on mac header. This means that
@@ -3902,6 +3903,7 @@ static inline int __bpf_skb_change_head(struct sk_buff *skb, u32 head_room,
39023903
* for redirection into L2 device.
39033904
*/
39043905
__skb_push(skb, head_room);
3906+
skb_postpush_data_move(skb, head_room, 0);
39053907
memset(skb->data, 0, head_room);
39063908
skb_reset_mac_header(skb);
39073909
skb_reset_mac_len(skb);

0 commit comments

Comments
 (0)