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


The following commit(s) were added to refs/heads/master by this push:
     new d546d3f335c drivers/serial/uart_rpmsg: scope and lock the dmatx abort
d546d3f335c is described below

commit d546d3f335c792f471b307e5aebdf108ef95b973
Author: wangyongrong <[email protected]>
AuthorDate: Mon Aug 3 20:14:17 2026 +0800

    drivers/serial/uart_rpmsg: scope and lock the dmatx abort
    
    uart_rpmsg_device_destroy() completed the in-flight TX descriptor
    unconditionally.  The dev->dmatx update and uart_xmitchars_done() call
    sat outside the "ept belongs to this rdev" test, and ran with no lock
    held.
    
    rpmsg_device_destroy() broadcasts to every registered callback, so the
    teardown of any remote link aborted the TX of every rpmsg tty in the
    system, including devices whose own link was up and devices whose ept
    had never been created.  uart_xmitchars_done() clears xfer->length and
    xfer->nlength while leaving xfer->nbuffer stale, and
    uart_rpmsg_dmasend() snapshots the transfer size once into total but
    re-reads xfer->length on every iteration.  A dmasend parked in
    rpmsg_wait() or rpmsg_get_tx_payload_buffer() therefore resumes with a
    stale total against a zeroed length, takes the wrapped branch, and
    memcpys from xfer->nbuffer, which is NULL for a non-wrapping transfer.
    ASan reports SEGV on address 0 in uart_rpmsg_dmasend().
    
    Restrict the abort to the rdev that actually owns the endpoint, and
    take dev->lock across it: dmasend, dmatxavail and ept_cb all touch
    dev->dmatx under that lock, and this callback was the only path that
    did not.  rpmsg_destroy_ept() stays outside the critical section
    because it can block.
    
    This closes the cross-CPU window.  A dmasend re-entered on the same
    thread through the recursive rpmsg_wait() dispatch still observes the
    mutation and needs dmasend to work off a descriptor snapshot; that is
    left to a separate change.
    
    Signed-off-by: wangyongrong <[email protected]>
    Signed-off-by: Bowen Wang <[email protected]>
---
 drivers/serial/uart_rpmsg.c | 9 ++++++---
 1 file changed, 6 insertions(+), 3 deletions(-)

diff --git a/drivers/serial/uart_rpmsg.c b/drivers/serial/uart_rpmsg.c
index d2fcb0da4fc..e8e4a4873ac 100644
--- a/drivers/serial/uart_rpmsg.c
+++ b/drivers/serial/uart_rpmsg.c
@@ -477,6 +477,7 @@ static void uart_rpmsg_device_destroy(FAR struct 
rpmsg_device *rdev,
 {
   FAR struct uart_dev_s *dev = priv_;
   FAR struct uart_rpmsg_priv_s *priv = dev->priv;
+  irqstate_t flags;
 
   if (priv->ept.priv != NULL &&
       strcmp(priv->cpuname, rpmsg_get_cpuname(rdev)) == 0)
@@ -492,10 +493,12 @@ static void uart_rpmsg_device_destroy(FAR struct 
rpmsg_device *rdev,
       priv->ackpos   = 0;
       rpmsg_destroy_ept(&priv->ept);
       uart_rpmsg_post(&priv->sendsem);
-    }
 
-  dev->dmatx.nbytes = dev->dmatx.length + dev->dmatx.nlength;
-  uart_xmitchars_done(dev);
+      flags = uart_spinlock(dev, true);
+      dev->dmatx.nbytes = dev->dmatx.length + dev->dmatx.nlength;
+      uart_xmitchars_done(dev);
+      uart_spinunlock(dev, true, flags);
+    }
 }
 
 static int uart_rpmsg_ept_cb(FAR struct rpmsg_endpoint *ept, FAR void *data,

Reply via email to