netdev.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH net-next] l2tp: fix incorrect parameter validation in the pppol2tp_getsockopt() function
@ 2024-03-06  9:58 Gavrilov Ilia
  2024-03-06 13:14 ` Tom Parkin
  0 siblings, 1 reply; 4+ messages in thread
From: Gavrilov Ilia @ 2024-03-06  9:58 UTC (permalink / raw)
  To: James Chapman
  Cc: David S. Miller, Eric Dumazet, 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: 3557baabf280 ("[L2TP]: PPP over L2TP driver core")
Signed-off-by: Gavrilov Ilia <Ilia.Gavrilov@infotecs.ru>
---
 net/l2tp/l2tp_ppp.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/net/l2tp/l2tp_ppp.c b/net/l2tp/l2tp_ppp.c
index f011af6601c9..6146e4e67bbb 100644
--- a/net/l2tp/l2tp_ppp.c
+++ b/net/l2tp/l2tp_ppp.c
@@ -1356,11 +1356,11 @@ static int pppol2tp_getsockopt(struct socket *sock, int level, int optname,
 	if (get_user(len, optlen))
 		return -EFAULT;
 
-	len = min_t(unsigned int, len, sizeof(int));
-
 	if (len < 0)
 		return -EINVAL;
 
+	len = min_t(unsigned int, len, sizeof(int));
+
 	err = -ENOTCONN;
 	if (!sk->sk_user_data)
 		goto end;
-- 
2.39.2

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

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

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2024-03-06  9:58 [PATCH net-next] l2tp: fix incorrect parameter validation in the pppol2tp_getsockopt() function Gavrilov Ilia
2024-03-06 13:14 ` Tom Parkin
2024-03-06 13:46   ` Gavrilov Ilia
2024-03-06 14:32     ` Tom Parkin

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).