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 da696ef748312c0872a0428cd3aeb2883a23e7ef
Author: Bowen Wang <[email protected]>
AuthorDate: Thu Nov 12 12:48:22 2026 +0800

    fs/rpmsgfs: hold an endpoint reference across the unbind sweep
    
    rpmsg_unregister_callback() runs device_destroy() once per rpmsg
    device.  With priv freed from the endpoint release callback, the device
    whose cpuname matches drops the endpoint's last reference and frees
    priv in the middle of that sweep, which then keeps reading
    priv->cpuname for every device left:
    
      device   rpmsgfs_device_destroy()             priv
      ------   -----------------------------------  ------------------
      tee      strcmp("audio", "tee")    != 0       alive
      audio    strcmp("audio", "audio")  == 0       freed by release_cb
      sensor   strcmp(<freed>, "sensor")            use after free
    
    Take a reference of our own before the sweep and put it back after, so
    that priv outlives every device_destroy() call made from it.
    
    Signed-off-by: Bowen Wang <[email protected]>
    Signed-off-by: jingfei <[email protected]>
---
 fs/rpmsgfs/rpmsgfs_client.c | 13 ++++++++++++-
 1 file changed, 12 insertions(+), 1 deletion(-)

diff --git a/fs/rpmsgfs/rpmsgfs_client.c b/fs/rpmsgfs/rpmsgfs_client.c
index 9e7f8f1eafc..0cbe56f4af1 100644
--- a/fs/rpmsgfs/rpmsgfs_client.c
+++ b/fs/rpmsgfs/rpmsgfs_client.c
@@ -835,11 +835,22 @@ int rpmsgfs_client_bind(FAR void **handle, FAR const char 
*cpuname)
 
 int rpmsgfs_client_unbind(FAR void *handle)
 {
-  rpmsg_unregister_callback(handle,
+  FAR struct rpmsgfs_s *priv = handle;
+
+  /* rpmsg_unregister_callback() runs device_destroy() once per rpmsg
+   * instance.  The matching one drops the endpoint's last reference and
+   * frees priv through rpmsgfs_ept_release(), while the sweep goes on
+   * reading priv->cpuname for the instances left, so hold a reference
+   * of our own across it.
+   */
+
+  rpmsg_ept_incref(&priv->ept);
+  rpmsg_unregister_callback(priv,
                             rpmsgfs_device_created,
                             rpmsgfs_device_destroy,
                             NULL,
                             NULL);
+  rpmsg_ept_decref(&priv->ept);
 
   return 0;
 }

Reply via email to