vsock: use sock_error() to consume sk_err after connect timeout
Subsystems (4)
PATCH 1/1 vsock: use sock_error() to consume sk_err after connect timeout
After vsock_connect() exits the wait loop due to sk->sk_err being set, the error was read but not cleared. This left sk->sk_err set for subsequent operations.
Switch to sock_error() which atomically reads and clears sk->sk_err, so the error is consumed when returned.
--- net/vmw_vsock/af_vsock.c | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-)
net/vmw_vsock/af_vsock.c +2 -5
@@ -1847,14 +1847,11 @@ static int vsock_connect(struct socket *sock, struct sockaddr_unsized *addr,prepare_to_wait (sk_sleep (sk), &wait,TASK_INTERRUPTIBLE ); } -if (sk->sk_err) { - err = -sk->sk_err; + err =sock_error (sk); +if (err) { sk->sk_state =TCP_CLOSE ; sock->state =SS_UNCONNECTED ; - }else { - err =0 ; } - out_wait:finish_wait (sk_sleep (sk), &wait); out:
Signature · 1 line
2.53.0
Stefano Garzarella
maintainerQuoted 3 lines · Nguyen Dinh Phi
After
vsock_connect()exits the wait loop due tosk->sk_errbeing set, the error was read but not cleared. This leftsk->sk_errset for subsequent operations.
So, is this a fix? If yes, we should put a Fixes tag.
Also, can you describe how to trigger the issue?
Because I see this in vsock_connect(), so I thought it was in some way already handled:
/* sk_err might have been set as a result of an earlier * (failed) connect attempt. */ sk->sk_err = 0;
Quoted 5 lines
Switch to
sock_error()which atomically reads and clearssk->sk_err, so the error is consumed when returned.Signed-off-by Nguyen Dinh Phi <[email protected]>Reported-by [email protected]
Can you explain how this patch fixes that issue?
(this should be the first information to be put in the commit message IMHO)
I'd like to understand better if this is a fix of real bug or just an improvement to the code (which is fine by me).
Thanks,
Stefano
Quoted 28 lines
---
net/vmw_vsock/af_vsock.c| 7 ++-----1 file changed, 2 insertions(+), 5 deletions(-)net/vmw_vsock/af_vsock.c +2
-5@@ -1847,14 +1847,11 @@ static int vsock_connect(struct socket *sock, struct sockaddr_unsized *addr,prepare_to_wait (sk_sleep (sk), &wait,TASK_INTERRUPTIBLE ); } -if (sk->sk_err) { - err = -sk->sk_err; + err =sock_error (sk); +if (err) { sk->sk_state =TCP_CLOSE ; sock->state =SS_UNCONNECTED ; - }else { - err =0 ; } -
out_wait:finish_wait(sk_sleep(sk), &wait);out:
Signature · 1 line
2.53.0
Quoted 7 lines · Stefano Garzarella
Quoted 3 lines · Nguyen Dinh Phi
After
vsock_connect()exits the wait loop due tosk->sk_errbeing set, the error was read but not cleared. This leftsk->sk_errset for subsequent operations.So, is this a fix? If yes, we should put a Fixes tag.
Quoted 9 lines
Also, can you describe how to trigger the issue?
Because I see this in
vsock_connect(), so I thought it was in some way already handled:/*
sk_errmight have been set as a result of an earlier
* (failed) connect attempt.
*/
sk->sk_err= 0;
This only handles the case where the function following the failed connect is another connect() call.
Quoted 6 lines
Quoted 5 lines
Switch to
sock_error()which atomically reads and clearssk->sk_err, so the error is consumed when returned.Signed-off-by Nguyen Dinh Phi <[email protected]>Reported-by [email protected]
Quoted 8 lines
Can you explain how this patch fixes that issue?
(this should be the first information to be put in the commit message IMHO)I'd like to understand better if this is a fix of real bug or just an improvement to the code (which is fine by me).
Thanks,
Stefano
Here are the steps of the syzkaller reproducer:
r0 = socket(AF_VSOCK, SOCK_STREAM, 0)
bind(r0, {VMADDR_CID_ANY, PORT})
connect(r0, {VMADDR_CID_LOCAL, PORT})
listen(r0, backlog)
r1 = socket(AF_VSOCK, SOCK_STREAM, 0)
connect(r1, {VMADDR_CID_LOCAL, PORT})
connect(r0 -> self) -> -1, EPROTO
listen(r0) -> 0
connect(r1 -> r0) -> 0
accept(r0) -> -1, EPROTO
Basically, it creates a socket (r0) and triggers a self-connect after binding it. This self-connect fails with EPROTO because it loops back to r0 while the socket is still in the TCP_SYN_SENT state, causing it to be incorrectly dispatched to the connecting-client path. The unexpected packet type encountered there sets sk_err to EPROTO.
After that, it invokes a listen() call on the same socket. This listen() call succeeds because the kernel's listening path never inspects or clears sk_err. Then, a new socket (r1) is created as a normal client and connects to r0. However, vsock_accept() rejects this incoming connection because the listener's sk_err still holds the EPROTO error from the earlier failed self-connect.
This rejection causes the child socket created for r1's connection to never be freed on virtio or hyperv transports; only the VMCI transport implements pending_work to revisit and clean up a rejected socket This patch will prevent the rejection branch to occur in this scenario.
I think we might schedule the cleanup worker to run in the rejection path for these transports as well.
Thanks,
Phi
Stefano Garzarella
maintainerQuoted 10 lines · Phi Nguyen
Quoted 9 lines · Stefano Garzarella
Quoted 3 lines · Nguyen Dinh Phi
After
vsock_connect()exits the wait loop due tosk->sk_errbeing set, the error was read but not cleared. This leftsk->sk_errset for subsequent operations.So, is this a fix? If yes, we should put a Fixes tag.
Also, can you describe how to trigger the issue?
Quoted 8 lines
Quoted 7 lines
Because I see this in
vsock_connect(), so I thought it was in some way already handled:/*
sk_errmight have been set as a result of an earlier
* (failed) connect attempt.
*/
sk->sk_err= 0;This only handles the case where the function following the failed connect is another
connect()call.
So, can we remove that with this patch, or better to leave as defensive action?
Quoted 35 lines
Quoted 7 lines
Quoted 6 lines
Switch to
sock_error()which atomically reads and clearssk->sk_err, so the error is consumed when returned.Signed-off-by Nguyen Dinh Phi <[email protected]>Reported-by [email protected]Quoted 8 lines
Can you explain how this patch fixes that issue?
(this should be the first information to be put in the commit message IMHO)I'd like to understand better if this is a fix of real bug or just an improvement to the code (which is fine by me).
Thanks,
StefanoHere are the steps of the syzkaller reproducer:
r0 =
socket(AF_VSOCK, SOCK_STREAM, 0)
bind(r0, {VMADDR_CID_ANY, PORT})
connect(r0, {VMADDR_CID_LOCAL, PORT})
listen(r0, backlog)r1 =
socket(AF_VSOCK, SOCK_STREAM, 0)
connect(r1, {VMADDR_CID_LOCAL, PORT})
connect(r0 -> self)-> -1, EPROTOlisten(r0) -> 0
connect(r1 -> r0)-> 0
Quoted 8 lines
accept(r0) -> -1, EPROTO
Basically, it creates a socket (r0) and triggers a self-connect after binding it. This self-connect fails with EPROTO because it loops back to r0 while the socket is still in the
TCP_SYN_SENTstate, causing it to be incorrectly dispatched to the connecting-client path. The unexpected packet type encountered there setssk_errto EPROTO.After that, it invokes a
listen()call on the same socket. Thislisten()call succeeds because the kernel's listening path never inspects or clearssk_err. Then, a new socket (r1) is created as a normal client and connects to r0. However,vsock_accept()rejects this incoming connection because the listener'ssk_errstill holds the EPROTO error from the earlier failed self-connect.This rejection causes the child socket created for r1's connection to never be freed on virtio or hyperv transports; only the VMCI transport implements
pending_workto revisit and clean up a rejected socket This patch will prevent the rejection branch to occur in this scenario.
Okay, get it now, thanks! Please include a summary of this in the commit description.
I understand that this resolves syzbot's specific test case, but it would be best to handle rejected sockets more effectively in af_vsock.c rather than in the transport layers (if possible). In any case, this can be done in another patch.
Quoted 2 lines
I think we might schedule the cleanup worker to run in the rejection path for these transports as well.
Yeah, we need to handle that part better, I think it's a leftover when we generalized AF_VSOCK to support more transport than vmci.
Indeed this part is a bit confusing:
/* If the listener socket has received an error, then we should
* reject this socket and return. Note that we simply mark the
* socket rejected, drop our reference, and let the cleanup
* function handle the cleanup; the fact that we found it in
* the listener's accept queue guarantees that the cleanup
* function hasn't run yet.
*/
if (err) {
vconnected->rejected = true;
} else {Would be nice to handle everything in af_vsock.c in some way.
In conclusion, the patch LGTM, but please expand the commit description, add the Fixes tag, and target the net tree in the v2.
Thanks,
Stefano
Quoted 18 lines · Stefano Garzarella
Quoted 17 lines · Phi Nguyen
Quoted 16 lines · Stefano Garzarella
Quoted 3 lines · Nguyen Dinh Phi
After
vsock_connect()exits the wait loop due tosk->sk_errbeing set, the error was read but not cleared. This leftsk->sk_errset for subsequent operations.So, is this a fix? If yes, we should put a Fixes tag.
Also, can you describe how to trigger the issue?
Because I see this in
vsock_connect(), so I thought it was in some way already handled:/*
sk_errmight have been set as a result of an earlier
* (failed) connect attempt.
*/
sk->sk_err= 0;
Quoted 5 lines
Quoted 1 line
This only handles the case where the function following the failed connect is another
connect()call.So, can we remove that with this patch, or better to leave as defensive action?
I prefer to keep it here as defensive action
Quoted 67 lines
Quoted 35 lines
Quoted 7 lines
Quoted 6 lines
Switch to
sock_error()which atomically reads and clearssk->sk_err, so the error is consumed when returned.Signed-off-by Nguyen Dinh Phi <[email protected]>Reported-by [email protected]Quoted 8 lines
Can you explain how this patch fixes that issue?
(this should be the first information to be put in the commit message IMHO)I'd like to understand better if this is a fix of real bug or just an improvement to the code (which is fine by me).
Thanks,
StefanoHere are the steps of the syzkaller reproducer:
r0 =
socket(AF_VSOCK, SOCK_STREAM, 0)bind(r0, {
VMADDR_CID_ANY, PORT})connect(r0, {
VMADDR_CID_LOCAL, PORT})listen(r0, backlog)
r1 =
socket(AF_VSOCK, SOCK_STREAM, 0)connect(r1, {
VMADDR_CID_LOCAL, PORT})connect(r0 -> self) -> -1, EPROTO
listen(r0) -> 0
connect(r1 -> r0) -> 0
Quoted 8 lines
accept(r0) -> -1, EPROTO
Basically, it creates a socket (r0) and triggers a self-connect after binding it. This self-connect fails with EPROTO because it loops back to r0 while the socket is still in the
TCP_SYN_SENTstate, causing it to be incorrectly dispatched to the connecting-client path. The unexpected packet type encountered there setssk_errto EPROTO.After that, it invokes a
listen()call on the same socket. Thislisten()call succeeds because the kernel's listening path never inspects or clearssk_err. Then, a new socket (r1) is created as a normal client and connects to r0. However,vsock_accept()rejects this incoming connection because the listener'ssk_errstill holds the EPROTO error from the earlier failed self-connect.This rejection causes the child socket created for r1's connection to never be freed on virtio or hyperv transports; only the VMCI transport implements
pending_workto revisit and clean up a rejected socket This patch will prevent the rejection branch to occur in this scenario.Okay, get it now, thanks! Please include a summary of this in the commit description.
I understand that this resolves syzbot's specific test case, but it would be best to handle rejected sockets more effectively in
af_vsock.crather than in the transport layers (if possible). In any case, this can be done in another patch.Quoted 2 lines
I think we might schedule the cleanup worker to run in the rejection path for these transports as well.
Yeah, we need to handle that part better, I think it's a leftover when we generalized
AF_VSOCKto support more transport than vmci.Indeed this part is a bit confusing:
/* If the listener socket has received an error, then we should
* reject this socket and return. Note that we simply mark the
* socket rejected, drop our reference, and let the cleanup
* function handle the cleanup; the fact that we found it in
* the listener's accept queue guarantees that the cleanup
* function hasn't run yet.
*/
if (err) {
vconnected->rejected= true;
} else {
Quoted 3 lines
Would be nice to handle everything in
af_vsock.cin some way.In conclusion, the patch LGTM, but please expand the commit description, add the Fixes tag, and target the net tree in the v2.
I'll send a v2 with an expanded commit description and the Fixes tag.
Regarding the rejected socket cleanup, I agree it would be cleaner to handle it entirely in af_vsock.c. I'll look at that as a follow-up.
Thanks,
Phi
Quoted 20 lines · Nguyen Dinh Phi [SG]
Quoted 19 lines · Stefano Garzarella
Quoted 18 lines · Phi Nguyen
Quoted 17 lines · Stefano Garzarella
Quoted 3 lines · Nguyen Dinh Phi
After
vsock_connect()exits the wait loop due tosk->sk_errbeing set, the error was read but not cleared. This leftsk->sk_errset for subsequent operations.So, is this a fix? If yes, we should put a Fixes tag.
Also, can you describe how to trigger the issue?
Because I see this in
vsock_connect(), so I thought it was in some way already handled:/*
sk_errmight have been set as a result of an earlier
* (failed) connect attempt.
*/
sk->sk_err= 0;
Quoted 8 lines
Quoted 6 lines
Quoted 2 lines
This only handles the case where the function following the failed connect is another
connect()call.So, can we remove that with this patch, or better to leave as defensive action?
I prefer to keep it here as defensive action
Is changing how vsock_poll() behaves intended?
I.e. if sk_err should be kept after a failed connect(), what about sk->sk_err = 0; in vsock_listen() instead?
Quoted 3 lines
Quoted 3 lines
...
Yeah, we need to handle that part better, I think it's a leftover when we generalizedAF_VSOCKto support more transport than vmci.
Speaking of leftovers, I have trouble understanding where does vsock set sk_err on listener sockets anyway. If it doesn't, why vsock_accept() checks for it?
thanks,
Michal
Stefano Garzarella
maintainerQuoted 24 lines · Michal Luczaj
Quoted 23 lines · Nguyen Dinh Phi [SG]
Quoted 22 lines · Stefano Garzarella
Quoted 20 lines · Phi Nguyen
Quoted 9 lines · Stefano Garzarella
Quoted 3 lines · Nguyen Dinh Phi
After
vsock_connect()exits the wait loop due tosk->sk_errbeing set, the error was read but not cleared. This leftsk->sk_errset for subsequent operations.So, is this a fix? If yes, we should put a Fixes tag.
Also, can you describe how to trigger the issue?
Quoted 8 lines
Because I see this in
vsock_connect(), so I thought it was in some way already handled:/*
sk_errmight have been set as a result of an earlier
* (failed) connect attempt.
*/
sk->sk_err= 0;This only handles the case where the function following the failed connect is another
connect()call.
Quoted 7 lines
Quoted 5 lines
Quoted 3 lines
So, can we remove that with this patch, or better to leave as defensive action?
I prefer to keep it here as defensive action
Is changing how
vsock_poll()behaves intended?
Good point, but IIUC __inet_stream_connect() is also using consuming the error with sock_error().
Quoted 3 lines
I.e. if
sk_errshould be kept after a failedconnect(), what aboutsk->sk_err = 0;invsock_listen()instead?
Yeah, maybe this is a bit less invasive.
Quoted 8 lines
Quoted 4 lines
Quoted 4 lines
...
Yeah, we need to handle that part better, I think it's a leftover when we generalizedAF_VSOCKto support more transport than vmci.Speaking of leftovers, I have trouble understanding where does vsock set
sk_erron listener sockets anyway. If it doesn't, whyvsock_accept()checks for it?
I can't also see where it can be set TBH. Should we remove it ?
Thanks,
Stefano
Quoted 25 lines · Stefano Garzarella
Quoted 24 lines · Michal Luczaj
Quoted 23 lines · Nguyen Dinh Phi [SG]
Quoted 22 lines · Stefano Garzarella
Quoted 20 lines · Phi Nguyen
Quoted 9 lines · Stefano Garzarella
Quoted 3 lines · Nguyen Dinh Phi
After
vsock_connect()exits the wait loop due tosk->sk_errbeing set, the error was read but not cleared. This leftsk->sk_errset for subsequent operations.So, is this a fix? If yes, we should put a Fixes tag.
Also, can you describe how to trigger the issue?
Quoted 8 lines
Because I see this in
vsock_connect(), so I thought it was in some way already handled:/*
sk_errmight have been set as a result of an earlier
* (failed) connect attempt.
*/
sk->sk_err= 0;This only handles the case where the function following the failed connect is another
connect()call.
Quoted 8 lines
Quoted 7 lines
Quoted 5 lines
Quoted 3 lines
So, can we remove that with this patch, or better to leave as defensive action?
I prefer to keep it here as defensive action
Is changing how
vsock_poll()behaves intended?
I think connect() already delivered the error directly to the caller when it returned -- there's no reason for poll() to keep reporting that same, already-handled error afterward.
Quoted 8 lines
Good point, but IIUC
__inet_stream_connect()is also using consuming the error withsock_error().Quoted 3 lines
I.e. if
sk_errshould be kept after a failedconnect(), what aboutsk->sk_err = 0;invsock_listen()instead?Yeah, maybe this is a bit less invasive.
yes, __inet_stream_connect() does it, and actually, other protocols like Bluetooth, TIPC, x25... are also consume sk_err with sock_error() after their wait loop.
I think it is an established pattern, so I'd rather keep sock_error() in vsock_connect() than move it to vsock_listen(). vsock_listen() would only protect the listen() path; I see other places in af_vsock.c use this sk_err.
Quoted 10 lines
Quoted 8 lines
Quoted 4 lines
Quoted 4 lines
...
Yeah, we need to handle that part better, I think it's a leftover when we generalizedAF_VSOCKto support more transport than vmci.Speaking of leftovers, I have trouble understanding where does vsock set
sk_erron listener sockets anyway. If it doesn't, whyvsock_accept()checks for it?I can't also see where it can be set TBH. Should we remove it ?
I couldn't find it for listener side too.
Thanks,
Phi.
Quoted 11 lines · Nguyen Dinh Phi [SG]
Quoted 9 lines
Quoted 7 lines
Quoted 3 lines
Quoted 3 lines
...
Yeah, we need to handle that part better, I think it's a leftover when we generalizedAF_VSOCKto support more transport than vmci.Speaking of leftovers, I have trouble understanding where does vsock set
sk_erron listener sockets anyway. If it doesn't, whyvsock_accept()checks for it?I can't also see where it can be set TBH. Should we remove it ?
I couldn't find it for listener side too.
Removing sk_err handling from vsock_accept() solves the problem, right?
thanks,
Michal
Quoted 9 lines · Michal Luczaj
Quoted 8 lines · Nguyen Dinh Phi [SG]
Quoted 8 lines
Quoted 7 lines
Quoted 3 lines
Quoted 3 lines
...
Yeah, we need to handle that part better, I think it's a leftover when we generalizedAF_VSOCKto support more transport than vmci.Speaking of leftovers, I have trouble understanding where does vsock set
sk_erron listener sockets anyway. If it doesn't, whyvsock_accept()checks for it?
Quoted 8 lines
Quoted 3 lines
Quoted 1 line
I can't also see where it can be set TBH. Should we remove it ?
I couldn't find it for listener side too.
Removing
sk_errhandling fromvsock_accept()solves the problem, right?thanks,
Michal
Yes, confirmed, removing sk_err checks from vsock_accept() does solve the problem.
Thanks,
Phi
Stefano Garzarella
maintainerQuoted 12 lines · Nguyen Dinh Phi [SG]
Quoted 11 lines · Michal Luczaj
Quoted 10 lines · Nguyen Dinh Phi [SG]
Quoted 9 lines
Quoted 7 lines
Quoted 3 lines
Quoted 3 lines
...
Yeah, we need to handle that part better, I think it's a leftover when we generalizedAF_VSOCKto support more transport than vmci.Speaking of leftovers, I have trouble understanding where does vsock set
sk_erron listener sockets anyway. If it doesn't, whyvsock_accept()checks for it?I can't also see where it can be set TBH. Should we remove it ?
Quoted 8 lines
Quoted 6 lines
Quoted 1 line
I couldn't find it for listener side too.
Removing
sk_errhandling fromvsock_accept()solves the problem, right?thanks,
MichalYes, confirmed, removing
sk_errchecks fromvsock_accept()does solve the problem.
Okay, so maybe better on going on this direction. WDYT?
Stefano
Quoted 17 lines · Stefano Garzarella
Quoted 16 lines · Nguyen Dinh Phi [SG]
Quoted 15 lines · Michal Luczaj
Quoted 11 lines · Nguyen Dinh Phi [SG]
Quoted 9 lines
Quoted 7 lines
Quoted 3 lines
Quoted 3 lines
...
Yeah, we need to handle that part better, I think it's a leftover when we generalizedAF_VSOCKto support more transport than vmci.Speaking of leftovers, I have trouble understanding where does vsock set
sk_erron listener sockets anyway. If it doesn't, whyvsock_accept()checks for it?I can't also see where it can be set TBH. Should we remove it ?
I couldn't find it for listener side too.
Removing
sk_errhandling fromvsock_accept()solves the problem, right?
Quoted 9 lines
Quoted 4 lines
Quoted 2 lines
thanks,
MichalYes, confirmed, removing
sk_errchecks fromvsock_accept()does solve the problem.Okay, so maybe better on going on this direction. WDYT?
Stefano
I'm still a bit concerned about how connect() and poll() interact here, even with the sk_err checks removed from vsock_accept().
For example:vsock_accept() now lets us reuse a socket whose connect() failed (call it r0) as syzbot reproducer does. After listen(), r0 becomes a listener (sk_state == TCP_LISTEN) and works correctly -- it accepts connections.
But poll() on r0 still marks POLLERR, even though there is no error on that socket at that point.
As I understand it, sk_err holds an error that has not yet been reported to userspace. In the blocking vsock_connect() case we have already read that error and returned it to the caller, so it is no longer pending Shouldn't sk_err be consumed/cleared when vsock_connect() returns it to userspace?
If you think the POLLERR above is acceptable, I'm fine going with just the vsock_accept() change.
Thanks,
Phi.
Stefano Garzarella
maintainerQuoted 30 lines · Nguyen Dinh Phi [SG]
Quoted 17 lines · Stefano Garzarella
Quoted 16 lines · Nguyen Dinh Phi [SG]
Quoted 15 lines · Michal Luczaj
Quoted 11 lines · Nguyen Dinh Phi [SG]
Quoted 9 lines
Quoted 7 lines
Quoted 3 lines
Quoted 3 lines
...
Yeah, we need to handle that part better, I think it's a leftover when we generalizedAF_VSOCKto support more transport than vmci.Speaking of leftovers, I have trouble understanding where does vsock set
sk_erron listener sockets anyway. If it doesn't, whyvsock_accept()checks for it?I can't also see where it can be set TBH. Should we remove it ?
I couldn't find it for listener side too.
Removing
sk_errhandling fromvsock_accept()solves the problem, right?Quoted 9 lines
Quoted 4 lines
Quoted 2 lines
thanks,
MichalYes, confirmed, removing
sk_errchecks fromvsock_accept()does solve the problem.Okay, so maybe better on going on this direction. WDYT?
Stefano
I'm still a bit concerned about how
connect()andpoll()interact here, even with thesk_errchecks removed fromvsock_accept().
Quoted 7 lines
For example:
vsock_accept()now lets us reuse a socket whoseconnect()failed (call it r0) as syzbot reproducer does. Afterlisten(), r0 becomes a listener (sk_state==TCP_LISTEN) and works correctly -- it accepts connections.But
poll()on r0 still marks POLLERR, even though there is no error on that socket at that point.As I understand it,
sk_errholds an error that has not yet been reported to userspace. In the blockingvsock_connect()case we have already read that error and returned it to the caller, so it is no longer pending Shouldn'tsk_errbe consumed/cleared whenvsock_connect()returns it to userspace?
Yeah, makes sense to me, I'll ack the v2.
@Michal WDYT?
As cleanup (separate patch), should we remove the sk_err check in vsock_accept() ?
Thanks,
Stefano
Quoted 51 lines · Stefano Garzarella
Quoted 43 lines · Nguyen Dinh Phi [SG]
Quoted 22 lines · Stefano Garzarella
Quoted 21 lines · Nguyen Dinh Phi [SG]
Quoted 19 lines · Michal Luczaj
Quoted 5 lines · Nguyen Dinh Phi [SG]
Quoted 5 lines
Quoted 5 lines
Quoted 4 lines
Quoted 4 lines
...
Yeah, we need to handle that part better, I think it's a leftover when
we generalizedAF_VSOCKto support more transport than vmci.Quoted 8 lines
Quoted 6 lines
Quoted 4 lines
Speaking of leftovers, I have trouble understanding where does vsock set
sk_erron listener sockets anyway. If it doesn't, whyvsock_accept()checks for it?I can't also see where it can be set TBH. Should we remove it ?
I couldn't find it for listener side too.
Removing
sk_errhandling fromvsock_accept()solves the problem, right?thanks,
MichalQuoted 7 lines
Quoted 2 lines
Yes, confirmed, removing
sk_errchecks fromvsock_accept()does solve the problem.Okay, so maybe better on going on this direction. WDYT?
Stefano
I'm still a bit concerned about how
connect()andpoll()interact here, even with thesk_errchecks removed fromvsock_accept().For example:
vsock_accept()now lets us reuse a socket whoseconnect()failed (call it r0) as syzbot reproducer does. Afterlisten(), r0 becomes a listener (sk_state==TCP_LISTEN) and works correctly -- it accepts connections.But
poll()on r0 still marks POLLERR, even though there is no error on that socket at that point.Quoted 6 lines
As I understand it,
sk_errholds an error that has not yet been reported to userspace. In the blockingvsock_connect()case we have already read that error and returned it to the caller, so it is no longer pending
Shouldn'tsk_errbe consumed/cleared whenvsock_connect()returns it to userspace?
Quoted 2 lines
Yeah, makes sense to me, I'll ack the v2.
@Michal WDYT?
I'm worried this patch does not address the non-blocking connect() case. Could vsock_connect_timeout() set sk->sk_err = ETIMEDOUT after connect() returns?
Quoted 2 lines
As cleanup (separate patch), should we remove the
sk_errcheck invsock_accept()?
Stefano Garzarella
maintainerQuoted 52 lines · Michal Luczaj
Quoted 51 lines · Stefano Garzarella
Quoted 49 lines · Nguyen Dinh Phi [SG]
Quoted 22 lines · Stefano Garzarella
Quoted 21 lines · Nguyen Dinh Phi [SG]
Quoted 19 lines · Michal Luczaj
Quoted 5 lines · Nguyen Dinh Phi [SG]
Quoted 5 lines
Quoted 5 lines
Quoted 4 lines
Quoted 4 lines
...
Yeah, we need to handle that part better, I think it's a leftover when
we generalizedAF_VSOCKto support more transport than vmci.Quoted 8 lines
Quoted 6 lines
Quoted 4 lines
Speaking of leftovers, I have trouble understanding where does vsock set
sk_erron listener sockets anyway. If it doesn't, whyvsock_accept()checks for it?I can't also see where it can be set TBH. Should we remove it ?
I couldn't find it for listener side too.
Removing
sk_errhandling fromvsock_accept()solves the problem, right?thanks,
MichalQuoted 7 lines
Quoted 2 lines
Yes, confirmed, removing
sk_errchecks fromvsock_accept()does solve the problem.Okay, so maybe better on going on this direction. WDYT?
Stefano
I'm still a bit concerned about how
connect()andpoll()interact here, even with thesk_errchecks removed fromvsock_accept().For example:
vsock_accept()now lets us reuse a socket whoseconnect()failed (call it r0) as syzbot reproducer does. Afterlisten(), r0 becomes a listener (sk_state==TCP_LISTEN) and works correctly -- it accepts connections.But
poll()on r0 still marks POLLERR, even though there is no error on that socket at that point.As I understand it,
sk_errholds an error that has not yet been reported to userspace. In the blockingvsock_connect()case we have already read that error and returned it to the caller, so it is no longer pending
Shouldn'tsk_errbe consumed/cleared whenvsock_connect()returns it to userspace?
Quoted 6 lines
Quoted 2 lines
Yeah, makes sense to me, I'll ack the v2.
@Michal WDYT?I'm worried this patch does not address the non-blocking
connect()case. Couldvsock_connect_timeout()setsk->sk_err = ETIMEDOUTafterconnect()returns?
This is a good point!
So we still need to remove sk_err check in vsock_accept(), or set sk->sk_err = 0 in vsock_listen() to have a complete fix, right?
Thanks,
Stefano
Quoted 56 lines · Stefano Garzarella
Quoted 55 lines · Michal Luczaj
Quoted 53 lines · Stefano Garzarella
Quoted 43 lines · Nguyen Dinh Phi [SG]
Quoted 22 lines · Stefano Garzarella
Quoted 21 lines · Nguyen Dinh Phi [SG]
Quoted 19 lines · Michal Luczaj
Quoted 5 lines · Nguyen Dinh Phi [SG]
Quoted 5 lines
Quoted 5 lines
Quoted 4 lines
Quoted 4 lines
...
Yeah, we need to handle that part better, I think it's a leftover when
we generalizedAF_VSOCKto support more transport than vmci.Quoted 8 lines
Quoted 6 lines
Quoted 4 lines
Speaking of leftovers, I have trouble understanding where does vsock set
sk_erron listener sockets anyway. If it doesn't, whyvsock_accept()checks for it?I can't also see where it can be set TBH. Should we remove it ?
I couldn't find it for listener side too.
Removing
sk_errhandling fromvsock_accept()solves the problem, right?thanks,
MichalQuoted 7 lines
Quoted 2 lines
Yes, confirmed, removing
sk_errchecks fromvsock_accept()does solve the problem.Okay, so maybe better on going on this direction. WDYT?
Stefano
I'm still a bit concerned about how
connect()andpoll()interact here, even with thesk_errchecks removed fromvsock_accept().For example:
vsock_accept()now lets us reuse a socket whoseconnect()failed (call it r0) as syzbot reproducer does. Afterlisten(), r0 becomes a listener (sk_state==TCP_LISTEN) and works correctly -- it accepts connections.But
poll()on r0 still marks POLLERR, even though there is no error on that socket at that point.Quoted 6 lines
As I understand it,
sk_errholds an error that has not yet been reported to userspace. In the blockingvsock_connect()case we have already read that error and returned it to the caller, so it is no longer pending
Shouldn'tsk_errbe consumed/cleared whenvsock_connect()returns it to userspace?Yeah, makes sense to me, I'll ack the v2.
@Michal WDYT?
Quoted 8 lines
Quoted 3 lines
I'm worried this patch does not address the non-blocking
connect()case. Couldvsock_connect_timeout()setsk->sk_err = ETIMEDOUTafterconnect()returns?This is a good point!
So we still need to remove
sk_errcheck invsock_accept(), or setsk->sk_err = 0invsock_listen()to have a complete fix, right?
Yup, that's my understanding as well.
That said, I'm not against flushing sk_err on a failed blocking connect() (this patch) as a follow up, if you guys agree that makes vsock behave like other socket families.
Quoted 4 lines · Michal Luczaj
Quoted 3 lines · Stefano Garzarella
This is a good point!
Quoted 8 lines
Quoted 2 lines
So we still need to remove
sk_errcheck invsock_accept(), or setsk->sk_err = 0invsock_listen()to have a complete fix, right?Yup, that's my understanding as well.
That said, I'm not against flushing
sk_erron a failed blockingconnect()(this patch) as a follow up, if you guys agree that makes vsock behave like other socket families.
IMO, we should remove the sk_err check in vsock_accept() and invoke sock_error() in vsock_connnect()
Thanks,
Phi