From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=100.103.45.18 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796507692; b=1rOMMJl05rIOculUqZl0R40JLWIFhav32CHGb0kKsI5tlnI4FUjhIGnyqzNtLSSjvbfC YaFf7OcPk0+w1VaH//a9pAIGsRRzoJz3Ewa5b9ia3Zx+nruWyZwv7PRFsHaDPII6tKcI3 CDGOyRDhP4yfpXNFBPExEtWxIhCwIj2rS9L9qxCyH/NSlmPOEvJvLSjsZ3qlUkukRUnC4 V9zh8jY8UOvIF+c1MtGONIslLBU4hj3q9o/rBexHTNX1F2omgUKNPmVVwy3lw3zzBUOIG YrwcGVrlAKoHhG81vBGpBtJmy/9x7CQ1CrorUUriwuXDXbAsrmW1Y95a9suAh1+8qKA== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796507692; h=Received:DKIM-Signature:Subject:From:To:Cc:Date:Message-ID: In-Reply-To:References:X-sashiko-severity:Content-Type: Content-Transfer-Encoding:MIME-Version; bh=SMwxIJ4qcml5aZMsuA7ffL7Eb5o2IN4AQzek4247jr8=; b=DfEdk8ckRXlCKieXm+p3tr0fLQZQn7A0cB81yVs2I5tvczG6Ymig0ltp2RD+s2c7f8Xl MNyujZB+WThXrewNsMuAsZecaSIfaca7ftE64bUB3C3qub4IR+1Yuoc2q9snzivdwkp1d ykM0PVqwuIhErCPWNA87Y5TpcSgy5EywdytvMht4itMLTZ9+PyZxhM/x0yScjuRrJOFsa LuAMquDsKuK8ybfPohp90GZT8ZNDhPCI07uU96XBOpbJSTnaGIcPiIVjByjCWyoQEK6bz 1ofUN15ypiVOx4Q4pkC37DOJrV3LlFM63aR8gSCQQdm8sITA6vjurFsiA5nqsqsKfHQ== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b=f+qvWwnO; arc=none smtp.remote-ip=100.103.45.18 Received: from smtp.kernel.org (quasi.space.kernel.org [100.103.45.18]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (prime256v1)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id EFB0C606A31F; Sat, 5 Dec 2026 21:54:51 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b=f+qvWwnO Received: by smtp.kernel.org (Postfix) with ESMTPSA id 2270E1F00A07; Sat, 5 Dec 2026 21:54:51 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org; s=k20260515; t=1796507691; bh=SMwxIJ4qcml5aZMsuA7ffL7Eb5o2IN4AQzek4247jr8=; h=Subject:From:To:Cc:Date:In-Reply-To:References; b=f+qvWwnOo2IpnrKp+qM6Y4m6unPCW4WMm3dfMQbmYe7t8HUMtRMO7x8InwlIIvk6R tE+PnvOvgzvLQShZEtVsb6xoP7k1MaNNpg33g7iflClVxwy4caoJWS8q6VV53iG6fQ A6IAqP84VcJbv79nBHnz5ogta2qMUJc6JSJOwsxlpRqFFbzHFejm+qLz+f6DiThZPA rQvim7sIg0rCvKcITV2XY4eZqGFP74ISMLZWGQWUVha94gS+KpAfGrhAaEYCEDl1LS ZlD6kUWkqAlbshefWrRrpWfUvLBQOHQckMWbMp6hkRrZJH/dvImL5sWtgU1SEDz+us JxgMqgQi8U3Gw== Subject: Re: [PATCH net v2] net: qrtr: smd: hold packets that arrive before probe has finished 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 Date: Sat, 05 Dec 2026 21:54:50 +0000 Message-ID: <179650769062.3148.8280707500727880191@kernel.org> In-Reply-To: <20261204210624.535124-1-gabin278@gmail.com> References: <20261204210624.535124-1-gabin278@gmail.com> X-sashiko-severity: Medium Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: 8bit X-Mailing-List: netdev@vger.kernel.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list MIME-Version: 1.0 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