Netdev List
 help / color / mirror / Atom feed
From: netdev-bot+sashiko@kernel.org
To: gabin278@gmail.com
Cc: mani@kernel.org, davem@davemloft.net, edumazet@kernel.org,
	kuba@kernel.org, pabeni@redhat.com, willemb@google.com,
	horms@kernel.org, andersson@kernel.org, netdev@vger.kernel.org,
	linux-arm-msm@vger.kernel.org
Subject: Re: [PATCH net v2] net: qrtr: smd: hold packets that arrive before probe has finished
Date: Sat, 05 Dec 2026 21:54:50 +0000	[thread overview]
Message-ID: <179650769062.3148.8280707500727880191@kernel.org> (raw)
In-Reply-To: <20261204210624.535124-1-gabin278@gmail.com>

Thank you for your contribution! Sashiko AI review found 2 potential
issue(s) to consider.

Critical: 0 · High: 0 (1) · Medium: 1 · Low: 1

If you believe none of the issues are legitimate, please reply to each
issue of Medium severity or higher and explain why the AI is wrong.
If any of them are legitimate and you plan to respin, please let patchwork
know by including "pw-bot: cr" as a separate line at the end of your reply
(one such reply per series is enough).

- [Medium] On SMD, this patch adds a way to lose a packet permanently,
  and that packet can be the remote's HELLO.
- [Low] The posted/dropped counts that qcom_smd_qrtr_post_held() reports
  are wrong.

Pre-existing issues:
- [High] This problem wasn't introduced by this patch, but there is a
  NULL dereference or use-after-free in the unbind window.

--

net: qrtr: smd: hold packets that arrive before probe has finished

Packets can arrive on the IPCRTR channel before qcom_smd_qrtr_probe() has
set the driver data. This patch keeps those packets in a skb queue managed
by devres, with a cap of 32. Once the endpoint is registered, probe posts
the held packets and then publishes the driver data, both under one global
spinlock.

> diff --git a/net/qrtr/smd.c b/net/qrtr/smd.c
> index 8b30b8275a2d9..f7b1fa340b790 100644
> --- a/net/qrtr/smd.c
> +++ b/net/qrtr/smd.c

[ ... ]

> @@ -36,6 +56,100 @@ static int qcom_smd_qrtr_callback(struct rpmsg_device *rpdev,
>  	return rc;
>  }
>  
> +static int qcom_smd_qrtr_hold(struct rpmsg_device *rpdev, void *data, int len)
> +{

[ ... ]

> +	skb = alloc_skb(len, GFP_ATOMIC);
> +	if (!skb) {
> +		rc = -ENOMEM;
> +		goto out;
> +	}
> +	skb_put_data(skb, data, len);
> +	__skb_queue_tail(held, skb);
> +
> +out:
> +	spin_unlock_irqrestore(&qrtr_smd_held_lock, flags);
> +
> +	return rc;
> +}
> +
> +/* Post the packets held during probe, then publish @qdev so the callback
> + * posts directly. Both happen under the lock, so held packets are posted
> + * before any packet that arrives later.
> + */
> +static void qcom_smd_qrtr_post_held(struct rpmsg_device *rpdev,
> +				    struct qrtr_smd_dev *qdev,
> +				    unsigned int *posted, unsigned int *dropped)
> +{

[ ... ]

> +	held = devres_find(&rpdev->dev, qcom_smd_qrtr_held_release, NULL, NULL);
> +	if (held) {
> +		while ((skb = __skb_dequeue(held))) {
> +			rc = qcom_smd_qrtr_post(qdev, skb->data, skb->len);
> +			if (rc) {
> +				kfree_skb(skb);
> +				(*dropped)++;

[Severity: Medium]
On SMD, can this lose a held packet for good? That packet could be the
remote's HELLO.

Before this patch, a packet that arrived before probe finished got
-EAGAIN. qcom_smd_channel_recv_single() in drivers/rpmsg/qcom_smd.c then
left it in the FIFO:

	ret = ept->cb(ept->rpdev, ptr, len, ept->priv, RPMSG_ADDR_ANY);
	if (ret < 0)
		return ret;

	/* Only forward the tail if the client consumed the data */
	qcom_smd_channel_advance(channel, len);

SMD would read the packet again later. The same happened when
qrtr_endpoint_post() itself failed with -ENOMEM.

Now qcom_smd_qrtr_hold() copies the packet and returns 0, so SMD moves
the tail past it.

In this loop, qrtr_endpoint_post() allocates with
__netdev_alloc_skb(NULL, len, GFP_ATOMIC | __GFP_NOWARN) while
qrtr_smd_held_lock is held with IRQs off. If that allocation fails, it
returns -ENOMEM, the skb is freed here, and nothing retries it.

The commit message says a held packet that can't be passed on "is dropped
with a warning". Before this patch, though, the SMD transport could not
lose a packet this way, and the commit message itself says that losing the
HELLO crashes the modem.

Could the SMD retry behaviour be kept for this case?

> +			} else {
> +				consume_skb(skb);
> +				(*posted)++;

[Severity: Low]
Are these posted/dropped counts accurate? qcom_smd_qrtr_post() turns
every -EINVAL from qrtr_endpoint_post() into 0:

	rc = qrtr_endpoint_post(&qdev->ep, data, len);
	if (rc == -EINVAL) {
		dev_err(qdev->dev, "invalid ipcrouter packet\n");
		/* return 0 to let smd drop the packet */
		rc = 0;
	}

qrtr_endpoint_post() returns -EINVAL from its err: path after freeing the
skb. It takes that path for a malformed header, when no socket is bound to
the destination port, and when sock_queue_rcv_skb() fails:

	ipc = qrtr_port_lookup(cb->dst_port);
	if (!ipc)
		goto err;
	...
err:
	kfree_skb(skb);
	return -EINVAL;

This loop counts those discarded packets as posted. The new dev_warn() in
qcom_smd_qrtr_probe() therefore counts only -ENOMEM drops, and the dev_dbg()
summary can report a lost HELLO as posted.

The "return 0 to let smd drop the packet" comment also no longer fits this
caller, because nothing is returned to SMD for held packets.

> +			}
> +		}
> +	}
> +
> +	dev_set_drvdata(&rpdev->dev, qdev);
> +
> +	spin_unlock_irqrestore(&qrtr_smd_held_lock, flags);
> +}
> +
> +/* from smd to qrtr */
> +static int qcom_smd_qrtr_callback(struct rpmsg_device *rpdev,
> +				  void *data, int len, void *priv, u32 addr)
> +{
> +	struct qrtr_smd_dev *qdev = dev_get_drvdata(&rpdev->dev);
> +
> +	if (!qdev)
> +		return qcom_smd_qrtr_hold(rpdev, data, len);
> +
> +	return qcom_smd_qrtr_post(qdev, data, len);
> +}

