Received: by 2002:a05:6358:7058:b0:131:369:b2a3 with SMTP id 24csp2057518rwp; Thu, 13 Jul 2023 23:18:30 -0700 (PDT) X-Google-Smtp-Source: APBJJlFRnmkcVMtI/FGpp15DCe3vpGmCC2xYnJ0Igw3JruRKLmcta7s+MC5pxPgtrR8bt8e8AgRF X-Received: by 2002:a05:6402:517a:b0:51e:527b:4170 with SMTP id d26-20020a056402517a00b0051e527b4170mr3408264ede.24.1689315510247; Thu, 13 Jul 2023 23:18:30 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1689315510; cv=none; d=google.com; s=arc-20160816; b=UihvTpANUG7mW0ufrhLei5jqL3nfuauw7OxpS1qytfhVoHF7BC1UOUmNrByjhm+Yqy AIJnqGodR7MFz3v9FxPr74rEo8P26x0qGYb0+4GV4z0MNb0xJ5ZwO4MxVjEaTIA2x5ew f9+s7g5GgtYloAXfwebZ16dHlegUaEfZc1I0ljYVGLrASZQTO5zkyU0DVZK1hVIEHwjD y8e8BdlXwKrsxIo7GQD0QVO0SCG2/r6D0YuSD4Xv0FZndCWBPm4VDXW55dJ6rLhZ9Pom 1xsKRwQohyKdl6nFqmmqqRub/F6k6y29SGqCNXa/3C3zy2sUYDqKE+yZLvcHaZAJeeax 0Q6A== 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=4V6PabsTD743AVM7/i0irVzfSDXf6+mOjdWKUlKl+sE=; fh=UyXiZHKKOzf5PfA4c8dbtgez+KVEy2wWlVez0NMUQQE=; b=szo4/FRBiLLW4mOsmt9S39BSvm/hHcYP2tm56fFToMLSIS501nCPDmPscjyt5z4AoJ 5l9A2Q7daTUZkFeM3fTL3ge2bqA3lgJb6Nnb7gnMPph94VTeono2Kukg6k4Q/BYWUpG/ goFbgXIRjm5HIAL2buBD1GH0pF6fS9XaVvYRCHfS6tt5R2H+LBM0Gcn8Du/MfvzSeOf9 xQrcEdiy6Vey1egJe8OdmVhR4V/uulS0XNtNoveEB9DVTeLMyj8+5C58hZTSt4z0DPwy qzwTtrETk8r6Zt2SdmuOtfM4tEPhzgmQNxnIRQ+OFBzQKslSxEIvgyGB2u7d8PN/p1lg 0FLw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@quicinc.com header.s=qcppdkim1 header.b=hbZFrnZf; 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 Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id k1-20020a05640212c100b0051d882750d2si8649859edx.569.2023.07.13.23.18.06; Thu, 13 Jul 2023 23:18:30 -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=hbZFrnZf; 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 S235012AbjGNF7e (ORCPT + 99 others); Fri, 14 Jul 2023 01:59:34 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:42690 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234888AbjGNF7a (ORCPT ); Fri, 14 Jul 2023 01:59:30 -0400 Received: from mx0a-0031df01.pphosted.com (mx0a-0031df01.pphosted.com [205.220.168.131]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 746FC2D4B; Thu, 13 Jul 2023 22:59:29 -0700 (PDT) Received: from pps.filterd (m0279864.ppops.net [127.0.0.1]) by mx0a-0031df01.pphosted.com (8.17.1.19/8.17.1.19) with ESMTP id 36E4hiFq010162; Fri, 14 Jul 2023 05:59:22 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=4V6PabsTD743AVM7/i0irVzfSDXf6+mOjdWKUlKl+sE=; b=hbZFrnZfTyqAVCB2NqLhPEBMr0gyyt0aOvJokmRfBOPfc2VWwrvCh0T6rEmBgfmT2YDs 9DfQnTKn+c59y4jfdVnosrKLoNh7ahomi7Er580/gSVs3GJHdxiR1+tMneNiyLY636mw RWndDjR6aa/1CyScVpMqUzBSke3T32XeCofiSLUIB9vwrjcyKfbDkzt86uq7ogW+Q0rX bMXKyo5juonMnff6tK8Fi3ZHEHJQnlqNNqkQJAtBnJcwHrOzs9KTMq1Z6a/O3BxDFf87 mQQ4q7uKfGEndevh+uQqORzlrXAAXqvqYoCajGeC8H16tymucKT7yGLm4WQnN8HfPmtW Iw== Received: from nalasppmta05.qualcomm.com (Global_NAT1.qualcomm.com [129.46.96.20]) by mx0a-0031df01.pphosted.com (PPS) with ESMTPS id 3rtptxh0bv-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Fri, 14 Jul 2023 05:59:21 +0000 Received: from nalasex01c.na.qualcomm.com (nalasex01c.na.qualcomm.com [10.47.97.35]) by NALASPPMTA05.qualcomm.com (8.17.1.5/8.17.1.5) with ESMTPS id 36E5xLR5027059 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Fri, 14 Jul 2023 05:59:21 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; Thu, 13 Jul 2023 22:59:15 -0700 From: Vignesh Viswanathan To: , , , , , , , CC: , , Vignesh Viswanathan , Simon Horman Subject: [PATCH V2 net-next 2/3] net: qrtr: ns: Change nodes radix tree to xarray Date: Fri, 14 Jul 2023 11:28:45 +0530 Message-ID: <20230714055846.1481015-3-quic_viswanat@quicinc.com> X-Mailer: git-send-email 2.41.0 In-Reply-To: <20230714055846.1481015-1-quic_viswanat@quicinc.com> References: <20230714055846.1481015-1-quic_viswanat@quicinc.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Content-Type: text/plain 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: I6C_sCFiXEixFJr6H4mJsprZ0uaebvzL X-Proofpoint-ORIG-GUID: I6C_sCFiXEixFJr6H4mJsprZ0uaebvzL 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-14_02,2023-07-13_01,2023-05-22_02 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 mlxlogscore=784 priorityscore=1501 clxscore=1015 impostorscore=0 bulkscore=0 mlxscore=0 phishscore=0 suspectscore=0 spamscore=0 adultscore=0 lowpriorityscore=0 malwarescore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2306200000 definitions=main-2307140055 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 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 af28d9e6b53f..b1db0b519179 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; } -- 2.41.0