-
-
Notifications
You must be signed in to change notification settings - Fork 6.7k
vquic.c HAVE_SENDMSG recvmsg_packets missing msg_iov reset #17120
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
On further analysis even this proposed fix is wrong. Since the
But then the question can be raised: What's the point of using |
So, you say there are OS that modify |
That's a good point. I will actually verify that this is really happening. |
@icing Here is the relevant part: https://github.com/NetBSD/src/blob/62ada091aa7963b3d5e7817f98a9bbd9ad38f949/sys/kern/subr_copy.c#L103 So for example in |
Arg. ok. Thanks for finding this. |
When calling recvmsg(), always set up the msg structures for each call as there are OS implemenations that change members of msg. refs curl#17120
Proposed fix in #17131. |
Actually, netbsd is not to blame after all. They do copy the structure from userland to kernel memory properly. After the internal processing, the msghdr is copied back, but iovec are not (obviously, as they should not be touched). So how come this is an issue in code that was derived from netbsd? When AmiTCP/IP was created in 1993, the peeps working on it took networking code from netbsd 0.9. Since AmigaOS has no separation between user and kernel memory, in their bout of optimisation, they removed some buffer copying and missed the distinction of iovec not being copied back to userland. Instead, they made the recvmsg/sendmsg pass the user-passed struct msghdr as-is to the internal engine doing the processing. This leads to the iovec being modified when it should not be. Oops. Somehow, this went unnoticed for 32 years. Thanks, libcurl, for dragging this ugly bit to the surface! |
When calling recvmsg(), always set up the msg structures for each call as there are OS implemenations that change members of msg. Fixes curl#17120 Reported-by: Harry Sintonen Closes curl#17131
When calling recvmsg(), always set up the msg structures for each call as there are OS implemenations that change members of msg. Fixes curl#17120 Reported-by: Harry Sintonen Closes curl#17131
I did this
It seems that vquic.c
HAVE_SENDMSG
recvmsg_packets
fails to reset themsg_iov.iov_base
andmsg_iov.iov_len
back tobuf
values when the buffer is been fully filled (that is inficated bymsg_iov.iov_len
becoming 0):curl/lib/vquic/vquic.c
Line 497 in 23bed34
In this case the code will call
recvmsg
withiov_len
of 0. Depending on the specific of the operating system network stack, this can lead to 0 being returned. If 0 is returned the loop will never terminate aspkts
can't advance.I believe the correct thing to do is to reset the
iov_base
andiov_len
when the whole buffer has been consumed, something like this:This seems to work for me, at least, but I am not 100% is this is what should be done here. Note that this codepath is not used on platforms that have
HAVE_SENDMMSG
.Bonus idea: Perhaps this and similar fallback codepaths should be exercised by testsuite by explicitly disabling configure flags?
I expected the following
recvmsg_packets
not getting stuck in a busyloop.curl/libcurl version
curl 8.13.0
operating system
MorphOS (network stack is a bsd variant that has recvmsg returning 0 when total iov_len is 0)
The text was updated successfully, but these errors were encountered: