From mboxrd@z Thu Jan 1 00:00:00 1970 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 8CB51222580 for ; Mon, 4 May 2026 06:24:23 +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=1777875864; cv=none; b=a7+XOVD3fV4s7kZ8mvXs2pz7exSk1BoqiPrhn1aPq2ReSv7G/xWyukx6ixbufmc9n95gzZcHPQnGJ5uoDUd5QIm05B5Snf/wRTLzla4eZGU28co6l7wYYLlofP1N2syY2BYlVFk6YmAi70OY8Y1MtGf5V/2apS3E+3R44W6pMeQ= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1777875864; c=relaxed/simple; bh=bcTkj7z6FKGNVOHa6c1rxzRLMWKib6fRDMdYaX8gzSU=; h=Message-ID:Date:MIME-Version:Subject:To:Cc:References:From: In-Reply-To:Content-Type; b=pLyureuWkATOUKXZe44jG9w0pmffQ+4a0eiOLct7ZrZQsG/s2UnG4kNZ0p7svVJ2hNea30MLyeqFH/CdhxaH1DRa7hoD2UCMQTkt/7E0DumUv3k1gmk97FgorSg9N9UMADwixZWQ59f6kWK4x9dymZtEj/USkXRqWsu4g9l2XSQ= 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=j9makQ2V; dkim=pass (2048-bit key) header.d=oss.qualcomm.com header.i=@oss.qualcomm.com header.b=cCcLpQjZ; arc=none smtp.client-ip=205.220.168.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="j9makQ2V"; dkim=pass (2048-bit key) header.d=oss.qualcomm.com header.i=@oss.qualcomm.com header.b="cCcLpQjZ" Received: from pps.filterd (m0279866.ppops.net [127.0.0.1]) by mx0a-0031df01.pphosted.com (8.18.1.11/8.18.1.11) with ESMTP id 6446DFlP2431713 for ; Mon, 4 May 2026 06:24:23 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= TNyRR0rELfmD0/XXE4YuZsBRKd2/cuC3uluE9QU1vLU=; b=j9makQ2VCl7+a92H Ms359avakOcDGNz8ZJfzNQmBfTNA946xGHczlH1u6/6vSkDQkPY4jefB3GjtSIq6 Fh5DSTC7ycKn6SYkIHN2O3x6Dwj0VrrEMzuSoFvLnbA/UPcfXrWszK3c5D7KRTjY Cx6xeG4+uRVJUIvkKPeEExDpqxzA0YMDmG327Qu4oWSloLysl6GNdZaKgDDiCC3l WZM+2VX2q7wO99Q+4pB7Z11FKIpnDxh1adEAU3VWQspVaSeg4OTyHKaQmwnFNfpn PcYy93sNJBnQV91mpvmhR1VGVZ/M+V+aKqRZxAKtyjJwOcmyRwUIg94RIpbMPHb4 oCfZ7A== Received: from mail-pl1-f200.google.com (mail-pl1-f200.google.com [209.85.214.200]) by mx0a-0031df01.pphosted.com (PPS) with ESMTPS id 4dwaj7ce3v-1 (version=TLSv1.3 cipher=TLS_AES_128_GCM_SHA256 bits=128 verify=NOT) for ; Mon, 04 May 2026 06:24:22 +0000 (GMT) Received: by mail-pl1-f200.google.com with SMTP id d9443c01a7336-2b9a6d84522so58988075ad.2 for ; Sun, 03 May 2026 23:24:22 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=oss.qualcomm.com; s=google; t=1777875862; x=1778480662; darn=vger.kernel.org; h=content-transfer-encoding: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; bh=TNyRR0rELfmD0/XXE4YuZsBRKd2/cuC3uluE9QU1vLU=; b=cCcLpQjZEdw1EPmTIsL0A2oMoXIAq3oKwkn01qeiiU4fVaELGnxBzqlOgZrSqs96Rk yR9nvlVNwuX8ExbxXzqY4JpQ4WVoDn5vpGcGVCX5cOL5I6iHkOXtfWf34cXuFWTIxjbF nyUdt/nef5tmzikwCstoFPFm7bj8otOf26CdtPO3gtlO8NmytUesmO/iDevboV2kSA80 c+P2g++ywOA6mVHapWyu+av6zkJPHt53nzBV2aTIThjD146gK5N10kOkgR/cKx48UBAm P1N72cbqE9/sZmXXX6SYxbKNv/iD+qVhZy90ksPmFaexGYW4QyWYH5HUrkhu8F3AC35u G4lQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1777875862; x=1778480662; h=content-transfer-encoding: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; bh=TNyRR0rELfmD0/XXE4YuZsBRKd2/cuC3uluE9QU1vLU=; b=REgwmFD5qHZLW9N/NfXdMQ/Akdq3WVdfy589rUgyTXkbwPILHKK+STNA1UYsa22eSu yGxo+v4KXvK1yyRAa30RrE4ozKDkYJGcXq5oWj0FrVuokFQUH7SDml5JOvV5e4UnpJBY XvAp3JFs0WnRKTR3COxbxOY6rp4mLjOc0IvkaMkFu7t23DSRCsbX8jusq740fzA6cdkN /6zoCi2jwiLfBX2DypVRthdqgUadyDKnCvqKJVlWhqNv2/jE4Ucgvm/SkwIl2FmRsVSr FFGuQovnOEaeUaCvATbbL/PVCJqr7Wbxhkc3ff/WtpSCmn/jKm3RK0ycgZfixQ3wTP3+ mMFQ== X-Forwarded-Encrypted: i=1; AFNElJ9Lrg5hpq8v5FbNib7rH5xIOjXNcZM6VxV7P7qjOAe1GLFXwZmzVyXNpDFmxiCvdHQ1ipNGoRFUje+74Ss=@vger.kernel.org X-Gm-Message-State: AOJu0Yy0+/1X8cKHPe0cCTq2Ub8cL20rfhElxlWr8Q0CnU4md3d1jjgf NahFGoXhD4MmP7NfdemMnbxcPxDuputpWKMSeiXtphjNyPI87JbDahkqcydekIhCID4n61o9D0A TSAyRbh0JMXcHCn7GOe3uEYKGh7z8ZF15zvYvYAyRp7AcAH95Kb0AZ39RKTOSo+XX8JE= X-Gm-Gg: AeBDieszBKevlD/vSZ8usmERozU1zITMaKL+6QsYCsTucvz8khZzqYAR+Obw52RCuTs c2aBAqBXmDwO2PVooZ/B5naf8nR1pdhXcLX3berq8dbo1KygAYKptRIGcb4s5lVw0yuno7xoAa0 6xa5wnn8q8rMylPnxNTa8ugW5nO0Jrla+2o/WOZobyatGI1JbB7rsIx0sPAN0KX1hJGhIGFGjZ/ OKLjWeEYFJax6jhZ0xpV9kSpHf0TnhAi75EGauqni7ZR5DMOrUYSrL3LU90TEP90SIGV7WP3qYn GGCQmYE7SOgD7LjnhXO9tjDyDMrM1/zfsvHgBCCvCvlBtflCRCEF2OWbggCbVlD4BVTx9MOqYbr z23iGWsf2eCKGZJSuTtbzvjJ2ACbe6NjkN13ozbAlEWAOP1n7L3/1K/YI49mfU9C8NZCTpN7STv a5CX1oyVS1hcj5heQqzsZj X-Received: by 2002:a17:902:d506:b0:2b2:4d36:7aa with SMTP id d9443c01a7336-2b9f280fe1emr84277365ad.35.1777875862068; Sun, 03 May 2026 23:24:22 -0700 (PDT) X-Received: by 2002:a17:902:d506:b0:2b2:4d36:7aa with SMTP id d9443c01a7336-2b9f280fe1emr84277065ad.35.1777875861559; Sun, 03 May 2026 23:24:21 -0700 (PDT) Received: from ?IPV6:240e:400:e18:23b6:48a3:6006:2608:1239? ([240e:400:e18:23b6:48a3:6006:2608:1239]) by smtp.gmail.com with ESMTPSA id d9443c01a7336-2b9cae0f67esm96626775ad.51.2026.05.03.23.24.16 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Sun, 03 May 2026 23:24:21 -0700 (PDT) Message-ID: Date: Mon, 4 May 2026 14:24:12 +0800 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] cpufreq: qcom-cpufreq-hw: Fix possible double free To: Guangshuo Li , "Rafael J. Wysocki" , Viresh Kumar , Manivannan Sadhasivam , linux-arm-msm@vger.kernel.org, linux-pm@vger.kernel.org, linux-kernel@vger.kernel.org Cc: stable@vger.kernel.org, zhongqiu.han@oss.qualcomm.com References: <20260501190005.504962-1-lgs201920130244@gmail.com> Content-Language: en-US From: Zhongqiu Han In-Reply-To: <20260501190005.504962-1-lgs201920130244@gmail.com> Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit X-Proofpoint-GUID: X1tO-c1jwZPIABS6wDgQ_AGsl5EE-B2h X-Proofpoint-Spam-Details-Enc: AW1haW4tMjYwNTA0MDA2NiBTYWx0ZWRfX7vqLILfcJHCK 6wVwBgTS1mAhHbnDJ5KiVrSmBk3GGZaUS2fM/CJTZwwW9xI6bMwGW6k4H1b+LIzEYBVSL3IrkpM 8G/dNp0ay0EArrkJ3jAfM+j2slEeCEoMYB9c4MqMeLNIAWZ8wFwl8uWYAzS36Zo5ESzkol8yHXQ CgJuVT2Y3vXT3tiALabV5/PRi2OaUVGWFWAAE2CS/Tn36fWi/sxR3/W8RERFEtQoIIujh0C/L0R ROQowJyArru/QYjqQ2C4HyVAjyNceLOUsrnBnBJ3VDme91BzdJrc88rPfehppoYEOeIDKVzXIe0 Kx5KMak1b5l38KYjd/iwq2Bq/d2LE74MBDkbcRnClKPm4J7BTSHKJvusLhOMgYr8gHpLMShPwDr 2DRKKy/rdfNZDA/9D4omIUgGONSQ6utluIcl1rYmJMRGEoB9+P37VcXbha8Pke+hgUeCIDXvCJ8 gBf9C201vDFTW2PIo4g== X-Authority-Analysis: v=2.4 cv=csirVV4i c=1 sm=1 tr=0 ts=69f83b96 cx=c_pps a=IZJwPbhc+fLeJZngyXXI0A==:117 a=xqWC_Br6kY4A:10 a=IkcTkHD0fZMA:10 a=NGcC8JguVDcA:10 a=s4-Qcg_JpJYA:10 a=VkNPw1HP01LnGYTKEx00:22 a=u7WPNUs3qKkmUXheDGA7:22 a=YMgV9FUhrdKAYTUUvYB2:22 a=c92rfblmAAAA:8 a=pGLkceISAAAA:8 a=VwQbUJbxAAAA:8 a=EUspDBNiAAAA:8 a=g1ydD-XOTWB8Hi5v_0UA:9 a=QEXdDO2ut3YA:10 a=uG9DUKGECoFWVXl0Dc02:22 a=GvGzcOZaWPEFPQC_NcjD:22 X-Proofpoint-ORIG-GUID: X1tO-c1jwZPIABS6wDgQ_AGsl5EE-B2h X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.293,Aquarius:18.0.1143,Hydra:6.1.51,FMLib:17.12.100.49 definitions=2026-05-04_02,2026-04-30_02,2025-10-01_01 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 priorityscore=1501 clxscore=1015 phishscore=0 bulkscore=0 impostorscore=0 suspectscore=0 adultscore=0 malwarescore=0 spamscore=0 lowpriorityscore=0 classifier=typeunknown authscore=0 authtc= authcc= route=outbound adjust=0 reason=mlx scancount=1 engine=8.22.0-2604200000 definitions=main-2605040066 On 5/2/2026 3:00 AM, Guangshuo Li wrote: > qcom_cpufreq.data is allocated with devm_kzalloc() in probe() as an > array of per-domain data. qcom_cpufreq_hw_cpu_init() stores a pointer to > one element of this array in policy->driver_data. > > qcom_cpufreq_hw_cpu_exit() currently calls kfree() on policy->driver_data. > This is not valid because the memory is devm-managed. For the first > domain, this can free the devm-managed allocation while the devres entry > is still active, leading to a possible double free when the platform > device is later detached. For other domains, the pointer may refer to an > element inside the array rather than the allocation base. > > Remove the kfree(data) call and let devres release qcom_cpufreq.data. > > This issue was found by a static analysis tool I am developing. > > Fixes: 054a3ef683a1 ("cpufreq: qcom-hw: Allocate qcom_cpufreq_data during probe") > Cc: stable@vger.kernel.org > Signed-off-by: Guangshuo Li Hi Guangshuo, Thanks for fixing this. Yes, qcom_cpufreq.data is devm-managed and policy->driver_data points into that per-domain array, so freeing it from ->exit() is invalid (and for non-zero domains it can even be a non-base pointer). Dropping kfree(data) is the correct fix. Reviewed-by: Zhongqiu Han Regarding the sashiko.dev AI-generated review comments[1]: all four issues raised are pre-existing possible problems in the driver and were not introduced by this patch. - The data->policy dangling pointer via the clock provider path - The race window in qcom_cpufreq_hw_cpu_offline() between cancel_delayed_work_sync() and disable_irq_nosync() - The unowned IRQ operations when request_threaded_irq() fails - The freq_table/OPP leak on cpu_init() error paths They are potentially valid observations worth addressing, but should be handled as separate follow-up patches. [1]https://sashiko.dev/#/patchset/20260501190005.504962-1-lgs201920130244%40gmail.com > --- > drivers/cpufreq/qcom-cpufreq-hw.c | 1 - > 1 file changed, 1 deletion(-) > > diff --git a/drivers/cpufreq/qcom-cpufreq-hw.c b/drivers/cpufreq/qcom-cpufreq-hw.c > index ea9a20d27b8f..ef19faedbfec 100644 > --- a/drivers/cpufreq/qcom-cpufreq-hw.c > +++ b/drivers/cpufreq/qcom-cpufreq-hw.c > @@ -578,7 +578,6 @@ static void qcom_cpufreq_hw_cpu_exit(struct cpufreq_policy *policy) > dev_pm_opp_of_cpumask_remove_table(policy->related_cpus); > qcom_cpufreq_hw_lmh_exit(data); > kfree(policy->freq_table); > - kfree(data); > } > > static void qcom_cpufreq_ready(struct cpufreq_policy *policy) -- Thx and BRs, Zhongqiu Han