Subject: [PATCH net-next] net: Return user_mss for TCP_MAXSEG in CLOSE/LISTEN state

From: Cambda Zhu <[email-masked]>
Date: Fri, 19 May 2023 16:01:18 +0800

This patch removes the tp->mss_cache check in getting TCP_MAXSEG of
CLOSE/LISTEN sock. Checking if tp->mss_cache is zero is probably a bug,
since tp->mss_cache is initialized with TCP_MSS_DEFAULT. Getting
TCP_MAXSEG of sock in other state will still return tp->mss_cache.

Signed-off-by: Cambda Zhu <[email-masked]>
Reported-by: Jack Yang <[email-masked]>
---
 net/ipv4/tcp.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/net/ipv4/tcp.c b/net/ipv4/tcp.c
index 3d18e295bb2f..713854f1f061 100644
--- a/net/ipv4/tcp.c
+++ b/net/ipv4/tcp.c
@@ -4083,7 +4083,7 @@ int do_tcp_getsockopt(struct sock *sk, int level,
 	switch (optname) {
 	case TCP_MAXSEG:
 		val = tp->mss_cache;
-		if (!val && ((1 << sk->sk_state) & (TCPF_CLOSE | TCPF_LISTEN)))
+		if ((1 << sk->sk_state) & (TCPF_CLOSE | TCPF_LISTEN))
 			val = tp->rx_opt.user_mss;
 		if (tp->repair)
 			val = tp->rx_opt.mss_clamp;
-- 
2.16.6