Repository navigation
net/rpmsg: fix integer overflow in sendmsg and datagram truncation - #21522
Conversation
|
casaroli
left a comment
There was a problem hiding this comment.
The Testing section has no build or runtime log, which CONTRIBUTING 1.7.2 requires for a code change. Fix: add a run on sim:rpserver + sim:rpproxy (or qemu-armv8a:rpproxy) that sends a SOCK_DGRAM message larger than the rpmsg buffer and shows -EMSGSIZE, and a normal stream and datagram transfer.
The commit has Assisted-by: Google Gemini below Signed-off-by:; CONTRIBUTING 1.5 wants it above the signature, in the form AGENT_NAME:MODEL_VERSION. Fix: move it above and add the model version.
1. In rpmsg_socket_get_iovlen(), iov_len values (size_t) were accumulated into a uint32_t without overflow checking. If the sum exceeded UINT32_MAX, it silently wrapped around. On 64-bit platforms, individual iov_len values larger than UINT32_MAX were also silently truncated. Fail with -EINVAL when the sum exceeds MIN(SSIZE_MAX, UINT32_MAX), matching usrsock (commit 6e1126a) and local (commit 56f37d5). 2. In rpmsg_socket_send_continuous() (SOCK_STREAM), handle error return from rpmsg_socket_get_iovlen() and return early. 3. In rpmsg_socket_send_single() (SOCK_DGRAM): - Check len against conn->sendsize without addition overflow before computing total = len + sizeof(uint32_t), returning -EMSGSIZE on violation per POSIX sendmsg() semantics. - Reject datagrams exceeding acquired TX buffer capacity (ipcsize) with -EMSGSIZE and release the buffer, rather than silently shortening total and len which transmitted truncated datagrams and caused unsigned integer underflow. - When concurrent senders reduce space below total under sendlock, release the buffer and return -EAGAIN for nonblocking sockets, or continue waiting on conn->sendsem for blocking sockets. Assisted-by: Google Gemini:gemini-3.8-flash Signed-off-by: Swatantra Yadav <[email protected]>
ab6e3ea to
f54f446
Compare
casaroli
left a comment
There was a problem hiding this comment.
The logs under Runtime Verification are not output of examples/rpmsgsocket: rpsock_client.c prints none of these lines (client test stream pass, client test dgram pass, client test dgram oversized payload rejected with -EMSGSIZE as expected), it never calls sendmsg(), and rpsock_dgram_client() does not read a fifth argument, so the 65536 of the third run is not used.
Fix: run the tests and paste the real, unedited console output.
updated |
Summary
RPMsg sockets (
net/rpmsg) contained integer overflow vulnerabilities duringiov_lenaccumulation, addition wrap-around in datagram size checks, and silent datagram truncation when payloads exceeded the acquired RPMsg buffer size.In
rpmsg_socket_get_iovlen(),size_t iov_lenvalues were accumulated intouint32_t lenwithout overflow checks. OnSOCK_STREAMconnections, an overflow caused silent data loss by skipping the transmit loop. OnSOCK_DGRAMconnections,total = len + sizeof(uint32_t)could wrap modulo 2^32, bypassing theconn->sendsizecheck. Furthermore,rpmsg_socket_send_single()previously shortenedtotalandlenusingMIN(), which silently transmitted truncated datagrams and caused unsigned integer underflow intotal - sizeof(uint32_t).This change bounds
iov_lenaccumulation toMIN(SSIZE_MAX, UINT32_MAX)returning-EINVAL, prevents addition wrap-around, rejects oversized datagrams upfront with-EMSGSIZE, and preserves blocking socket semantics when concurrent senders reduce window space.Behavior Comparison
get_iovlensum > 4 GBuint32_tsilently wraps; skips loop on stream sockets-EINVALlen + 4addition check3 > sendsize(passes)len > sendsize - 4before additionipcsizeMIN()and sends partial packet; unsigned underflow inlen-EMSGSIZEand releases buffer-EAGAINif space dropsnet_sem_timedwaitImpact
Testing
ubuntu:22.04, GCC 11.4 multilib, tools/nxstyle, checkpatch.sh)sim:rpserver+sim:rpproxytools/nxstyle net/rpmsg/rpmsg_sockif.c(0 errors, 0 warnings).tools/checkpatch.sh -r -K -m -g HEAD~1..HEAD:Runtime Verification (
sim:rpserver&sim:rpproxy/examples/rpmsgsocket)Tested using dual-instance simulation (
sim:rpservermaster andsim:rpproxyslave over OpenAMP shared memory).rpsock_serveronsim:rpserver:proxyconsole viacuand runrpsock_client(sim:rpproxy):