You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@nuttx.apache.org by "JianyuWang0623 (via GitHub)" <gi...@apache.org> on 2024/10/11 04:20:25 UTC

[PR] misc/rpmsgdev: The private data should be freed only when endpoint is released [nuttx]

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

   ## Summary
   A use-after-free problem occurs when there are multiple remotes in the list `g_rpmsg` and the matching remote is not the last item in the list.
   
   ### Log
   ```
   # Export the device "/dev/LOCAL_DEV" to remote "REMOTE_CPU"
   ap> testdev -d 2 -c "REMOTE_CPU" -l "/dev/LOCAL_DEV"
   [ap] kasan_report: kasan detected a read access error, address at 0x3c3d4740,size is 4, return address: 0x2c33620f
   [ap] kasan_show_memory: Shadow bytes around the buggy address:
   [ap] kasan_show_memory:   0x3c3d46f0: cc cc cc cc cc cc cc cc cc cc cc cc cc cc cc cc
   [ap] kasan_show_memory:   0x3c3d4700: aa aa aa aa cc cc cc cc cc cc cc cc cc cc cc cc
   [ap] kasan_show_memory:   0x3c3d4710: 40 47 3d 3c ed 61 33 2c 00 00 00 00 00 00 00 00
   [ap] kasan_show_memory:   0x3c3d4720: 00 00 00 00 00 00 00 00 00 00 00 00 cc cc cc cc
   [ap] kasan_show_memory:   0x3c3d4730: 55 55 55 55 38 00 00 00 02 2c 00 00 cc cc cc cc
   [ap] kasan_show_memory:   0x3c3d4740:[00 00 00 00]66 e0 42 3c cc cc cc cc cc cc cc cc
   [ap] kasan_show_memory:   0x3c3d4750: cc cc cc cc cc cc cc cc cc cc cc cc cc cc cc cc
   [ap] kasan_show_memory:   0x3c3d4760: aa aa aa aa 38 00 00 00 01 2c 00 00 cc cc cc cc
   [ap] kasan_show_memory:   0x3c3d4770: 50 57 44 3d 2f 00 cc cc cc cc cc cc cc cc cc cc
   [ap] kasan_show_memory:   0x3c3d4780: cc cc cc cc cc cc cc cc cc cc cc cc cc cc cc cc
   [ap] dump_assert_info: Current Version: NuttX ****** ***** *** 12.3.0 **********-***** *** ** 2024 **:**:** arm
   [ap] dump_assert_info: Assertion failed panic: at file: kasan/hook.c:187 task: testdev process: testdev 0x2ca20495
   
   $ addr2line -fe nuttx/nuttx 0x2c33620f
   rpmsgdev_server_created
   /workspace/nuttx/drivers/misc/rpmsgdev_server.c:529
   # Line 529 => strcmp()
   ```
   ## Impact
   misc/rpmsgdev
   
   ## Testing
   CI
   


-- 
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: commits-unsubscribe@nuttx.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] misc/rpmsgdev: The private data should be freed only when endpoint is released [nuttx]

Posted by "nuttxpr (via GitHub)" <gi...@apache.org>.
nuttxpr commented on PR #14076:
URL: https://github.com/apache/nuttx/pull/14076#issuecomment-2406534854

   [**\[Experimental Bot, please feedback here\]**](https://github.com/search?q=repo%3Aapache%2Fnuttx+13552&type=issues)
   
   
   
   The provided PR summary does not meet the NuttX requirements. Here's why and how to improve it:
   
   **What's Missing/Needs Improvement:**
   
   1. **Insufficient Explanation:**  The summary briefly mentions a use-after-free but lacks detail.  It needs to clearly articulate:
       * **Root Cause:** What specific code path leads to freeing memory while it's still in use? 
       * **Solution:** How does the PR fix the use-after-free? Does it change data structures, synchronization mechanisms, or code logic?
   2. **Missing Context:**
       * **Frequency:** Is this use-after-free easily triggered? Under what conditions?
       * **Severity:** What are the consequences of hitting this bug (data corruption, crash)?
   3. **Incomplete Impact Assessment:**
       * **User Impact:** Will existing applications using `rpmsgdev` be affected? How?
       * **Build Impact:**  Any changes to build configuration, Kconfig options, etc.? 
       * **Security Impact:** Use-after-free are security-critical.  Is this exploitable? 
   4. **Inadequate Testing:**
      * **CI is Insufficient:** CI passing is good but not enough for memory safety bugs.
      * **Targeted Tests Required:** The PR needs tests that reliably reproduce the use-after-free *before* the fix and then demonstrate the fix prevents it. 
      * **Test Case Code:** Include the actual test code snippets used (or added) for verification.
   
   **Example of an Improved Summary:**
   
   ```
   ## Summary
   
   This PR fixes a use-after-free vulnerability in the `rpmsgdev` driver that can occur when a remote is removed while `rpmsgdev_server_created()` is processing a new connection from that same remote. The issue arises due to a race condition where the remote's entry in the `g_rpmsg` list is freed prematurely. 
   
   The fix introduces a locking mechanism around accesses to the `g_rpmsg` list within `rpmsgdev_server_created()` to prevent the use of a freed remote entry. 
   
   This vulnerability could lead to denial-of-service or potentially remote code execution, as it allows an attacker to corrupt memory contents.
   
   ## Impact
   
   * **Impact on user:** Existing `rpmsgdev` users should upgrade to this patched version for improved system stability and security.
   * **Impact on build:** No changes to the build process.
   * **Impact on hardware:** No hardware-specific changes.
   * **Impact on documentation:** No documentation updates required.
   * **Impact on security:** This addresses a use-after-free vulnerability (CVE-XXXX-YYYY).
   * **Impact on compatibility:** No compatibility issues.
   
   ## Testing
   
   This PR includes a new test case in `drivers/misc/rpmsgdev/test_rpmsgdev.c` that simulates the race condition and verifies the fix:
   
   ```c
   // Test case code demonstrating the bug and the fix
   ```
   
   **Build Host:** Linux (Ubuntu 20.04), x86_64, GCC 9.4.0
   **Target:** QEMU (virt) - ARMv7-M, Cortex-M4F
   
   **Testing logs before the change:**
   ```
   <Logs showing the crash/corruption>
   ```
   
   **Testing logs after the change:**
   ```
   <Logs demonstrating the fix and successful execution>
   ```
   
   ``` 
   
   **Key Points for a Strong NuttX PR:**
   
   * **Clarity is Paramount:** Clearly explain the technical details of the bug and your solution.
   * **Provide Context:** Help reviewers understand the bug's significance and the reasoning behind your changes.
   * **Robust Testing:**  Demonstrate that you've thoroughly tested your fix, especially for memory safety issues.
   * **Follow the Template:** Adhere to the provided PR template structure. 
   


-- 
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: commits-unsubscribe@nuttx.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] misc/rpmsgdev: The private data should be freed only when endpoint is released [nuttx]

Posted by "xiaoxiang781216 (via GitHub)" <gi...@apache.org>.
xiaoxiang781216 merged PR #14076:
URL: https://github.com/apache/nuttx/pull/14076


-- 
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: commits-unsubscribe@nuttx.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org