CV-Bowen opened a new pull request, #22369:
URL: https://github.com/apache/nuttx/pull/22369

   ## Summary
   
   mmap() on rpmsg sockets, in the order the changes were made:
   
   - `net: let a socket address family implement mmap()`: `sock_file_ops`
     had no mmap method, so mmap() on any socket failed. New
     `si_mmap` in `struct sock_intf_s` (appended, so positional
     initializers of the other address families stay valid), called from
     `sock_file_mmap()`; without it mmap() returns `-EOPNOTSUPP`.
   - `net/rpmsg: support mmap() on rpmsg sockets`: the mapping is a buffer
     from the rpmsg device's shared memory (`rpmsg_alloc_buf()`), freed by
     munmap(); a transport without buffer allocation returns `-ENOSYS`.
   - `net: add psock_mmap()`: the dispatch moves to
     `net/socket/net_mmap.c` next to the other `psock_*()` operations.
   - `net/rpmsg: fix use-after-free in rpmsg_socket_munmap`: munmap() after
     the socket was closed dereferenced the freed connection; the mapping
     now keeps the rpmsg device instead.
   
   ## Impact
   
   - New `si_mmap` member at the end of `struct sock_intf_s` and new
     `psock_mmap()`; address families without it are unchanged except that
     mmap() now fails with `-EOPNOTSUPP`.
   - mmap() works on connected rpmsg sockets whose transport can allocate
     shared buffers (rpmsg_virtio on the driver side).
   
   ## Testing
   
   Host: Ubuntu 22.04.5 LTS x86_64, QEMU version 10.2.1, sim: cc (Ubuntu 
13.1.0-8ubuntu1~22.04) 13.1.0, qemu-armv8a: aarch64-none-elf-gcc (Arm GNU 
Toolchain 12.2.Rel1 (Build arm-12.24)) 12.2.1 20221205
   
   Every commit builds sim:rpserver, sim:rpproxy, qemu-armv8a:rpserver and
   qemu-armv8a:rpproxy with 0 warnings.
   
   A test-only program on the server connects a stream socket to
   `rpsock_server stream block mm1` on the proxy, maps 256 bytes, writes
   them, unmaps and closes:
   
   | | master | this PR |
   |---|---|---|
   | sim | `mmap failed errno 38` | `mmap ok`, `munmap 0` |
   | qemu-armv8a | `mmap failed errno 29` | `mmap ok`, `munmap 0` |
   
   Not tested: munmap() after close() (the use-after-free); the proxy side
   (rpmsg_virtio device role) allocates from `RPMSG_HEAP`, which these
   configurations do not enable, so it returns `-ENOMEM` there.
   
   No regression in rpmsg: sim:rpserver/rpproxy and 
qemu-armv8a:rpserver/rpproxy boot and pass the fixed rpmsg cases (dump, ping, 
rpmsgfs; 15/15). qemu-armv8a was built with LIBC_ENVPATH and BINFMT_CHECKEXEC 
disabled, which current master needs for nxinit to start nsh there; unrelated 
to this change.
   


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to