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 2/6] net: export sock_disable_timestamp() declaration
Date: Tue, 19 May 2026 08:25:12 +0000	[thread overview]
Message-ID: <20260519082513.D38EFC2BCC6@smtp.kernel.org> (raw)
In-Reply-To: <20260518082344.96647-3-kerneljasonxing@gmail.com>

Thank you for your contribution! Sashiko AI review found 2 potential issue(s) to consider:
- [High] Calling `bpf_setsockopt` to enable or disable `SK_BPF_CB_RX_TIMESTAMPING` from BPF hooks executing in softirq will trigger a kernel panic (sleep in atomic context) if `CONFIG_JUMP_LABEL` is not enabled.
- [Low] API asymmetry between `sock_enable_timestamp` and `sock_disable_timestamp` creates a dangerous bitmask trap.
--

commit ae551b79a5c9f8c77421dc360627b1e40e3ceaec
Author: Jason Xing <kerneljasonxing@gmail.com>
Subject: net: export sock_disable_timestamp() declaration

This patch removes the static modifier from sock_disable_timestamp() and adds
its declaration to include/net/sock.h. This change exposes the function to the
rest of the kernel, specifically allowing the BPF subsystem to dynamically turn
off the global time record function.

> diff --git a/include/net/sock.h b/include/net/sock.h
> index dccd3738c3687..8a49312ee0976 100644
> --- a/include/net/sock.h
> +++ b/include/net/sock.h
> @@ -3038,6 +3038,7 @@ static inline bool sk_listener_or_tw(const struct sock *sk)
>  }
>  
>  void sock_enable_timestamp(struct sock *sk, enum sock_flags flag);
> +void sock_disable_timestamp(struct sock *sk, unsigned long flags);

This isn't a bug, but does exporting these two functions with asymmetrical
signatures create a bitmask trap?

The newly exported sock_disable_timestamp() expects a bitmask (unsigned long
flags), while sock_enable_timestamp() expects an enum index (enum sock_flags
flag).

If a future developer mistakenly passes an enum index (like SOCK_TIMESTAMP
which has value 7) to sock_disable_timestamp(), wouldn't it silently clear
multiple unrelated socket flags (bits 0, 1, and 2) instead of the intended
flag?

>  int sock_recv_errqueue(struct sock *sk, struct msghdr *msg, int len, int level,
>  		       int type);

[ ... ]

> diff --git a/net/core/sock.c b/net/core/sock.c
> index b37b664b6eb92..2d552ae5edd42 100644
> --- a/net/core/sock.c
> +++ b/net/core/sock.c
> @@ -474,7 +474,7 @@ static bool sock_needs_netstamp(const struct sock *sk)
>  	}
>  }
>  
> -static void sock_disable_timestamp(struct sock *sk, unsigned long flags)
> +void sock_disable_timestamp(struct sock *sk, unsigned long flags)
>  {
>  	if (sk->sk_flags & flags) {
>  		sk->sk_flags &= ~flags;

If BPF programs running in an atomic softirq context call bpf_setsockopt() to
disable SK_BPF_CB_RX_TIMESTAMPING, could this trigger a panic?

Looking at net_disable_timestamp() which is called immediately after this
bitmask update, if CONFIG_JUMP_LABEL is not enabled, the code falls back to
calling static_branch_dec() on netstamp_needed_key.

This expands to static_key_slow_dec(), which unconditionally acquires
jump_label_mutex and cpus_read_lock().

Since acquiring a sleeping mutex inside a softirq context triggers a
sleep-in-atomic panic, will this cause a deterministic crash when users
dynamically attach these BPF programs?

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

  reply	other threads:[~2026-05-19  8:25 UTC|newest]

Thread overview: 27+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-05-18  8:23 [PATCH net-next 0/6] bpf-timetamp: support rx side Jason Xing
2026-05-18  8:23 ` [PATCH net-next 1/6] bpf: Add bpf_ktime_get_real_ns() kfunc Jason Xing
2026-05-18 11:57   ` Jesper Dangaard Brouer
2026-05-18 12:35     ` Jason Xing
2026-05-18  8:23 ` [PATCH net-next 2/6] net: export sock_disable_timestamp() declaration Jason Xing
2026-05-19  8:25   ` sashiko-bot [this message]
2026-05-19 11:50     ` Jason Xing
2026-05-18  8:23 ` [PATCH net-next 3/6] bpf: support bpf_setsockopt for bpf timestamping rx feature Jason Xing
2026-05-18  8:23 ` [PATCH net-next 4/6] bpf: add BPF_SOCK_OPS_TSTAMP_RCV_CB callback Jason Xing
2026-05-18  8:23 ` [PATCH net-next 5/6] bpf: enable bpf timestamping rx in TCP layer Jason Xing
2026-05-18 13:01   ` Jesper Dangaard Brouer
2026-05-18 13:53     ` Jason Xing
2026-05-18 16:40       ` Jesper Dangaard Brouer
2026-05-18 23:16         ` Jason Xing
2026-05-18 23:24           ` Jason Xing
2026-05-19  9:57             ` Toke Høiland-Jørgensen
2026-06-03 11:07               ` Toke Høiland-Jørgensen
2026-05-18 15:34   ` Stanislav Fomichev
2026-05-18 23:56     ` Jason Xing
2026-05-19  8:25   ` sashiko-bot
2026-05-19 10:31     ` Jiayuan Chen
2026-05-19 12:26     ` Jason Xing
2026-05-18  8:23 ` [PATCH net-next 6/6] selftests/bpf: Add RX latency tests for bpf timestamping Jason Xing
2026-05-19  8:25   ` sashiko-bot
2026-05-19 12:05     ` Jason Xing
2026-05-18 11:46 ` [PATCH net-next 0/6] bpf-timetamp: support rx side Jesper Dangaard Brouer
2026-05-18 12:32   ` 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=20260519082513.D38EFC2BCC6@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.