BPF List
 help / color / mirror / Atom feed
From: sashiko-bot@kernel.org
To: "Kuniyuki Iwashima" <kuniyu@google.com>
Cc: bpf@vger.kernel.org
Subject: Re: [PATCH v4 bpf-next 09/10] bpf: tcp: Add kfunc to adjust sk->sk_rcvlowat.
Date: Tue, 06 Oct 2026 19:42:00 +0000	[thread overview]
Message-ID: <sashiko-outbox-162405@kernel.org> (raw)
In-Reply-To: <20261006192601.1875100-10-kuniyu@google.com>

Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
- [High] bpf: bpf_tcp_ops_set_rcvlowat() allows out-of-bounds writes and data races via arbitrary sockets
--

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

bpf: tcp: Add kfunc to adjust sk->sk_rcvlowat.

This commit adds a new BPF kfunc bpf_tcp_ops_set_rcvlowat() to dynamically
adjust a socket's sk_rcvlowat to suppress unnecessary wakeups. The function
determines whether to trigger a wakeup based on the BPF struct_ops hook
context.

> diff --git a/net/ipv4/bpf_tcp_ops.c b/net/ipv4/bpf_tcp_ops.c
> index 8182037c42690..2ba73dd6c52cc 100644
> --- a/net/ipv4/bpf_tcp_ops.c
> +++ b/net/ipv4/bpf_tcp_ops.c

[ ... ]

> @@ -361,12 +361,31 @@ __bpf_kfunc int bpf_tcp_ops_set_flags(struct tcp_sock *tp, u32 enable, u32 disab
>  	return 0;
>  }
>  
> +__bpf_kfunc int bpf_tcp_ops_set_rcvlowat(struct sock *sk, int rcvlowat,
> +					 const struct bpf_prog_aux *aux)
> +{
> +	u32 moff = aux->attach_st_ops_member_off;
> +	bool wakeup = false;
> +
> +	if (moff == offsetof(struct bpf_tcp_ops, dequeue_rcvq))
> +		wakeup = true;
> +
> +	if (rcvlowat < 0)
> +		rcvlowat = INT_MAX;
> +
> +	return __tcp_set_rcvlowat(sk, rcvlowat, wakeup);

[Severity: High]
Does this code allow out-of-bounds writes if a non-TCP socket is passed?

The BPF verifier allows passing any trusted socket to kfuncs expecting a
struct sock *, such as those obtained via bpf_sk_lookup_udp() or
bpf_sk_lookup_tcp(). This means the sk argument is not restricted to the
locked context socket passed to the enqueue_rcvq or dequeue_rcvq hooks.

If a UDP socket is passed in, __tcp_set_rcvlowat() unsafely casts it to
struct tcp_sock and modifies tp->window_clamp:

net/ipv4/tcp.c:__tcp_set_rcvlowat() {
    struct tcp_sock *tp = tcp_sk(sk);
    ...
    if (space > sk->sk_rcvbuf) {
        ...
        if (tp->window_clamp && tp->window_clamp < val)
            WRITE_ONCE(tp->window_clamp, val);
    }
}

Since struct udp_sock is smaller and lacks the window_clamp field, will this
write out of bounds? Should the signature take a struct tcp_sock *tp instead,
similar to bpf_tcp_ops_set_flags()?

Additionally, if a valid TCP socket is passed via a lookup, its socket lock
is not held. __tcp_set_rcvlowat() modifies sk_rcvlowat, sk_rcvbuf, and
window_clamp using logic that relies on the socket lock being held. Is there
a risk of data races and state corruption if it is called on an unlocked
socket?

Finally, passing an MPTCP subflow could bypass the intended restriction
since MPTCP subflows typically need to use mptcp_set_rcvlowat().

> +}

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

  reply	other threads:[~2026-10-06 19:42 UTC|newest]

Thread overview: 36+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-10-06 19:24 [PATCH v4 bpf-next 00/10] bpf: Add bpf_tcp_ops hooks for TCP AutoLOWAT Kuniyuki Iwashima
2026-10-06 19:24 ` [PATCH v4 bpf-next 01/10] bpf: tcp: Convert deny-list for bpf_{get,set}sockopt() to allow-list Kuniyuki Iwashima
2026-10-06 23:09   ` Amery Hung
2026-10-06 19:24 ` [PATCH v4 bpf-next 02/10] bpf: tcp: Add a new per-socket flag and kfunc for bpf_tcp_ops Kuniyuki Iwashima
2026-10-06 22:04   ` Stanislav Fomichev
2026-10-06 23:10   ` Amery Hung
2026-10-06 19:24 ` [PATCH v4 bpf-next 03/10] selftest: bpf: Use bpf_tcp_ops_set_flags() in bpf_tcp_ops_hdr.c Kuniyuki Iwashima
2026-10-06 22:04   ` Stanislav Fomichev
2026-10-06 23:12   ` Amery Hung
2026-10-06 19:24 ` [PATCH v4 bpf-next 04/10] bpf: tcp: Guard fast-path bpf_tcp_ops_call() under per-socket flag Kuniyuki Iwashima
2026-10-06 22:05   ` Stanislav Fomichev
2026-10-06 23:25   ` Amery Hung
2026-10-07  2:48     ` Kuniyuki Iwashima
2026-10-07 22:36       ` Amery Hung
2026-10-08  2:10         ` Kuniyuki Iwashima
2026-10-06 19:24 ` [PATCH v4 bpf-next 05/10] bpf: tcp: Check BPF_SOCK_OPS_TEST_FLAG() after cgroup_bpf_enabled(CGROUP_SOCK_OPS) Kuniyuki Iwashima
2026-10-06 20:11   ` bot+bpf-ci
2026-10-06 22:05   ` Stanislav Fomichev
2026-10-07 22:38   ` Amery Hung
2026-10-06 19:24 ` [PATCH v4 bpf-next 06/10] bpf: tcp: Introduce bpf_tcp_ops.{enqueue,dequeue}_rcvq() Kuniyuki Iwashima
2026-10-06 22:06   ` Stanislav Fomichev
2026-10-06 23:26   ` Amery Hung
2026-10-06 19:24 ` [PATCH v4 bpf-next 07/10] tcp: Split out __tcp_set_rcvlowat() Kuniyuki Iwashima
2026-10-07 22:43   ` Amery Hung
2026-10-06 19:24 ` [PATCH v4 bpf-next 08/10] bpf: mptcp: Don't support BPF_TCP_OPS_FLAG_RCVQ Kuniyuki Iwashima
2026-10-06 22:06   ` Stanislav Fomichev
2026-10-07 22:43   ` Amery Hung
2026-10-06 19:24 ` [PATCH v4 bpf-next 09/10] bpf: tcp: Add kfunc to adjust sk->sk_rcvlowat Kuniyuki Iwashima
2026-10-06 19:42   ` sashiko-bot [this message]
2026-10-07 23:06   ` Amery Hung
2026-10-07 23:21     ` Kuniyuki Iwashima
2026-10-07 23:42       ` Amery Hung
2026-10-06 19:24 ` [PATCH v4 bpf-next 10/10] selftest: bpf: Add test for bpf_tcp_ops.{enqueue,dequeue}_rcvq() Kuniyuki Iwashima
2026-10-06 19:43   ` sashiko-bot
2026-10-06 22:06   ` Stanislav Fomichev
2026-10-07 13:11 ` [PATCH v4 bpf-next 00/10] bpf: Add bpf_tcp_ops hooks for TCP AutoLOWAT Jakub Sitnicki

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=sashiko-outbox-162405@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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox