All of lore.kernel.org
 help / color / mirror / Atom feed
From: "SandeepI" <irlanki.s@samsung.com>
To: <sashiko-reviews@lists.linux.dev>
Cc: <bpf@vger.kernel.org>, <netdev@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>,
	<irlanki.s@samsung.com>, <raj.kumars@samsung.com>,
	"'Taeseok Lee'" <ts413.lee@samsung.com>
Subject: RE: [PATCH net-next] tcp: add TCP_ECN and TCP_ECN_OPTION socket options
Date: Fri, 11 Sep 2026 15:55:27 +0530	[thread overview]
Message-ID: <045c01dd41d7$df167d30$9d437790$@samsung.com> (raw)
In-Reply-To: <20260910144455.CA7751F00893@smtp.kernel.org>

> -----Original Message-----
> From: sashiko-bot@kernel.org <sashiko-bot@kernel.org>
> Sent: 10 September 2026 20:15
> To: Irlanki Sandeep <irlanki.s@samsung.com>
> Cc: bpf@vger.kernel.org
> Subject: Re: [PATCH net-next] tcp: add TCP_ECN and TCP_ECN_OPTION socket
> options
> 
> Thank you for your contribution! Sashiko AI review found 2 potential issue(s) to
> consider:
> - [High] Per-socket TCP_ECN configuration is ignored during SYN floods because
> syncookies validation checks the global sysctl instead of the listener socket's
> effective ECN mode.
> - [Medium] Missing READ_ONCE() when reading `ecn_mode` and `ecn_option`
> introduces a data race and double-fetch vulnerability, leaking the UNSPEC
> placeholder (255) into TCP operational logic.
> --
> 
> commit d87f9153f9de86df8e7de5798f8dffdac8f0e2fd
> Author: Irlanki Sandeep <irlanki.s@samsung.com>
> Subject: tcp: add TCP_ECN and TCP_ECN_OPTION socket options
> 
> This patch introduces granular, per-connection dynamic adaptation for ECN and
> AccECN configurations. It adds two new socket options, TCP_ECN and
> TCP_ECN_OPTION, which override the system-wide sysctl settings to prevent
> connection failures or packet loss on paths with anomalous middleboxes.
> 
> > diff --git a/include/net/tcp_ecn.h b/include/net/tcp_ecn.h index
> > 865d5c5a7718d..931e0877176c7 100644
> > --- a/include/net/tcp_ecn.h
> > +++ b/include/net/tcp_ecn.h
> [ ... ]
> > @@ -30,8 +31,29 @@ enum tcp_accecn_option {
> >  	TCP_ACCECN_OPTION_MINIMUM = 1,
> >  	TCP_ACCECN_OPTION_FULL = 2,
> >  	TCP_ACCECN_OPTION_PERSIST = 3,
> > +	TCP_ACCECN_OPTION_UNSPEC = 255,	/* Use sysctl default (per-
> socket) */
> >  };
> >
> > +/* Resolve the effective ECN mode: per-socket override or sysctl
> > +fallback */ static inline u8 tcp_ecn_mode_eff(const struct sock *sk)
> > +{
> > +	u8 mode = tcp_sk(sk)->ecn_mode;
> > +
> > +	if (mode == TCP_ECN_MODE_UNSPEC)
> > +		return READ_ONCE(sock_net(sk)->ipv4.sysctl_tcp_ecn);
> > +	return mode;
> > +}
> 
> [Severity: Medium]
> Is it possible for the compiler to double-fetch tcp_sk(sk)->ecn_mode here?
> 
> Since the ecn_mode field is updated concurrently via WRITE_ONCE() (for
> example, during a setsockopt call while handling an incoming SYN packet in
> softirq context), a lack of READ_ONCE() on the reader side could result in the
> UNSPEC placeholder (255) leaking into the return evaluation.
> 
> If that placeholder leaks, could it cause AccECN to be incorrectly enabled later in
> tcp_ecn_create_request(), where 255 >= 3 would evaluate to true?
> 
> > +
> > +/* Resolve the effective AccECN option: per-socket override or sysctl
> > +fallback */ static inline u8 tcp_accecn_option_eff(const struct sock
> > +*sk) {
> > +	u8 opt = tcp_sk(sk)->ecn_option;
> > +
> > +	if (opt == TCP_ACCECN_OPTION_UNSPEC)
> > +		return READ_ONCE(sock_net(sk)->ipv4.sysctl_tcp_ecn_option);
> > +	return opt;
> > +}
> 
> [Severity: Medium]
> Does tcp_sk(sk)->ecn_option also require a READ_ONCE() here to prevent a
> similar data race and double-fetch?
Yes, tcp_sk(sk)->ecn_mode and tcp_sk(sk)->ecn_option are updated
concurrently via WRITE_ONCE() in do_tcp_setsockopt(). Without READ_ONCE(),
a compiler double-fetch could leak the TCP_ECN_MODE_UNSPEC (255) sentinel
value into operational evaluations.

