Skip to content

Commit bdf1fa3

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 a7551ef commit bdf1fa3

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;
@@ -3891,7 +3892,7 @@ static inline int __bpf_skb_change_head(struct sk_buff *skb, u32 head_room,
38913892
new_len < skb->len))
38923893
return -EINVAL;
38933894

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

0 commit comments

Comments
 (0)