From: Simon Horman <horms@kernel.org>
To: Mihai Moldovan <ionic@ionic.de>
Cc: linux-arm-msm@vger.kernel.org,
Manivannan Sadhasivam <mani@kernel.org>,
Denis Kenzior <denkenz@gmail.com>,
Eric Dumazet <edumazet@google.com>,
Kuniyuki Iwashima <kuniyu@google.com>,
Paolo Abeni <pabeni@redhat.com>,
Willem de Bruijn <willemb@google.com>,
"David S . Miller" <davem@davemloft.net>,
Jakub Kicinski <kuba@kernel.org>,
linux-kernel@vger.kernel.org, netdev@vger.kernel.org
Subject: Re: [PATCH v3 04/11] net: qrtr: support identical node ids
Date: Thu, 24 Jul 2025 14:08:36 +0100 [thread overview]
Message-ID: <20250724130836.GL1150792@horms.kernel.org> (raw)
In-Reply-To: <8fc53fad3065a9860e3f44cf8853494dd6eb6b47.1753312999.git.ionic@ionic.de>
On Thu, Jul 24, 2025 at 01:24:01AM +0200, Mihai Moldovan wrote:
> From: Denis Kenzior <denkenz@gmail.com>
>
> Add support for tracking multiple endpoints that may have conflicting
> node identifiers. This is achieved by using both the node and endpoint
> identifiers as the key inside the radix_tree data structure.
>
> For backward compatibility with existing clients, the previous key
> schema (node identifier only) is preserved. However, this schema will
> only support the first endpoint/node combination. This is acceptable
> for legacy clients as support for multiple endpoints with conflicting
> node identifiers was not previously possible.
>
> Signed-off-by: Denis Kenzior <denkenz@gmail.com>
> Reviewed-by: Marcel Holtmann <marcel@holtmann.org>
> Reviewed-by: Andy Gross <agross@kernel.org>
> Signed-off-by: Mihai Moldovan <ionic@ionic.de>
...
> diff --git a/net/qrtr/af_qrtr.c b/net/qrtr/af_qrtr.c
...
> @@ -465,19 +466,36 @@ static struct qrtr_node *qrtr_node_lookup(unsigned int nid)
> *
> * This is mostly useful for automatic node id assignment, based on
> * the source id in the incoming packet.
> + *
> + * Return: 0 on success; negative error code on failure
> */
> -static void qrtr_node_assign(struct qrtr_node *node, unsigned int nid)
> +static int qrtr_node_assign(struct qrtr_node *node, unsigned int nid)
> {
> unsigned long flags;
> + unsigned long key;
>
> if (nid == QRTR_EP_NID_AUTO)
> - return;
> + return 0;
>
> spin_lock_irqsave(&qrtr_nodes_lock, flags);
> - radix_tree_insert(&qrtr_nodes, nid, node);
> +
> + if (node->ep->id > QRTR_INDEX_HALF_UNSIGNED_MAX ||
> + nid > QRTR_INDEX_HALF_UNSIGNED_MAX)
> + return -EINVAL;
Hi Mihai, Denis, all,
This will leak holding qrtr_nodes_lock.
Flagged by Smatch.
> +
> + /* Always insert with the endpoint_id + node_id */
> + key = ((unsigned long)(node->ep->id) << QRTR_INDEX_HALF_BITS) |
> + ((unsigned long)(nid) & QRTR_INDEX_HALF_UNSIGNED_MAX);
> + radix_tree_insert(&qrtr_nodes, key, node);
> +
> + if (!radix_tree_lookup(&qrtr_nodes, nid))
> + radix_tree_insert(&qrtr_nodes, nid, node);
> +
> if (node->nid == QRTR_EP_NID_AUTO)
> node->nid = nid;
> spin_unlock_irqrestore(&qrtr_nodes_lock, flags);
> +
> + return 0;
> }
>
> /**
> @@ -571,14 +589,18 @@ int qrtr_endpoint_post(struct qrtr_endpoint *ep, const void *data, size_t len)
>
> skb_put_data(skb, data + hdrlen, size);
When declared, ret is assigned the value -EINVAL.
And that is still the value of ret if this line is reached.
>
> - qrtr_node_assign(node, cb->src_node);
> + ret = qrtr_node_assign(node, cb->src_node);
> + if (ret)
> + goto err;
With this patch, if we get to this line, ret is 0.
Whereas before this patch it was -EINVAL.
>
> if (cb->type == QRTR_TYPE_NEW_SERVER) {
> /* Remote node endpoint can bridge other distant nodes */
> const struct qrtr_ctrl_pkt *pkt;
>
> pkt = data + hdrlen;
> - qrtr_node_assign(node, le32_to_cpu(pkt->server.node));
> + ret = qrtr_node_assign(node, le32_to_cpu(pkt->server.node));
> + if (ret)
> + goto err;
> }
>
> if (cb->type == QRTR_TYPE_RESUME_TX) {
The next portion of this function looks like this:
ret = qrtr_tx_resume(node, skb);
if (ret)
goto err;
} else {
ipc = qrtr_port_lookup(cb->dst_port);
if (!ipc)
goto err;
If we get to the line above, then the function will jump to err,
free skb, and return ret.
But ret is now 0, whereas before this patch it was -EINVAL.
This seems both to be an unintentional side effect of this patch,
and incorrect.
Also flagged by Smatch.
...
next prev parent reply other threads:[~2025-07-24 13:08 UTC|newest]
Thread overview: 21+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-07-23 23:23 [PATCH v3 00/11] QRTR Multi-endpoint support Mihai Moldovan
2025-07-23 23:23 ` [PATCH v3 01/11] net: qrtr: ns: validate msglen before ctrl_pkt use Mihai Moldovan
2025-07-23 23:23 ` [PATCH v3 02/11] net: qrtr: allocate and track endpoint ids Mihai Moldovan
2025-07-23 23:24 ` [PATCH v3 03/11] net: qrtr: fit node ID + port number combination into unsigned long Mihai Moldovan
2025-07-23 23:24 ` [PATCH v3 04/11] net: qrtr: support identical node ids Mihai Moldovan
2025-07-24 13:05 ` Jakub Kicinski
2025-07-24 13:08 ` Simon Horman [this message]
2025-07-27 13:09 ` Mihai Moldovan
2025-07-27 14:40 ` Simon Horman
2025-07-27 17:33 ` Mihai Moldovan
2025-07-28 10:51 ` Simon Horman
2025-08-01 17:25 ` Dan Carpenter
2025-08-04 9:55 ` Simon Horman
2025-08-04 10:19 ` Dan Carpenter
2025-07-23 23:24 ` [PATCH v3 05/11] net: qrtr: Report sender endpoint in aux data Mihai Moldovan
2025-07-23 23:24 ` [PATCH v3 06/11] net: qrtr: Report endpoint for locally generated messages Mihai Moldovan
2025-07-23 23:24 ` [PATCH v3 07/11] net: qrtr: Allow sendmsg to target an endpoint Mihai Moldovan
2025-07-23 23:24 ` [PATCH v3 08/11] net: qrtr: allow socket endpoint binding Mihai Moldovan
2025-07-23 23:24 ` [PATCH v3 09/11] net: qrtr: Drop remote {NEW|DEL}_LOOKUP messages Mihai Moldovan
2025-07-23 23:24 ` [PATCH v3 10/11] net: qrtr: ns: support multiple endpoints Mihai Moldovan
2025-07-23 23:24 ` [PATCH v3 11/11] net: qrtr: mhi: Report endpoint id in sysfs Mihai Moldovan
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=20250724130836.GL1150792@horms.kernel.org \
--to=horms@kernel.org \
--cc=davem@davemloft.net \
--cc=denkenz@gmail.com \
--cc=edumazet@google.com \
--cc=ionic@ionic.de \
--cc=kuba@kernel.org \
--cc=kuniyu@google.com \
--cc=linux-arm-msm@vger.kernel.org \
--cc=linux-kernel@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
all inboxes | Powered by JetHome®