Both accessors (tcp_ecn_mode_eff and tcp_accecn_option_eff) have been updated
in V3 with READ_ONCE() to eliminate data races and prevent double-fetching.


> [ ... ]
> > diff --git a/net/ipv4/tcp_input.c b/net/ipv4/tcp_input.c index
> > 0f60a1dbf9274..b7dea787f8237 100644
> > --- a/net/ipv4/tcp_input.c
> > +++ b/net/ipv4/tcp_input.c
> > @@ -7463,7 +7463,7 @@ static void tcp_ecn_create_request(struct
> request_sock *req,
> >  	u32 ecn_ok_dst;
> >
> >  	if (tcp_accecn_syn_requested(th) &&
> > -	    (READ_ONCE(net->ipv4.sysctl_tcp_ecn) >= 3 ||
> > +	    (tcp_ecn_mode_eff(listen_sk) >= 3 ||
> >  	     tcp_ca_needs_accecn(listen_sk))) {
> >  		inet_rsk(req)->ecn_ok = 1;
> >  		tcp_rsk(req)->accecn_ok = 1;
> 
> [Severity: High]
> Does the SYN cookies path also need to be updated to respect this new per-
> socket configuration?
> 
> During a SYN flood, this standard tcp_ecn_create_request() path is bypassed in
> favor of syncookies. Currently, cookie_v4_check() and cookie_v6_check()
> determine ECN support by calling cookie_ecn_ok(), which only checks the global
> sysctl:
> 
> static inline bool cookie_ecn_ok(const struct net *net, const struct dst_entry
> *dst) {
>         return READ_ONCE(net->ipv4.sysctl_tcp_ecn) ||
>                 dst_feature(dst, RTAX_FEATURE_ECN); }
> 
> If the system has the global sysctl_tcp_ecn disabled but a service has enabled it
> locally via TCP_ECN on its listener socket, will established connections silently
> lose their ECN capability during a SYN flood?

Agreed. Under SYN flood conditions, cookie_v4_check() and cookie_v6_check()
must honor the listener socket's effective ECN configuration rather than
falling back exclusively to the global sysctl.

Moved cookie_ecn_ok() from include/net/tcp.h to include/net/tcp_ecn.h
to avoid circular header dependencies (since tcp_ecn_mode_eff() is defined
in tcp_ecn.h and tcp.h does not include tcp_ecn.h), and updated it to take
'const struct sock *sk' so it evaluates tcp_ecn_mode_eff(sk).

Both issues have been addressed in the [PATCH net-next v3] tcp: add TCP_ECN and TCP_ECN_OPTION socket options

Thanks,
Sandeep.



      reply	other threads:[~2026-09-11 10:25 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
     [not found] <CGME20260909144437epcas5p282be513a761ca5aec3f2b0fefcd2ecfa@epcas5p2.samsung.com>
2026-09-09 14:45 ` [PATCH net-next] tcp: add TCP_ECN and TCP_ECN_OPTION socket options Irlanki Sandeep
2026-09-10  1:38   ` kernel test robot
2026-09-10 14:44   ` sashiko-bot
2026-09-11 10:25     ` SandeepI [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='045c01dd41d7$df167d30$9d437790$@samsung.com' \
    --to=irlanki.s@samsung.com \
    --cc=bpf@vger.kernel.org \
    --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=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.