AI Trajectory


Trajectory: (Expand/Collapse All)
Seq Timestamp Type Name Duration
0/0 2026/09/15 06:23 flow patch-triage
8m Args:
null

Results:
{
  "EnableConfigs": [
    "QRTR",
    "QRTR_TUN"
  ],
  "FocusSymbols": [
    "qrtr_setsockopt",
    "qrtr_getsockopt",
    "qrtr_msg_get_endpoint",
    "qrtr_sendmsg",
    "qrtr_recvmsg",
    "qrtr_endpoint_post",
    "qrtr_endpoint_register",
    "qrtr_ns_worker"
  ],
  "KMSANReasoning": "The patch series introduces endpoint routing and management to the Qualcomm IPC Router (QRTR) subsystem, adding setsockopt/getsockopt options (QRTR_REPORT_ENDPOINT, QRTR_BIND_ENDPOINT), CMSG endpoint support (QRTR_ENDPOINT), hierarchical radix trees for endpoint node lookups, and endpoint tracking in the nameservice daemon (ns.c).\n\nKMSAN vs KASAN applicability analysis:\n1. User-space copies \u0026 Info-leaks:\n   - In qrtr_getsockopt(), 'val' is an unsigned int (sizeof(int)) explicitly assigned via test_bit() or READ_ONCE(), and len is fixed to sizeof(int) before copy_to_user(). No uninitialized structure padding or uninitialized memory is exposed.\n   - In qrtr_setsockopt(), 'val' is initialized to 0 upon declaration, avoiding uninitialized memory use if optlen \u003c sizeof(val).\n   - In qrtr_recvmsg(), put_cmsg() is called with cb-\u003eendpoint_id (u32). The skb-\u003ecb endpoint_id is explicitly set on all packet ingress paths (qrtr_endpoint_post and qrtr_local_enqueue).\n   - In mhi.c, endpoint_show() formats ep.id into sysfs via sprintf().\n2. Uninitialized struct fields and buffers:\n   - In ns.c, all dynamically allocated structures (struct qrtr_ns_endpoint, struct qrtr_node, struct qrtr_server) are allocated with kzalloc_obj(). All control packets (struct qrtr_ctrl_pkt) transmitted by ns.c are explicitly cleared with memset(\u0026pkt, 0, sizeof(pkt)).\n   - In af_qrtr.c, helper0 is static in BSS, node is allocated with kzalloc, and ep-\u003ehelper in struct qrtr_endpoint is properly initialized.\n   - qrtr_msg_get_endpoint() initializes endpoint_id to 0 and strictly checks cmsg lengths before reading CMSG_DATA.\n3. Memory safety risks:\n   - The modifications alter radix tree hierarchies and node acquisition/release lifetimes (e.g., in __qrtr_node_release, qrtr_endpoint_register, qrtr_endpoint_unregister), which primarily risk use-after-free, NULL pointer dereferences, or lock-related deadlocks. These bugs are properly covered by KASAN and LOCKDEP.\n\nNo uninitialized memory hazards or info-leak risks are introduced or exposed. Therefore, a dedicated KMSAN fuzzing session is not warranted.",
  "NeedsKMSAN": false,
  "Reasoning": "The patch series implements endpoint-based isolation and tracking for Qualcomm IPC Router (AF_QIPCRTR) sockets. It introduces SOL_QRTR socket options (QRTR_REPORT_ENDPOINT, QRTR_BIND_ENDPOINT), ancillary control messages (QRTR_ENDPOINT) for sendmsg and recvmsg, per-endpoint radix-tree node management, and multi-endpoint tracking in the in-kernel name service (ns.c). QRTR sockets and the /dev/qrtr-tun device are fully accessible in standard QEMU virtualized environments without specialized hardware. Fuzzing is warranted to test new setsockopt/getsockopt logic, cmsg handling, and radix-tree/xarray concurrency and lifecycle management.",
  "WorthFuzzing": true
}

1/1 2026/09/15 06:23 action read-patch-diff
0m Args:
null

Results:
{
  "PatchDiff": "commit e9367e40a1c817184c46735d76d64ca5edc6c819\nAuthor: syz-cluster \u003ctriage@syzkaller.com\u003e\nDate:   Tue Sep 15 06:23:20 2026 +0000\n\n    syz-cluster: applied patch under review\n\ndiff --git a/include/linux/socket.h b/include/linux/socket.h\nindex 5a5eb12501032..d4e2ba3bd6b39 100644\n--- a/include/linux/socket.h\n+++ b/include/linux/socket.h\n@@ -400,6 +400,7 @@ struct ucred {\n #define SOL_MCTP\t285\n #define SOL_SMC\t\t286\n #define SOL_VSOCK\t287\n+#define SOL_QRTR\t288\n \n /* IPX options */\n #define IPX_TYPE\t1\ndiff --git a/include/uapi/linux/qrtr.h b/include/uapi/linux/qrtr.h\nindex f7e2fb3d752b5..0a8667b049c3d 100644\n--- a/include/uapi/linux/qrtr.h\n+++ b/include/uapi/linux/qrtr.h\n@@ -46,4 +46,11 @@ struct qrtr_ctrl_pkt {\n \t};\n } __packed;\n \n+/* setsockopt / getsockopt */\n+#define QRTR_REPORT_ENDPOINT 1\n+#define QRTR_BIND_ENDPOINT 2\n+\n+/* CMSG */\n+#define QRTR_ENDPOINT 1\n+\n #endif /* _LINUX_QRTR_H */\ndiff --git a/net/qrtr/af_qrtr.c b/net/qrtr/af_qrtr.c\nindex a30fa56e6aa31..7c50d32b11015 100644\n--- a/net/qrtr/af_qrtr.c\n+++ b/net/qrtr/af_qrtr.c\n@@ -22,9 +22,14 @@\n #define QRTR_MAX_EPH_SOCKET 0x7fff\n #define QRTR_EPH_PORT_RANGE \\\n \t\tXA_LIMIT(QRTR_MIN_EPH_SOCKET, QRTR_MAX_EPH_SOCKET)\n+#define QRTR_ENDPOINT_RANGE XA_LIMIT(qrtr_local_nid + 1, INT_MAX)\n \n #define QRTR_PORT_CTRL_LEGACY 0xffff\n \n+enum {\n+\tQRTR_F_REPORT_ENDPOINT,\n+};\n+\n /**\n  * struct qrtr_hdr_v1 - (I|R)PCrouter packet header version 1\n  * @version: protocol version\n@@ -78,6 +83,7 @@ struct qrtr_cb {\n \tu32 src_port;\n \tu32 dst_node;\n \tu32 dst_port;\n+\tu32 endpoint_id;\n \n \tu8 type;\n \tu8 confirm_rx;\n@@ -91,6 +97,8 @@ struct qrtr_sock {\n \tstruct sock sk;\n \tstruct sockaddr_qrtr us;\n \tstruct sockaddr_qrtr peer;\n+\tunsigned long flags;\n+\tu32 bound_endpoint;\n };\n \n static inline struct qrtr_sock *qrtr_sk(struct sock *sk)\n@@ -99,6 +107,43 @@ static inline struct qrtr_sock *qrtr_sk(struct sock *sk)\n \treturn container_of(sk, struct qrtr_sock, sk);\n }\n \n+void qrtr_sock_set_report_endpoint(struct sock *sk)\n+{\n+\tstruct qrtr_sock *ipc = qrtr_sk(sk);\n+\n+\tassign_bit(QRTR_F_REPORT_ENDPOINT, \u0026ipc-\u003eflags, 1);\n+}\n+\n+int qrtr_msg_get_endpoint(struct msghdr *msg, u32 *out_endpoint_id)\n+{\n+\tstruct cmsghdr *cmsg;\n+\tu32 endpoint_id = 0;\n+\n+\tfor_each_cmsghdr(cmsg, msg) {\n+\t\tif (!CMSG_OK(msg, cmsg))\n+\t\t\treturn -EINVAL;\n+\n+\t\tif (cmsg-\u003ecmsg_level != SOL_QRTR)\n+\t\t\tcontinue;\n+\n+\t\tif (cmsg-\u003ecmsg_type != QRTR_ENDPOINT)\n+\t\t\treturn -EINVAL;\n+\n+\t\tif (cmsg-\u003ecmsg_len \u003c CMSG_LEN(sizeof(u32)))\n+\t\t\treturn -EINVAL;\n+\n+\t\t/* Endpoint ids start at 1 */\n+\t\tendpoint_id = *(u32 *)CMSG_DATA(cmsg);\n+\t\tif (!endpoint_id)\n+\t\t\treturn -EINVAL;\n+\t}\n+\n+\tif (out_endpoint_id)\n+\t\t*out_endpoint_id = endpoint_id;\n+\n+\treturn 0;\n+}\n+\n static unsigned int qrtr_local_nid = 1;\n \n /* for node ids */\n@@ -109,9 +154,37 @@ static LIST_HEAD(qrtr_all_nodes);\n /* lock for qrtr_all_nodes and node reference */\n static DEFINE_MUTEX(qrtr_node_lock);\n \n+/* endpoint id allocation management */\n+static DEFINE_XARRAY_ALLOC(qrtr_endpoints);\n+static u32 next_endpoint_id;\n+\n /* local port allocation management */\n static DEFINE_XARRAY_ALLOC(qrtr_ports);\n \n+/* The xarray API uses fixed unsigned long keys and we will have to make\n+ * do with that.\n+ * These keys are often a combination of node IDs and port numbers or\n+ * endpoint IDs and node IDs (all currently u32).\n+ * Using the high 32 bits for the node/endpoint ID and the low 32 bits for the\n+ * port number/node ID will work fine to create keys on platforms where\n+ * unsigned long is 64 bits wide, but obviously is not be possible on\n+ * platforms where unsigned long is smaller.\n+ * Virtually split up unsigned long in half and assign the upper bits to\n+ * node/endpoint IDs and the lower bits to the port number/node ID, however\n+ * big that may be.\n+ */\n+#define QRTR_XARRAY_INDEX_BITS  (8 /* CHAR_BIT */ * sizeof(unsigned long))\n+#define QRTR_INDEX_HALF_BITS (QRTR_XARRAY_INDEX_BITS \u003e\u003e 1)\n+\n+#define QRTR_INDEX_HALF_UNSIGNED_MAX ((~(unsigned long)(0)) \u003e\u003e QRTR_INDEX_HALF_BITS)\n+#define QRTR_INDEX_HALF_UNSIGNED_MIN ((unsigned long)(0))\n+\n+#define QRTR_INDEX_HALF_SIGNED_MAX ((long)(QRTR_INDEX_HALF_UNSIGNED_MAX) \u003e\u003e 1)\n+#define QRTR_INDEX_HALF_SIGNED_MIN ((long)(-1) - QRTR_INDEX_HALF_SIGNED_MAX)\n+\n+/* endpoint not defined, i.e. endpoint 0 */\n+static struct qrtr_node_lookup_helper helper0;\n+\n /**\n  * struct qrtr_node - endpoint node\n  * @ep_lock: lock for endpoint management and callbacks\n@@ -152,9 +225,11 @@ struct qrtr_tx_flow {\n #define QRTR_TX_FLOW_LOW\t5\n \n static int qrtr_local_enqueue(struct qrtr_node *node, struct sk_buff *skb,\n+\t\t\t      u32 endpoint_id,\n \t\t\t      int type, struct sockaddr_qrtr *from,\n \t\t\t      struct sockaddr_qrtr *to);\n static int qrtr_bcast_enqueue(struct qrtr_node *node, struct sk_buff *skb,\n+\t\t\t      u32 endpoint_id,\n \t\t\t      int type, struct sockaddr_qrtr *from,\n \t\t\t      struct sockaddr_qrtr *to);\n static struct qrtr_sock *qrtr_port_lookup(int port);\n@@ -169,9 +244,11 @@ static void __qrtr_node_release(struct kref *kref)\n {\n \tstruct qrtr_node *node = container_of(kref, struct qrtr_node, ref);\n \tstruct radix_tree_iter iter;\n+\tstruct radix_tree_iter iter2;\n \tstruct qrtr_tx_flow *flow;\n \tunsigned long flags;\n \tvoid __rcu **slot;\n+\tvoid __rcu **slot2;\n \tunsigned long index;\n \n \tspin_lock_irqsave(\u0026qrtr_nodes_lock, flags);\n@@ -179,8 +256,18 @@ static void __qrtr_node_release(struct kref *kref)\n \t * multiple entries pointing to our released node, delete them all.\n \t */\n \tradix_tree_for_each_slot(slot, \u0026qrtr_nodes, \u0026iter, 0) {\n-\t\tif (*slot == node)\n+\t\tstruct qrtr_node_lookup_helper *helper = *slot;\n+\n+\t\tif (!helper)\n+\t\t\tcontinue;\n+\t\tradix_tree_for_each_slot(slot2, \u0026helper-\u003enodes, \u0026iter2, 0) {\n+\t\t\tif (*slot2 == node)\n+\t\t\t\tradix_tree_iter_delete(\u0026helper-\u003enodes, \u0026iter2, slot2);\n+\t\t}\n+\t\tif (helper != \u0026helper0 \u0026\u0026 radix_tree_empty(\u0026helper-\u003enodes)) {\n \t\t\tradix_tree_iter_delete(\u0026qrtr_nodes, \u0026iter, slot);\n+\t\t\thelper-\u003eadded = 0;\n+\t\t}\n \t}\n \tspin_unlock_irqrestore(\u0026qrtr_nodes_lock, flags);\n \n@@ -216,16 +303,23 @@ static void qrtr_node_release(struct qrtr_node *node)\n  * qrtr_tx_resume() - reset flow control counter\n  * @node:\tqrtr_node that the QRTR_TYPE_RESUME_TX packet arrived on\n  * @skb:\tresume_tx packet\n+ *\n+ * Return: 0 on success; negative error code on failure\n  */\n-static void qrtr_tx_resume(struct qrtr_node *node, struct sk_buff *skb)\n+static int qrtr_tx_resume(struct qrtr_node *node, struct sk_buff *skb)\n {\n \tstruct qrtr_ctrl_pkt *pkt = (struct qrtr_ctrl_pkt *)skb-\u003edata;\n \tu64 remote_node = le32_to_cpu(pkt-\u003eclient.node);\n \tu32 remote_port = le32_to_cpu(pkt-\u003eclient.port);\n \tstruct qrtr_tx_flow *flow;\n-\tunsigned long key;\n+\tunsigned long key = 0;\n+\n+\t/* Don't check node/port for the valid range, use only low\n+\t * 16 bits on 32-bit architectures.\n+\t */\n \n-\tkey = remote_node \u003c\u003c 32 | remote_port;\n+\tkey = ((unsigned long)(remote_node) \u003c\u003c QRTR_INDEX_HALF_BITS) |\n+\t      ((unsigned long)(remote_port) \u0026 QRTR_INDEX_HALF_UNSIGNED_MAX);\n \n \tflow = xa_load(\u0026node-\u003eqrtr_tx_flow, key);\n \tif (flow) {\n@@ -236,6 +330,8 @@ static void qrtr_tx_resume(struct qrtr_node *node, struct sk_buff *skb)\n \t}\n \n \tconsume_skb(skb);\n+\n+\treturn 0;\n }\n \n /**\n@@ -256,11 +352,18 @@ static void qrtr_tx_resume(struct qrtr_node *node, struct sk_buff *skb)\n static int qrtr_tx_wait(struct qrtr_node *node, int dest_node, int dest_port,\n \t\t\tint type)\n {\n-\tunsigned long key = (u64)dest_node \u003c\u003c 32 | dest_port;\n+\tunsigned long key = 0;\n \tstruct qrtr_tx_flow *flow;\n \tint confirm_rx = 0;\n \tint ret;\n \n+\t/* Don't check node/port for the valid range, use only low\n+\t * 16 bits on 32-bit architectures.\n+\t */\n+\n+\tkey = ((unsigned long)(dest_node) \u003c\u003c QRTR_INDEX_HALF_BITS) |\n+\t      ((unsigned long)(dest_port) \u0026 QRTR_INDEX_HALF_UNSIGNED_MAX);\n+\n \t/* Never set confirm_rx on non-data packets */\n \tif (type != QRTR_TYPE_DATA)\n \t\treturn 0;\n@@ -317,23 +420,35 @@ static int qrtr_tx_wait(struct qrtr_node *node, int dest_node, int dest_port,\n  * message associated with the dropped confirm_rx message.\n  * Work around this by marking the flow as having a failed transmission and\n  * cause the next transmission attempt to be sent with the confirm_rx.\n+ *\n+ * Return: 0 on success; negative error code on failure\n  */\n-static void qrtr_tx_flow_failed(struct qrtr_node *node, int dest_node,\n-\t\t\t\tint dest_port)\n+static int qrtr_tx_flow_failed(struct qrtr_node *node, int dest_node,\n+\t\t\t       int dest_port)\n {\n-\tunsigned long key = (u64)dest_node \u003c\u003c 32 | dest_port;\n+\tunsigned long key = 0;\n \tstruct qrtr_tx_flow *flow;\n \n+\t/* Don't check node/port for the valid range, use only low\n+\t * 16 bits on 32-bit architectures.\n+\t */\n+\n+\tkey = ((unsigned long)(dest_node) \u003c\u003c QRTR_INDEX_HALF_BITS) |\n+\t      ((unsigned long)(dest_port) \u0026 QRTR_INDEX_HALF_UNSIGNED_MAX);\n+\n \tflow = xa_load(\u0026node-\u003eqrtr_tx_flow, key);\n \tif (flow) {\n \t\tspin_lock_irq(\u0026flow-\u003eresume_tx.lock);\n \t\tflow-\u003etx_failed = 1;\n \t\tspin_unlock_irq(\u0026flow-\u003eresume_tx.lock);\n \t}\n+\n+\treturn 0;\n }\n \n /* Pass an outgoing packet socket buffer to the endpoint driver. */\n static int qrtr_node_enqueue(struct qrtr_node *node, struct sk_buff *skb,\n+\t\t\t     u32 endpoint_id,\n \t\t\t     int type, struct sockaddr_qrtr *from,\n \t\t\t     struct sockaddr_qrtr *to)\n {\n@@ -377,7 +492,7 @@ static int qrtr_node_enqueue(struct qrtr_node *node, struct sk_buff *skb,\n \t/* Need to ensure that a subsequent message carries the otherwise lost\n \t * confirm_rx flag if we dropped this one */\n \tif (rc \u0026\u0026 confirm_rx)\n-\t\tqrtr_tx_flow_failed(node, to-\u003esq_node, to-\u003esq_port);\n+\t\trc = qrtr_tx_flow_failed(node, to-\u003esq_node, to-\u003esq_port);\n \n \treturn rc;\n }\n@@ -386,14 +501,18 @@ static int qrtr_node_enqueue(struct qrtr_node *node, struct sk_buff *skb,\n  *\n  * callers must release with qrtr_node_release()\n  */\n-static struct qrtr_node *qrtr_node_lookup(unsigned int nid)\n+static struct qrtr_node *qrtr_node_lookup(unsigned int endpoint_id,\n+\t\t\t\t\t  unsigned int nid)\n {\n-\tstruct qrtr_node *node;\n+\tstruct qrtr_node *node = NULL;\n+\tstruct qrtr_node_lookup_helper *helper = NULL;\n \tunsigned long flags;\n \n \tmutex_lock(\u0026qrtr_node_lock);\n \tspin_lock_irqsave(\u0026qrtr_nodes_lock, flags);\n-\tnode = radix_tree_lookup(\u0026qrtr_nodes, nid);\n+\thelper = radix_tree_lookup(\u0026qrtr_nodes, endpoint_id);\n+\tif (helper)\n+\t\tnode = radix_tree_lookup(\u0026helper-\u003enodes, nid);\n \tnode = qrtr_node_acquire(node);\n \tspin_unlock_irqrestore(\u0026qrtr_nodes_lock, flags);\n \tmutex_unlock(\u0026qrtr_node_lock);\n@@ -405,19 +524,51 @@ static struct qrtr_node *qrtr_node_lookup(unsigned int nid)\n  *\n  * This is mostly useful for automatic node id assignment, based on\n  * the source id in the incoming packet.\n+ *\n+ * Return: 0 on success; negative error code on failure\n  */\n-static void qrtr_node_assign(struct qrtr_node *node, unsigned int nid)\n+static int qrtr_node_assign(struct qrtr_node *node, unsigned int nid)\n {\n \tunsigned long flags;\n+\tint rc = 0;\n+\tint did_insert0 = 0;\n \n \tif (nid == QRTR_EP_NID_AUTO)\n-\t\treturn;\n+\t\treturn 0;\n \n \tspin_lock_irqsave(\u0026qrtr_nodes_lock, flags);\n-\tradix_tree_insert(\u0026qrtr_nodes, nid, node);\n+\n+\tif (!radix_tree_lookup(\u0026helper0.nodes, nid)) {\n+\t\trc = radix_tree_insert(\u0026helper0.nodes, nid, node);\n+\t\tif (rc)\n+\t\t\tgoto err_lock;\n+\t\tdid_insert0 = 1;\n+\t}\n+\tif (!node-\u003eep-\u003ehelper.added) {\n+\t\tINIT_RADIX_TREE(\u0026node-\u003eep-\u003ehelper.nodes, GFP_ATOMIC);\n+\t\trc = radix_tree_insert(\u0026qrtr_nodes, node-\u003eep-\u003eid,\n+\t\t\t\t       \u0026node-\u003eep-\u003ehelper);\n+\t\tif (rc)\n+\t\t\tgoto err_insert0;\n+\t\tnode-\u003eep-\u003ehelper.added = 1;\n+\t}\n+\trc = radix_tree_insert(\u0026node-\u003eep-\u003ehelper.nodes, nid, node);\n+\tif (rc \u0026\u0026 rc != -EEXIST)\n+\t\tgoto err_insert0; // Don't revert helper insertion\n+\n \tif (node-\u003enid == QRTR_EP_NID_AUTO)\n \t\tnode-\u003enid = nid;\n \tspin_unlock_irqrestore(\u0026qrtr_nodes_lock, flags);\n+\n+\treturn 0;\n+\n+err_insert0:\n+\tif (did_insert0)\n+\t\tradix_tree_delete(\u0026helper0.nodes, nid);\n+\n+err_lock:\n+\tspin_unlock_irqrestore(\u0026qrtr_nodes_lock, flags);\n+\treturn rc;\n }\n \n /**\n@@ -439,6 +590,7 @@ int qrtr_endpoint_post(struct qrtr_endpoint *ep, const void *data, size_t len)\n \tsize_t size;\n \tunsigned int ver;\n \tsize_t hdrlen;\n+\tint ret = -EINVAL;\n \n \tif (len == 0 || len \u0026 3)\n \t\treturn -EINVAL;\n@@ -496,9 +648,16 @@ int qrtr_endpoint_post(struct qrtr_endpoint *ep, const void *data, size_t len)\n \tif (cb-\u003edst_port == QRTR_PORT_CTRL_LEGACY)\n \t\tcb-\u003edst_port = QRTR_PORT_CTRL;\n \n+\tcb-\u003eendpoint_id = ep-\u003eid;\n+\n \tif (!size || size \u003e len || len != ALIGN(size, 4) + hdrlen)\n \t\tgoto err;\n \n+\t/* Don't allow remote lookups */\n+\tif (cb-\u003etype == QRTR_TYPE_NEW_LOOKUP ||\n+\t    cb-\u003etype == QRTR_TYPE_DEL_LOOKUP)\n+\t\tgoto err;\n+\n \tif ((cb-\u003etype == QRTR_TYPE_NEW_SERVER ||\n \t     cb-\u003etype == QRTR_TYPE_RESUME_TX) \u0026\u0026\n \t    size \u003c sizeof(struct qrtr_ctrl_pkt))\n@@ -510,26 +669,39 @@ int qrtr_endpoint_post(struct qrtr_endpoint *ep, const void *data, size_t len)\n \n \tskb_put_data(skb, data + hdrlen, size);\n \n-\tqrtr_node_assign(node, cb-\u003esrc_node);\n+\tret = qrtr_node_assign(node, cb-\u003esrc_node);\n+\tif (ret)\n+\t\tgoto err;\n \n \tif (cb-\u003etype == QRTR_TYPE_NEW_SERVER) {\n \t\t/* Remote node endpoint can bridge other distant nodes */\n \t\tconst struct qrtr_ctrl_pkt *pkt;\n \n \t\tpkt = data + hdrlen;\n-\t\tqrtr_node_assign(node, le32_to_cpu(pkt-\u003eserver.node));\n+\t\tret = qrtr_node_assign(node, le32_to_cpu(pkt-\u003eserver.node));\n+\t\tif (ret)\n+\t\t\tgoto err;\n \t}\n \n \tif (cb-\u003etype == QRTR_TYPE_RESUME_TX) {\n-\t\tqrtr_tx_resume(node, skb);\n+\t\tret = qrtr_tx_resume(node, skb);\n+\t\tif (ret)\n+\t\t\tgoto err;\n \t} else {\n \t\tipc = qrtr_port_lookup(cb-\u003edst_port);\n-\t\tif (!ipc)\n+\t\tif (!ipc) {\n+\t\t\tret = -EINVAL;\n \t\t\tgoto err;\n+\t\t}\n \n-\t\tif (sock_queue_rcv_skb(\u0026ipc-\u003esk, skb)) {\n-\t\t\tqrtr_port_put(ipc);\n-\t\t\tgoto err;\n+\t\t/* Sockets bound to an endpoint only rx from that endpoint */\n+\t\tif (!ipc-\u003ebound_endpoint ||\n+\t\t    ipc-\u003ebound_endpoint == cb-\u003eendpoint_id) {\n+\t\t\tret = sock_queue_rcv_skb(\u0026ipc-\u003esk, skb);\n+\t\t\tif (ret) {\n+\t\t\t\tqrtr_port_put(ipc);\n+\t\t\t\tgoto err;\n+\t\t\t}\n \t\t}\n \n \t\tqrtr_port_put(ipc);\n@@ -539,7 +711,7 @@ int qrtr_endpoint_post(struct qrtr_endpoint *ep, const void *data, size_t len)\n \n err:\n \tkfree_skb(skb);\n-\treturn -EINVAL;\n+\treturn ret;\n \n }\n EXPORT_SYMBOL_GPL(qrtr_endpoint_post);\n@@ -581,6 +753,8 @@ static struct sk_buff *qrtr_alloc_ctrl_packet(struct qrtr_ctrl_pkt **pkt,\n int qrtr_endpoint_register(struct qrtr_endpoint *ep, unsigned int nid)\n {\n \tstruct qrtr_node *node;\n+\tu32 endpoint_id;\n+\tint rc;\n \n \tif (!ep || !ep-\u003exmit)\n \t\treturn -EINVAL;\n@@ -589,6 +763,13 @@ int qrtr_endpoint_register(struct qrtr_endpoint *ep, unsigned int nid)\n \tif (!node)\n \t\treturn -ENOMEM;\n \n+\trc = xa_alloc_cyclic(\u0026qrtr_endpoints, \u0026endpoint_id, NULL,\n+\t\t\t     QRTR_ENDPOINT_RANGE, \u0026next_endpoint_id,\n+\t\t\t     GFP_KERNEL);\n+\n+\tif (rc \u003c 0)\n+\t\tgoto free_node;\n+\n \tkref_init(\u0026node-\u003eref);\n \tmutex_init(\u0026node-\u003eep_lock);\n \tskb_queue_head_init(\u0026node-\u003erx_queue);\n@@ -598,14 +779,21 @@ int qrtr_endpoint_register(struct qrtr_endpoint *ep, unsigned int nid)\n \txa_init(\u0026node-\u003eqrtr_tx_flow);\n \tmutex_init(\u0026node-\u003eqrtr_tx_lock);\n \n-\tqrtr_node_assign(node, nid);\n+\trc = qrtr_node_assign(node, nid);\n+\tif (rc \u003c 0)\n+\t\tgoto free_node;\n \n \tmutex_lock(\u0026qrtr_node_lock);\n \tlist_add(\u0026node-\u003eitem, \u0026qrtr_all_nodes);\n \tmutex_unlock(\u0026qrtr_node_lock);\n \tep-\u003enode = node;\n+\tep-\u003eid = endpoint_id;\n+\tep-\u003ehelper.added = 0;\n \n \treturn 0;\n+free_node:\n+\tkfree(node);\n+\treturn rc;\n }\n EXPORT_SYMBOL_GPL(qrtr_endpoint_register);\n \n@@ -619,29 +807,46 @@ void qrtr_endpoint_unregister(struct qrtr_endpoint *ep)\n \tstruct sockaddr_qrtr src = {AF_QIPCRTR, node-\u003enid, QRTR_PORT_CTRL};\n \tstruct sockaddr_qrtr dst = {AF_QIPCRTR, qrtr_local_nid, QRTR_PORT_CTRL};\n \tstruct radix_tree_iter iter;\n+\tstruct radix_tree_iter iter2;\n \tstruct qrtr_ctrl_pkt *pkt;\n \tstruct qrtr_tx_flow *flow;\n \tstruct sk_buff *skb;\n \tunsigned long flags;\n \tunsigned long index;\n \tvoid __rcu **slot;\n+\tvoid __rcu **slot2;\n+\tu32 endpoint_id;\n \n \tmutex_lock(\u0026node-\u003eep_lock);\n+\tendpoint_id = node-\u003eep-\u003eid;\n \tnode-\u003eep = NULL;\n \tmutex_unlock(\u0026node-\u003eep_lock);\n \n \t/* Notify the local controller about the event */\n \tspin_lock_irqsave(\u0026qrtr_nodes_lock, flags);\n \tradix_tree_for_each_slot(slot, \u0026qrtr_nodes, \u0026iter, 0) {\n-\t\tif (*slot != node)\n+\t\tstruct qrtr_node_lookup_helper *helper = *slot;\n+\n+\t\tif (!helper)\n \t\t\tcontinue;\n-\t\tsrc.sq_node = iter.index;\n-\t\tskb = qrtr_alloc_ctrl_packet(\u0026pkt, GFP_ATOMIC);\n-\t\tif (skb) {\n-\t\t\tpkt-\u003ecmd = cpu_to_le32(QRTR_TYPE_BYE);\n-\t\t\tqrtr_local_enqueue(NULL, skb, QRTR_TYPE_BYE, \u0026src, \u0026dst);\n+\t\tradix_tree_for_each_slot(slot2, \u0026helper-\u003enodes, \u0026iter2, 0) {\n+\t\t\tif (*slot2 != node)\n+\t\t\t\tcontinue;\n+\t\t\tsrc.sq_node = iter.index;\n+\t\t\tskb = qrtr_alloc_ctrl_packet(\u0026pkt, GFP_ATOMIC);\n+\t\t\tif (skb) {\n+\t\t\t\tpkt-\u003ecmd = cpu_to_le32(QRTR_TYPE_BYE);\n+\t\t\t\tqrtr_local_enqueue(NULL, skb, endpoint_id,\n+\t\t\t\t\t\t   QRTR_TYPE_BYE, \u0026src, \u0026dst);\n+\t\t\t}\n \t\t}\n \t}\n+\tif (ep-\u003ehelper.added) {\n+\t\tradix_tree_for_each_slot(slot, \u0026ep-\u003ehelper.nodes, \u0026iter, 0)\n+\t\t\tradix_tree_iter_delete(\u0026ep-\u003ehelper.nodes, \u0026iter, slot);\n+\t\tradix_tree_delete(\u0026qrtr_nodes, ep-\u003eid);\n+\t\tep-\u003ehelper.added = 0;\n+\t}\n \tspin_unlock_irqrestore(\u0026qrtr_nodes_lock, flags);\n \n \t/* Wake up any transmitters waiting for resume-tx from the node */\n@@ -651,6 +856,10 @@ void qrtr_endpoint_unregister(struct qrtr_endpoint *ep)\n \tmutex_unlock(\u0026node-\u003eqrtr_tx_lock);\n \n \tqrtr_node_release(node);\n+\n+\txa_erase(\u0026qrtr_endpoints, endpoint_id);\n+\n+\tep-\u003eid = 0;\n \tep-\u003enode = NULL;\n }\n EXPORT_SYMBOL_GPL(qrtr_endpoint_unregister);\n@@ -700,8 +909,8 @@ static void qrtr_port_remove(struct qrtr_sock *ipc)\n \t\tpkt-\u003eclient.port = cpu_to_le32(ipc-\u003eus.sq_port);\n \n \t\tskb_set_owner_w(skb, \u0026ipc-\u003esk);\n-\t\tqrtr_bcast_enqueue(NULL, skb, QRTR_TYPE_DEL_CLIENT, \u0026ipc-\u003eus,\n-\t\t\t\t   \u0026to);\n+\t\tqrtr_bcast_enqueue(NULL, skb, qrtr_local_nid,\n+\t\t\t\t   QRTR_TYPE_DEL_CLIENT, \u0026ipc-\u003eus, \u0026to);\n \t}\n \n \tif (port == QRTR_PORT_CTRL)\n@@ -841,37 +1050,52 @@ static int qrtr_bind(struct socket *sock, struct sockaddr_unsized *saddr, int le\n \n /* Queue packet to local peer socket. */\n static int qrtr_local_enqueue(struct qrtr_node *node, struct sk_buff *skb,\n+\t\t\t      u32 endpoint_id,\n \t\t\t      int type, struct sockaddr_qrtr *from,\n \t\t\t      struct sockaddr_qrtr *to)\n {\n \tstruct qrtr_sock *ipc;\n \tstruct qrtr_cb *cb;\n+\tint ret = -ENODEV;\n \n \tipc = qrtr_port_lookup(to-\u003esq_port);\n-\tif (!ipc || \u0026ipc-\u003esk == skb-\u003esk) { /* do not send to self */\n-\t\tif (ipc)\n-\t\t\tqrtr_port_put(ipc);\n-\t\tkfree_skb(skb);\n-\t\treturn -ENODEV;\n-\t}\n+\tif (!ipc)\n+\t\tgoto done;\n+\n+\tif (\u0026ipc-\u003esk == skb-\u003esk) /* do not send to self */\n+\t\tgoto done;\n+\n+\t/*\n+\t * Filter out unwanted packets that are not on behalf of the bound\n+\t * endpoint.  Certain special packets (such as an empty NEW_SERVER\n+\t * packet that serves as a sentinel value) always go through.\n+\t */\n+\tif (endpoint_id \u0026\u0026 ipc-\u003ebound_endpoint \u0026\u0026\n+\t    ipc-\u003ebound_endpoint != endpoint_id)\n+\t\tgoto done;\n \n \tcb = (struct qrtr_cb *)skb-\u003ecb;\n \tcb-\u003esrc_node = from-\u003esq_node;\n \tcb-\u003esrc_port = from-\u003esq_port;\n+\tcb-\u003eendpoint_id = endpoint_id;\n \n-\tif (sock_queue_rcv_skb(\u0026ipc-\u003esk, skb)) {\n-\t\tqrtr_port_put(ipc);\n-\t\tkfree_skb(skb);\n-\t\treturn -ENOSPC;\n-\t}\n+\tret = -ENOSPC;\n+\tif (sock_queue_rcv_skb(\u0026ipc-\u003esk, skb))\n+\t\tgoto done;\n \n \tqrtr_port_put(ipc);\n \n \treturn 0;\n+done:\n+\tif (ipc)\n+\t\tqrtr_port_put(ipc);\n+\tkfree_skb(skb);\n+\treturn ret;\n }\n \n /* Queue packet for broadcast. */\n static int qrtr_bcast_enqueue(struct qrtr_node *node, struct sk_buff *skb,\n+\t\t\t      u32 endpoint_id,\n \t\t\t      int type, struct sockaddr_qrtr *from,\n \t\t\t      struct sockaddr_qrtr *to)\n {\n@@ -883,11 +1107,11 @@ static int qrtr_bcast_enqueue(struct qrtr_node *node, struct sk_buff *skb,\n \t\tif (!skbn)\n \t\t\tbreak;\n \t\tskb_set_owner_w(skbn, skb-\u003esk);\n-\t\tqrtr_node_enqueue(node, skbn, type, from, to);\n+\t\tqrtr_node_enqueue(node, skbn, endpoint_id, type, from, to);\n \t}\n \tmutex_unlock(\u0026qrtr_node_lock);\n \n-\tqrtr_local_enqueue(NULL, skb, type, from, to);\n+\tqrtr_local_enqueue(NULL, skb, endpoint_id, type, from, to);\n \n \treturn 0;\n }\n@@ -895,12 +1119,16 @@ static int qrtr_bcast_enqueue(struct qrtr_node *node, struct sk_buff *skb,\n static int qrtr_sendmsg(struct socket *sock, struct msghdr *msg, size_t len)\n {\n \tDECLARE_SOCKADDR(struct sockaddr_qrtr *, addr, msg-\u003emsg_name);\n-\tint (*enqueue_fn)(struct qrtr_node *, struct sk_buff *, int,\n-\t\t\t  struct sockaddr_qrtr *, struct sockaddr_qrtr *);\n+\tint (*enqueue_fn)(struct qrtr_node *node, struct sk_buff *skb,\n+\t\t\t  u32 endpoint_id, int type,\n+\t\t\t  struct sockaddr_qrtr *from,\n+\t\t\t  struct sockaddr_qrtr *to);\n \t__le32 qrtr_type = cpu_to_le32(QRTR_TYPE_DATA);\n \tstruct qrtr_sock *ipc = qrtr_sk(sock-\u003esk);\n \tstruct sock *sk = sock-\u003esk;\n \tstruct qrtr_node *node;\n+\tu32 msg_endpoint_id;\n+\tu32 endpoint_id = qrtr_local_nid;\n \tstruct sk_buff *skb;\n \tsize_t plen;\n \tu32 type;\n@@ -912,46 +1140,49 @@ static int qrtr_sendmsg(struct socket *sock, struct msghdr *msg, size_t len)\n \tif (len \u003e 65535)\n \t\treturn -EMSGSIZE;\n \n+\trc = qrtr_msg_get_endpoint(msg, \u0026msg_endpoint_id);\n+\tif (rc \u003c 0)\n+\t\treturn rc;\n+\n \tlock_sock(sk);\n \n \tif (addr) {\n-\t\tif (msg-\u003emsg_namelen \u003c sizeof(*addr)) {\n-\t\t\trelease_sock(sk);\n-\t\t\treturn -EINVAL;\n-\t\t}\n+\t\trc = -EINVAL;\n \n-\t\tif (addr-\u003esq_family != AF_QIPCRTR) {\n-\t\t\trelease_sock(sk);\n-\t\t\treturn -EINVAL;\n-\t\t}\n+\t\tif (msg-\u003emsg_namelen \u003c sizeof(*addr))\n+\t\t\tgoto release_sock;\n+\n+\t\tif (addr-\u003esq_family != AF_QIPCRTR)\n+\t\t\tgoto release_sock;\n \n \t\trc = qrtr_autobind(sock);\n-\t\tif (rc) {\n-\t\t\trelease_sock(sk);\n-\t\t\treturn rc;\n-\t\t}\n+\t\tif (rc)\n+\t\t\tgoto release_sock;\n \t} else if (sk-\u003esk_state == TCP_ESTABLISHED) {\n \t\taddr = \u0026ipc-\u003epeer;\n \t} else {\n-\t\trelease_sock(sk);\n-\t\treturn -ENOTCONN;\n+\t\trc = -ENOTCONN;\n+\t\tgoto release_sock;\n \t}\n \n \tnode = NULL;\n \tif (addr-\u003esq_node == QRTR_NODE_BCAST) {\n \t\tif (addr-\u003esq_port != QRTR_PORT_CTRL \u0026\u0026\n \t\t    qrtr_local_nid != QRTR_NODE_BCAST) {\n-\t\t\trelease_sock(sk);\n-\t\t\treturn -ENOTCONN;\n+\t\t\trc = -ENOTCONN;\n+\t\t\tgoto release_sock;\n \t\t}\n \t\tenqueue_fn = qrtr_bcast_enqueue;\n \t} else if (addr-\u003esq_node == ipc-\u003eus.sq_node) {\n \t\tenqueue_fn = qrtr_local_enqueue;\n \t} else {\n-\t\tnode = qrtr_node_lookup(addr-\u003esq_node);\n+\t\tendpoint_id = msg_endpoint_id ?\n+\t\t\t      msg_endpoint_id : ipc-\u003ebound_endpoint;\n+\n+\t\tnode = qrtr_node_lookup(endpoint_id, addr-\u003esq_node);\n \t\tif (!node) {\n-\t\t\trelease_sock(sk);\n-\t\t\treturn -ECONNRESET;\n+\t\t\trc = endpoint_id ? -ENXIO : -ECONNRESET;\n+\t\t\tgoto release_sock;\n \t\t}\n \t\tenqueue_fn = qrtr_node_enqueue;\n \t}\n@@ -981,15 +1212,21 @@ static int qrtr_sendmsg(struct socket *sock, struct msghdr *msg, size_t len)\n \n \t\t/* control messages already require the type as 'command' */\n \t\tskb_copy_bits(skb, 0, \u0026qrtr_type, 4);\n+\t\t/*\n+\t\t * Allow local name service to make packets appear as if\n+\t\t * they originated remotely\n+\t\t */\n+\t\tendpoint_id = msg_endpoint_id;\n \t}\n \n \ttype = le32_to_cpu(qrtr_type);\n-\trc = enqueue_fn(node, skb, type, \u0026ipc-\u003eus, addr);\n+\trc = enqueue_fn(node, skb, endpoint_id, type, \u0026ipc-\u003eus, addr);\n \tif (rc \u003e= 0)\n \t\trc = len;\n \n out_node:\n \tqrtr_node_release(node);\n+release_sock:\n \trelease_sock(sk);\n \n \treturn rc;\n@@ -1004,7 +1241,7 @@ static int qrtr_send_resume_tx(struct qrtr_cb *cb)\n \tstruct sk_buff *skb;\n \tint ret;\n \n-\tnode = qrtr_node_lookup(remote.sq_node);\n+\tnode = qrtr_node_lookup(cb-\u003eendpoint_id, remote.sq_node);\n \tif (!node)\n \t\treturn -EINVAL;\n \n@@ -1018,7 +1255,8 @@ static int qrtr_send_resume_tx(struct qrtr_cb *cb)\n \tpkt-\u003eclient.node = cpu_to_le32(cb-\u003edst_node);\n \tpkt-\u003eclient.port = cpu_to_le32(cb-\u003edst_port);\n \n-\tret = qrtr_node_enqueue(node, skb, QRTR_TYPE_RESUME_TX, \u0026local, \u0026remote);\n+\tret = qrtr_node_enqueue(node, skb, cb-\u003eendpoint_id,\n+\t\t\t\tQRTR_TYPE_RESUME_TX, \u0026local, \u0026remote);\n \n \tqrtr_node_release(node);\n \n@@ -1029,6 +1267,7 @@ static int qrtr_recvmsg(struct socket *sock, struct msghdr *msg,\n \t\t\tsize_t size, int flags)\n {\n \tDECLARE_SOCKADDR(struct sockaddr_qrtr *, addr, msg-\u003emsg_name);\n+\tstruct qrtr_sock *ipc = qrtr_sk(sock-\u003esk);\n \tstruct sock *sk = sock-\u003esk;\n \tstruct sk_buff *skb;\n \tstruct qrtr_cb *cb;\n@@ -1054,6 +1293,10 @@ static int qrtr_recvmsg(struct socket *sock, struct msghdr *msg,\n \t\tmsg-\u003emsg_flags |= MSG_TRUNC;\n \t}\n \n+\tif (cb-\u003eendpoint_id \u0026\u0026 test_bit(QRTR_F_REPORT_ENDPOINT, \u0026ipc-\u003eflags))\n+\t\tput_cmsg(msg, SOL_QRTR, QRTR_ENDPOINT,\n+\t\t\t sizeof(cb-\u003eendpoint_id), \u0026cb-\u003eendpoint_id);\n+\n \trc = skb_copy_datagram_msg(skb, 0, msg, copied);\n \tif (rc \u003c 0)\n \t\tgoto out;\n@@ -1199,6 +1442,74 @@ static int qrtr_ioctl(struct socket *sock, unsigned int cmd, unsigned long arg)\n \treturn rc;\n }\n \n+static int qrtr_setsockopt(struct socket *sock, int level, int optname,\n+\t\t\t   sockptr_t optval, unsigned int optlen)\n+{\n+\tstruct qrtr_sock *ipc = qrtr_sk(sock-\u003esk);\n+\tunsigned int val = 0;\n+\tint rc = 0;\n+\n+\tif (level != SOL_QRTR)\n+\t\treturn -ENOPROTOOPT;\n+\n+\tif (optlen \u003e= sizeof(val) \u0026\u0026\n+\t    copy_from_sockptr(\u0026val, optval, sizeof(val)))\n+\t\treturn -EFAULT;\n+\n+\tswitch (optname) {\n+\tcase QRTR_REPORT_ENDPOINT:\n+\t\tassign_bit(QRTR_F_REPORT_ENDPOINT, \u0026ipc-\u003eflags, val);\n+\t\tbreak;\n+\tcase QRTR_BIND_ENDPOINT:\n+\t\tWRITE_ONCE(ipc-\u003ebound_endpoint, val);\n+\t\tbreak;\n+\tdefault:\n+\t\trc = -ENOPROTOOPT;\n+\t}\n+\n+\treturn rc;\n+}\n+\n+static int qrtr_getsockopt(struct socket *sock, int level, int optname,\n+\t\t\t   char __user *optval, int __user *optlen)\n+{\n+\tstruct qrtr_sock *ipc = qrtr_sk(sock-\u003esk);\n+\tunsigned int val;\n+\tint len;\n+\tint rc = 0;\n+\n+\tif (level != SOL_QRTR)\n+\t\treturn -ENOPROTOOPT;\n+\n+\tif (get_user(len, optlen))\n+\t\treturn -EFAULT;\n+\n+\tif (len \u003c sizeof(val))\n+\t\treturn -EINVAL;\n+\n+\tswitch (optname) {\n+\tcase QRTR_REPORT_ENDPOINT:\n+\t\tval = test_bit(QRTR_F_REPORT_ENDPOINT, \u0026ipc-\u003eflags);\n+\t\tbreak;\n+\tcase QRTR_BIND_ENDPOINT:\n+\t\tval = READ_ONCE(ipc-\u003ebound_endpoint);\n+\t\tbreak;\n+\tdefault:\n+\t\trc = -ENOPROTOOPT;\n+\t}\n+\n+\tif (rc)\n+\t\treturn rc;\n+\n+\tlen = sizeof(int);\n+\n+\tif (put_user(len, optlen) ||\n+\t    copy_to_user(optval, \u0026val, len))\n+\t\trc = -EFAULT;\n+\n+\treturn rc;\n+}\n+\n static int qrtr_release(struct socket *sock)\n {\n \tstruct sock *sk = sock-\u003esk;\n@@ -1246,6 +1557,8 @@ static const struct proto_ops qrtr_proto_ops = {\n \t.shutdown\t= sock_no_shutdown,\n \t.release\t= qrtr_release,\n \t.mmap\t\t= sock_no_mmap,\n+\t.setsockopt\t= qrtr_setsockopt,\n+\t.getsockopt\t= qrtr_getsockopt,\n };\n \n static struct proto qrtr_proto = {\n@@ -1310,8 +1623,17 @@ static int __init qrtr_proto_init(void)\n \tif (rc)\n \t\tgoto err_sock;\n \n+\trc = radix_tree_insert(\u0026qrtr_nodes, 0, \u0026helper0);\n+\tif (rc)\n+\t\tgoto err_ns;\n+\n+\tINIT_RADIX_TREE(\u0026helper0.nodes, GFP_ATOMIC);\n+\thelper0.added = 1;\n+\n \treturn 0;\n \n+err_ns:\n+\tqrtr_ns_remove();\n err_sock:\n \tsock_unregister(qrtr_family.family);\n err_proto:\n@@ -1322,6 +1644,7 @@ postcore_initcall(qrtr_proto_init);\n \n static void __exit qrtr_proto_fini(void)\n {\n+\tradix_tree_delete(\u0026qrtr_nodes, 0);\n \tqrtr_ns_remove();\n \tsock_unregister(qrtr_family.family);\n \tproto_unregister(\u0026qrtr_proto);\ndiff --git a/net/qrtr/mhi.c b/net/qrtr/mhi.c\nindex 3990da1a65dc4..630ce0da060e5 100644\n--- a/net/qrtr/mhi.c\n+++ b/net/qrtr/mhi.c\n@@ -106,6 +106,16 @@ static int qcom_mhi_qrtr_queue_dl_buffers(struct mhi_device *mhi_dev)\n \treturn 0;\n }\n \n+static ssize_t endpoint_show(struct device *dev,\n+\t\t\t     struct device_attribute *attr, char *buf)\n+{\n+\tstruct qrtr_mhi_dev *qdev = dev_get_drvdata(dev);\n+\n+\treturn sprintf(buf, \"%u\\n\", qdev-\u003eep.id);\n+}\n+\n+static DEVICE_ATTR_RO(endpoint);\n+\n static int qcom_mhi_qrtr_probe(struct mhi_device *mhi_dev,\n \t\t\t       const struct mhi_device_id *id)\n {\n@@ -135,6 +145,9 @@ static int qcom_mhi_qrtr_probe(struct mhi_device *mhi_dev,\n \tif (rc)\n \t\tgoto err_unregister;\n \n+\tif (device_create_file(\u0026mhi_dev-\u003edev, \u0026dev_attr_endpoint) \u003c 0)\n+\t\tdev_err(qdev-\u003edev, \"Failed to create endpoint attribute\\n\");\n+\n \tdev_dbg(qdev-\u003edev, \"Qualcomm MHI QRTR driver probed\\n\");\n \n \treturn 0;\n@@ -151,6 +164,7 @@ static void qcom_mhi_qrtr_remove(struct mhi_device *mhi_dev)\n {\n \tstruct qrtr_mhi_dev *qdev = dev_get_drvdata(\u0026mhi_dev-\u003edev);\n \n+\tdevice_remove_file(\u0026mhi_dev-\u003edev, \u0026dev_attr_endpoint);\n \tqrtr_endpoint_unregister(\u0026qdev-\u003eep);\n \tmhi_unprepare_from_transfer(mhi_dev);\n \tdev_set_drvdata(\u0026mhi_dev-\u003edev, NULL);\ndiff --git a/net/qrtr/ns.c b/net/qrtr/ns.c\nindex c5e7e01db2498..31dfa764e186a 100644\n--- a/net/qrtr/ns.c\n+++ b/net/qrtr/ns.c\n@@ -5,6 +5,7 @@\n  * Copyright (c) 2020, Linaro Ltd.\n  */\n \n+#define pr_fmt(fmt) \"QRTR NS: \"fmt\n #include \u003clinux/module.h\u003e\n #include \u003clinux/qrtr.h\u003e\n #include \u003clinux/workqueue.h\u003e\n@@ -16,7 +17,7 @@\n #define CREATE_TRACE_POINTS\n #include \u003ctrace/events/qrtr.h\u003e\n \n-static DEFINE_XARRAY(nodes);\n+static DEFINE_XARRAY(endpoints);\n \n static struct {\n \tstruct socket *sock;\n@@ -62,6 +63,7 @@ struct qrtr_server {\n \n \tunsigned int node;\n \tunsigned int port;\n+\tu32 endpoint_id;\n \n \tstruct list_head qli;\n };\n@@ -72,6 +74,11 @@ struct qrtr_node {\n \tu32 server_count;\n };\n \n+struct qrtr_ns_endpoint {\n+\tunsigned int id;\n+\tstruct xarray nodes;\n+};\n+\n /* Max nodes, server, lookup limits are chosen based on the current platform\n  * requirements. If the requirement changes in the future, these values can be\n  * increased.\n@@ -82,35 +89,90 @@ struct qrtr_node {\n \n static u16 node_count;\n \n-static struct qrtr_node *node_get(unsigned int node_id)\n+static struct qrtr_node *node_get(u32 endpoint_id, unsigned int node_id)\n {\n+\tstruct qrtr_ns_endpoint *endpoint;\n \tstruct qrtr_node *node;\n+\tbool new_endpoint = false;\n+\n+\tendpoint = xa_load(\u0026endpoints, endpoint_id);\n+\tif (!endpoint) {\n+\t\tendpoint = kzalloc_obj(*endpoint);\n+\t\tif (!endpoint)\n+\t\t\treturn NULL;\n+\n+\t\tendpoint-\u003eid = endpoint_id;\n+\t\txa_init(\u0026endpoint-\u003enodes);\n+\n+\t\tif (xa_store(\u0026endpoints, endpoint_id, endpoint, GFP_KERNEL)) {\n+\t\t\tkfree(endpoint);\n+\t\t\treturn NULL;\n+\t\t}\n+\n+\t\tnew_endpoint = true;\n+\t}\n \n-\tnode = xa_load(\u0026nodes, node_id);\n+\tnode = xa_load(\u0026endpoint-\u003enodes, node_id);\n \tif (node)\n \t\treturn node;\n \n \tif (node_count \u003e= QRTR_NS_MAX_NODES) {\n \t\tpr_err_ratelimited(\"QRTR clients exceed max node limit!\\n\");\n-\t\treturn NULL;\n+\t\tgoto error;\n \t}\n \n \t/* If node didn't exist, allocate and insert it to the tree */\n \tnode = kzalloc_obj(*node);\n \tif (!node)\n-\t\treturn NULL;\n+\t\tgoto error;\n \n \tnode-\u003eid = node_id;\n \txa_init(\u0026node-\u003eservers);\n \n-\tif (xa_store(\u0026nodes, node_id, node, GFP_KERNEL)) {\n+\tif (xa_store(\u0026endpoint-\u003enodes, node_id, node, GFP_KERNEL)) {\n \t\tkfree(node);\n-\t\treturn NULL;\n+\t\tgoto error;\n \t}\n \n \tnode_count++;\n \n \treturn node;\n+error:\n+\tif (new_endpoint) {\n+\t\txa_erase(\u0026endpoints, endpoint_id);\n+\t\tkfree(endpoint);\n+\t}\n+\n+\treturn NULL;\n+}\n+\n+static void node_erase(u32 endpoint_id, unsigned int node_id)\n+{\n+\tstruct qrtr_ns_endpoint *endpoint;\n+\tstruct qrtr_node *node;\n+\n+\tendpoint = xa_load(\u0026endpoints, endpoint_id);\n+\tif (!endpoint)\n+\t\treturn;\n+\n+\tnode = xa_load(\u0026endpoint-\u003enodes, node_id);\n+\tif (!node)\n+\t\treturn;\n+\n+\txa_erase(\u0026endpoint-\u003enodes, node_id);\n+\tkfree(node);\n+\tnode_count--;\n+}\n+\n+static struct qrtr_node *node_lookup(u32 endpoint_id, unsigned int node_id)\n+{\n+\tstruct qrtr_ns_endpoint *endpoint;\n+\n+\tendpoint = xa_load(\u0026endpoints, endpoint_id);\n+\tif (!endpoint)\n+\t\treturn NULL;\n+\n+\treturn xa_load(\u0026endpoint-\u003enodes, node_id);\n }\n \n static int server_match(const struct qrtr_server *srv,\n@@ -126,19 +188,42 @@ static int server_match(const struct qrtr_server *srv,\n \treturn (srv-\u003einstance \u0026 ifilter) == f-\u003einstance;\n }\n \n-static int service_announce_new(struct sockaddr_qrtr *dest,\n-\t\t\t\tstruct qrtr_server *srv)\n+static int qrtr_ns_sendmsg(u32 endpoint_id, struct sockaddr_qrtr *dest,\n+\t\t\t   struct qrtr_ctrl_pkt *pkt)\n {\n-\tstruct qrtr_ctrl_pkt pkt;\n \tstruct msghdr msg = { };\n \tstruct kvec iv;\n+\tu8 control[CMSG_SPACE(sizeof(endpoint_id))];\n+\tstruct cmsghdr *cmsg;\n+\n+\tiv.iov_base = pkt;\n+\tiv.iov_len = sizeof(*pkt);\n+\n+\tmsg.msg_name = (struct sockaddr *)dest;\n+\tmsg.msg_namelen = sizeof(*dest);\n+\n+\tif (endpoint_id) {\n+\t\tmsg.msg_control = control;\n+\t\tmsg.msg_controllen = sizeof(control);\n+\n+\t\tcmsg = CMSG_FIRSTHDR(\u0026msg);\n+\t\tcmsg-\u003ecmsg_level = SOL_QRTR;\n+\t\tcmsg-\u003ecmsg_type = QRTR_ENDPOINT;\n+\t\tcmsg-\u003ecmsg_len = CMSG_LEN(sizeof(endpoint_id));\n+\t\tmemcpy(CMSG_DATA(cmsg), \u0026endpoint_id, sizeof(endpoint_id));\n+\t}\n+\n+\treturn kernel_sendmsg(qrtr_ns.sock, \u0026msg, \u0026iv, 1, sizeof(*pkt));\n+}\n+\n+static int service_announce_new(u32 endpoint_id, struct sockaddr_qrtr *dest,\n+\t\t\t\tstruct qrtr_server *srv)\n+{\n+\tstruct qrtr_ctrl_pkt pkt;\n \n \ttrace_qrtr_ns_service_announce_new(srv-\u003eservice, srv-\u003einstance,\n \t\t\t\t\t   srv-\u003enode, srv-\u003eport);\n \n-\tiv.iov_base = \u0026pkt;\n-\tiv.iov_len = sizeof(pkt);\n-\n \tmemset(\u0026pkt, 0, sizeof(pkt));\n \tpkt.cmd = cpu_to_le32(QRTR_TYPE_NEW_SERVER);\n \tpkt.server.service = cpu_to_le32(srv-\u003eservice);\n@@ -146,26 +231,18 @@ static int service_announce_new(struct sockaddr_qrtr *dest,\n \tpkt.server.node = cpu_to_le32(srv-\u003enode);\n \tpkt.server.port = cpu_to_le32(srv-\u003eport);\n \n-\tmsg.msg_name = (struct sockaddr *)dest;\n-\tmsg.msg_namelen = sizeof(*dest);\n-\n-\treturn kernel_sendmsg(qrtr_ns.sock, \u0026msg, \u0026iv, 1, sizeof(pkt));\n+\treturn qrtr_ns_sendmsg(endpoint_id, dest, \u0026pkt);\n }\n \n-static void service_announce_del(struct sockaddr_qrtr *dest,\n+static void service_announce_del(u32 endpoint_id, struct sockaddr_qrtr *dest,\n \t\t\t\t struct qrtr_server *srv)\n {\n \tstruct qrtr_ctrl_pkt pkt;\n-\tstruct msghdr msg = { };\n-\tstruct kvec iv;\n \tint ret;\n \n \ttrace_qrtr_ns_service_announce_del(srv-\u003eservice, srv-\u003einstance,\n \t\t\t\t\t   srv-\u003enode, srv-\u003eport);\n \n-\tiv.iov_base = \u0026pkt;\n-\tiv.iov_len = sizeof(pkt);\n-\n \tmemset(\u0026pkt, 0, sizeof(pkt));\n \tpkt.cmd = cpu_to_le32(QRTR_TYPE_DEL_SERVER);\n \tpkt.server.service = cpu_to_le32(srv-\u003eservice);\n@@ -173,26 +250,24 @@ static void service_announce_del(struct sockaddr_qrtr *dest,\n \tpkt.server.node = cpu_to_le32(srv-\u003enode);\n \tpkt.server.port = cpu_to_le32(srv-\u003eport);\n \n-\tmsg.msg_name = (struct sockaddr *)dest;\n-\tmsg.msg_namelen = sizeof(*dest);\n-\n-\tret = kernel_sendmsg(qrtr_ns.sock, \u0026msg, \u0026iv, 1, sizeof(pkt));\n+\tret = qrtr_ns_sendmsg(endpoint_id, dest, \u0026pkt);\n \tif (ret \u003c 0 \u0026\u0026 ret != -ENODEV)\n \t\tpr_err(\"failed to announce del service\\n\");\n \n \treturn;\n }\n \n-static void lookup_notify(struct sockaddr_qrtr *to, struct qrtr_server *srv,\n-\t\t\t  bool new)\n+static void lookup_notify(u32 endpoint_id, struct sockaddr_qrtr *to,\n+\t\t\t  struct qrtr_server *srv, bool new)\n {\n \tstruct qrtr_ctrl_pkt pkt;\n-\tstruct msghdr msg = { };\n-\tstruct kvec iv;\n \tint ret;\n \n-\tiv.iov_base = \u0026pkt;\n-\tiv.iov_len = sizeof(pkt);\n+\t/*\n+\t * Notify a local client at @to about a server change.  The aux data\n+\t * will look as if it came from the endpoint that reported the event\n+\t * (remote or local)\n+\t */\n \n \tmemset(\u0026pkt, 0, sizeof(pkt));\n \tpkt.cmd = new ? cpu_to_le32(QRTR_TYPE_NEW_SERVER) :\n@@ -204,28 +279,25 @@ static void lookup_notify(struct sockaddr_qrtr *to, struct qrtr_server *srv,\n \t\tpkt.server.port = cpu_to_le32(srv-\u003eport);\n \t}\n \n-\tmsg.msg_name = (struct sockaddr *)to;\n-\tmsg.msg_namelen = sizeof(*to);\n-\n-\tret = kernel_sendmsg(qrtr_ns.sock, \u0026msg, \u0026iv, 1, sizeof(pkt));\n+\tret = qrtr_ns_sendmsg(endpoint_id, to, \u0026pkt);\n \tif (ret \u003c 0 \u0026\u0026 ret != -ENODEV)\n \t\tpr_err(\"failed to send lookup notification\\n\");\n }\n \n-static int announce_servers(struct sockaddr_qrtr *sq)\n+static int announce_servers(u32 endpoint_id, struct sockaddr_qrtr *sq)\n {\n \tstruct qrtr_server *srv;\n \tstruct qrtr_node *node;\n \tunsigned long index;\n \tint ret;\n \n-\tnode = node_get(qrtr_ns.local_node);\n+\tnode = node_lookup(qrtr_ns.local_node, qrtr_ns.local_node);\n \tif (!node)\n \t\treturn 0;\n \n-\t/* Announce the list of servers registered in this node */\n+\t/* Announce servers registered on local endpoint to remote endpoint */\n \txa_for_each(\u0026node-\u003eservers, index, srv) {\n-\t\tret = service_announce_new(sq, srv);\n+\t\tret = service_announce_new(endpoint_id, sq, srv);\n \t\tif (ret \u003c 0) {\n \t\t\tif (ret == -ENODEV)\n \t\t\t\tcontinue;\n@@ -237,7 +309,8 @@ static int announce_servers(struct sockaddr_qrtr *sq)\n \treturn 0;\n }\n \n-static struct qrtr_server *server_add(unsigned int service,\n+static struct qrtr_server *server_add(u32 endpoint_id,\n+\t\t\t\t      unsigned int service,\n \t\t\t\t      unsigned int instance,\n \t\t\t\t      unsigned int node_id,\n \t\t\t\t      unsigned int port)\n@@ -249,7 +322,7 @@ static struct qrtr_server *server_add(unsigned int service,\n \tif (!service || !port)\n \t\treturn NULL;\n \n-\tnode = node_get(node_id);\n+\tnode = node_get(endpoint_id, node_id);\n \tif (!node)\n \t\treturn NULL;\n \n@@ -293,7 +366,8 @@ static struct qrtr_server *server_add(unsigned int service,\n \treturn NULL;\n }\n \n-static int server_del(struct qrtr_node *node, unsigned int port, bool bcast)\n+static int server_del(u32 endpoint_id, struct qrtr_node *node,\n+\t\t      unsigned int port, bool bcast)\n {\n \tstruct qrtr_lookup *lookup;\n \tstruct qrtr_server *srv;\n@@ -305,9 +379,10 @@ static int server_del(struct qrtr_node *node, unsigned int port, bool bcast)\n \n \txa_erase(\u0026node-\u003eservers, port);\n \n-\t/* Broadcast the removal of local servers */\n+\t/* Broadcast the removal of local servers to remote endpoints */\n \tif (srv-\u003enode == qrtr_ns.local_node \u0026\u0026 bcast)\n-\t\tservice_announce_del(\u0026qrtr_ns.bcast_sq, srv);\n+\t\tservice_announce_del(qrtr_ns.local_node,\n+\t\t\t\t     \u0026qrtr_ns.bcast_sq, srv);\n \n \t/* Announce the service's disappearance to observers */\n \tlist_for_each(li, \u0026qrtr_ns.lookups) {\n@@ -317,7 +392,7 @@ static int server_del(struct qrtr_node *node, unsigned int port, bool bcast)\n \t\tif (lookup-\u003einstance \u0026\u0026 lookup-\u003einstance != srv-\u003einstance)\n \t\t\tcontinue;\n \n-\t\tlookup_notify(\u0026lookup-\u003esq, srv, false);\n+\t\tlookup_notify(endpoint_id, \u0026lookup-\u003esq, srv, false);\n \t}\n \n \tkfree(srv);\n@@ -326,23 +401,15 @@ static int server_del(struct qrtr_node *node, unsigned int port, bool bcast)\n \treturn 0;\n }\n \n-static int say_hello(struct sockaddr_qrtr *dest)\n+static int say_hello(u32 endpoint_id, struct sockaddr_qrtr *dest)\n {\n \tstruct qrtr_ctrl_pkt pkt;\n-\tstruct msghdr msg = { };\n-\tstruct kvec iv;\n \tint ret;\n \n-\tiv.iov_base = \u0026pkt;\n-\tiv.iov_len = sizeof(pkt);\n-\n \tmemset(\u0026pkt, 0, sizeof(pkt));\n \tpkt.cmd = cpu_to_le32(QRTR_TYPE_HELLO);\n \n-\tmsg.msg_name = (struct sockaddr *)dest;\n-\tmsg.msg_namelen = sizeof(*dest);\n-\n-\tret = kernel_sendmsg(qrtr_ns.sock, \u0026msg, \u0026iv, 1, sizeof(pkt));\n+\tret = qrtr_ns_sendmsg(endpoint_id, dest, \u0026pkt);\n \tif (ret \u003c 0)\n \t\tpr_err(\"failed to send hello msg\\n\");\n \n@@ -350,42 +417,38 @@ static int say_hello(struct sockaddr_qrtr *dest)\n }\n \n /* Announce the list of servers registered on the local node */\n-static int ctrl_cmd_hello(struct sockaddr_qrtr *sq)\n+static int ctrl_cmd_hello(u32 endpoint_id, struct sockaddr_qrtr *sq)\n {\n \tint ret;\n \n-\tret = say_hello(sq);\n+\t/* Send Hello and New Server messages to remote endpoint */\n+\tret = say_hello(endpoint_id, sq);\n \tif (ret \u003c 0)\n \t\treturn ret;\n \n-\treturn announce_servers(sq);\n+\treturn announce_servers(endpoint_id, sq);\n }\n \n-static int ctrl_cmd_bye(struct sockaddr_qrtr *from)\n+static int ctrl_cmd_bye(u32 endpoint_id, struct sockaddr_qrtr *from)\n {\n \tstruct qrtr_node *local_node;\n \tstruct qrtr_ctrl_pkt pkt;\n \tstruct qrtr_server *srv;\n \tstruct sockaddr_qrtr sq;\n-\tstruct msghdr msg = { };\n \tstruct qrtr_node *node;\n \tunsigned long index;\n-\tstruct kvec iv;\n \tint ret = 0;\n \n-\tiv.iov_base = \u0026pkt;\n-\tiv.iov_len = sizeof(pkt);\n-\n-\tnode = node_get(from-\u003esq_node);\n+\tnode = node_get(endpoint_id, from-\u003esq_node);\n \tif (!node)\n \t\treturn 0;\n \n \t/* Advertise removal of this client to all servers of remote node */\n \txa_for_each(\u0026node-\u003eservers, index, srv)\n-\t\tserver_del(node, srv-\u003eport, true);\n+\t\tserver_del(endpoint_id, node, srv-\u003eport, true);\n \n \t/* Advertise the removal of this client to all local servers */\n-\tlocal_node = node_get(qrtr_ns.local_node);\n+\tlocal_node = node_get(qrtr_ns.local_node, qrtr_ns.local_node);\n \tif (!local_node) {\n \t\tret = 0;\n \t\tgoto delete_node;\n@@ -400,10 +463,8 @@ static int ctrl_cmd_bye(struct sockaddr_qrtr *from)\n \t\tsq.sq_node = srv-\u003enode;\n \t\tsq.sq_port = srv-\u003eport;\n \n-\t\tmsg.msg_name = (struct sockaddr *)\u0026sq;\n-\t\tmsg.msg_namelen = sizeof(sq);\n-\n-\t\tret = kernel_sendmsg(qrtr_ns.sock, \u0026msg, \u0026iv, 1, sizeof(pkt));\n+\t\t/* Bye will look as if it came from endpoint_id */\n+\t\tret = qrtr_ns_sendmsg(endpoint_id, \u0026sq, \u0026pkt);\n \t\tif (ret \u003c 0 \u0026\u0026 ret != -ENODEV) {\n \t\t\tpr_err(\"failed to send bye cmd\\n\");\n \t\t\tgoto delete_node;\n@@ -414,32 +475,25 @@ static int ctrl_cmd_bye(struct sockaddr_qrtr *from)\n \tret = 0;\n \n delete_node:\n-\txa_erase(\u0026nodes, from-\u003esq_node);\n-\tkfree(node);\n-\tnode_count--;\n+\tnode_erase(endpoint_id, from-\u003esq_node);\n \n \treturn ret;\n }\n \n-static int ctrl_cmd_del_client(struct sockaddr_qrtr *from,\n+static int ctrl_cmd_del_client(u32 endpoint_id, struct sockaddr_qrtr *from,\n \t\t\t       unsigned int node_id, unsigned int port)\n {\n \tstruct qrtr_node *local_node;\n \tstruct qrtr_lookup *lookup;\n \tstruct qrtr_ctrl_pkt pkt;\n-\tstruct msghdr msg = { };\n \tstruct qrtr_server *srv;\n \tstruct sockaddr_qrtr sq;\n \tstruct qrtr_node *node;\n \tstruct list_head *tmp;\n \tstruct list_head *li;\n \tunsigned long index;\n-\tstruct kvec iv;\n \tint ret;\n \n-\tiv.iov_base = \u0026pkt;\n-\tiv.iov_len = sizeof(pkt);\n-\n \t/* Don't accept spoofed messages */\n \tif (from-\u003esq_node != node_id)\n \t\treturn -EINVAL;\n@@ -465,12 +519,12 @@ static int ctrl_cmd_del_client(struct sockaddr_qrtr *from,\n \t * DEL_SERVER. Neighbours would've already removed the server belonging\n \t * to this port due to the DEL_CLIENT broadcast from qrtr_port_remove().\n \t */\n-\tnode = node_get(node_id);\n+\tnode = node_lookup(endpoint_id, node_id);\n \tif (node)\n-\t\tserver_del(node, port, false);\n+\t\tserver_del(endpoint_id, node, port, false);\n \n \t/* Advertise the removal of this client to all local servers */\n-\tlocal_node = node_get(qrtr_ns.local_node);\n+\tlocal_node = node_lookup(qrtr_ns.local_node, qrtr_ns.local_node);\n \tif (!local_node)\n \t\treturn 0;\n \n@@ -484,10 +538,8 @@ static int ctrl_cmd_del_client(struct sockaddr_qrtr *from,\n \t\tsq.sq_node = srv-\u003enode;\n \t\tsq.sq_port = srv-\u003eport;\n \n-\t\tmsg.msg_name = (struct sockaddr *)\u0026sq;\n-\t\tmsg.msg_namelen = sizeof(sq);\n-\n-\t\tret = kernel_sendmsg(qrtr_ns.sock, \u0026msg, \u0026iv, 1, sizeof(pkt));\n+\t\t/* Del Client will look as if it came from endpoint_id */\n+\t\tret = qrtr_ns_sendmsg(endpoint_id, \u0026sq, \u0026pkt);\n \t\tif (ret \u003c 0 \u0026\u0026 ret != -ENODEV) {\n \t\t\tpr_err(\"failed to send del client cmd\\n\");\n \t\t\treturn ret;\n@@ -496,7 +548,7 @@ static int ctrl_cmd_del_client(struct sockaddr_qrtr *from,\n \treturn 0;\n }\n \n-static int ctrl_cmd_new_server(struct sockaddr_qrtr *from,\n+static int ctrl_cmd_new_server(u32 endpoint_id, struct sockaddr_qrtr *from,\n \t\t\t       unsigned int service, unsigned int instance,\n \t\t\t       unsigned int node_id, unsigned int port)\n {\n@@ -511,12 +563,16 @@ static int ctrl_cmd_new_server(struct sockaddr_qrtr *from,\n \t\tport = from-\u003esq_port;\n \t}\n \n-\tsrv = server_add(service, instance, node_id, port);\n-\tif (!srv)\n+\tsrv = server_add(endpoint_id, service, instance, node_id, port);\n+\tif (!srv) {\n+\t\tpr_err(\"Failed to add server\\n\");\n \t\treturn -EINVAL;\n+\t}\n \n \tif (srv-\u003enode == qrtr_ns.local_node) {\n-\t\tret = service_announce_new(\u0026qrtr_ns.bcast_sq, srv);\n+\t\t/* Broadcast local server info to all peer endpoints */\n+\t\tret = service_announce_new(qrtr_ns.local_node,\n+\t\t\t\t\t   \u0026qrtr_ns.bcast_sq, srv);\n \t\tif (ret \u003c 0) {\n \t\t\tpr_err(\"failed to announce new service\\n\");\n \t\t\treturn ret;\n@@ -531,13 +587,13 @@ static int ctrl_cmd_new_server(struct sockaddr_qrtr *from,\n \t\tif (lookup-\u003einstance \u0026\u0026 lookup-\u003einstance != instance)\n \t\t\tcontinue;\n \n-\t\tlookup_notify(\u0026lookup-\u003esq, srv, true);\n+\t\tlookup_notify(endpoint_id, \u0026lookup-\u003esq, srv, true);\n \t}\n \n \treturn ret;\n }\n \n-static int ctrl_cmd_del_server(struct sockaddr_qrtr *from,\n+static int ctrl_cmd_del_server(u32 endpoint_id, struct sockaddr_qrtr *from,\n \t\t\t       unsigned int service, unsigned int instance,\n \t\t\t       unsigned int node_id, unsigned int port)\n {\n@@ -553,24 +609,22 @@ static int ctrl_cmd_del_server(struct sockaddr_qrtr *from,\n \tif (from-\u003esq_node == qrtr_ns.local_node \u0026\u0026 from-\u003esq_port != port)\n \t\treturn -EINVAL;\n \n-\tnode = node_get(node_id);\n+\tnode = node_lookup(endpoint_id, node_id);\n \tif (!node)\n \t\treturn -ENOENT;\n \n-\tserver_del(node, port, true);\n+\tserver_del(endpoint_id, node, port, true);\n \n \treturn 0;\n }\n \n-static int ctrl_cmd_new_lookup(struct sockaddr_qrtr *from,\n+static int ctrl_cmd_new_lookup(u32 endpoint_id, struct sockaddr_qrtr *from,\n \t\t\t       unsigned int service, unsigned int instance)\n {\n \tstruct qrtr_server_filter filter;\n \tstruct qrtr_lookup *lookup;\n-\tstruct qrtr_server *srv;\n-\tstruct qrtr_node *node;\n-\tunsigned long node_idx;\n-\tunsigned long srv_idx;\n+\tunsigned long id;\n+\tstruct qrtr_ns_endpoint *endpoint;\n \n \t/* Accept only local observers */\n \tif (from-\u003esq_node != qrtr_ns.local_node)\n@@ -595,22 +649,30 @@ static int ctrl_cmd_new_lookup(struct sockaddr_qrtr *from,\n \tfilter.service = service;\n \tfilter.instance = instance;\n \n-\txa_for_each(\u0026nodes, node_idx, node) {\n-\t\txa_for_each(\u0026node-\u003eservers, srv_idx, srv) {\n-\t\t\tif (!server_match(srv, \u0026filter))\n-\t\t\t\tcontinue;\n+\txa_for_each(\u0026endpoints, id, endpoint) {\n+\t\tstruct qrtr_node *node;\n+\t\tunsigned long node_idx;\n \n-\t\t\tlookup_notify(from, srv, true);\n+\t\txa_for_each(\u0026endpoint-\u003enodes, node_idx, node) {\n+\t\t\tunsigned long srv_idx;\n+\t\t\tstruct qrtr_server *srv;\n+\n+\t\t\txa_for_each(\u0026node-\u003eservers, srv_idx, srv) {\n+\t\t\t\tif (!server_match(srv, \u0026filter))\n+\t\t\t\t\tcontinue;\n+\n+\t\t\t\tlookup_notify(id, from, srv, true);\n+\t\t\t}\n \t\t}\n \t}\n \n \t/* Empty notification, to indicate end of listing */\n-\tlookup_notify(from, NULL, true);\n+\tlookup_notify(0, from, NULL, true);\n \n \treturn 0;\n }\n \n-static void ctrl_cmd_del_lookup(struct sockaddr_qrtr *from,\n+static void ctrl_cmd_del_lookup(u32 endpoint_id, struct sockaddr_qrtr *from,\n \t\t\t\tunsigned int service, unsigned int instance)\n {\n \tstruct qrtr_lookup *lookup;\n@@ -644,6 +706,7 @@ static void qrtr_ns_worker(struct work_struct *work)\n \tssize_t msglen;\n \tvoid *recv_buf;\n \tstruct kvec iv;\n+\tu8 control[32];\n \tint ret;\n \n \tmsg.msg_name = (struct sockaddr *)\u0026sq;\n@@ -654,8 +717,12 @@ static void qrtr_ns_worker(struct work_struct *work)\n \t\treturn;\n \n \tfor (;;) {\n+\t\tu32 endpoint_id;\n+\n \t\tiv.iov_base = recv_buf;\n \t\tiv.iov_len = recv_buf_size;\n+\t\tmsg.msg_control = control;\n+\t\tmsg.msg_controllen = sizeof(control);\n \n \t\tmsglen = kernel_recvmsg(qrtr_ns.sock, \u0026msg, \u0026iv, 1,\n \t\t\t\t\tiv.iov_len, MSG_DONTWAIT);\n@@ -668,6 +735,19 @@ static void qrtr_ns_worker(struct work_struct *work)\n \t\t\tbreak;\n \t\t}\n \n+\t\t/* AUX data is written direct into the control buffer */\n+\t\tmsg.msg_control = control;\n+\t\tmsg.msg_controllen = sizeof(control) - msg.msg_controllen;\n+\n+\t\tret = qrtr_msg_get_endpoint(\u0026msg, \u0026endpoint_id);\n+\t\tif (ret \u003c 0) {\n+\t\t\tpr_err(\"error receiving endpoint id: %d\\n\", ret);\n+\t\t\tbreak;\n+\t\t}\n+\n+\t\tif ((size_t)msglen \u003c sizeof(*pkt))\n+\t\t\tbreak;\n+\n \t\tpkt = recv_buf;\n \t\tcmd = le32_to_cpu(pkt-\u003ecmd);\n \t\tif (cmd \u003c ARRAY_SIZE(qrtr_ctrl_pkt_strings) \u0026\u0026\n@@ -678,25 +758,25 @@ static void qrtr_ns_worker(struct work_struct *work)\n \t\tret = 0;\n \t\tswitch (cmd) {\n \t\tcase QRTR_TYPE_HELLO:\n-\t\t\tret = ctrl_cmd_hello(\u0026sq);\n+\t\t\tret = ctrl_cmd_hello(endpoint_id, \u0026sq);\n \t\t\tbreak;\n \t\tcase QRTR_TYPE_BYE:\n-\t\t\tret = ctrl_cmd_bye(\u0026sq);\n+\t\t\tret = ctrl_cmd_bye(endpoint_id, \u0026sq);\n \t\t\tbreak;\n \t\tcase QRTR_TYPE_DEL_CLIENT:\n-\t\t\tret = ctrl_cmd_del_client(\u0026sq,\n+\t\t\tret = ctrl_cmd_del_client(endpoint_id, \u0026sq,\n \t\t\t\t\tle32_to_cpu(pkt-\u003eclient.node),\n \t\t\t\t\tle32_to_cpu(pkt-\u003eclient.port));\n \t\t\tbreak;\n \t\tcase QRTR_TYPE_NEW_SERVER:\n-\t\t\tret = ctrl_cmd_new_server(\u0026sq,\n+\t\t\tret = ctrl_cmd_new_server(endpoint_id, \u0026sq,\n \t\t\t\t\tle32_to_cpu(pkt-\u003eserver.service),\n \t\t\t\t\tle32_to_cpu(pkt-\u003eserver.instance),\n \t\t\t\t\tle32_to_cpu(pkt-\u003eserver.node),\n \t\t\t\t\tle32_to_cpu(pkt-\u003eserver.port));\n \t\t\tbreak;\n \t\tcase QRTR_TYPE_DEL_SERVER:\n-\t\t\tret = ctrl_cmd_del_server(\u0026sq,\n+\t\t\tret = ctrl_cmd_del_server(endpoint_id, \u0026sq,\n \t\t\t\t\t le32_to_cpu(pkt-\u003eserver.service),\n \t\t\t\t\t le32_to_cpu(pkt-\u003eserver.instance),\n \t\t\t\t\t le32_to_cpu(pkt-\u003eserver.node),\n@@ -707,12 +787,12 @@ static void qrtr_ns_worker(struct work_struct *work)\n \t\tcase QRTR_TYPE_RESUME_TX:\n \t\t\tbreak;\n \t\tcase QRTR_TYPE_NEW_LOOKUP:\n-\t\t\tret = ctrl_cmd_new_lookup(\u0026sq,\n+\t\t\tret = ctrl_cmd_new_lookup(endpoint_id, \u0026sq,\n \t\t\t\t\t le32_to_cpu(pkt-\u003eserver.service),\n \t\t\t\t\t le32_to_cpu(pkt-\u003eserver.instance));\n \t\t\tbreak;\n \t\tcase QRTR_TYPE_DEL_LOOKUP:\n-\t\t\tctrl_cmd_del_lookup(\u0026sq,\n+\t\t\tctrl_cmd_del_lookup(endpoint_id, \u0026sq,\n \t\t\t\t    le32_to_cpu(pkt-\u003eserver.service),\n \t\t\t\t    le32_to_cpu(pkt-\u003eserver.instance));\n \t\t\tbreak;\n@@ -746,6 +826,8 @@ int qrtr_ns_init(void)\n \tif (ret \u003c 0)\n \t\treturn ret;\n \n+\tqrtr_sock_set_report_endpoint(qrtr_ns.sock-\u003esk);\n+\n \tret = kernel_getsockname(qrtr_ns.sock, (struct sockaddr *)\u0026sq);\n \tif (ret \u003c 0) {\n \t\tpr_err(\"failed to get socket name\\n\");\n@@ -774,7 +856,7 @@ int qrtr_ns_init(void)\n \tqrtr_ns.bcast_sq.sq_node = QRTR_NODE_BCAST;\n \tqrtr_ns.bcast_sq.sq_port = QRTR_PORT_CTRL;\n \n-\tret = say_hello(\u0026qrtr_ns.bcast_sq);\n+\tret = say_hello(qrtr_ns.local_node, \u0026qrtr_ns.bcast_sq);\n \tif (ret \u003c 0)\n \t\tgoto err_wq;\n \ndiff --git a/net/qrtr/qrtr.h b/net/qrtr/qrtr.h\nindex 3f2d28696062a..affc24f426c64 100644\n--- a/net/qrtr/qrtr.h\n+++ b/net/qrtr/qrtr.h\n@@ -9,6 +9,15 @@ struct sk_buff;\n /* endpoint node id auto assignment */\n #define QRTR_EP_NID_AUTO (-1)\n \n+/**\n+ * struct qrtr_node_lookup_helper - node lookup helper, stored in qrtr_nodes\n+ * @nodes: nodes, indexed by node_id\n+ */\n+struct qrtr_node_lookup_helper {\n+\tint added;\n+\tstruct radix_tree_root nodes;\n+};\n+\n /**\n  * struct qrtr_endpoint - endpoint handle\n  * @xmit: Callback for outgoing packets\n@@ -21,6 +30,8 @@ struct qrtr_endpoint {\n \tint (*xmit)(struct qrtr_endpoint *ep, struct sk_buff *skb);\n \t/* private: not for endpoint use */\n \tstruct qrtr_node *node;\n+\tstruct qrtr_node_lookup_helper helper;\n+\tu32 id;\n };\n \n int qrtr_endpoint_register(struct qrtr_endpoint *ep, unsigned int nid);\n@@ -33,4 +44,7 @@ int qrtr_ns_init(void);\n \n void qrtr_ns_remove(void);\n \n+int qrtr_msg_get_endpoint(struct msghdr *msg, u32 *out_endpoint_id);\n+void qrtr_sock_set_report_endpoint(struct sock *sk);\n+\n #endif\n"
}

2/1 2026/09/15 06:23 agent patch-evaluator
0m Model:
core

Args:
null

Results:
{
  "EnableConfigs": [
    "QRTR",
    "QRTR_TUN"
  ],
  "FocusSymbols": [
    "qrtr_setsockopt",
    "qrtr_getsockopt",
    "qrtr_msg_get_endpoint",
    "qrtr_sendmsg",
    "qrtr_recvmsg",
    "qrtr_endpoint_post",
    "qrtr_endpoint_register",
    "qrtr_ns_worker"
  ],
  "Reasoning": "The patch series implements endpoint-based isolation and tracking for Qualcomm IPC Router (AF_QIPCRTR) sockets. It introduces SOL_QRTR socket options (QRTR_REPORT_ENDPOINT, QRTR_BIND_ENDPOINT), ancillary control messages (QRTR_ENDPOINT) for sendmsg and recvmsg, per-endpoint radix-tree node management, and multi-endpoint tracking in the in-kernel name service (ns.c). QRTR sockets and the /dev/qrtr-tun device are fully accessible in standard QEMU virtualized environments without specialized hardware. Fuzzing is warranted to test new setsockopt/getsockopt logic, cmsg handling, and radix-tree/xarray concurrency and lifecycle management.",
  "WorthFuzzing": true
}

Instruction:
You are an expert Linux kernel maintainer and security engineer.
Your job is to review a provided patch series and evaluate whether it warrants fuzzing with syzkaller.

IMPORTANT: The changes have ALREADY been applied and committed as the HEAD commit in
your workspace. Do NOT rely on internal assumptions. You must actively use your code access
tools to inspect the actual source code, callers, and surrounding context.

================================================================================
1. CORE TRIAGE PHILOSOPHY
================================================================================
The goal of patch fuzzing is to discover crashes, regressions, exposed latent bugs,
and newly triggered assertions introduced by the patch series.

- REACHABILITY IS THE PRIMARY GATE:
  Fuzzing can only discover bugs in code that can actually execute in standard virtualized
  environments (GCE or QEMU, utilizing software-emulated devices like USB gadgets, netdev, tun/tap).
  If the modified code is structurally unreachable (see Section 2), it MUST NOT be fuzzed,
  regardless of whether it adds assertions or complex logic.

- DO NOT BLINDLY TRUST "NO FUNCTIONAL CHANGE" (NFCI) OR "REFACTORING" CLAIMS:
  Patch authors routinely label changes as "cleanups", "refactorings", or state
  "No functional change intended". Do NOT take these claims at face value.
  Code refactorings that rearrange logic, introduce helper functions, or alter state management
  in core subsystems frequently introduce subtle semantic shifts or uncover latent kernel bugs.
  If reachable executable code is modified or refactored, it MUST be fuzzed.

- NEW OR MODIFIED ASSERTIONS IN REACHABLE CODE MUST BE FUZZED:
  When a patch introduces or modifies runtime checks or assertions (e.g., WARN_ON*, VM_WARN_ON*,
  BUG_ON*, lockdep_assert*) in reachable code paths, it enforces new or stricter invariants.
  Even if the author believes the invariant always holds, fuzzing is essential to verify whether
  an unusual sequence of operations can violate it.

================================================================================
2. WHEN TO RETURN WorthFuzzing=false (NEGATIVE CRITERIA)
================================================================================
Return WorthFuzzing=false ONLY IF all modified code falls strictly into one or more of these categories:

- Non-kernel and non-executable changes:
  * Modifications to Documentation/, comments, or spelling fixes.
  * User-space directories, self-tests, samples, or scripts (e.g., tools/, samples/, scripts/, usr/)
    that do not affect the compiled kernel image (vmlinux) or kernel modules.
  * Purely decorative logging (e.g., message strings in pr_err, printk, dev_info) or tracepoints
    that do not alter control flow or data structures.
  * Build system or Kconfig changes that do not alter compiled C logic.
- Structurally unreachable hardware:
  * Vendor-specific PCIe switches, SmartNICs, or GPU drivers (e.g., mlxsw, pds_core, qed,
    ionic, amdgpu) requiring physical ASIC/PCIe cards not emulated in standard QEMU.
- Unreachable execution paths:
  * Driver teardown callbacks (.remove, .shutdown, pci_unregister_driver) executed only during
    physical PCI hot-unplug or manual sysfs driver unbinding.
  * Code paths exclusive to architectures other than the target architecture.

================================================================================
3. WHEN TO RETURN WorthFuzzing=true (POSITIVE CRITERIA)
================================================================================
Return WorthFuzzing=true whenever the patch touches reachable executable code, including:
- Core Subsystems:
  * Any logic modifications in memory management (mm/), synchronization/locking (kernel/locking/),
    BPF, scheduler, core networking, VFS, or syscall handling.
- Refactorings and Code Cleanups:
  * Any restructuring of reachable data structures, helper abstractions, or algorithm flows.
- Runtime Assertions and Defensive Checks:
  * Any introduction or alteration of assertions (WARN_ON*, VM_WARN_ON*, BUG_ON*, etc.) in reachable paths.
- Reachable Drivers and Protocols:
  * Drivers accessible via virtual buses (virtio, USB gadget, loopback, netlink, binder, sockets, etc.).

================================================================================
4. EXTRACTING FocusSymbols (PREVENTING DILUTION)
================================================================================
When WorthFuzzing=true, you must extract specific kernel functions into FocusSymbols to guide the fuzzer:

- AVOID UBIQUITOUS LIFECYCLE HOT-PATHS:
  Do NOT list generic, ubiquitous functions called by almost every program in the corpus
  (including, but not limited to: general memory allocators and deallocators, page fault
  and trap handlers, or core synchronization primitives; this is not an exhaustive list).
  Listing ubiquitous functions causes the fuzzer to classify thousands of unrelated tests as "focused",
  which severely dilutes fuzzing effort away from the actual changes.

- TARGET SPECIFIC FEATURE LOGIC AND ENTRYPOINTS:
  List functions that specifically implement the logic being added or altered, or direct API entrypoints
  for the subsystem feature under review.

- HANDLING STATIC INLINE FUNCTIONS IN HEADERS (.h):
  Compiler-inlined static functions (such as static inlines in mm/*.h or include/linux/*.h) lack
  distinct symbol addresses in vmlinux and cannot be targeted directly by symbol coverage filters.
  If the changes are primarily in static inline helpers, identify non-static, feature-specific caller
  functions in .c files that exercise them (avoiding ubiquitous lifecycle wrappers).

================================================================================
5. IDENTIFYING EnableConfigs
================================================================================
Identify any specific CONFIG_ options required to properly compile and reach the modified code:
- Inspect Kconfig files and #ifdef guards; do not make assumptions.
- Check "depends on" lines in Kconfig to include any non-standard parent subsystem configs needed.
- Strip any 'CONFIG_' prefix (e.g., return "NET_IPV4" instead of "CONFIG_NET_IPV4").
Prefer calling several tools at the same time to save round-trips.


Use set-results tool to provide results of the analysis.
It must be called exactly once before the final reply.
Ignore results of this tool.

Prompt:
Target architecture: amd64

For your convenience, here is the diff of the changes:
commit e9367e40a1c817184c46735d76d64ca5edc6c819
Author: syz-cluster <triage@syzkaller.com>
Date:   Tue Sep 15 06:23:20 2026 +0000

    syz-cluster: applied patch under review

diff --git a/include/linux/socket.h b/include/linux/socket.h
index 5a5eb12501032..d4e2ba3bd6b39 100644
--- a/include/linux/socket.h
+++ b/include/linux/socket.h
@@ -400,6 +400,7 @@ struct ucred {
 #define SOL_MCTP	285
 #define SOL_SMC		286
 #define SOL_VSOCK	287
+#define SOL_QRTR	288
 
 /* IPX options */
 #define IPX_TYPE	1
diff --git a/include/uapi/linux/qrtr.h b/include/uapi/linux/qrtr.h
index f7e2fb3d752b5..0a8667b049c3d 100644
--- a/include/uapi/linux/qrtr.h
+++ b/include/uapi/linux/qrtr.h
@@ -46,4 +46,11 @@ struct qrtr_ctrl_pkt {
 	};
 } __packed;
 
+/* setsockopt / getsockopt */
+#define QRTR_REPORT_ENDPOINT 1
+#define QRTR_BIND_ENDPOINT 2
+
+/* CMSG */
+#define QRTR_ENDPOINT 1
+
 #endif /* _LINUX_QRTR_H */
diff --git a/net/qrtr/af_qrtr.c b/net/qrtr/af_qrtr.c
index a30fa56e6aa31..7c50d32b11015 100644
--- a/net/qrtr/af_qrtr.c
+++ b/net/qrtr/af_qrtr.c
@@ -22,9 +22,14 @@
 #define QRTR_MAX_EPH_SOCKET 0x7fff
 #define QRTR_EPH_PORT_RANGE \
 		XA_LIMIT(QRTR_MIN_EPH_SOCKET, QRTR_MAX_EPH_SOCKET)
+#define QRTR_ENDPOINT_RANGE XA_LIMIT(qrtr_local_nid + 1, INT_MAX)
 
 #define QRTR_PORT_CTRL_LEGACY 0xffff
 
+enum {
+	QRTR_F_REPORT_ENDPOINT,
+};
+
 /**
  * struct qrtr_hdr_v1 - (I|R)PCrouter packet header version 1
  * @version: protocol version
@@ -78,6 +83,7 @@ struct qrtr_cb {
 	u32 src_port;
 	u32 dst_node;
 	u32 dst_port;
+	u32 endpoint_id;
 
 	u8 type;
 	u8 confirm_rx;
@@ -91,6 +97,8 @@ struct qrtr_sock {
 	struct sock sk;
 	struct sockaddr_qrtr us;
 	struct sockaddr_qrtr peer;
+	unsigned long flags;
+	u32 bound_endpoint;
 };
 
 static inline struct qrtr_sock *qrtr_sk(struct sock *sk)
@@ -99,6 +107,43 @@ static inline struct qrtr_sock *qrtr_sk(struct sock *sk)
 	return container_of(sk, struct qrtr_sock, sk);
 }
 
+void qrtr_sock_set_report_endpoint(struct sock *sk)
+{
+	struct qrtr_sock *ipc = qrtr_sk(sk);
+
+	assign_bit(QRTR_F_REPORT_ENDPOINT, &ipc->flags, 1);
+}
+
+int qrtr_msg_get_endpoint(struct msghdr *msg, u32 *out_endpoint_id)
+{
+	struct cmsghdr *cmsg;
+	u32 endpoint_id = 0;
+
+	for_each_cmsghdr(cmsg, msg) {
+		if (!CMSG_OK(msg, cmsg))
+			return -EINVAL;
+
+		if (cmsg->cmsg_level != SOL_QRTR)
+			continue;
+
+		if (cmsg->cmsg_type != QRTR_ENDPOINT)
+			return -EINVAL;
+
+		if (cmsg->cmsg_len < CMSG_LEN(sizeof(u32)))
+			return -EINVAL;
+
+		/* Endpoint ids start at 1 */
+		endpoint_id = *(u32 *)CMSG_DATA(cmsg);
+		if (!endpoint_id)
+			return -EINVAL;
+	}
+
+	if (out_endpoint_id)
+		*out_endpoint_id = endpoint_id;
+
+	return 0;
+}
+
 static unsigned int qrtr_local_nid = 1;
 
 /* for node ids */
@@ -109,9 +154,37 @@ static LIST_HEAD(qrtr_all_nodes);
 /* lock for qrtr_all_nodes and node reference */
 static DEFINE_MUTEX(qrtr_node_lock);
 
+/* endpoint id allocation management */
+static DEFINE_XARRAY_ALLOC(qrtr_endpoints);
+static u32 next_endpoint_id;
+
 /* local port allocation management */
 static DEFINE_XARRAY_ALLOC(qrtr_ports);
 
+/* The xarray API uses fixed unsigned long keys and we will have to make
+ * do with that.
+ * These keys are often a combination of node IDs and port numbers or
+ * endpoint IDs and node IDs (all currently u32).
+ * Using the high 32 bits for the node/endpoint ID and the low 32 bits for the
+ * port number/node ID will work fine to create keys on platforms where
+ * unsigned long is 64 bits wide, but obviously is not be possible on
+ * platforms where unsigned long is smaller.
+ * Virtually split up unsigned long in half and assign the upper bits to
+ * node/endpoint IDs and the lower bits to the port number/node ID, however
+ * big that may be.
+ */
+#define QRTR_XARRAY_INDEX_BITS  (8 /* CHAR_BIT */ * sizeof(unsigned long))
+#define QRTR_INDEX_HALF_BITS (QRTR_XARRAY_INDEX_BITS >> 1)
+
+#define QRTR_INDEX_HALF_UNSIGNED_MAX ((~(unsigned long)(0)) >> QRTR_INDEX_HALF_BITS)
+#define QRTR_INDEX_HALF_UNSIGNED_MIN ((unsigned long)(0))
+
+#define QRTR_INDEX_HALF_SIGNED_MAX ((long)(QRTR_INDEX_HALF_UNSIGNED_MAX) >> 1)
+#define QRTR_INDEX_HALF_SIGNED_MIN ((long)(-1) - QRTR_INDEX_HALF_SIGNED_MAX)
+
+/* endpoint not defined, i.e. endpoint 0 */
+static struct qrtr_node_lookup_helper helper0;
+
 /**
  * struct qrtr_node - endpoint node
  * @ep_lock: lock for endpoint management and callbacks
@@ -152,9 +225,11 @@ struct qrtr_tx_flow {
 #define QRTR_TX_FLOW_LOW	5
 
 static int qrtr_local_enqueue(struct qrtr_node *node, struct sk_buff *skb,
+			      u32 endpoint_id,
 			      int type, struct sockaddr_qrtr *from,
 			      struct sockaddr_qrtr *to);
 static int qrtr_bcast_enqueue(struct qrtr_node *node, struct sk_buff *skb,
+			      u32 endpoint_id,
 			      int type, struct sockaddr_qrtr *from,
 			      struct sockaddr_qrtr *to);
 static struct qrtr_sock *qrtr_port_lookup(int port);
@@ -169,9 +244,11 @@ static void __qrtr_node_release(struct kref *kref)
 {
 	struct qrtr_node *node = container_of(kref, struct qrtr_node, ref);
 	struct radix_tree_iter iter;
+	struct radix_tree_iter iter2;
 	struct qrtr_tx_flow *flow;
 	unsigned long flags;
 	void __rcu **slot;
+	void __rcu **slot2;
 	unsigned long index;
 
 	spin_lock_irqsave(&qrtr_nodes_lock, flags);
@@ -179,8 +256,18 @@ static void __qrtr_node_release(struct kref *kref)
 	 * multiple entries pointing to our released node, delete them all.
 	 */
 	radix_tree_for_each_slot(slot, &qrtr_nodes, &iter, 0) {
-		if (*slot == node)
+		struct qrtr_node_lookup_helper *helper = *slot;
+
+		if (!helper)
+			continue;
+		radix_tree_for_each_slot(slot2, &helper->nodes, &iter2, 0) {
+			if (*slot2 == node)
+				radix_tree_iter_delete(&helper->nodes, &iter2, slot2);
+		}
+		if (helper != &helper0 && radix_tree_empty(&helper->nodes)) {
 			radix_tree_iter_delete(&qrtr_nodes, &iter, slot);
+			helper->added = 0;
+		}
 	}
 	spin_unlock_irqrestore(&qrtr_nodes_lock, flags);
 
@@ -216,16 +303,23 @@ static void qrtr_node_release(struct qrtr_node *node)
  * qrtr_tx_resume() - reset flow control counter
  * @node:	qrtr_node that the QRTR_TYPE_RESUME_TX packet arrived on
  * @skb:	resume_tx packet
+ *
+ * Return: 0 on success; negative error code on failure
  */
-static void qrtr_tx_resume(struct qrtr_node *node, struct sk_buff *skb)
+static int qrtr_tx_resume(struct qrtr_node *node, struct sk_buff *skb)
 {
 	struct qrtr_ctrl_pkt *pkt = (struct qrtr_ctrl_pkt *)skb->data;
 	u64 remote_node = le32_to_cpu(pkt->client.node);
 	u32 remote_port = le32_to_cpu(pkt->client.port);
 	struct qrtr_tx_flow *flow;
-	unsigned long key;
+	unsigned long key = 0;
+
+	/* Don't check node/port for the valid range, use only low
+	 * 16 bits on 32-bit architectures.
+	 */
 
-	key = remote_node << 32 | remote_port;
+	key = ((unsigned long)(remote_node) << QRTR_INDEX_HALF_BITS) |
+	      ((unsigned long)(remote_port) & QRTR_INDEX_HALF_UNSIGNED_MAX);
 
 	flow = xa_load(&node->qrtr_tx_flow, key);
 	if (flow) {
@@ -236,6 +330,8 @@ static void qrtr_tx_resume(struct qrtr_node *node, struct sk_buff *skb)
 	}
 
 	consume_skb(skb);
+
+	return 0;
 }
 
 /**
@@ -256,11 +352,18 @@ static void qrtr_tx_resume(struct qrtr_node *node, struct sk_buff *skb)
 static int qrtr_tx_wait(struct qrtr_node *node, int dest_node, int dest_port,
 			int type)
 {
-	unsigned long key = (u64)dest_node << 32 | dest_port;
+	unsigned long key = 0;
 	struct qrtr_tx_flow *flow;
 	int confirm_rx = 0;
 	int ret;
 
+	/* Don't check node/port for the valid range, use only low
+	 * 16 bits on 32-bit architectures.
+	 */
+
+	key = ((unsigned long)(dest_node) << QRTR_INDEX_HALF_BITS) |
+	      ((unsigned long)(dest_port) & QRTR_INDEX_HALF_UNSIGNED_MAX);
+
 	/* Never set confirm_rx on non-data packets */
 	if (type != QRTR_TYPE_DATA)
 		return 0;
@@ -317,23 +420,35 @@ static int qrtr_tx_wait(struct qrtr_node *node, int dest_node, int dest_port,
  * message associated with the dropped confirm_rx message.
  * Work around this by marking the flow as having a failed transmission and
  * cause the next transmission attempt to be sent with the confirm_rx.
+ *
+ * Return: 0 on success; negative error code on failure
  */
-static void qrtr_tx_flow_failed(struct qrtr_node *node, int dest_node,
-				int dest_port)
+static int qrtr_tx_flow_failed(struct qrtr_node *node, int dest_node,
+			       int dest_port)
 {
-	unsigned long key = (u64)dest_node << 32 | dest_port;
+	unsigned long key = 0;
 	struct qrtr_tx_flow *flow;
 
+	/* Don't check node/port for the valid range, use only low
+	 * 16 bits on 32-bit architectures.
+	 */
+
+	key = ((unsigned long)(dest_node) << QRTR_INDEX_HALF_BITS) |
+	      ((unsigned long)(dest_port) & QRTR_INDEX_HALF_UNSIGNED_MAX);
+
 	flow = xa_load(&node->qrtr_tx_flow, key);
 	if (flow) {
 		spin_lock_irq(&flow->resume_tx.lock);
 		flow->tx_failed = 1;
 		spin_unlock_irq(&flow->resume_tx.lock);
 	}
+
+	return 0;
 }
 
 /* Pass an outgoing packet socket buffer to the endpoint driver. */
 static int qrtr_node_enqueue(struct qrtr_node *node, struct sk_buff *skb,
+			     u32 endpoint_id,
 			     int type, struct sockaddr_qrtr *from,
 			     struct sockaddr_qrtr *to)
 {
@@ -377,7 +492,7 @@ static int qrtr_node_enqueue(struct qrtr_node *node, struct sk_buff *skb,
 	/* Need to ensure that a subsequent message carries the otherwise lost
 	 * confirm_rx flag if we dropped this one */
 	if (rc && confirm_rx)
-		qrtr_tx_flow_failed(node, to->sq_node, to->sq_port);
+		rc = qrtr_tx_flow_failed(node, to->sq_node, to->sq_port);
 
 	return rc;
 }
@@ -386,14 +501,18 @@ static int qrtr_node_enqueue(struct qrtr_node *node, struct sk_buff *skb,
  *
  * callers must release with qrtr_node_release()
  */
-static struct qrtr_node *qrtr_node_lookup(unsigned int nid)
+static struct qrtr_node *qrtr_node_lookup(unsigned int endpoint_id,
+					  unsigned int nid)
 {
-	struct qrtr_node *node;
+	struct qrtr_node *node = NULL;
+	struct qrtr_node_lookup_helper *helper = NULL;
 	unsigned long flags;
 
 	mutex_lock(&qrtr_node_lock);
 	spin_lock_irqsave(&qrtr_nodes_lock, flags);
-	node = radix_tree_lookup(&qrtr_nodes, nid);
+	helper = radix_tree_lookup(&qrtr_nodes, endpoint_id);
+	if (helper)
+		node = radix_tree_lookup(&helper->nodes, nid);
 	node = qrtr_node_acquire(node);
 	spin_unlock_irqrestore(&qrtr_nodes_lock, flags);
 	mutex_unlock(&qrtr_node_lock);
@@ -405,19 +524,51 @@ 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;
+	int rc = 0;
+	int did_insert0 = 0;
 
 	if (nid == QRTR_EP_NID_AUTO)
-		return;
+		return 0;
 
 	spin_lock_irqsave(&qrtr_nodes_lock, flags);
-	radix_tree_insert(&qrtr_nodes, nid, node);
+
+	if (!radix_tree_lookup(&helper0.nodes, nid)) {
+		rc = radix_tree_insert(&helper0.nodes, nid, node);
+		if (rc)
+			goto err_lock;
+		did_insert0 = 1;
+	}
+	if (!node->ep->helper.added) {
+		INIT_RADIX_TREE(&node->ep->helper.nodes, GFP_ATOMIC);
+		rc = radix_tree_insert(&qrtr_nodes, node->ep->id,
+				       &node->ep->helper);
+		if (rc)
+			goto err_insert0;
+		node->ep->helper.added = 1;
+	}
+	rc = radix_tree_insert(&node->ep->helper.nodes, nid, node);
+	if (rc && rc != -EEXIST)
+		goto err_insert0; // Don't revert helper insertion
+
 	if (node->nid == QRTR_EP_NID_AUTO)
 		node->nid = nid;
 	spin_unlock_irqrestore(&qrtr_nodes_lock, flags);
+
+	return 0;
+
+err_insert0:
+	if (did_insert0)
+		radix_tree_delete(&helper0.nodes, nid);
+
+err_lock:
+	spin_unlock_irqrestore(&qrtr_nodes_lock, flags);
+	return rc;
 }
 
 /**
@@ -439,6 +590,7 @@ int qrtr_endpoint_post(struct qrtr_endpoint *ep, const void *data, size_t len)
 	size_t size;
 	unsigned int ver;
 	size_t hdrlen;
+	int ret = -EINVAL;
 
 	if (len == 0 || len & 3)
 		return -EINVAL;
@@ -496,9 +648,16 @@ int qrtr_endpoint_post(struct qrtr_endpoint *ep, const void *data, size_t len)
 	if (cb->dst_port == QRTR_PORT_CTRL_LEGACY)
 		cb->dst_port = QRTR_PORT_CTRL;
 
+	cb->endpoint_id = ep->id;
+
 	if (!size || size > len || len != ALIGN(size, 4) + hdrlen)
 		goto err;
 
+	/* Don't allow remote lookups */
+	if (cb->type == QRTR_TYPE_NEW_LOOKUP ||
+	    cb->type == QRTR_TYPE_DEL_LOOKUP)
+		goto err;
+
 	if ((cb->type == QRTR_TYPE_NEW_SERVER ||
 	     cb->type == QRTR_TYPE_RESUME_TX) &&
 	    size < sizeof(struct qrtr_ctrl_pkt))
@@ -510,26 +669,39 @@ int qrtr_endpoint_post(struct qrtr_endpoint *ep, const void *data, size_t len)
 
 	skb_put_data(skb, data + hdrlen, size);
 
-	qrtr_node_assign(node, cb->src_node);
+	ret = qrtr_node_assign(node, cb->src_node);
+	if (ret)
+		goto err;
 
 	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) {
-		qrtr_tx_resume(node, skb);
+		ret = qrtr_tx_resume(node, skb);
+		if (ret)
+			goto err;
 	} else {
 		ipc = qrtr_port_lookup(cb->dst_port);
-		if (!ipc)
+		if (!ipc) {
+			ret = -EINVAL;
 			goto err;
+		}
 
-		if (sock_queue_rcv_skb(&ipc->sk, skb)) {
-			qrtr_port_put(ipc);
-			goto err;
+		/* Sockets bound to an endpoint only rx from that endpoint */
+		if (!ipc->bound_endpoint ||
+		    ipc->bound_endpoint == cb->endpoint_id) {
+			ret = sock_queue_rcv_skb(&ipc->sk, skb);
+			if (ret) {
+				qrtr_port_put(ipc);
+				goto err;
+			}
 		}
 
 		qrtr_port_put(ipc);
@@ -539,7 +711,7 @@ int qrtr_endpoint_post(struct qrtr_endpoint *ep, const void *data, size_t len)
 
 err:
 	kfree_skb(skb);
-	return -EINVAL;
+	return ret;
 
 }
 EXPORT_SYMBOL_GPL(qrtr_endpoint_post);
@@ -581,6 +753,8 @@ static struct sk_buff *qrtr_alloc_ctrl_packet(struct qrtr_ctrl_pkt **pkt,
 int qrtr_endpoint_register(struct qrtr_endpoint *ep, unsigned int nid)
 {
 	struct qrtr_node *node;
+	u32 endpoint_id;
+	int rc;
 
 	if (!ep || !ep->xmit)
 		return -EINVAL;
@@ -589,6 +763,13 @@ int qrtr_endpoint_register(struct qrtr_endpoint *ep, unsigned int nid)
 	if (!node)
 		return -ENOMEM;
 
+	rc = xa_alloc_cyclic(&qrtr_endpoints, &endpoint_id, NULL,
+			     QRTR_ENDPOINT_RANGE, &next_endpoint_id,
+			     GFP_KERNEL);
+
+	if (rc < 0)
+		goto free_node;
+
 	kref_init(&node->ref);
 	mutex_init(&node->ep_lock);
 	skb_queue_head_init(&node->rx_queue);
@@ -598,14 +779,21 @@ int qrtr_endpoint_register(struct qrtr_endpoint *ep, unsigned int nid)
 	xa_init(&node->qrtr_tx_flow);
 	mutex_init(&node->qrtr_tx_lock);
 
-	qrtr_node_assign(node, nid);
+	rc = qrtr_node_assign(node, nid);
+	if (rc < 0)
+		goto free_node;
 
 	mutex_lock(&qrtr_node_lock);
 	list_add(&node->item, &qrtr_all_nodes);
 	mutex_unlock(&qrtr_node_lock);
 	ep->node = node;
+	ep->id = endpoint_id;
+	ep->helper.added = 0;
 
 	return 0;
+free_node:
+	kfree(node);
+	return rc;
 }
 EXPORT_SYMBOL_GPL(qrtr_endpoint_register);
 
@@ -619,29 +807,46 @@ void qrtr_endpoint_unregister(struct qrtr_endpoint *ep)
 	struct sockaddr_qrtr src = {AF_QIPCRTR, node->nid, QRTR_PORT_CTRL};
 	struct sockaddr_qrtr dst = {AF_QIPCRTR, qrtr_local_nid, QRTR_PORT_CTRL};
 	struct radix_tree_iter iter;
+	struct radix_tree_iter iter2;
 	struct qrtr_ctrl_pkt *pkt;
 	struct qrtr_tx_flow *flow;
 	struct sk_buff *skb;
 	unsigned long flags;
 	unsigned long index;
 	void __rcu **slot;
+	void __rcu **slot2;
+	u32 endpoint_id;
 
 	mutex_lock(&node->ep_lock);
+	endpoint_id = node->ep->id;
 	node->ep = NULL;
 	mutex_unlock(&node->ep_lock);
 
 	/* Notify the local controller about the event */
 	spin_lock_irqsave(&qrtr_nodes_lock, flags);
 	radix_tree_for_each_slot(slot, &qrtr_nodes, &iter, 0) {
-		if (*slot != node)
+		struct qrtr_node_lookup_helper *helper = *slot;
+
+		if (!helper)
 			continue;
-		src.sq_node = iter.index;
-		skb = qrtr_alloc_ctrl_packet(&pkt, GFP_ATOMIC);
-		if (skb) {
-			pkt->cmd = cpu_to_le32(QRTR_TYPE_BYE);
-			qrtr_local_enqueue(NULL, skb, QRTR_TYPE_BYE, &src, &dst);
+		radix_tree_for_each_slot(slot2, &helper->nodes, &iter2, 0) {
+			if (*slot2 != node)
+				continue;
+			src.sq_node = iter.index;
+			skb = qrtr_alloc_ctrl_packet(&pkt, GFP_ATOMIC);
+			if (skb) {
+				pkt->cmd = cpu_to_le32(QRTR_TYPE_BYE);
+				qrtr_local_enqueue(NULL, skb, endpoint_id,
+						   QRTR_TYPE_BYE, &src, &dst);
+			}
 		}
 	}
+	if (ep->helper.added) {
+		radix_tree_for_each_slot(slot, &ep->helper.nodes, &iter, 0)
+			radix_tree_iter_delete(&ep->helper.nodes, &iter, slot);
+		radix_tree_delete(&qrtr_nodes, ep->id);
+		ep->helper.added = 0;
+	}
 	spin_unlock_irqrestore(&qrtr_nodes_lock, flags);
 
 	/* Wake up any transmitters waiting for resume-tx from the node */
@@ -651,6 +856,10 @@ void qrtr_endpoint_unregister(struct qrtr_endpoint *ep)
 	mutex_unlock(&node->qrtr_tx_lock);
 
 	qrtr_node_release(node);
+
+	xa_erase(&qrtr_endpoints, endpoint_id);
+
+	ep->id = 0;
 	ep->node = NULL;
 }
 EXPORT_SYMBOL_GPL(qrtr_endpoint_unregister);
@@ -700,8 +909,8 @@ static void qrtr_port_remove(struct qrtr_sock *ipc)
 		pkt->client.port = cpu_to_le32(ipc->us.sq_port);
 
 		skb_set_owner_w(skb, &ipc->sk);
-		qrtr_bcast_enqueue(NULL, skb, QRTR_TYPE_DEL_CLIENT, &ipc->us,
-				   &to);
+		qrtr_bcast_enqueue(NULL, skb, qrtr_local_nid,
+				   QRTR_TYPE_DEL_CLIENT, &ipc->us, &to);
 	}
 
 	if (port == QRTR_PORT_CTRL)
@@ -841,37 +1050,52 @@ static int qrtr_bind(struct socket *sock, struct sockaddr_unsized *saddr, int le
 
 /* Queue packet to local peer socket. */
 static int qrtr_local_enqueue(struct qrtr_node *node, struct sk_buff *skb,
+			      u32 endpoint_id,
 			      int type, struct sockaddr_qrtr *from,
 			      struct sockaddr_qrtr *to)
 {
 	struct qrtr_sock *ipc;
 	struct qrtr_cb *cb;
+	int ret = -ENODEV;
 
 	ipc = qrtr_port_lookup(to->sq_port);
-	if (!ipc || &ipc->sk == skb->sk) { /* do not send to self */
-		if (ipc)
-			qrtr_port_put(ipc);
-		kfree_skb(skb);
-		return -ENODEV;
-	}
+	if (!ipc)
+		goto done;
+
+	if (&ipc->sk == skb->sk) /* do not send to self */
+		goto done;
+
+	/*
+	 * Filter out unwanted packets that are not on behalf of the bound
+	 * endpoint.  Certain special packets (such as an empty NEW_SERVER
+	 * packet that serves as a sentinel value) always go through.
+	 */
+	if (endpoint_id && ipc->bound_endpoint &&
+	    ipc->bound_endpoint != endpoint_id)
+		goto done;
 
 	cb = (struct qrtr_cb *)skb->cb;
 	cb->src_node = from->sq_node;
 	cb->src_port = from->sq_port;
+	cb->endpoint_id = endpoint_id;
 
-	if (sock_queue_rcv_skb(&ipc->sk, skb)) {
-		qrtr_port_put(ipc);
-		kfree_skb(skb);
-		return -ENOSPC;
-	}
+	ret = -ENOSPC;
+	if (sock_queue_rcv_skb(&ipc->sk, skb))
+		goto done;
 
 	qrtr_port_put(ipc);
 
 	return 0;
+done:
+	if (ipc)
+		qrtr_port_put(ipc);
+	kfree_skb(skb);
+	return ret;
 }
 
 /* Queue packet for broadcast. */
 static int qrtr_bcast_enqueue(struct qrtr_node *node, struct sk_buff *skb,
+			      u32 endpoint_id,
 			      int type, struct sockaddr_qrtr *from,
 			      struct sockaddr_qrtr *to)
 {
@@ -883,11 +1107,11 @@ static int qrtr_bcast_enqueue(struct qrtr_node *node, struct sk_buff *skb,
 		if (!skbn)
 			break;
 		skb_set_owner_w(skbn, skb->sk);
-		qrtr_node_enqueue(node, skbn, type, from, to);
+		qrtr_node_enqueue(node, skbn, endpoint_id, type, from, to);
 	}
 	mutex_unlock(&qrtr_node_lock);
 
-	qrtr_local_enqueue(NULL, skb, type, from, to);
+	qrtr_local_enqueue(NULL, skb, endpoint_id, type, from, to);
 
 	return 0;
 }
@@ -895,12 +1119,16 @@ static int qrtr_bcast_enqueue(struct qrtr_node *node, struct sk_buff *skb,
 static int qrtr_sendmsg(struct socket *sock, struct msghdr *msg, size_t len)
 {
 	DECLARE_SOCKADDR(struct sockaddr_qrtr *, addr, msg->msg_name);
-	int (*enqueue_fn)(struct qrtr_node *, struct sk_buff *, int,
-			  struct sockaddr_qrtr *, struct sockaddr_qrtr *);
+	int (*enqueue_fn)(struct qrtr_node *node, struct sk_buff *skb,
+			  u32 endpoint_id, int type,
+			  struct sockaddr_qrtr *from,
+			  struct sockaddr_qrtr *to);
 	__le32 qrtr_type = cpu_to_le32(QRTR_TYPE_DATA);
 	struct qrtr_sock *ipc = qrtr_sk(sock->sk);
 	struct sock *sk = sock->sk;
 	struct qrtr_node *node;
+	u32 msg_endpoint_id;
+	u32 endpoint_id = qrtr_local_nid;
 	struct sk_buff *skb;
 	size_t plen;
 	u32 type;
@@ -912,46 +1140,49 @@ static int qrtr_sendmsg(struct socket *sock, struct msghdr *msg, size_t len)
 	if (len > 65535)
 		return -EMSGSIZE;
 
+	rc = qrtr_msg_get_endpoint(msg, &msg_endpoint_id);
+	if (rc < 0)
+		return rc;
+
 	lock_sock(sk);
 
 	if (addr) {
-		if (msg->msg_namelen < sizeof(*addr)) {
-			release_sock(sk);
-			return -EINVAL;
-		}
+		rc = -EINVAL;
 
-		if (addr->sq_family != AF_QIPCRTR) {
-			release_sock(sk);
-			return -EINVAL;
-		}
+		if (msg->msg_namelen < sizeof(*addr))
+			goto release_sock;
+
+		if (addr->sq_family != AF_QIPCRTR)
+			goto release_sock;
 
 		rc = qrtr_autobind(sock);
-		if (rc) {
-			release_sock(sk);
-			return rc;
-		}
+		if (rc)
+			goto release_sock;
 	} else if (sk->sk_state == TCP_ESTABLISHED) {
 		addr = &ipc->peer;
 	} else {
-		release_sock(sk);
-		return -ENOTCONN;
+		rc = -ENOTCONN;
+		goto release_sock;
 	}
 
 	node = NULL;
 	if (addr->sq_node == QRTR_NODE_BCAST) {
 		if (addr->sq_port != QRTR_PORT_CTRL &&
 		    qrtr_local_nid != QRTR_NODE_BCAST) {
-			release_sock(sk);
-			return -ENOTCONN;
+			rc = -ENOTCONN;
+			goto release_sock;
 		}
 		enqueue_fn = qrtr_bcast_enqueue;
 	} else if (addr->sq_node == ipc->us.sq_node) {
 		enqueue_fn = qrtr_local_enqueue;
 	} else {
-		node = qrtr_node_lookup(addr->sq_node);
+		endpoint_id = msg_endpoint_id ?
+			      msg_endpoint_id : ipc->bound_endpoint;
+
+		node = qrtr_node_lookup(endpoint_id, addr->sq_node);
 		if (!node) {
-			release_sock(sk);
-			return -ECONNRESET;
+			rc = endpoint_id ? -ENXIO : -ECONNRESET;
+			goto release_sock;
 		}
 		enqueue_fn = qrtr_node_enqueue;
 	}
@@ -981,15 +1212,21 @@ static int qrtr_sendmsg(struct socket *sock, struct msghdr *msg, size_t len)
 
 		/* control messages already require the type as 'command' */
 		skb_copy_bits(skb, 0, &qrtr_type, 4);
+		/*
+		 * Allow local name service to make packets appear as if
+		 * they originated remotely
+		 */
+		endpoint_id = msg_endpoint_id;
 	}
 
 	type = le32_to_cpu(qrtr_type);
-	rc = enqueue_fn(node, skb, type, &ipc->us, addr);
+	rc = enqueue_fn(node, skb, endpoint_id, type, &ipc->us, addr);
 	if (rc >= 0)
 		rc = len;
 
 out_node:
 	qrtr_node_release(node);
+release_sock:
 	release_sock(sk);
 
 	return rc;
@@ -1004,7 +1241,7 @@ static int qrtr_send_resume_tx(struct qrtr_cb *cb)
 	struct sk_buff *skb;
 	int ret;
 
-	node = qrtr_node_lookup(remote.sq_node);
+	node = qrtr_node_lookup(cb->endpoint_id, remote.sq_node);
 	if (!node)
 		return -EINVAL;
 
@@ -1018,7 +1255,8 @@ static int qrtr_send_resume_tx(struct qrtr_cb *cb)
 	pkt->client.node = cpu_to_le32(cb->dst_node);
 	pkt->client.port = cpu_to_le32(cb->dst_port);
 
-	ret = qrtr_node_enqueue(node, skb, QRTR_TYPE_RESUME_TX, &local, &remote);
+	ret = qrtr_node_enqueue(node, skb, cb->endpoint_id,
+				QRTR_TYPE_RESUME_TX, &local, &remote);
 
 	qrtr_node_release(node);
 
@@ -1029,6 +1267,7 @@ static int qrtr_recvmsg(struct socket *sock, struct msghdr *msg,
 			size_t size, int flags)
 {
 	DECLARE_SOCKADDR(struct sockaddr_qrtr *, addr, msg->msg_name);
+	struct qrtr_sock *ipc = qrtr_sk(sock->sk);
 	struct sock *sk = sock->sk;
 	struct sk_buff *skb;
 	struct qrtr_cb *cb;
@@ -1054,6 +1293,10 @@ static int qrtr_recvmsg(struct socket *sock, struct msghdr *msg,
 		msg->msg_flags |= MSG_TRUNC;
 	}
 
+	if (cb->endpoint_id && test_bit(QRTR_F_REPORT_ENDPOINT, &ipc->flags))
+		put_cmsg(msg, SOL_QRTR, QRTR_ENDPOINT,
+			 sizeof(cb->endpoint_id), &cb->endpoint_id);
+
 	rc = skb_copy_datagram_msg(skb, 0, msg, copied);
 	if (rc < 0)
 		goto out;
@@ -1199,6 +1442,74 @@ static int qrtr_ioctl(struct socket *sock, unsigned int cmd, unsigned long arg)
 	return rc;
 }
 
+static int qrtr_setsockopt(struct socket *sock, int level, int optname,
+			   sockptr_t optval, unsigned int optlen)
+{
+	struct qrtr_sock *ipc = qrtr_sk(sock->sk);
+	unsigned int val = 0;
+	int rc = 0;
+
+	if (level != SOL_QRTR)
+		return -ENOPROTOOPT;
+
+	if (optlen >= sizeof(val) &&
+	    copy_from_sockptr(&val, optval, sizeof(val)))
+		return -EFAULT;
+
+	switch (optname) {
+	case QRTR_REPORT_ENDPOINT:
+		assign_bit(QRTR_F_REPORT_ENDPOINT, &ipc->flags, val);
+		break;
+	case QRTR_BIND_ENDPOINT:
+		WRITE_ONCE(ipc->bound_endpoint, val);
+		break;
+	default:
+		rc = -ENOPROTOOPT;
+	}
+
+	return rc;
+}
+
+static int qrtr_getsockopt(struct socket *sock, int level, int optname,
+			   char __user *optval, int __user *optlen)
+{
+	struct qrtr_sock *ipc = qrtr_sk(sock->sk);
+	unsigned int val;
+	int len;
+	int rc = 0;
+
+	if (level != SOL_QRTR)
+		return -ENOPROTOOPT;
+
+	if (get_user(len, optlen))
+		return -EFAULT;
+
+	if (len < sizeof(val))
+		return -EINVAL;
+
+	switch (optname) {
+	case QRTR_REPORT_ENDPOINT:
+		val = test_bit(QRTR_F_REPORT_ENDPOINT, &ipc->flags);
+		break;
+	case QRTR_BIND_ENDPOINT:
+		val = READ_ONCE(ipc->bound_endpoint);
+		break;
+	default:
+		rc = -ENOPROTOOPT;
+	}
+
+	if (rc)
+		return rc;
+
+	len = sizeof(int);
+
+	if (put_user(len, optlen) ||
+	    copy_to_user(optval, &val, len))
+		rc = -EFAULT;
+
+	return rc;
+}
+
 static int qrtr_release(struct socket *sock)
 {
 	struct sock *sk = sock->sk;
@@ -1246,6 +1557,8 @@ static const struct proto_ops qrtr_proto_ops = {
 	.shutdown	= sock_no_shutdown,
 	.release	= qrtr_release,
 	.mmap		= sock_no_mmap,
+	.setsockopt	= qrtr_setsockopt,
+	.getsockopt	= qrtr_getsockopt,
 };
 
 static struct proto qrtr_proto = {
@@ -1310,8 +1623,17 @@ static int __init qrtr_proto_init(void)
 	if (rc)
 		goto err_sock;
 
+	rc = radix_tree_insert(&qrtr_nodes, 0, &helper0);
+	if (rc)
+		goto err_ns;
+
+	INIT_RADIX_TREE(&helper0.nodes, GFP_ATOMIC);
+	helper0.added = 1;
+
 	return 0;
 
+err_ns:
+	qrtr_ns_remove();
 err_sock:
 	sock_unregister(qrtr_family.family);
 err_proto:
@@ -1322,6 +1644,7 @@ postcore_initcall(qrtr_proto_init);
 
 static void __exit qrtr_proto_fini(void)
 {
+	radix_tree_delete(&qrtr_nodes, 0);
 	qrtr_ns_remove();
 	sock_unregister(qrtr_family.family);
 	proto_unregister(&qrtr_proto);
diff --git a/net/qrtr/mhi.c b/net/qrtr/mhi.c
index 3990da1a65dc4..630ce0da060e5 100644
--- a/net/qrtr/mhi.c
+++ b/net/qrtr/mhi.c
@@ -106,6 +106,16 @@ static int qcom_mhi_qrtr_queue_dl_buffers(struct mhi_device *mhi_dev)
 	return 0;
 }
 
+static ssize_t endpoint_show(struct device *dev,
+			     struct device_attribute *attr, char *buf)
+{
+	struct qrtr_mhi_dev *qdev = dev_get_drvdata(dev);
+
+	return sprintf(buf, "%u\n", qdev->ep.id);
+}
+
+static DEVICE_ATTR_RO(endpoint);
+
 static int qcom_mhi_qrtr_probe(struct mhi_device *mhi_dev,
 			       const struct mhi_device_id *id)
 {
@@ -135,6 +145,9 @@ static int qcom_mhi_qrtr_probe(struct mhi_device *mhi_dev,
 	if (rc)
 		goto err_unregister;
 
+	if (device_create_file(&mhi_dev->dev, &dev_attr_endpoint) < 0)
+		dev_err(qdev->dev, "Failed to create endpoint attribute\n");
+
 	dev_dbg(qdev->dev, "Qualcomm MHI QRTR driver probed\n");
 
 	return 0;
@@ -151,6 +164,7 @@ static void qcom_mhi_qrtr_remove(struct mhi_device *mhi_dev)
 {
 	struct qrtr_mhi_dev *qdev = dev_get_drvdata(&mhi_dev->dev);
 
+	device_remove_file(&mhi_dev->dev, &dev_attr_endpoint);
 	qrtr_endpoint_unregister(&qdev->ep);
 	mhi_unprepare_from_transfer(mhi_dev);
 	dev_set_drvdata(&mhi_dev->dev, NULL);
diff --git a/net/qrtr/ns.c b/net/qrtr/ns.c
index c5e7e01db2498..31dfa764e186a 100644
--- a/net/qrtr/ns.c
+++ b/net/qrtr/ns.c
@@ -5,6 +5,7 @@
  * Copyright (c) 2020, Linaro Ltd.
  */
 
+#define pr_fmt(fmt) "QRTR NS: "fmt
 #include <linux/module.h>
 #include <linux/qrtr.h>
 #include <linux/workqueue.h>
@@ -16,7 +17,7 @@
 #define CREATE_TRACE_POINTS
 #include <trace/events/qrtr.h>
 
-static DEFINE_XARRAY(nodes);
+static DEFINE_XARRAY(endpoints);
 
 static struct {
 	struct socket *sock;
@@ -62,6 +63,7 @@ struct qrtr_server {
 
 	unsigned int node;
 	unsigned int port;
+	u32 endpoint_id;
 
 	struct list_head qli;
 };
@@ -72,6 +74,11 @@ struct qrtr_node {
 	u32 server_count;
 };
 
+struct qrtr_ns_endpoint {
+	unsigned int id;
+	struct xarray nodes;
+};
+
 /* Max nodes, server, lookup limits are chosen based on the current platform
  * requirements. If the requirement changes in the future, these values can be
  * increased.
@@ -82,35 +89,90 @@ struct qrtr_node {
 
 static u16 node_count;
 
-static struct qrtr_node *node_get(unsigned int node_id)
+static struct qrtr_node *node_get(u32 endpoint_id, unsigned int node_id)
 {
+	struct qrtr_ns_endpoint *endpoint;
 	struct qrtr_node *node;
+	bool new_endpoint = false;
+
+	endpoint = xa_load(&endpoints, endpoint_id);
+	if (!endpoint) {
+		endpoint = kzalloc_obj(*endpoint);
+		if (!endpoint)
+			return NULL;
+
+		endpoint->id = endpoint_id;
+		xa_init(&endpoint->nodes);
+
+		if (xa_store(&endpoints, endpoint_id, endpoint, GFP_KERNEL)) {
+			kfree(endpoint);
+			return NULL;
+		}
+
+		new_endpoint = true;
+	}
 
-	node = xa_load(&nodes, node_id);
+	node = xa_load(&endpoint->nodes, node_id);
 	if (node)
 		return node;
 
 	if (node_count >= QRTR_NS_MAX_NODES) {
 		pr_err_ratelimited("QRTR clients exceed max node limit!\n");
-		return NULL;
+		goto error;
 	}
 
 	/* If node didn't exist, allocate and insert it to the tree */
 	node = kzalloc_obj(*node);
 	if (!node)
-		return NULL;
+		goto error;
 
 	node->id = node_id;
 	xa_init(&node->servers);
 
-	if (xa_store(&nodes, node_id, node, GFP_KERNEL)) {
+	if (xa_store(&endpoint->nodes, node_id, node, GFP_KERNEL)) {
 		kfree(node);
-		return NULL;
+		goto error;
 	}
 
 	node_count++;
 
 	return node;
+error:
+	if (new_endpoint) {
+		xa_erase(&endpoints, endpoint_id);
+		kfree(endpoint);
+	}
+
+	return NULL;
+}
+
+static void node_erase(u32 endpoint_id, unsigned int node_id)
+{
+	struct qrtr_ns_endpoint *endpoint;
+	struct qrtr_node *node;
+
+	endpoint = xa_load(&endpoints, endpoint_id);
+	if (!endpoint)
+		return;
+
+	node = xa_load(&endpoint->nodes, node_id);
+	if (!node)
+		return;
+
+	xa_erase(&endpoint->nodes, node_id);
+	kfree(node);
+	node_count--;
+}
+
+static struct qrtr_node *node_lookup(u32 endpoint_id, unsigned int node_id)
+{
+	struct qrtr_ns_endpoint *endpoint;
+
+	endpoint = xa_load(&endpoints, endpoint_id);
+	if (!endpoint)
+		return NULL;
+
+	return xa_load(&endpoint->nodes, node_id);
 }
 
 static int server_match(const struct qrtr_server *srv,
@@ -126,19 +188,42 @@ static int server_match(const struct qrtr_server *srv,
 	return (srv->instance & ifilter) == f->instance;
 }
 
-static int service_announce_new(struct sockaddr_qrtr *dest,
-				struct qrtr_server *srv)
+static int qrtr_ns_sendmsg(u32 endpoint_id, struct sockaddr_qrtr *dest,
+			   struct qrtr_ctrl_pkt *pkt)
 {
-	struct qrtr_ctrl_pkt pkt;
 	struct msghdr msg = { };
 	struct kvec iv;
+	u8 control[CMSG_SPACE(sizeof(endpoint_id))];
+	struct cmsghdr *cmsg;
+
+	iv.iov_base = pkt;
+	iv.iov_len = sizeof(*pkt);
+
+	msg.msg_name = (struct sockaddr *)dest;
+	msg.msg_namelen = sizeof(*dest);
+
+	if (endpoint_id) {
+		msg.msg_control = control;
+		msg.msg_controllen = sizeof(control);
+
+		cmsg = CMSG_FIRSTHDR(&msg);
+		cmsg->cmsg_level = SOL_QRTR;
+		cmsg->cmsg_type = QRTR_ENDPOINT;
+		cmsg->cmsg_len = CMSG_LEN(sizeof(endpoint_id));
+		memcpy(CMSG_DATA(cmsg), &endpoint_id, sizeof(endpoint_id));
+	}
+
+	return kernel_sendmsg(qrtr_ns.sock, &msg, &iv, 1, sizeof(*pkt));
+}
+
+static int service_announce_new(u32 endpoint_id, struct sockaddr_qrtr *dest,
+				struct qrtr_server *srv)
+{
+	struct qrtr_ctrl_pkt pkt;
 
 	trace_qrtr_ns_service_announce_new(srv->service, srv->instance,
 					   srv->node, srv->port);
 
-	iv.iov_base = &pkt;
-	iv.iov_len = sizeof(pkt);
-
 	memset(&pkt, 0, sizeof(pkt));
 	pkt.cmd = cpu_to_le32(QRTR_TYPE_NEW_SERVER);
 	pkt.server.service = cpu_to_le32(srv->service);
@@ -146,26 +231,18 @@ static int service_announce_new(struct sockaddr_qrtr *dest,
 	pkt.server.node = cpu_to_le32(srv->node);
 	pkt.server.port = cpu_to_le32(srv->port);
 
-	msg.msg_name = (struct sockaddr *)dest;
-	msg.msg_namelen = sizeof(*dest);
-
-	return kernel_sendmsg(qrtr_ns.sock, &msg, &iv, 1, sizeof(pkt));
+	return qrtr_ns_sendmsg(endpoint_id, dest, &pkt);
 }
 
-static void service_announce_del(struct sockaddr_qrtr *dest,
+static void service_announce_del(u32 endpoint_id, struct sockaddr_qrtr *dest,
 				 struct qrtr_server *srv)
 {
 	struct qrtr_ctrl_pkt pkt;
-	struct msghdr msg = { };
-	struct kvec iv;
 	int ret;
 
 	trace_qrtr_ns_service_announce_del(srv->service, srv->instance,
 					   srv->node, srv->port);
 
-	iv.iov_base = &pkt;
-	iv.iov_len = sizeof(pkt);
-
 	memset(&pkt, 0, sizeof(pkt));
 	pkt.cmd = cpu_to_le32(QRTR_TYPE_DEL_SERVER);
 	pkt.server.service = cpu_to_le32(srv->service);
@@ -173,26 +250,24 @@ static void service_announce_del(struct sockaddr_qrtr *dest,
 	pkt.server.node = cpu_to_le32(srv->node);
 	pkt.server.port = cpu_to_le32(srv->port);
 
-	msg.msg_name = (struct sockaddr *)dest;
-	msg.msg_namelen = sizeof(*dest);
-
-	ret = kernel_sendmsg(qrtr_ns.sock, &msg, &iv, 1, sizeof(pkt));
+	ret = qrtr_ns_sendmsg(endpoint_id, dest, &pkt);
 	if (ret < 0 && ret != -ENODEV)
 		pr_err("failed to announce del service\n");
 
 	return;
 }
 
-static void lookup_notify(struct sockaddr_qrtr *to, struct qrtr_server *srv,
-			  bool new)
+static void lookup_notify(u32 endpoint_id, struct sockaddr_qrtr *to,
+			  struct qrtr_server *srv, bool new)
 {
 	struct qrtr_ctrl_pkt pkt;
-	struct msghdr msg = { };
-	struct kvec iv;
 	int ret;
 
-	iv.iov_base = &pkt;
-	iv.iov_len = sizeof(pkt);
+	/*
+	 * Notify a local client at @to about a server change.  The aux data
+	 * will look as if it came from the endpoint that reported the event
+	 * (remote or local)
+	 */
 
 	memset(&pkt, 0, sizeof(pkt));
 	pkt.cmd = new ? cpu_to_le32(QRTR_TYPE_NEW_SERVER) :
@@ -204,28 +279,25 @@ static void lookup_notify(struct sockaddr_qrtr *to, struct qrtr_server *srv,
 		pkt.server.port = cpu_to_le32(srv->port);
 	}
 
-	msg.msg_name = (struct sockaddr *)to;
-	msg.msg_namelen = sizeof(*to);
-
-	ret = kernel_sendmsg(qrtr_ns.sock, &msg, &iv, 1, sizeof(pkt));
+	ret = qrtr_ns_sendmsg(endpoint_id, to, &pkt);
 	if (ret < 0 && ret != -ENODEV)
 		pr_err("failed to send lookup notification\n");
 }
 
-static int announce_servers(struct sockaddr_qrtr *sq)
+static int announce_servers(u32 endpoint_id, struct sockaddr_qrtr *sq)
 {
 	struct qrtr_server *srv;
 	struct qrtr_node *node;
 	unsigned long index;
 	int ret;
 
-	node = node_get(qrtr_ns.local_node);
+	node = node_lookup(qrtr_ns.local_node, qrtr_ns.local_node);
 	if (!node)
 		return 0;
 
-	/* Announce the list of servers registered in this node */
+	/* Announce servers registered on local endpoint to remote endpoint */
 	xa_for_each(&node->servers, index, srv) {
-		ret = service_announce_new(sq, srv);
+		ret = service_announce_new(endpoint_id, sq, srv);
 		if (ret < 0) {
 			if (ret == -ENODEV)
 				continue;
@@ -237,7 +309,8 @@ static int announce_servers(struct sockaddr_qrtr *sq)
 	return 0;
 }
 
-static struct qrtr_server *server_add(unsigned int service,
+static struct qrtr_server *server_add(u32 endpoint_id,
+				      unsigned int service,
 				      unsigned int instance,
 				      unsigned int node_id,
 				      unsigned int port)
@@ -249,7 +322,7 @@ static struct qrtr_server *server_add(unsigned int service,
 	if (!service || !port)
 		return NULL;
 
-	node = node_get(node_id);
+	node = node_get(endpoint_id, node_id);
 	if (!node)
 		return NULL;
 
@@ -293,7 +366,8 @@ static struct qrtr_server *server_add(unsigned int service,
 	return NULL;
 }
 
-static int server_del(struct qrtr_node *node, unsigned int port, bool bcast)
+static int server_del(u32 endpoint_id, struct qrtr_node *node,
+		      unsigned int port, bool bcast)
 {
 	struct qrtr_lookup *lookup;
 	struct qrtr_server *srv;
@@ -305,9 +379,10 @@ static int server_del(struct qrtr_node *node, unsigned int port, bool bcast)
 
 	xa_erase(&node->servers, port);
 
-	/* Broadcast the removal of local servers */
+	/* Broadcast the removal of local servers to remote endpoints */
 	if (srv->node == qrtr_ns.local_node && bcast)
-		service_announce_del(&qrtr_ns.bcast_sq, srv);
+		service_announce_del(qrtr_ns.local_node,
+				     &qrtr_ns.bcast_sq, srv);
 
 	/* Announce the service's disappearance to observers */
 	list_for_each(li, &qrtr_ns.lookups) {
@@ -317,7 +392,7 @@ static int server_del(struct qrtr_node *node, unsigned int port, bool bcast)
 		if (lookup->instance && lookup->instance != srv->instance)
 			continue;
 
-		lookup_notify(&lookup->sq, srv, false);
+		lookup_notify(endpoint_id, &lookup->sq, srv, false);
 	}
 
 	kfree(srv);
@@ -326,23 +401,15 @@ static int server_del(struct qrtr_node *node, unsigned int port, bool bcast)
 	return 0;
 }
 
-static int say_hello(struct sockaddr_qrtr *dest)
+static int say_hello(u32 endpoint_id, struct sockaddr_qrtr *dest)
 {
 	struct qrtr_ctrl_pkt pkt;
-	struct msghdr msg = { };
-	struct kvec iv;
 	int ret;
 
-	iv.iov_base = &pkt;
-	iv.iov_len = sizeof(pkt);
-
 	memset(&pkt, 0, sizeof(pkt));
 	pkt.cmd = cpu_to_le32(QRTR_TYPE_HELLO);
 
-	msg.msg_name = (struct sockaddr *)dest;
-	msg.msg_namelen = sizeof(*dest);
-
-	ret = kernel_sendmsg(qrtr_ns.sock, &msg, &iv, 1, sizeof(pkt));
+	ret = qrtr_ns_sendmsg(endpoint_id, dest, &pkt);
 	if (ret < 0)
 		pr_err("failed to send hello msg\n");
 
@@ -350,42 +417,38 @@ static int say_hello(struct sockaddr_qrtr *dest)
 }
 
 /* Announce the list of servers registered on the local node */
-static int ctrl_cmd_hello(struct sockaddr_qrtr *sq)
+static int ctrl_cmd_hello(u32 endpoint_id, struct sockaddr_qrtr *sq)
 {
 	int ret;
 
-	ret = say_hello(sq);
+	/* Send Hello and New Server messages to remote endpoint */
+	ret = say_hello(endpoint_id, sq);
 	if (ret < 0)
 		return ret;
 
-	return announce_servers(sq);
+	return announce_servers(endpoint_id, sq);
 }
 
-static int ctrl_cmd_bye(struct sockaddr_qrtr *from)
+static int ctrl_cmd_bye(u32 endpoint_id, struct sockaddr_qrtr *from)
 {
 	struct qrtr_node *local_node;
 	struct qrtr_ctrl_pkt pkt;
 	struct qrtr_server *srv;
 	struct sockaddr_qrtr sq;
-	struct msghdr msg = { };
 	struct qrtr_node *node;
 	unsigned long index;
-	struct kvec iv;
 	int ret = 0;
 
-	iv.iov_base = &pkt;
-	iv.iov_len = sizeof(pkt);
-
-	node = node_get(from->sq_node);
+	node = node_get(endpoint_id, from->sq_node);
 	if (!node)
 		return 0;
 
 	/* Advertise removal of this client to all servers of remote node */
 	xa_for_each(&node->servers, index, srv)
-		server_del(node, srv->port, true);
+		server_del(endpoint_id, node, srv->port, true);
 
 	/* Advertise the removal of this client to all local servers */
-	local_node = node_get(qrtr_ns.local_node);
+	local_node = node_get(qrtr_ns.local_node, qrtr_ns.local_node);
 	if (!local_node) {
 		ret = 0;
 		goto delete_node;
@@ -400,10 +463,8 @@ static int ctrl_cmd_bye(struct sockaddr_qrtr *from)
 		sq.sq_node = srv->node;
 		sq.sq_port = srv->port;
 
-		msg.msg_name = (struct sockaddr *)&sq;
-		msg.msg_namelen = sizeof(sq);
-
-		ret = kernel_sendmsg(qrtr_ns.sock, &msg, &iv, 1, sizeof(pkt));
+		/* Bye will look as if it came from endpoint_id */
+		ret = qrtr_ns_sendmsg(endpoint_id, &sq, &pkt);
 		if (ret < 0 && ret != -ENODEV) {
 			pr_err("failed to send bye cmd\n");
 			goto delete_node;
@@ -414,32 +475,25 @@ static int ctrl_cmd_bye(struct sockaddr_qrtr *from)
 	ret = 0;
 
 delete_node:
-	xa_erase(&nodes, from->sq_node);
-	kfree(node);
-	node_count--;
+	node_erase(endpoint_id, from->sq_node);
 
 	return ret;
 }
 
-static int ctrl_cmd_del_client(struct sockaddr_qrtr *from,
+static int ctrl_cmd_del_client(u32 endpoint_id, struct sockaddr_qrtr *from,
 			       unsigned int node_id, unsigned int port)
 {
 	struct qrtr_node *local_node;
 	struct qrtr_lookup *lookup;
 	struct qrtr_ctrl_pkt pkt;
-	struct msghdr msg = { };
 	struct qrtr_server *srv;
 	struct sockaddr_qrtr sq;
 	struct qrtr_node *node;
 	struct list_head *tmp;
 	struct list_head *li;
 	unsigned long index;
-	struct kvec iv;
 	int ret;
 
-	iv.iov_base = &pkt;
-	iv.iov_len = sizeof(pkt);
-
 	/* Don't accept spoofed messages */
 	if (from->sq_node != node_id)
 		return -EINVAL;
@@ -465,12 +519,12 @@ static int ctrl_cmd_del_client(struct sockaddr_qrtr *from,
 	 * DEL_SERVER. Neighbours would've already removed the server belonging
 	 * to this port due to the DEL_CLIENT broadcast from qrtr_port_remove().
 	 */
-	node = node_get(node_id);
+	node = node_lookup(endpoint_id, node_id);
 	if (node)
-		server_del(node, port, false);
+		server_del(endpoint_id, node, port, false);
 
 	/* Advertise the removal of this client to all local servers */
-	local_node = node_get(qrtr_ns.local_node);
+	local_node = node_lookup(qrtr_ns.local_node, qrtr_ns.local_node);
 	if (!local_node)
 		return 0;
 
@@ -484,10 +538,8 @@ static int ctrl_cmd_del_client(struct sockaddr_qrtr *from,
 		sq.sq_node = srv->node;
 		sq.sq_port = srv->port;
 
-		msg.msg_name = (struct sockaddr *)&sq;
-		msg.msg_namelen = sizeof(sq);
-
-		ret = kernel_sendmsg(qrtr_ns.sock, &msg, &iv, 1, sizeof(pkt));
+		/* Del Client will look as if it came from endpoint_id */
+		ret = qrtr_ns_sendmsg(endpoint_id, &sq, &pkt);
 		if (ret < 0 && ret != -ENODEV) {
 			pr_err("failed to send del client cmd\n");
 			return ret;
@@ -496,7 +548,7 @@ static int ctrl_cmd_del_client(struct sockaddr_qrtr *from,
 	return 0;
 }
 
-static int ctrl_cmd_new_server(struct sockaddr_qrtr *from,
+static int ctrl_cmd_new_server(u32 endpoint_id, struct sockaddr_qrtr *from,
 			       unsigned int service, unsigned int instance,
 			       unsigned int node_id, unsigned int port)
 {
@@ -511,12 +563,16 @@ static int ctrl_cmd_new_server(struct sockaddr_qrtr *from,
 		port = from->sq_port;
 	}
 
-	srv = server_add(service, instance, node_id, port);
-	if (!srv)
+	srv = server_add(endpoint_id, service, instance, node_id, port);
+	if (!srv) {
+		pr_err("Failed to add server\n");
 		return -EINVAL;
+	}
 
 	if (srv->node == qrtr_ns.local_node) {
-		ret = service_announce_new(&qrtr_ns.bcast_sq, srv);
+		/* Broadcast local server info to all peer endpoints */
+		ret = service_announce_new(qrtr_ns.local_node,
+					   &qrtr_ns.bcast_sq, srv);
 		if (ret < 0) {
 			pr_err("failed to announce new service\n");
 			return ret;
@@ -531,13 +587,13 @@ static int ctrl_cmd_new_server(struct sockaddr_qrtr *from,
 		if (lookup->instance && lookup->instance != instance)
 			continue;
 
-		lookup_notify(&lookup->sq, srv, true);
+		lookup_notify(endpoint_id, &lookup->sq, srv, true);
 	}
 
 	return ret;
 }
 
-static int ctrl_cmd_del_server(struct sockaddr_qrtr *from,
+static int ctrl_cmd_del_server(u32 endpoint_id, struct sockaddr_qrtr *from,
 			       unsigned int service, unsigned int instance,
 			       unsigned int node_id, unsigned int port)
 {
@@ -553,24 +609,22 @@ static int ctrl_cmd_del_server(struct sockaddr_qrtr *from,
 	if (from->sq_node == qrtr_ns.local_node && from->sq_port != port)
 		return -EINVAL;
 
-	node = node_get(node_id);
+	node = node_lookup(endpoint_id, node_id);
 	if (!node)
 		return -ENOENT;
 
-	server_del(node, port, true);
+	server_del(endpoint_id, node, port, true);
 
 	return 0;
 }
 
-static int ctrl_cmd_new_lookup(struct sockaddr_qrtr *from,
+static int ctrl_cmd_new_lookup(u32 endpoint_id, struct sockaddr_qrtr *from,
 			       unsigned int service, unsigned int instance)
 {
 	struct qrtr_server_filter filter;
 	struct qrtr_lookup *lookup;
-	struct qrtr_server *srv;
-	struct qrtr_node *node;
-	unsigned long node_idx;
-	unsigned long srv_idx;
+	unsigned long id;
+	struct qrtr_ns_endpoint *endpoint;
 
 	/* Accept only local observers */
 	if (from->sq_node != qrtr_ns.local_node)
@@ -595,22 +649,30 @@ static int ctrl_cmd_new_lookup(struct sockaddr_qrtr *from,
 	filter.service = service;
 	filter.instance = instance;
 
-	xa_for_each(&nodes, node_idx, node) {
-		xa_for_each(&node->servers, srv_idx, srv) {
-			if (!server_match(srv, &filter))
-				continue;
+	xa_for_each(&endpoints, id, endpoint) {
+		struct qrtr_node *node;
+		unsigned long node_idx;
 
-			lookup_notify(from, srv, true);
+		xa_for_each(&endpoint->nodes, node_idx, node) {
+			unsigned long srv_idx;
+			struct qrtr_server *srv;
+
+			xa_for_each(&node->servers, srv_idx, srv) {
+				if (!server_match(srv, &filter))
+					continue;
+
+				lookup_notify(id, from, srv, true);
+			}
 		}
 	}
 
 	/* Empty notification, to indicate end of listing */
-	lookup_notify(from, NULL, true);
+	lookup_notify(0, from, NULL, true);
 
 	return 0;
 }
 
-static void ctrl_cmd_del_lookup(struct sockaddr_qrtr *from,
+static void ctrl_cmd_del_lookup(u32 endpoint_id, struct sockaddr_qrtr *from,
 				unsigned int service, unsigned int instance)
 {
 	struct qrtr_lookup *lookup;
@@ -644,6 +706,7 @@ static void qrtr_ns_worker(struct work_struct *work)
 	ssize_t msglen;
 	void *recv_buf;
 	struct kvec iv;
+	u8 control[32];
 	int ret;
 
 	msg.msg_name = (struct sockaddr *)&sq;
@@ -654,8 +717,12 @@ static void qrtr_ns_worker(struct work_struct *work)
 		return;
 
 	for (;;) {
+		u32 endpoint_id;
+
 		iv.iov_base = recv_buf;
 		iv.iov_len = recv_buf_size;
+		msg.msg_control = control;
+		msg.msg_controllen = sizeof(control);
 
 		msglen = kernel_recvmsg(qrtr_ns.sock, &msg, &iv, 1,
 					iv.iov_len, MSG_DONTWAIT);
@@ -668,6 +735,19 @@ static void qrtr_ns_worker(struct work_struct *work)
 			break;
 		}
 
+		/* AUX data is written direct into the control buffer */
+		msg.msg_control = control;
+		msg.msg_controllen = sizeof(control) - msg.msg_controllen;
+
+		ret = qrtr_msg_get_endpoint(&msg, &endpoint_id);
+		if (ret < 0) {
+			pr_err("error receiving endpoint id: %d\n", ret);
+			break;
+		}
+
+		if ((size_t)msglen < sizeof(*pkt))
+			break;
+
 		pkt = recv_buf;
 		cmd = le32_to_cpu(pkt->cmd);
 		if (cmd < ARRAY_SIZE(qrtr_ctrl_pkt_strings) &&
@@ -678,25 +758,25 @@ static void qrtr_ns_worker(struct work_struct *work)
 		ret = 0;
 		switch (cmd) {
 		case QRTR_TYPE_HELLO:
-			ret = ctrl_cmd_hello(&sq);
+			ret = ctrl_cmd_hello(endpoint_id, &sq);
 			break;
 		case QRTR_TYPE_BYE:
-			ret = ctrl_cmd_bye(&sq);
+			ret = ctrl_cmd_bye(endpoint_id, &sq);
 			break;
 		case QRTR_TYPE_DEL_CLIENT:
-			ret = ctrl_cmd_del_client(&sq,
+			ret = ctrl_cmd_del_client(endpoint_id, &sq,
 					le32_to_cpu(pkt->client.node),
 					le32_to_cpu(pkt->client.port));
 			break;
 		case QRTR_TYPE_NEW_SERVER:
-			ret = ctrl_cmd_new_server(&sq,
+			ret = ctrl_cmd_new_server(endpoint_id, &sq,
 					le32_to_cpu(pkt->server.service),
 					le32_to_cpu(pkt->server.instance),
 					le32_to_cpu(pkt->server.node),
 					le32_to_cpu(pkt->server.port));
 			break;
 		case QRTR_TYPE_DEL_SERVER:
-			ret = ctrl_cmd_del_server(&sq,
+			ret = ctrl_cmd_del_server(endpoint_id, &sq,
 					 le32_to_cpu(pkt->server.service),
 					 le32_to_cpu(pkt->server.instance),
 					 le32_to_cpu(pkt->server.node),
@@ -707,12 +787,12 @@ static void qrtr_ns_worker(struct work_struct *work)
 		case QRTR_TYPE_RESUME_TX:
 			break;
 		case QRTR_TYPE_NEW_LOOKUP:
-			ret = ctrl_cmd_new_lookup(&sq,
+			ret = ctrl_cmd_new_lookup(endpoint_id, &sq,
 					 le32_to_cpu(pkt->server.service),
 					 le32_to_cpu(pkt->server.instance));
 			break;
 		case QRTR_TYPE_DEL_LOOKUP:
-			ctrl_cmd_del_lookup(&sq,
+			ctrl_cmd_del_lookup(endpoint_id, &sq,
 				    le32_to_cpu(pkt->server.service),
 				    le32_to_cpu(pkt->server.instance));
 			break;
@@ -746,6 +826,8 @@ int qrtr_ns_init(void)
 	if (ret < 0)
 		return ret;
 
+	qrtr_sock_set_report_endpoint(qrtr_ns.sock->sk);
+
 	ret = kernel_getsockname(qrtr_ns.sock, (struct sockaddr *)&sq);
 	if (ret < 0) {
 		pr_err("failed to get socket name\n");
@@ -774,7 +856,7 @@ int qrtr_ns_init(void)
 	qrtr_ns.bcast_sq.sq_node = QRTR_NODE_BCAST;
 	qrtr_ns.bcast_sq.sq_port = QRTR_PORT_CTRL;
 
-	ret = say_hello(&qrtr_ns.bcast_sq);
+	ret = say_hello(qrtr_ns.local_node, &qrtr_ns.bcast_sq);
 	if (ret < 0)
 		goto err_wq;
 
diff --git a/net/qrtr/qrtr.h b/net/qrtr/qrtr.h
index 3f2d28696062a..affc24f426c64 100644
--- a/net/qrtr/qrtr.h
+++ b/net/qrtr/qrtr.h
@@ -9,6 +9,15 @@ struct sk_buff;
 /* endpoint node id auto assignment */
 #define QRTR_EP_NID_AUTO (-1)
 
+/**
+ * struct qrtr_node_lookup_helper - node lookup helper, stored in qrtr_nodes
+ * @nodes: nodes, indexed by node_id
+ */
+struct qrtr_node_lookup_helper {
+	int added;
+	struct radix_tree_root nodes;
+};
+
 /**
  * struct qrtr_endpoint - endpoint handle
  * @xmit: Callback for outgoing packets
@@ -21,6 +30,8 @@ struct qrtr_endpoint {
 	int (*xmit)(struct qrtr_endpoint *ep, struct sk_buff *skb);
 	/* private: not for endpoint use */
 	struct qrtr_node *node;
+	struct qrtr_node_lookup_helper helper;
+	u32 id;
 };
 
 int qrtr_endpoint_register(struct qrtr_endpoint *ep, unsigned int nid);
@@ -33,4 +44,7 @@ int qrtr_ns_init(void);
 
 void qrtr_ns_remove(void);
 
+int qrtr_msg_get_endpoint(struct msghdr *msg, u32 *out_endpoint_id);
+void qrtr_sock_set_report_endpoint(struct sock *sk);
+
 #endif

3/2 2026/09/15 06:23 llm patch-evaluator
0m Model:
gemini-3.8-flash

Args:
null

Results:
null

Tokens:
							input: 22941
							output: 20
							thoughts: 332
						

Thoughts:
**My Analysis of the QRTR Endpoint Management Patch**

Okay, so this patch is adding some crucial endpoint management features to QRTR, the Qualcomm IPC Router. My initial thought is, this is a pretty significant addition. Let's see, it looks like the core of the changes revolve around these key areas:

*   The kernel headers are being updated: specifically `socket.h` and `qrtr.h`, with the introduction of new socket options, namely `SOL_QRTR`, `QRTR_REPORT_ENDPOINT`, `QRTR_BIND_ENDPOINT`, and `QRTR_ENDPOINT`. These are the foundational elements for enabling the endpoint control.
*   `af_qrtr.c` is the heart of the changes: the implementation of `setsockopt` and `getsockopt` with the new options. We've got `cmsg` parsing for the endpoint information which is crucial for passing the endpoint data and the radix tree is being adjusted to manage these new endpoints efficiently. Then there's endpoint filtering and post-processing, which is critical for security and ensuring data integrity and some new helper functions.
*   The inclusion of endpoint sysfs attribute is also added, and, interestingly, nameservice handling for multi-endpoint support seems to be another addition.

My next step is to examine the Kconfig options. I need to understand the configuration possibilities and, critically, how accessible this functionality is from userspace. It's QRTR sockets, so they should be standard network sockets - `socket(AF_QIPCRTR, ...)`. I wonder if this can be accessed in a VM environment? Can a user space application using `AF_QIPCRTR` be opened without specific hardware requirements? I need to check the net/qrtr/ directory to clarify this. That will tell me if QEMU or syzkaller can be used to exploit any potential issues.



4/2 2026/09/15 06:23 tool grepper
0m Args:
{
  "Expression": "AF_QIPCRTR"
}

Results:
{
  "Output": "Documentation/accel/qaic/aic100.rst=187=of the defined channels, and their uses.\n--\nDocumentation/accel/qaic/aic100.rst-231-+----------------+---------+----------+----------------------------------------+\nDocumentation/accel/qaic/aic100.rst:232:| IPCR           | 24 \u0026 25 | AMSS     | AF_QIPCRTR clients and servers.        |\nDocumentation/accel/qaic/aic100.rst-233-+----------------+---------+----------+----------------------------------------+\n--\ndrivers/net/ipa/ipa_qmi.c=448=ipa_client_new_server(struct qmi_handle *qmi, struct qmi_service *svc)\n--\ndrivers/net/ipa/ipa_qmi.c-453-\ndrivers/net/ipa/ipa_qmi.c:454:\tipa_qmi-\u003emodem_sq.sq_family = AF_QIPCRTR;\ndrivers/net/ipa/ipa_qmi.c-455-\tipa_qmi-\u003emodem_sq.sq_node = svc-\u003enode;\n--\ndrivers/net/wireless/ath/ath10k/qmi.c=982=static int ath10k_qmi_new_server(struct qmi_handle *qmi_hdl,\n--\ndrivers/net/wireless/ath/ath10k/qmi.c-989-\ndrivers/net/wireless/ath/ath10k/qmi.c:990:\tsq-\u003esq_family = AF_QIPCRTR;\ndrivers/net/wireless/ath/ath10k/qmi.c-991-\tsq-\u003esq_node = service-\u003enode;\n--\ndrivers/net/wireless/ath/ath11k/qmi.c=3167=static int ath11k_qmi_ops_new_server(struct qmi_handle *qmi_hdl,\n--\ndrivers/net/wireless/ath/ath11k/qmi.c-3174-\ndrivers/net/wireless/ath/ath11k/qmi.c:3175:\tsq-\u003esq_family = AF_QIPCRTR;\ndrivers/net/wireless/ath/ath11k/qmi.c-3176-\tsq-\u003esq_node = service-\u003enode;\n--\ndrivers/net/wireless/ath/ath12k/qmi.c=3937=static int ath12k_qmi_ops_new_server(struct qmi_handle *qmi_hdl,\n--\ndrivers/net/wireless/ath/ath12k/qmi.c-3944-\ndrivers/net/wireless/ath/ath12k/qmi.c:3945:\tsq-\u003esq_family = AF_QIPCRTR;\ndrivers/net/wireless/ath/ath12k/qmi.c-3946-\tsq-\u003esq_node = service-\u003enode;\n--\ndrivers/remoteproc/qcom_sysmon.c=421=static int ssctl_new_server(struct qmi_handle *qmi, struct qmi_service *svc)\n--\ndrivers/remoteproc/qcom_sysmon.c-441-\ndrivers/remoteproc/qcom_sysmon.c:442:\tsysmon-\u003essctl.sq_family = AF_QIPCRTR;\ndrivers/remoteproc/qcom_sysmon.c-443-\tsysmon-\u003essctl.sq_node = svc-\u003enode;\n--\ndrivers/slimbus/qcom-ngd-ctrl.c=1364=static int qcom_slim_ngd_qmi_new_server(struct qmi_handle *hdl,\n--\ndrivers/slimbus/qcom-ngd-ctrl.c-1371-\ndrivers/slimbus/qcom-ngd-ctrl.c:1372:\tqmi-\u003esvc_info.sq_family = AF_QIPCRTR;\ndrivers/slimbus/qcom-ngd-ctrl.c-1373-\tqmi-\u003esvc_info.sq_node = service-\u003enode;\n--\ndrivers/soc/qcom/pdr_interface.c=73=static int pdr_locator_new_server(struct qmi_handle *qmi,\n--\ndrivers/soc/qcom/pdr_interface.c-80-\t/* Create a local client port for QMI communication */\ndrivers/soc/qcom/pdr_interface.c:81:\tpdr-\u003elocator_addr.sq_family = AF_QIPCRTR;\ndrivers/soc/qcom/pdr_interface.c-82-\tpdr-\u003elocator_addr.sq_node = svc-\u003enode;\n--\ndrivers/soc/qcom/pdr_interface.c=191=static int pdr_notifier_new_server(struct qmi_handle *qmi,\n--\ndrivers/soc/qcom/pdr_interface.c-203-\t\t\tpds-\u003eneed_notifier_register = true;\ndrivers/soc/qcom/pdr_interface.c:204:\t\t\tpds-\u003eaddr.sq_family = AF_QIPCRTR;\ndrivers/soc/qcom/pdr_interface.c-205-\t\t\tpds-\u003eaddr.sq_node = svc-\u003enode;\n--\ndrivers/soc/qcom/qmi_interface.c=585=static struct socket *qmi_sock_create(struct qmi_handle *qmi,\n--\ndrivers/soc/qcom/qmi_interface.c-590-\ndrivers/soc/qcom/qmi_interface.c:591:\tret = sock_create_kern(\u0026init_net, AF_QIPCRTR, SOCK_DGRAM,\ndrivers/soc/qcom/qmi_interface.c-592-\t\t\t       PF_QIPCRTR, \u0026sock);\n--\ninclude/linux/socket.h=197=struct ucred {\n--\ninclude/linux/socket.h-247-#define AF_KCM\t\t41\t/* Kernel Connection Multiplexor*/\ninclude/linux/socket.h:248:#define AF_QIPCRTR\t42\t/* Qualcomm IPC Router          */\ninclude/linux/socket.h-249-#define AF_SMC\t\t43\t/* smc sockets: reserve number for\n--\ninclude/linux/socket.h-304-#define PF_KCM\t\tAF_KCM\ninclude/linux/socket.h:305:#define PF_QIPCRTR\tAF_QIPCRTR\ninclude/linux/socket.h-306-#define PF_SMC\t\tAF_SMC\n--\nnet/core/sock.c=217=static struct lock_class_key af_family_kern_slock_keys[AF_MAX];\n--\nnet/core/sock.c-239-  x \"AF_NFC\"   ,\tx \"AF_VSOCK\"    ,\tx \"AF_KCM\"      , \\\nnet/core/sock.c:240:  x \"AF_QIPCRTR\",\tx \"AF_SMC\"\t,\tx \"AF_XDP\"\t, \\\nnet/core/sock.c-241-  x \"AF_MCTP\"  , \\\n--\nnet/qrtr/af_qrtr.c=804=void qrtr_endpoint_unregister(struct qrtr_endpoint *ep)\n--\nnet/qrtr/af_qrtr.c-806-\tstruct qrtr_node *node = ep-\u003enode;\nnet/qrtr/af_qrtr.c:807:\tstruct sockaddr_qrtr src = {AF_QIPCRTR, node-\u003enid, QRTR_PORT_CTRL};\nnet/qrtr/af_qrtr.c:808:\tstruct sockaddr_qrtr dst = {AF_QIPCRTR, qrtr_local_nid, QRTR_PORT_CTRL};\nnet/qrtr/af_qrtr.c-809-\tstruct radix_tree_iter iter;\n--\nnet/qrtr/af_qrtr.c=894=static void qrtr_port_remove(struct qrtr_sock *ipc)\n--\nnet/qrtr/af_qrtr.c-900-\nnet/qrtr/af_qrtr.c:901:\tto.sq_family = AF_QIPCRTR;\nnet/qrtr/af_qrtr.c-902-\tto.sq_node = QRTR_NODE_BCAST;\n--\nnet/qrtr/af_qrtr.c=1015=static int qrtr_autobind(struct socket *sock)\n--\nnet/qrtr/af_qrtr.c-1022-\nnet/qrtr/af_qrtr.c:1023:\taddr.sq_family = AF_QIPCRTR;\nnet/qrtr/af_qrtr.c-1024-\taddr.sq_node = qrtr_local_nid;\n--\nnet/qrtr/af_qrtr.c=1031=static int qrtr_bind(struct socket *sock, struct sockaddr_unsized *saddr, int len)\n--\nnet/qrtr/af_qrtr.c-1037-\nnet/qrtr/af_qrtr.c:1038:\tif (len \u003c sizeof(*addr) || addr-\u003esq_family != AF_QIPCRTR)\nnet/qrtr/af_qrtr.c-1039-\t\treturn -EINVAL;\n--\nnet/qrtr/af_qrtr.c=1119=static int qrtr_sendmsg(struct socket *sock, struct msghdr *msg, size_t len)\n--\nnet/qrtr/af_qrtr.c-1154-\nnet/qrtr/af_qrtr.c:1155:\t\tif (addr-\u003esq_family != AF_QIPCRTR)\nnet/qrtr/af_qrtr.c-1156-\t\t\tgoto release_sock;\n--\nnet/qrtr/af_qrtr.c=1235=static int qrtr_send_resume_tx(struct qrtr_cb *cb)\nnet/qrtr/af_qrtr.c-1236-{\nnet/qrtr/af_qrtr.c:1237:\tstruct sockaddr_qrtr remote = { AF_QIPCRTR, cb-\u003esrc_node, cb-\u003esrc_port };\nnet/qrtr/af_qrtr.c:1238:\tstruct sockaddr_qrtr local = { AF_QIPCRTR, cb-\u003edst_node, cb-\u003edst_port };\nnet/qrtr/af_qrtr.c-1239-\tstruct qrtr_ctrl_pkt *pkt;\n--\nnet/qrtr/af_qrtr.c=1266=static int qrtr_recvmsg(struct socket *sock, struct msghdr *msg,\n--\nnet/qrtr/af_qrtr.c-1310-\nnet/qrtr/af_qrtr.c:1311:\t\taddr-\u003esq_family = AF_QIPCRTR;\nnet/qrtr/af_qrtr.c-1312-\t\taddr-\u003esq_node = cb-\u003esrc_node;\n--\nnet/qrtr/af_qrtr.c=1327=static int qrtr_connect(struct socket *sock, struct sockaddr_unsized *saddr,\n--\nnet/qrtr/af_qrtr.c-1334-\nnet/qrtr/af_qrtr.c:1335:\tif (len \u003c sizeof(*addr) || addr-\u003esq_family != AF_QIPCRTR)\nnet/qrtr/af_qrtr.c-1336-\t\treturn -EINVAL;\n--\nnet/qrtr/af_qrtr.c=1358=static int qrtr_getname(struct socket *sock, struct sockaddr *saddr,\n--\nnet/qrtr/af_qrtr.c-1377-\nnet/qrtr/af_qrtr.c:1378:\tqaddr.sq_family = AF_QIPCRTR;\nnet/qrtr/af_qrtr.c-1379-\n--\nnet/qrtr/af_qrtr.c=1543=static const struct proto_ops qrtr_proto_ops = {\nnet/qrtr/af_qrtr.c-1544-\t.owner\t\t= THIS_MODULE,\nnet/qrtr/af_qrtr.c:1545:\t.family\t\t= AF_QIPCRTR,\nnet/qrtr/af_qrtr.c-1546-\t.bind\t\t= qrtr_bind,\n--\nnet/qrtr/af_qrtr.c=1570=static int qrtr_create(struct net *net, struct socket *sock,\n--\nnet/qrtr/af_qrtr.c-1586-\nnet/qrtr/af_qrtr.c:1587:\tsk = sk_alloc(net, AF_QIPCRTR, GFP_KERNEL, \u0026qrtr_proto, kern);\nnet/qrtr/af_qrtr.c-1588-\tif (!sk)\n--\nnet/qrtr/af_qrtr.c-1596-\tipc = qrtr_sk(sk);\nnet/qrtr/af_qrtr.c:1597:\tipc-\u003eus.sq_family = AF_QIPCRTR;\nnet/qrtr/af_qrtr.c-1598-\tipc-\u003eus.sq_node = qrtr_local_nid;\n--\nnet/qrtr/af_qrtr.c=1604=static const struct net_proto_family qrtr_family = {\nnet/qrtr/af_qrtr.c-1605-\t.owner\t= THIS_MODULE,\nnet/qrtr/af_qrtr.c:1606:\t.family\t= AF_QIPCRTR,\nnet/qrtr/af_qrtr.c-1607-\t.create\t= qrtr_create,\n--\nnet/qrtr/ns.c=432=static int ctrl_cmd_bye(u32 endpoint_id, struct sockaddr_qrtr *from)\n--\nnet/qrtr/ns.c-461-\txa_for_each(\u0026local_node-\u003eservers, index, srv) {\nnet/qrtr/ns.c:462:\t\tsq.sq_family = AF_QIPCRTR;\nnet/qrtr/ns.c-463-\t\tsq.sq_node = srv-\u003enode;\n--\nnet/qrtr/ns.c=483=static int ctrl_cmd_del_client(u32 endpoint_id, struct sockaddr_qrtr *from,\n--\nnet/qrtr/ns.c-536-\txa_for_each(\u0026local_node-\u003eservers, index, srv) {\nnet/qrtr/ns.c:537:\t\tsq.sq_family = AF_QIPCRTR;\nnet/qrtr/ns.c-538-\t\tsq.sq_node = srv-\u003enode;\n--\nnet/qrtr/ns.c=816=int qrtr_ns_init(void)\n--\nnet/qrtr/ns.c-823-\nnet/qrtr/ns.c:824:\tret = sock_create_kern(\u0026init_net, AF_QIPCRTR, SOCK_DGRAM,\nnet/qrtr/ns.c-825-\t\t\t       PF_QIPCRTR, \u0026qrtr_ns.sock);\n--\nnet/qrtr/ns.c-854-\nnet/qrtr/ns.c:855:\tqrtr_ns.bcast_sq.sq_family = AF_QIPCRTR;\nnet/qrtr/ns.c-856-\tqrtr_ns.bcast_sq.sq_node = QRTR_NODE_BCAST;\n--\nsamples/qmi/qmi_sample_client.c=533=static int qmi_sample_new_server(struct qmi_handle *qmi,\n--\nsamples/qmi/qmi_sample_client.c-536-\tstruct platform_device *pdev;\nsamples/qmi/qmi_sample_client.c:537:\tstruct sockaddr_qrtr sq = { AF_QIPCRTR, service-\u003enode, service-\u003eport };\nsamples/qmi/qmi_sample_client.c-538-\tint ret;\n--\ntools/perf/trace/beauty/include/linux/socket.h=197=struct ucred {\n--\ntools/perf/trace/beauty/include/linux/socket.h-247-#define AF_KCM\t\t41\t/* Kernel Connection Multiplexor*/\ntools/perf/trace/beauty/include/linux/socket.h:248:#define AF_QIPCRTR\t42\t/* Qualcomm IPC Router          */\ntools/perf/trace/beauty/include/linux/socket.h-249-#define AF_SMC\t\t43\t/* smc sockets: reserve number for\n--\ntools/perf/trace/beauty/include/linux/socket.h-304-#define PF_KCM\t\tAF_KCM\ntools/perf/trace/beauty/include/linux/socket.h:305:#define PF_QIPCRTR\tAF_QIPCRTR\ntools/perf/trace/beauty/include/linux/socket.h-306-#define PF_SMC\t\tAF_SMC\n"
}

5/2 2026/09/15 06:23 llm patch-evaluator
0m Model:
gemini-3.8-flash

Args:
null

Results:
null

Tokens:
							input: 27994
							output: 33
							thoughts: 21
						

Thoughts:
Here's my summary, as though I were examining `net/qrtr/Kconfig`:

**Diving into the QRTR Configuration**

Okay, time to get a handle on the configurability of the QRTR subsystem. I'm going to start by cracking open `net/qrtr/Kconfig`. This is where all the good stuff is – the configuration options, the dependencies, the underlying architecture choices. I want to see what knobs we have to tune, what other kernel features we need enabled, and what the overall design space looks like. Understanding the `Kconfig` file is the first step to truly understanding how this thing works and what potential adjustments I can make for optimization or special use cases. It's like a roadmap to the subsystem's capabilities. Let's see what's in store.



6/2 2026/09/15 06:23 tool read-file
0m Args:
{
  "File": "net/qrtr/Kconfig",
  "FirstLine": 1,
  "LineCount": 50
}

Results:
{
  "Contents": "   1:\t# SPDX-License-Identifier: GPL-2.0-only\n   2:\t# Qualcomm IPC Router configuration\n   3:\t#\n   4:\t\n   5:\tconfig QRTR\n   6:\t\ttristate \"Qualcomm IPC Router support\"\n   7:\t\thelp\n   8:\t\t  Say Y if you intend to use Qualcomm IPC router protocol.  The\n   9:\t\t  protocol is used to communicate with services provided by other\n  10:\t\t  hardware blocks in the system.\n  11:\t\n  12:\t\t  In order to do service lookups, a userspace daemon is required to\n  13:\t\t  maintain a service listing.\n  14:\t\n  15:\tif QRTR\n  16:\t\n  17:\tconfig QRTR_SMD\n  18:\t\ttristate \"SMD IPC Router channels\"\n  19:\t\tdepends on RPMSG || (COMPILE_TEST \u0026\u0026 RPMSG=n)\n  20:\t\thelp\n  21:\t\t  Say Y here to support SMD based ipcrouter channels.  SMD is the\n  22:\t\t  most common transport for IPC Router.\n  23:\t\n  24:\tconfig QRTR_TUN\n  25:\t\ttristate \"TUN device for Qualcomm IPC Router\"\n  26:\t\thelp\n  27:\t\t  Say Y here to expose a character device that allows user space to\n  28:\t\t  implement endpoints of QRTR, for purpose of tunneling data to other\n  29:\t\t  hosts or testing purposes.\n  30:\t\n  31:\tconfig QRTR_MHI\n  32:\t\ttristate \"MHI IPC Router channels\"\n  33:\t\tdepends on MHI_BUS\n  34:\t\thelp\n  35:\t\t  Say Y here to support MHI based ipcrouter channels. MHI is the\n  36:\t\t  transport used for communicating to external modems.\n  37:\t\n  38:\tendif # QRTR\n"
}

7/2 2026/09/15 06:23 llm patch-evaluator
0m Model:
gemini-3.8-flash

Args:
null

Results:
null

Tokens:
							input: 28705
							output: 32
							thoughts: 61
						

Thoughts:
**QRTR Deep Dive**

Okay, let's dive into this `QRTR` situation. First, I need to understand the relationship between `QRTR_TUN` and `QRTR`. Right away, it looks like `QRTR` is responsible for a core set of functionalities, specifically `net/qrtr/af_qrtr.c` and `net/qrtr/ns.c`. That's the foundation we need to grasp.  Now, to get a better handle on the overall structure, I'll need to examine `net/qrtr/Makefile`. This will reveal how all the components fit together, the build process, and any dependencies. I need to see the big picture!



8/2 2026/09/15 06:23 tool read-file
0m Args:
{
  "File": "net/qrtr/Makefile",
  "FirstLine": 1,
  "LineCount": 20
}

Results:
{
  "Contents": "   1:\t# SPDX-License-Identifier: GPL-2.0-only\n   2:\tobj-$(CONFIG_QRTR) += qrtr.o\n   3:\tqrtr-y\t:= af_qrtr.o ns.o\n   4:\t\n   5:\tobj-$(CONFIG_QRTR_SMD) += qrtr-smd.o\n   6:\tqrtr-smd-y\t:= smd.o\n   7:\tobj-$(CONFIG_QRTR_TUN) += qrtr-tun.o\n   8:\tqrtr-tun-y\t:= tun.o\n   9:\tobj-$(CONFIG_QRTR_MHI) += qrtr-mhi.o\n  10:\tqrtr-mhi-y\t:= mhi.o\n"
}

9/2 2026/09/15 06:23 llm patch-evaluator
0m Model:
gemini-3.8-flash

Args:
null

Results:
null

Tokens:
							input: 29145
							output: 31
							thoughts: 253
						

Thoughts:
**My Analysis of the QRTR Driver**

Okay, so I'm looking at this kernel code and it seems straightforward, but I need to quickly get up to speed. `obj-$(CONFIG_QRTR) += qrtr.o` tells me the QRTR driver is being compiled, and within that, we have `qrtr-y := af_qrtr.o ns.o`.  And there's also `obj-$(CONFIG_QRTR_TUN) += qrtr-tun.o`. I should double check if Syzkaller has descriptions for QRTR/AF_QIPCRTR. I can find relevant information in its syzlang files, but even if it doesn't, this is a standard network socket family (`AF_QIPCRTR`, value 42), so I can infer a lot.

Any userspace process can create and interact with `socket(AF_QIPCRTR, SOCK_DGRAM, 0)` – standard stuff. Then `bind()`, `setsockopt(..., SOL_QRTR, QRTR_REPORT_ENDPOINT/QRTR_BIND_ENDPOINT, ...)` for configuration. And of course, `getsockopt(...)` to query the state. Then there's `sendmsg()` and `recvmsg()` for data transfer, using `SOL_QRTR` / `QRTR_ENDPOINT` control messages. Pretty typical network socket interaction.

What's particularly interesting is this `QRTR_TUN` device (`/dev/qrtr-tun`). This suggests that userspace can *create* its own endpoints via a TUN interface! So, let me investigate what `qrtr_endpoint_register` is doing in relation to the `QRTR_TUN` functionality; that's where the real magic might be happening.



10/2 2026/09/15 06:23 tool grepper
0m Args:
{
  "Expression": "qrtr_endpoint_register",
  "PathPrefix": "net/qrtr/"
}

Results:
{
  "Output": "net/qrtr/af_qrtr.c=729=static struct sk_buff *qrtr_alloc_ctrl_packet(struct qrtr_ctrl_pkt **pkt,\n--\nnet/qrtr/af_qrtr.c-745-/**\nnet/qrtr/af_qrtr.c:746: * qrtr_endpoint_register() - register a new endpoint\nnet/qrtr/af_qrtr.c-747- * @ep: endpoint to register\n--\nnet/qrtr/af_qrtr.c-752- */\nnet/qrtr/af_qrtr.c:753:int qrtr_endpoint_register(struct qrtr_endpoint *ep, unsigned int nid)\nnet/qrtr/af_qrtr.c-754-{\n--\nnet/qrtr/af_qrtr.c-797-}\nnet/qrtr/af_qrtr.c:798:EXPORT_SYMBOL_GPL(qrtr_endpoint_register);\nnet/qrtr/af_qrtr.c-799-\n--\nnet/qrtr/mhi.c=119=static int qcom_mhi_qrtr_probe(struct mhi_device *mhi_dev,\n--\nnet/qrtr/mhi.c-139-\nnet/qrtr/mhi.c:140:\trc = qrtr_endpoint_register(\u0026qdev-\u003eep, QRTR_EP_NID_AUTO);\nnet/qrtr/mhi.c-141-\tif (rc)\n--\nnet/qrtr/qrtr.h=29=struct qrtr_endpoint {\n--\nnet/qrtr/qrtr.h-36-\nnet/qrtr/qrtr.h:37:int qrtr_endpoint_register(struct qrtr_endpoint *ep, unsigned int nid);\nnet/qrtr/qrtr.h-38-\n--\nnet/qrtr/smd.c=59=static int qcom_smd_qrtr_probe(struct rpmsg_device *rpdev)\n--\nnet/qrtr/smd.c-71-\nnet/qrtr/smd.c:72:\trc = qrtr_endpoint_register(\u0026qdev-\u003eep, QRTR_EP_NID_AUTO);\nnet/qrtr/smd.c-73-\tif (rc)\n--\nnet/qrtr/tun.c=31=static int qrtr_tun_open(struct inode *inode, struct file *filp)\n--\nnet/qrtr/tun.c-46-\nnet/qrtr/tun.c:47:\tret = qrtr_endpoint_register(\u0026tun-\u003eep, QRTR_EP_NID_AUTO);\nnet/qrtr/tun.c-48-\tif (ret)\n"
}

11/2 2026/09/15 06:23 llm patch-evaluator
0m Model:
gemini-3.8-flash

Args:
null

Results:
null

Tokens:
							input: 30498
							output: 34
							thoughts: 83
						

Thoughts:
Here's my understanding of the situation, framed as if it were my thought process:

**Diving into the QRTR Tunnel Driver**

Okay, so I see that this code sequence is opening up a `/dev/qrtr-tun` device, and the interesting bit is the call to `qrtr_endpoint_register(&tun->ep, QRTR_EP_NID_AUTO)`. That suggests it's setting up a QRTR endpoint, probably assigning a Node ID automatically. After that, it seems that there are writes happening to the `/dev/qrtr-tun` device, which are then passed to `qrtr_endpoint_post(&tun->ep, ...)` function. This means that data is likely being queued up for transmission over the QRTR network.

To understand the core mechanics, I'll need to drill down into the details of the driver itself. Let me check the `net/qrtr/tun.c` source file. I'm keen to see how the endpoint is initialized, how data is handled, and how it interacts with the underlying QRTR bus. This will give a good grounding to the system as a whole.



12/2 2026/09/15 06:23 tool read-file
0m Args:
{
  "File": "net/qrtr/tun.c",
  "FirstLine": 1,
  "LineCount": 90
}

Results:
{
  "Contents": "   1:\t// SPDX-License-Identifier: GPL-2.0\n   2:\t/* Copyright (c) 2018, Linaro Ltd */\n   3:\t\n   4:\t#include \u003clinux/miscdevice.h\u003e\n   5:\t#include \u003clinux/module.h\u003e\n   6:\t#include \u003clinux/poll.h\u003e\n   7:\t#include \u003clinux/skbuff.h\u003e\n   8:\t#include \u003clinux/uaccess.h\u003e\n   9:\t\n  10:\t#include \"qrtr.h\"\n  11:\t\n  12:\tstruct qrtr_tun {\n  13:\t\tstruct qrtr_endpoint ep;\n  14:\t\n  15:\t\tstruct sk_buff_head queue;\n  16:\t\twait_queue_head_t readq;\n  17:\t};\n  18:\t\n  19:\tstatic int qrtr_tun_send(struct qrtr_endpoint *ep, struct sk_buff *skb)\n  20:\t{\n  21:\t\tstruct qrtr_tun *tun = container_of(ep, struct qrtr_tun, ep);\n  22:\t\n  23:\t\tskb_queue_tail(\u0026tun-\u003equeue, skb);\n  24:\t\n  25:\t\t/* wake up any blocking processes, waiting for new data */\n  26:\t\twake_up_interruptible(\u0026tun-\u003ereadq);\n  27:\t\n  28:\t\treturn 0;\n  29:\t}\n  30:\t\n  31:\tstatic int qrtr_tun_open(struct inode *inode, struct file *filp)\n  32:\t{\n  33:\t\tstruct qrtr_tun *tun;\n  34:\t\tint ret;\n  35:\t\n  36:\t\ttun = kzalloc_obj(*tun);\n  37:\t\tif (!tun)\n  38:\t\t\treturn -ENOMEM;\n  39:\t\n  40:\t\tskb_queue_head_init(\u0026tun-\u003equeue);\n  41:\t\tinit_waitqueue_head(\u0026tun-\u003ereadq);\n  42:\t\n  43:\t\ttun-\u003eep.xmit = qrtr_tun_send;\n  44:\t\n  45:\t\tfilp-\u003eprivate_data = tun;\n  46:\t\n  47:\t\tret = qrtr_endpoint_register(\u0026tun-\u003eep, QRTR_EP_NID_AUTO);\n  48:\t\tif (ret)\n  49:\t\t\tgoto out;\n  50:\t\n  51:\t\treturn 0;\n  52:\t\n  53:\tout:\n  54:\t\tfilp-\u003eprivate_data = NULL;\n  55:\t\tkfree(tun);\n  56:\t\treturn ret;\n  57:\t}\n  58:\t\n  59:\tstatic ssize_t qrtr_tun_read_iter(struct kiocb *iocb, struct iov_iter *to)\n  60:\t{\n  61:\t\tstruct file *filp = iocb-\u003eki_filp;\n  62:\t\tstruct qrtr_tun *tun = filp-\u003eprivate_data;\n  63:\t\tstruct sk_buff *skb;\n  64:\t\tint count;\n  65:\t\n  66:\t\twhile (!(skb = skb_dequeue(\u0026tun-\u003equeue))) {\n  67:\t\t\tif (filp-\u003ef_flags \u0026 O_NONBLOCK)\n  68:\t\t\t\treturn -EAGAIN;\n  69:\t\n  70:\t\t\t/* Wait until we get data or the endpoint goes away */\n  71:\t\t\tif (wait_event_interruptible(tun-\u003ereadq,\n  72:\t\t\t\t\t\t     !skb_queue_empty(\u0026tun-\u003equeue)))\n  73:\t\t\t\treturn -ERESTARTSYS;\n  74:\t\t}\n  75:\t\n  76:\t\tcount = min_t(size_t, iov_iter_count(to), skb-\u003elen);\n  77:\t\tif (copy_to_iter(skb-\u003edata, count, to) != count)\n  78:\t\t\tcount = -EFAULT;\n  79:\t\n  80:\t\tkfree_skb(skb);\n  81:\t\n  82:\t\treturn count;\n  83:\t}\n  84:\t\n  85:\tstatic ssize_t qrtr_tun_write_iter(struct kiocb *iocb, struct iov_iter *from)\n  86:\t{\n  87:\t\tstruct file *filp = iocb-\u003eki_filp;\n  88:\t\tstruct qrtr_tun *tun = filp-\u003eprivate_data;\n  89:\t\tsize_t len = iov_iter_count(from);\n  90:\t\tssize_t ret;\n"
}

13/2 2026/09/15 06:23 llm patch-evaluator
0m Model:
gemini-3.8-flash

Args:
null

Results:
null

Tokens:
							input: 32058
							output: 40
							thoughts: 727
						

Thoughts:
**My Assessment of the QRTR Socket and Name Server Enhancements**

Okay, so I'm looking at this patch and, if I understand correctly, we can now reach QRTR sockets AND the QRTR tun interface without needing any physical hardware! That's a huge shift. We can directly open `AF_QIPCRTR` sockets using `socket(AF_QIPCRTR, SOCK_DGRAM, 0)`. That's a significant change to QRTR’s reachability.

Let's break down the code changes:

First, `af_qrtr.c`: This is where the core socket layer work is being done. We've got new `setsockopt` and `getsockopt` handlers for `SOL_QRTR` – `qrtr_setsockopt` and `qrtr_getsockopt`, respectively. They handle options like `QRTR_REPORT_ENDPOINT` and `QRTR_BIND_ENDPOINT`. Then there's `qrtr_msg_get_endpoint`, which parses the control message for endpoint information under `SOL_QRTR`. The patch has helper functions `qrtr_sock_set_report_endpoint` to set `QRTR_F_REPORT_ENDPOINT`, `qrtr_sendmsg` to parse control messages and route appropriately, `qrtr_recvmsg` to set `QRTR_ENDPOINT` in the control message if reporting is enabled, `qrtr_node_lookup` to perform lookups, `qrtr_node_assign` for radix tree manipulation, and `qrtr_endpoint_register`/`qrtr_endpoint_unregister` for allocating, registering, and unregistering endpoint IDs in the radix tree. `qrtr_endpoint_post` is used for filtering remote lookups and bound sockets. Finally, we've got the update to `qrtr_proto_ops` that hooks the `setsockopt` and `getsockopt` functions, and a `qrtr_proto_init` function to register `helper0`.

Next, `ns.c` tackles the QRTR Name Service, which seems to have had a major overhaul. We now have an internal kernel worker thread, `qrtr_ns_worker`, handling control packets. It looks like it's been refactored to manage per-endpoint node tables. I see xarrays of `qrtr_ns_endpoint` containing nodes xarrays. I see functions like `node_get`, `node_erase`, and `node_lookup`, and several new functions like `qrtr_ns_sendmsg`, `service_announce_new`, `service_announce_del`, `lookup_notify`, `announce_servers`, `server_add`, `server_del`, `say_hello`, and various `ctrl_cmd_*` functions for interacting with the name service. This seems to be the core of the name service functionality.

Then, `mhi.c`. The patch adds an endpoint sysfs attribute, but this part relies on MHI hardware or emulation. However, what's crucial is that `af_qrtr`, the name server, and the tun interface are *independent* of MHI.

This is a substantial set of features being added to the QRTR socket layer and name server! I'm noticing core network code that's now reachable with this change. This is definitely worth a full fuzzing campaign!

My immediate question is: Can regular users open these `AF_QIPCRTR` sockets, or are root privileges or special hardware still required? Let me check `qrtr_create` in `net/qrtr/af_qrtr.c`.



14/2 2026/09/15 06:24 tool read-file
0m Args:
{
  "File": "net/qrtr/af_qrtr.c",
  "FirstLine": 1565,
  "LineCount": 40
}

Results:
{
  "Contents": "1565:\t\t.name\t\t= \"QIPCRTR\",\n1566:\t\t.owner\t\t= THIS_MODULE,\n1567:\t\t.obj_size\t= sizeof(struct qrtr_sock),\n1568:\t};\n1569:\t\n1570:\tstatic int qrtr_create(struct net *net, struct socket *sock,\n1571:\t\t\t       int protocol, int kern)\n1572:\t{\n1573:\t\tstruct qrtr_sock *ipc;\n1574:\t\tstruct sock *sk;\n1575:\t\n1576:\t\tif (sock-\u003etype != SOCK_DGRAM)\n1577:\t\t\treturn -EPROTOTYPE;\n1578:\t\n1579:\t\t/* QRTR keeps its port and node state in module-global variables that\n1580:\t\t * are not partitioned per network namespace, and the in-kernel name\n1581:\t\t * service only operates in init_net. Confine the family to init_net so\n1582:\t\t * a socket in another namespace cannot reach the global control plane.\n1583:\t\t */\n1584:\t\tif (!net_eq(net, \u0026init_net))\n1585:\t\t\treturn -EAFNOSUPPORT;\n1586:\t\n1587:\t\tsk = sk_alloc(net, AF_QIPCRTR, GFP_KERNEL, \u0026qrtr_proto, kern);\n1588:\t\tif (!sk)\n1589:\t\t\treturn -ENOMEM;\n1590:\t\n1591:\t\tsock_set_flag(sk, SOCK_ZAPPED);\n1592:\t\n1593:\t\tsock_init_data(sock, sk);\n1594:\t\tsock-\u003eops = \u0026qrtr_proto_ops;\n1595:\t\n1596:\t\tipc = qrtr_sk(sk);\n1597:\t\tipc-\u003eus.sq_family = AF_QIPCRTR;\n1598:\t\tipc-\u003eus.sq_node = qrtr_local_nid;\n1599:\t\tipc-\u003eus.sq_port = 0;\n1600:\t\n1601:\t\treturn 0;\n1602:\t}\n1603:\t\n1604:\tstatic const struct net_proto_family qrtr_family = {\n"
}

15/2 2026/09/15 06:24 llm patch-evaluator
0m Model:
gemini-3.8-flash

Args:
null

Results:
null

Tokens:
							input: 34200
							output: 263
							thoughts: 1625
						

Thoughts:
**QRTR Subsystem Fuzzing Assessment**

Alright, let's break this down. My initial assessment is that the Qualcomm IPC Router (QRTR) subsystem is definitely worth a closer look for fuzzing. The fact that `qrtr_create` only requires `net_eq(net, &init_net)` and *no* special privileges like `CAP_NET_ADMIN` is a red flag, along with the accessibility of `/dev/qrtr-tun` as a misc device. Any unprivileged user can leverage this.

First, I examined the required configurations. `CONFIG_QRTR` seems fundamental, with `CONFIG_QRTR_TUN` dependent on it. There are no other dependencies on the base configuration, according to the `Kconfig` files. Thus, getting `QRTR` and optionally `QRTR_TUN` enabled is key.

Then, I turned my attention to the patch itself. I meticulously reviewed the functions added or modified, focusing on their potential impact and relevance to fuzzing. Here's what stood out:

*   In `net/qrtr/af_qrtr.c`, we've got:
    *   `qrtr_setsockopt` and `qrtr_getsockopt`: New socket option handling, always a target.
    *   `qrtr_sendmsg` and `qrtr_recvmsg`: Critical entry points for message handling, now with `QRTR_ENDPOINT` CMSG support.
    *   `qrtr_msg_get_endpoint`: a helper function, called from the important socket functions.
    *   `qrtr_endpoint_register`, `qrtr_endpoint_unregister`, `qrtr_endpoint_post`:  Endpoint management, crucial for tracking.
    *   `qrtr_sock_set_report_endpoint`: New helper, worth a closer look.

*   In `net/qrtr/ns.c`, the changes are equally significant:
    *   `qrtr_ns_worker`: Workqueue handling QRTR control packets, likely handles control message races.

I checked for symbol visibility with `nm`. The functions `qrtr_setsockopt`, `qrtr_getsockopt`, `qrtr_sendmsg`, and `qrtr_recvmsg` are explicitly listed in `qrtr_proto_ops` which means they will be distinct and not inlined. `qrtr_msg_get_endpoint` is a non-static function with external linkage (declared in `qrtr.h`), called by `af_qrtr.c` and `ns.c`. `qrtr_endpoint_register`, `qrtr_endpoint_unregister`, `qrtr_endpoint_post` are EXPORT_SYMBOL_GPL. `qrtr_ns_worker` is passed to `INIT_WORK`. This gives me confidence in their distinctness.

These functions - `qrtr_setsockopt`, `qrtr_getsockopt`, `qrtr_msg_get_endpoint`, `qrtr_sendmsg`, `qrtr_recvmsg`, `qrtr_endpoint_post`, `qrtr_endpoint_register`, `qrtr_ns_worker` - are perfect "FocusSymbols". They're highly specific to the QRTR subsystem, cover all the new endpoint reporting/binding functionality, and are entry points to the new message handling. Importantly, none of them are ubiquitous; they're QRTR-specific.

The patch introduces critical endpoint functionality via socket options, CMsgs in `sendmsg`/`recvmsg`, endpoint ID management (radix trees), and updates to the in-kernel name service. `AF_QIPCRTR` sockets and `QRTR` tun devices are available in virtualized environments like QEMU. The new attack surface is there to examine the message routing, lifecycle, and socket handling.

For enabling the configurations, `QRTR` and `QRTR_TUN` are the only required configurations to reach the subsystem.

Thus, the final `set-results` parameters are as follows:

*   `WorthFuzzing`: true
*   `Reasoning`: Concise explanation of the new endpoint support and the associated attack surface.
*   `FocusSymbols`: \[
    "qrtr\_setsockopt",
    "qrtr\_getsockopt",
    "qrtr\_msg\_get\_endpoint",
    "qrtr\_sendmsg",
    "qrtr\_recvmsg",
    "qrtr\_endpoint\_post",
    "qrtr\_endpoint\_register",
    "qrtr\_ns\_worker"
    ]
*   `EnableConfigs`: \[
    "QRTR",
    "QRTR\_TUN"
    ]

Let's call `set-results`.



16/2 2026/09/15 06:24 tool set-results
0m Args:
{
  "EnableConfigs": [
    "QRTR",
    "QRTR_TUN"
  ],
  "FocusSymbols": [
    "qrtr_setsockopt",
    "qrtr_getsockopt",
    "qrtr_msg_get_endpoint",
    "qrtr_sendmsg",
    "qrtr_recvmsg",
    "qrtr_endpoint_post",
    "qrtr_endpoint_register",
    "qrtr_ns_worker"
  ],
  "Reasoning": "The patch series implements endpoint-based isolation and tracking for Qualcomm IPC Router (AF_QIPCRTR) sockets. It introduces SOL_QRTR socket options (QRTR_REPORT_ENDPOINT, QRTR_BIND_ENDPOINT), ancillary control messages (QRTR_ENDPOINT) for sendmsg and recvmsg, per-endpoint radix-tree node management, and multi-endpoint tracking in the in-kernel name service (ns.c). QRTR sockets and the /dev/qrtr-tun device are fully accessible in standard QEMU virtualized environments without specialized hardware. Fuzzing is warranted to test new setsockopt/getsockopt logic, cmsg handling, and radix-tree/xarray concurrency and lifecycle management.",
  "WorthFuzzing": true
}

Results:
{
  "EnableConfigs": [
    "QRTR",
    "QRTR_TUN"
  ],
  "FocusSymbols": [
    "qrtr_setsockopt",
    "qrtr_getsockopt",
    "qrtr_msg_get_endpoint",
    "qrtr_sendmsg",
    "qrtr_recvmsg",
    "qrtr_endpoint_post",
    "qrtr_endpoint_register",
    "qrtr_ns_worker"
  ],
  "Reasoning": "The patch series implements endpoint-based isolation and tracking for Qualcomm IPC Router (AF_QIPCRTR) sockets. It introduces SOL_QRTR socket options (QRTR_REPORT_ENDPOINT, QRTR_BIND_ENDPOINT), ancillary control messages (QRTR_ENDPOINT) for sendmsg and recvmsg, per-endpoint radix-tree node management, and multi-endpoint tracking in the in-kernel name service (ns.c). QRTR sockets and the /dev/qrtr-tun device are fully accessible in standard QEMU virtualized environments without specialized hardware. Fuzzing is warranted to test new setsockopt/getsockopt logic, cmsg handling, and radix-tree/xarray concurrency and lifecycle management.",
  "WorthFuzzing": true
}

17/1 2026/09/15 06:24 action If
7m Args:
{
  "WorthFuzzing": true
}

Results:
null

18/2 2026/09/15 06:24 agent kmsan-evaluator
7m Model:
core

Args:
null

Results:
{
  "KMSANReasoning": "The patch series introduces endpoint routing and management to the Qualcomm IPC Router (QRTR) subsystem, adding setsockopt/getsockopt options (QRTR_REPORT_ENDPOINT, QRTR_BIND_ENDPOINT), CMSG endpoint support (QRTR_ENDPOINT), hierarchical radix trees for endpoint node lookups, and endpoint tracking in the nameservice daemon (ns.c).\n\nKMSAN vs KASAN applicability analysis:\n1. User-space copies \u0026 Info-leaks:\n   - In qrtr_getsockopt(), 'val' is an unsigned int (sizeof(int)) explicitly assigned via test_bit() or READ_ONCE(), and len is fixed to sizeof(int) before copy_to_user(). No uninitialized structure padding or uninitialized memory is exposed.\n   - In qrtr_setsockopt(), 'val' is initialized to 0 upon declaration, avoiding uninitialized memory use if optlen \u003c sizeof(val).\n   - In qrtr_recvmsg(), put_cmsg() is called with cb-\u003eendpoint_id (u32). The skb-\u003ecb endpoint_id is explicitly set on all packet ingress paths (qrtr_endpoint_post and qrtr_local_enqueue).\n   - In mhi.c, endpoint_show() formats ep.id into sysfs via sprintf().\n2. Uninitialized struct fields and buffers:\n   - In ns.c, all dynamically allocated structures (struct qrtr_ns_endpoint, struct qrtr_node, struct qrtr_server) are allocated with kzalloc_obj(). All control packets (struct qrtr_ctrl_pkt) transmitted by ns.c are explicitly cleared with memset(\u0026pkt, 0, sizeof(pkt)).\n   - In af_qrtr.c, helper0 is static in BSS, node is allocated with kzalloc, and ep-\u003ehelper in struct qrtr_endpoint is properly initialized.\n   - qrtr_msg_get_endpoint() initializes endpoint_id to 0 and strictly checks cmsg lengths before reading CMSG_DATA.\n3. Memory safety risks:\n   - The modifications alter radix tree hierarchies and node acquisition/release lifetimes (e.g., in __qrtr_node_release, qrtr_endpoint_register, qrtr_endpoint_unregister), which primarily risk use-after-free, NULL pointer dereferences, or lock-related deadlocks. These bugs are properly covered by KASAN and LOCKDEP.\n\nNo uninitialized memory hazards or info-leak risks are introduced or exposed. Therefore, a dedicated KMSAN fuzzing session is not warranted.",
  "NeedsKMSAN": false
}

Instruction:
You are an expert Linux kernel security engineer specializing in kernel memory
error detectors (KASAN and KMSAN). Your job is to review the provided patch series and
determine if the code changes justify spawning a dedicated KMSAN (KernelMemorySanitizer)
fuzzing session in addition to standard KASAN fuzzing.

CRITICAL DISTINCTION BETWEEN KASAN AND KMSAN:
- Standard KASAN kernel builds (upstream-apparmor-kasan.config) already enable
  a comprehensive suite of debugging tools and sanitizers, including KASAN
  (out-of-bounds accesses, use-after-free, double free, invalid free), LOCKDEP
  (locking bugs and deadlocks), UB-sanitizers, and memory corruption checks.
- KMSAN (KernelMemorySanitizer) detects reads of UNINITIALIZED memory (stack, heap,
  or page allocations) and kernel-to-user memory info-leaks.

Rule: THERE IS NO SENSE IN RUNNING A KMSAN SESSION IF A BUG CAN BE CAUGHT BY KASAN,
LOCKDEP, OR OTHER STANDARD BUG DETECTORS.
A dedicated KMSAN fuzzing session incurs significant resource costs. You must ONLY
set NeedsKMSAN=true if the code changes introduce or expose UNINITIALIZED MEMORY risks
that are detected ONLY by KMSAN.

Look holistically at the patch series and surrounding code. Even if no direct
uninitialized field accesses or new buffer allocations are added in the diff itself,
a patch may alter control flow, bounds checking, or data length calculations in ways
that change how the rest of the code operates on existing buffers (e.g. allowing
uninitialized stack/heap memory to be read, copied to user space, or used in control
flow). Do not hesitate to use your code access tools to inspect the surrounding code,
called functions, and callers.

Set NeedsKMSAN=true ONLY IF the patch introduces or modifies:
1. Kernel structures sent to user space (via copy_to_user, put_user, netlink skb
   attributes, ioctl output arguments, socket options, or BPF buffers) where fields
   or structure padding might not be fully initialized/zeroed.
2. Conditional logic or branching that depends on potentially uninitialized variables
   or struct fields.
3. Allocation or initialization of complex data structures where uninitialized fields
   could be read later in reachable code paths.
4. Bounds checks, lengths, or logic in a way that allows surrounding code to access
   uninitialized bytes of existing buffers.

Set NeedsKMSAN=false IF:
- The code changes primarily risk out-of-bounds access, array overflows, NULL pointer
  dereferences, locking deadlocks, or use-after-free bugs (these are already caught
  by KASAN, LOCKDEP, or standard bug detectors).
- All stack/heap structures touched or introduced by the patch are fully zeroed
  or initialized (e.g. using = {0}, memset, kzalloc) before being read or copied.
- The patch does not introduce any risk of uninitialized memory usage or info-leaks.

Use your code access tools to inspect the surrounding code if necessary, then provide
detailed KMSANReasoning contrasting KASAN vs KMSAN applicability for this patch.
Prefer calling several tools at the same time to save round-trips.


Use set-results tool to provide results of the analysis.
It must be called exactly once before the final reply.
Ignore results of this tool.

Prompt:
Target architecture: amd64

For your convenience, here is the diff of the changes:
commit e9367e40a1c817184c46735d76d64ca5edc6c819
Author: syz-cluster <triage@syzkaller.com>
Date:   Tue Sep 15 06:23:20 2026 +0000

    syz-cluster: applied patch under review

diff --git a/include/linux/socket.h b/include/linux/socket.h
index 5a5eb12501032..d4e2ba3bd6b39 100644
--- a/include/linux/socket.h
+++ b/include/linux/socket.h
@@ -400,6 +400,7 @@ struct ucred {
 #define SOL_MCTP	285
 #define SOL_SMC		286
 #define SOL_VSOCK	287
+#define SOL_QRTR	288
 
 /* IPX options */
 #define IPX_TYPE	1
diff --git a/include/uapi/linux/qrtr.h b/include/uapi/linux/qrtr.h
index f7e2fb3d752b5..0a8667b049c3d 100644
--- a/include/uapi/linux/qrtr.h
+++ b/include/uapi/linux/qrtr.h
@@ -46,4 +46,11 @@ struct qrtr_ctrl_pkt {
 	};
 } __packed;
 
+/* setsockopt / getsockopt */
+#define QRTR_REPORT_ENDPOINT 1
+#define QRTR_BIND_ENDPOINT 2
+
+/* CMSG */
+#define QRTR_ENDPOINT 1
+
 #endif /* _LINUX_QRTR_H */
diff --git a/net/qrtr/af_qrtr.c b/net/qrtr/af_qrtr.c
index a30fa56e6aa31..7c50d32b11015 100644
--- a/net/qrtr/af_qrtr.c
+++ b/net/qrtr/af_qrtr.c
@@ -22,9 +22,14 @@
 #define QRTR_MAX_EPH_SOCKET 0x7fff
 #define QRTR_EPH_PORT_RANGE \
 		XA_LIMIT(QRTR_MIN_EPH_SOCKET, QRTR_MAX_EPH_SOCKET)
+#define QRTR_ENDPOINT_RANGE XA_LIMIT(qrtr_local_nid + 1, INT_MAX)
 
 #define QRTR_PORT_CTRL_LEGACY 0xffff
 
+enum {
+	QRTR_F_REPORT_ENDPOINT,
+};
+
 /**
  * struct qrtr_hdr_v1 - (I|R)PCrouter packet header version 1
  * @version: protocol version
@@ -78,6 +83,7 @@ struct qrtr_cb {
 	u32 src_port;
 	u32 dst_node;
 	u32 dst_port;
+	u32 endpoint_id;
 
 	u8 type;
 	u8 confirm_rx;
@@ -91,6 +97,8 @@ struct qrtr_sock {
 	struct sock sk;
 	struct sockaddr_qrtr us;
 	struct sockaddr_qrtr peer;
+	unsigned long flags;
+	u32 bound_endpoint;
 };
 
 static inline struct qrtr_sock *qrtr_sk(struct sock *sk)
@@ -99,6 +107,43 @@ static inline struct qrtr_sock *qrtr_sk(struct sock *sk)
 	return container_of(sk, struct qrtr_sock, sk);
 }
 
+void qrtr_sock_set_report_endpoint(struct sock *sk)
+{
+	struct qrtr_sock *ipc = qrtr_sk(sk);
+
+	assign_bit(QRTR_F_REPORT_ENDPOINT, &ipc->flags, 1);
+}
+
+int qrtr_msg_get_endpoint(struct msghdr *msg, u32 *out_endpoint_id)
+{
+	struct cmsghdr *cmsg;
+	u32 endpoint_id = 0;
+
+	for_each_cmsghdr(cmsg, msg) {
+		if (!CMSG_OK(msg, cmsg))
+			return -EINVAL;
+
+		if (cmsg->cmsg_level != SOL_QRTR)
+			continue;
+
+		if (cmsg->cmsg_type != QRTR_ENDPOINT)
+			return -EINVAL;
+
+		if (cmsg->cmsg_len < CMSG_LEN(sizeof(u32)))
+			return -EINVAL;
+
+		/* Endpoint ids start at 1 */
+		endpoint_id = *(u32 *)CMSG_DATA(cmsg);
+		if (!endpoint_id)
+			return -EINVAL;
+	}
+
+	if (out_endpoint_id)
+		*out_endpoint_id = endpoint_id;
+
+	return 0;
+}
+
 static unsigned int qrtr_local_nid = 1;
 
 /* for node ids */
@@ -109,9 +154,37 @@ static LIST_HEAD(qrtr_all_nodes);
 /* lock for qrtr_all_nodes and node reference */
 static DEFINE_MUTEX(qrtr_node_lock);
 
+/* endpoint id allocation management */
+static DEFINE_XARRAY_ALLOC(qrtr_endpoints);
+static u32 next_endpoint_id;
+
 /* local port allocation management */
 static DEFINE_XARRAY_ALLOC(qrtr_ports);
 
+/* The xarray API uses fixed unsigned long keys and we will have to make
+ * do with that.
+ * These keys are often a combination of node IDs and port numbers or
+ * endpoint IDs and node IDs (all currently u32).
+ * Using the high 32 bits for the node/endpoint ID and the low 32 bits for the
+ * port number/node ID will work fine to create keys on platforms where
+ * unsigned long is 64 bits wide, but obviously is not be possible on
+ * platforms where unsigned long is smaller.
+ * Virtually split up unsigned long in half and assign the upper bits to
+ * node/endpoint IDs and the lower bits to the port number/node ID, however
+ * big that may be.
+ */
+#define QRTR_XARRAY_INDEX_BITS  (8 /* CHAR_BIT */ * sizeof(unsigned long))
+#define QRTR_INDEX_HALF_BITS (QRTR_XARRAY_INDEX_BITS >> 1)
+
+#define QRTR_INDEX_HALF_UNSIGNED_MAX ((~(unsigned long)(0)) >> QRTR_INDEX_HALF_BITS)
+#define QRTR_INDEX_HALF_UNSIGNED_MIN ((unsigned long)(0))
+
+#define QRTR_INDEX_HALF_SIGNED_MAX ((long)(QRTR_INDEX_HALF_UNSIGNED_MAX) >> 1)
+#define QRTR_INDEX_HALF_SIGNED_MIN ((long)(-1) - QRTR_INDEX_HALF_SIGNED_MAX)
+
+/* endpoint not defined, i.e. endpoint 0 */
+static struct qrtr_node_lookup_helper helper0;
+
 /**
  * struct qrtr_node - endpoint node
  * @ep_lock: lock for endpoint management and callbacks
@@ -152,9 +225,11 @@ struct qrtr_tx_flow {
 #define QRTR_TX_FLOW_LOW	5
 
 static int qrtr_local_enqueue(struct qrtr_node *node, struct sk_buff *skb,
+			      u32 endpoint_id,
 			      int type, struct sockaddr_qrtr *from,
 			      struct sockaddr_qrtr *to);
 static int qrtr_bcast_enqueue(struct qrtr_node *node, struct sk_buff *skb,
+			      u32 endpoint_id,
 			      int type, struct sockaddr_qrtr *from,
 			      struct sockaddr_qrtr *to);
 static struct qrtr_sock *qrtr_port_lookup(int port);
@@ -169,9 +244,11 @@ static void __qrtr_node_release(struct kref *kref)
 {
 	struct qrtr_node *node = container_of(kref, struct qrtr_node, ref);
 	struct radix_tree_iter iter;
+	struct radix_tree_iter iter2;
 	struct qrtr_tx_flow *flow;
 	unsigned long flags;
 	void __rcu **slot;
+	void __rcu **slot2;
 	unsigned long index;
 
 	spin_lock_irqsave(&qrtr_nodes_lock, flags);
@@ -179,8 +256,18 @@ static void __qrtr_node_release(struct kref *kref)
 	 * multiple entries pointing to our released node, delete them all.
 	 */
 	radix_tree_for_each_slot(slot, &qrtr_nodes, &iter, 0) {
-		if (*slot == node)
+		struct qrtr_node_lookup_helper *helper = *slot;
+
+		if (!helper)
+			continue;
+		radix_tree_for_each_slot(slot2, &helper->nodes, &iter2, 0) {
+			if (*slot2 == node)
+				radix_tree_iter_delete(&helper->nodes, &iter2, slot2);
+		}
+		if (helper != &helper0 && radix_tree_empty(&helper->nodes)) {
 			radix_tree_iter_delete(&qrtr_nodes, &iter, slot);
+			helper->added = 0;
+		}
 	}
 	spin_unlock_irqrestore(&qrtr_nodes_lock, flags);
 
@@ -216,16 +303,23 @@ static void qrtr_node_release(struct qrtr_node *node)
  * qrtr_tx_resume() - reset flow control counter
  * @node:	qrtr_node that the QRTR_TYPE_RESUME_TX packet arrived on
  * @skb:	resume_tx packet
+ *
+ * Return: 0 on success; negative error code on failure
  */
-static void qrtr_tx_resume(struct qrtr_node *node, struct sk_buff *skb)
+static int qrtr_tx_resume(struct qrtr_node *node, struct sk_buff *skb)
 {
 	struct qrtr_ctrl_pkt *pkt = (struct qrtr_ctrl_pkt *)skb->data;
 	u64 remote_node = le32_to_cpu(pkt->client.node);
 	u32 remote_port = le32_to_cpu(pkt->client.port);
 	struct qrtr_tx_flow *flow;
-	unsigned long key;
+	unsigned long key = 0;
+
+	/* Don't check node/port for the valid range, use only low
+	 * 16 bits on 32-bit architectures.
+	 */
 
-	key = remote_node << 32 | remote_port;
+	key = ((unsigned long)(remote_node) << QRTR_INDEX_HALF_BITS) |
+	      ((unsigned long)(remote_port) & QRTR_INDEX_HALF_UNSIGNED_MAX);
 
 	flow = xa_load(&node->qrtr_tx_flow, key);
 	if (flow) {
@@ -236,6 +330,8 @@ static void qrtr_tx_resume(struct qrtr_node *node, struct sk_buff *skb)
 	}
 
 	consume_skb(skb);
+
+	return 0;
 }
 
 /**
@@ -256,11 +352,18 @@ static void qrtr_tx_resume(struct qrtr_node *node, struct sk_buff *skb)
 static int qrtr_tx_wait(struct qrtr_node *node, int dest_node, int dest_port,
 			int type)
 {
-	unsigned long key = (u64)dest_node << 32 | dest_port;
+	unsigned long key = 0;
 	struct qrtr_tx_flow *flow;
 	int confirm_rx = 0;
 	int ret;
 
+	/* Don't check node/port for the valid range, use only low
+	 * 16 bits on 32-bit architectures.
+	 */
+
+	key = ((unsigned long)(dest_node) << QRTR_INDEX_HALF_BITS) |
+	      ((unsigned long)(dest_port) & QRTR_INDEX_HALF_UNSIGNED_MAX);
+
 	/* Never set confirm_rx on non-data packets */
 	if (type != QRTR_TYPE_DATA)
 		return 0;
@@ -317,23 +420,35 @@ static int qrtr_tx_wait(struct qrtr_node *node, int dest_node, int dest_port,
  * message associated with the dropped confirm_rx message.
  * Work around this by marking the flow as having a failed transmission and
  * cause the next transmission attempt to be sent with the confirm_rx.
+ *
+ * Return: 0 on success; negative error code on failure
  */
-static void qrtr_tx_flow_failed(struct qrtr_node *node, int dest_node,
-				int dest_port)
+static int qrtr_tx_flow_failed(struct qrtr_node *node, int dest_node,
+			       int dest_port)
 {
-	unsigned long key = (u64)dest_node << 32 | dest_port;
+	unsigned long key = 0;
 	struct qrtr_tx_flow *flow;
 
+	/* Don't check node/port for the valid range, use only low
+	 * 16 bits on 32-bit architectures.
+	 */
+
+	key = ((unsigned long)(dest_node) << QRTR_INDEX_HALF_BITS) |
+	      ((unsigned long)(dest_port) & QRTR_INDEX_HALF_UNSIGNED_MAX);
+
 	flow = xa_load(&node->qrtr_tx_flow, key);
 	if (flow) {
 		spin_lock_irq(&flow->resume_tx.lock);
 		flow->tx_failed = 1;
 		spin_unlock_irq(&flow->resume_tx.lock);
 	}
+
+	return 0;
 }
 
 /* Pass an outgoing packet socket buffer to the endpoint driver. */
 static int qrtr_node_enqueue(struct qrtr_node *node, struct sk_buff *skb,
+			     u32 endpoint_id,
 			     int type, struct sockaddr_qrtr *from,
 			     struct sockaddr_qrtr *to)
 {
@@ -377,7 +492,7 @@ static int qrtr_node_enqueue(struct qrtr_node *node, struct sk_buff *skb,
 	/* Need to ensure that a subsequent message carries the otherwise lost
 	 * confirm_rx flag if we dropped this one */
 	if (rc && confirm_rx)
-		qrtr_tx_flow_failed(node, to->sq_node, to->sq_port);
+		rc = qrtr_tx_flow_failed(node, to->sq_node, to->sq_port);
 
 	return rc;
 }
@@ -386,14 +501,18 @@ static int qrtr_node_enqueue(struct qrtr_node *node, struct sk_buff *skb,
  *
  * callers must release with qrtr_node_release()
  */
-static struct qrtr_node *qrtr_node_lookup(unsigned int nid)
+static struct qrtr_node *qrtr_node_lookup(unsigned int endpoint_id,
+					  unsigned int nid)
 {
-	struct qrtr_node *node;
+	struct qrtr_node *node = NULL;
+	struct qrtr_node_lookup_helper *helper = NULL;
 	unsigned long flags;
 
 	mutex_lock(&qrtr_node_lock);
 	spin_lock_irqsave(&qrtr_nodes_lock, flags);
-	node = radix_tree_lookup(&qrtr_nodes, nid);
+	helper = radix_tree_lookup(&qrtr_nodes, endpoint_id);
+	if (helper)
+		node = radix_tree_lookup(&helper->nodes, nid);
 	node = qrtr_node_acquire(node);
 	spin_unlock_irqrestore(&qrtr_nodes_lock, flags);
 	mutex_unlock(&qrtr_node_lock);
@@ -405,19 +524,51 @@ 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;
+	int rc = 0;
+	int did_insert0 = 0;
 
 	if (nid == QRTR_EP_NID_AUTO)
-		return;
+		return 0;
 
 	spin_lock_irqsave(&qrtr_nodes_lock, flags);
-	radix_tree_insert(&qrtr_nodes, nid, node);
+
+	if (!radix_tree_lookup(&helper0.nodes, nid)) {
+		rc = radix_tree_insert(&helper0.nodes, nid, node);
+		if (rc)
+			goto err_lock;
+		did_insert0 = 1;
+	}
+	if (!node->ep->helper.added) {
+		INIT_RADIX_TREE(&node->ep->helper.nodes, GFP_ATOMIC);
+		rc = radix_tree_insert(&qrtr_nodes, node->ep->id,
+				       &node->ep->helper);
+		if (rc)
+			goto err_insert0;
+		node->ep->helper.added = 1;
+	}
+	rc = radix_tree_insert(&node->ep->helper.nodes, nid, node);
+	if (rc && rc != -EEXIST)
+		goto err_insert0; // Don't revert helper insertion
+
 	if (node->nid == QRTR_EP_NID_AUTO)
 		node->nid = nid;
 	spin_unlock_irqrestore(&qrtr_nodes_lock, flags);
+
+	return 0;
+
+err_insert0:
+	if (did_insert0)
+		radix_tree_delete(&helper0.nodes, nid);
+
+err_lock:
+	spin_unlock_irqrestore(&qrtr_nodes_lock, flags);
+	return rc;
 }
 
 /**
@@ -439,6 +590,7 @@ int qrtr_endpoint_post(struct qrtr_endpoint *ep, const void *data, size_t len)
 	size_t size;
 	unsigned int ver;
 	size_t hdrlen;
+	int ret = -EINVAL;
 
 	if (len == 0 || len & 3)
 		return -EINVAL;
@@ -496,9 +648,16 @@ int qrtr_endpoint_post(struct qrtr_endpoint *ep, const void *data, size_t len)
 	if (cb->dst_port == QRTR_PORT_CTRL_LEGACY)
 		cb->dst_port = QRTR_PORT_CTRL;
 
+	cb->endpoint_id = ep->id;
+
 	if (!size || size > len || len != ALIGN(size, 4) + hdrlen)
 		goto err;
 
+	/* Don't allow remote lookups */
+	if (cb->type == QRTR_TYPE_NEW_LOOKUP ||
+	    cb->type == QRTR_TYPE_DEL_LOOKUP)
+		goto err;
+
 	if ((cb->type == QRTR_TYPE_NEW_SERVER ||
 	     cb->type == QRTR_TYPE_RESUME_TX) &&
 	    size < sizeof(struct qrtr_ctrl_pkt))
@@ -510,26 +669,39 @@ int qrtr_endpoint_post(struct qrtr_endpoint *ep, const void *data, size_t len)
 
 	skb_put_data(skb, data + hdrlen, size);
 
-	qrtr_node_assign(node, cb->src_node);
+	ret = qrtr_node_assign(node, cb->src_node);
+	if (ret)
+		goto err;
 
 	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) {
-		qrtr_tx_resume(node, skb);
+		ret = qrtr_tx_resume(node, skb);
+		if (ret)
+			goto err;
 	} else {
 		ipc = qrtr_port_lookup(cb->dst_port);
-		if (!ipc)
+		if (!ipc) {
+			ret = -EINVAL;
 			goto err;
+		}
 
-		if (sock_queue_rcv_skb(&ipc->sk, skb)) {
-			qrtr_port_put(ipc);
-			goto err;
+		/* Sockets bound to an endpoint only rx from that endpoint */
+		if (!ipc->bound_endpoint ||
+		    ipc->bound_endpoint == cb->endpoint_id) {
+			ret = sock_queue_rcv_skb(&ipc->sk, skb);
+			if (ret) {
+				qrtr_port_put(ipc);
+				goto err;
+			}
 		}
 
 		qrtr_port_put(ipc);
@@ -539,7 +711,7 @@ int qrtr_endpoint_post(struct qrtr_endpoint *ep, const void *data, size_t len)
 
 err:
 	kfree_skb(skb);
-	return -EINVAL;
+	return ret;
 
 }
 EXPORT_SYMBOL_GPL(qrtr_endpoint_post);
@@ -581,6 +753,8 @@ static struct sk_buff *qrtr_alloc_ctrl_packet(struct qrtr_ctrl_pkt **pkt,
 int qrtr_endpoint_register(struct qrtr_endpoint *ep, unsigned int nid)
 {
 	struct qrtr_node *node;
+	u32 endpoint_id;
+	int rc;
 
 	if (!ep || !ep->xmit)
 		return -EINVAL;
@@ -589,6 +763,13 @@ int qrtr_endpoint_register(struct qrtr_endpoint *ep, unsigned int nid)
 	if (!node)
 		return -ENOMEM;
 
+	rc = xa_alloc_cyclic(&qrtr_endpoints, &endpoint_id, NULL,
+			     QRTR_ENDPOINT_RANGE, &next_endpoint_id,
+			     GFP_KERNEL);
+
+	if (rc < 0)
+		goto free_node;
+
 	kref_init(&node->ref);
 	mutex_init(&node->ep_lock);
 	skb_queue_head_init(&node->rx_queue);
@@ -598,14 +779,21 @@ int qrtr_endpoint_register(struct qrtr_endpoint *ep, unsigned int nid)
 	xa_init(&node->qrtr_tx_flow);
 	mutex_init(&node->qrtr_tx_lock);
 
-	qrtr_node_assign(node, nid);
+	rc = qrtr_node_assign(node, nid);
+	if (rc < 0)
+		goto free_node;
 
 	mutex_lock(&qrtr_node_lock);
 	list_add(&node->item, &qrtr_all_nodes);
 	mutex_unlock(&qrtr_node_lock);
 	ep->node = node;
+	ep->id = endpoint_id;
+	ep->helper.added = 0;
 
 	return 0;
+free_node:
+	kfree(node);
+	return rc;
 }
 EXPORT_SYMBOL_GPL(qrtr_endpoint_register);
 
@@ -619,29 +807,46 @@ void qrtr_endpoint_unregister(struct qrtr_endpoint *ep)
 	struct sockaddr_qrtr src = {AF_QIPCRTR, node->nid, QRTR_PORT_CTRL};
 	struct sockaddr_qrtr dst = {AF_QIPCRTR, qrtr_local_nid, QRTR_PORT_CTRL};
 	struct radix_tree_iter iter;
+	struct radix_tree_iter iter2;
 	struct qrtr_ctrl_pkt *pkt;
 	struct qrtr_tx_flow *flow;
 	struct sk_buff *skb;
 	unsigned long flags;
 	unsigned long index;
 	void __rcu **slot;
+	void __rcu **slot2;
+	u32 endpoint_id;
 
 	mutex_lock(&node->ep_lock);
+	endpoint_id = node->ep->id;
 	node->ep = NULL;
 	mutex_unlock(&node->ep_lock);
 
 	/* Notify the local controller about the event */
 	spin_lock_irqsave(&qrtr_nodes_lock, flags);
 	radix_tree_for_each_slot(slot, &qrtr_nodes, &iter, 0) {
-		if (*slot != node)
+		struct qrtr_node_lookup_helper *helper = *slot;
+
+		if (!helper)
 			continue;
-		src.sq_node = iter.index;
-		skb = qrtr_alloc_ctrl_packet(&pkt, GFP_ATOMIC);
-		if (skb) {
-			pkt->cmd = cpu_to_le32(QRTR_TYPE_BYE);
-			qrtr_local_enqueue(NULL, skb, QRTR_TYPE_BYE, &src, &dst);
+		radix_tree_for_each_slot(slot2, &helper->nodes, &iter2, 0) {
+			if (*slot2 != node)
+				continue;
+			src.sq_node = iter.index;
+			skb = qrtr_alloc_ctrl_packet(&pkt, GFP_ATOMIC);
+			if (skb) {
+				pkt->cmd = cpu_to_le32(QRTR_TYPE_BYE);
+				qrtr_local_enqueue(NULL, skb, endpoint_id,
+						   QRTR_TYPE_BYE, &src, &dst);
+			}
 		}
 	}
+	if (ep->helper.added) {
+		radix_tree_for_each_slot(slot, &ep->helper.nodes, &iter, 0)
+			radix_tree_iter_delete(&ep->helper.nodes, &iter, slot);
+		radix_tree_delete(&qrtr_nodes, ep->id);
+		ep->helper.added = 0;
+	}
 	spin_unlock_irqrestore(&qrtr_nodes_lock, flags);
 
 	/* Wake up any transmitters waiting for resume-tx from the node */
@@ -651,6 +856,10 @@ void qrtr_endpoint_unregister(struct qrtr_endpoint *ep)
 	mutex_unlock(&node->qrtr_tx_lock);
 
 	qrtr_node_release(node);
+
+	xa_erase(&qrtr_endpoints, endpoint_id);
+
+	ep->id = 0;
 	ep->node = NULL;
 }
 EXPORT_SYMBOL_GPL(qrtr_endpoint_unregister);
@@ -700,8 +909,8 @@ static void qrtr_port_remove(struct qrtr_sock *ipc)
 		pkt->client.port = cpu_to_le32(ipc->us.sq_port);
 
 		skb_set_owner_w(skb, &ipc->sk);
-		qrtr_bcast_enqueue(NULL, skb, QRTR_TYPE_DEL_CLIENT, &ipc->us,
-				   &to);
+		qrtr_bcast_enqueue(NULL, skb, qrtr_local_nid,
+				   QRTR_TYPE_DEL_CLIENT, &ipc->us, &to);
 	}
 
 	if (port == QRTR_PORT_CTRL)
@@ -841,37 +1050,52 @@ static int qrtr_bind(struct socket *sock, struct sockaddr_unsized *saddr, int le
 
 /* Queue packet to local peer socket. */
 static int qrtr_local_enqueue(struct qrtr_node *node, struct sk_buff *skb,
+			      u32 endpoint_id,
 			      int type, struct sockaddr_qrtr *from,
 			      struct sockaddr_qrtr *to)
 {
 	struct qrtr_sock *ipc;
 	struct qrtr_cb *cb;
+	int ret = -ENODEV;
 
 	ipc = qrtr_port_lookup(to->sq_port);
-	if (!ipc || &ipc->sk == skb->sk) { /* do not send to self */
-		if (ipc)
-			qrtr_port_put(ipc);
-		kfree_skb(skb);
-		return -ENODEV;
-	}
+	if (!ipc)
+		goto done;
+
+	if (&ipc->sk == skb->sk) /* do not send to self */
+		goto done;
+
+	/*
+	 * Filter out unwanted packets that are not on behalf of the bound
+	 * endpoint.  Certain special packets (such as an empty NEW_SERVER
+	 * packet that serves as a sentinel value) always go through.
+	 */
+	if (endpoint_id && ipc->bound_endpoint &&
+	    ipc->bound_endpoint != endpoint_id)
+		goto done;
 
 	cb = (struct qrtr_cb *)skb->cb;
 	cb->src_node = from->sq_node;
 	cb->src_port = from->sq_port;
+	cb->endpoint_id = endpoint_id;
 
-	if (sock_queue_rcv_skb(&ipc->sk, skb)) {
-		qrtr_port_put(ipc);
-		kfree_skb(skb);
-		return -ENOSPC;
-	}
+	ret = -ENOSPC;
+	if (sock_queue_rcv_skb(&ipc->sk, skb))
+		goto done;
 
 	qrtr_port_put(ipc);
 
 	return 0;
+done:
+	if (ipc)
+		qrtr_port_put(ipc);
+	kfree_skb(skb);
+	return ret;
 }
 
 /* Queue packet for broadcast. */
 static int qrtr_bcast_enqueue(struct qrtr_node *node, struct sk_buff *skb,
+			      u32 endpoint_id,
 			      int type, struct sockaddr_qrtr *from,
 			      struct sockaddr_qrtr *to)
 {
@@ -883,11 +1107,11 @@ static int qrtr_bcast_enqueue(struct qrtr_node *node, struct sk_buff *skb,
 		if (!skbn)
 			break;
 		skb_set_owner_w(skbn, skb->sk);
-		qrtr_node_enqueue(node, skbn, type, from, to);
+		qrtr_node_enqueue(node, skbn, endpoint_id, type, from, to);
 	}
 	mutex_unlock(&qrtr_node_lock);
 
-	qrtr_local_enqueue(NULL, skb, type, from, to);
+	qrtr_local_enqueue(NULL, skb, endpoint_id, type, from, to);
 
 	return 0;
 }
@@ -895,12 +1119,16 @@ static int qrtr_bcast_enqueue(struct qrtr_node *node, struct sk_buff *skb,
 static int qrtr_sendmsg(struct socket *sock, struct msghdr *msg, size_t len)
 {
 	DECLARE_SOCKADDR(struct sockaddr_qrtr *, addr, msg->msg_name);
-	int (*enqueue_fn)(struct qrtr_node *, struct sk_buff *, int,
-			  struct sockaddr_qrtr *, struct sockaddr_qrtr *);
+	int (*enqueue_fn)(struct qrtr_node *node, struct sk_buff *skb,
+			  u32 endpoint_id, int type,
+			  struct sockaddr_qrtr *from,
+			  struct sockaddr_qrtr *to);
 	__le32 qrtr_type = cpu_to_le32(QRTR_TYPE_DATA);
 	struct qrtr_sock *ipc = qrtr_sk(sock->sk);
 	struct sock *sk = sock->sk;
 	struct qrtr_node *node;
+	u32 msg_endpoint_id;
+	u32 endpoint_id = qrtr_local_nid;
 	struct sk_buff *skb;
 	size_t plen;
 	u32 type;
@@ -912,46 +1140,49 @@ static int qrtr_sendmsg(struct socket *sock, struct msghdr *msg, size_t len)
 	if (len > 65535)
 		return -EMSGSIZE;
 
+	rc = qrtr_msg_get_endpoint(msg, &msg_endpoint_id);
+	if (rc < 0)
+		return rc;
+
 	lock_sock(sk);
 
 	if (addr) {
-		if (msg->msg_namelen < sizeof(*addr)) {
-			release_sock(sk);
-			return -EINVAL;
-		}
+		rc = -EINVAL;
 
-		if (addr->sq_family != AF_QIPCRTR) {
-			release_sock(sk);
-			return -EINVAL;
-		}
+		if (msg->msg_namelen < sizeof(*addr))
+			goto release_sock;
+
+		if (addr->sq_family != AF_QIPCRTR)
+			goto release_sock;
 
 		rc = qrtr_autobind(sock);
-		if (rc) {
-			release_sock(sk);
-			return rc;
-		}
+		if (rc)
+			goto release_sock;
 	} else if (sk->sk_state == TCP_ESTABLISHED) {
 		addr = &ipc->peer;
 	} else {
-		release_sock(sk);
-		return -ENOTCONN;
+		rc = -ENOTCONN;
+		goto release_sock;
 	}
 
 	node = NULL;
 	if (addr->sq_node == QRTR_NODE_BCAST) {
 		if (addr->sq_port != QRTR_PORT_CTRL &&
 		    qrtr_local_nid != QRTR_NODE_BCAST) {
-			release_sock(sk);
-			return -ENOTCONN;
+			rc = -ENOTCONN;
+			goto release_sock;
 		}
 		enqueue_fn = qrtr_bcast_enqueue;
 	} else if (addr->sq_node == ipc->us.sq_node) {
 		enqueue_fn = qrtr_local_enqueue;
 	} else {
-		node = qrtr_node_lookup(addr->sq_node);
+		endpoint_id = msg_endpoint_id ?
+			      msg_endpoint_id : ipc->bound_endpoint;
+
+		node = qrtr_node_lookup(endpoint_id, addr->sq_node);
 		if (!node) {
-			release_sock(sk);
-			return -ECONNRESET;
+			rc = endpoint_id ? -ENXIO : -ECONNRESET;
+			goto release_sock;
 		}
 		enqueue_fn = qrtr_node_enqueue;
 	}
@@ -981,15 +1212,21 @@ static int qrtr_sendmsg(struct socket *sock, struct msghdr *msg, size_t len)
 
 		/* control messages already require the type as 'command' */
 		skb_copy_bits(skb, 0, &qrtr_type, 4);
+		/*
+		 * Allow local name service to make packets appear as if
+		 * they originated remotely
+		 */
+		endpoint_id = msg_endpoint_id;
 	}
 
 	type = le32_to_cpu(qrtr_type);
-	rc = enqueue_fn(node, skb, type, &ipc->us, addr);
+	rc = enqueue_fn(node, skb, endpoint_id, type, &ipc->us, addr);
 	if (rc >= 0)
 		rc = len;
 
 out_node:
 	qrtr_node_release(node);
+release_sock:
 	release_sock(sk);
 
 	return rc;
@@ -1004,7 +1241,7 @@ static int qrtr_send_resume_tx(struct qrtr_cb *cb)
 	struct sk_buff *skb;
 	int ret;
 
-	node = qrtr_node_lookup(remote.sq_node);
+	node = qrtr_node_lookup(cb->endpoint_id, remote.sq_node);
 	if (!node)
 		return -EINVAL;
 
@@ -1018,7 +1255,8 @@ static int qrtr_send_resume_tx(struct qrtr_cb *cb)
 	pkt->client.node = cpu_to_le32(cb->dst_node);
 	pkt->client.port = cpu_to_le32(cb->dst_port);
 
-	ret = qrtr_node_enqueue(node, skb, QRTR_TYPE_RESUME_TX, &local, &remote);
+	ret = qrtr_node_enqueue(node, skb, cb->endpoint_id,
+				QRTR_TYPE_RESUME_TX, &local, &remote);
 
 	qrtr_node_release(node);
 
@@ -1029,6 +1267,7 @@ static int qrtr_recvmsg(struct socket *sock, struct msghdr *msg,
 			size_t size, int flags)
 {
 	DECLARE_SOCKADDR(struct sockaddr_qrtr *, addr, msg->msg_name);
+	struct qrtr_sock *ipc = qrtr_sk(sock->sk);
 	struct sock *sk = sock->sk;
 	struct sk_buff *skb;
 	struct qrtr_cb *cb;
@@ -1054,6 +1293,10 @@ static int qrtr_recvmsg(struct socket *sock, struct msghdr *msg,
 		msg->msg_flags |= MSG_TRUNC;
 	}
 
+	if (cb->endpoint_id && test_bit(QRTR_F_REPORT_ENDPOINT, &ipc->flags))
+		put_cmsg(msg, SOL_QRTR, QRTR_ENDPOINT,
+			 sizeof(cb->endpoint_id), &cb->endpoint_id);
+
 	rc = skb_copy_datagram_msg(skb, 0, msg, copied);
 	if (rc < 0)
 		goto out;
@@ -1199,6 +1442,74 @@ static int qrtr_ioctl(struct socket *sock, unsigned int cmd, unsigned long arg)
 	return rc;
 }
 
+static int qrtr_setsockopt(struct socket *sock, int level, int optname,
+			   sockptr_t optval, unsigned int optlen)
+{
+	struct qrtr_sock *ipc = qrtr_sk(sock->sk);
+	unsigned int val = 0;
+	int rc = 0;
+
+	if (level != SOL_QRTR)
+		return -ENOPROTOOPT;
+
+	if (optlen >= sizeof(val) &&
+	    copy_from_sockptr(&val, optval, sizeof(val)))
+		return -EFAULT;
+
+	switch (optname) {
+	case QRTR_REPORT_ENDPOINT:
+		assign_bit(QRTR_F_REPORT_ENDPOINT, &ipc->flags, val);
+		break;
+	case QRTR_BIND_ENDPOINT:
+		WRITE_ONCE(ipc->bound_endpoint, val);
+		break;
+	default:
+		rc = -ENOPROTOOPT;
+	}
+
+	return rc;
+}
+
+static int qrtr_getsockopt(struct socket *sock, int level, int optname,
+			   char __user *optval, int __user *optlen)
+{
+	struct qrtr_sock *ipc = qrtr_sk(sock->sk);
+	unsigned int val;
+	int len;
+	int rc = 0;
+
+	if (level != SOL_QRTR)
+		return -ENOPROTOOPT;
+
+	if (get_user(len, optlen))
+		return -EFAULT;
+
+	if (len < sizeof(val))
+		return -EINVAL;
+
+	switch (optname) {
+	case QRTR_REPORT_ENDPOINT:
+		val = test_bit(QRTR_F_REPORT_ENDPOINT, &ipc->flags);
+		break;
+	case QRTR_BIND_ENDPOINT:
+		val = READ_ONCE(ipc->bound_endpoint);
+		break;
+	default:
+		rc = -ENOPROTOOPT;
+	}
+
+	if (rc)
+		return rc;
+
+	len = sizeof(int);
+
+	if (put_user(len, optlen) ||
+	    copy_to_user(optval, &val, len))
+		rc = -EFAULT;
+
+	return rc;
+}
+
 static int qrtr_release(struct socket *sock)
 {
 	struct sock *sk = sock->sk;
@@ -1246,6 +1557,8 @@ static const struct proto_ops qrtr_proto_ops = {
 	.shutdown	= sock_no_shutdown,
 	.release	= qrtr_release,
 	.mmap		= sock_no_mmap,
+	.setsockopt	= qrtr_setsockopt,
+	.getsockopt	= qrtr_getsockopt,
 };
 
 static struct proto qrtr_proto = {
@@ -1310,8 +1623,17 @@ static int __init qrtr_proto_init(void)
 	if (rc)
 		goto err_sock;
 
+	rc = radix_tree_insert(&qrtr_nodes, 0, &helper0);
+	if (rc)
+		goto err_ns;
+
+	INIT_RADIX_TREE(&helper0.nodes, GFP_ATOMIC);
+	helper0.added = 1;
+
 	return 0;
 
+err_ns:
+	qrtr_ns_remove();
 err_sock:
 	sock_unregister(qrtr_family.family);
 err_proto:
@@ -1322,6 +1644,7 @@ postcore_initcall(qrtr_proto_init);
 
 static void __exit qrtr_proto_fini(void)
 {
+	radix_tree_delete(&qrtr_nodes, 0);
 	qrtr_ns_remove();
 	sock_unregister(qrtr_family.family);
 	proto_unregister(&qrtr_proto);
diff --git a/net/qrtr/mhi.c b/net/qrtr/mhi.c
index 3990da1a65dc4..630ce0da060e5 100644
--- a/net/qrtr/mhi.c
+++ b/net/qrtr/mhi.c
@@ -106,6 +106,16 @@ static int qcom_mhi_qrtr_queue_dl_buffers(struct mhi_device *mhi_dev)
 	return 0;
 }
 
+static ssize_t endpoint_show(struct device *dev,
+			     struct device_attribute *attr, char *buf)
+{
+	struct qrtr_mhi_dev *qdev = dev_get_drvdata(dev);
+
+	return sprintf(buf, "%u\n", qdev->ep.id);
+}
+
+static DEVICE_ATTR_RO(endpoint);
+
 static int qcom_mhi_qrtr_probe(struct mhi_device *mhi_dev,
 			       const struct mhi_device_id *id)
 {
@@ -135,6 +145,9 @@ static int qcom_mhi_qrtr_probe(struct mhi_device *mhi_dev,
 	if (rc)
 		goto err_unregister;
 
+	if (device_create_file(&mhi_dev->dev, &dev_attr_endpoint) < 0)
+		dev_err(qdev->dev, "Failed to create endpoint attribute\n");
+
 	dev_dbg(qdev->dev, "Qualcomm MHI QRTR driver probed\n");
 
 	return 0;
@@ -151,6 +164,7 @@ static void qcom_mhi_qrtr_remove(struct mhi_device *mhi_dev)
 {
 	struct qrtr_mhi_dev *qdev = dev_get_drvdata(&mhi_dev->dev);
 
+	device_remove_file(&mhi_dev->dev, &dev_attr_endpoint);
 	qrtr_endpoint_unregister(&qdev->ep);
 	mhi_unprepare_from_transfer(mhi_dev);
 	dev_set_drvdata(&mhi_dev->dev, NULL);
diff --git a/net/qrtr/ns.c b/net/qrtr/ns.c
index c5e7e01db2498..31dfa764e186a 100644
--- a/net/qrtr/ns.c
+++ b/net/qrtr/ns.c
@@ -5,6 +5,7 @@
  * Copyright (c) 2020, Linaro Ltd.
  */
 
+#define pr_fmt(fmt) "QRTR NS: "fmt
 #include <linux/module.h>
 #include <linux/qrtr.h>
 #include <linux/workqueue.h>
@@ -16,7 +17,7 @@
 #define CREATE_TRACE_POINTS
 #include <trace/events/qrtr.h>
 
-static DEFINE_XARRAY(nodes);
+static DEFINE_XARRAY(endpoints);
 
 static struct {
 	struct socket *sock;
@@ -62,6 +63,7 @@ struct qrtr_server {
 
 	unsigned int node;
 	unsigned int port;
+	u32 endpoint_id;
 
 	struct list_head qli;
 };
@@ -72,6 +74,11 @@ struct qrtr_node {
 	u32 server_count;
 };
 
+struct qrtr_ns_endpoint {
+	unsigned int id;
+	struct xarray nodes;
+};
+
 /* Max nodes, server, lookup limits are chosen based on the current platform
  * requirements. If the requirement changes in the future, these values can be
  * increased.
@@ -82,35 +89,90 @@ struct qrtr_node {
 
 static u16 node_count;
 
-static struct qrtr_node *node_get(unsigned int node_id)
+static struct qrtr_node *node_get(u32 endpoint_id, unsigned int node_id)
 {
+	struct qrtr_ns_endpoint *endpoint;
 	struct qrtr_node *node;
+	bool new_endpoint = false;
+
+	endpoint = xa_load(&endpoints, endpoint_id);
+	if (!endpoint) {
+		endpoint = kzalloc_obj(*endpoint);
+		if (!endpoint)
+			return NULL;
+
+		endpoint->id = endpoint_id;
+		xa_init(&endpoint->nodes);
+
+		if (xa_store(&endpoints, endpoint_id, endpoint, GFP_KERNEL)) {
+			kfree(endpoint);
+			return NULL;
+		}
+
+		new_endpoint = true;
+	}
 
-	node = xa_load(&nodes, node_id);
+	node = xa_load(&endpoint->nodes, node_id);
 	if (node)
 		return node;
 
 	if (node_count >= QRTR_NS_MAX_NODES) {
 		pr_err_ratelimited("QRTR clients exceed max node limit!\n");
-		return NULL;
+		goto error;
 	}
 
 	/* If node didn't exist, allocate and insert it to the tree */
 	node = kzalloc_obj(*node);
 	if (!node)
-		return NULL;
+		goto error;
 
 	node->id = node_id;
 	xa_init(&node->servers);
 
-	if (xa_store(&nodes, node_id, node, GFP_KERNEL)) {
+	if (xa_store(&endpoint->nodes, node_id, node, GFP_KERNEL)) {
 		kfree(node);
-		return NULL;
+		goto error;
 	}
 
 	node_count++;
 
 	return node;
+error:
+	if (new_endpoint) {
+		xa_erase(&endpoints, endpoint_id);
+		kfree(endpoint);
+	}
+
+	return NULL;
+}
+
+static void node_erase(u32 endpoint_id, unsigned int node_id)
+{
+	struct qrtr_ns_endpoint *endpoint;
+	struct qrtr_node *node;
+
+	endpoint = xa_load(&endpoints, endpoint_id);
+	if (!endpoint)
+		return;
+
+	node = xa_load(&endpoint->nodes, node_id);
+	if (!node)
+		return;
+
+	xa_erase(&endpoint->nodes, node_id);
+	kfree(node);
+	node_count--;
+}
+
+static struct qrtr_node *node_lookup(u32 endpoint_id, unsigned int node_id)
+{
+	struct qrtr_ns_endpoint *endpoint;
+
+	endpoint = xa_load(&endpoints, endpoint_id);
+	if (!endpoint)
+		return NULL;
+
+	return xa_load(&endpoint->nodes, node_id);
 }
 
 static int server_match(const struct qrtr_server *srv,
@@ -126,19 +188,42 @@ static int server_match(const struct qrtr_server *srv,
 	return (srv->instance & ifilter) == f->instance;
 }
 
-static int service_announce_new(struct sockaddr_qrtr *dest,
-				struct qrtr_server *srv)
+static int qrtr_ns_sendmsg(u32 endpoint_id, struct sockaddr_qrtr *dest,
+			   struct qrtr_ctrl_pkt *pkt)
 {
-	struct qrtr_ctrl_pkt pkt;
 	struct msghdr msg = { };
 	struct kvec iv;
+	u8 control[CMSG_SPACE(sizeof(endpoint_id))];
+	struct cmsghdr *cmsg;
+
+	iv.iov_base = pkt;
+	iv.iov_len = sizeof(*pkt);
+
+	msg.msg_name = (struct sockaddr *)dest;
+	msg.msg_namelen = sizeof(*dest);
+
+	if (endpoint_id) {
+		msg.msg_control = control;
+		msg.msg_controllen = sizeof(control);
+
+		cmsg = CMSG_FIRSTHDR(&msg);
+		cmsg->cmsg_level = SOL_QRTR;
+		cmsg->cmsg_type = QRTR_ENDPOINT;
+		cmsg->cmsg_len = CMSG_LEN(sizeof(endpoint_id));
+		memcpy(CMSG_DATA(cmsg), &endpoint_id, sizeof(endpoint_id));
+	}
+
+	return kernel_sendmsg(qrtr_ns.sock, &msg, &iv, 1, sizeof(*pkt));
+}
+
+static int service_announce_new(u32 endpoint_id, struct sockaddr_qrtr *dest,
+				struct qrtr_server *srv)
+{
+	struct qrtr_ctrl_pkt pkt;
 
 	trace_qrtr_ns_service_announce_new(srv->service, srv->instance,
 					   srv->node, srv->port);
 
-	iv.iov_base = &pkt;
-	iv.iov_len = sizeof(pkt);
-
 	memset(&pkt, 0, sizeof(pkt));
 	pkt.cmd = cpu_to_le32(QRTR_TYPE_NEW_SERVER);
 	pkt.server.service = cpu_to_le32(srv->service);
@@ -146,26 +231,18 @@ static int service_announce_new(struct sockaddr_qrtr *dest,
 	pkt.server.node = cpu_to_le32(srv->node);
 	pkt.server.port = cpu_to_le32(srv->port);
 
-	msg.msg_name = (struct sockaddr *)dest;
-	msg.msg_namelen = sizeof(*dest);
-
-	return kernel_sendmsg(qrtr_ns.sock, &msg, &iv, 1, sizeof(pkt));
+	return qrtr_ns_sendmsg(endpoint_id, dest, &pkt);
 }
 
-static void service_announce_del(struct sockaddr_qrtr *dest,
+static void service_announce_del(u32 endpoint_id, struct sockaddr_qrtr *dest,
 				 struct qrtr_server *srv)
 {
 	struct qrtr_ctrl_pkt pkt;
-	struct msghdr msg = { };
-	struct kvec iv;
 	int ret;
 
 	trace_qrtr_ns_service_announce_del(srv->service, srv->instance,
 					   srv->node, srv->port);
 
-	iv.iov_base = &pkt;
-	iv.iov_len = sizeof(pkt);
-
 	memset(&pkt, 0, sizeof(pkt));
 	pkt.cmd = cpu_to_le32(QRTR_TYPE_DEL_SERVER);
 	pkt.server.service = cpu_to_le32(srv->service);
@@ -173,26 +250,24 @@ static void service_announce_del(struct sockaddr_qrtr *dest,
 	pkt.server.node = cpu_to_le32(srv->node);
 	pkt.server.port = cpu_to_le32(srv->port);
 
-	msg.msg_name = (struct sockaddr *)dest;
-	msg.msg_namelen = sizeof(*dest);
-
-	ret = kernel_sendmsg(qrtr_ns.sock, &msg, &iv, 1, sizeof(pkt));
+	ret = qrtr_ns_sendmsg(endpoint_id, dest, &pkt);
 	if (ret < 0 && ret != -ENODEV)
 		pr_err("failed to announce del service\n");
 
 	return;
 }
 
-static void lookup_notify(struct sockaddr_qrtr *to, struct qrtr_server *srv,
-			  bool new)
+static void lookup_notify(u32 endpoint_id, struct sockaddr_qrtr *to,
+			  struct qrtr_server *srv, bool new)
 {
 	struct qrtr_ctrl_pkt pkt;
-	struct msghdr msg = { };
-	struct kvec iv;
 	int ret;
 
-	iv.iov_base = &pkt;
-	iv.iov_len = sizeof(pkt);
+	/*
+	 * Notify a local client at @to about a server change.  The aux data
+	 * will look as if it came from the endpoint that reported the event
+	 * (remote or local)
+	 */
 
 	memset(&pkt, 0, sizeof(pkt));
 	pkt.cmd = new ? cpu_to_le32(QRTR_TYPE_NEW_SERVER) :
@@ -204,28 +279,25 @@ static void lookup_notify(struct sockaddr_qrtr *to, struct qrtr_server *srv,
 		pkt.server.port = cpu_to_le32(srv->port);
 	}
 
-	msg.msg_name = (struct sockaddr *)to;
-	msg.msg_namelen = sizeof(*to);
-
-	ret = kernel_sendmsg(qrtr_ns.sock, &msg, &iv, 1, sizeof(pkt));
+	ret = qrtr_ns_sendmsg(endpoint_id, to, &pkt);
 	if (ret < 0 && ret != -ENODEV)
 		pr_err("failed to send lookup notification\n");
 }
 
-static int announce_servers(struct sockaddr_qrtr *sq)
+static int announce_servers(u32 endpoint_id, struct sockaddr_qrtr *sq)
 {
 	struct qrtr_server *srv;
 	struct qrtr_node *node;
 	unsigned long index;
 	int ret;
 
-	node = node_get(qrtr_ns.local_node);
+	node = node_lookup(qrtr_ns.local_node, qrtr_ns.local_node);
 	if (!node)
 		return 0;
 
-	/* Announce the list of servers registered in this node */
+	/* Announce servers registered on local endpoint to remote endpoint */
 	xa_for_each(&node->servers, index, srv) {
-		ret = service_announce_new(sq, srv);
+		ret = service_announce_new(endpoint_id, sq, srv);
 		if (ret < 0) {
 			if (ret == -ENODEV)
 				continue;
@@ -237,7 +309,8 @@ static int announce_servers(struct sockaddr_qrtr *sq)
 	return 0;
 }
 
-static struct qrtr_server *server_add(unsigned int service,
+static struct qrtr_server *server_add(u32 endpoint_id,
+				      unsigned int service,
 				      unsigned int instance,
 				      unsigned int node_id,
 				      unsigned int port)
@@ -249,7 +322,7 @@ static struct qrtr_server *server_add(unsigned int service,
 	if (!service || !port)
 		return NULL;
 
-	node = node_get(node_id);
+	node = node_get(endpoint_id, node_id);
 	if (!node)
 		return NULL;
 
@@ -293,7 +366,8 @@ static struct qrtr_server *server_add(unsigned int service,
 	return NULL;
 }
 
-static int server_del(struct qrtr_node *node, unsigned int port, bool bcast)
+static int server_del(u32 endpoint_id, struct qrtr_node *node,
+		      unsigned int port, bool bcast)
 {
 	struct qrtr_lookup *lookup;
 	struct qrtr_server *srv;
@@ -305,9 +379,10 @@ static int server_del(struct qrtr_node *node, unsigned int port, bool bcast)
 
 	xa_erase(&node->servers, port);
 
-	/* Broadcast the removal of local servers */
+	/* Broadcast the removal of local servers to remote endpoints */
 	if (srv->node == qrtr_ns.local_node && bcast)
-		service_announce_del(&qrtr_ns.bcast_sq, srv);
+		service_announce_del(qrtr_ns.local_node,
+				     &qrtr_ns.bcast_sq, srv);
 
 	/* Announce the service's disappearance to observers */
 	list_for_each(li, &qrtr_ns.lookups) {
@@ -317,7 +392,7 @@ static int server_del(struct qrtr_node *node, unsigned int port, bool bcast)
 		if (lookup->instance && lookup->instance != srv->instance)
 			continue;
 
-		lookup_notify(&lookup->sq, srv, false);
+		lookup_notify(endpoint_id, &lookup->sq, srv, false);
 	}
 
 	kfree(srv);
@@ -326,23 +401,15 @@ static int server_del(struct qrtr_node *node, unsigned int port, bool bcast)
 	return 0;
 }
 
-static int say_hello(struct sockaddr_qrtr *dest)
+static int say_hello(u32 endpoint_id, struct sockaddr_qrtr *dest)
 {
 	struct qrtr_ctrl_pkt pkt;
-	struct msghdr msg = { };
-	struct kvec iv;
 	int ret;
 
-	iv.iov_base = &pkt;
-	iv.iov_len = sizeof(pkt);
-
 	memset(&pkt, 0, sizeof(pkt));
 	pkt.cmd = cpu_to_le32(QRTR_TYPE_HELLO);
 
-	msg.msg_name = (struct sockaddr *)dest;
-	msg.msg_namelen = sizeof(*dest);
-
-	ret = kernel_sendmsg(qrtr_ns.sock, &msg, &iv, 1, sizeof(pkt));
+	ret = qrtr_ns_sendmsg(endpoint_id, dest, &pkt);
 	if (ret < 0)
 		pr_err("failed to send hello msg\n");
 
@@ -350,42 +417,38 @@ static int say_hello(struct sockaddr_qrtr *dest)
 }
 
 /* Announce the list of servers registered on the local node */
-static int ctrl_cmd_hello(struct sockaddr_qrtr *sq)
+static int ctrl_cmd_hello(u32 endpoint_id, struct sockaddr_qrtr *sq)
 {
 	int ret;
 
-	ret = say_hello(sq);
+	/* Send Hello and New Server messages to remote endpoint */
+	ret = say_hello(endpoint_id, sq);
 	if (ret < 0)
 		return ret;
 
-	return announce_servers(sq);
+	return announce_servers(endpoint_id, sq);
 }
 
-static int ctrl_cmd_bye(struct sockaddr_qrtr *from)
+static int ctrl_cmd_bye(u32 endpoint_id, struct sockaddr_qrtr *from)
 {
 	struct qrtr_node *local_node;
 	struct qrtr_ctrl_pkt pkt;
 	struct qrtr_server *srv;
 	struct sockaddr_qrtr sq;
-	struct msghdr msg = { };
 	struct qrtr_node *node;
 	unsigned long index;
-	struct kvec iv;
 	int ret = 0;
 
-	iv.iov_base = &pkt;
-	iv.iov_len = sizeof(pkt);
-
-	node = node_get(from->sq_node);
+	node = node_get(endpoint_id, from->sq_node);
 	if (!node)
 		return 0;
 
 	/* Advertise removal of this client to all servers of remote node */
 	xa_for_each(&node->servers, index, srv)
-		server_del(node, srv->port, true);
+		server_del(endpoint_id, node, srv->port, true);
 
 	/* Advertise the removal of this client to all local servers */
-	local_node = node_get(qrtr_ns.local_node);
+	local_node = node_get(qrtr_ns.local_node, qrtr_ns.local_node);
 	if (!local_node) {
 		ret = 0;
 		goto delete_node;
@@ -400,10 +463,8 @@ static int ctrl_cmd_bye(struct sockaddr_qrtr *from)
 		sq.sq_node = srv->node;
 		sq.sq_port = srv->port;
 
-		msg.msg_name = (struct sockaddr *)&sq;
-		msg.msg_namelen = sizeof(sq);
-
-		ret = kernel_sendmsg(qrtr_ns.sock, &msg, &iv, 1, sizeof(pkt));
+		/* Bye will look as if it came from endpoint_id */
+		ret = qrtr_ns_sendmsg(endpoint_id, &sq, &pkt);
 		if (ret < 0 && ret != -ENODEV) {
 			pr_err("failed to send bye cmd\n");
 			goto delete_node;
@@ -414,32 +475,25 @@ static int ctrl_cmd_bye(struct sockaddr_qrtr *from)
 	ret = 0;
 
 delete_node:
-	xa_erase(&nodes, from->sq_node);
-	kfree(node);
-	node_count--;
+	node_erase(endpoint_id, from->sq_node);
 
 	return ret;
 }
 
-static int ctrl_cmd_del_client(struct sockaddr_qrtr *from,
+static int ctrl_cmd_del_client(u32 endpoint_id, struct sockaddr_qrtr *from,
 			       unsigned int node_id, unsigned int port)
 {
 	struct qrtr_node *local_node;
 	struct qrtr_lookup *lookup;
 	struct qrtr_ctrl_pkt pkt;
-	struct msghdr msg = { };
 	struct qrtr_server *srv;
 	struct sockaddr_qrtr sq;
 	struct qrtr_node *node;
 	struct list_head *tmp;
 	struct list_head *li;
 	unsigned long index;
-	struct kvec iv;
 	int ret;
 
-	iv.iov_base = &pkt;
-	iv.iov_len = sizeof(pkt);
-
 	/* Don't accept spoofed messages */
 	if (from->sq_node != node_id)
 		return -EINVAL;
@@ -465,12 +519,12 @@ static int ctrl_cmd_del_client(struct sockaddr_qrtr *from,
 	 * DEL_SERVER. Neighbours would've already removed the server belonging
 	 * to this port due to the DEL_CLIENT broadcast from qrtr_port_remove().
 	 */
-	node = node_get(node_id);
+	node = node_lookup(endpoint_id, node_id);
 	if (node)
-		server_del(node, port, false);
+		server_del(endpoint_id, node, port, false);
 
 	/* Advertise the removal of this client to all local servers */
-	local_node = node_get(qrtr_ns.local_node);
+	local_node = node_lookup(qrtr_ns.local_node, qrtr_ns.local_node);
 	if (!local_node)
 		return 0;
 
@@ -484,10 +538,8 @@ static int ctrl_cmd_del_client(struct sockaddr_qrtr *from,
 		sq.sq_node = srv->node;
 		sq.sq_port = srv->port;
 
-		msg.msg_name = (struct sockaddr *)&sq;
-		msg.msg_namelen = sizeof(sq);
-
-		ret = kernel_sendmsg(qrtr_ns.sock, &msg, &iv, 1, sizeof(pkt));
+		/* Del Client will look as if it came from endpoint_id */
+		ret = qrtr_ns_sendmsg(endpoint_id, &sq, &pkt);
 		if (ret < 0 && ret != -ENODEV) {
 			pr_err("failed to send del client cmd\n");
 			return ret;
@@ -496,7 +548,7 @@ static int ctrl_cmd_del_client(struct sockaddr_qrtr *from,
 	return 0;
 }
 
-static int ctrl_cmd_new_server(struct sockaddr_qrtr *from,
+static int ctrl_cmd_new_server(u32 endpoint_id, struct sockaddr_qrtr *from,
 			       unsigned int service, unsigned int instance,
 			       unsigned int node_id, unsigned int port)
 {
@@ -511,12 +563,16 @@ static int ctrl_cmd_new_server(struct sockaddr_qrtr *from,
 		port = from->sq_port;
 	}
 
-	srv = server_add(service, instance, node_id, port);
-	if (!srv)
+	srv = server_add(endpoint_id, service, instance, node_id, port);
+	if (!srv) {
+		pr_err("Failed to add server\n");
 		return -EINVAL;
+	}
 
 	if (srv->node == qrtr_ns.local_node) {
-		ret = service_announce_new(&qrtr_ns.bcast_sq, srv);
+		/* Broadcast local server info to all peer endpoints */
+		ret = service_announce_new(qrtr_ns.local_node,
+					   &qrtr_ns.bcast_sq, srv);
 		if (ret < 0) {
 			pr_err("failed to announce new service\n");
 			return ret;
@@ -531,13 +587,13 @@ static int ctrl_cmd_new_server(struct sockaddr_qrtr *from,
 		if (lookup->instance && lookup->instance != instance)
 			continue;
 
-		lookup_notify(&lookup->sq, srv, true);
+		lookup_notify(endpoint_id, &lookup->sq, srv, true);
 	}
 
 	return ret;
 }
 
-static int ctrl_cmd_del_server(struct sockaddr_qrtr *from,
+static int ctrl_cmd_del_server(u32 endpoint_id, struct sockaddr_qrtr *from,
 			       unsigned int service, unsigned int instance,
 			       unsigned int node_id, unsigned int port)
 {
@@ -553,24 +609,22 @@ static int ctrl_cmd_del_server(struct sockaddr_qrtr *from,
 	if (from->sq_node == qrtr_ns.local_node && from->sq_port != port)
 		return -EINVAL;
 
-	node = node_get(node_id);
+	node = node_lookup(endpoint_id, node_id);
 	if (!node)
 		return -ENOENT;
 
-	server_del(node, port, true);
+	server_del(endpoint_id, node, port, true);
 
 	return 0;
 }
 
-static int ctrl_cmd_new_lookup(struct sockaddr_qrtr *from,
+static int ctrl_cmd_new_lookup(u32 endpoint_id, struct sockaddr_qrtr *from,
 			       unsigned int service, unsigned int instance)
 {
 	struct qrtr_server_filter filter;
 	struct qrtr_lookup *lookup;
-	struct qrtr_server *srv;
-	struct qrtr_node *node;
-	unsigned long node_idx;
-	unsigned long srv_idx;
+	unsigned long id;
+	struct qrtr_ns_endpoint *endpoint;
 
 	/* Accept only local observers */
 	if (from->sq_node != qrtr_ns.local_node)
@@ -595,22 +649,30 @@ static int ctrl_cmd_new_lookup(struct sockaddr_qrtr *from,
 	filter.service = service;
 	filter.instance = instance;
 
-	xa_for_each(&nodes, node_idx, node) {
-		xa_for_each(&node->servers, srv_idx, srv) {
-			if (!server_match(srv, &filter))
-				continue;
+	xa_for_each(&endpoints, id, endpoint) {
+		struct qrtr_node *node;
+		unsigned long node_idx;
 
-			lookup_notify(from, srv, true);
+		xa_for_each(&endpoint->nodes, node_idx, node) {
+			unsigned long srv_idx;
+			struct qrtr_server *srv;
+
+			xa_for_each(&node->servers, srv_idx, srv) {
+				if (!server_match(srv, &filter))
+					continue;
+
+				lookup_notify(id, from, srv, true);
+			}
 		}
 	}
 
 	/* Empty notification, to indicate end of listing */
-	lookup_notify(from, NULL, true);
+	lookup_notify(0, from, NULL, true);
 
 	return 0;
 }
 
-static void ctrl_cmd_del_lookup(struct sockaddr_qrtr *from,
+static void ctrl_cmd_del_lookup(u32 endpoint_id, struct sockaddr_qrtr *from,
 				unsigned int service, unsigned int instance)
 {
 	struct qrtr_lookup *lookup;
@@ -644,6 +706,7 @@ static void qrtr_ns_worker(struct work_struct *work)
 	ssize_t msglen;
 	void *recv_buf;
 	struct kvec iv;
+	u8 control[32];
 	int ret;
 
 	msg.msg_name = (struct sockaddr *)&sq;
@@ -654,8 +717,12 @@ static void qrtr_ns_worker(struct work_struct *work)
 		return;
 
 	for (;;) {
+		u32 endpoint_id;
+
 		iv.iov_base = recv_buf;
 		iv.iov_len = recv_buf_size;
+		msg.msg_control = control;
+		msg.msg_controllen = sizeof(control);
 
 		msglen = kernel_recvmsg(qrtr_ns.sock, &msg, &iv, 1,
 					iv.iov_len, MSG_DONTWAIT);
@@ -668,6 +735,19 @@ static void qrtr_ns_worker(struct work_struct *work)
 			break;
 		}
 
+		/* AUX data is written direct into the control buffer */
+		msg.msg_control = control;
+		msg.msg_controllen = sizeof(control) - msg.msg_controllen;
+
+		ret = qrtr_msg_get_endpoint(&msg, &endpoint_id);
+		if (ret < 0) {
+			pr_err("error receiving endpoint id: %d\n", ret);
+			break;
+		}
+
+		if ((size_t)msglen < sizeof(*pkt))
+			break;
+
 		pkt = recv_buf;
 		cmd = le32_to_cpu(pkt->cmd);
 		if (cmd < ARRAY_SIZE(qrtr_ctrl_pkt_strings) &&
@@ -678,25 +758,25 @@ static void qrtr_ns_worker(struct work_struct *work)
 		ret = 0;
 		switch (cmd) {
 		case QRTR_TYPE_HELLO:
-			ret = ctrl_cmd_hello(&sq);
+			ret = ctrl_cmd_hello(endpoint_id, &sq);
 			break;
 		case QRTR_TYPE_BYE:
-			ret = ctrl_cmd_bye(&sq);
+			ret = ctrl_cmd_bye(endpoint_id, &sq);
 			break;
 		case QRTR_TYPE_DEL_CLIENT:
-			ret = ctrl_cmd_del_client(&sq,
+			ret = ctrl_cmd_del_client(endpoint_id, &sq,
 					le32_to_cpu(pkt->client.node),
 					le32_to_cpu(pkt->client.port));
 			break;
 		case QRTR_TYPE_NEW_SERVER:
-			ret = ctrl_cmd_new_server(&sq,
+			ret = ctrl_cmd_new_server(endpoint_id, &sq,
 					le32_to_cpu(pkt->server.service),
 					le32_to_cpu(pkt->server.instance),
 					le32_to_cpu(pkt->server.node),
 					le32_to_cpu(pkt->server.port));
 			break;
 		case QRTR_TYPE_DEL_SERVER:
-			ret = ctrl_cmd_del_server(&sq,
+			ret = ctrl_cmd_del_server(endpoint_id, &sq,
 					 le32_to_cpu(pkt->server.service),
 					 le32_to_cpu(pkt->server.instance),
 					 le32_to_cpu(pkt->server.node),
@@ -707,12 +787,12 @@ static void qrtr_ns_worker(struct work_struct *work)
 		case QRTR_TYPE_RESUME_TX:
 			break;
 		case QRTR_TYPE_NEW_LOOKUP:
-			ret = ctrl_cmd_new_lookup(&sq,
+			ret = ctrl_cmd_new_lookup(endpoint_id, &sq,
 					 le32_to_cpu(pkt->server.service),
 					 le32_to_cpu(pkt->server.instance));
 			break;
 		case QRTR_TYPE_DEL_LOOKUP:
-			ctrl_cmd_del_lookup(&sq,
+			ctrl_cmd_del_lookup(endpoint_id, &sq,
 				    le32_to_cpu(pkt->server.service),
 				    le32_to_cpu(pkt->server.instance));
 			break;
@@ -746,6 +826,8 @@ int qrtr_ns_init(void)
 	if (ret < 0)
 		return ret;
 
+	qrtr_sock_set_report_endpoint(qrtr_ns.sock->sk);
+
 	ret = kernel_getsockname(qrtr_ns.sock, (struct sockaddr *)&sq);
 	if (ret < 0) {
 		pr_err("failed to get socket name\n");
@@ -774,7 +856,7 @@ int qrtr_ns_init(void)
 	qrtr_ns.bcast_sq.sq_node = QRTR_NODE_BCAST;
 	qrtr_ns.bcast_sq.sq_port = QRTR_PORT_CTRL;
 
-	ret = say_hello(&qrtr_ns.bcast_sq);
+	ret = say_hello(qrtr_ns.local_node, &qrtr_ns.bcast_sq);
 	if (ret < 0)
 		goto err_wq;
 
diff --git a/net/qrtr/qrtr.h b/net/qrtr/qrtr.h
index 3f2d28696062a..affc24f426c64 100644
--- a/net/qrtr/qrtr.h
+++ b/net/qrtr/qrtr.h
@@ -9,6 +9,15 @@ struct sk_buff;
 /* endpoint node id auto assignment */
 #define QRTR_EP_NID_AUTO (-1)
 
+/**
+ * struct qrtr_node_lookup_helper - node lookup helper, stored in qrtr_nodes
+ * @nodes: nodes, indexed by node_id
+ */
+struct qrtr_node_lookup_helper {
+	int added;
+	struct radix_tree_root nodes;
+};
+
 /**
  * struct qrtr_endpoint - endpoint handle
  * @xmit: Callback for outgoing packets
@@ -21,6 +30,8 @@ struct qrtr_endpoint {
 	int (*xmit)(struct qrtr_endpoint *ep, struct sk_buff *skb);
 	/* private: not for endpoint use */
 	struct qrtr_node *node;
+	struct qrtr_node_lookup_helper helper;
+	u32 id;
 };
 
 int qrtr_endpoint_register(struct qrtr_endpoint *ep, unsigned int nid);
@@ -33,4 +44,7 @@ int qrtr_ns_init(void);
 
 void qrtr_ns_remove(void);
 
+int qrtr_msg_get_endpoint(struct msghdr *msg, u32 *out_endpoint_id);
+void qrtr_sock_set_report_endpoint(struct sock *sk);
+
 #endif

19/3 2026/09/15 06:24 llm kmsan-evaluator
0m Model:
gemini-3.8-flash

Args:
null

Results:
null

Tokens:
							input: 22153
							output: 34
							thoughts: 754
						

Thoughts:
**KMSAN Fuzzing Assessment for QRTR Endpoint Support**

Okay, let's dive into this patch series. The task is to determine if adding endpoint support to QRTR necessitates a dedicated KMSAN fuzzing session. I need to figure out if there are any obvious uninitialized memory risks or potential information leaks introduced by this change.

First, I see the core of the patch: it's adding endpoint support to Qualcomm IPC Router (QRTR). This involves some header additions (defining `SOL_QRTR` and related constants), and more importantly, changes within the `net/qrtr/af_qrtr.c` file. This is where the work happens. It includes implementing `setsockopt` and `getsockopt` for the new `SOL_QRTR` options, handling control message (cmsg) parsing and sending related to the new endpoints, using radix trees for endpoint management, and adding functions like `qrtr_msg_get_endpoint`. There are also changes within `mhi.c` for sysfs interactions and updates to `ns.c`.

Let's start by examining potential risks. My immediate focus is on any code paths that might lead to reading uninitialized memory, padding leaks, or other info leaks.

I'm starting with `qrtr_getsockopt`. I see that `val` is an `unsigned int`, which is a good starting point to look at how we might get an uninitialized value.

In `qrtr_getsockopt`, for `QRTR_REPORT_ENDPOINT`, `val` is set via `test_bit`, which should be fine. For `QRTR_BIND_ENDPOINT`, the value is set with `READ_ONCE(ipc->bound_endpoint)`. This means `ipc->bound_endpoint` has to be initialized. Okay, where is that done? I'll need to figure out where `struct qrtr_sock` is allocated in the QRTR subsystem to see where that member is initialized. I need to trace back from `qrtr_getsockopt` to the socket creation code and see how `struct qrtr_sock` is allocated and initialized to ensure there isn't a race condition, or a case where this `bound_endpoint` isn't initialized. I'll search for socket allocation functions, likely using `sk_alloc` or similar, to locate the `qrtr_sock` allocation.



20/3 2026/09/15 06:24 tool grepper
0m Args:
{
  "Expression": "sk_alloc.*AF_QIPCRTR",
  "PathPrefix": "net/qrtr"
}

Results:
{
  "Output": "net/qrtr/af_qrtr.c=1570=static int qrtr_create(struct net *net, struct socket *sock,\n--\nnet/qrtr/af_qrtr.c-1586-\nnet/qrtr/af_qrtr.c:1587:\tsk = sk_alloc(net, AF_QIPCRTR, GFP_KERNEL, \u0026qrtr_proto, kern);\nnet/qrtr/af_qrtr.c-1588-\tif (!sk)\n"
}

21/3 2026/09/15 06:24 llm kmsan-evaluator
0m Model:
gemini-3.8-flash

Args:
null

Results:
null

Tokens:
							input: 23584
							output: 27
							thoughts: 33
						

Thoughts:
**Checking Socket Allocation in QRTR Protocol**

Okay, so I'm looking at how sockets are being allocated. The `sk_alloc` function is apparently responsible for zeroing out the allocated socket object (`sk_prot->obj_size`). Right, that makes sense – clean memory is crucial. Now, I need to verify what that `obj_size` actually is within the context of the QRTR protocol. Let me go check what `qrtr_proto.obj_size` is defined as. I need to be sure the memory being zeroed is the expected size and includes all necessary fields for this specific protocol. Need to verify that it's sized correctly for the QRTR implementation.



22/3 2026/09/15 06:24 tool grepper
0m Args:
{
  "Expression": "obj_size",
  "PathPrefix": "net/qrtr"
}

Results:
{
  "Output": "net/qrtr/af_qrtr.c=1564=static struct proto qrtr_proto = {\n--\nnet/qrtr/af_qrtr.c-1566-\t.owner\t\t= THIS_MODULE,\nnet/qrtr/af_qrtr.c:1567:\t.obj_size\t= sizeof(struct qrtr_sock),\nnet/qrtr/af_qrtr.c-1568-};\n"
}

23/3 2026/09/15 06:24 llm kmsan-evaluator
0m Model:
gemini-3.8-flash

Args:
null

Results:
null

Tokens:
							input: 23909
							output: 28
							thoughts: 367
						

Thoughts:
**Decoding the QRTR Receive Path**

Okay, so the `qrtr_sock` struct is zero-allocated, meaning it's likely initialized in-place, which is helpful to keep in mind. Now, let's dive into `qrtr_recvmsg`. I see this new check being added, specifically the addition of a `SOL_QRTR` control message, reporting the `cb->endpoint_id`, but only if the `QRTR_F_REPORT_ENDPOINT` flag is set in the `ipc->flags`. Makes sense. This lets the receiver know the originating endpoint ID, which could be important for routing or demultiplexing.

But hold on a second... where *does* `cb->endpoint_id` get populated? This is crucial. Let me check the definition of `struct qrtr_cb` itself. Ah, there it is: `endpoint_id` is a member alongside source and destination information. Okay, good. But I need to trace *where* this `qrtr_cb` struct is actually populated on incoming packet paths. So, that means I need to hunt for where `skb->cb` is set because that's what's getting copied into `cb`. Let's grep for `qrtr_cb` or `skb->cb` in the `net/qrtr/` directory. That should show me all the places where this important context is set for arriving packets. Let's see...



24/3 2026/09/15 06:24 tool grepper
0m Args:
{
  "Expression": "skb-\u003ecb",
  "PathPrefix": "net/qrtr"
}

Results:
{
  "Output": "net/qrtr/af_qrtr.c=582=int qrtr_endpoint_post(struct qrtr_endpoint *ep, const void *data, size_t len)\n--\nnet/qrtr/af_qrtr.c-601-\nnet/qrtr/af_qrtr.c:602:\tcb = (struct qrtr_cb *)skb-\u003ecb;\nnet/qrtr/af_qrtr.c-603-\n--\nnet/qrtr/af_qrtr.c=1052=static int qrtr_local_enqueue(struct qrtr_node *node, struct sk_buff *skb,\n--\nnet/qrtr/af_qrtr.c-1076-\nnet/qrtr/af_qrtr.c:1077:\tcb = (struct qrtr_cb *)skb-\u003ecb;\nnet/qrtr/af_qrtr.c-1078-\tcb-\u003esrc_node = from-\u003esq_node;\n--\nnet/qrtr/af_qrtr.c=1266=static int qrtr_recvmsg(struct socket *sock, struct msghdr *msg,\n--\nnet/qrtr/af_qrtr.c-1287-\t}\nnet/qrtr/af_qrtr.c:1288:\tcb = (struct qrtr_cb *)skb-\u003ecb;\nnet/qrtr/af_qrtr.c-1289-\n"
}

25/3 2026/09/15 06:24 llm kmsan-evaluator
0m Model:
gemini-3.8-flash

Args:
null

Results:
null

Tokens:
							input: 24978
							output: 33
							thoughts: 51
						

Thoughts:
Okay, let's dive into this. Here's how I'd approach that problem, as though it were my own thought process.

**Diving into `sock_queue_rcv_skb` Calls**

Alright, the objective here is to understand the places where `sock_queue_rcv_skb(&ipc->sk, skb)` is being invoked, which implies a desire to examine the network-related queuing and handling of socket buffers, particularly related to the `ipc->sk` socket. My initial thought is a straightforward, direct approach. To begin, I'll use `grep` to quickly identify all instances of `sock_queue_rcv_skb` within the `net/qrtr` directory. This is likely a good place to start since the context given suggests some interaction with a QRTR network interface. This search should provide a list of all call sites within that particular network sub-system. Then, depending on how many hits I get, I would decide on the next step: either look at each call site individually, or apply more advanced search terms.



26/3 2026/09/15 06:24 tool grepper
0m Args:
{
  "Expression": "sock_queue_rcv_skb",
  "PathPrefix": "net/qrtr"
}

Results:
{
  "Output": "net/qrtr/af_qrtr.c=582=int qrtr_endpoint_post(struct qrtr_endpoint *ep, const void *data, size_t len)\n--\nnet/qrtr/af_qrtr.c-699-\t\t    ipc-\u003ebound_endpoint == cb-\u003eendpoint_id) {\nnet/qrtr/af_qrtr.c:700:\t\t\tret = sock_queue_rcv_skb(\u0026ipc-\u003esk, skb);\nnet/qrtr/af_qrtr.c-701-\t\t\tif (ret) {\n--\nnet/qrtr/af_qrtr.c=1052=static int qrtr_local_enqueue(struct qrtr_node *node, struct sk_buff *skb,\n--\nnet/qrtr/af_qrtr.c-1082-\tret = -ENOSPC;\nnet/qrtr/af_qrtr.c:1083:\tif (sock_queue_rcv_skb(\u0026ipc-\u003esk, skb))\nnet/qrtr/af_qrtr.c-1084-\t\tgoto done;\n"
}

27/3 2026/09/15 06:24 llm kmsan-evaluator
0m Model:
gemini-3.8-flash

Args:
null

Results:
null

Tokens:
							input: 25574
							output: 39
							thoughts: 47
						

Thoughts:
Okay, here's my interpretation of that thought process, assuming I'm already quite familiar with networking and kernel internals:

**Analyzing the Socket Receive Queue in the QRTR Subsystem**

Alright, I'm focusing on the receive queue within the QRTR subsystem, specifically related to sockets. My immediate thought is, "Where exactly does data get placed into that socket receive queue?" I know the importance of this, especially for understanding performance and potential bottlenecks.

The initial hunch, and it's a critical one, is that *only* two locations are responsible for writing data to the socket's receive queue. That narrows the scope considerably. This is a very important fact as it limits the number of places to look for issues.

I now need to pinpoint precisely how data ends up there. My line of thinking leads me directly to `qrtr_endpoint_post`. That's the function I need to understand. I'm going to delve into `qrtr_endpoint_post`, specifically focusing on the code around lines 600-660. My aim is to meticulously examine this section and trace the data flow to see exactly how and when data is placed onto the receive queue. I know from experience that understanding the post function is key to understand how the system works.



28/3 2026/09/15 06:25 tool read-file
0m Args:
{
  "File": "net/qrtr/af_qrtr.c",
  "FirstLine": 585,
  "LineCount": 80
}

Results:
{
  "Contents": " 585:\t\tconst struct qrtr_hdr_v1 *v1;\n 586:\t\tconst struct qrtr_hdr_v2 *v2;\n 587:\t\tstruct qrtr_sock *ipc;\n 588:\t\tstruct sk_buff *skb;\n 589:\t\tstruct qrtr_cb *cb;\n 590:\t\tsize_t size;\n 591:\t\tunsigned int ver;\n 592:\t\tsize_t hdrlen;\n 593:\t\tint ret = -EINVAL;\n 594:\t\n 595:\t\tif (len == 0 || len \u0026 3)\n 596:\t\t\treturn -EINVAL;\n 597:\t\n 598:\t\tskb = __netdev_alloc_skb(NULL, len, GFP_ATOMIC | __GFP_NOWARN);\n 599:\t\tif (!skb)\n 600:\t\t\treturn -ENOMEM;\n 601:\t\n 602:\t\tcb = (struct qrtr_cb *)skb-\u003ecb;\n 603:\t\n 604:\t\t/* Version field in v1 is little endian, so this works for both cases */\n 605:\t\tver = *(u8*)data;\n 606:\t\n 607:\t\tswitch (ver) {\n 608:\t\tcase QRTR_PROTO_VER_1:\n 609:\t\t\tif (len \u003c sizeof(*v1))\n 610:\t\t\t\tgoto err;\n 611:\t\t\tv1 = data;\n 612:\t\t\thdrlen = sizeof(*v1);\n 613:\t\n 614:\t\t\tcb-\u003etype = le32_to_cpu(v1-\u003etype);\n 615:\t\t\tcb-\u003esrc_node = le32_to_cpu(v1-\u003esrc_node_id);\n 616:\t\t\tcb-\u003esrc_port = le32_to_cpu(v1-\u003esrc_port_id);\n 617:\t\t\tcb-\u003econfirm_rx = !!le32_to_cpu(v1-\u003econfirm_rx);\n 618:\t\t\tcb-\u003edst_node = le32_to_cpu(v1-\u003edst_node_id);\n 619:\t\t\tcb-\u003edst_port = le32_to_cpu(v1-\u003edst_port_id);\n 620:\t\n 621:\t\t\tsize = le32_to_cpu(v1-\u003esize);\n 622:\t\t\tbreak;\n 623:\t\tcase QRTR_PROTO_VER_2:\n 624:\t\t\tif (len \u003c sizeof(*v2))\n 625:\t\t\t\tgoto err;\n 626:\t\t\tv2 = data;\n 627:\t\t\thdrlen = sizeof(*v2) + v2-\u003eoptlen;\n 628:\t\n 629:\t\t\tcb-\u003etype = v2-\u003etype;\n 630:\t\t\tcb-\u003econfirm_rx = !!(v2-\u003eflags \u0026 QRTR_FLAGS_CONFIRM_RX);\n 631:\t\t\tcb-\u003esrc_node = le16_to_cpu(v2-\u003esrc_node_id);\n 632:\t\t\tcb-\u003esrc_port = le16_to_cpu(v2-\u003esrc_port_id);\n 633:\t\t\tcb-\u003edst_node = le16_to_cpu(v2-\u003edst_node_id);\n 634:\t\t\tcb-\u003edst_port = le16_to_cpu(v2-\u003edst_port_id);\n 635:\t\n 636:\t\t\tif (cb-\u003esrc_port == (u16)QRTR_PORT_CTRL)\n 637:\t\t\t\tcb-\u003esrc_port = QRTR_PORT_CTRL;\n 638:\t\t\tif (cb-\u003edst_port == (u16)QRTR_PORT_CTRL)\n 639:\t\t\t\tcb-\u003edst_port = QRTR_PORT_CTRL;\n 640:\t\n 641:\t\t\tsize = le32_to_cpu(v2-\u003esize);\n 642:\t\t\tbreak;\n 643:\t\tdefault:\n 644:\t\t\tpr_err(\"qrtr: Invalid version %d\\n\", ver);\n 645:\t\t\tgoto err;\n 646:\t\t}\n 647:\t\n 648:\t\tif (cb-\u003edst_port == QRTR_PORT_CTRL_LEGACY)\n 649:\t\t\tcb-\u003edst_port = QRTR_PORT_CTRL;\n 650:\t\n 651:\t\tcb-\u003eendpoint_id = ep-\u003eid;\n 652:\t\n 653:\t\tif (!size || size \u003e len || len != ALIGN(size, 4) + hdrlen)\n 654:\t\t\tgoto err;\n 655:\t\n 656:\t\t/* Don't allow remote lookups */\n 657:\t\tif (cb-\u003etype == QRTR_TYPE_NEW_LOOKUP ||\n 658:\t\t    cb-\u003etype == QRTR_TYPE_DEL_LOOKUP)\n 659:\t\t\tgoto err;\n 660:\t\n 661:\t\tif ((cb-\u003etype == QRTR_TYPE_NEW_SERVER ||\n 662:\t\t     cb-\u003etype == QRTR_TYPE_RESUME_TX) \u0026\u0026\n 663:\t\t    size \u003c sizeof(struct qrtr_ctrl_pkt))\n 664:\t\t\tgoto err;\n"
}

29/3 2026/09/15 06:25 llm kmsan-evaluator
0m Model:
gemini-3.8-flash

Args:
null

Results:
null

Tokens:
							input: 27281
							output: 27
							thoughts: 1309
						

Thoughts:
**Analyzing QRTR Endpoint ID Handling**

Okay, let's break this down. First, I see `cb->endpoint_id = ep->id;` being set.  Then, in `qrtr_local_enqueue`, it's also set within the callback structure. So far, so good, this seems to be the expected behavior.

But now, I'm thinking about `qrtr_sendmsg` and `qrtr_msg_get_endpoint`. That's where things can get interesting.  Let's dig into `qrtr_sendmsg`.  Ah, there it is: `qrtr_msg_get_endpoint(msg, &msg_endpoint_id);`.  The key here is how this function handles the message control header.  

My immediate concern is what happens if the message doesn't *have* any control messages (cmsgs).  If `msg->msg_controllen` is zero, the `for_each_cmsghdr` loop won't iterate.  Then, inside `qrtr_msg_get_endpoint`, `endpoint_id` remains at its initialized value of `0` because it is initialized to 0. It is set here `u32 endpoint_id = 0;`. Okay, and then, that value is written to `*out_endpoint_id` which is `msg_endpoint_id`, So `msg_endpoint_id` ends up being initialized to `0`.  That covers the no cmsg case.  Now, what if `out_endpoint_id` is NULL? The `if (out_endpoint_id)` check handles this!  

Now, what about cmsgs where the level isn't `SOL_QRTR`? The code `if (cmsg->cmsg_level != SOL_QRTR) continue;` is there, so that cmsg type is skipped and moves on. This means, the endpoint is zero when there are no valid `SOL_QRTR` headers.  Finally, and importantly, the code handles malformed messages as well. If `!CMSG_OK`, a negative error code is returned immediately, so `msg_endpoint_id` isn't touched, and `qrtr_sendmsg` returns.

I need to confirm the use case in `qrtr_ns_worker` too. Let me see... in `net/qrtr/ns.c`, there's `qrtr_ns_worker`. Okay, within the loop, the `kernel_recvmsg` and then `qrtr_msg_get_endpoint` are used together!  

Now I'm focusing on that `msg.msg_controllen` field. How does `kernel_recvmsg` *modify* this? It sets it! Let's check `qrtr_recvmsg`. Oh, I see. Okay, this section has been completed.
`put_cmsg` is the next function to be checked in the kernel. Let's see how `put_cmsg` works with cmsg!



30/3 2026/09/15 06:25 tool grepper
0m Args:
{
  "Expression": "int put_cmsg",
  "PathPrefix": "net/"
}

Results:
{
  "Output": "net/compat.c=138=int cmsghdr_from_user_compat_to_kern(struct msghdr *kmsg, struct sock *sk,\n--\nnet/compat.c-225-\nnet/compat.c:226:int put_cmsg_compat(struct msghdr *kmsg, int level, int type, int len, void *data)\nnet/compat.c-227-{\n--\nnet/core/scm.c=253=EXPORT_SYMBOL(__scm_send);\nnet/core/scm.c-254-\nnet/core/scm.c:255:int put_cmsg(struct msghdr * msg, int level, int type, int len, void *data)\nnet/core/scm.c-256-{\n--\nnet/core/scm.c=303=EXPORT_SYMBOL(put_cmsg);\nnet/core/scm.c-304-\nnet/core/scm.c:305:int put_cmsg_notrunc(struct msghdr *msg, int level, int type, int len,\nnet/core/scm.c-306-\t\t     void *data)\n"
}

31/3 2026/09/15 06:25 llm kmsan-evaluator
0m Model:
gemini-3.8-flash

Args:
null

Results:
null

Tokens:
							input: 29563
							output: 35
							thoughts: 20
						

Thoughts:
Here's a summary of my thought process, as requested:

**Diving into `put_cmsg`**

Okay, so I need to understand how control messages are being handled in the networking stack. My initial thought is to dive right into the core implementation. Let's see... the most likely place to start is `net/core/scm.c`, and specifically the `put_cmsg` function. I'm guessing this function is responsible for actually placing the control message in the buffer, presumably after all the necessary checks and setup. I want to see how it interacts with the underlying data structures, how it handles potential errors, and most importantly, understand the logic for laying out the data. I'm interested in how it manages the various control message types and their specific data formats, and how this relates to the overall Socket Control Message (SCM) design. This will be a good starting point for tracing the control message path.



32/3 2026/09/15 06:25 tool read-file
0m Args:
{
  "File": "net/core/scm.c",
  "FirstLine": 250,
  "LineCount": 40
}

Results:
{
  "Contents": " 250:\t\tscm_destroy(p);\n 251:\t\treturn err;\n 252:\t}\n 253:\tEXPORT_SYMBOL(__scm_send);\n 254:\t\n 255:\tint put_cmsg(struct msghdr * msg, int level, int type, int len, void *data)\n 256:\t{\n 257:\t\tint cmlen = CMSG_LEN(len);\n 258:\t\n 259:\t\tif (msg-\u003emsg_flags \u0026 MSG_CMSG_COMPAT)\n 260:\t\t\treturn put_cmsg_compat(msg, level, type, len, data);\n 261:\t\n 262:\t\tif (!msg-\u003emsg_control || msg-\u003emsg_controllen \u003c sizeof(struct cmsghdr)) {\n 263:\t\t\tmsg-\u003emsg_flags |= MSG_CTRUNC;\n 264:\t\t\treturn 0; /* XXX: return error? check spec. */\n 265:\t\t}\n 266:\t\tif (msg-\u003emsg_controllen \u003c cmlen) {\n 267:\t\t\tmsg-\u003emsg_flags |= MSG_CTRUNC;\n 268:\t\t\tcmlen = msg-\u003emsg_controllen;\n 269:\t\t}\n 270:\t\n 271:\t\tif (msg-\u003emsg_control_is_user) {\n 272:\t\t\tstruct cmsghdr __user *cm = msg-\u003emsg_control_user;\n 273:\t\n 274:\t\t\tcheck_object_size(data, cmlen - sizeof(*cm), true);\n 275:\t\n 276:\t\t\tscoped_user_write_access_size(cm, cmlen, efault) {\n 277:\t\t\t\tunsafe_put_user(cmlen, \u0026cm-\u003ecmsg_len, efault);\n 278:\t\t\t\tunsafe_put_user(level, \u0026cm-\u003ecmsg_level, efault);\n 279:\t\t\t\tunsafe_put_user(type, \u0026cm-\u003ecmsg_type, efault);\n 280:\t\t\t\tunsafe_copy_to_user(CMSG_USER_DATA(cm), data,\n 281:\t\t\t\t\t\t    cmlen - sizeof(*cm), efault);\n 282:\t\t\t}\n 283:\t\t} else {\n 284:\t\t\tstruct cmsghdr *cm = msg-\u003emsg_control;\n 285:\t\n 286:\t\t\tcm-\u003ecmsg_level = level;\n 287:\t\t\tcm-\u003ecmsg_type = type;\n 288:\t\t\tcm-\u003ecmsg_len = cmlen;\n 289:\t\t\tmemcpy(CMSG_DATA(cm), data, cmlen - sizeof(*cm));\n"
}

33/3 2026/09/15 06:25 llm kmsan-evaluator
0m Model:
gemini-3.8-flash

Args:
null

Results:
null

Tokens:
							input: 30508
							output: 35
							thoughts: 45
						

Thoughts:
Here's my take on the thought process, as if it were my own:

**Diving into `scm.c`**

Alright, let's get down to brass tacks. I'm focusing in on the `net/core/scm.c` file. Specifically, I need to understand something related to SCM (Socket Credential Management), so I'm honing in on a specific section. My intuition suggests that lines 270-300 might hold the key, but to be sure, I'll broaden my scope slightly and take a look at lines 280 to 305 to ensure I don't miss anything that's relevant in that immediate region. This should give me the context I need to figure out what's going on.



34/3 2026/09/15 06:25 tool read-file
0m Args:
{
  "File": "net/core/scm.c",
  "FirstLine": 280,
  "LineCount": 25
}

Results:
{
  "Contents": " 280:\t\t\t\tunsafe_copy_to_user(CMSG_USER_DATA(cm), data,\n 281:\t\t\t\t\t\t    cmlen - sizeof(*cm), efault);\n 282:\t\t\t}\n 283:\t\t} else {\n 284:\t\t\tstruct cmsghdr *cm = msg-\u003emsg_control;\n 285:\t\n 286:\t\t\tcm-\u003ecmsg_level = level;\n 287:\t\t\tcm-\u003ecmsg_type = type;\n 288:\t\t\tcm-\u003ecmsg_len = cmlen;\n 289:\t\t\tmemcpy(CMSG_DATA(cm), data, cmlen - sizeof(*cm));\n 290:\t\t}\n 291:\t\n 292:\t\tcmlen = min(CMSG_SPACE(len), msg-\u003emsg_controllen);\n 293:\t\tif (msg-\u003emsg_control_is_user)\n 294:\t\t\tmsg-\u003emsg_control_user += cmlen;\n 295:\t\telse\n 296:\t\t\tmsg-\u003emsg_control += cmlen;\n 297:\t\tmsg-\u003emsg_controllen -= cmlen;\n 298:\t\treturn 0;\n 299:\t\n 300:\tefault:\n 301:\t\treturn -EFAULT;\n 302:\t}\n 303:\tEXPORT_SYMBOL(put_cmsg);\n 304:\t\n"
}

35/3 2026/09/15 06:25 llm kmsan-evaluator
0m Model:
gemini-3.8-flash

Args:
null

Results:
null

Tokens:
							input: 31128
							output: 30
							thoughts: 2504
						

Thoughts:
**Analyzing Potential Uninitialized Memory Read in qrtr_ns_worker**

Okay, I need to trace this carefully. My initial thought is the `put_cmsg` function. I see how it interacts with `msghdr` structures, specifically when `msg->msg_control_is_user` is true or false. The critical point is that when it's *false* (as is the case in `qrtr_ns_worker`), the control buffer is in kernel space, not user space.

I see `qrtr_ns_worker` in `net/qrtr/ns.c`, using `kernel_recvmsg` and then `put_cmsg`. The key is the uninitialized `u8 control[32];` stack buffer. It's not initialized, which immediately makes me wary.

I need to track the `control` buffer's lifecycle in `qrtr_ns_worker`. I see it's used with `kernel_recvmsg`. Inside `kernel_recvmsg`, the kernel calls `qrtr_recvmsg`. I need to follow the logic: If `cb->endpoint_id` is 0 or `test_bit(...)` is false, `put_cmsg` is not called, and msg.msg_controllen remains 32. In that case, `msg.msg_controllen` ends up being 0, and the function appears to work as designed. If `put_cmsg` isn't called, there is no read of the uninitialized memory.

However, if `cb->endpoint_id` is *not* zero, `put_cmsg` *is* called. This is the crucial point to evaluate. I need to understand what `put_cmsg` writes. It constructs a `cmsghdr` and copies data. The size of the `cmsghdr` structure on a 64-bit architecture is 16 bytes. `CMSG_LEN(4)` is 20 and `CMSG_SPACE(4)` is 24. So `put_cmsg` writes 20 bytes into the `control` buffer, which is sized to 32 bytes and advances `msg->msg_control` and reduces `msg->msg_controllen`. `put_cmsg` writes the level, type, length, and the endpoint id. `msg->msg_controllen` becomes 8 in `qrtr_recvmsg`.

Back in `qrtr_ns_worker`, `msg.msg_controllen` becomes `32 - 8 = 24`. Now the function calls `qrtr_msg_get_endpoint`.

The important thing is how `for_each_cmsghdr` operates. The check if `cmsg->cmsg_len >= sizeof(struct cmsghdr)` and `cmsg->cmsg_len <= msg->msg_controllen` (20 <= 24).  So the first iteration reads the 20 bytes of `put_cmsg`. It seems safe here.

Ultimately, by carefully tracing the code path, I've confirmed that the uninitialized stack buffer `control` is *not* read when `cb->endpoint_id` is zero. However, when it is non-zero, the `put_cmsg` is called, initializes the first 20 bytes of `control`, and it is read during the subsequent operations. Thus, `put_cmsg` protects against reads of the uninitialized region.



36/3 2026/09/15 06:25 tool grepper
0m Args:
{
  "Expression": "define for_each_cmsghdr",
  "PathPrefix": "include/"
}

Results:
{
  "Output": "include/linux/socket.h=119=struct cmsghdr {\n--\ninclude/linux/socket.h-149-\t\t\t      ((char *)(cmsg) - (char *)(mhdr)-\u003emsg_control)))\ninclude/linux/socket.h:150:#define for_each_cmsghdr(cmsg, msg) \\\ninclude/linux/socket.h-151-\tfor (cmsg = CMSG_FIRSTHDR(msg); \\\n"
}

37/3 2026/09/15 06:25 llm kmsan-evaluator
0m Model:
gemini-3.8-flash

Args:
null

Results:
null

Tokens:
							input: 34527
							output: 35
							thoughts: 23
						

Thoughts:
Here's a first-person summary, tailored as requested:

**Diving into the Socket Plumbing**

Alright, let's get down to brass tacks. I need to refresh my memory on the core socket definitions, so I'm going to pull up `include/linux/socket.h` and focus specifically on lines 120 through 160. I know this section likely holds the foundational data structures and macro definitions that govern the behavior of the socket layer within the kernel. I'm expecting to see definitions for the core socket types, flags, and perhaps some essential error codes. Specifically, I'm looking for the structural organization of these data types, and how the Linux kernel provides a high level interface. This should give me a quick handle on which key structures are at the heart of any socket operation, and maybe some hints on the underlying API that is used. I'll be particularly interested in identifying any areas that might have changed recently, or that present opportunities for optimization if I need to refactor or work with them later.



38/3 2026/09/15 06:25 tool read-file
0m Args:
{
  "File": "include/linux/socket.h",
  "FirstLine": 120,
  "LineCount": 40
}

Results:
{
  "Contents": " 120:\t\t__kernel_size_t\tcmsg_len;\t/* data byte count, including hdr */\n 121:\t        int\t\tcmsg_level;\t/* originating protocol */\n 122:\t        int\t\tcmsg_type;\t/* protocol-specific type */\n 123:\t};\n 124:\t\n 125:\t/*\n 126:\t *\tAncillary data object information MACROS\n 127:\t *\tTable 5-14 of POSIX 1003.1g\n 128:\t */\n 129:\t\n 130:\t#define __CMSG_NXTHDR(ctl, len, cmsg) __cmsg_nxthdr((ctl),(len),(cmsg))\n 131:\t#define CMSG_NXTHDR(mhdr, cmsg) cmsg_nxthdr((mhdr), (cmsg))\n 132:\t\n 133:\t#define CMSG_ALIGN(len) ( ((len)+sizeof(long)-1) \u0026 ~(sizeof(long)-1) )\n 134:\t\n 135:\t#define CMSG_DATA(cmsg) \\\n 136:\t\t((void *)(cmsg) + sizeof(struct cmsghdr))\n 137:\t#define CMSG_USER_DATA(cmsg) \\\n 138:\t\t((void __user *)(cmsg) + sizeof(struct cmsghdr))\n 139:\t#define CMSG_SPACE(len) (sizeof(struct cmsghdr) + CMSG_ALIGN(len))\n 140:\t#define CMSG_LEN(len) (sizeof(struct cmsghdr) + (len))\n 141:\t\n 142:\t#define __CMSG_FIRSTHDR(ctl,len) ((len) \u003e= sizeof(struct cmsghdr) ? \\\n 143:\t\t\t\t\t  (struct cmsghdr *)(ctl) : \\\n 144:\t\t\t\t\t  (struct cmsghdr *)NULL)\n 145:\t#define CMSG_FIRSTHDR(msg)\t__CMSG_FIRSTHDR((msg)-\u003emsg_control, (msg)-\u003emsg_controllen)\n 146:\t#define CMSG_OK(mhdr, cmsg) ((cmsg)-\u003ecmsg_len \u003e= sizeof(struct cmsghdr) \u0026\u0026 \\\n 147:\t\t\t\t     (cmsg)-\u003ecmsg_len \u003c= (unsigned long) \\\n 148:\t\t\t\t     ((mhdr)-\u003emsg_controllen - \\\n 149:\t\t\t\t      ((char *)(cmsg) - (char *)(mhdr)-\u003emsg_control)))\n 150:\t#define for_each_cmsghdr(cmsg, msg) \\\n 151:\t\tfor (cmsg = CMSG_FIRSTHDR(msg); \\\n 152:\t\t     cmsg; \\\n 153:\t\t     cmsg = CMSG_NXTHDR(msg, cmsg))\n 154:\t\n 155:\t/*\n 156:\t *\tGet the next cmsg header\n 157:\t *\n 158:\t *\tPLEASE, do not touch this function. If you think, that it is\n 159:\t *\tincorrect, grep kernel sources and think about consequences\n"
}

39/3 2026/09/15 06:25 llm kmsan-evaluator
0m Model:
gemini-3.8-flash

Args:
null

Results:
null

Tokens:
							input: 35609
							output: 35
							thoughts: 23
						

Thoughts:
Okay, here's my interpretation of that thought process, tailored for an expert audience, and presented as if it were my own internal monologue:

**Diving into the Next Header**

Alright, I need to get a handle on what's happening with message control, specifically the structure of the next header. I need to refresh my memory on the handling of `cmsg_nxthdr`. I'm going to jump into the code, and I'm really looking to understand the mechanics of how the control message data is structured within the context of the larger message. I want to trace its use within lines 160-200. I need to refresh the details of the internal structures, especially in relation to how it's handled in the context of `msghdr` and `cmsghdr`. I know this is a critical section for efficient data access, so I'm paying close attention to any subtle optimizations or potential pitfalls that might be present in this segment. Specifically, I'm thinking about the implications for memory alignment and pointer arithmetic within this function. I'll need to double check any potential off-by-one errors that might crop up. This is a common point for subtle, difficult-to-debug issues.



40/3 2026/09/15 06:25 tool read-file
0m Args:
{
  "File": "include/linux/socket.h",
  "FirstLine": 160,
  "LineCount": 40
}

Results:
{
  "Contents": " 160:\t *\tbefore trying to improve it.\n 161:\t *\n 162:\t *\tNow it always returns valid, not truncated ancillary object\n 163:\t *\tHEADER. But caller still MUST check, that cmsg-\u003ecmsg_len is\n 164:\t *\tinside range, given by msg-\u003emsg_controllen before using\n 165:\t *\tancillary object DATA.\t\t\t\t--ANK (980731)\n 166:\t */\n 167:\t\n 168:\tstatic inline struct cmsghdr * __cmsg_nxthdr(void *__ctl, __kernel_size_t __size,\n 169:\t\t\t\t\t\t       struct cmsghdr *__cmsg)\n 170:\t{\n 171:\t\tstruct cmsghdr * __ptr;\n 172:\t\n 173:\t\t__ptr = (struct cmsghdr*)(((unsigned char *) __cmsg) +  CMSG_ALIGN(__cmsg-\u003ecmsg_len));\n 174:\t\tif ((unsigned long)((char*)(__ptr+1) - (char *) __ctl) \u003e __size)\n 175:\t\t\treturn (struct cmsghdr *)0;\n 176:\t\n 177:\t\treturn __ptr;\n 178:\t}\n 179:\t\n 180:\tstatic inline struct cmsghdr * cmsg_nxthdr (struct msghdr *__msg, struct cmsghdr *__cmsg)\n 181:\t{\n 182:\t\treturn __cmsg_nxthdr(__msg-\u003emsg_control, __msg-\u003emsg_controllen, __cmsg);\n 183:\t}\n 184:\t\n 185:\tstatic inline size_t msg_data_left(const struct msghdr *msg)\n 186:\t{\n 187:\t\treturn iov_iter_count(\u0026msg-\u003emsg_iter);\n 188:\t}\n 189:\t\n 190:\t/* \"Socket\"-level control message types: */\n 191:\t\n 192:\t#define\tSCM_RIGHTS\t0x01\t\t/* rw: access rights (array of int) */\n 193:\t#define SCM_CREDENTIALS 0x02\t\t/* rw: struct ucred\t\t*/\n 194:\t#define SCM_SECURITY\t0x03\t\t/* rw: security label\t\t*/\n 195:\t#define SCM_PIDFD\t0x04\t\t/* ro: pidfd (int)\t\t*/\n 196:\t\n 197:\tstruct ucred {\n 198:\t\t__u32\tpid;\n 199:\t\t__u32\tuid;\n"
}

41/3 2026/09/15 06:25 llm kmsan-evaluator
0m Model:
gemini-3.8-flash

Args:
null

Results:
null

Tokens:
							input: 36622
							output: 29
							thoughts: 2433
						

Thoughts:
**Analyzing Potential Information Leaks in QRTR Driver**

Okay, so I've been digging into this QRTR driver code, specifically looking for potential information leaks, and I think I've got a decent handle on the situation. Initially, I was looking at the `cmsg_nxthdr` macro and how it handles control messages, and although it terminates cleanly, it didn't seem to be a vector for leaking information.

My attention then shifted to `qrtr_ns_sendmsg` and how it crafts control messages. I noticed the use of `CMSG_SPACE` and `CMSG_LEN` with the `endpoint_id`. The control buffer is allocated on the stack with `CMSG_SPACE`, but initialized with `CMSG_LEN`. That leaves the padding bytes between `CMSG_LEN` and `CMSG_SPACE` uninitialized, which is a bit of a red flag. However, after carefully examining the code path, including `kernel_sendmsg` which calls `sock_sendmsg` and then `qrtr_sendmsg`, I don't see any read of those uninitialized bytes in the kernel. `qrtr_msg_get_endpoint` which reads the endpoint id does not look at the uninitialized bytes. Nothing is copied to userspace from this area. So, that seems safe.

Then, I looked at the user-space facing interfaces `qrtr_setsockopt` and `qrtr_getsockopt`. The options `QRTR_REPORT_ENDPOINT` and `QRTR_BIND_ENDPOINT` seemed promising. However, the data returned is either zero-initialized or set by `setsockopt`. So those seem ok.

However, the real key is the `qrtr_recvmsg` function. I was initially going to write this off but now, I see something. The `cb` structure, cast to an `skb`, is where `cb->endpoint_id` comes from, and this is where `put_cmsg` gets called. Now, I have to trace EVERY code path that allocates `skb` and queues it to the `qrtr_sock`. I need to be sure that the `cb->endpoint_id` is *always* initialized. I'm going to have to make sure to check everywhere where `sock_queue_rcv_skb` or `skb_queue_tail` is used. This is going to be my key focus.



42/3 2026/09/15 06:26 tool grepper
0m Args:
{
  "Expression": "sk_receive_queue",
  "PathPrefix": "net/qrtr"
}

Results:
{
  "Output": "net/qrtr/af_qrtr.c=1385=static int qrtr_ioctl(struct socket *sock, unsigned int cmd, unsigned long arg)\n--\nnet/qrtr/af_qrtr.c-1405-\tcase TIOCINQ:\nnet/qrtr/af_qrtr.c:1406:\t\tskb = skb_peek(\u0026sk-\u003esk_receive_queue);\nnet/qrtr/af_qrtr.c-1407-\t\tif (skb)\n--\nnet/qrtr/af_qrtr.c=1513=static int qrtr_release(struct socket *sock)\n--\nnet/qrtr/af_qrtr.c-1534-\nnet/qrtr/af_qrtr.c:1535:\tskb_queue_purge(\u0026sk-\u003esk_receive_queue);\nnet/qrtr/af_qrtr.c-1536-\n"
}

43/3 2026/09/15 06:26 llm kmsan-evaluator
0m Model:
gemini-3.8-flash

Args:
null

Results:
null

Tokens:
							input: 39841
							output: 30
							thoughts: 234
						

Thoughts:
**Analyzing `sock_queue_rcv_skb` in the QRTR Subsystem**

Okay, let's dive into this. I need to understand the usage of `sock_queue_rcv_skb` within the QRTR subsystem. My initial focus is on `net/qrtr/`, and the immediate thought is to check every instance where `sock_queue_rcv_skb` is invoked.

Alright, the first two calls I've identified are within `qrtr_endpoint_post` at line 700, and `qrtr_local_enqueue` at line 1083. In `qrtr_endpoint_post`, it's fairly straightforward: we're grabbing the `qrtr_cb` from the skb, setting the endpoint ID, and then pushing the skb onto the receive queue using `sock_queue_rcv_skb`. `qrtr_local_enqueue` looks similar; we're setting source information and the endpoint ID in the callback structure and then using `sock_queue_rcv_skb` as well.

Wait a second, let's step back a bit and consider what *calls* `qrtr_local_enqueue`. That's the missing piece here. Knowing that will give me better context for analyzing `sock_queue_rcv_skb` usage. Looks like I need to search for all callers of `qrtr_local_enqueue` now.



44/3 2026/09/15 06:26 tool grepper
0m Args:
{
  "Expression": "qrtr_local_enqueue",
  "PathPrefix": "net/qrtr"
}

Results:
{
  "Output": "net/qrtr/af_qrtr.c=218=struct qrtr_tx_flow {\n--\nnet/qrtr/af_qrtr.c-226-\nnet/qrtr/af_qrtr.c:227:static int qrtr_local_enqueue(struct qrtr_node *node, struct sk_buff *skb,\nnet/qrtr/af_qrtr.c-228-\t\t\t      u32 endpoint_id,\n--\nnet/qrtr/af_qrtr.c=804=void qrtr_endpoint_unregister(struct qrtr_endpoint *ep)\n--\nnet/qrtr/af_qrtr.c-838-\t\t\t\tpkt-\u003ecmd = cpu_to_le32(QRTR_TYPE_BYE);\nnet/qrtr/af_qrtr.c:839:\t\t\t\tqrtr_local_enqueue(NULL, skb, endpoint_id,\nnet/qrtr/af_qrtr.c-840-\t\t\t\t\t\t   QRTR_TYPE_BYE, \u0026src, \u0026dst);\n--\nnet/qrtr/af_qrtr.c=1031=static int qrtr_bind(struct socket *sock, struct sockaddr_unsized *saddr, int len)\n--\nnet/qrtr/af_qrtr.c-1051-/* Queue packet to local peer socket. */\nnet/qrtr/af_qrtr.c:1052:static int qrtr_local_enqueue(struct qrtr_node *node, struct sk_buff *skb,\nnet/qrtr/af_qrtr.c-1053-\t\t\t      u32 endpoint_id,\n--\nnet/qrtr/af_qrtr.c=1097=static int qrtr_bcast_enqueue(struct qrtr_node *node, struct sk_buff *skb,\n--\nnet/qrtr/af_qrtr.c-1113-\nnet/qrtr/af_qrtr.c:1114:\tqrtr_local_enqueue(NULL, skb, endpoint_id, type, from, to);\nnet/qrtr/af_qrtr.c-1115-\n--\nnet/qrtr/af_qrtr.c=1119=static int qrtr_sendmsg(struct socket *sock, struct msghdr *msg, size_t len)\n--\nnet/qrtr/af_qrtr.c-1176-\t} else if (addr-\u003esq_node == ipc-\u003eus.sq_node) {\nnet/qrtr/af_qrtr.c:1177:\t\tenqueue_fn = qrtr_local_enqueue;\nnet/qrtr/af_qrtr.c-1178-\t} else {\n"
}

45/3 2026/09/15 06:26 llm kmsan-evaluator
0m Model:
gemini-3.8-flash

Args:
null

Results:
null

Tokens:
							input: 41088
							output: 40
							thoughts: 162
						

Thoughts:
**Investigating the QRTR Message Callback ID**

Okay, so I'm digging into this QRTR code and trying to understand how message callbacks work, specifically the `endpoint_id`. It looks like in `qrtr_local_enqueue`, we're grabbing the callback structure, which is stored in `skb->cb`, and setting some key source information: `src_node`, `src_port`, and most importantly, `cb->endpoint_id = endpoint_id;`. Aha, so the `endpoint_id` is definitely being assigned there. And then, I see that within `qrtr_endpoint_post`, it's being set again: `cb->endpoint_id = ep->id;`. Okay, that seems consistent. So, based on those two places the value is always being set.

But wait, hold on. This seems *too* straightforward. I need to be absolutely sure, and the real question is, what about when sending a message initially? Where does this ID come from initially? I'm going to look at `qrtr_sendmsg` to see. Let me check lines 1140-1230 of `net/qrtr/af_qrtr.c` and figure this out.



46/3 2026/09/15 06:26 tool read-file
0m Args:
{
  "File": "net/qrtr/af_qrtr.c",
  "FirstLine": 1140,
  "LineCount": 85
}

Results:
{
  "Contents": "1140:\t\tif (len \u003e 65535)\n1141:\t\t\treturn -EMSGSIZE;\n1142:\t\n1143:\t\trc = qrtr_msg_get_endpoint(msg, \u0026msg_endpoint_id);\n1144:\t\tif (rc \u003c 0)\n1145:\t\t\treturn rc;\n1146:\t\n1147:\t\tlock_sock(sk);\n1148:\t\n1149:\t\tif (addr) {\n1150:\t\t\trc = -EINVAL;\n1151:\t\n1152:\t\t\tif (msg-\u003emsg_namelen \u003c sizeof(*addr))\n1153:\t\t\t\tgoto release_sock;\n1154:\t\n1155:\t\t\tif (addr-\u003esq_family != AF_QIPCRTR)\n1156:\t\t\t\tgoto release_sock;\n1157:\t\n1158:\t\t\trc = qrtr_autobind(sock);\n1159:\t\t\tif (rc)\n1160:\t\t\t\tgoto release_sock;\n1161:\t\t} else if (sk-\u003esk_state == TCP_ESTABLISHED) {\n1162:\t\t\taddr = \u0026ipc-\u003epeer;\n1163:\t\t} else {\n1164:\t\t\trc = -ENOTCONN;\n1165:\t\t\tgoto release_sock;\n1166:\t\t}\n1167:\t\n1168:\t\tnode = NULL;\n1169:\t\tif (addr-\u003esq_node == QRTR_NODE_BCAST) {\n1170:\t\t\tif (addr-\u003esq_port != QRTR_PORT_CTRL \u0026\u0026\n1171:\t\t\t    qrtr_local_nid != QRTR_NODE_BCAST) {\n1172:\t\t\t\trc = -ENOTCONN;\n1173:\t\t\t\tgoto release_sock;\n1174:\t\t\t}\n1175:\t\t\tenqueue_fn = qrtr_bcast_enqueue;\n1176:\t\t} else if (addr-\u003esq_node == ipc-\u003eus.sq_node) {\n1177:\t\t\tenqueue_fn = qrtr_local_enqueue;\n1178:\t\t} else {\n1179:\t\t\tendpoint_id = msg_endpoint_id ?\n1180:\t\t\t\t      msg_endpoint_id : ipc-\u003ebound_endpoint;\n1181:\t\n1182:\t\t\tnode = qrtr_node_lookup(endpoint_id, addr-\u003esq_node);\n1183:\t\t\tif (!node) {\n1184:\t\t\t\trc = endpoint_id ? -ENXIO : -ECONNRESET;\n1185:\t\t\t\tgoto release_sock;\n1186:\t\t\t}\n1187:\t\t\tenqueue_fn = qrtr_node_enqueue;\n1188:\t\t}\n1189:\t\n1190:\t\tplen = (len + 3) \u0026 ~3;\n1191:\t\tskb = sock_alloc_send_skb(sk, plen + QRTR_HDR_MAX_SIZE,\n1192:\t\t\t\t\t  msg-\u003emsg_flags \u0026 MSG_DONTWAIT, \u0026rc);\n1193:\t\tif (!skb) {\n1194:\t\t\trc = -ENOMEM;\n1195:\t\t\tgoto out_node;\n1196:\t\t}\n1197:\t\n1198:\t\tskb_reserve(skb, QRTR_HDR_MAX_SIZE);\n1199:\t\n1200:\t\trc = memcpy_from_msg(skb_put(skb, len), msg, len);\n1201:\t\tif (rc) {\n1202:\t\t\tkfree_skb(skb);\n1203:\t\t\tgoto out_node;\n1204:\t\t}\n1205:\t\n1206:\t\tif (ipc-\u003eus.sq_port == QRTR_PORT_CTRL) {\n1207:\t\t\tif (len \u003c 4) {\n1208:\t\t\t\trc = -EINVAL;\n1209:\t\t\t\tkfree_skb(skb);\n1210:\t\t\t\tgoto out_node;\n1211:\t\t\t}\n1212:\t\n1213:\t\t\t/* control messages already require the type as 'command' */\n1214:\t\t\tskb_copy_bits(skb, 0, \u0026qrtr_type, 4);\n1215:\t\t\t/*\n1216:\t\t\t * Allow local name service to make packets appear as if\n1217:\t\t\t * they originated remotely\n1218:\t\t\t */\n1219:\t\t\tendpoint_id = msg_endpoint_id;\n1220:\t\t}\n1221:\t\n1222:\t\ttype = le32_to_cpu(qrtr_type);\n1223:\t\trc = enqueue_fn(node, skb, endpoint_id, type, \u0026ipc-\u003eus, addr);\n1224:\t\tif (rc \u003e= 0)\n"
}

47/3 2026/09/15 06:26 llm kmsan-evaluator
0m Model:
gemini-3.8-flash

Args:
null

Results:
null

Tokens:
							input: 42802
							output: 39
							thoughts: 60
						

Thoughts:
**Analyzing the QRTR Node Enqueue Function**

Okay, let's dive in and dissect how this `qrtr_node_enqueue` function operates. My immediate focus is on how it handles the Socket Buffer (`skb`) and the `endpoint_id`. Understanding their interaction is key to grasping the core functionality. I'm going to jump straight to the source code, specifically around lines 440 to 500, to pinpoint exactly what's happening within that segment of the code. This should illuminate the specific processing steps concerning those crucial parameters.



48/3 2026/09/15 06:26 tool read-file
0m Args:
{
  "File": "net/qrtr/af_qrtr.c",
  "FirstLine": 440,
  "LineCount": 60
}

Results:
{
  "Contents": " 440:\t\tif (flow) {\n 441:\t\t\tspin_lock_irq(\u0026flow-\u003eresume_tx.lock);\n 442:\t\t\tflow-\u003etx_failed = 1;\n 443:\t\t\tspin_unlock_irq(\u0026flow-\u003eresume_tx.lock);\n 444:\t\t}\n 445:\t\n 446:\t\treturn 0;\n 447:\t}\n 448:\t\n 449:\t/* Pass an outgoing packet socket buffer to the endpoint driver. */\n 450:\tstatic int qrtr_node_enqueue(struct qrtr_node *node, struct sk_buff *skb,\n 451:\t\t\t\t     u32 endpoint_id,\n 452:\t\t\t\t     int type, struct sockaddr_qrtr *from,\n 453:\t\t\t\t     struct sockaddr_qrtr *to)\n 454:\t{\n 455:\t\tstruct qrtr_hdr_v1 *hdr;\n 456:\t\tsize_t len = skb-\u003elen;\n 457:\t\tint rc, confirm_rx;\n 458:\t\n 459:\t\tconfirm_rx = qrtr_tx_wait(node, to-\u003esq_node, to-\u003esq_port, type);\n 460:\t\tif (confirm_rx \u003c 0) {\n 461:\t\t\tkfree_skb(skb);\n 462:\t\t\treturn confirm_rx;\n 463:\t\t}\n 464:\t\n 465:\t\thdr = skb_push(skb, sizeof(*hdr));\n 466:\t\thdr-\u003eversion = cpu_to_le32(QRTR_PROTO_VER_1);\n 467:\t\thdr-\u003etype = cpu_to_le32(type);\n 468:\t\thdr-\u003esrc_node_id = cpu_to_le32(from-\u003esq_node);\n 469:\t\thdr-\u003esrc_port_id = cpu_to_le32(from-\u003esq_port);\n 470:\t\tif (to-\u003esq_port == QRTR_PORT_CTRL) {\n 471:\t\t\thdr-\u003edst_node_id = cpu_to_le32(node-\u003enid);\n 472:\t\t\thdr-\u003edst_port_id = cpu_to_le32(QRTR_PORT_CTRL);\n 473:\t\t} else {\n 474:\t\t\thdr-\u003edst_node_id = cpu_to_le32(to-\u003esq_node);\n 475:\t\t\thdr-\u003edst_port_id = cpu_to_le32(to-\u003esq_port);\n 476:\t\t}\n 477:\t\n 478:\t\thdr-\u003esize = cpu_to_le32(len);\n 479:\t\thdr-\u003econfirm_rx = cpu_to_le32(!!confirm_rx);\n 480:\t\n 481:\t\trc = skb_put_padto(skb, ALIGN(len, 4) + sizeof(*hdr));\n 482:\t\n 483:\t\tif (!rc) {\n 484:\t\t\tmutex_lock(\u0026node-\u003eep_lock);\n 485:\t\t\trc = -ENODEV;\n 486:\t\t\tif (node-\u003eep)\n 487:\t\t\t\trc = node-\u003eep-\u003exmit(node-\u003eep, skb);\n 488:\t\t\telse\n 489:\t\t\t\tkfree_skb(skb);\n 490:\t\t\tmutex_unlock(\u0026node-\u003eep_lock);\n 491:\t\t}\n 492:\t\t/* Need to ensure that a subsequent message carries the otherwise lost\n 493:\t\t * confirm_rx flag if we dropped this one */\n 494:\t\tif (rc \u0026\u0026 confirm_rx)\n 495:\t\t\trc = qrtr_tx_flow_failed(node, to-\u003esq_node, to-\u003esq_port);\n 496:\t\n 497:\t\treturn rc;\n 498:\t}\n 499:\t\n"
}

49/3 2026/09/15 06:26 llm kmsan-evaluator
0m Model:
gemini-3.8-flash

Args:
null

Results:
null

Tokens:
							input: 44034
							output: 36
							thoughts: 1180
						

Thoughts:
**Analyzing QRTR Endpoint Registration and Initialization**

Okay, let's break this down. First, it's immediately apparent that `qrtr_node_enqueue` doesn't use `endpoint_id`, which seems odd. It's essentially just using the `enqueue_fn` signature. I need to keep that in mind as a potential point of optimization or simplification later. And the padding with zeroes in `skb_put_padto` is standard practice, not a concern.

Now, I'm focusing on the registration and unregistration process via `qrtr_endpoint_register` and `qrtr_endpoint_unregister`, specifically what happens with that `endpoint_id`. Looking at `qrtr_endpoint_register`, I see that `xa_alloc_cyclic` is used to get an `endpoint_id`. Importantly, if `qrtr_node_assign` fails *after* `xa_alloc_cyclic` succeeds, the code jumps to `free_node`. My immediate thought is, "Does it clean up the `endpoint_id` allocation?". No, it doesn't. But, that's a resource leak, not an uninitialized memory issue. It would be important to track, but it's not the primary concern here. Also, what if `qrtr_node_assign` succeeded partially? This is handled inside `qrtr_node_assign`.

Then I remember `helper0` from `net/qrtr/af_qrtr.c`. I need to ensure that it's correctly initialized as a static global variable that is zero-initialized due to its location in BSS. In `qrtr_proto_init`, `radix_tree_insert` is used and then, the tree is properly initialized with `INIT_RADIX_TREE`. So, `helper0` is safe.

Now, my attention is drawn to `ep->helper` within the `struct qrtr_endpoint`. The crucial point is how this `helper` is being initialized. Checking the `qrtr_endpoint_register` function, I notice `ep->id = endpoint_id;` and `ep->helper.added = 0;`. This part seems okay. Then `qrtr_node_assign` looks to insert the `helper`. So, `node->ep->helper` is correctly initialized before any use.

I need to quickly review `net/qrtr/ns.c` as well. In the new code, I see the `struct qrtr_server` and how its fields are declared. Now, I need to see where it is allocated by reading `server_add` in `net/qrtr/ns.c`!



50/3 2026/09/15 06:26 tool read-file
0m Args:
{
  "File": "net/qrtr/ns.c",
  "FirstLine": 315,
  "LineCount": 60
}

Results:
{
  "Contents": " 315:\t\t\t\t\t      unsigned int node_id,\n 316:\t\t\t\t\t      unsigned int port)\n 317:\t{\n 318:\t\tstruct qrtr_server *srv;\n 319:\t\tstruct qrtr_server *old;\n 320:\t\tstruct qrtr_node *node;\n 321:\t\n 322:\t\tif (!service || !port)\n 323:\t\t\treturn NULL;\n 324:\t\n 325:\t\tnode = node_get(endpoint_id, node_id);\n 326:\t\tif (!node)\n 327:\t\t\treturn NULL;\n 328:\t\n 329:\t\t/* Make sure the new servers per port are capped at the maximum value */\n 330:\t\told = xa_load(\u0026node-\u003eservers, port);\n 331:\t\tif (!old \u0026\u0026 node-\u003eserver_count \u003e= QRTR_NS_MAX_SERVERS) {\n 332:\t\t\tpr_err_ratelimited(\"QRTR client node %u exceeds max server limit!\\n\", node_id);\n 333:\t\t\treturn NULL;\n 334:\t\t}\n 335:\t\n 336:\t\tsrv = kzalloc_obj(*srv);\n 337:\t\tif (!srv)\n 338:\t\t\treturn NULL;\n 339:\t\n 340:\t\tsrv-\u003eservice = service;\n 341:\t\tsrv-\u003einstance = instance;\n 342:\t\tsrv-\u003enode = node_id;\n 343:\t\tsrv-\u003eport = port;\n 344:\t\n 345:\t\t/* Delete the old server on the same port */\n 346:\t\told = xa_store(\u0026node-\u003eservers, port, srv, GFP_KERNEL);\n 347:\t\tif (old) {\n 348:\t\t\tif (xa_is_err(old)) {\n 349:\t\t\t\tpr_err(\"failed to add server [0x%x:0x%x] ret:%d\\n\",\n 350:\t\t\t\t       srv-\u003eservice, srv-\u003einstance, xa_err(old));\n 351:\t\t\t\tgoto err;\n 352:\t\t\t} else {\n 353:\t\t\t\tkfree(old);\n 354:\t\t\t}\n 355:\t\t} else {\n 356:\t\t\tnode-\u003eserver_count++;\n 357:\t\t}\n 358:\t\n 359:\t\ttrace_qrtr_ns_server_add(srv-\u003eservice, srv-\u003einstance,\n 360:\t\t\t\t\t srv-\u003enode, srv-\u003eport);\n 361:\t\n 362:\t\treturn srv;\n 363:\t\n 364:\terr:\n 365:\t\tkfree(srv);\n 366:\t\treturn NULL;\n 367:\t}\n 368:\t\n 369:\tstatic int server_del(u32 endpoint_id, struct qrtr_node *node,\n 370:\t\t\t      unsigned int port, bool bcast)\n 371:\t{\n 372:\t\tstruct qrtr_lookup *lookup;\n 373:\t\tstruct qrtr_server *srv;\n 374:\t\tstruct list_head *li;\n"
}

51/3 2026/09/15 06:26 llm kmsan-evaluator
0m Model:
gemini-3.8-flash

Args:
null

Results:
null

Tokens:
							input: 46643
							output: 31
							thoughts: 68
						

Thoughts:
**Analyzing Potential Memory Corruption in QRTR Nameservice**

Okay, so I'm looking at this `net/qrtr/ns.c` code and something immediately jumps out. Specifically, I'm seeing this line, `srv = kzalloc_obj(*srv);`. That's a `kzalloc`, meaning the memory is zeroed out. Good, that's generally a safe practice.

But then my expert instincts kick in. I'm wondering about `srv->endpoint_id`. I don't recall seeing it explicitly initialized in the `server_add` function itself. That's a potential problem right there. I know better than most how crucial proper initialization is to prevent data leaks or unexpected behavior. If it's not initialized, then accessing this value may give me unexpected results.

Alright, time to get to the bottom of this. I need to figure out if `srv->endpoint_id` is ever even read. I'm going to launch a `grep` search right now within this file (`net/qrtr/ns.c`), specifically for the term `endpoint_id`. Let's see where that variable is used and if it's potentially causing a problem. I'm hoping I can find where and when it's being used. I will likely be able to trace it back from there to figure out if there's a problem or not.



52/3 2026/09/15 06:26 tool grepper
0m Args:
{
  "Expression": "endpoint_id",
  "PathPrefix": "net/qrtr/ns.c"
}

Results:
{
  "Output": "net/qrtr/ns.c=60=struct qrtr_server {\n--\nnet/qrtr/ns.c-65-\tunsigned int port;\nnet/qrtr/ns.c:66:\tu32 endpoint_id;\nnet/qrtr/ns.c-67-\n--\nnet/qrtr/ns.c=90=static u16 node_count;\nnet/qrtr/ns.c-91-\nnet/qrtr/ns.c:92:static struct qrtr_node *node_get(u32 endpoint_id, unsigned int node_id)\nnet/qrtr/ns.c-93-{\n--\nnet/qrtr/ns.c-97-\nnet/qrtr/ns.c:98:\tendpoint = xa_load(\u0026endpoints, endpoint_id);\nnet/qrtr/ns.c-99-\tif (!endpoint) {\n--\nnet/qrtr/ns.c-103-\nnet/qrtr/ns.c:104:\t\tendpoint-\u003eid = endpoint_id;\nnet/qrtr/ns.c-105-\t\txa_init(\u0026endpoint-\u003enodes);\nnet/qrtr/ns.c-106-\nnet/qrtr/ns.c:107:\t\tif (xa_store(\u0026endpoints, endpoint_id, endpoint, GFP_KERNEL)) {\nnet/qrtr/ns.c-108-\t\t\tkfree(endpoint);\n--\nnet/qrtr/ns.c-141-\tif (new_endpoint) {\nnet/qrtr/ns.c:142:\t\txa_erase(\u0026endpoints, endpoint_id);\nnet/qrtr/ns.c-143-\t\tkfree(endpoint);\n--\nnet/qrtr/ns.c-148-\nnet/qrtr/ns.c:149:static void node_erase(u32 endpoint_id, unsigned int node_id)\nnet/qrtr/ns.c-150-{\n--\nnet/qrtr/ns.c-153-\nnet/qrtr/ns.c:154:\tendpoint = xa_load(\u0026endpoints, endpoint_id);\nnet/qrtr/ns.c-155-\tif (!endpoint)\n--\nnet/qrtr/ns.c-166-\nnet/qrtr/ns.c:167:static struct qrtr_node *node_lookup(u32 endpoint_id, unsigned int node_id)\nnet/qrtr/ns.c-168-{\n--\nnet/qrtr/ns.c-170-\nnet/qrtr/ns.c:171:\tendpoint = xa_load(\u0026endpoints, endpoint_id);\nnet/qrtr/ns.c-172-\tif (!endpoint)\n--\nnet/qrtr/ns.c=178=static int server_match(const struct qrtr_server *srv,\n--\nnet/qrtr/ns.c-190-\nnet/qrtr/ns.c:191:static int qrtr_ns_sendmsg(u32 endpoint_id, struct sockaddr_qrtr *dest,\nnet/qrtr/ns.c-192-\t\t\t   struct qrtr_ctrl_pkt *pkt)\n--\nnet/qrtr/ns.c-195-\tstruct kvec iv;\nnet/qrtr/ns.c:196:\tu8 control[CMSG_SPACE(sizeof(endpoint_id))];\nnet/qrtr/ns.c-197-\tstruct cmsghdr *cmsg;\n--\nnet/qrtr/ns.c-204-\nnet/qrtr/ns.c:205:\tif (endpoint_id) {\nnet/qrtr/ns.c-206-\t\tmsg.msg_control = control;\n--\nnet/qrtr/ns.c-211-\t\tcmsg-\u003ecmsg_type = QRTR_ENDPOINT;\nnet/qrtr/ns.c:212:\t\tcmsg-\u003ecmsg_len = CMSG_LEN(sizeof(endpoint_id));\nnet/qrtr/ns.c:213:\t\tmemcpy(CMSG_DATA(cmsg), \u0026endpoint_id, sizeof(endpoint_id));\nnet/qrtr/ns.c-214-\t}\n--\nnet/qrtr/ns.c-218-\nnet/qrtr/ns.c:219:static int service_announce_new(u32 endpoint_id, struct sockaddr_qrtr *dest,\nnet/qrtr/ns.c-220-\t\t\t\tstruct qrtr_server *srv)\n--\nnet/qrtr/ns.c-233-\nnet/qrtr/ns.c:234:\treturn qrtr_ns_sendmsg(endpoint_id, dest, \u0026pkt);\nnet/qrtr/ns.c-235-}\nnet/qrtr/ns.c-236-\nnet/qrtr/ns.c:237:static void service_announce_del(u32 endpoint_id, struct sockaddr_qrtr *dest,\nnet/qrtr/ns.c-238-\t\t\t\t struct qrtr_server *srv)\n--\nnet/qrtr/ns.c-252-\nnet/qrtr/ns.c:253:\tret = qrtr_ns_sendmsg(endpoint_id, dest, \u0026pkt);\nnet/qrtr/ns.c-254-\tif (ret \u003c 0 \u0026\u0026 ret != -ENODEV)\n--\nnet/qrtr/ns.c-259-\nnet/qrtr/ns.c:260:static void lookup_notify(u32 endpoint_id, struct sockaddr_qrtr *to,\nnet/qrtr/ns.c-261-\t\t\t  struct qrtr_server *srv, bool new)\n--\nnet/qrtr/ns.c-281-\nnet/qrtr/ns.c:282:\tret = qrtr_ns_sendmsg(endpoint_id, to, \u0026pkt);\nnet/qrtr/ns.c-283-\tif (ret \u003c 0 \u0026\u0026 ret != -ENODEV)\n--\nnet/qrtr/ns.c-286-\nnet/qrtr/ns.c:287:static int announce_servers(u32 endpoint_id, struct sockaddr_qrtr *sq)\nnet/qrtr/ns.c-288-{\n--\nnet/qrtr/ns.c-299-\txa_for_each(\u0026node-\u003eservers, index, srv) {\nnet/qrtr/ns.c:300:\t\tret = service_announce_new(endpoint_id, sq, srv);\nnet/qrtr/ns.c-301-\t\tif (ret \u003c 0) {\n--\nnet/qrtr/ns.c-311-\nnet/qrtr/ns.c:312:static struct qrtr_server *server_add(u32 endpoint_id,\nnet/qrtr/ns.c-313-\t\t\t\t      unsigned int service,\n--\nnet/qrtr/ns.c-324-\nnet/qrtr/ns.c:325:\tnode = node_get(endpoint_id, node_id);\nnet/qrtr/ns.c-326-\tif (!node)\n--\nnet/qrtr/ns.c-368-\nnet/qrtr/ns.c:369:static int server_del(u32 endpoint_id, struct qrtr_node *node,\nnet/qrtr/ns.c-370-\t\t      unsigned int port, bool bcast)\n--\nnet/qrtr/ns.c-394-\nnet/qrtr/ns.c:395:\t\tlookup_notify(endpoint_id, \u0026lookup-\u003esq, srv, false);\nnet/qrtr/ns.c-396-\t}\n--\nnet/qrtr/ns.c-403-\nnet/qrtr/ns.c:404:static int say_hello(u32 endpoint_id, struct sockaddr_qrtr *dest)\nnet/qrtr/ns.c-405-{\n--\nnet/qrtr/ns.c-411-\nnet/qrtr/ns.c:412:\tret = qrtr_ns_sendmsg(endpoint_id, dest, \u0026pkt);\nnet/qrtr/ns.c-413-\tif (ret \u003c 0)\n--\nnet/qrtr/ns.c-419-/* Announce the list of servers registered on the local node */\nnet/qrtr/ns.c:420:static int ctrl_cmd_hello(u32 endpoint_id, struct sockaddr_qrtr *sq)\nnet/qrtr/ns.c-421-{\n--\nnet/qrtr/ns.c-424-\t/* Send Hello and New Server messages to remote endpoint */\nnet/qrtr/ns.c:425:\tret = say_hello(endpoint_id, sq);\nnet/qrtr/ns.c-426-\tif (ret \u003c 0)\n--\nnet/qrtr/ns.c-428-\nnet/qrtr/ns.c:429:\treturn announce_servers(endpoint_id, sq);\nnet/qrtr/ns.c-430-}\nnet/qrtr/ns.c-431-\nnet/qrtr/ns.c:432:static int ctrl_cmd_bye(u32 endpoint_id, struct sockaddr_qrtr *from)\nnet/qrtr/ns.c-433-{\n--\nnet/qrtr/ns.c-441-\nnet/qrtr/ns.c:442:\tnode = node_get(endpoint_id, from-\u003esq_node);\nnet/qrtr/ns.c-443-\tif (!node)\n--\nnet/qrtr/ns.c-447-\txa_for_each(\u0026node-\u003eservers, index, srv)\nnet/qrtr/ns.c:448:\t\tserver_del(endpoint_id, node, srv-\u003eport, true);\nnet/qrtr/ns.c-449-\n--\nnet/qrtr/ns.c-465-\nnet/qrtr/ns.c:466:\t\t/* Bye will look as if it came from endpoint_id */\nnet/qrtr/ns.c:467:\t\tret = qrtr_ns_sendmsg(endpoint_id, \u0026sq, \u0026pkt);\nnet/qrtr/ns.c-468-\t\tif (ret \u003c 0 \u0026\u0026 ret != -ENODEV) {\n--\nnet/qrtr/ns.c-477-delete_node:\nnet/qrtr/ns.c:478:\tnode_erase(endpoint_id, from-\u003esq_node);\nnet/qrtr/ns.c-479-\n--\nnet/qrtr/ns.c-482-\nnet/qrtr/ns.c:483:static int ctrl_cmd_del_client(u32 endpoint_id, struct sockaddr_qrtr *from,\nnet/qrtr/ns.c-484-\t\t\t       unsigned int node_id, unsigned int port)\n--\nnet/qrtr/ns.c-521-\t */\nnet/qrtr/ns.c:522:\tnode = node_lookup(endpoint_id, node_id);\nnet/qrtr/ns.c-523-\tif (node)\nnet/qrtr/ns.c:524:\t\tserver_del(endpoint_id, node, port, false);\nnet/qrtr/ns.c-525-\n--\nnet/qrtr/ns.c-540-\nnet/qrtr/ns.c:541:\t\t/* Del Client will look as if it came from endpoint_id */\nnet/qrtr/ns.c:542:\t\tret = qrtr_ns_sendmsg(endpoint_id, \u0026sq, \u0026pkt);\nnet/qrtr/ns.c-543-\t\tif (ret \u003c 0 \u0026\u0026 ret != -ENODEV) {\n--\nnet/qrtr/ns.c-550-\nnet/qrtr/ns.c:551:static int ctrl_cmd_new_server(u32 endpoint_id, struct sockaddr_qrtr *from,\nnet/qrtr/ns.c-552-\t\t\t       unsigned int service, unsigned int instance,\n--\nnet/qrtr/ns.c-565-\nnet/qrtr/ns.c:566:\tsrv = server_add(endpoint_id, service, instance, node_id, port);\nnet/qrtr/ns.c-567-\tif (!srv) {\n--\nnet/qrtr/ns.c-589-\nnet/qrtr/ns.c:590:\t\tlookup_notify(endpoint_id, \u0026lookup-\u003esq, srv, true);\nnet/qrtr/ns.c-591-\t}\n--\nnet/qrtr/ns.c-595-\nnet/qrtr/ns.c:596:static int ctrl_cmd_del_server(u32 endpoint_id, struct sockaddr_qrtr *from,\nnet/qrtr/ns.c-597-\t\t\t       unsigned int service, unsigned int instance,\n--\nnet/qrtr/ns.c-611-\nnet/qrtr/ns.c:612:\tnode = node_lookup(endpoint_id, node_id);\nnet/qrtr/ns.c-613-\tif (!node)\n--\nnet/qrtr/ns.c-615-\nnet/qrtr/ns.c:616:\tserver_del(endpoint_id, node, port, true);\nnet/qrtr/ns.c-617-\n--\nnet/qrtr/ns.c-620-\nnet/qrtr/ns.c:621:static int ctrl_cmd_new_lookup(u32 endpoint_id, struct sockaddr_qrtr *from,\nnet/qrtr/ns.c-622-\t\t\t       unsigned int service, unsigned int instance)\n--\nnet/qrtr/ns.c-674-\nnet/qrtr/ns.c:675:static void ctrl_cmd_del_lookup(u32 endpoint_id, struct sockaddr_qrtr *from,\nnet/qrtr/ns.c-676-\t\t\t\tunsigned int service, unsigned int instance)\n--\nnet/qrtr/ns.c=699=static void qrtr_ns_worker(struct work_struct *work)\n--\nnet/qrtr/ns.c-719-\tfor (;;) {\nnet/qrtr/ns.c:720:\t\tu32 endpoint_id;\nnet/qrtr/ns.c-721-\n--\nnet/qrtr/ns.c-741-\nnet/qrtr/ns.c:742:\t\tret = qrtr_msg_get_endpoint(\u0026msg, \u0026endpoint_id);\nnet/qrtr/ns.c-743-\t\tif (ret \u003c 0) {\n--\nnet/qrtr/ns.c-760-\t\tcase QRTR_TYPE_HELLO:\nnet/qrtr/ns.c:761:\t\t\tret = ctrl_cmd_hello(endpoint_id, \u0026sq);\nnet/qrtr/ns.c-762-\t\t\tbreak;\nnet/qrtr/ns.c-763-\t\tcase QRTR_TYPE_BYE:\nnet/qrtr/ns.c:764:\t\t\tret = ctrl_cmd_bye(endpoint_id, \u0026sq);\nnet/qrtr/ns.c-765-\t\t\tbreak;\nnet/qrtr/ns.c-766-\t\tcase QRTR_TYPE_DEL_CLIENT:\nnet/qrtr/ns.c:767:\t\t\tret = ctrl_cmd_del_client(endpoint_id, \u0026sq,\nnet/qrtr/ns.c-768-\t\t\t\t\tle32_to_cpu(pkt-\u003eclient.node),\n--\nnet/qrtr/ns.c-771-\t\tcase QRTR_TYPE_NEW_SERVER:\nnet/qrtr/ns.c:772:\t\t\tret = ctrl_cmd_new_server(endpoint_id, \u0026sq,\nnet/qrtr/ns.c-773-\t\t\t\t\tle32_to_cpu(pkt-\u003eserver.service),\n--\nnet/qrtr/ns.c-778-\t\tcase QRTR_TYPE_DEL_SERVER:\nnet/qrtr/ns.c:779:\t\t\tret = ctrl_cmd_del_server(endpoint_id, \u0026sq,\nnet/qrtr/ns.c-780-\t\t\t\t\t le32_to_cpu(pkt-\u003eserver.service),\n--\nnet/qrtr/ns.c-789-\t\tcase QRTR_TYPE_NEW_LOOKUP:\nnet/qrtr/ns.c:790:\t\t\tret = ctrl_cmd_new_lookup(endpoint_id, \u0026sq,\nnet/qrtr/ns.c-791-\t\t\t\t\t le32_to_cpu(pkt-\u003eserver.service),\n--\nnet/qrtr/ns.c-794-\t\tcase QRTR_TYPE_DEL_LOOKUP:\nnet/qrtr/ns.c:795:\t\t\tctrl_cmd_del_lookup(endpoint_id, \u0026sq,\nnet/qrtr/ns.c-796-\t\t\t\t    le32_to_cpu(pkt-\u003eserver.service),\n"
}

53/3 2026/09/15 06:26 llm kmsan-evaluator
0m Model:
gemini-3.8-flash

Args:
null

Results:
null

Tokens:
							input: 51306
							output: 31
							thoughts: 639
						

Thoughts:
**My Investigation into the `srv->endpoint_id` Variable**

Okay, so I started with the observation that `srv->endpoint_id` seems unused.  I immediately thought, "Hang on, is it truly never read anywhere?" I need to verify that. My first thought was to do a quick search in the code base, which confirmed my suspicion - it's never *directly* read.

Then, a thought struck me: Let's check `net/qrtr/mhi.c`. I recall that sysfs attributes can sometimes touch these kinds of things. Sure enough, there's `endpoint_show`: `sprintf(buf, "%u\n", qdev->ep.id);`. The code *does* read the endpoint ID via sysfs. This uses `qdev->ep.id`, which is a `u32` initialized during endpoint registration via `qrtr_endpoint_register`. At first, I was worried about uninitialized data exposure, but sysfs formatting looked standard, so I didn't think there was a problem.

Now, wait a second.  I need to dig deeper. I remembered that `qrtr_msg_get_endpoint` existed. I need to be sure. I've got it:
```c
int qrtr_msg_get_endpoint(struct msghdr *msg, u32 *out_endpoint_id)
{
	struct cmsghdr *cmsg;
	u32 endpoint_id = 0;

	for_each_cmsghdr(cmsg, msg) {
		if (!CMSG_OK(msg, cmsg))
			return -EINVAL;

		if (cmsg->cmsg_level != SOL_QRTR)
			continue;

		if (cmsg->cmsg_type != QRTR_ENDPOINT)
			return -EINVAL;

		if (cmsg->cmsg_len < CMSG_LEN(sizeof(u32)))
			return -EINVAL;

		/* Endpoint ids start at 1 */
		endpoint_id = *(u32 *)CMSG_DATA(cmsg);
		if (!endpoint_id)
			return -EINVAL;
	}

	if (out_endpoint_id)
		*out_endpoint_id = endpoint_id;

	return 0;
}
```

Okay, so that's where things get interesting! Can userspace craft a `msghdr` with a specific endpoint ID and pass it via `sendmsg`? The answer is yes! In `qrtr_sendmsg`, it calls `qrtr_msg_get_endpoint`. That's the link. So the real question is how does the kernel handle the `msg_control` part of a `sendmsg` call from userspace?

I need to dive into the kernel sources. It looks like it's a good idea to check `__sys_sendmsg` or `___sys_sendmsg`. Does the `sendmsg` syscall actually copy `msg_control` from userspace memory into kernel memory? Yes! `___sys_sendmsg` is the one. I see it calls `___sys_sendmsg` -> `copy_msghdr_from_user` -> `__copy_msghdr_from_user`, which suggests a copy. But I need to verify how that copy works. Is it allocated with `kmalloc`, or something else, and could that present a problem? I need to check the kernel sources, or this might be a vulnerability!



54/3 2026/09/15 06:26 tool grepper
0m Args:
{
  "Expression": "int ___sys_sendmsg",
  "PathPrefix": "net/socket.c"
}

Results:
{
  "Output": "net/socket.c=2732=static int sendmsg_copy_msghdr(struct msghdr *msg,\n--\nnet/socket.c-2751-\nnet/socket.c:2752:static int ___sys_sendmsg(struct socket *sock, struct user_msghdr __user *msg,\nnet/socket.c-2753-\t\t\t struct msghdr *msg_sys, unsigned int flags,\n"
}

55/3 2026/09/15 06:26 llm kmsan-evaluator
0m Model:
gemini-3.8-flash

Args:
null

Results:
null

Tokens:
							input: 52858
							output: 34
							thoughts: 30
						

Thoughts:
Here's my take on the process, considering my expertise:

**Diving into `sys_sendmsg` and `sendmsg_copy_msghdr`**

Okay, time to get my hands dirty. I'm going to jump into the `net/socket.c` file and dissect the `___sys_sendmsg` and `sendmsg_copy_msghdr` functions. I'm already anticipating some interesting interactions here. I want to see precisely how the kernel handles the low-level mechanics of sending messages, specifically the *`msghdr`* structure, which is critical for describing the message's destination, control data, and ancillary data. I'm expecting to find out how the kernel manages the copying of that header information into kernel space from user space, because of the inherent security concerns. It's the `sendmsg_copy_msghdr` function that will make or break the design.

I'm thinking about the potential performance implications too. Is this optimized for common socket types and use cases? Are there any potential areas for improvement? I'll be particularly interested to see if there are any subtle inefficiencies or opportunities for zero-copy techniques, or if there is any legacy code still in there. Given my background, I'll be looking for nuances around memory allocation, data validation, and potential race conditions within the copying process or when sharing the `msghdr`. I need to get to the nuts and bolts of what goes on under the hood.



56/3 2026/09/15 06:26 tool read-file
0m Args:
{
  "File": "net/socket.c",
  "FirstLine": 2730,
  "LineCount": 40
}

Results:
{
  "Contents": "2730:\t}\n2731:\t\n2732:\tstatic int sendmsg_copy_msghdr(struct msghdr *msg,\n2733:\t\t\t\t       struct user_msghdr __user *umsg, unsigned flags,\n2734:\t\t\t\t       struct iovec **iov)\n2735:\t{\n2736:\t\tint err;\n2737:\t\n2738:\t\tif (flags \u0026 MSG_CMSG_COMPAT) {\n2739:\t\t\tstruct compat_msghdr __user *msg_compat;\n2740:\t\n2741:\t\t\tmsg_compat = (struct compat_msghdr __user *) umsg;\n2742:\t\t\terr = get_compat_msghdr(msg, msg_compat, NULL, iov);\n2743:\t\t} else {\n2744:\t\t\terr = copy_msghdr_from_user(msg, umsg, NULL, iov);\n2745:\t\t}\n2746:\t\tif (err \u003c 0)\n2747:\t\t\treturn err;\n2748:\t\n2749:\t\treturn 0;\n2750:\t}\n2751:\t\n2752:\tstatic int ___sys_sendmsg(struct socket *sock, struct user_msghdr __user *msg,\n2753:\t\t\t\t struct msghdr *msg_sys, unsigned int flags,\n2754:\t\t\t\t struct used_address *used_address,\n2755:\t\t\t\t unsigned int allowed_msghdr_flags)\n2756:\t{\n2757:\t\tstruct sockaddr_storage address;\n2758:\t\tstruct iovec iovstack[UIO_FASTIOV], *iov = iovstack;\n2759:\t\tssize_t err;\n2760:\t\n2761:\t\tmsg_sys-\u003emsg_name = \u0026address;\n2762:\t\n2763:\t\terr = sendmsg_copy_msghdr(msg_sys, msg, flags, \u0026iov);\n2764:\t\tif (err \u003c 0)\n2765:\t\t\treturn err;\n2766:\t\n2767:\t\terr = ____sys_sendmsg(sock, msg_sys, flags, used_address,\n2768:\t\t\t\t\tallowed_msghdr_flags);\n2769:\t\tkfree(iov);\n"
}

57/3 2026/09/15 06:26 llm kmsan-evaluator
0m Model:
gemini-3.8-flash

Args:
null

Results:
null

Tokens:
							input: 53845
							output: 34
							thoughts: 35
						

Thoughts:
Okay, here's my interpretation of that thought process, assuming I'm deep in the weeds of network programming:

**Deconstructing `____sys_sendmsg`**

Alright, I need to understand what `____sys_sendmsg` is actually *doing*. Time to dive into the kernel source. Specifically, I'm zeroing in on `net/socket.c`. I know that's the likely location for socket-related system call implementations. Now, let's see, the context suggests the relevant code should be in the `sendmsg` implementation. If I recall correctly, the `____sys_` prefix indicates a system call wrapper.  Okay, so lines 2700-2730 in `net/socket.c` is the target, that's where the magic probably happens. Hopefully, the code comments are helpful and the logic is straightforward. Let's get cracking and get the pieces together.



58/3 2026/09/15 06:26 tool read-file
0m Args:
{
  "File": "net/socket.c",
  "FirstLine": 2700,
  "LineCount": 35
}

Results:
{
  "Contents": "2700:\t\t/*\n2701:\t\t * If this is sendmmsg() and current destination address is same as\n2702:\t\t * previously succeeded address, omit asking LSM's decision.\n2703:\t\t * used_address-\u003ename_len is initialized to UINT_MAX so that the first\n2704:\t\t * destination address never matches.\n2705:\t\t */\n2706:\t\tif (used_address \u0026\u0026 msg_sys-\u003emsg_name \u0026\u0026\n2707:\t\t    used_address-\u003ename_len == msg_sys-\u003emsg_namelen \u0026\u0026\n2708:\t\t    !memcmp(\u0026used_address-\u003ename, msg_sys-\u003emsg_name,\n2709:\t\t\t    used_address-\u003ename_len)) {\n2710:\t\t\terr = sock_sendmsg_nosec(sock, msg_sys);\n2711:\t\t\tgoto out_freectl;\n2712:\t\t}\n2713:\t\terr = __sock_sendmsg(sock, msg_sys);\n2714:\t\t/*\n2715:\t\t * If this is sendmmsg() and sending to current destination address was\n2716:\t\t * successful, remember it.\n2717:\t\t */\n2718:\t\tif (used_address \u0026\u0026 err \u003e= 0) {\n2719:\t\t\tused_address-\u003ename_len = msg_sys-\u003emsg_namelen;\n2720:\t\t\tif (msg_sys-\u003emsg_name)\n2721:\t\t\t\tmemcpy(\u0026used_address-\u003ename, msg_sys-\u003emsg_name,\n2722:\t\t\t\t       used_address-\u003ename_len);\n2723:\t\t}\n2724:\t\n2725:\tout_freectl:\n2726:\t\tif (ctl_buf != ctl)\n2727:\t\t\tsock_kfree_s(sock-\u003esk, ctl_buf, ctl_len);\n2728:\tout:\n2729:\t\treturn err;\n2730:\t}\n2731:\t\n2732:\tstatic int sendmsg_copy_msghdr(struct msghdr *msg,\n2733:\t\t\t\t       struct user_msghdr __user *umsg, unsigned flags,\n2734:\t\t\t\t       struct iovec **iov)\n"
}

59/3 2026/09/15 06:26 llm kmsan-evaluator
0m Model:
gemini-3.8-flash

Args:
null

Results:
null

Tokens:
							input: 54691
							output: 34
							thoughts: 26
						

Thoughts:
Here's my summary, as though I'm thinking through this process:

**Diving into the `ctl_buf` Copy**

Alright, let's zoom in on lines 2660-2700. My immediate focus is on how `ctl_buf` is being handled. This is where user-provided data is coming into play, and that always triggers my security alarms. I need to understand *exactly* how this data is copied from user space. What are the checks being performed? Are we validating the size of the buffer? Is there any chance of a buffer overflow? Are there any potential vulnerabilities related to uninitialized memory or incorrect offsets? I'm going to carefully scrutinize the memory copy functions used here – `copy_from_user` or whatever we're using – and triple-check the error handling. I want to make sure we're not vulnerable to any kind of malicious input crafted to overwrite sensitive data or cause a crash. This section is a prime target for fuzzing, I'm thinking. I'll need to develop some test cases that explore various sizes and contents of the `ctl_buf` to make sure nothing slips through the cracks.



60/3 2026/09/15 06:27 tool read-file
0m Args:
{
  "File": "net/socket.c",
  "FirstLine": 2660,
  "LineCount": 40
}

Results:
{
  "Contents": "2660:\t\tunsigned char ctl[sizeof(struct cmsghdr) + 20]\n2661:\t\t\t\t\t__aligned(sizeof(__kernel_size_t));\n2662:\t\t/* 20 is size of ipv6_pktinfo */\n2663:\t\tunsigned char *ctl_buf = ctl;\n2664:\t\tint ctl_len;\n2665:\t\tssize_t err;\n2666:\t\n2667:\t\terr = -ENOBUFS;\n2668:\t\n2669:\t\tif (msg_sys-\u003emsg_controllen \u003e INT_MAX)\n2670:\t\t\tgoto out;\n2671:\t\tflags |= (msg_sys-\u003emsg_flags \u0026 allowed_msghdr_flags);\n2672:\t\tctl_len = msg_sys-\u003emsg_controllen;\n2673:\t\tif ((MSG_CMSG_COMPAT \u0026 flags) \u0026\u0026 ctl_len) {\n2674:\t\t\terr =\n2675:\t\t\t    cmsghdr_from_user_compat_to_kern(msg_sys, sock-\u003esk, ctl,\n2676:\t\t\t\t\t\t\t     sizeof(ctl));\n2677:\t\t\tif (err)\n2678:\t\t\t\tgoto out;\n2679:\t\t\tctl_buf = msg_sys-\u003emsg_control;\n2680:\t\t\tctl_len = msg_sys-\u003emsg_controllen;\n2681:\t\t} else if (ctl_len) {\n2682:\t\t\tBUILD_BUG_ON(sizeof(struct cmsghdr) !=\n2683:\t\t\t\t     CMSG_ALIGN(sizeof(struct cmsghdr)));\n2684:\t\t\tif (ctl_len \u003e sizeof(ctl)) {\n2685:\t\t\t\tctl_buf = sock_kmalloc(sock-\u003esk, ctl_len, GFP_KERNEL);\n2686:\t\t\t\tif (ctl_buf == NULL)\n2687:\t\t\t\t\tgoto out;\n2688:\t\t\t}\n2689:\t\t\terr = -EFAULT;\n2690:\t\t\tif (copy_from_user(ctl_buf, msg_sys-\u003emsg_control_user, ctl_len))\n2691:\t\t\t\tgoto out_freectl;\n2692:\t\t\tmsg_sys-\u003emsg_control = ctl_buf;\n2693:\t\t\tmsg_sys-\u003emsg_control_is_user = false;\n2694:\t\t}\n2695:\t\tflags \u0026= ~MSG_INTERNAL_SENDMSG_FLAGS;\n2696:\t\tmsg_sys-\u003emsg_flags = flags;\n2697:\t\n2698:\t\tif (sock-\u003efile-\u003ef_flags \u0026 O_NONBLOCK)\n2699:\t\t\tmsg_sys-\u003emsg_flags |= MSG_DONTWAIT;\n"
}

61/3 2026/09/15 06:27 llm kmsan-evaluator
0m Model:
gemini-3.8-flash

Args:
null

Results:
null

Tokens:
							input: 55696
							output: 30
							thoughts: 2065
						

Thoughts:
**Analysis of Potential Uninitialized Memory Reads in QRTR Driver**

Okay, let's break this down. My initial concern was centered around potential uninitialized memory reads within the QRTR driver, particularly in areas dealing with control messages, socket options, and radix tree lookups.

First, the control buffer (`ctl_buf`) and `qrtr_msg_get_endpoint` were examined. It appears that the control buffer is fully copied from user space and marked as initialized by KMSAN before `qrtr_msg_get_endpoint` parses it. The key here is the case where `msg->msg_controllen` is zero. The `for_each_cmsghdr` macro handles this gracefully, returning `NULL` when the control message length is zero, avoiding a read from an uninitialized buffer and correctly setting `endpoint_id` to zero. This is good.  Compatibility mode (`MSG_CMSG_COMPAT`) is handled via `cmsghdr_from_user_compat_to_kern` and `put_cmsg_compat`, ensuring that the correct data is copied for 32-bit applications running on a 64-bit kernel. This is fine too.

Next, I looked at `qrtr_setsockopt`. The possibility of `optlen` being smaller than the size of the value being copied was investigated. However, I realized that if `optlen` is smaller than the expected size, the `copy_from_sockptr` function is *not* executed. The `val` variable is initialized to 0, so the `assign_bit` and `WRITE_ONCE` operations use an initialized value, avoiding uninitialized memory access. That's a solid defense.

`qrtr_getsockopt` was the next focus. Here, the case where `optname` is unrecognized was important.  If it's not one of the recognized options, the `rc` is set to -ENOPROTOOPT and the function returns without copying anything to user space.  When `optname` is valid, `val` is properly initialized *before* the `copy_to_user`, and we set the `len` to the appropriate value, so the entire `val` is safely copied, thus avoiding information leak.  This part looks fine too.

Finally, I analyzed `qrtr_node_release` and the radix tree lookups. The use of a radix tree iteration process was examined. The code iterates through the radix tree and checks `*slot` and `*slot2` for the node we are trying to release. The potential for reading uninitialized memory here depends on the initialization of the helpers and nodes in the radix tree.  The code accesses `helper->added` and the `helper->nodes` radix tree. It appeared that `helper0` is statically initialized and that `ep->helper` (if used) is part of a `qrtr_endpoint` struct. After a quick search, it appears that `qrtr_endpoint` structs are allocated via `qrtr_endpoint_register`. Therefore, any `ep->helper` would be properly initialized during the endpoint registration.  It now appears that the radix tree entries are either initialized by the static `helper0` or the endpoints, eliminating the possibility of uninitialized reads.

In conclusion, after this detailed review, it seems that there are no uninitialized memory reads in these sections of the QRTR driver. The code consistently handles edge cases, initialization, and compatibility modes in a way that prevents such vulnerabilities. The logic is sound, and the design is robust.



62/3 2026/09/15 06:27 tool grepper
0m Args:
{
  "Expression": "qrtr_endpoint_register",
  "PathPrefix": "net/qrtr"
}

Results:
{
  "Output": "net/qrtr/af_qrtr.c=729=static struct sk_buff *qrtr_alloc_ctrl_packet(struct qrtr_ctrl_pkt **pkt,\n--\nnet/qrtr/af_qrtr.c-745-/**\nnet/qrtr/af_qrtr.c:746: * qrtr_endpoint_register() - register a new endpoint\nnet/qrtr/af_qrtr.c-747- * @ep: endpoint to register\n--\nnet/qrtr/af_qrtr.c-752- */\nnet/qrtr/af_qrtr.c:753:int qrtr_endpoint_register(struct qrtr_endpoint *ep, unsigned int nid)\nnet/qrtr/af_qrtr.c-754-{\n--\nnet/qrtr/af_qrtr.c-797-}\nnet/qrtr/af_qrtr.c:798:EXPORT_SYMBOL_GPL(qrtr_endpoint_register);\nnet/qrtr/af_qrtr.c-799-\n--\nnet/qrtr/mhi.c=119=static int qcom_mhi_qrtr_probe(struct mhi_device *mhi_dev,\n--\nnet/qrtr/mhi.c-139-\nnet/qrtr/mhi.c:140:\trc = qrtr_endpoint_register(\u0026qdev-\u003eep, QRTR_EP_NID_AUTO);\nnet/qrtr/mhi.c-141-\tif (rc)\n--\nnet/qrtr/qrtr.h=29=struct qrtr_endpoint {\n--\nnet/qrtr/qrtr.h-36-\nnet/qrtr/qrtr.h:37:int qrtr_endpoint_register(struct qrtr_endpoint *ep, unsigned int nid);\nnet/qrtr/qrtr.h-38-\n--\nnet/qrtr/smd.c=59=static int qcom_smd_qrtr_probe(struct rpmsg_device *rpdev)\n--\nnet/qrtr/smd.c-71-\nnet/qrtr/smd.c:72:\trc = qrtr_endpoint_register(\u0026qdev-\u003eep, QRTR_EP_NID_AUTO);\nnet/qrtr/smd.c-73-\tif (rc)\n--\nnet/qrtr/tun.c=31=static int qrtr_tun_open(struct inode *inode, struct file *filp)\n--\nnet/qrtr/tun.c-46-\nnet/qrtr/tun.c:47:\tret = qrtr_endpoint_register(\u0026tun-\u003eep, QRTR_EP_NID_AUTO);\nnet/qrtr/tun.c-48-\tif (ret)\n"
}

63/3 2026/09/15 06:27 llm kmsan-evaluator
0m Model:
gemini-3.8-flash

Args:
null

Results:
null

Tokens:
							input: 59234
							output: 28
							thoughts: 20
						

Thoughts:
Here's my attempt at summarizing the thought process, tailored for an expert audience:

**Investigating QRTR Endpoint Registration Callers**

Okay, so I need to understand the usage of `qrtr_endpoint_register`. I'm going to start by looking for other places in the kernel code where this function is called. The most logical place to begin that search is within the `drivers/` directory, as it's the usual location for device drivers and QRTR is often used for inter-processor communication related to devices or sub-systems. This should give me a good overview of how the registration mechanism is being used across the board. Hopefully, this approach will quickly reveal how and where this endpoint registration is being initiated within the system. Let's see what we can find!



64/3 2026/09/15 06:27 tool grepper
0m Error:
no matches

Args:
{
  "Expression": "qrtr_endpoint_register",
  "PathPrefix": "drivers/"
}

Results:
{
  "error": "no matches"
}

65/3 2026/09/15 06:27 llm kmsan-evaluator
0m Model:
gemini-3.8-flash

Args:
null

Results:
null

Tokens:
							input: 59459
							output: 28
							thoughts: 21
						

Thoughts:
**Investigating Potential `qrtr_endpoint_register` Callers**

Okay, so I need to see what else within the `net/` directory might be using the `qrtr_endpoint_register` function. Seems like a good starting point for tracing down its purpose and impact. Let's dig in and see if there are any other direct calls I should be aware of. Gotta make sure I'm not missing anything crucial here.



66/3 2026/09/15 06:27 tool grepper
0m Args:
{
  "Expression": "qrtr_endpoint_register",
  "PathPrefix": "net/"
}

Results:
{
  "Output": "net/qrtr/af_qrtr.c=729=static struct sk_buff *qrtr_alloc_ctrl_packet(struct qrtr_ctrl_pkt **pkt,\n--\nnet/qrtr/af_qrtr.c-745-/**\nnet/qrtr/af_qrtr.c:746: * qrtr_endpoint_register() - register a new endpoint\nnet/qrtr/af_qrtr.c-747- * @ep: endpoint to register\n--\nnet/qrtr/af_qrtr.c-752- */\nnet/qrtr/af_qrtr.c:753:int qrtr_endpoint_register(struct qrtr_endpoint *ep, unsigned int nid)\nnet/qrtr/af_qrtr.c-754-{\n--\nnet/qrtr/af_qrtr.c-797-}\nnet/qrtr/af_qrtr.c:798:EXPORT_SYMBOL_GPL(qrtr_endpoint_register);\nnet/qrtr/af_qrtr.c-799-\n--\nnet/qrtr/mhi.c=119=static int qcom_mhi_qrtr_probe(struct mhi_device *mhi_dev,\n--\nnet/qrtr/mhi.c-139-\nnet/qrtr/mhi.c:140:\trc = qrtr_endpoint_register(\u0026qdev-\u003eep, QRTR_EP_NID_AUTO);\nnet/qrtr/mhi.c-141-\tif (rc)\n--\nnet/qrtr/qrtr.h=29=struct qrtr_endpoint {\n--\nnet/qrtr/qrtr.h-36-\nnet/qrtr/qrtr.h:37:int qrtr_endpoint_register(struct qrtr_endpoint *ep, unsigned int nid);\nnet/qrtr/qrtr.h-38-\n--\nnet/qrtr/smd.c=59=static int qcom_smd_qrtr_probe(struct rpmsg_device *rpdev)\n--\nnet/qrtr/smd.c-71-\nnet/qrtr/smd.c:72:\trc = qrtr_endpoint_register(\u0026qdev-\u003eep, QRTR_EP_NID_AUTO);\nnet/qrtr/smd.c-73-\tif (rc)\n--\nnet/qrtr/tun.c=31=static int qrtr_tun_open(struct inode *inode, struct file *filp)\n--\nnet/qrtr/tun.c-46-\nnet/qrtr/tun.c:47:\tret = qrtr_endpoint_register(\u0026tun-\u003eep, QRTR_EP_NID_AUTO);\nnet/qrtr/tun.c-48-\tif (ret)\n"
}

67/3 2026/09/15 06:27 llm kmsan-evaluator
0m Model:
gemini-3.8-flash

Args:
null

Results:
null

Tokens:
							input: 60291
							output: 35
							thoughts: 52
						

Thoughts:
Okay, let's dive in.

**Analyzing the Potential Attack Surface: QRTR-TUN**

Right, so, the syzkaller fuzzing infrastructure flagged `/dev/qrtr-tun` as a potential point of interest. That immediately tells me `net/qrtr/tun.c` is the likely target. Time to start digging into the code. My primary focus right now is figuring out how the `tun` device is *actually* allocated within the QRTR subsystem, specifically inside the `qrtr_tun_open` function. That's where the connection starts, where the device is brought into existence. Understanding *that* allocation process is crucial for identifying any potential vulnerabilities. Let's see what the initial setup looks like and trace the execution path.



68/3 2026/09/15 06:27 tool read-file
0m Args:
{
  "File": "net/qrtr/tun.c",
  "FirstLine": 30,
  "LineCount": 30
}

Results:
{
  "Contents": "  30:\t\n  31:\tstatic int qrtr_tun_open(struct inode *inode, struct file *filp)\n  32:\t{\n  33:\t\tstruct qrtr_tun *tun;\n  34:\t\tint ret;\n  35:\t\n  36:\t\ttun = kzalloc_obj(*tun);\n  37:\t\tif (!tun)\n  38:\t\t\treturn -ENOMEM;\n  39:\t\n  40:\t\tskb_queue_head_init(\u0026tun-\u003equeue);\n  41:\t\tinit_waitqueue_head(\u0026tun-\u003ereadq);\n  42:\t\n  43:\t\ttun-\u003eep.xmit = qrtr_tun_send;\n  44:\t\n  45:\t\tfilp-\u003eprivate_data = tun;\n  46:\t\n  47:\t\tret = qrtr_endpoint_register(\u0026tun-\u003eep, QRTR_EP_NID_AUTO);\n  48:\t\tif (ret)\n  49:\t\t\tgoto out;\n  50:\t\n  51:\t\treturn 0;\n  52:\t\n  53:\tout:\n  54:\t\tfilp-\u003eprivate_data = NULL;\n  55:\t\tkfree(tun);\n  56:\t\treturn ret;\n  57:\t}\n  58:\t\n  59:\tstatic ssize_t qrtr_tun_read_iter(struct kiocb *iocb, struct iov_iter *to)\n"
}

69/3 2026/09/15 06:27 llm kmsan-evaluator
2m Model:
gemini-3.8-flash

Args:
null

Results:
null

Tokens:
							input: 60914
							output: 39
							thoughts: 1566
						

Thoughts:
**Analysis of QRTR Endpoint Registration and Unregistration**

Okay, let's break this down. First, initializing `tun = kzalloc_obj(*tun)` in `qrtr_endpoint_register` looks standard enough. The registration process sets up `ep->node`, `ep->id`, and `ep->helper.added`. The explicit initialization of the `helper` structure is good.

But wait, what's going on with `qrtr_endpoint_unregister`? I see some interesting operations within the radix trees. The code iterates through `qrtr_nodes` and, within that, `helper->nodes`. It constructs a "BYE" control packet. Crucially, I see a call to `qrtr_alloc_ctrl_packet`, and a zeroing happens in `*pkt = skb_put_zero(skb, pkt_len);` ensuring the packet is initialized.

Now, a critical point: `src.sq_node = iter.index;`. I need to understand what `src` is initialized to. Aha, `src` is a `sockaddr_qrtr` structure, and crucially, `src.sq_node` is assigned `iter.index`. Let's clarify what `iter.index` represents in the context of the radix trees. Within `qrtr_nodes`, the key is `0` (for helper0) or `ep->id`, while for `helper->nodes`, the keys are `nid`.

Previously, `qrtr_nodes` was indexed by `nid`, but now, I see that `qrtr_nodes` is indexed by `endpoint_id`, while `helper->nodes` is indexed by `nid`. This is a significant change! The line `src.sq_node = iter.index` *now* sets `src.sq_node` to `endpoint_id` instead of `nid` of a source node for `qrtr_endpoint_unregister`. That's a logic bug in `qrtr_endpoint_unregister`! It's not an uninitialized memory bug since `iter.index` is an integer. However, it *is* a logic error, a functional bug. It will result in an incorrect source node identifier in the "BYE" packet sent to remote peers. This won't cause KASAN or KMSAN issues because it's not uninitialized memory access; it will, however, result in incorrect packet processing on the other side.

Now, let's consider `qrtr_node_assign`. I have to consider the case where `node->ep` is accessed and think about the cases where that may be `NULL`. But wait! In `qrtr_endpoint_register`: `node->ep = ep;` is done *before* `qrtr_node_assign` is called. So it is not `NULL` there.

Now, what about `qrtr_endpoint_post`? Inside this function, `qrtr_node_assign(node, cb->src_node);` is called. That means `node->ep` is assigned before. Now I need to see how the parameter `node` is passed in `qrtr_endpoint_post`. Looking at the code around line 580:



70/3 2026/09/15 06:30 tool read-file
0m Args:
{
  "File": "net/qrtr/af_qrtr.c",
  "FirstLine": 580,
  "LineCount": 35
}

Results:
{
  "Contents": " 580:\t * Return: 0 on success; negative error code on failure\n 581:\t */\n 582:\tint qrtr_endpoint_post(struct qrtr_endpoint *ep, const void *data, size_t len)\n 583:\t{\n 584:\t\tstruct qrtr_node *node = ep-\u003enode;\n 585:\t\tconst struct qrtr_hdr_v1 *v1;\n 586:\t\tconst struct qrtr_hdr_v2 *v2;\n 587:\t\tstruct qrtr_sock *ipc;\n 588:\t\tstruct sk_buff *skb;\n 589:\t\tstruct qrtr_cb *cb;\n 590:\t\tsize_t size;\n 591:\t\tunsigned int ver;\n 592:\t\tsize_t hdrlen;\n 593:\t\tint ret = -EINVAL;\n 594:\t\n 595:\t\tif (len == 0 || len \u0026 3)\n 596:\t\t\treturn -EINVAL;\n 597:\t\n 598:\t\tskb = __netdev_alloc_skb(NULL, len, GFP_ATOMIC | __GFP_NOWARN);\n 599:\t\tif (!skb)\n 600:\t\t\treturn -ENOMEM;\n 601:\t\n 602:\t\tcb = (struct qrtr_cb *)skb-\u003ecb;\n 603:\t\n 604:\t\t/* Version field in v1 is little endian, so this works for both cases */\n 605:\t\tver = *(u8*)data;\n 606:\t\n 607:\t\tswitch (ver) {\n 608:\t\tcase QRTR_PROTO_VER_1:\n 609:\t\t\tif (len \u003c sizeof(*v1))\n 610:\t\t\t\tgoto err;\n 611:\t\t\tv1 = data;\n 612:\t\t\thdrlen = sizeof(*v1);\n 613:\t\n 614:\t\t\tcb-\u003etype = le32_to_cpu(v1-\u003etype);\n"
}

71/3 2026/09/15 06:30 llm kmsan-evaluator
0m Model:
gemini-3.8-flash

Args:
null

Results:
null

Tokens:
							input: 63740
							output: 36
							thoughts: 676
						

Thoughts:
**My Immediate Concerns Regarding QRTR Packet Initialization**

Okay, so I'm looking at how QRTR messages are constructed and sent. I see that `struct qrtr_node *node = ep->node;` and then `qrtr_node_assign(node, cb->src_node);` implies a relationship between endpoints and nodes, where the endpoint's node is assigned. That's fine.

But now, I'm diving into the `net/qrtr/ns.c` code to see how announcements and notifications work. I notice a pattern in `service_announce_new`, `service_announce_del`, and `lookup_notify`. They all zero out the packet structure `pkt` with `memset(&pkt, 0, sizeof(pkt));` *before* populating it with the relevant data. This is good practice. Also, `say_hello` also zero-initializes the packet. It's a clear and safe way to ensure the packet has a known state before the important fields are set.

However, something *really* strikes me as odd. I've got to ask... what's happening with `ctrl_cmd_bye`? I see it uses `qrtr_ns_sendmsg` to send a packet, but where is that `pkt` struct initialized?! Is it also zeroed beforehand? **I need to read `ctrl_cmd_bye` carefully.** I'm going to scan the entire function to make *absolutely* sure that this packet is initialized correctly, or else we're looking at a potential security vulnerability if garbage data is sent over the network.



72/3 2026/09/15 06:30 tool read-file
0m Args:
{
  "File": "net/qrtr/ns.c",
  "FirstLine": 430,
  "LineCount": 55
}

Results:
{
  "Contents": " 430:\t}\n 431:\t\n 432:\tstatic int ctrl_cmd_bye(u32 endpoint_id, struct sockaddr_qrtr *from)\n 433:\t{\n 434:\t\tstruct qrtr_node *local_node;\n 435:\t\tstruct qrtr_ctrl_pkt pkt;\n 436:\t\tstruct qrtr_server *srv;\n 437:\t\tstruct sockaddr_qrtr sq;\n 438:\t\tstruct qrtr_node *node;\n 439:\t\tunsigned long index;\n 440:\t\tint ret = 0;\n 441:\t\n 442:\t\tnode = node_get(endpoint_id, from-\u003esq_node);\n 443:\t\tif (!node)\n 444:\t\t\treturn 0;\n 445:\t\n 446:\t\t/* Advertise removal of this client to all servers of remote node */\n 447:\t\txa_for_each(\u0026node-\u003eservers, index, srv)\n 448:\t\t\tserver_del(endpoint_id, node, srv-\u003eport, true);\n 449:\t\n 450:\t\t/* Advertise the removal of this client to all local servers */\n 451:\t\tlocal_node = node_get(qrtr_ns.local_node, qrtr_ns.local_node);\n 452:\t\tif (!local_node) {\n 453:\t\t\tret = 0;\n 454:\t\t\tgoto delete_node;\n 455:\t\t}\n 456:\t\n 457:\t\tmemset(\u0026pkt, 0, sizeof(pkt));\n 458:\t\tpkt.cmd = cpu_to_le32(QRTR_TYPE_BYE);\n 459:\t\tpkt.client.node = cpu_to_le32(from-\u003esq_node);\n 460:\t\n 461:\t\txa_for_each(\u0026local_node-\u003eservers, index, srv) {\n 462:\t\t\tsq.sq_family = AF_QIPCRTR;\n 463:\t\t\tsq.sq_node = srv-\u003enode;\n 464:\t\t\tsq.sq_port = srv-\u003eport;\n 465:\t\n 466:\t\t\t/* Bye will look as if it came from endpoint_id */\n 467:\t\t\tret = qrtr_ns_sendmsg(endpoint_id, \u0026sq, \u0026pkt);\n 468:\t\t\tif (ret \u003c 0 \u0026\u0026 ret != -ENODEV) {\n 469:\t\t\t\tpr_err(\"failed to send bye cmd\\n\");\n 470:\t\t\t\tgoto delete_node;\n 471:\t\t\t}\n 472:\t\t}\n 473:\t\n 474:\t\t/* Ignore -ENODEV */\n 475:\t\tret = 0;\n 476:\t\n 477:\tdelete_node:\n 478:\t\tnode_erase(endpoint_id, from-\u003esq_node);\n 479:\t\n 480:\t\treturn ret;\n 481:\t}\n 482:\t\n 483:\tstatic int ctrl_cmd_del_client(u32 endpoint_id, struct sockaddr_qrtr *from,\n 484:\t\t\t\t       unsigned int node_id, unsigned int port)\n"
}

73/3 2026/09/15 06:30 llm kmsan-evaluator
0m Model:
gemini-3.8-flash

Args:
null

Results:
null

Tokens:
							input: 65635
							output: 36
							thoughts: 67
						

Thoughts:
**Checking for Data Initialization**

Okay, so I see `memset(&pkt, 0, sizeof(pkt));` used in `ctrl_cmd_bye` on line 457. This is standard practice, obviously, to initialize the packet buffer. Now, a similar function is `ctrl_cmd_del_client`. I need to ensure the packet buffer is also initialized there. Considering the potential for security vulnerabilities if data isn't properly cleared, I'm going to quickly check the code block for `ctrl_cmd_del_client` in `net/qrtr/ns.c` between lines 483 and 550. Let's make sure nothing slips through the cracks. It's a fundamental part of robust network code.



74/3 2026/09/15 06:30 tool read-file
0m Args:
{
  "File": "net/qrtr/ns.c",
  "FirstLine": 483,
  "LineCount": 68
}

Results:
{
  "Contents": " 483:\tstatic int ctrl_cmd_del_client(u32 endpoint_id, struct sockaddr_qrtr *from,\n 484:\t\t\t\t       unsigned int node_id, unsigned int port)\n 485:\t{\n 486:\t\tstruct qrtr_node *local_node;\n 487:\t\tstruct qrtr_lookup *lookup;\n 488:\t\tstruct qrtr_ctrl_pkt pkt;\n 489:\t\tstruct qrtr_server *srv;\n 490:\t\tstruct sockaddr_qrtr sq;\n 491:\t\tstruct qrtr_node *node;\n 492:\t\tstruct list_head *tmp;\n 493:\t\tstruct list_head *li;\n 494:\t\tunsigned long index;\n 495:\t\tint ret;\n 496:\t\n 497:\t\t/* Don't accept spoofed messages */\n 498:\t\tif (from-\u003esq_node != node_id)\n 499:\t\t\treturn -EINVAL;\n 500:\t\n 501:\t\t/* Local DEL_CLIENT messages comes from the port being closed */\n 502:\t\tif (from-\u003esq_node == qrtr_ns.local_node \u0026\u0026 from-\u003esq_port != port)\n 503:\t\t\treturn -EINVAL;\n 504:\t\n 505:\t\t/* Remove any lookups by this client */\n 506:\t\tlist_for_each_safe(li, tmp, \u0026qrtr_ns.lookups) {\n 507:\t\t\tlookup = container_of(li, struct qrtr_lookup, li);\n 508:\t\t\tif (lookup-\u003esq.sq_node != node_id)\n 509:\t\t\t\tcontinue;\n 510:\t\t\tif (lookup-\u003esq.sq_port != port)\n 511:\t\t\t\tcontinue;\n 512:\t\n 513:\t\t\tlist_del(\u0026lookup-\u003eli);\n 514:\t\t\tkfree(lookup);\n 515:\t\t\tqrtr_ns.lookup_count--;\n 516:\t\t}\n 517:\t\n 518:\t\t/* Remove the server belonging to this port but don't broadcast\n 519:\t\t * DEL_SERVER. Neighbours would've already removed the server belonging\n 520:\t\t * to this port due to the DEL_CLIENT broadcast from qrtr_port_remove().\n 521:\t\t */\n 522:\t\tnode = node_lookup(endpoint_id, node_id);\n 523:\t\tif (node)\n 524:\t\t\tserver_del(endpoint_id, node, port, false);\n 525:\t\n 526:\t\t/* Advertise the removal of this client to all local servers */\n 527:\t\tlocal_node = node_lookup(qrtr_ns.local_node, qrtr_ns.local_node);\n 528:\t\tif (!local_node)\n 529:\t\t\treturn 0;\n 530:\t\n 531:\t\tmemset(\u0026pkt, 0, sizeof(pkt));\n 532:\t\tpkt.cmd = cpu_to_le32(QRTR_TYPE_DEL_CLIENT);\n 533:\t\tpkt.client.node = cpu_to_le32(node_id);\n 534:\t\tpkt.client.port = cpu_to_le32(port);\n 535:\t\n 536:\t\txa_for_each(\u0026local_node-\u003eservers, index, srv) {\n 537:\t\t\tsq.sq_family = AF_QIPCRTR;\n 538:\t\t\tsq.sq_node = srv-\u003enode;\n 539:\t\t\tsq.sq_port = srv-\u003eport;\n 540:\t\n 541:\t\t\t/* Del Client will look as if it came from endpoint_id */\n 542:\t\t\tret = qrtr_ns_sendmsg(endpoint_id, \u0026sq, \u0026pkt);\n 543:\t\t\tif (ret \u003c 0 \u0026\u0026 ret != -ENODEV) {\n 544:\t\t\t\tpr_err(\"failed to send del client cmd\\n\");\n 545:\t\t\t\treturn ret;\n 546:\t\t\t}\n 547:\t\t}\n 548:\t\treturn 0;\n 549:\t}\n 550:\t\n"
}

75/3 2026/09/15 06:30 llm kmsan-evaluator
0m Model:
gemini-3.8-flash

Args:
null

Results:
null

Tokens:
							input: 66984
							output: 30
							thoughts: 998
						

Thoughts:
**Analyzing QRTR Nameservice Initialization and Cleanup**

Okay, so I see `memset(&pkt, 0, sizeof(pkt));` in line 531 again, good, good. Now, let's make sure I've got all instances of that in `ns.c`. Ah, right, let's drill down into `ctrl_cmd_new_lookup` to see how it's used. Okay, iterating through those XArrays... and calling `lookup_notify`. I recall checking `lookup_notify` earlier... here it is. It's initializing `pkt` using `memset`, and then populating the relevant fields if `srv` is not NULL. The important bit here is when `srv` *is* NULL. That's when we send the empty notification to signal the end of a listing. I see the memset, but it seems correct. Everything *should* be zeroed.

Okay, let's step back, and think through the endpoint ID passed to `qrtr_ns_sendmsg`. Ah, when `endpoint_id` is zero, we *don't* set `msg.msg_control` and `msg.msg_controllen`, so no cmsg is sent. Alright, so no issue there.

Now, let's dig into memory management. What about `node_get`? Okay, `endpoint` is `kzalloc`'d, and `node` is `kzalloc`'d. That means everything is zero initialized.

Finally, what about `node_erase`? Let's check `qrtr_ns_remove` and make sure there are no dangling pointers or memory leaks. Okay, `xa_erase` and `kfree` on the `node`. Looks clean. 



76/3 2026/09/15 06:30 tool grepper
0m Args:
{
  "Expression": "qrtr_ns_remove",
  "PathPrefix": "net/qrtr"
}

Results:
{
  "Output": "net/qrtr/af_qrtr.c=1610=static int __init qrtr_proto_init(void)\n--\nnet/qrtr/af_qrtr.c-1635-err_ns:\nnet/qrtr/af_qrtr.c:1636:\tqrtr_ns_remove();\nnet/qrtr/af_qrtr.c-1637-err_sock:\n--\nnet/qrtr/af_qrtr.c=1645=static void __exit qrtr_proto_fini(void)\n--\nnet/qrtr/af_qrtr.c-1647-\tradix_tree_delete(\u0026qrtr_nodes, 0);\nnet/qrtr/af_qrtr.c:1648:\tqrtr_ns_remove();\nnet/qrtr/af_qrtr.c-1649-\tsock_unregister(qrtr_family.family);\n--\nnet/qrtr/ns.c=893=EXPORT_SYMBOL_GPL(qrtr_ns_init);\nnet/qrtr/ns.c-894-\nnet/qrtr/ns.c:895:void qrtr_ns_remove(void)\nnet/qrtr/ns.c-896-{\n--\nnet/qrtr/ns.c-914-}\nnet/qrtr/ns.c:915:EXPORT_SYMBOL_GPL(qrtr_ns_remove);\nnet/qrtr/ns.c-916-\n--\nnet/qrtr/qrtr.h=43=int qrtr_ns_init(void);\nnet/qrtr/qrtr.h-44-\nnet/qrtr/qrtr.h:45:void qrtr_ns_remove(void);\nnet/qrtr/qrtr.h-46-\n"
}

77/3 2026/09/15 06:30 llm kmsan-evaluator
0m Model:
gemini-3.8-flash

Args:
null

Results:
null

Tokens:
							input: 68845
							output: 36
							thoughts: 24
						

Thoughts:
Here's a summary of my immediate thought process, from the perspective of someone familiar with the subject:

**Analyzing the QRTR Namespace Removal Function**

Okay, time to dive into the `qrtr_ns_remove` implementation. I need to refresh my understanding of how namespace removal is handled within the QRTR subsystem, specifically in `net/qrtr/ns.c`. I'm focusing on the mechanics of this removal process, looking for potential areas of concern or points of optimization. I'll be scrutinizing the code for any subtle race conditions, resource leaks, or inefficient data structures that might impact overall system performance and stability during namespace management. Let's see how this function handles the details.



78/3 2026/09/15 06:30 tool read-file
0m Args:
{
  "File": "net/qrtr/ns.c",
  "FirstLine": 895,
  "LineCount": 30
}

Results:
{
  "Contents": " 895:\tvoid qrtr_ns_remove(void)\n 896:\t{\n 897:\t\twrite_lock_bh(\u0026qrtr_ns.sock-\u003esk-\u003esk_callback_lock);\n 898:\t\tqrtr_ns.sock-\u003esk-\u003esk_data_ready = qrtr_ns.saved_data_ready;\n 899:\t\twrite_unlock_bh(\u0026qrtr_ns.sock-\u003esk-\u003esk_callback_lock);\n 900:\t\n 901:\t\tcancel_work_sync(\u0026qrtr_ns.work);\n 902:\t\tsynchronize_net();\n 903:\t\tdestroy_workqueue(qrtr_ns.workqueue);\n 904:\t\n 905:\t\t/* sock_release() expects the two references that were put during\n 906:\t\t * qrtr_ns_init(). This function is only called during module remove,\n 907:\t\t * so try_stop_module() has already set the refcnt to 0. Use\n 908:\t\t * __module_get() instead of try_module_get() to successfully take two\n 909:\t\t * references.\n 910:\t\t */\n 911:\t\t__module_get(qrtr_ns.sock-\u003eops-\u003eowner);\n 912:\t\t__module_get(qrtr_ns.sock-\u003esk-\u003esk_prot_creator-\u003eowner);\n 913:\t\tsock_release(qrtr_ns.sock);\n 914:\t}\n 915:\tEXPORT_SYMBOL_GPL(qrtr_ns_remove);\n 916:\t\n 917:\tMODULE_AUTHOR(\"Manivannan Sadhasivam \u003cmanivannan.sadhasivam@linaro.org\u003e\");\n 918:\tMODULE_DESCRIPTION(\"Qualcomm IPC Router Nameservice\");\n 919:\tMODULE_LICENSE(\"Dual BSD/GPL\");\n"
}

79/3 2026/09/15 06:30 llm kmsan-evaluator
0m Model:
gemini-3.8-flash

Args:
null

Results:
null

Tokens:
							input: 69530
							output: 32
							thoughts: 2339
						

Thoughts:
**Deep Dive into QRTR Code: Potential UAF Vulnerability and Code Analysis**

Okay, let's break this down. My initial inspection of `net/qrtr/af_qrtr.c` regarding the QRTR index definitions seems straightforward, particularly the half-index calculations and their limitations on 32-bit architectures. The code in `qrtr_tx_resume`, `qrtr_tx_wait`, and `qrtr_tx_flow_failed` seems correctly initialized and handles flow control with a clear understanding of the architectural limitations.  No immediate issues there.

Now, let's switch gears and focus on `qrtr_msg_get_endpoint`. The function extracts an endpoint ID from a control message. I see the checks for valid control message length with `CMSG_OK` and the validation of `endpoint_id`, including that it can't be zero.  I've confirmed there are no issues with the checks or the reads. I am satisfied that `CMSG_OK` is checking the length of the data as expected and that KASAN/KMSAN will catch any reads past the end of the buffer. The alignment issues were properly handled with `CMSG_NXTHDR` / `CMSG_FIRSTHDR`.

Moving on to `qrtr_node_lookup`, the use of `radix_tree_lookup` and the helper structure look safe, especially since `qrtr_node_acquire` is correctly handling reference counting.  It's returning the node from the `radix_tree`.

*Aha!* Now, focusing on the potential memory safety issue that has been previously reported. I see a critical area in `__qrtr_node_release` and the interaction with `qrtr_endpoint_unregister`. The key is: `if (helper != &helper0 && radix_tree_empty(&helper->nodes))` within `__qrtr_node_release`. The `helper` can be `&ep->helper`.

This looks like a classic Use-After-Free (UAF) situation! If `qrtr_endpoint_unregister` is called, and *then* a node is released that was associated with the unregistered endpoint, or the endpoint is freed before the helper structure is cleaned up, we could be looking at an access to freed memory. This requires further investigation. This type of UAF will most likely be detected by KASAN.

Finally, regarding potential uninitialized memory, the `struct qrtr_cb` looks fine in terms of size relative to `skb->cb`. I've confirmed `cb->endpoint_id` is initialized before being used in several places, including `qrtr_recvmsg`, `qrtr_endpoint_post`, and `qrtr_send_resume_tx`.  This seems to be safe, however it needs further careful analysis to ensure it is always the case.

I need to confirm all the paths where `qrtr_cb` is initialized, and that includes looking for calls to `qrtr_send_resume_tx` throughout the code base. We can then confidently assess the risk. I am going to run the appropriate tests and code coverage to ensure these points are valid.



80/3 2026/09/15 06:30 tool grepper
0m Args:
{
  "Expression": "qrtr_send_resume_tx",
  "PathPrefix": "net/qrtr"
}

Results:
{
  "Output": "net/qrtr/af_qrtr.c=1119=static int qrtr_sendmsg(struct socket *sock, struct msghdr *msg, size_t len)\n--\nnet/qrtr/af_qrtr.c-1234-\nnet/qrtr/af_qrtr.c:1235:static int qrtr_send_resume_tx(struct qrtr_cb *cb)\nnet/qrtr/af_qrtr.c-1236-{\n--\nnet/qrtr/af_qrtr.c=1266=static int qrtr_recvmsg(struct socket *sock, struct msghdr *msg,\n--\nnet/qrtr/af_qrtr.c-1318-\tif (cb-\u003econfirm_rx)\nnet/qrtr/af_qrtr.c:1319:\t\tqrtr_send_resume_tx(cb);\nnet/qrtr/af_qrtr.c-1320-\n"
}

81/3 2026/09/15 06:30 llm kmsan-evaluator
0m Model:
gemini-3.8-flash

Args:
null

Results:
null

Tokens:
							input: 72823
							output: 39
							thoughts: 3873
						

Thoughts:
**Comprehensive Analysis of Potential Information Leakage in QRTR Subsystem**

Alright, let's break this down systematically. My concern here is centered around the potential for uninitialized memory reads, which could lead to information leaks. After a thorough review of the code, I've focused on various potential entry points and scenarios to ensure no sensitive data is exposed.

1.  **`qrtr_recvmsg` and `cb->endpoint_id`:** The initial trigger was the call to `qrtr_send_resume_tx(cb)` within `qrtr_recvmsg` and how the `cb` is initialized. I've tracked the initialization of `cb->endpoint_id`, confirming it's set in both `qrtr_endpoint_post` and `qrtr_local_enqueue`. No other assignments are observed.

    *   I examined the `qrtr_ns_worker` function, specifically how it uses `kernel_recvmsg` to receive packets on `qrtr_ns.sock`. The interesting point here is the loop and control message handling. This is where I meticulously checked for uninitialized memory reads, especially within the `for (;;)` loop.
    *   I traced the execution with `QRTR_REPORT_ENDPOINT` enabled in the `qrtr_ns_init` function, ensuring the `cb->endpoint_id` is properly handled within the control message. Specifically, `qrtr_msg_get_endpoint` is only called if the endpoint ID is set, avoiding a read-of-uninitialized if the endpoint ID is zero.
    *   I scrutinized the data flow. If the endpoint ID is zero or if a user-space socket has `QRTR_REPORT_ENDPOINT` enabled, the check for `cb->endpoint_id && test_bit(QRTR_F_REPORT_ENDPOINT, &ipc->flags)` avoids a `put_cmsg` call. This prevents writing any kernel memory via the control buffer if the ID is zero.
    *   I checked what happens with the control message buffer in `qrtr_recvmsg` and how it is written to the user in the control path. Specifically, I went through the `put_cmsg` function very carefully. I ensured that there are no uninitialized values being copied to user space, and any data passed is explicitly set.

2.  **`qrtr_sendmsg` and `qrtr_msg_get_endpoint`:** The focus shifted to `qrtr_sendmsg`. Here, I reviewed `qrtr_msg_get_endpoint` and confirmed that any retrieved endpoint ID is always initialized. The code handles both cases where a control message is present (containing the endpoint ID) and when it's absent (using the bound endpoint).

3.  **`qrtr_setsockopt` and `qrtr_getsockopt`:** I looked at the socket options. I carefully assessed the `qrtr_setsockopt` and `qrtr_getsockopt` functions. It appears that the use of a local variable `unsigned int val = 0;` prevents the issue. I explicitly checked what happened with the `val` variable when `optlen` is less than `sizeof(val)`. In `qrtr_getsockopt`, `val` is always initialized by either `test_bit` or `READ_ONCE`, and I confirmed any error paths prevent leaking the value.

4.  **`QRTR_ENDPOINT_RANGE` and Endpoint Allocation:** I've confirmed that the `endpoint_id` is initialized by `xa_alloc_cyclic`, and if the allocation fails, `endpoint_id` is not used.

5.  **`qrtr_bcast_enqueue` and Concurrency:** The use of `qrtr_bcast_enqueue` was reviewed, including the `qrtr_node_lock` and the `list_for_each_entry` to ensure that any `node->ep` is properly protected in the `qrtr_endpoint_unregister` function call. I also checked if `node` is removed from `qrtr_all_nodes` in `qrtr_endpoint_unregister`.

In conclusion, I've conducted a robust analysis of potential information leakage in the QRTR subsystem, particularly focusing on uninitialized memory reads. All of the potential scenarios and code paths I reviewed appear to be safe with respect to information leakage. The code contains no glaring issues. The presence of explicit initialization, robust error handling, and careful data flow management indicates that there are no remaining obvious vulnerabilities with uninitialized memory reads.



82/3 2026/09/15 06:31 tool read-file
0m Args:
{
  "File": "net/qrtr/af_qrtr.c",
  "FirstLine": 805,
  "LineCount": 60
}

Results:
{
  "Contents": " 805:\t{\n 806:\t\tstruct qrtr_node *node = ep-\u003enode;\n 807:\t\tstruct sockaddr_qrtr src = {AF_QIPCRTR, node-\u003enid, QRTR_PORT_CTRL};\n 808:\t\tstruct sockaddr_qrtr dst = {AF_QIPCRTR, qrtr_local_nid, QRTR_PORT_CTRL};\n 809:\t\tstruct radix_tree_iter iter;\n 810:\t\tstruct radix_tree_iter iter2;\n 811:\t\tstruct qrtr_ctrl_pkt *pkt;\n 812:\t\tstruct qrtr_tx_flow *flow;\n 813:\t\tstruct sk_buff *skb;\n 814:\t\tunsigned long flags;\n 815:\t\tunsigned long index;\n 816:\t\tvoid __rcu **slot;\n 817:\t\tvoid __rcu **slot2;\n 818:\t\tu32 endpoint_id;\n 819:\t\n 820:\t\tmutex_lock(\u0026node-\u003eep_lock);\n 821:\t\tendpoint_id = node-\u003eep-\u003eid;\n 822:\t\tnode-\u003eep = NULL;\n 823:\t\tmutex_unlock(\u0026node-\u003eep_lock);\n 824:\t\n 825:\t\t/* Notify the local controller about the event */\n 826:\t\tspin_lock_irqsave(\u0026qrtr_nodes_lock, flags);\n 827:\t\tradix_tree_for_each_slot(slot, \u0026qrtr_nodes, \u0026iter, 0) {\n 828:\t\t\tstruct qrtr_node_lookup_helper *helper = *slot;\n 829:\t\n 830:\t\t\tif (!helper)\n 831:\t\t\t\tcontinue;\n 832:\t\t\tradix_tree_for_each_slot(slot2, \u0026helper-\u003enodes, \u0026iter2, 0) {\n 833:\t\t\t\tif (*slot2 != node)\n 834:\t\t\t\t\tcontinue;\n 835:\t\t\t\tsrc.sq_node = iter.index;\n 836:\t\t\t\tskb = qrtr_alloc_ctrl_packet(\u0026pkt, GFP_ATOMIC);\n 837:\t\t\t\tif (skb) {\n 838:\t\t\t\t\tpkt-\u003ecmd = cpu_to_le32(QRTR_TYPE_BYE);\n 839:\t\t\t\t\tqrtr_local_enqueue(NULL, skb, endpoint_id,\n 840:\t\t\t\t\t\t\t   QRTR_TYPE_BYE, \u0026src, \u0026dst);\n 841:\t\t\t\t}\n 842:\t\t\t}\n 843:\t\t}\n 844:\t\tif (ep-\u003ehelper.added) {\n 845:\t\t\tradix_tree_for_each_slot(slot, \u0026ep-\u003ehelper.nodes, \u0026iter, 0)\n 846:\t\t\t\tradix_tree_iter_delete(\u0026ep-\u003ehelper.nodes, \u0026iter, slot);\n 847:\t\t\tradix_tree_delete(\u0026qrtr_nodes, ep-\u003eid);\n 848:\t\t\tep-\u003ehelper.added = 0;\n 849:\t\t}\n 850:\t\tspin_unlock_irqrestore(\u0026qrtr_nodes_lock, flags);\n 851:\t\n 852:\t\t/* Wake up any transmitters waiting for resume-tx from the node */\n 853:\t\tmutex_lock(\u0026node-\u003eqrtr_tx_lock);\n 854:\t\txa_for_each(\u0026node-\u003eqrtr_tx_flow, index, flow)\n 855:\t\t\twake_up_interruptible_all(\u0026flow-\u003eresume_tx);\n 856:\t\tmutex_unlock(\u0026node-\u003eqrtr_tx_lock);\n 857:\t\n 858:\t\tqrtr_node_release(node);\n 859:\t\n 860:\t\txa_erase(\u0026qrtr_endpoints, endpoint_id);\n 861:\t\n 862:\t\tep-\u003eid = 0;\n 863:\t\tep-\u003enode = NULL;\n 864:\t}\n"
}

83/3 2026/09/15 06:31 llm kmsan-evaluator
0m Model:
gemini-3.8-flash

Args:
null

Results:
null

Tokens:
							input: 78719
							output: 574
							thoughts: 2165
						

Thoughts:
**KMSAN Assessment: No Need Here!**

Okay, so I've been diving deep into this patch, specifically the potential for uninitialized memory usage, and after a thorough review, I'm confident that `NeedsKMSAN` is false. Let me walk you through my thought process.

First, I had to ensure I understood the core difference between KASAN and KMSAN. KASAN is my go-to for catching out-of-bounds accesses, use-after-free errors, and locking issues – the usual suspects. KMSAN, on the other hand, is laser-focused on detecting reads of truly uninitialized memory, be it on the stack, heap, or within page allocations, and also potential leaks of kernel memory to user space. KMSAN is a heavyweight, so only deploy if nothing else will catch the bugs.

Given that, I went through the code with a fine-tooth comb, systematically checking against the KMSAN guidelines.

1.  **User-Space Exposure:** I checked every instance where kernel structures are sent to user space (via `copy_to_user`, `put_user`, socket options, etc.). Specifically:
    *   In `qrtr_getsockopt`, all values returned are properly initialized before being copied. The socket option data is simple `unsigned int` variables, fully initialized before being copied out, so zero risk there.
    *   In `qrtr_setsockopt`, I confirmed that even if the socket option length is smaller than expected, the target is still initialized.
    *   In `qrtr_recvmsg`, I traced the path of `cb->endpoint_id`, and I verified that the endpoint ID is properly initialized on all packet ingress paths. The `put_cmsg` writes the necessary fields and the value from the `cb->endpoint_id` that is known and initialised from the `qrtr_endpoint_post` or `qrtr_local_enqueue` paths, so there’s no leaking of kernel memory to user space.

2.  **Conditional Logic:** I looked at any conditional branching. In `qrtr_setsockopt` with the `val = 0;` assignment covers the potential uninitialized read. In `qrtr_sendmsg` and `qrtr_msg_get_endpoint` the outputs are initialized. I didn’t see any obvious risks there either.

3.  **Complex Data Structures:** I double-checked the allocation and initialization of data structures.
    *   I've made certain that everything allocated dynamically (with `kzalloc` or `memset` in `af_qrtr.c` and `ns.c`) is properly initialized. Helper structures are initialized in place. The code ensures these allocations are zeroed or properly initialized before any read.

4.  **Bounds and Lengths:** I paid close attention to bounds checks and length calculations, scrutinizing how these might inadvertently expose uninitialized memory.
    *   `qrtr_msg_get_endpoint` and `qrtr_endpoint_post` have bounds checks for `cmsg_len` and size/length validations. I confirmed that these checks are rigorous and prevent any accesses to uninitialized regions.

Now, for potential bugs... I found some concurrency/lifecycle issues and a few logic bugs (e.g., incorrect index), which will cause UAF errors or resource leaks. However, these failures are caught by KASAN and LOCKDEP. They don’t reveal any uninitialized memory usage. These potential bugs are exactly the type that KASAN, LOCKDEP and standard bug detectors are meant to catch. They are not the type of bugs that KMSAN would detect.

In summary, this patch does not introduce any risks of uninitialized memory usage or memory leaks, given the comprehensive initialization practices, and the potential failures would be detected by standard KASAN and LOCKDEP detectors.



84/3 2026/09/15 06:31 tool set-results
0m Args:
{
  "KMSANReasoning": "The patch series introduces endpoint routing and management to the Qualcomm IPC Router (QRTR) subsystem, adding setsockopt/getsockopt options (QRTR_REPORT_ENDPOINT, QRTR_BIND_ENDPOINT), CMSG endpoint support (QRTR_ENDPOINT), hierarchical radix trees for endpoint node lookups, and endpoint tracking in the nameservice daemon (ns.c).\n\nKMSAN vs KASAN applicability analysis:\n1. User-space copies \u0026 Info-leaks:\n   - In qrtr_getsockopt(), 'val' is an unsigned int (sizeof(int)) explicitly assigned via test_bit() or READ_ONCE(), and len is fixed to sizeof(int) before copy_to_user(). No uninitialized structure padding or uninitialized memory is exposed.\n   - In qrtr_setsockopt(), 'val' is initialized to 0 upon declaration, avoiding uninitialized memory use if optlen \u003c sizeof(val).\n   - In qrtr_recvmsg(), put_cmsg() is called with cb-\u003eendpoint_id (u32). The skb-\u003ecb endpoint_id is explicitly set on all packet ingress paths (qrtr_endpoint_post and qrtr_local_enqueue).\n   - In mhi.c, endpoint_show() formats ep.id into sysfs via sprintf().\n2. Uninitialized struct fields and buffers:\n   - In ns.c, all dynamically allocated structures (struct qrtr_ns_endpoint, struct qrtr_node, struct qrtr_server) are allocated with kzalloc_obj(). All control packets (struct qrtr_ctrl_pkt) transmitted by ns.c are explicitly cleared with memset(\u0026pkt, 0, sizeof(pkt)).\n   - In af_qrtr.c, helper0 is static in BSS, node is allocated with kzalloc, and ep-\u003ehelper in struct qrtr_endpoint is properly initialized.\n   - qrtr_msg_get_endpoint() initializes endpoint_id to 0 and strictly checks cmsg lengths before reading CMSG_DATA.\n3. Memory safety risks:\n   - The modifications alter radix tree hierarchies and node acquisition/release lifetimes (e.g., in __qrtr_node_release, qrtr_endpoint_register, qrtr_endpoint_unregister), which primarily risk use-after-free, NULL pointer dereferences, or lock-related deadlocks. These bugs are properly covered by KASAN and LOCKDEP.\n\nNo uninitialized memory hazards or info-leak risks are introduced or exposed. Therefore, a dedicated KMSAN fuzzing session is not warranted.",
  "NeedsKMSAN": false
}

Results:
{
  "KMSANReasoning": "The patch series introduces endpoint routing and management to the Qualcomm IPC Router (QRTR) subsystem, adding setsockopt/getsockopt options (QRTR_REPORT_ENDPOINT, QRTR_BIND_ENDPOINT), CMSG endpoint support (QRTR_ENDPOINT), hierarchical radix trees for endpoint node lookups, and endpoint tracking in the nameservice daemon (ns.c).\n\nKMSAN vs KASAN applicability analysis:\n1. User-space copies \u0026 Info-leaks:\n   - In qrtr_getsockopt(), 'val' is an unsigned int (sizeof(int)) explicitly assigned via test_bit() or READ_ONCE(), and len is fixed to sizeof(int) before copy_to_user(). No uninitialized structure padding or uninitialized memory is exposed.\n   - In qrtr_setsockopt(), 'val' is initialized to 0 upon declaration, avoiding uninitialized memory use if optlen \u003c sizeof(val).\n   - In qrtr_recvmsg(), put_cmsg() is called with cb-\u003eendpoint_id (u32). The skb-\u003ecb endpoint_id is explicitly set on all packet ingress paths (qrtr_endpoint_post and qrtr_local_enqueue).\n   - In mhi.c, endpoint_show() formats ep.id into sysfs via sprintf().\n2. Uninitialized struct fields and buffers:\n   - In ns.c, all dynamically allocated structures (struct qrtr_ns_endpoint, struct qrtr_node, struct qrtr_server) are allocated with kzalloc_obj(). All control packets (struct qrtr_ctrl_pkt) transmitted by ns.c are explicitly cleared with memset(\u0026pkt, 0, sizeof(pkt)).\n   - In af_qrtr.c, helper0 is static in BSS, node is allocated with kzalloc, and ep-\u003ehelper in struct qrtr_endpoint is properly initialized.\n   - qrtr_msg_get_endpoint() initializes endpoint_id to 0 and strictly checks cmsg lengths before reading CMSG_DATA.\n3. Memory safety risks:\n   - The modifications alter radix tree hierarchies and node acquisition/release lifetimes (e.g., in __qrtr_node_release, qrtr_endpoint_register, qrtr_endpoint_unregister), which primarily risk use-after-free, NULL pointer dereferences, or lock-related deadlocks. These bugs are properly covered by KASAN and LOCKDEP.\n\nNo uninitialized memory hazards or info-leak risks are introduced or exposed. Therefore, a dedicated KMSAN fuzzing session is not warranted.",
  "NeedsKMSAN": false
}

LLM Calls Summary:
Total Calls Total Tokens Avg Tokens Total Duration (Seconds) Avg Duration (Seconds)
Tool Calls Summary:
Total Calls Total Duration (Seconds) Avg Duration (Seconds)