jingfei195887 opened a new pull request, #22014:
URL: https://github.com/apache/nuttx/pull/22014
## Summary
- **fs/procfs: refuse MAP_SHARED mappings with ENODEV.**
procfs has no `mmap` method, so `file_mmap_()` keeps `ret` at `-ENOTTY`
and falls back to `rammap()` for every mapping, including `MAP_SHARED`.
`mmap(MAP_SHARED)` of a procfs file therefore returns a private RAM copy
as if it were shared. PSE52 RT_mmap TP25 and RT_mmap_P TP28 map
`/proc/version` with `MAP_SHARED` and expect `ENODEV`.
A procfs file has no backing store to share: its content is generated
on every read. Add `procfs_mmap()`, which returns `-ENODEV` for
`MAP_SHARED` and `-ENOTTY` otherwise. `file_mmap_()` also calls the
method for a read-only `MAP_PRIVATE` mapping, so `-ENOTTY` keeps the
`rammap()` copy for private mappings.
Refusing every `MAP_SHARED` mapping without an `mmap` method in
`fs_mmap.c` was not chosen: FAT, littlefs and other file systems rely on
the `rammap()` fallback for read-only shared mappings.
## Impact
- New feature / API change: NO.
- Behavior: `mmap(MAP_SHARED)` of a procfs file fails with `ENODEV`
instead of returning a private copy. `MAP_PRIVATE` is unchanged.
- Build, hardware, documentation, security, compatibility: NO.
## Testing
Host: Ubuntu 22.04 x86_64, gcc (Ubuntu 13.1.0-8ubuntu1~22.04) 13.1.0.
`sim:nsh` with `CONFIG_FS_PROCFS` and `CONFIG_FS_RAMMAP`, and a small test
app that opens `/proc/version` read-only and maps 64 bytes with
`PROT_READ`, once with `MAP_SHARED` and once with `MAP_PRIVATE`.
Testing logs before change (master fc8d354f9a):
```
procmmap: shared OK errno=0
procmmap: private OK errno=0
```
Testing logs after change:
```
procmmap: shared FAILED errno=19
procmmap: private OK errno=0
```
- `./tools/checkpatch.sh -g master..HEAD`: all checks pass.
- `sim:nsh` with `CONFIG_FS_PROCFS` and `CONFIG_FS_RAMMAP`: Make and CMake
builds pass with no new warnings in the changed file; `ostest` exits
with status 0.
- Verified on sim only.
## PR verification Self-Check
* [x] This PR introduces only one functional change.
* [x] I have updated all required description fields above.
* [x] My PR adheres to Contributing Guidelines and Documentation (git commit
title and message, coding standard, etc).
* [ ] My PR is still work in progress (not ready for review).
* [x] My PR is ready for review and can be safely merged into a codebase.
--
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]