This is a note to let you know that I've just added the patch titled tcp: Return user_mss for TCP_MAXSEG in CLOSE/LISTEN state if user_mss set to the 6.3-stable tree which can be found at: http://www.kernel.org/git/?p=linux/kernel/git/stable/stable-queue.git;a=summary The filename of the patch is: tcp-return-user_mss-for-tcp_maxseg-in-close-listen-s.patch and it can be found in the queue-6.3 subdirectory. If you, or anyone else, feels it should not be added to the stable tree, please let <stable@xxxxxxxxxxxxxxx> know about it. commit 83f388225e9bc6432186334e47e366be9fbf992d Author: Cambda Zhu <cambda@xxxxxxxxxxxxxxxxx> Date: Sat May 27 12:03:17 2023 +0800 tcp: Return user_mss for TCP_MAXSEG in CLOSE/LISTEN state if user_mss set [ Upstream commit 34dfde4ad87b84d21278a7e19d92b5b2c68e6c4d ] This patch replaces the tp->mss_cache check in getting TCP_MAXSEG with tp->rx_opt.user_mss check for CLOSE/LISTEN sock. Since tp->mss_cache is initialized with TCP_MSS_DEFAULT, checking if it's zero is probably a bug. With this change, getting TCP_MAXSEG before connecting will return default MSS normally, and return user_mss if user_mss is set. Fixes: 1da177e4c3f4 ("Linux-2.6.12-rc2") Reported-by: Jack Yang <mingliang@xxxxxxxxxxxxxxxxx> Suggested-by: Eric Dumazet <edumazet@xxxxxxxxxx> Link: https://lore.kernel.org/netdev/CANn89i+3kL9pYtkxkwxwNMzvC_w3LNUum_2=3u+UyLBmGmifHA@xxxxxxxxxxxxxx/#t Signed-off-by: Cambda Zhu <cambda@xxxxxxxxxxxxxxxxx> Link: https://lore.kernel.org/netdev/14D45862-36EA-4076-974C-EA67513C92F6@xxxxxxxxxxxxxxxxx/ Reviewed-by: Jason Xing <kerneljasonxing@xxxxxxxxx> Reviewed-by: Eric Dumazet <edumazet@xxxxxxxxxx> Link: https://lore.kernel.org/r/20230527040317.68247-1-cambda@xxxxxxxxxxxxxxxxx Signed-off-by: Jakub Kicinski <kuba@xxxxxxxxxx> Signed-off-by: Sasha Levin <sashal@xxxxxxxxxx> diff --git a/net/ipv4/tcp.c b/net/ipv4/tcp.c index f4b243cc7f4a5..6bb8eb8031051 100644 --- a/net/ipv4/tcp.c +++ b/net/ipv4/tcp.c @@ -4077,7 +4077,8 @@ 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 (tp->rx_opt.user_mss && + ((1 << sk->sk_state) & (TCPF_CLOSE | TCPF_LISTEN))) val = tp->rx_opt.user_mss; if (tp->repair) val = tp->rx_opt.mss_clamp;