This is an automated email from the ASF dual-hosted git repository.

xiaoxiang781216 pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/nuttx.git

commit 0184bd10ecda3384aa4a872f8b1a9c6018e258f8
Author: huojianchao <[email protected]>
AuthorDate: Tue Oct 13 20:11:18 2026 +0800

    drivers/note: stop sched_note_add() walking off a malformed packet
    
    sched_note_add() walks the notes forwarded by another CPU and trusts
    nc_length: only a DEBUGASSERT checks that a note is at least a note
    header and fits in what is left.  Without CONFIG_DEBUG_ASSERTIONS:
    
    - a note claiming more than is left makes len, a size_t, wrap to a huge
      value, so the walk goes on past the end of the packet and takes
      whatever it finds there as the next note;
    - a note with nc_length 0 never moves the walk forward, so the loop
      does not end.
    
    nc_length comes from the peer, so a truncated or corrupted packet is
    enough to get there.  Drop the rest of the packet instead.  The check
    replaces the DEBUGASSERT: losing the tail of a bad packet is better than
    panicking the CPU that receives it.
    
    Signed-off-by: huojianchao <[email protected]>
---
 drivers/note/note_driver.c | 11 +++++++++--
 1 file changed, 9 insertions(+), 2 deletions(-)

diff --git a/drivers/note/note_driver.c b/drivers/note/note_driver.c
index 86f8e83546a..2e8027c5caf 100644
--- a/drivers/note/note_driver.c
+++ b/drivers/note/note_driver.c
@@ -603,8 +603,15 @@ void sched_note_add(FAR const void *data, size_t len)
       size_t notelen = note->nc_length;
       FAR struct note_driver_s **driver;
 
-      DEBUGASSERT(notelen >= sizeof(struct note_common_s) &&
-                  len >= notelen);
+      /* nc_length comes from the peer, and len is unsigned: a note that
+       * claims more than is left would wrap len and walk off the packet.
+       */
+
+      if (notelen < sizeof(struct note_common_s) || notelen > len)
+        {
+          break;
+        }
+
       for (driver = g_note_drivers; *driver; driver++)
         {
           if ((*driver)->ops->add == NULL)

Reply via email to