All of lore.kernel.org
 help / color / mirror / Atom feed
From: sashiko-bot@kernel.org
To: "Kuniyuki Iwashima" <kuniyu@google.com>
Cc: bpf@vger.kernel.org
Subject: Re: [PATCH v2 bpf-next/net 3/5] bpf: Add bpf_skb_set_hwtstamp().
Date: Sat, 13 Jun 2026 01:12:52 +0000	[thread overview]
Message-ID: <20260613011253.0CA741F000E9@smtp.kernel.org> (raw)
In-Reply-To: <20260613010039.1362312-4-kuniyu@google.com>

Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
- [High] Potential use-after-free read of `attrs->hwtstamp` if the BPF program passes a pointer to the packet payload.
--

commit 41caec1764c831fb81388c5eab46d122318a01be
Author: Kuniyuki Iwashima <kuniyu@google.com>

bpf: Add bpf_skb_set_hwtstamp().

This commit adds a new kfunc, bpf_skb_set_hwtstamp(), to allow BPF programs
at TC ingress to update the hardware timestamp of an skb. This enables user
space proxies to encapsulate and pass hardware timestamps to socket
applications bypassing the kernel networking stack.

> diff --git a/net/core/filter.c b/net/core/filter.c
> index acdc66aa4f27c..bee1e7eee5eae 100644
> --- a/net/core/filter.c
> +++ b/net/core/filter.c
[ ... ]
> @@ -12372,6 +12372,30 @@ __bpf_kfunc int bpf_sock_ops_enable_tx_tstamp(struct bpf_sock_ops_kern *skops,
>  	return 0;
>  }
>  
> +__bpf_kfunc int bpf_skb_set_hwtstamp(struct __sk_buff *s,
> +				     struct bpf_hwtstamp *attrs, int attrs__sz)
> +{
> +	int defined_sz = offsetofend(struct bpf_hwtstamp, hwtstamp);
> +	struct sk_buff *skb = (struct sk_buff *)s;
> +
> +	if (attrs__sz != sizeof(*attrs) ||
> +	    memchr_inv((char *)attrs + defined_sz, 0, sizeof(u64)))
> +		return -EINVAL;
> +
> +	if (!skb_at_tc_ingress(skb))
> +		return -EINVAL;
> +
> +	if (skb_unclone(skb, GFP_ATOMIC))
> +		return -ENOMEM;
> +
> +	skb_clear_tstamp(skb);
> +	skb_hwtstamps(skb)->hwtstamp = attrs->hwtstamp;

[Severity: High]
Could this result in a use-after-free if the BPF program passes a pointer
to the packet payload as the attrs argument?

The BPF verifier allows passing a packet pointer to a kfunc argument that
has an associated size parameter (attrs__sz). If the attrs pointer points
into the packet's payload (skb->data) and the skb happens to be cloned,
skb_unclone() will invoke pskb_expand_head().

This reallocation frees the original packet buffer, meaning the attrs
pointer becomes dangling. The subsequent read of attrs->hwtstamp would then
dereference freed memory.

Would it be safer to read the attrs->hwtstamp value into a local variable
before calling skb_unclone()?

> +
> +	bpf_compute_data_pointers(skb);
> +
> +	return 0;
> +}

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/20260613010039.1362312-1-kuniyu@google.com?part=3

  reply	other threads:[~2026-06-13  1:12 UTC|newest]

Thread overview: 19+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-06-13  0:59 [PATCH v2 bpf-next/net 0/5] bpf: Support RX/TX HW timestamp proxy Kuniyuki Iwashima
2026-06-13  0:59 ` [PATCH v2 bpf-next/net 1/5] ethtool: Introduce ETHTOOL_MSG_TSINFO_SET for virtual interfaces Kuniyuki Iwashima
2026-06-13  1:21   ` sashiko-bot
2026-06-13  2:29   ` Stanislav Fomichev
2026-06-13  3:43     ` Kuniyuki Iwashima
2026-06-13  0:59 ` [PATCH v2 bpf-next/net 2/5] bpf: Rename bpf_kfunc_set_tcp_reqsk to bpf_kfunc_set_sched_cls Kuniyuki Iwashima
2026-06-13  1:00 ` [PATCH v2 bpf-next/net 3/5] bpf: Add bpf_skb_set_hwtstamp() Kuniyuki Iwashima
2026-06-13  1:12   ` sashiko-bot [this message]
2026-06-13 22:01     ` Kuniyuki Iwashima
2026-06-13  1:00 ` [PATCH v2 bpf-next/net 4/5] bpf: Add kfunc to proxy TX HW Timestamp Kuniyuki Iwashima
2026-06-13  1:20   ` sashiko-bot
2026-06-13 22:03     ` Kuniyuki Iwashima
2026-06-13  1:00 ` [PATCH v2 bpf-next/net 5/5] selftest: bpf: Add test for hwtstamp proxy Kuniyuki Iwashima
2026-06-13  1:31   ` Alexei Starovoitov
2026-06-13 22:08     ` Kuniyuki Iwashima
2026-06-13 17:20 ` [PATCH v2 bpf-next/net 0/5] bpf: Support RX/TX HW timestamp proxy Jakub Kicinski
2026-06-13 21:43   ` Kuniyuki Iwashima
2026-06-13 22:47     ` Jakub Kicinski
2026-06-13 23:18       ` Kuniyuki Iwashima

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20260613011253.0CA741F000E9@smtp.kernel.org \
    --to=sashiko-bot@kernel.org \
    --cc=bpf@vger.kernel.org \
    --cc=kuniyu@google.com \
    --cc=sashiko-reviews@lists.linux.dev \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.