All of lore.kernel.org
 help / color / mirror / Atom feed
From: sashiko-bot@kernel.org
To: "Jason Xing" <kerneljasonxing@gmail.com>
Cc: bpf@vger.kernel.org
Subject: Re: [PATCH net-next v2 3/6] bpf: support bpf_setsockopt for bpf timestamping rx feature
Date: Sat, 30 May 2026 00:46:02 +0000	[thread overview]
Message-ID: <20260530004602.E31E61F0089B@smtp.kernel.org> (raw)
In-Reply-To: <20260521135244.40869-4-kerneljasonxing@gmail.com>

Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
- [High] Lockless invocation of `sk_bpf_set_get_cb_flags` causes `sk_flags` corruption and global netstamp refcount leaks via `sock_enable_timestamp()` / `sock_disable_timestamp()`.
--

commit 3f400ad3640a19655fbde51eedae40506ebf95a8
Author: Jason Xing <kerneljasonxing@gmail.com>

bpf: support bpf_setsockopt for bpf timestamping rx feature

Add SK_BPF_CB_RX_TIMESTAMPING callback flag to enable RX timestamping via
bpf_setsockopt. It updates sk_flags centrally to manage the global network
timestamp static keys.

> diff --git a/net/core/filter.c b/net/core/filter.c
> index 9590877b0714f..08ad102f204e0 100644
> --- a/net/core/filter.c
> +++ b/net/core/filter.c
> @@ -5304,6 +5304,14 @@ static int sk_bpf_set_get_cb_flags(struct sock *sk, char *optval, bool getopt)
>  	if (sk_bpf_cb_flags & ~SK_BPF_CB_MASK)
>  		return -EINVAL;
>  
> +	if ((sk_bpf_cb_flags ^ sk->sk_bpf_cb_flags) & SK_BPF_CB_RX_TIMESTAMPING) {
> +		if (sk_bpf_cb_flags & SK_BPF_CB_RX_TIMESTAMPING)
> +			sock_enable_timestamp(sk, SOCK_BPF_TIMESTAMPING_RX);
> +		else
> +			sock_disable_timestamp(sk,
> +					       (1UL << SOCK_BPF_TIMESTAMPING_RX));
> +	}

[Severity: High]
Could this lead to socket flags corruption if called locklessly?

sk_bpf_set_get_cb_flags() can be reached without the socket lock held, such
as through the following call chain:

bpf_unlocked_sk_setsockopt()
  __bpf_setsockopt()
    sk_bpf_set_get_cb_flags()

Since sock_enable_timestamp() and sock_disable_timestamp() use non-atomic
bitwise operations to modify sk->sk_flags, concurrent execution might race
and accidentally drop critical flags like SOCK_DEAD or SOCK_DONE.

Additionally, because the checks against previous_flags in these functions
are not atomic with the bitwise updates, could a race here lead to unbalanced
net_enable_timestamp() or net_disable_timestamp() calls, permanently skewing
the global netstamp static key refcount?

> +
>  	sk->sk_bpf_cb_flags = sk_bpf_cb_flags;
>  
>  	return 0;

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/20260521135244.40869-1-kerneljasonxing@gmail.com?part=3

  parent reply	other threads:[~2026-05-30  0:46 UTC|newest]

Thread overview: 16+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-05-21 13:52 [PATCH net-next v2 0/6] bpf-timestamp: support rx side Jason Xing
2026-05-21 13:52 ` [PATCH net-next v2 1/6] bpf: Add bpf_ktime_get_real_ns() kfunc Jason Xing
2026-05-21 13:52 ` [PATCH net-next v2 2/6] net: export sock_disable_timestamp() declaration Jason Xing
2026-05-30  0:46   ` sashiko-bot
2026-05-21 13:52 ` [PATCH net-next v2 3/6] bpf: support bpf_setsockopt for bpf timestamping rx feature Jason Xing
2026-05-23  4:02   ` Kuniyuki Iwashima
2026-05-30  0:46   ` sashiko-bot [this message]
2026-05-21 13:52 ` [PATCH net-next v2 4/6] bpf: add BPF_SOCK_OPS_TSTAMP_RCV_CB callback Jason Xing
2026-05-30  0:46   ` sashiko-bot
2026-05-21 13:52 ` [PATCH net-next v2 5/6] bpf: enable bpf timestamping rx in TCP layer Jason Xing
2026-05-23  3:45   ` Kuniyuki Iwashima
2026-05-28  0:50     ` Jason Xing
2026-05-21 13:52 ` [PATCH net-next v2 6/6] selftests/bpf: Add RX latency tests for bpf timestamping Jason Xing
2026-05-30  0:46   ` sashiko-bot
2026-05-23  3:47 ` [PATCH net-next v2 0/6] bpf-timestamp: support rx side Kuniyuki Iwashima
2026-05-28  0:50   ` Jason Xing

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=20260530004602.E31E61F0089B@smtp.kernel.org \
    --to=sashiko-bot@kernel.org \
    --cc=bpf@vger.kernel.org \
    --cc=kerneljasonxing@gmail.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.