netdev.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH net-next] tcp: fix incorrect parameter validation in the do_tcp_getsockopt() function
@ 2024-03-06  9:57 Gavrilov Ilia
  2024-03-06 11:36 ` Paolo Abeni
  0 siblings, 1 reply; 7+ messages in thread
From: Gavrilov Ilia @ 2024-03-06  9:57 UTC (permalink / raw)
  To: Eric Dumazet
  Cc: David S. Miller, David Ahern, Jakub Kicinski, Paolo Abeni,
	netdev@vger.kernel.org, linux-kernel@vger.kernel.org,
	lvc-project@linuxtesting.org

The 'len' variable can't be negative because all 'min_t' parameters
cast to unsigned int, and then the minimum one is chosen.

To fix it, move the if statement higher.

Fixes: 1da177e4c3f4 ("Linux-2.6.12-rc2")
Signed-off-by: Gavrilov Ilia <Ilia.Gavrilov@infotecs.ru>
---
 net/ipv4/tcp.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/net/ipv4/tcp.c b/net/ipv4/tcp.c
index c82dc42f57c6..a4f418592314 100644
--- a/net/ipv4/tcp.c
+++ b/net/ipv4/tcp.c
@@ -4010,11 +4010,11 @@ int do_tcp_getsockopt(struct sock *sk, int level,
 	if (copy_from_sockptr(&len, optlen, sizeof(int)))
 		return -EFAULT;
 
-	len = min_t(unsigned int, len, sizeof(int));
-
 	if (len < 0)
 		return -EINVAL;
 
+	len = min_t(unsigned int, len, sizeof(int));
+
 	switch (optname) {
 	case TCP_MAXSEG:
 		val = tp->mss_cache;
-- 
2.39.2

^ permalink raw reply related	[flat|nested] 7+ messages in thread

end of thread, other threads:[~2024-03-07 14:17 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2024-03-06  9:57 [PATCH net-next] tcp: fix incorrect parameter validation in the do_tcp_getsockopt() function Gavrilov Ilia
2024-03-06 11:36 ` Paolo Abeni
2024-03-06 11:54   ` Gavrilov Ilia
2024-03-07  8:40     ` Simon Horman
2024-03-07 14:17       ` Gavrilov Ilia
2024-03-06 11:56   ` Jason Xing
2024-03-06 14:55     ` Eric Dumazet

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).