jingfei195887 opened a new pull request, #21665:
URL: https://github.com/apache/nuttx/pull/21665

   ## Summary
   
   `shmfs_mmap()` maps the whole object regardless of the requested
   length. In flat and protected builds the object address is returned
   directly, so a mapping longer than the object lets the caller read and
   write past its end into adjacent heap memory. Return -EINVAL for such a
   request in those builds. Kernel builds map whole pages through the MMU
   and are not changed.
   
   ## Impact
   
   `mmap()` of a shared memory object with a length larger than the object
   now fails with EINVAL in flat and protected builds. Mappings up to the
   object size are unchanged.
   
   ## Testing
   
   Host: Ubuntu x86_64, gcc (Ubuntu 13.1.0-8ubuntu1~22.04) 13.1.0, master 
03aea78639, `sim:nsh` with
   `CONFIG_FS_SHMFS=y`. A small test program creates a 64-byte object with
   `shm_open()` and `ftruncate()`, then maps it with different lengths:
   
   | length | master | this PR |
   |---:|---|---|
   | 64 | OK | OK |
   | 32 | OK | OK |
   | 4096 | OK | EINVAL |
   
   - `./tools/checkpatch.sh -g master..HEAD`: all checks pass.
   - Make and CMake builds pass; `ostest` exits with status 0.
   


-- 
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