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

   ## Summary
   
   Return `-ENOMEM` when `nfs_bind()` cannot allocate its RPC client.
   
   `ret` starts at zero. The allocation failure jumps to the cleanup label
   without changing it, so the mount state is freed but the caller receives
   success. The VFS then installs a mountpoint with a null private handle.
   Set the error before entering the existing cleanup path.
   
   ## Impact
   
   - Behavior: this allocation failure now makes `mount()` fail with `ENOMEM`
     instead of reporting success and leaving an invalid mountpoint.
   - Cleanup: the existing mutex destruction and mount-state release are
     retained.
   - Public API, configuration, build, hardware, documentation: no changes.
   - Compatibility: successful mounts and other failure results are unchanged.
   - Security: avoids exposing a mountpoint whose private state was never set.
   
   ## Testing
   
   Host: Ubuntu 22.04, Linux x86_64, GCC 13.1.0. Target: `sim:nsh`.
   Base: `01829d2136b96ad612b61a2cf32b447d257b0f35`.
   Head: `ddafc3ef58dbd3e2acbe7a050d52cfbbf0d60491`.
   
   The before/after functional builds enable `ALLOW_BSD_COMPONENTS`, `NFS`,
   `NET`, `NET_IPv4`, `NET_TCP`, `NET_SOCKOPTS`, `DEBUG_SYMBOLS`, and
   `DEBUG_NOOPT`.
   
   GDB forces the selected local allocation result to null before its null
   check, skipping the allocator call. The remaining `nfs_bind()` cleanup
   and VFS mount handling execute normally. The RPC failure test runs:
   
   ```text
   nfsmount 127.0.0.1 /nfsrpc /rpc
   nfsmount 127.0.0.1 /nfsrpc /rpc
   ```
   
   The debugger stops at the `rpc = fs_heap_zalloc(...)` statement, sets
   `rpc = 0`, and moves the program counter to the following `if (!rpc)`.
   A breakpoint at the cleanup return prints `ret`.
   
   Testing logs before change:
   
   ```text
   nsh> nfsmount 127.0.0.1 /nfsrpc /rpc
   NFS_ALLOCATION_FAILURE rpc
   NFS_CLEANUP /rpc ret=0
   nsh> nfsmount 127.0.0.1 /nfsrpc /rpc
   nsh: nfsmount: mount failed: 20
   ```
   
   The first mount incorrectly succeeds. The retry fails with `ENOTDIR`
   because the invalid mountpoint remains.
   
   Testing logs after change:
   
   ```text
   nsh> nfsmount 127.0.0.1 /nfsrpc /rpc
   NFS_ALLOCATION_FAILURE rpc
   NFS_CLEANUP /rpc ret=-12
   nsh: nfsmount: mount failed: 12
   nsh> nfsmount 127.0.0.1 /nfsrpc /rpc
   NFS_ALLOCATION_FAILURE rpc
   NFS_CLEANUP /rpc ret=-12
   nsh: nfsmount: mount failed: 12
   ```
   
   Both calls now reach the bind operation and fail with `ENOMEM`; the
   first failure does not leave a mountpoint behind.
   
   Additional before/after checks:
   
   | Case | Base | This PR |
   |---|---|---|
   | Initial mount-state allocation fails | ENOMEM | ENOMEM |
   | RPC connection returns ECONNREFUSED | ECONNREFUSED, cleanup runs | Same |
   | RPC connection and fsinfo report success | Non-null mount handle; unmount 
succeeds | Same |
   
   RPC connect, disconnect, and fsinfo operations in these additional cases
   are debugger stubs. They test local bind/unbind handling, not NFS protocol
   interoperability. No live NFS server or physical board is used.
   
   Final commit validation also enables UDP, so both socket implementations
   are built:
   
   ```text
   checkpatch: rc=0
   commits missing your Signed-off-by: 0
   make build: rc=0
   warnings in changed files: 0
   ostest: Exiting with status 0
   cmake reconfigure: rc=0
   cmake build: rc=0
   worktree tracked changes after: 0
   RESULT: PASS
   ```
   
   Full-file `checkpatch.sh -f fs/nfs/nfs_vfsops.c` and `git diff --check`
   also pass.
   
   ## 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]

Reply via email to