Skip to content

Commit 4e0d58b

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 5d8a485 commit 4e0d58b

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
@@ -3873,6 +3873,7 @@ static const struct bpf_func_proto sk_skb_change_tail_proto = {
38733873
static inline int __bpf_skb_change_head(struct sk_buff *skb, u32 head_room,
38743874
u64 flags)
38753875
{
3876+
const u8 meta_len = skb_metadata_len(skb);
38763877
u32 max_len = BPF_SKB_MAX_LEN;
38773878
u32 new_len = skb->len + head_room;
38783879
int ret;
@@ -3881,7 +3882,7 @@ static inline int __bpf_skb_change_head(struct sk_buff *skb, u32 head_room,
38813882
new_len < skb->len))
38823883
return -EINVAL;
38833884

3884-
ret = skb_cow(skb, head_room);
3885+
ret = skb_cow(skb, meta_len + head_room);
38853886
if (likely(!ret)) {
38863887
/* Idea for this helper is that we currently only
38873888
* allow to expand on mac header. This means that
@@ -3893,6 +3894,7 @@ static inline int __bpf_skb_change_head(struct sk_buff *skb, u32 head_room,
38933894
* for redirection into L2 device.
38943895
*/
38953896
__skb_push(skb, head_room);
3897+
skb_postpush_data_move(skb, head_room, 0);
38963898
memset(skb->data, 0, head_room);
38973899
skb_reset_mac_header(skb);
38983900
skb_reset_mac_len(skb);

0 commit comments

Comments
 (0)