Received: by 2002:a05:7412:3b8b:b0:fc:a2b0:25d7 with SMTP id nd11csp2590804rdb; Mon, 12 Feb 2024 09:30:36 -0800 (PST) X-Forwarded-Encrypted: i=3; AJvYcCXQtxaN/cWc0OmkfmtFa3kkl/AIvrsYlSF25o4mb/xgjn1lDR3wBL3RDvYEuyGipy9/o+EFGj0nPFfrm7Bv66/CeCKesKWWZFrbMk6jMQ== X-Google-Smtp-Source: AGHT+IFuQ8I+KQ4o6Vh9sfHTShMaBFIV4ybxhWwaE1E9rTKwo3BCQ1cMll8bf65uBYwlCxsAsQNU X-Received: by 2002:a17:906:80c:b0:a3c:91e:a7d7 with SMTP id e12-20020a170906080c00b00a3c091ea7d7mr5056309ejd.60.1707759036356; Mon, 12 Feb 2024 09:30:36 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1707759036; cv=pass; d=google.com; s=arc-20160816; b=ZPQg1AL1b8PLFZ/q4VqcjTrrgragHUq9Pxef6K+j6yHDhUsQWf+6TrOfrg6AxJbsLZ D5vPx+ejJyR11KsARaQjYWJw0ysIJtcZshAvLuUTJ8lZpgc+g+8nQddUHdyxUi1UV+wd ZMxIL+DJYdrKs77gaslYgVFcD0TjR9VPYnISKl93347chbwRy0NcJZIXEml+/W0iwRnN hvQd00YqfgMugrvCcTbnwNiZQoUynJux25nWHSIGU7moFLPj/fRxZ6gwaaV/Io/r4tHp GBY3Voh9vwo1K3DZ1Rr4GOUT5ay92Z+OlsrRQVNxAX5+ul/riW+Ju8TlH9g1Z6koXXIt 6uuQ== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:in-reply-to:content-language:references :cc:to:subject:from:user-agent:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:date:message-id:dkim-signature; bh=mFP93yrNCBsj8NEPJw3QpaEx/+1X39HZCQ2vhvFATU4=; fh=G5IXJ1DNzn5GVnwCZFB+QxJANb6l9mzjQU/eyqZHhjg=; b=VaXuksx9sKSNViZs1OaZlEtRbe3leg+/P/li/r8/kKhRjoe96JWBr+fGDTHUamMIFn aX7Va48zX7WgghsqST2fjmKNEenUih+z8UNZofva6YV2YOccXgnv7UzPEwFjMLKFoNTE /vPK3ileaYuA6LuVjnbuh5P08zK/S2mG4MsrJ0shA4d/uumnvAU/uv9aq7nwunkkOzBz wrlj6P+SYLocoXPbSCZCNGDB7NKFTbUcQSWNrHlMN8nXRPjODLrKDBbmqKnRzWbUQa16 vayuVykvClSpoo60DSRmqBgndj1MqklpV7mlLchly9O+eD9gu/4QsBUMVmmcNm3fAfYT oJtw==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@quicinc.com header.s=qcppdkim1 header.b=XhoQwY6c; arc=pass (i=1 spf=pass spfdomain=quicinc.com dkim=pass dkdomain=quicinc.com dmarc=pass fromdomain=quicinc.com); spf=pass (google.com: domain of linux-kernel+bounces-62100-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) smtp.mailfrom="linux-kernel+bounces-62100-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=quicinc.com X-Forwarded-Encrypted: i=2; AJvYcCXGUaMk9q1AW3lGTK6OK9hAO8D+yDfGxFdN2vroie+0KP3sb5zquUmc/VV4uePR7Pd3I6UzKE39ewV3PClFJogIK92s+uOSEhoEnDg33A== Return-Path: Received: from am.mirrors.kernel.org (am.mirrors.kernel.org. [147.75.80.249]) by mx.google.com with ESMTPS id v5-20020a170906564500b00a37abcce965si380820ejr.230.2024.02.12.09.30.36 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 12 Feb 2024 09:30:36 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-62100-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) client-ip=147.75.80.249; Authentication-Results: mx.google.com; dkim=pass header.i=@quicinc.com header.s=qcppdkim1 header.b=XhoQwY6c; arc=pass (i=1 spf=pass spfdomain=quicinc.com dkim=pass dkdomain=quicinc.com dmarc=pass fromdomain=quicinc.com); spf=pass (google.com: domain of linux-kernel+bounces-62100-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) smtp.mailfrom="linux-kernel+bounces-62100-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=quicinc.com Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by am.mirrors.kernel.org (Postfix) with ESMTPS id 1BAA41F2375A for ; Mon, 12 Feb 2024 17:30:36 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 0744B3EA7A; Mon, 12 Feb 2024 17:30:25 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=quicinc.com header.i=@quicinc.com header.b="XhoQwY6c" Received: from mx0a-0031df01.pphosted.com (mx0a-0031df01.pphosted.com [205.220.168.131]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 8D21A3F8D0; Mon, 12 Feb 2024 17:30:22 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=205.220.168.131 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707759024; cv=none; b=bh6TpMOWeZ6iabcPs5WiDEoYu4YlTibLgJsCh7XgCScp9TBSarGk/Gh3k+eC6lsRM3d0EnOGjeWcQ6NFy1akcokcvI+FA+oAXgD1Q3+sa7v2jGL1jbEqPJAO3gEyyuro9ML0PyK5ouROI3QUISXmNGg9Ch16D82RVCPfYpAHjyc= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707759024; c=relaxed/simple; bh=ZHz2/Ii2ezqNSyAK1WHFHID3r78PJgY7A/ovJL/qKVs=; h=Message-ID:Date:MIME-Version:From:Subject:To:CC:References: In-Reply-To:Content-Type; b=jmTSR4mlhIzMxwCKl7bgT+36ScVYSpnRNXsjGd74trdIFiYtvRpGXqy/Y1yTi4CrmiG7XZjZclNG27VRu42ycFHyMnT6kMrCCV9mfJ9DAOpy86u1yMBGHFXVjsYmdOjCmMSnOOkmTgDRSuk2MqK2c+YFcNRVN9Br1TlkXUdVjhQ= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=quicinc.com; spf=pass smtp.mailfrom=quicinc.com; dkim=pass (2048-bit key) header.d=quicinc.com header.i=@quicinc.com header.b=XhoQwY6c; arc=none smtp.client-ip=205.220.168.131 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=quicinc.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=quicinc.com Received: from pps.filterd (m0279867.ppops.net [127.0.0.1]) by mx0a-0031df01.pphosted.com (8.17.1.24/8.17.1.24) with ESMTP id 41CDWMM2029846; Mon, 12 Feb 2024 17:30:01 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=quicinc.com; h= message-id:date:mime-version:from:subject:to:cc:references :in-reply-to:content-type:content-transfer-encoding; s= qcppdkim1; bh=mFP93yrNCBsj8NEPJw3QpaEx/+1X39HZCQ2vhvFATU4=; b=Xh oQwY6cFCoNr21eQv9CMDQAUN7ZiaLKUEdtxPi3MgdyjEdOuwPlLIHKWehZ9u8xCL sjxkBxx6GIaP3s+LGEywfy87A0U4WWgXCWcyA9/hlHAUqlKHR/TaBDULqOeTZRzo tMltdFXGh7to9XIi8kwIcSPUO4Z/axOC5RdlyyiGW2763+2dGDql2TYioJOQwdlv ze9sVhH4Nq3a8jRUD3jwLcihDTMdZwlGPPlxfkP3UHNrcdzvW5ZJCHw/7Lfdj5a6 cvMKKBUAxyQmtoBgx9aYxkzvkA8cXWh+UjKa9hXh+UKHWFrw2aeS42E+QRVdMMgS cbQvmBe8NPNwKQk/fbDA== Received: from nasanppmta05.qualcomm.com (i-global254.qualcomm.com [199.106.103.254]) by mx0a-0031df01.pphosted.com (PPS) with ESMTPS id 3w7ju78t7h-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Mon, 12 Feb 2024 17:30:01 +0000 (GMT) Received: from nasanex01c.na.qualcomm.com (nasanex01c.na.qualcomm.com [10.45.79.139]) by NASANPPMTA05.qualcomm.com (8.17.1.5/8.17.1.5) with ESMTPS id 41CHU0wC027045 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Mon, 12 Feb 2024 17:30:00 GMT Received: from [10.216.55.125] (10.80.80.8) by nasanex01c.na.qualcomm.com (10.45.79.139) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.1118.40; Mon, 12 Feb 2024 09:29:53 -0800 Message-ID: <13da9cd9-218d-4b3f-98f8-62edcd91a23e@quicinc.com> Date: Mon, 12 Feb 2024 22:59:50 +0530 Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 User-Agent: Mozilla Thunderbird From: Pratyush Brahma Subject: Re: [PATCH v4 03/10] iommu/arm-smmu-qcom: Add support for TBUs To: CC: , , , , , , , , , , , , , , , , , , References: <20240201210529.7728-4-quic_c_gdjako@quicinc.com> Content-Language: en-US In-Reply-To: <20240201210529.7728-4-quic_c_gdjako@quicinc.com> Content-Type: text/plain; charset="UTF-8"; format=flowed Content-Transfer-Encoding: 7bit X-ClientProxiedBy: nasanex01a.na.qualcomm.com (10.52.223.231) To nasanex01c.na.qualcomm.com (10.45.79.139) X-QCInternal: smtphost X-Proofpoint-Virus-Version: vendor=nai engine=6200 definitions=5800 signatures=585085 X-Proofpoint-ORIG-GUID: 9AwD145O5tY5kb5MEBPsEImeSD339Gw- X-Proofpoint-GUID: 9AwD145O5tY5kb5MEBPsEImeSD339Gw- X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.272,Aquarius:18.0.1011,Hydra:6.0.619,FMLib:17.11.176.26 definitions=2024-02-12_14,2024-02-12_03,2023-05-22_02 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 impostorscore=0 mlxlogscore=999 lowpriorityscore=0 spamscore=0 clxscore=1011 priorityscore=1501 mlxscore=0 malwarescore=0 suspectscore=0 phishscore=0 adultscore=0 bulkscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.19.0-2401310000 definitions=main-2402120133 Hi The following patch would introduce a use-after-free bug which was found during KASAN testing on qcm6490 with the patch. diff --git a/drivers/iommu/arm/arm-smmu/arm-smmu-qcom.c b/drivers/iommu/arm/arm-smmu/arm-smmu-qcom.c index 8b04ece00420..ca806644e6eb 100644 --- a/drivers/iommu/arm/arm-smmu/arm-smmu-qcom.c +++ b/drivers/iommu/arm/arm-smmu/arm-smmu-qcom.c @@ -1,12 +1,14 @@ // SPDX-License-Identifier: GPL-2.0-only /* * Copyright (c) 2019, The Linux Foundation. All rights reserved. + * Copyright (c) 2024 Qualcomm Innovation Center, Inc. All rights reserved */ #include #include #include #include +#include #include #include "arm-smmu.h" @@ -446,6 +448,7 @@ static struct arm_smmu_device *qcom_smmu_create(struct arm_smmu_device *smmu, const struct device_node *np = smmu->dev->of_node; const struct arm_smmu_impl *impl; struct qcom_smmu *qsmmu; + int ret; if (!data) return ERR_PTR(-EINVAL); @@ -469,6 +472,12 @@ static struct arm_smmu_device *qcom_smmu_create(struct arm_smmu_device *smmu, qsmmu->smmu.impl = impl; qsmmu->cfg = data->cfg; + INIT_LIST_HEAD(&qsmmu->tbu_list); + mutex_init(&qsmmu->tbu_list_lock); + ret = devm_of_platform_populate(smmu->dev); // smmu has been freed by devm_krealloc() above but is being accessed here again later. This causes use-after-free bug. + if (ret) + return ERR_PTR(ret); + return &qsmmu->smmu; } Can it be done like below? qsmmu->smmu.impl = impl; qsmmu->cfg = data->cfg; + INIT_LIST_HEAD(&qsmmu->tbu_list); + mutex_init(&qsmmu->tbu_list_lock); + ret = devm_of_platform_populate(qsmmu->smmu.dev);// Using the struct to which smmu was copied instead of freed ptr. Thanks, Pratyush