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

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

commit f164306cc982badb9d464654c323bf29dfc23f4f
Author: pangzhen1 <[email protected]>
AuthorDate: Wed May 20 17:29:52 2026 +0800

    drivers/misc/rpmsgdev_server: read the configdata length unaligned
    
    The ioctl payload sits in a packed message and may be unaligned, so
    reading config_data_s::len through a cast is an unaligned access.
    Copy it out with memcpy().
    
    Signed-off-by: pangzhen1 <[email protected]>
    Signed-off-by: Bowen Wang <[email protected]>
---
 drivers/misc/rpmsgdev_server.c | 20 ++++++++++++++++----
 1 file changed, 16 insertions(+), 4 deletions(-)

diff --git a/drivers/misc/rpmsgdev_server.c b/drivers/misc/rpmsgdev_server.c
index d667b18efc9..6390d0aafbf 100644
--- a/drivers/misc/rpmsgdev_server.c
+++ b/drivers/misc/rpmsgdev_server.c
@@ -478,11 +478,23 @@ static int rpmsgdev_ioctl_handler(FAR struct 
rpmsg_endpoint *ept,
 {
   FAR struct rpmsgdev_ioctl_s *msg = data;
   FAR struct file *filep = (FAR struct file *)(uintptr_t)msg->filep;
+  bool   is_cfg = (msg->request >= CFGDIOC_GETCONFIG &&
+                   msg->request <= CFGDIOC_NEXTCONFIG);
+  size_t cfglen = 0;
 
-  if (msg->request >= CFGDIOC_GETCONFIG &&
-      msg->request <= CFGDIOC_NEXTCONFIG &&
-      msg->arglen != (sizeof(struct config_data_s) +
-      ((FAR struct config_data_s *)msg->buf)->len))
+  if (is_cfg)
+    {
+      /* msg->buf is a char[] inside a packed wire struct and may be
+       * unaligned; use memcpy to read config_data_s::len safely instead
+       * of casting to (struct config_data_s *).
+       */
+
+      memcpy(&cfglen,
+             msg->buf + offsetof(struct config_data_s, len),
+             sizeof(cfglen));
+    }
+
+  if (is_cfg && msg->arglen != sizeof(struct config_data_s) + cfglen)
     {
       msg->header.result = -EMSGSIZE;
     }

Reply via email to