From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=205.220.168.131 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796027453; b=mzvB4EcTZgSjzuMYZxPaHBC7UQ51TGmpcjRfVtPLG9y+KKH55A2MqB2eFRPHZtfdX0zj shS5zeVFHV6li6aKuP+pJ0hzYO5Q6ISrAA2I3Rl2P0AWWFveSsxSmtCvbYA1lVo0QoK3/ 8Z+eKVfbLS05q7l2xqedqrmQvBjrUrofoxpumhRZT5xPkHVPXnO5LMRIdtb4Tkhmy+I/M aoTAGTRhtTuDSRj6h5Id7+3fPLZpgFxo64ktXM4QjGpaMbT7414ODP/+ohOLFD3FkbEBo pzNpp5K/kgG4jvb/m+rO5AUHN4PFNXYI5JCP27zJTm7+Gir95srx068RUlyoBE2uNyA== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796027453; h=DMARC-Filter:Received:DKIM-Signature:Received:Received: DKIM-Signature:X-Google-DKIM-Signature:X-Forwarded-Encrypted: X-Gm-Message-State:X-Gm-Gg:X-Received:X-Received:Received:Message-ID: Date:MIME-Version:User-Agent:Subject:To:Cc:References: Content-Language:From:In-Reply-To:Content-Type: Content-Transfer-Encoding:X-Proofpoint-Spam-Details-Enc: X-Proofpoint-ORIG-GUID:X-Proofpoint-GUID:X-Authority-Analysis: X-Proofpoint-Spam-Info:X-Proofpoint-Virus-Version: X-Proofpoint-Spam-Details; bh=Cez4rn4/SgeUh4nkcUN+YC/OP7M2ZbZ/zMrB7hkwmDQ=; b=HdkR5qKOj44BmJxKWhru+c4dttGsHnYQFbvqTS6sGA8j2Ftq6tCjwn4CsJbyrMOyVrX7 iFBKYPuxtfDHj4x6M9qhE72JtGR1D9b8HdA+yxtk8OQXjZ2b73+25vF4Bp0tK1lDonuch vojlyRrDS6scHJJ63wsQSoE+J65Ct+Mh8FtnUjhsgffKMHikjUSe1mFWsWjPeHLWNR/EF i7v9Ks3OIrRqEd9SgKJcxCMEYhUph3SCtEbSUf9kMVyRbamY3JU+WFd+86GiyE5LM++ZV dnoD5eMmxpYcehdHPTNGdN14dQ+pwthfwbB5POM1wuYATSneDK/frkMhmbbwpQfgWRQ== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass header.from=oss.qualcomm.com; spf=pass smtp.mailfrom=oss.qualcomm.com; dkim=pass header.d=qualcomm.com header.i=@qualcomm.com header.a=rsa-sha256 header.s=qcppdkim1 header.b=dHYDqG60; dkim=pass header.d=oss.qualcomm.com header.i=@oss.qualcomm.com header.a=rsa-sha256 header.s=google header.b="TPTv/URr"; arc=none smtp.remote-ip=205.220.168.131 Received: from mx0a-0031df01.pphosted.com (mx0a-0031df01.pphosted.com [205.220.168.131]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (prime256v1) server-digest SHA256) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 35D50606A334 for ; Mon, 30 Nov 2026 08:30:53 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org 35D50606A334 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=oss.qualcomm.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=oss.qualcomm.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=qualcomm.com header.i=@qualcomm.com header.a=rsa-sha256 header.s=qcppdkim1 header.b=dHYDqG60; dkim=pass (2048-bit key) header.d=oss.qualcomm.com header.i=@oss.qualcomm.com header.a=rsa-sha256 header.s=google header.b=TPTv/URr Received: from pps.filterd (m0279864.ppops.net [127.0.0.1]) by mx0a-0031df01.pphosted.com (8.18.1.11/8.18.1.11) with ESMTP id 6AU7DgUI265140 for ; Mon, 30 Nov 2026 08:30:52 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=qualcomm.com; h= cc:content-transfer-encoding:content-type:date:from:in-reply-to :message-id:mime-version:references:subject:to; s=qcppdkim1; bh= Cez4rn4/SgeUh4nkcUN+YC/OP7M2ZbZ/zMrB7hkwmDQ=; b=dHYDqG60TvKuzC7b VsdDL1aA+CZh8mZdX+sI0yPzAiuqtcRhsgFOdlH6u5eczsJaVYxbpfWExGrUgG2j +JdKhMn6FGuzxmMrXpp9JBcuRKs5mW2+KuTSu1KzpgvdjyWEI+n8AJc9hYN4dcj1 74ENqBW9jRj//RF6eaXuRFFPYY/OyLrzWCa2p1YP1bQAHZVKsO4ql1O15KPEgpq3 421pdzXu8f3cNFOIL2UuoPS8zKZJA/QLCXv/yOuCKUHBR2Z8jRFRkx6XjgUq6hOP ARTFgxpd/HY2PEzvjiLKWoQUOln1fHMLCeQVyVcd6iMnz50CRafjOaOF4ut939S5 n0VZKQ== Received: from mail-pj1-f70.google.com (mail-pj1-f70.google.com [209.85.216.70]) by mx0a-0031df01.pphosted.com (PPS) with ESMTPS id 4j94jrg8x2-1 (version=TLSv1.3 cipher=TLS_AES_128_GCM_SHA256 bits=128 verify=NOT) for ; Mon, 30 Nov 2026 08:30:52 +0000 (GMT) Received: by mail-pj1-f70.google.com with SMTP id 98e67ed59e1d1-3acc98e3b3cso7689053a91.3 for ; Mon, 30 Nov 2026 00:30:52 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=oss.qualcomm.com; s=google; t=1796027451; x=1796632251; darn=vger.kernel.org; h=content-transfer-encoding:content-type:in-reply-to:from :content-language:references:cc:to:subject:user-agent:mime-version :date:message-id:from:to:cc:subject:date:message-id:reply-to :content-type; bh=Cez4rn4/SgeUh4nkcUN+YC/OP7M2ZbZ/zMrB7hkwmDQ=; b=TPTv/URrNdHuw0Kj7G3trniep6lOLG0kORUA5zCedvXxEp8xv6WhTq5Us32yWMd2sP YxD+xVPi6AlmwAFxUP6ba44+ZSP6K3oUmwNzwK2PJO4Jv1qibHHqdU2kJxFYNFqCfW+H sC9VEik2K7EIRNB4Pln+0lSc1G014DQU4cWMj0IXCXvxpgCDoSFL/PB46oQ1ui3CMXi/ PwplKnv2Z4mfL8Oh/+W7KXIcwYmSXllEo2nGZTuiuEAh2zg3IwEnaLnEtjW4aMo4mH3i /1nYlmtPCVHyABrO6Mt457WpSUzKF0Qjd1L0XlMpTLArc9+ubj2J1g3MfU01cQ/7R73v ICdA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20260707; t=1796027451; x=1796632251; h=content-transfer-encoding:content-type:in-reply-to:from :content-language:references:cc:to:subject:user-agent:mime-version :date:message-id:x-gm-gg:x-gm-message-state:from:to:cc:subject:date :message-id:reply-to:content-type; bh=Cez4rn4/SgeUh4nkcUN+YC/OP7M2ZbZ/zMrB7hkwmDQ=; b=qgEgvPAXjyIuANRdCO87wuhZtYIp6rs9NmCVn7MTUtXcLJTTZolTGfeY51Edb+Y8UG 41YiAdBWX6Nqrlm8xb8DF+ZIYC1I+30EN4vlAiC3jWckYIr+8KOxFtyJrwW5eTqUXrjW OPJbGsXXjKxyLfovMoTh08Ni+H+b220LLwC234lXBcJPs+AZn4MTr/08gNcQxq/OLV6+ 0TKUf6ykBnntZ3FipbfYPMIGxVyAoabMbdYHJyevX0C9sMwDL9vg9aL8sF4t/IjC2Fpr rBvPEbxpGSl/HMW1qKODmBv4YWQMQBrdoTUIM1sSP9C/NZGa5qhMInTF1uLmE3XsubGf xVTg== X-Forwarded-Encrypted: i=1; AL+hErHgwHv21zcypjVv20nAFihAYBU4k7HAWCE5H/N9q9edJtaheNW53POyODFIS1159bqqAaV/nafMI58PGGw=@vger.kernel.org X-Gm-Message-State: APuU4Z+XkW97Y1Abm8Mc+Mv2kwNaeMh9c1HN5GglN9JACL8xDBUXYvmE Y3DV2/ub3lhcdaTFMSkoQ4yluFLTlgIDWk8NhJbqVWGkGjhKoeTDjbvOH0Q9kq7+QYGFkGLj6nT /D8qT3YqEkznElEJshLiiQ/WF/TTA/Z8dOmV9z9WDrLo1AcYO9w1viYHOxAxoZ/TKWvg= X-Gm-Gg: AZFdTZe73x7aAHMJEqpOQ8B4TDCSObMCG/nZte1KXa+qgee69fixwlIjDeK7uJcTjVf hTmM7s5KgKVZbueuI/kSimzE/Ctlwp2z/CLER3/1DZ/GaSymB4pv2zwEnWVsMdZ3G5mQrP4DO+6 UaGjbEHo8+GOib7z5narCe2YoZOlMhMbcByOZ4mtnWLDHv4fsOxiQP7iX8FGG0MjDpiw7ZxMWD2 EgLC0uVNkrfASb4ctVaUgMr87d9QiyxCvnv5C8zIiCn56uIUlu6GQM0bBK3mwtld40o0QjjD1cA LHtMas4gFCgRvExamKVi79yA82we1YbzYW3JvRA4UG7lfB3MztipF3otIEEn7fxj4WRZOgiCGVY buN4D+NPfvmb8/In8sySKCDs3VdXQDsNUJ7gh3/qKbRlgkw6MpG2yJyyr819vQEJ1hBhYT0agNa Yt X-Received: by 2002:a17:90a:e705:b0:3a7:f4d:b23d with SMTP id 98e67ed59e1d1-3b41c97ca8fmr30051703a91.52.1796027451379; Mon, 30 Nov 2026 00:30:51 -0800 (PST) X-Received: by 2002:a17:90a:e705:b0:3a7:f4d:b23d with SMTP id 98e67ed59e1d1-3b41c97ca8fmr30051684a91.52.1796027450842; Mon, 30 Nov 2026 00:30:50 -0800 (PST) Received: from [10.219.56.59] ([202.46.23.19]) by smtp.gmail.com with ESMTPSA id 98e67ed59e1d1-3b495035339sm38465780a91.0.2026.11.30.00.30.47 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Mon, 30 Nov 2026 00:30:50 -0800 (PST) Message-ID: <6f4a51b1-a9be-40a5-9961-da2a786656e4@oss.qualcomm.com> Date: Mon, 30 Nov 2026 14:00:46 +0530 X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: [PATCH] misc: fastrpc: fix use-after-free of fastrpc_user in dma-buf ops To: Shawn Guo , Srinivas Kandagatla Cc: Arnd Bergmann , Greg Kroah-Hartman , Kumari Pallavi , Dmitry Baryshkov , linux-arm-msm@vger.kernel.org, dri-devel@lists.freedesktop.org, linux-kernel@vger.kernel.org, stable@vger.kernel.org References: <20261130045227.4150363-1-shengchao.guo@oss.qualcomm.com> Content-Language: en-US From: Ekansh Gupta In-Reply-To: <20261130045227.4150363-1-shengchao.guo@oss.qualcomm.com> Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 7bit X-Proofpoint-Spam-Details-Enc: AW1haW4tMjYxMTMwMDAzMyBTYWx0ZWRfXwhFdP4vD8+35 HWDowbRRwRKWrW8fV3rsv148RBLL5r0ihjC+XeBRTtN6/4uGkzhFZhFbHWOgkdM7SAjDhiLhZ7l YdKPeud8sD7NjfA6zcED8eaydmoPPm6q2qAOa77KY8A9hYag0+92mkAMExSPUs3olTut+XJXHi6 kFLGK2mjV8q+fOiRLPWuwhT7SZGctZOblAjjoCgMyWPhDZmnxH29mJPdyMEyKfB6YtJBEoPVBOX B/MyMUKRFgEB5G4hOyf1IAZ87w+DHlvonXWlN1c89zeqgRoVXCW+YaPuajYX8vIptPtAVEc9vxu dUTrgmLmdSig5n727N0OrUHbYOwpmCi+lxeTKoukqNusJoFJLXrIEx4QubpCjhZ6qrHWMYF98g8 G+JQ6HqN850CoUp4AZy5oiGmwRDww32OEE4RzopLTyZpQAS9mLM4diNUQe7EGNMG+Z0Ko1NsVPx Mck66ZdSFtQudpK9w/A== X-Proofpoint-ORIG-GUID: ZGu20Cvj-_749h8CQ_Z6Inb1tVbNY8ST X-Proofpoint-GUID: ZGu20Cvj-_749h8CQ_Z6Inb1tVbNY8ST X-Authority-Analysis: v=2.4 cv=NepzRGD4 c=1 sm=1 tr=0 ts=6b0d343c cx=c_pps a=0uOsjrqzRL749jD1oC5vDA==:117 a=j4ogTh8yFefVWWEFDRgCtg==:17 a=IkcTkHD0fZMA:10 a=zJRp6_cAMcgA:10 a=s4-Qcg_JpJYA:10 a=VkNPw1HP01LnGYTKEx00:22 a=u7WPNUs3qKkmUXheDGA7:22 a=DJpcGTmdVt4CTyJn9g5Z:22 a=VwQbUJbxAAAA:8 a=EUspDBNiAAAA:8 a=iCSWBTg4hsONGXlMuvYA:9 a=QEXdDO2ut3YA:10 a=mQ_c8vxmzFEMiUWkPHU9:22 X-Proofpoint-Spam-Info: AW1haW4tMjYxMTMwMDAzMyBTYWx0ZWRfX9IY/MMqwhjM9 6eiO/cSI3zhV5vxrhG277+OeZZ5zhvpyjAXhBhHcQzSDcRNIyR6Cu+fEtYxH1tiYpKQ+ZAMi4w/ vNhsYqTnx8C7TE3IIcunx8Xx8uAKCoA= X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.293,Aquarius:18.0.1176,Hydra:6.1.138,FMLib:17.12.100.49 definitions=2026-11-30_02,2026-11-27_03,2025-10-01_01 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 impostorscore=0 lowpriorityscore=0 malwarescore=0 phishscore=0 priorityscore=1501 suspectscore=0 clxscore=1015 adultscore=0 spamscore=0 bulkscore=0 classifier=typeunknown authscore=0 authtc= authcc= route=outbound adjust=0 reason=mlx scancount=1 engine=8.22.0-2611040001 definitions=main-2611300033 On 30-11-2026 10:22, Shawn Guo wrote: > A buffer allocated with FASTRPC_IOCTL_ALLOC_DMA_BUFF is exported as a > dma-buf that can outlive the fastrpc file it was allocated from, but > it holds no reference on that file's fastrpc_user. The dma-buf > release, attach and mmap ops nevertheless dereference buf->fl->cctx > to strip the SID bits from the DSP address. If the fastrpc fd is > closed first, e.g. when the remoteproc is stopped, the dma-buf release > reads freed memory: > > Unable to handle kernel NULL pointer dereference at virtual address 00000000000005e9 > ... > Workqueue: events delayed_fput > pc : fastrpc_release+0x34/0x70 [fastrpc] > lr : dma_buf_release+0x40/0xa0 > Call trace: > fastrpc_release+0x34/0x70 [fastrpc] (P) > dma_buf_release+0x40/0xa0 > dentry_kill+0xec/0x2d4 > finish_dput+0x1c/0x90 > dput+0x3c/0x40 > __fput+0x110/0x2f0 > delayed_fput+0x4c/0x68 > > Taking a reference on fastrpc_user from the dma-buf would create a > cycle, as fl->maps can hold the same dma-buf and is only released when > fastrpc_user is freed. Instead, save the handle returned by > dma_alloc_coherent() in the buffer and use it in the DMA API calls, so > that the dma-buf ops no longer need fastrpc_user. Remove > fastrpc_ipa_to_dma_addr(), which has no users left. > > The crash was seen once on Nord Ride when stopping the ADSP remoteproc, > among many test cycles. Whether it happens depends on the dma-buf being > released after the fastrpc fd and on the freed fastrpc_user having been > reused. > > Fixes: 1d94ce8996d7 ("misc: fastrpc: Add support for new DSP IOVA formatting") > Cc: stable@vger.kernel.org # v7.0+ > Signed-off-by: Shawn Guo > --- > drivers/misc/fastrpc.c | 21 +++++++-------------- > 1 file changed, 7 insertions(+), 14 deletions(-) > > diff --git a/drivers/misc/fastrpc.c b/drivers/misc/fastrpc.c > index be183e55faa1..67a16b2368ba 100644 > --- a/drivers/misc/fastrpc.c > +++ b/drivers/misc/fastrpc.c > @@ -230,6 +230,8 @@ struct fastrpc_buf { > struct device *dev; > void *virt; > dma_addr_t dma_addr; > + /* Handle from dma_alloc_coherent(), without the SID bits */ > + dma_addr_t dma_handle; Nit: can you add comment for dma_addr also? Something like: /* DSP-visible IOVA, may include SID bits */ Reviewed-by: Ekansh Gupta > u64 size; > /* Lock for dma buf attachments */ > struct mutex lock; > @@ -371,14 +373,6 @@ struct fastrpc_user { > struct kref refcount; > }; > > -/* Extract SMMU PA from consolidated IOVA */ > -static inline dma_addr_t fastrpc_ipa_to_dma_addr(struct fastrpc_channel_ctx *cctx, dma_addr_t iova) > -{ > - if (!cctx->soc_data->sid_pos) > - return 0; > - return iova & GENMASK_ULL(cctx->soc_data->sid_pos - 1, 0); > -} > - > /* > * Prepare the consolidated iova to send to DSP by prepending the SID > * to smmu PA at the appropriate position > @@ -482,8 +476,7 @@ static void fastrpc_buf_free(struct fastrpc_buf *buf) > if (!buf) > return; > > - dma_free_coherent(buf->dev, buf->size, buf->virt, > - fastrpc_ipa_to_dma_addr(buf->fl->cctx, buf->dma_addr)); > + dma_free_coherent(buf->dev, buf->size, buf->virt, buf->dma_handle); > kfree(buf); > } > > @@ -515,6 +508,7 @@ static int __fastrpc_buf_alloc(struct fastrpc_user *fl, struct device *dev, > return -ENOMEM; > } > > + buf->dma_handle = buf->dma_addr; > *obuf = buf; > > return 0; > @@ -896,8 +890,7 @@ static int fastrpc_dma_buf_attach(struct dma_buf *dmabuf, > return -ENOMEM; > > ret = dma_get_sgtable(buffer->dev, &a->sgt, buffer->virt, > - fastrpc_ipa_to_dma_addr(buffer->fl->cctx, buffer->dma_addr), > - buffer->size); > + buffer->dma_handle, buffer->size); > if (ret < 0) { > dev_err(buffer->dev, "failed to get scatterlist from DMA API\n"); > kfree(a); > @@ -945,8 +938,8 @@ static int fastrpc_mmap(struct dma_buf *dmabuf, > > dma_resv_assert_held(dmabuf->resv); > > - return dma_mmap_coherent(buf->dev, vma, buf->virt, > - fastrpc_ipa_to_dma_addr(buf->fl->cctx, buf->dma_addr), size); > + return dma_mmap_coherent(buf->dev, vma, buf->virt, buf->dma_handle, > + size); > } > > static const struct dma_buf_ops fastrpc_dma_buf_ops = {