Commit 35686ad2 authored by Eric Dumazet's avatar Eric Dumazet Committed by sanglipeng
Browse files

tcp: annotate data-races around tp->linger2

stable inclusion
from stable-v5.10.188
commit f891375eba6e24c3a077c07d13e418ba681e0dac
category: bugfix
bugzilla: https://gitee.com/openeuler/kernel/issues/I8KYFP

Reference: https://git.kernel.org/pub/scm/linux/kernel/git/stable/linux.git/commit/?id=f891375eba6e24c3a077c07d13e418ba681e0dac



--------------------------------

[ Upstream commit 9df5335c ]

do_tcp_getsockopt() reads tp->linger2 while another cpu
might change its value.

Fixes: 1da177e4 ("Linux-2.6.12-rc2")
Signed-off-by: default avatarEric Dumazet <edumazet@google.com>
Link: https://lore.kernel.org/r/20230719212857.3943972-8-edumazet@google.com


Signed-off-by: default avatarJakub Kicinski <kuba@kernel.org>
Signed-off-by: default avatarSasha Levin <sashal@kernel.org>
Signed-off-by: default avatarsanglipeng <sanglipeng1@jd.com>
parent 8abcda03
Loading
Loading
Loading
Loading
+4 −4
Original line number Diff line number Diff line
@@ -3349,11 +3349,11 @@ static int do_tcp_setsockopt(struct sock *sk, int level, int optname,

	case TCP_LINGER2:
		if (val < 0)
			tp->linger2 = -1;
			WRITE_ONCE(tp->linger2, -1);
		else if (val > TCP_FIN_TIMEOUT_MAX / HZ)
			tp->linger2 = TCP_FIN_TIMEOUT_MAX;
			WRITE_ONCE(tp->linger2, TCP_FIN_TIMEOUT_MAX);
		else
			tp->linger2 = val * HZ;
			WRITE_ONCE(tp->linger2, val * HZ);
		break;

	case TCP_DEFER_ACCEPT:
@@ -3747,7 +3747,7 @@ static int do_tcp_getsockopt(struct sock *sk, int level,
			READ_ONCE(net->ipv4.sysctl_tcp_syn_retries);
		break;
	case TCP_LINGER2:
		val = tp->linger2;
		val = READ_ONCE(tp->linger2);
		if (val >= 0)
			val = (val ? : READ_ONCE(net->ipv4.sysctl_tcp_fin_timeout)) / HZ;
		break;