jingfei195887 opened a new pull request, #22017:
URL: https://github.com/apache/nuttx/pull/22017
## Summary
- **mtd_partition: fix NULL erase dereference in part_ioctl().**
`mtd_partition()` already leaves the partition's own `erase` method NULL
when the parent has none (memories without an erase operation, such as
RRAM). `part_ioctl()` does not check this: `MTDIOC_BULKERASE` calls
`priv->parent->erase` directly, and `MTDIOC_ERASESECTORS` reaches it
through `part_erase()`, so either ioctl calls through a NULL pointer.
Return `-ENOSYS` instead.
## Impact
- New feature / API change: NO.
- Behavior: `MTDIOC_BULKERASE` and `MTDIOC_ERASESECTORS` on a partition of
an MTD without an `erase` method fail with `ENOSYS` instead of crashing.
Partitions of MTDs that have `erase` are 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_MTD` and `CONFIG_MTD_PARTITION`, and a small test
app that registers an MTD with `bread`, `bwrite` and `ioctl` but no
`erase`, creates a partition on it with `mtd_partition()`, and calls the
partition's `ioctl()` with `MTDIOC_BULKERASE` and then
`MTDIOC_ERASESECTORS`.
Testing logs before change (master fc8d354f9a): the simulator crashes
with a segmentation fault (exit status 139) in `MTDIOC_BULKERASE`:
```
mtdnoerase: partition erase=0
timeout: the monitored command dumped core
```
Testing logs after change:
```
mtdnoerase: partition erase=0
mtdnoerase: BULKERASE ret=-38
mtdnoerase: ERASESECTORS ret=-38
```
- `./tools/checkpatch.sh -g master..HEAD`: all checks pass.
- `sim:nsh` with `CONFIG_MTD` and `CONFIG_MTD_PARTITION`: 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]