From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mx0b-0031df01.pphosted.com (mx0b-0031df01.pphosted.com [205.220.180.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 BF143367B67 for ; Thu, 20 Aug 2026 04:44:31 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=205.220.180.131 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1787201073; cv=none; b=B9ZysdzKDnWJw5OGDPAcJOf30RjqgsaZZIO1kuB/d125VejzGggyLBBg4dQtEy8zHBUXvB4Txy3YFoXbMs/cAMrmqL/XctZ7Mt45xqA9NelYWU+uNssJZ7u5F+mB3twoOXF9I1ruTlCFWK1qTuc6kZklCDJQIOlq2B9O0GxuOpU= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1787201073; c=relaxed/simple; bh=Tm7ushPO3+o0tFF8ecTjKX3feR6JwGsZGq1xnLwN6k0=; h=Message-ID:Date:MIME-Version:Subject:To:Cc:References:From: In-Reply-To:Content-Type; b=TPclLcrscMLycyWkYeGtIZv2IOyvXUalY5izDK4qVBERmUMremy74bmqLUYJMoafPXvreo/klzFBOk+WTjbxTdgBv1u1DJ0hAsY/C+6DPbkGAZlO72aTZ9fKm1ZXTACqiNUcSWFH70vrV7ARiphI5W/YjMUl1sntot2ehoMCUsA= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=oss.qualcomm.com; spf=pass smtp.mailfrom=oss.qualcomm.com; dkim=pass (2048-bit key) header.d=qualcomm.com header.i=@qualcomm.com header.b=Oqg64kbl; dkim=pass (2048-bit key) header.d=oss.qualcomm.com header.i=@oss.qualcomm.com header.b=SKhUR220; arc=none smtp.client-ip=205.220.180.131 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject 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.b="Oqg64kbl"; dkim=pass (2048-bit key) header.d=oss.qualcomm.com header.i=@oss.qualcomm.com header.b="SKhUR220" Received: from pps.filterd (m0279868.ppops.net [127.0.0.1]) by mx0a-0031df01.pphosted.com (8.18.1.11/8.18.1.11) with ESMTP id 67JL84Ot1258536 for ; Thu, 20 Aug 2026 04:44:30 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= 4YowyjfOG9pQiJVkE66VCvqOZqFDnt2tLDraq/jeeko=; b=Oqg64kblkgDE9hM+ 5R3gEXL6b2PwZeH7sTYv+rflEPuOfHtuPlgqgtIlyTidJd7zDARS8qKhipyqQ37S /A1W24mvxmALJ7exMbU6+CdVsb+8KcTawjYrKtZ3o2k3XqnNfjNIRs/ilOfC01oE 1t9a22Kr4jdj+L6NdPUMnrEpzPxgkr35MxZ0n+PNhjEloqePxZKk8Yp9/AnI6rj0 GS3X+MYoI/qkjXskgFPVVrT1veiqgl5L/UCrwf3B1PgKmLJQx+oI0u57Ef7raNZq g0RdqqUGQbTRF7lgO7+dqpWrwrushcA+yjeMdlKBM9h8zr1utauJTs19h5n6imS0 APeQ0g== 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 4g5es6335k-1 (version=TLSv1.3 cipher=TLS_AES_128_GCM_SHA256 bits=128 verify=NOT) for ; Thu, 20 Aug 2026 04:44:30 +0000 (GMT) Received: by mail-pj1-f70.google.com with SMTP id 98e67ed59e1d1-3954def0191so3303213a91.3 for ; Wed, 19 Aug 2026 21:44:30 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=oss.qualcomm.com; s=google; t=1787201069; x=1787805869; 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=4YowyjfOG9pQiJVkE66VCvqOZqFDnt2tLDraq/jeeko=; b=SKhUR220CxSNiGD/BkdoZ+fzXM+h6o1UTEUp1e+G0JxLfAh31f4efntqiJvymI5S4C 1fBKYfE5nLmKoTrk8DRsnBXPNd2ZEeyxlq5BqPZCGsXY+JMXxU/Wy0mNqRA3twU5bMU7 RcQ6kcM/KzHV+19pWsmzyLT81EGg74GDe8cHwG67Xei/m2KCcoNho1nE49XnFrG0uSRp j6aSTGZx7A24q6loVj23xeFqh6v0gfeqkUkN4dAu+8SHrmwRR0C9VOaw81rvU2MNUnOz w1PzzzXDHokDOWyCX33EhERydPzYEATe+eFRwkMh6biN2lCmRSFKi2U4b+td7qZ6HbYS o4kA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1787201069; x=1787805869; 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=4YowyjfOG9pQiJVkE66VCvqOZqFDnt2tLDraq/jeeko=; b=lvABr0G8QIq9zM2JOEgIJvpPWY7SoIGxKS5/GSCFU7GC7Yv1agykT24EQzvIGmyD3k yG5Vf2EV+jFZyB4vv9RSdbB4OheRppUetcBOpeyGz6qfPdU8rho9k6caYV22PRA+zmgw qNhUfSai2wI/Zd8wy67X+FGRUQoQzQSV8Ks9Wi+06FhVFO2gAlfZj98IIfEtm8ppKKgh LHVOqoQ7FT4/FI9QdO8Y9eBnqCMKvz1KkgZGo+7CI1kI8P0u9wM7VxYzt4t0ca0Ulid7 tM2gK0qo2nU0gqk+ItCKVgETx3awV/LxB8/ukdKn27/KI1GWju7DfEYjzAJwfsdup17R Dcfw== X-Forwarded-Encrypted: i=1; AHgh+RoCbMTNoQoZOKV/HTAoNG4t7WDtfX+Y2fG0CjjDwro7XSHrIcrcU40TEzZ94feizrD6KyCGmd12MOsARQs=@vger.kernel.org X-Gm-Message-State: AFuF++mzWx+0Uey3ofA2AvhquNUgWlvF0D8S3ZZ65J85aNYK1XSaP5ES VWaYdWQE64Dsbl5fwlAfU3q57C1jYMUA7O6dljrJmndCg4vDlxhehb/EY6GoJKOMxDBrOmmIPth mIb2lhiBnvi1AoBp/uiZ6Eq9a4FhKniIFhfKt/efhx6M7IrUlOAaywGZzuTRDkkvqpvo= X-Gm-Gg: AR+sD12qNHCACxwwe6p28FbiPtIlsq5c7GRxibRqFfVHdOn8KGmo8D+dDwebo2vpwWZ w/b+sV8rXFnVIcgXHGrI8Jy+ZiBA1qKj21D7KpG9j4tQIMKh3iWpzjdh9uyvYR2QqtKmwSxhrIM C8UVqRo1Y4TB1y0//V7lxEuV3LcTM4vcXOjqqy/aLft+NNP6Lys/8bmpz7r9MSiixXm7QmCuBg5 y/mzcXsAQwrcCkL4KPclwTn6i+LlAS+CUOFC+BUx9xiTofo5IPWI2smTjMpL86p0DxF3/SHQuSF ptINVy5sWLAhMVLofJB8mVQiAn+V8p9Jgy1p/Q18Fc9Z4KQzhBFTBMIL3nu9WXaT4o9316Vbh+k 4rEHI+A2wueic8fJ2o+LZRU1Jn48IQg== X-Received: by 2002:a17:90b:2f06:b0:37f:e177:f58 with SMTP id 98e67ed59e1d1-3958108a0f9mr19146132a91.9.1787201069227; Wed, 19 Aug 2026 21:44:29 -0700 (PDT) X-Received: by 2002:a17:90b:2f06:b0:37f:e177:f58 with SMTP id 98e67ed59e1d1-3958108a0f9mr19146062a91.9.1787201068747; Wed, 19 Aug 2026 21:44:28 -0700 (PDT) Received: from [10.219.56.166] ([202.46.23.19]) by smtp.gmail.com with ESMTPSA id 5a478bee46e88-327bef7a0easm14338932eec.12.2026.08.19.21.44.24 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Wed, 19 Aug 2026 21:44:28 -0700 (PDT) Message-ID: Date: Thu, 20 Aug 2026 10:14:22 +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 Subject: Re: [PATCH v2] misc: fastrpc: fix double-free in fastrpc_map_attach() error path To: Yifei Gao , Srinivas Kandagatla , Amol Maheshwari Cc: Greg Kroah-Hartman , Arnd Bergmann , Abel Vesa , Dmitry Baryshkov , linux-arm-msm@vger.kernel.org, dri-devel@lists.freedesktop.org, linaro-mm-sig@lists.linaro.org, linux-kernel@vger.kernel.org, stable@vger.kernel.org References: <20260806235056.456341-1-gyf161023@gmail.com> <20260811225102.1077841-1-gyf161023@gmail.com> Content-Language: en-US From: Ekansh Gupta In-Reply-To: <20260811225102.1077841-1-gyf161023@gmail.com> Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 7bit X-Authority-Analysis: v=2.4 cv=E5/9Y6dl c=1 sm=1 tr=0 ts=6a86862e cx=c_pps a=0uOsjrqzRL749jD1oC5vDA==:117 a=j4ogTh8yFefVWWEFDRgCtg==:17 a=IkcTkHD0fZMA:10 a=Sv0fKeRqtYgA:10 a=s4-Qcg_JpJYA:10 a=VkNPw1HP01LnGYTKEx00:22 a=u7WPNUs3qKkmUXheDGA7:22 a=ZpdpYltYx_vBUK5n70dp:22 a=VwQbUJbxAAAA:8 a=pGLkceISAAAA:8 a=EUspDBNiAAAA:8 a=GpFdYKwLFXUddJV2vI0A:9 a=QEXdDO2ut3YA:10 a=mQ_c8vxmzFEMiUWkPHU9:22 X-Proofpoint-GUID: p0wOrLQfrC0MXcw4LzK9betxIdVnz73Q X-Proofpoint-Spam-Details-Enc: AW1haW4tMjYwODIwMDAzMSBTYWx0ZWRfX9ha3Wqi7Fea+ 4eRxpOiUYZCfHrHEzGak3fdXujc9K1t3aL+KrIRr8YUgawbrGn8ONTv0typwlnttSVyuZ5P6LPh HQAN9/oQr0nG4AKNPMn543Co1Wfy7sZrbJ313JsoaYaGwWUW/WN+wQ6p7KkrQnNE3claFSbibrQ VQP7VUeb9+VqW0URq0vJ4EOTvrBPGWsqkdLivsESBom5crYgtXJDn8AsFE5HyLk4JVxk5McmoF9 DP8tJ50CZet5ohzoUux7GfI3jT87MjM5Nc2frxEGsjBiZYMFYJrnZrQbFy47Zl+kx+9Qrj8JZrZ KPXfB4afrbboEp2qBqESZTvSRtL/5MOeiufN4pachWFfZxyTxMBkZnJtj0R0m0jWxTNGvthpHcD pb+7TdbNcyTxKtuvehpHeTwU+2lJJuQHh/ArwvBrJL26DbzCHw5YLkQyoAdIl6YQ2fFFMmapJYB GurOiUkJaUH/Mr9q8jA== X-Proofpoint-ORIG-GUID: p0wOrLQfrC0MXcw4LzK9betxIdVnz73Q X-Proofpoint-Spam-Info: AW1haW4tMjYwODIwMDAzMSBTYWx0ZWRfX6kAKUMpRBYEX Y4dJpILk4EmitCnsjTrctNHMe+puNCtIYeHxIuTf9Min+Um1bv426PpfHa++XYUEx1GwLh2WemF G0z0pYI+E/eRBZmSh50WOtQMwJCTk14= X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.293,Aquarius:18.0.1176,Hydra:6.1.134,FMLib:17.12.100.49 definitions=2026-08-19_06,2026-08-19_02,2025-10-01_01 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 impostorscore=0 clxscore=1015 adultscore=0 priorityscore=1501 suspectscore=0 phishscore=0 bulkscore=0 malwarescore=0 lowpriorityscore=0 spamscore=0 classifier=typeunknown authscore=0 authtc= authcc= route=outbound adjust=0 reason=mlx scancount=1 engine=8.22.0-2606150000 definitions=main-2608200031 On 12-08-2026 04:21, Yifei Gao wrote: > map->table is assigned right after dma_buf_map_attachment_unlocked() > succeeds. The two failure checks that follow, the len > map->size test > and, where subsystem VMIDs are configured, a failed qcom_scm_assign_mem(), > jump to map_err with map->table already set. > > map_err manually calls dma_buf_detach() and dma_buf_put() and then falls > through to fastrpc_map_put(). Since that change the error path tail is > fastrpc_map_put() -> fastrpc_free_map(), and fastrpc_free_map() already > unmaps, detaches and puts the dma-buf whenever map->table is set. > The two operations therefore run twice: the second dma_buf_put() drops an > extra reference on map->buf, and dma_buf_unmap_attachment_unlocked() > dereferences the map->attach already freed by the manual dma_buf_detach(). > kref_init() sets the refcount to 1 with no intervening get, so the final > fastrpc_map_put() frees the map synchronously and the redundant cleanup is > deterministic. > > The len > map->size branch is reachable by an unprivileged process via > FASTRPC_IOCTL_MEM_MAP with an fd whose dma-buf is smaller than the > requested length, before any DSP invocation. > > Route both map->table-is-set failure branches to get_err instead of > map_err, so fastrpc_free_map() is the single owner of the > unmap/detach/put sequence. map_err is retained for the > dma_buf_map_attachment_unlocked() failure, which is reached with > map->table still NULL and an attachment that fastrpc_free_map() will not > clean up, so its dma_buf_detach()/dma_buf_put() must still run manually. > > Fixes: 334f1a1cbe03 ("misc: fastrpc: Use fastrpc_map_put in fastrpc_map_create on fail") > Cc: stable@vger.kernel.org > Assisted-by: Claude:claude-opus-4-8 > Signed-off-by: Yifei Gao Reviewed-by: Ekansh Gupta