Skip to contentSkip to conversation

vsock: reject negative tv_usec in SO_VM_SOCKETS_CONNECT_TIMEOUT

PATCH Applied [email protected] 6 participants 7 messages Oct 30 – Nov 3

Subsystems (4)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 vsock: reject negative tv_usec in SO_VM_SOCKETS_CONNECT_TIMEOUT

From: Nguyen Dinh Phi <[email protected]>

The timeval validation checks tv_usec < USEC_PER_SEC but not tv_usec >= 0, so a negative tv_usec makes the timeout computation wrap into a bogus value, later tripping "schedule_timeout: wrong timeout value" instead of being rejected.

Fixes d021c344051a ("VSOCK: Introduce VM Sockets")
---
 net/vmw_vsock/af_vsock.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
net/vmw_vsock/af_vsock.c +2 -1
index d0508887a2fb..1d7d53542724 100644
@@ -2156,7 +2156,8 @@ static int vsock_connectible_setsockopt(struct socket *sock,
 					     optname == SO_VM_SOCKETS_CONNECT_TIMEOUT_OLD);
 		if (err)
 			break;
-		if (tv.tv_sec >= 0 && tv.tv_usec < USEC_PER_SEC &&
+		if (tv.tv_sec >= 0 && tv.tv_usec >= 0 &&
+		    tv.tv_usec < USEC_PER_SEC &&
 		    tv.tv_sec < (MAX_SCHEDULE_TIMEOUT / HZ - 1)) {
 			vsk->connect_timeout = tv.tv_sec * HZ +
 				DIV_ROUND_UP((unsigned long)tv.tv_usec, (USEC_PER_SEC / HZ));
Signature · 1 line
2.43.0
#1 lore raw
This is an automated message. This series looks like a fix, but its commit messages seem to be missing some information:

Hi!

This is an automated message. This series looks like a fix, but its commit messages seem to be missing some information:

- How the issue was discovered, e.g. hit in production, hit during development, syzbot report, manual code inspection, LLM or static analysis tool scan.

Please do not repost the series just to address the above. Instead, reply to this email with the missing information, so that reviewers can take it into account. If the series needs another revision for other reasons, please include the information in the commit messages then.

The evaluation is done by an LLM so it may be wrong, if you think that is the case please reply and explain.

maintainer Reviewed-by on v1 1/1
#2 lore raw
In reply to [email protected]
Quoted 9 lines · On Fri, Oct 30, 2026 at 02:43:50PM +0800, [email protected] wrote:

From: Nguyen Dinh Phi <[email protected]>

The timeval validation checks tv_usec < USEC_PER_SEC but not tv_usec >= 0, so a negative tv_usec makes the timeout computation wrap into a bogus value, later tripping "schedule_timeout: wrong timeout value" instead of being rejected.

Fixes d021c344051a ("VSOCK: Introduce VM Sockets")

This blank line shouldn't be there, maybe it can be fixed when the net maintainers apply this patch, so please wait their comments before sending a v2.

Quoted 22 lines

---
net/vmw_vsock/af_vsock.c | 3 ++-

1 file changed, 2 insertions(+), 1 deletion(-)
net/vmw_vsock/af_vsock.c +2 -1
index d0508887a2fb..1d7d53542724 100644
@@ -2156,7 +2156,8 @@ static int vsock_connectible_setsockopt(struct socket *sock,
 					     optname == SO_VM_SOCKETS_CONNECT_TIMEOUT_OLD);
 		if (err)
 			break;
-		if (tv.tv_sec >= 0 && tv.tv_usec < USEC_PER_SEC &&
+		if (tv.tv_sec >= 0 && tv.tv_usec >= 0 &&
+		    tv.tv_usec < USEC_PER_SEC &&
 		    tv.tv_sec < (MAX_SCHEDULE_TIMEOUT / HZ - 1)) {
 			vsk->connect_timeout = tv.tv_sec * HZ +
 				DIV_ROUND_UP((unsigned long)tv.tv_usec, (USEC_PER_SEC / HZ));
Signature · 1 line
2.43.0

LGTM:

maintainer
#3 lore raw
Quoted 8 lines · Stefano Garzarella
Quoted 7 lines · On Fri, Oct 30, 2026 at 02:43:50PM +0800, [email protected] wrote:

From: Nguyen Dinh Phi <[email protected]>

The timeval validation checks tv_usec < USEC_PER_SEC but not tv_usec >= 0, so a negative tv_usec makes the timeout computation wrap into a bogus value, later tripping "schedule_timeout: wrong timeout value" instead of being rejected.

Quoted 5 lines
Quoted 2 lines
Fixes d021c344051a ("VSOCK: Introduce VM Sockets")

This blank line shouldn't be there, maybe it can be fixed when the net maintainers apply this patch, so please wait their comments before sending a v2.

No need to repost: I fixed it while applying the patch.

/P

reviewer Reviewed-by on v1 1/1
#4 lore raw
In reply to [email protected]
Quoted 31 lines · On Fri, Oct 30, 2026 at 02:43:50PM +0800, [email protected] wrote:

From: Nguyen Dinh Phi <[email protected]>

The timeval validation checks tv_usec < USEC_PER_SEC but not tv_usec >= 0, so a negative tv_usec makes the timeout computation wrap into a bogus value, later tripping "schedule_timeout: wrong timeout value" instead of being rejected.

Fixes d021c344051a ("VSOCK: Introduce VM Sockets")
---
 net/vmw_vsock/af_vsock.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
net/vmw_vsock/af_vsock.c +2 -1
index d0508887a2fb..1d7d53542724 100644
@@ -2156,7 +2156,8 @@ static int vsock_connectible_setsockopt(struct socket *sock,
 					     optname == SO_VM_SOCKETS_CONNECT_TIMEOUT_OLD);
 		if (err)
 			break;
-		if (tv.tv_sec >= 0 && tv.tv_usec < USEC_PER_SEC &&
+		if (tv.tv_sec >= 0 && tv.tv_usec >= 0 &&
+		    tv.tv_usec < USEC_PER_SEC &&
 		    tv.tv_sec < (MAX_SCHEDULE_TIMEOUT / HZ - 1)) {
 			vsk->connect_timeout = tv.tv_sec * HZ +
 				DIV_ROUND_UP((unsigned long)tv.tv_usec, (USEC_PER_SEC / HZ));
Signature · 1 line
2.43.0

LGTM. Maybe we could think about adding some easy opt range tests into vsock_test in the future.

#5 lore raw
In reply to [email protected]
Quoted 6 lines · On Fri, Oct 30, 2026 at 02:43:50PM +0800, [email protected] wrote:

From: Nguyen Dinh Phi <[email protected]>

The timeval validation checks tv_usec < USEC_PER_SEC but not tv_usec >= 0, so a negative tv_usec makes the timeout computation wrap into a bogus value, later tripping "schedule_timeout: wrong timeout value" instead of being rejected.

BTW, this does need the 'net' prefix.

Quoted 25 lines
Fixes d021c344051a ("VSOCK: Introduce VM Sockets")
---
 net/vmw_vsock/af_vsock.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
net/vmw_vsock/af_vsock.c +2 -1
index d0508887a2fb..1d7d53542724 100644
@@ -2156,7 +2156,8 @@ static int vsock_connectible_setsockopt(struct socket *sock,
 					     optname == SO_VM_SOCKETS_CONNECT_TIMEOUT_OLD);
 		if (err)
 			break;
-		if (tv.tv_sec >= 0 && tv.tv_usec < USEC_PER_SEC &&
+		if (tv.tv_sec >= 0 && tv.tv_usec >= 0 &&
+		    tv.tv_usec < USEC_PER_SEC &&
 		    tv.tv_sec < (MAX_SCHEDULE_TIMEOUT / HZ - 1)) {
 			vsk->connect_timeout = tv.tv_sec * HZ +
 				DIV_ROUND_UP((unsigned long)tv.tv_usec, (USEC_PER_SEC / HZ));
Signature · 1 line
2.43.0
#6 lore raw
In reply to [email protected]
This patch was applied to netdev/net.git (main) by Paolo Abeni <[email protected]>:

Hello:

This patch was applied to netdev/net.git (main)
by Paolo Abeni <[email protected]>:

Quoted 8 lines · On Fri, 30 Oct 2026 14:43:50 +0800 you wrote:

From: Nguyen Dinh Phi <[email protected]>

The timeval validation checks tv_usec < USEC_PER_SEC but not tv_usec >= 0, so a negative tv_usec makes the timeout computation wrap into a bogus value, later tripping "schedule_timeout: wrong timeout value" instead of being rejected.

[...]

Here is the summary with links:
- vsock: reject negative tv_usec in SO_VM_SOCKETS_CONNECT_TIMEOUT

    https://git.kernel.org/netdev/net/c/c0ef6144b4d6

You are awesome, thank you!

Signature · 2 lines
Deet-doot-dot, I am a bot.
https://korg.docs.kernel.org/patchwork/pwbot.html