diff --git a/net/ipv4/tcp_input.c b/net/ipv4/tcp_input.c
index c61edd023b352123e2a77465782e0d32689e96b0..08a477e74cf3267b725294c66b46fdad12bd2b72 100644
--- a/net/ipv4/tcp_input.c
+++ b/net/ipv4/tcp_input.c
@@ -3791,6 +3791,8 @@ void tcp_parse_options(const struct net *net,
 			length--;
 			continue;
 		default:
+			if (length < 2)
+				return;
 			opsize = *ptr++;
 			if (opsize < 2) /* "silly options" */
 				return;