[Severity: High]
This is a pre-existing issue, not one introduced by this patch. Can this
callback run against a released qrtr node during unbind?

rpmsg_dev_remove() calls the driver's remove() before it destroys the
endpoint:

	if (rpdrv->remove)
		rpdrv->remove(rpdev);

	if (rpdev->ept)
		rpmsg_destroy_ept(rpdev->ept);

qcom_smd_qrtr_remove() unregisters the endpoint before it clears the
driver data:

	qrtr_endpoint_unregister(&qdev->ep);

	dev_set_drvdata(&rpdev->dev, NULL);

qrtr_endpoint_unregister() ends with qrtr_node_release(node), which can
free the node, and then sets ep->node = NULL. A packet that arrives in
this window still sees a non-NULL qdev here and goes through:

qcom_smd_qrtr_callback()
  qcom_smd_qrtr_post()
    qrtr_endpoint_post()
      qrtr_node_assign(ep->node, ...)
        radix_tree_insert(&qrtr_nodes, nid, node);

With a NULL node, this oopses on node->nid. With a freed node, a dangling
pointer ends up in the global qrtr_nodes radix tree.

The notes below the commit message mention this ordering problem and
promise a separate fix. Could that fix use the new qrtr_smd_held_lock to
order clearing the driver data against the callback, before
qrtr_endpoint_unregister() is called?

-- 
Sashiko AI review · https://netdev-ai.bots.linux.dev/sashiko/#/patchset/20261204210624.535124-1-gabin278%40gmail.com

      reply	other threads:[~2026-12-05 21:54 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-12-04 21:06 [PATCH net v2] net: qrtr: smd: hold packets that arrive before probe has finished Andrey Derkach
2026-12-05 21:54 ` netdev-bot+sashiko [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=179650769062.3148.8280707500727880191@kernel.org \
    --to=netdev-bot+sashiko@kernel.org \
    --cc=andersson@kernel.org \
    --cc=davem@davemloft.net \
    --cc=edumazet@kernel.org \
    --cc=gabin278@gmail.com \
    --cc=horms@kernel.org \
    --cc=kuba@kernel.org \
    --cc=linux-arm-msm@vger.kernel.org \
    --cc=mani@kernel.org \
    --cc=netdev@vger.kernel.org \
    --cc=pabeni@redhat.com \
    --cc=willemb@google.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox