From patchwork Wed Jul 12 11:26:29 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Vignesh Viswanathan X-Patchwork-Id: 119099 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:a6b2:0:b0:3e4:2afc:c1 with SMTP id c18csp1084828vqm; Wed, 12 Jul 2023 04:40:11 -0700 (PDT) X-Google-Smtp-Source: APBJJlHtezGPcS0YzhJGPT8CZUkYCO1CKVgkv0AY5fhFTu1YIU41HSmkBW2vFU2u5nf/nkOJL/sm X-Received: by 2002:a19:e005:0:b0:4f6:3ab6:3d9e with SMTP id x5-20020a19e005000000b004f63ab63d9emr13785778lfg.59.1689162010718; Wed, 12 Jul 2023 04:40:10 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1689162010; cv=none; d=google.com; s=arc-20160816; b=MFoXoRZr5cyTMGSvy7uKqHv0DFcSotCas11i1dwssNFqgBHWG+JLczV8X+qqEnvIAa vNsf9oD9yx45MAU/EGvA72aHbGnrllEp6hLrrJrHOLR3AH8TL/HWRZkGQukeMK+XOXH5 YiaKeggCUmmSHJ637pO2YVs+Rt6YwNTQdloVLOPEECVaawwYKwkyaZnab9glJQ8czp81 u8mwrMVHg/33voYmPyCjlE5TAtcHCmTr5rQjNnRByFaSRRCo8wRhkgus8a5ifGohp6yH 4nsb1Etgf47NneNRGUZEe+6/ysF18Pgp52Df5RQPaWZ9NWklMoz6IfXLHLdDBY5O5XdH WEPA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=dtyb8RrTEDjACnbVRF/5ewLfoMkIxFOfcdWAKcWgTm8=; fh=xHrKp8+bUxvfI02f9POZGuAxmAt/WwBN7skM37uOXYU=; b=OtdQCs5NYecp3slAxHaQSjEds6sBnQ0s1w3oKCBwJO+WWtTJjtv9JC/SiTJGT26LGa OCHh8rvEugU78f/IiIZQJZubif6WNbwulqLfMwABMAmFqfao17YcELAuky0JwKmEZB9B eOwhJqqeINnJ3gwKB/yjrhSChKtcNZNhEiAF0fAxlgtPjsiaMw7DLAwNSRiwYAxJt+KL outRojj40uSR8dxjyf6tMKWh9fOwYAdDbyR0UUQNNQprmxHmCCT66PRz+tGo9d+YqA/c SWQwuWl88Bt3QHWDM7/2iKx+W2CZ0L8lNVowXf1GviJF5217mwfehl3mkLog4Fh83uZu WqwQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@quicinc.com header.s=qcppdkim1 header.b=pYSAvd2i; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=quicinc.com Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id y17-20020aa7c251000000b0051e2ded9b50si4405217edo.632.2023.07.12.04.39.47; Wed, 12 Jul 2023 04:40:10 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@quicinc.com header.s=qcppdkim1 header.b=pYSAvd2i; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=quicinc.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233190AbjGLL1k (ORCPT + 99 others); Wed, 12 Jul 2023 07:27:40 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:51646 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233167AbjGLL1g (ORCPT ); Wed, 12 Jul 2023 07:27:36 -0400 Received: from mx0a-0031df01.pphosted.com (mx0a-0031df01.pphosted.com [205.220.168.131]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id D36B08F; Wed, 12 Jul 2023 04:27:34 -0700 (PDT) Received: from pps.filterd (m0279862.ppops.net [127.0.0.1]) by mx0a-0031df01.pphosted.com (8.17.1.19/8.17.1.19) with ESMTP id 36CB5Vx8008296; Wed, 12 Jul 2023 11:27:27 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=quicinc.com; h=from : to : cc : subject : date : message-id : in-reply-to : references : mime-version : content-transfer-encoding : content-type; s=qcppdkim1; bh=dtyb8RrTEDjACnbVRF/5ewLfoMkIxFOfcdWAKcWgTm8=; b=pYSAvd2iab5IbWWkE14krwaHZxtbclZ4DnwJAUTXRNzKb9/Vft33wq/XHI1EM0vRtN+f 9ytqn1VwsGGFUytz1a2gy/SL3ATB0X49IEPEAbBqHsB54OfQ+o2TqigmNOg/4ta8bajU nBYxwM2YWiuB8jIALZhJYgQTxq3bUlKEt9pgZKcDf9buFqIV7D76FwcP1aQ4/YjitBKZ NRXOAtiVYm5a4Gozoc6OnPXhYSO485tm9TYHjdUyFc04cJa7dXXcUDtUPOdmC/WpQOMU fbCZJs9oXDBJZlSitlL2a5TPGC5ZFG/M7MmmRlC1yzV2arL8GEibyVH4bF04EW6zBJWJ fA== Received: from nalasppmta02.qualcomm.com (Global_NAT1.qualcomm.com [129.46.96.20]) by mx0a-0031df01.pphosted.com (PPS) with ESMTPS id 3rsgar9532-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Wed, 12 Jul 2023 11:27:27 +0000 Received: from nalasex01c.na.qualcomm.com (nalasex01c.na.qualcomm.com [10.47.97.35]) by NALASPPMTA02.qualcomm.com (8.17.1.5/8.17.1.5) with ESMTPS id 36CBRQNn005639 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Wed, 12 Jul 2023 11:27:26 GMT Received: from hu-viswanat-blr.qualcomm.com (10.80.80.8) by nalasex01c.na.qualcomm.com (10.47.97.35) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.1118.30; Wed, 12 Jul 2023 04:26:59 -0700 From: Vignesh Viswanathan To: , , , , , , , CC: , , Vignesh Viswanathan Subject: [PATCH net-next 1/3] net: qrtr: ns: Change servers radix tree to xarray Date: Wed, 12 Jul 2023 16:56:29 +0530 Message-ID: <20230712112631.3461793-2-quic_viswanat@quicinc.com> X-Mailer: git-send-email 2.41.0 In-Reply-To: <20230712112631.3461793-1-quic_viswanat@quicinc.com> References: <20230712112631.3461793-1-quic_viswanat@quicinc.com> MIME-Version: 1.0 X-Originating-IP: [10.80.80.8] X-ClientProxiedBy: nasanex01a.na.qualcomm.com (10.52.223.231) To nalasex01c.na.qualcomm.com (10.47.97.35) X-QCInternal: smtphost X-Proofpoint-Virus-Version: vendor=nai engine=6200 definitions=5800 signatures=585085 X-Proofpoint-GUID: GIJBNhFWSBLwORGMDm6no3MArMxnTeYN X-Proofpoint-ORIG-GUID: GIJBNhFWSBLwORGMDm6no3MArMxnTeYN X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.254,Aquarius:18.0.957,Hydra:6.0.591,FMLib:17.11.176.26 definitions=2023-07-12_06,2023-07-11_01,2023-05-22_02 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 mlxscore=0 suspectscore=0 mlxlogscore=999 spamscore=0 priorityscore=1501 impostorscore=0 phishscore=0 clxscore=1011 adultscore=0 malwarescore=0 lowpriorityscore=0 bulkscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2305260000 definitions=main-2307120102 X-Spam-Status: No, score=-2.8 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_LOW,SPF_HELO_NONE, SPF_PASS,T_SCC_BODY_TEXT_LINE,URIBL_BLOCKED autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1771214744718300022 X-GMAIL-MSGID: 1771214744718300022 There is a use after free scenario while iterating through the servers radix tree despite the ns being a single threaded process. This can happen when the radix tree APIs are not synchronized with the rcu_read_lock() APIs. Convert the radix tree for servers to xarray to take advantage of the built in rcu lock usage provided by xarray. Signed-off-by: Chris Lew Signed-off-by: Vignesh Viswanathan Reviewed-by: Simon Horman --- net/qrtr/ns.c | 133 +++++++++----------------------------------------- 1 file changed, 24 insertions(+), 109 deletions(-) diff --git a/net/qrtr/ns.c b/net/qrtr/ns.c index 0f7a729f1a1f..039313c3e044 100644 --- a/net/qrtr/ns.c +++ b/net/qrtr/ns.c @@ -66,7 +66,7 @@ struct qrtr_server { struct qrtr_node { unsigned int id; - struct radix_tree_root servers; + struct xarray servers; }; static struct qrtr_node *node_get(unsigned int node_id) @@ -83,6 +83,7 @@ static struct qrtr_node *node_get(unsigned int node_id) return NULL; node->id = node_id; + xa_init(&node->servers); if (radix_tree_insert(&nodes, node_id, node)) { kfree(node); @@ -193,40 +194,23 @@ static void lookup_notify(struct sockaddr_qrtr *to, struct qrtr_server *srv, static int announce_servers(struct sockaddr_qrtr *sq) { - struct radix_tree_iter iter; struct qrtr_server *srv; struct qrtr_node *node; - void __rcu **slot; + unsigned long index; int ret; node = node_get(qrtr_ns.local_node); if (!node) return 0; - rcu_read_lock(); /* Announce the list of servers registered in this node */ - radix_tree_for_each_slot(slot, &node->servers, &iter, 0) { - srv = radix_tree_deref_slot(slot); - if (!srv) - continue; - if (radix_tree_deref_retry(srv)) { - slot = radix_tree_iter_retry(&iter); - continue; - } - slot = radix_tree_iter_resume(slot, &iter); - rcu_read_unlock(); - + xa_for_each(&node->servers, index, srv) { ret = service_announce_new(sq, srv); if (ret < 0) { pr_err("failed to announce new service\n"); return ret; } - - rcu_read_lock(); } - - rcu_read_unlock(); - return 0; } @@ -256,14 +240,17 @@ static struct qrtr_server *server_add(unsigned int service, goto err; /* Delete the old server on the same port */ - old = radix_tree_lookup(&node->servers, port); + old = xa_store(&node->servers, port, srv, GFP_KERNEL); if (old) { - radix_tree_delete(&node->servers, port); - kfree(old); + if (xa_is_err(old)) { + pr_err("failed to add server [0x%x:0x%x] ret:%d\n", + srv->service, srv->instance, xa_err(old)); + goto err; + } else { + kfree(old); + } } - radix_tree_insert(&node->servers, port, srv); - trace_qrtr_ns_server_add(srv->service, srv->instance, srv->node, srv->port); @@ -280,11 +267,11 @@ static int server_del(struct qrtr_node *node, unsigned int port, bool bcast) struct qrtr_server *srv; struct list_head *li; - srv = radix_tree_lookup(&node->servers, port); + srv = xa_load(&node->servers, port); if (!srv) return -ENOENT; - radix_tree_delete(&node->servers, port); + xa_erase(&node->servers, port); /* Broadcast the removal of local servers */ if (srv->node == qrtr_ns.local_node && bcast) @@ -344,13 +331,12 @@ static int ctrl_cmd_hello(struct sockaddr_qrtr *sq) static int ctrl_cmd_bye(struct sockaddr_qrtr *from) { struct qrtr_node *local_node; - struct radix_tree_iter iter; struct qrtr_ctrl_pkt pkt; struct qrtr_server *srv; struct sockaddr_qrtr sq; struct msghdr msg = { }; struct qrtr_node *node; - void __rcu **slot; + unsigned long index; struct kvec iv; int ret; @@ -361,22 +347,9 @@ static int ctrl_cmd_bye(struct sockaddr_qrtr *from) if (!node) return 0; - rcu_read_lock(); /* Advertise removal of this client to all servers of remote node */ - radix_tree_for_each_slot(slot, &node->servers, &iter, 0) { - srv = radix_tree_deref_slot(slot); - if (!srv) - continue; - if (radix_tree_deref_retry(srv)) { - slot = radix_tree_iter_retry(&iter); - continue; - } - slot = radix_tree_iter_resume(slot, &iter); - rcu_read_unlock(); + xa_for_each(&node->servers, index, srv) server_del(node, srv->port, true); - rcu_read_lock(); - } - rcu_read_unlock(); /* Advertise the removal of this client to all local servers */ local_node = node_get(qrtr_ns.local_node); @@ -387,18 +360,7 @@ static int ctrl_cmd_bye(struct sockaddr_qrtr *from) pkt.cmd = cpu_to_le32(QRTR_TYPE_BYE); pkt.client.node = cpu_to_le32(from->sq_node); - rcu_read_lock(); - radix_tree_for_each_slot(slot, &local_node->servers, &iter, 0) { - srv = radix_tree_deref_slot(slot); - if (!srv) - continue; - if (radix_tree_deref_retry(srv)) { - slot = radix_tree_iter_retry(&iter); - continue; - } - slot = radix_tree_iter_resume(slot, &iter); - rcu_read_unlock(); - + xa_for_each(&local_node->servers, index, srv) { sq.sq_family = AF_QIPCRTR; sq.sq_node = srv->node; sq.sq_port = srv->port; @@ -411,11 +373,7 @@ static int ctrl_cmd_bye(struct sockaddr_qrtr *from) pr_err("failed to send bye cmd\n"); return ret; } - rcu_read_lock(); } - - rcu_read_unlock(); - return 0; } @@ -423,7 +381,6 @@ static int ctrl_cmd_del_client(struct sockaddr_qrtr *from, unsigned int node_id, unsigned int port) { struct qrtr_node *local_node; - struct radix_tree_iter iter; struct qrtr_lookup *lookup; struct qrtr_ctrl_pkt pkt; struct msghdr msg = { }; @@ -432,7 +389,7 @@ static int ctrl_cmd_del_client(struct sockaddr_qrtr *from, struct qrtr_node *node; struct list_head *tmp; struct list_head *li; - void __rcu **slot; + unsigned long index; struct kvec iv; int ret; @@ -477,18 +434,7 @@ static int ctrl_cmd_del_client(struct sockaddr_qrtr *from, pkt.client.node = cpu_to_le32(node_id); pkt.client.port = cpu_to_le32(port); - rcu_read_lock(); - radix_tree_for_each_slot(slot, &local_node->servers, &iter, 0) { - srv = radix_tree_deref_slot(slot); - if (!srv) - continue; - if (radix_tree_deref_retry(srv)) { - slot = radix_tree_iter_retry(&iter); - continue; - } - slot = radix_tree_iter_resume(slot, &iter); - rcu_read_unlock(); - + xa_for_each(&local_node->servers, index, srv) { sq.sq_family = AF_QIPCRTR; sq.sq_node = srv->node; sq.sq_port = srv->port; @@ -501,11 +447,7 @@ static int ctrl_cmd_del_client(struct sockaddr_qrtr *from, pr_err("failed to send del client cmd\n"); return ret; } - rcu_read_lock(); } - - rcu_read_unlock(); - return 0; } @@ -576,13 +518,12 @@ static int ctrl_cmd_del_server(struct sockaddr_qrtr *from, static int ctrl_cmd_new_lookup(struct sockaddr_qrtr *from, unsigned int service, unsigned int instance) { - struct radix_tree_iter node_iter; struct qrtr_server_filter filter; - struct radix_tree_iter srv_iter; struct qrtr_lookup *lookup; struct qrtr_node *node; - void __rcu **node_slot; - void __rcu **srv_slot; + struct qrtr_server *srv; + unsigned long node_idx; + unsigned long srv_idx; /* Accept only local observers */ if (from->sq_node != qrtr_ns.local_node) @@ -601,40 +542,14 @@ static int ctrl_cmd_new_lookup(struct sockaddr_qrtr *from, filter.service = service; filter.instance = instance; - rcu_read_lock(); - radix_tree_for_each_slot(node_slot, &nodes, &node_iter, 0) { - node = radix_tree_deref_slot(node_slot); - if (!node) - continue; - if (radix_tree_deref_retry(node)) { - node_slot = radix_tree_iter_retry(&node_iter); - continue; - } - node_slot = radix_tree_iter_resume(node_slot, &node_iter); - - radix_tree_for_each_slot(srv_slot, &node->servers, - &srv_iter, 0) { - struct qrtr_server *srv; - - srv = radix_tree_deref_slot(srv_slot); - if (!srv) - continue; - if (radix_tree_deref_retry(srv)) { - srv_slot = radix_tree_iter_retry(&srv_iter); - continue; - } - + xa_for_each(&nodes, node_idx, node) { + xa_for_each(&node->servers, srv_idx, srv) { if (!server_match(srv, &filter)) continue; - srv_slot = radix_tree_iter_resume(srv_slot, &srv_iter); - - rcu_read_unlock(); lookup_notify(from, srv, true); - rcu_read_lock(); } } - rcu_read_unlock(); /* Empty notification, to indicate end of listing */ lookup_notify(from, NULL, true); From patchwork Wed Jul 12 11:26:30 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Vignesh Viswanathan X-Patchwork-Id: 119098 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:a6b2:0:b0:3e4:2afc:c1 with SMTP id c18csp1084630vqm; Wed, 12 Jul 2023 04:39:48 -0700 (PDT) X-Google-Smtp-Source: APBJJlFe9S2wA+JFBgR9k/7VkDUkP+Ha3quuFrj1x4pK19Hei3rUZlj5Je1Hv7GryzHtIQKJAEnE X-Received: by 2002:a05:6870:fba7:b0:1b0:3075:2f9d with SMTP id kv39-20020a056870fba700b001b030752f9dmr18652059oab.34.1689161988289; Wed, 12 Jul 2023 04:39:48 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1689161988; cv=none; d=google.com; s=arc-20160816; b=Srj14LbuN5oFNQX7Zg/HbxNF5GyYBPSZ7ICqApskSD4+Gah4ZZBk8PMsN70EeD75aS T/L8IDddL21cD129RcfrTjn4kvzdKLPaGLbt8zZHZJdzM777rtzZXP+afwlvZ6VeUX1t fwwlwvMnN6s8JJwgkrnMwPyXRwcK/586EdcRbMAcMf4qSFpTrDu9ccVwCX/qQEU0nnHM rvUC9Zz8sCU21jZIcALQg0gIa8XvQwUs53o+wWOOdfP0IJS9bLaIxr3a1q/LRFdOWslh pgO2ySjAJahZQLeo9C9XKZb4ZlSfLwTTGcsnwMTaz9kGeyy+Oa9fvUlwmZCjNdB4jzjg rs3g== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=Gs56pmtfCp16afU4tLMf5PgqdJecLIO6WoHfuRQb6Uo=; fh=xHrKp8+bUxvfI02f9POZGuAxmAt/WwBN7skM37uOXYU=; b=tOroMJtWiqM6W6sVgwOi6R01zS69/TD1TM0zi9DNQYgfL8TMl4SQxXAnwZctS2Jkag FZx6SsfmjriFQtg4yuZa0iWkvZfrNVHtbO3z7HNQBbfzWRphn837Doqvx0IF+KGIpBLZ seYZeL73QYzkyC6M4uaYieZZimjbtajHMIs2xdkAXMYKjEp/mERQwxyF1Ph9DPZ3EStd L21odYewVtX4RhOiL0Z87PxWcFA7ve2HKLA1QSArAZFgBwX0KlcMqMnfs9hYX2n6N5e7 UZCXDChEYNGV7DiJGrp3H2Ez6t2AZ4Q6qloJUtOlCtpht0uFfkmJ8zb2og9W3qghgplO XTeA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@quicinc.com header.s=qcppdkim1 header.b=YxPaY4CW; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=quicinc.com Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id kg14-20020a170903060e00b001b9e3a18270si3045650plb.420.2023.07.12.04.39.34; Wed, 12 Jul 2023 04:39:48 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@quicinc.com header.s=qcppdkim1 header.b=YxPaY4CW; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=quicinc.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232979AbjGLL1h (ORCPT + 99 others); Wed, 12 Jul 2023 07:27:37 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:51634 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233013AbjGLL1e (ORCPT ); Wed, 12 Jul 2023 07:27:34 -0400 Received: from mx0a-0031df01.pphosted.com (mx0a-0031df01.pphosted.com [205.220.168.131]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 39773173A; Wed, 12 Jul 2023 04:27:33 -0700 (PDT) Received: from pps.filterd (m0279867.ppops.net [127.0.0.1]) by mx0a-0031df01.pphosted.com (8.17.1.19/8.17.1.19) with ESMTP id 36C8cmuk026157; Wed, 12 Jul 2023 11:27:27 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=quicinc.com; h=from : to : cc : subject : date : message-id : in-reply-to : references : mime-version : content-transfer-encoding : content-type; s=qcppdkim1; bh=Gs56pmtfCp16afU4tLMf5PgqdJecLIO6WoHfuRQb6Uo=; b=YxPaY4CWl8YFeyWzOX+Frhas2ixuCMHNK6bqrObOt8W6Y0b9xXFY2ajQsILLpV1ohsBL QlcDr9K2Q4/RLqkqJXzpPkiuDCjPH0daYrt8/29wcAee4uBR4U5QLZjQ00B/NurDgYe+ T8IOLahUYr9IEeHdl4r93szNHQOIJhNiL8QjA4A7RhxOVa1PnWuXK+Y2izb7JEf43Jvw N1uCPzQ3tDWdjRNS87rOKXGaRsBa2L8tOJDke/BX1tLfQo1mE9/Fk8i/ztSJbwqwVZTA 91+WXx8toxCCaFKcsxznXNyeMFrwU3bpmCY1gVoBxR7QuZ1Sfp0MQg6rqI9txTXDnBin 4Q== Received: from nalasppmta02.qualcomm.com (Global_NAT1.qualcomm.com [129.46.96.20]) by mx0a-0031df01.pphosted.com (PPS) with ESMTPS id 3rsf4s9a6p-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Wed, 12 Jul 2023 11:27:27 +0000 Received: from nalasex01c.na.qualcomm.com (nalasex01c.na.qualcomm.com [10.47.97.35]) by NALASPPMTA02.qualcomm.com (8.17.1.5/8.17.1.5) with ESMTPS id 36CBRQNo005639 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Wed, 12 Jul 2023 11:27:26 GMT Received: from hu-viswanat-blr.qualcomm.com (10.80.80.8) by nalasex01c.na.qualcomm.com (10.47.97.35) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.1118.30; Wed, 12 Jul 2023 04:27:04 -0700 From: Vignesh Viswanathan To: , , , , , , , CC: , , Vignesh Viswanathan Subject: [PATCH net-next 2/3] net: qrtr: ns: Change nodes radix tree to xarray Date: Wed, 12 Jul 2023 16:56:30 +0530 Message-ID: <20230712112631.3461793-3-quic_viswanat@quicinc.com> X-Mailer: git-send-email 2.41.0 In-Reply-To: <20230712112631.3461793-1-quic_viswanat@quicinc.com> References: <20230712112631.3461793-1-quic_viswanat@quicinc.com> MIME-Version: 1.0 X-Originating-IP: [10.80.80.8] X-ClientProxiedBy: nasanex01a.na.qualcomm.com (10.52.223.231) To nalasex01c.na.qualcomm.com (10.47.97.35) X-QCInternal: smtphost X-Proofpoint-Virus-Version: vendor=nai engine=6200 definitions=5800 signatures=585085 X-Proofpoint-GUID: L24iVOAFuh7LFLT1Zfvw4aZCLWNZ38KE X-Proofpoint-ORIG-GUID: L24iVOAFuh7LFLT1Zfvw4aZCLWNZ38KE X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.254,Aquarius:18.0.957,Hydra:6.0.591,FMLib:17.11.176.26 definitions=2023-07-12_06,2023-07-11_01,2023-05-22_02 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 impostorscore=0 clxscore=1015 priorityscore=1501 lowpriorityscore=0 malwarescore=0 spamscore=0 mlxscore=0 mlxlogscore=724 phishscore=0 adultscore=0 suspectscore=0 bulkscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2305260000 definitions=main-2307120102 X-Spam-Status: No, score=-2.8 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_LOW,SPF_HELO_NONE, SPF_PASS,T_SCC_BODY_TEXT_LINE,URIBL_BLOCKED autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1771214721245208430 X-GMAIL-MSGID: 1771214721245208430 There is a use after free scenario while iterating through the nodes radix tree despite the ns being a single threaded process. This can happen when the radix tree APIs are not synchronized with the rcu_read_lock() APIs. Convert the radix tree for nodes to xarray to take advantage of the built in rcu lock usage provided by xarray. Signed-off-by: Chris Lew Signed-off-by: Vignesh Viswanathan Reviewed-by: Simon Horman --- net/qrtr/ns.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/net/qrtr/ns.c b/net/qrtr/ns.c index 039313c3e044..12de671d7992 100644 --- a/net/qrtr/ns.c +++ b/net/qrtr/ns.c @@ -16,7 +16,7 @@ #define CREATE_TRACE_POINTS #include -static RADIX_TREE(nodes, GFP_KERNEL); +static DEFINE_XARRAY(nodes); static struct { struct socket *sock; @@ -73,7 +73,7 @@ static struct qrtr_node *node_get(unsigned int node_id) { struct qrtr_node *node; - node = radix_tree_lookup(&nodes, node_id); + node = xa_load(&nodes, node_id); if (node) return node; @@ -85,7 +85,7 @@ static struct qrtr_node *node_get(unsigned int node_id) node->id = node_id; xa_init(&node->servers); - if (radix_tree_insert(&nodes, node_id, node)) { + if (xa_store(&nodes, node_id, node, GFP_KERNEL)) { kfree(node); return NULL; } From patchwork Wed Jul 12 11:26:31 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Vignesh Viswanathan X-Patchwork-Id: 119118 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:a6b2:0:b0:3e4:2afc:c1 with SMTP id c18csp1098804vqm; Wed, 12 Jul 2023 05:06:14 -0700 (PDT) X-Google-Smtp-Source: APBJJlF3oRTiRX7+Fek2NJ1s+FJ7YLXtXPrEUNd033mE0RcOcjC8Dp7GhJ3a7UdDoZbNgGc1QBdX X-Received: by 2002:a05:6402:2686:b0:51e:5aac:6bad with SMTP id w6-20020a056402268600b0051e5aac6badmr2369094edd.11.1689163573780; Wed, 12 Jul 2023 05:06:13 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1689163573; cv=none; d=google.com; s=arc-20160816; b=smtoPljZeVb3ZPXCXmeNA6fRS7/ikOp/5StH2KzGrZHe+GkmcM5oHsIUsSE355Q0LH uiiAKSsWXSC6d3Xlfv26DYABgHSkx4JMDYt/gM50e9Jil/cfFNguB44pSXYgb1yntk1C TBcU3kERmGTeAnz9Derm7o2ihnbgYeEWtmxE3Vgr+gMqRc2eBMNvBwK7CDAzCrMHo2l3 KfSFhta6cG5U23I8yJBCELSfYJR1+NHEUelTWfZ0fstJ5I38jzM71vBMhhBLSp24DlJ0 GT1dxQ4T5y0JjUV6q9YZ4dQ/EhWY6RyfNjRf+OwlSsxV9sMWfjFAMpnl9/DpOEtTWyzQ 9TJQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=cmLwhl220UufF6mjISkXG0k6vuwgQbfw2yx/QD8D/8Y=; fh=xHrKp8+bUxvfI02f9POZGuAxmAt/WwBN7skM37uOXYU=; b=A27ENksm2TOWzdL7py66AxkjFEQFjCLeuukJLXgNEc360ZensG4506lC/5ZTPexT7C yp0WOggs0rCMQ33SvnDyP61U7QF+hFUCFF1RDU1PDQpj0kqqyeph47RGlVB99txHXBIi E8gvSa2xh/3Ts2r4wNMaT5rHb71EPwvFMsyScbWIqILvg44MD95jH02RmLGlWrLGXLaR bphJX5L8lxbajpyZRBJQUlCkTgK4CKooYk+R/vFQAI3aZanI68bvk2waiFmwz1LYZFvY Ww9YhavvowLiUHfaIje1+BB2M/LQsWeNPMlaNPVxMZk3uXTtXxQWXdFIakaRI5gTs4lz ca0w== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@quicinc.com header.s=qcppdkim1 header.b="O/FXsB2J"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=quicinc.com Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id n23-20020a056402061700b0051df43b5333si4486259edv.330.2023.07.12.05.05.49; Wed, 12 Jul 2023 05:06:13 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@quicinc.com header.s=qcppdkim1 header.b="O/FXsB2J"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=quicinc.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233161AbjGLL1g (ORCPT + 99 others); Wed, 12 Jul 2023 07:27:36 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:51636 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232837AbjGLL1e (ORCPT ); Wed, 12 Jul 2023 07:27:34 -0400 Received: from mx0a-0031df01.pphosted.com (mx0a-0031df01.pphosted.com [205.220.168.131]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id AECCD173C; Wed, 12 Jul 2023 04:27:33 -0700 (PDT) Received: from pps.filterd (m0279863.ppops.net [127.0.0.1]) by mx0a-0031df01.pphosted.com (8.17.1.19/8.17.1.19) with ESMTP id 36C8dJKC002271; Wed, 12 Jul 2023 11:27:27 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=quicinc.com; h=from : to : cc : subject : date : message-id : in-reply-to : references : mime-version : content-transfer-encoding : content-type; s=qcppdkim1; bh=cmLwhl220UufF6mjISkXG0k6vuwgQbfw2yx/QD8D/8Y=; b=O/FXsB2JgQmLCG2UzIOK9VqsKt7DaSZTjw9rPnyEtz9a+rYpvHMiQrcXtVcgLEoAoma0 MkFR5xaAq+4Zo2tcBcovQl+QsLNkMn2Lm/rz1noxIyld2AYwqicu9tCjcd2FWFT/h+Hf KByLZpJNvEjznRO1XbFrXSAp/86sXgVpLm4EqsBwGL/JYVbmhFH49x5etJy4VEGcMXhK JdfzKLd1Saoax+E8JZJLfCu9xrZDHoaXvwruUP2Fn1vUVe2kzPrlxg+ffE+NwlXi8O0k zmyAHXpZORGRmV0qTmoE9BKmsK+INCPIcOUmLg/pVm0w8hp0mukRd/xNo87bjGePWOyD 1Q== Received: from nalasppmta02.qualcomm.com (Global_NAT1.qualcomm.com [129.46.96.20]) by mx0a-0031df01.pphosted.com (PPS) with ESMTPS id 3rsetdsb6t-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Wed, 12 Jul 2023 11:27:27 +0000 Received: from nalasex01c.na.qualcomm.com (nalasex01c.na.qualcomm.com [10.47.97.35]) by NALASPPMTA02.qualcomm.com (8.17.1.5/8.17.1.5) with ESMTPS id 36CBRQNp005639 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Wed, 12 Jul 2023 11:27:26 GMT Received: from hu-viswanat-blr.qualcomm.com (10.80.80.8) by nalasex01c.na.qualcomm.com (10.47.97.35) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.1118.30; Wed, 12 Jul 2023 04:27:08 -0700 From: Vignesh Viswanathan To: , , , , , , , CC: , , Vignesh Viswanathan Subject: [PATCH net-next 3/3] net: qrtr: Handle IPCR control port format of older targets Date: Wed, 12 Jul 2023 16:56:31 +0530 Message-ID: <20230712112631.3461793-4-quic_viswanat@quicinc.com> X-Mailer: git-send-email 2.41.0 In-Reply-To: <20230712112631.3461793-1-quic_viswanat@quicinc.com> References: <20230712112631.3461793-1-quic_viswanat@quicinc.com> MIME-Version: 1.0 X-Originating-IP: [10.80.80.8] X-ClientProxiedBy: nasanex01a.na.qualcomm.com (10.52.223.231) To nalasex01c.na.qualcomm.com (10.47.97.35) X-QCInternal: smtphost X-Proofpoint-Virus-Version: vendor=nai engine=6200 definitions=5800 signatures=585085 X-Proofpoint-ORIG-GUID: HVaK991--dRbY0Zrp94qzLBwEF0GgsyZ X-Proofpoint-GUID: HVaK991--dRbY0Zrp94qzLBwEF0GgsyZ X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.254,Aquarius:18.0.957,Hydra:6.0.591,FMLib:17.11.176.26 definitions=2023-07-12_06,2023-07-11_01,2023-05-22_02 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 bulkscore=0 suspectscore=0 lowpriorityscore=0 impostorscore=0 clxscore=1015 priorityscore=1501 mlxlogscore=999 spamscore=0 mlxscore=0 adultscore=0 malwarescore=0 phishscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2305260000 definitions=main-2307120102 X-Spam-Status: No, score=-2.8 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_LOW,SPF_HELO_NONE, SPF_PASS,T_SCC_BODY_TEXT_LINE,URIBL_BLOCKED autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1771216383835672664 X-GMAIL-MSGID: 1771216383835672664 The destination port value in the IPCR control buffer on older targets is 0xFFFF. Handle the same by updating the dst_port to QRTR_PORT_CTRL. Signed-off-by: Vignesh Viswanathan Reviewed-by: Simon Horman --- net/qrtr/af_qrtr.c | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/net/qrtr/af_qrtr.c b/net/qrtr/af_qrtr.c index 78beb74146e7..41ece61eb57a 100644 --- a/net/qrtr/af_qrtr.c +++ b/net/qrtr/af_qrtr.c @@ -23,6 +23,8 @@ #define QRTR_EPH_PORT_RANGE \ XA_LIMIT(QRTR_MIN_EPH_SOCKET, QRTR_MAX_EPH_SOCKET) +#define QRTR_PORT_CTRL_LEGACY 0xffff + /** * struct qrtr_hdr_v1 - (I|R)PCrouter packet header version 1 * @version: protocol version @@ -495,6 +497,9 @@ int qrtr_endpoint_post(struct qrtr_endpoint *ep, const void *data, size_t len) goto err; } + if (cb->dst_port == QRTR_PORT_CTRL_LEGACY) + cb->dst_port = QRTR_PORT_CTRL; + if (!size || len != ALIGN(size, 4) + hdrlen) goto err;