# \[PATCH net-next\] tcp: enable data-less, empty-cookie SYN with TFO\_SERVER\_COOKIE\_NOT\_REQD

- Subsystems: NETWORKING \[GENERAL\], NETWORKING \[TCP\], THE REST
- Maintainers: "David S. Miller", Eric Dumazet, Jakub Kicinski, Paolo Abeni, Neal Cardwell, Linus Torvalds
- Status: LANDED · 2 reviews, 1 by a maintainer (e3faa49bcecd · 2021-08-17 00:25 M Neal Cardwell Yuchung Cheng)
- Landed in mainline as e3faa49bcecd on 2021-08-17.
- 2 review trailers (1 from subsystem maintainers).
- List: netdev
- 2 messages, 2 authors
- Page: https://ratatoskr.run/netdev/2021/08/11209428/t

## \[PATCH net-next\] tcp: enable data-less, empty-cookie SYN with TFO\_SERVER\_COOKIE\_NOT\_REQD

- From: Luke Hsiao \<hidden\>
- Date: 2021-08-16 20:51:52 
- Message: https://ratatoskr.run/netdev/2021/08/11209428.md

```text
From: Luke Hsiao <redacted>

Since the original TFO server code was implemented in commit
168a8f58059a22feb9e9a2dcc1b8053dbbbc12ef ("tcp: TCP Fast Open Server -
main code path") the TFO server code has supported the sysctl bit flag
TFO_SERVER_COOKIE_NOT_REQD. Currently, when the TFO_SERVER_ENABLE and
TFO_SERVER_COOKIE_NOT_REQD sysctl bit flags are set, a server connection
will accept a SYN with N bytes of data (N > 0) that has no TFO cookie,
create a new fast open connection, process the incoming data in the SYN,
and make the connection ready for accepting. After accepting, the
connection is ready for read()/recvmsg() to read the N bytes of data in
the SYN, ready for write()/sendmsg() calls and data transmissions to
transmit data.

This commit changes an edge case in this feature by changing this
behavior to apply to (N >= 0) bytes of data in the SYN rather than only
(N > 0) bytes of data in the SYN. Now, a server will accept a data-less
SYN without a TFO cookie if TFO_SERVER_COOKIE_NOT_REQD is set.

Caveat! While this enables a new kind of TFO (data-less empty-cookie
SYN), some firewall rules setup may not work if they assume such packets
are not legit TFOs and will filter them.

Signed-off-by: Luke Hsiao <redacted>
Acked-by: Neal Cardwell <ncardwell@google.com>
Acked-by: Yuchung Cheng <redacted>
Signed-off-by: Eric Dumazet <redacted>
---
 net/ipv4/tcp_fastopen.c | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)

diff --git a/net/ipv4/tcp_fastopen.c b/net/ipv4/tcp_fastopen.c
index 62ba8d0f2c60..59412d6354a0 100644
--- a/net/ipv4/tcp_fastopen.c
+++ b/net/ipv4/tcp_fastopen.c
@@ -368,8 +368,7 @@ struct sock *tcp_try_fastopen(struct sock *sk, struct sk_buff *skb,
 		return NULL;
 	}

-	if (syn_data &&
-	    tcp_fastopen_no_cookie(sk, dst, TFO_SERVER_COOKIE_NOT_REQD))
+	if (tcp_fastopen_no_cookie(sk, dst, TFO_SERVER_COOKIE_NOT_REQD))
 		goto fastopen;

 	if (foc->len == 0) {
--
2.33.0.rc1.237.g0d66db33f3-goog

```

## Re: \[PATCH net-next\] tcp: enable data-less, empty-cookie SYN with TFO\_SERVER\_COOKIE\_NOT\_REQD

- From: Jakub Kicinski \<kuba@kernel.org\>
- Date: 2021-08-17 13:35:20 
- Message: https://ratatoskr.run/netdev/2021/08/11209517.md

```text
On Mon, 16 Aug 2021 20:51:06 +0000 Luke Hsiao wrote:
> From: Luke Hsiao <redacted>
> 
> Since the original TFO server code was implemented in commit
> 168a8f58059a22feb9e9a2dcc1b8053dbbbc12ef ("tcp: TCP Fast Open Server -
> main code path") the TFO server code has supported the sysctl bit flag
> TFO_SERVER_COOKIE_NOT_REQD. Currently, when the TFO_SERVER_ENABLE and
> TFO_SERVER_COOKIE_NOT_REQD sysctl bit flags are set, a server connection
> will accept a SYN with N bytes of data (N > 0) that has no TFO cookie,
> create a new fast open connection, process the incoming data in the SYN,
> and make the connection ready for accepting. After accepting, the
> connection is ready for read()/recvmsg() to read the N bytes of data in
> the SYN, ready for write()/sendmsg() calls and data transmissions to
> transmit data.
> 
> This commit changes an edge case in this feature by changing this
> behavior to apply to (N >= 0) bytes of data in the SYN rather than only
> (N > 0) bytes of data in the SYN. Now, a server will accept a data-less
> SYN without a TFO cookie if TFO_SERVER_COOKIE_NOT_REQD is set.
> 
> Caveat! While this enables a new kind of TFO (data-less empty-cookie
> SYN), some firewall rules setup may not work if they assume such packets
> are not legit TFOs and will filter them.
> 
> Signed-off-by: Luke Hsiao <redacted>
> Acked-by: Neal Cardwell <ncardwell@google.com>
> Acked-by: Yuchung Cheng <redacted>
> Signed-off-by: Eric Dumazet <redacted>

Applied, thanks!
```
