All of lore.kernel.org
 help / color / mirror / Atom feed
From: "Irlanki Sandeep" <irlanki.s@samsung.com>
To: <sashiko-reviews@lists.linux.dev>
Cc: <bpf@vger.kernel.org>, <lorenzo@google.com>, <maze@google.com>,
	<sporeba@google.com>, <motomuman@google.com>,
	<srihari.k@samsung.com>, <g.pokhra@samsung.com>,
	<r.kumawat@samsung.com>, <raj.kumars@samsung.com>,
	<ts413.lee@samsung.com>, <ramyashree.s@samsung.com>,
	<daeil2.hwang@samsung.com>, <netdev@vger.kernel.org>,
	<cpgs@samsung.com>, <irlanki.s@samsung.com>
Subject: RE: [PATCH net-next v5] tcp: add TCP_ECN and TCP_ECN_OPTION kfuncs
Date: Thu, 1 Oct 2026 19:34:16 +0530	[thread overview]
Message-ID: <00fc01dd51ad$c0c91aa0$425b4fe0$@samsung.com> (raw)
In-Reply-To: <20261001102200.0BC711F000FF@smtp.kernel.org>

> [Severity: High]
> Could this lead to an out-of-bounds write for non-TCP sockets?
> 
> When a UDP socket requests hardware timestamping, the transmission skb gets
> SKBTX_HW_TSTAMP set, which implicitly sets SKBTX_BPF. When the timestamp
> is delivered, __skb_tstamp_tx() triggers bpf_skops_tx_timestamping(),
> invoking the CGROUP_SOCK_OPS BPF program for the UDP socket with
> is_fullsock set to 1.
> 
> If the BPF program calls this kfunc, it bypasses the !is_fullsock check.
> Since there is no verification that the socket protocol is IPPROTO_TCP, it casts
> the smaller udp_sock to a tcp_sock. Writing to ecn_option would then
> corrupt memory past the end of the udp_sock structure.

Thanks for catching this. Fixed in v6 by adding a sk_is_tcp() check to
both bpf_sock_ops_set_ecn_mode() and bpf_sock_ops_set_accecn_option()
to reject non-TCP sockets.

> [Severity: Medium]
> Will this assertion fail due to child sockets inadvertently inheriting the
> listener's ECN overrides?
> 
> When a passive connection is established, tcp_create_openreq_child() in
> net/ipv4/tcp_minisocks.c clones the listener socket via inet_csk_clone_lock().
> This copies the entire tcp_sock structure, including the new ecn_mode and
> ecn_option fields.
> 
> Since these fields are not explicitly reset to TCP_ECN_MODE_UNSPEC during
> the initialization block in tcp_create_openreq_child(), the child socket seems
> to retain the listener's mode, breaking the intended design and causing this
> test assertion to fail.

You are right, thanks. The v5 description and selftest wrongly assumed
accepted sockets go through tcp_init_sock(); they are cloned from the
listener via inet_csk_clone_lock() and inherit both fields.

Rather than reset them in tcp_create_openreq_child(), v6 keeps the
inheritance, since that is how every other tcp_sock setting behaves
(keepalive, TCP_NODELAY, tcp_tx_delay, and congestion control). A server-side BPF program
that sets ecn_option on a listener expects the accepted sockets to
follow it without re-applying it on every PASSIVE_ESTABLISHED_CB.

The description, kernel-doc, comments, and selftest assertions are
updated accordingly in v6.

> [Severity: Low]
> Does this multi-line comment violate the BPF subsystem style rules? The
> required style places the opening /* on its own line.

Fixed in v6 to conform to BPF comment formatting rules in both
selftest files.

v6 has been submitted here:
https://lore.kernel.org/all/20261001132759.1076145-1-irlanki.s@samsung.com/

Thanks,
Sandeep


      reply	other threads:[~2026-10-01 14:04 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
     [not found] <CGME20260930102144epcas5p419270301dba37c520277e6c6cff75def@epcas5p4.samsung.com>
2026-09-30 10:23 ` [PATCH net-next v5] tcp: add TCP_ECN and TCP_ECN_OPTION kfuncs Irlanki Sandeep
2026-10-01 10:21   ` sashiko-bot
2026-10-01 14:04     ` Irlanki Sandeep [this message]

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='00fc01dd51ad$c0c91aa0$425b4fe0$@samsung.com' \
    --to=irlanki.s@samsung.com \
    --cc=bpf@vger.kernel.org \
    --cc=cpgs@samsung.com \
    --cc=daeil2.hwang@samsung.com \
    --cc=g.pokhra@samsung.com \
    --cc=lorenzo@google.com \
    --cc=maze@google.com \
    --cc=motomuman@google.com \
    --cc=netdev@vger.kernel.org \
    --cc=r.kumawat@samsung.com \
    --cc=raj.kumars@samsung.com \
    --cc=ramyashree.s@samsung.com \
    --cc=sashiko-reviews@lists.linux.dev \
    --cc=sporeba@google.com \
    --cc=srihari.k@samsung.com \
    --cc=ts413.lee@samsung.com \
    /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.