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 42ECE2E7179 for ; Mon, 30 Mar 2026 04:00:32 +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=1774843233; cv=none; b=G6WtVpCCYvxtS4QsAf/xV7SKt7TmmDuTLJa2PZra/LEZdugJ9YQnYiRK3/ct/Lf1pIzLDbdDv/nyvb7Pxs+DB6m1c5u+1lQvYCy4ytkEYbWbaxZ5mC6qTn3MYaEQTtHM3LzwoZSlcgQV9oM7Inpkvq2+13aaPH+GD7qYOPDkxSU= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1774843233; c=relaxed/simple; bh=IQ4Hv7CmFJDeTRg3ksKaW7dAb8F2JaANB1UcQ0r6UHc=; h=Message-ID:Date:MIME-Version:Subject:To:Cc:References:From: In-Reply-To:Content-Type; b=P270MrOM05rVNzY3aFEsHihKnuAYjE7dmKJIIxYfcMVvYcOKO0W7zWMfNrr74u7dKyKKyxA+lB1uaxfZb931nQWEHJyjDZ22ct9/le+Aqdaj82oiDbJogzA4M68/217QAaRwzb9fc8Iqd7Bu7qsi3oxCFI7KA2lYc6vaLW6Pid8= 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=daHPCWMY; dkim=pass (2048-bit key) header.d=oss.qualcomm.com header.i=@oss.qualcomm.com header.b=Jult7jYG; 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="daHPCWMY"; dkim=pass (2048-bit key) header.d=oss.qualcomm.com header.i=@oss.qualcomm.com header.b="Jult7jYG" Received: from pps.filterd (m0279871.ppops.net [127.0.0.1]) by mx0a-0031df01.pphosted.com (8.18.1.11/8.18.1.11) with ESMTP id 62TMx6ac1694358 for ; Mon, 30 Mar 2026 04:00:31 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= nsc1vnHePPh/q8rVFB3VpPaeFGpcpTqB5sVGBQPhgwc=; b=daHPCWMYK39cOcxE Tmw5+Nb97BSKaX483K3b5PomPURPt+P5VRKgwoQc1MURo1+EXqC55YMGVb6BQPZd b3UiiKrJGQp5QPLRO74h97y9IkC6jHzsCldj7TzW8l6koxEvrPFNJ1NZ5mmRQmEf dJptLluXwc2yXykRn3e7juHP5P1XUTTR18xw1bNR8hsCM6zBY53+vWSVrkoPldA5 tL+vr3ks3cM3QXD8v+D2WiPwY/E1zCroR4Y5B/ZAuMgSI4SFx8enijTOHx7i5MZt UKiFfnqot0czktnts28Q4EG9dvfEPhBDMxlqkgTSFRYVFaJKQDNLyRzNZ3gMKtJD w4RAAQ== 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 4d66jwmcv8-1 (version=TLSv1.3 cipher=TLS_AES_128_GCM_SHA256 bits=128 verify=NOT) for ; Mon, 30 Mar 2026 04:00:29 +0000 (GMT) Received: by mail-pl1-f200.google.com with SMTP id d9443c01a7336-2adc527eaf5so34729215ad.0 for ; Sun, 29 Mar 2026 21:00:29 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=oss.qualcomm.com; s=google; t=1774843228; x=1775448028; 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=nsc1vnHePPh/q8rVFB3VpPaeFGpcpTqB5sVGBQPhgwc=; b=Jult7jYGVZIDaCdRrmWdWYHQt6Z+MSBNfnqyrnYk6Zx7JK/Vt4iQo+YrUGQxMnGvDJ Q3BmbzrMXf1vw/CaDrJw7GbvIyIB5S8fh9sw/BRmcUJBsDg8bnwOAnqDPKYUS49h6+63 AWFRg0iWP68YhKgh4nWDcuFsILwKcPteWhFUIXYd84WsVyAssUBMC3PClJvtdDJ84ROu ZFzObhKGsEPLrFTcHi3zyAJoG6qp6Qhi7BnDjWbofe9JB0GC1ZONVKG7MdsNDlJTLMhd 9nHDjSro0C2nEuZKfanlG+83auwt4mlEjZQZq8+uFHingwr8WJd5kRiYk23jA4xlHE1F YjQQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1774843228; x=1775448028; 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=nsc1vnHePPh/q8rVFB3VpPaeFGpcpTqB5sVGBQPhgwc=; b=Pk6efqj4ERXXJBRsiQjtXw644ZQM1oPrPv+hW+8jpBF5CKf9UYruv9T22RpcDhqbee ba1/Jb9MKMz8ueGLWZoZu/+5tsKojZ6MgnbSOPNIzMREM+Y/HZ9amayT46ZA2WPAEWck J+6EaL+8QSb5JGZAJozPgpSoOnBxdsx4rZ1oMYRHM5BF3etceRuz1haDph7XE4W8iz9f qyARpE/HIxdhScGQo5cpMB21A1SI2cVxGqie2Vf5zKSVIlRNFl/iye5iuIABri++BBqu 6s/TOn3Wpsb3ivxT7tc7IsFFlXuBRdic9YzITDl3aXfXJoPzaij9fgk7pKEppOAc8Xj/ Yf4g== X-Forwarded-Encrypted: i=1; AJvYcCVmNe46Y9lb/BTscJX5uU9siT+HXIwphodjgjlmVBDLRbulGwTIg6p0ipUqSPzUDOdg52a1Lmel8WdwoGg=@vger.kernel.org X-Gm-Message-State: AOJu0YxbOGhCD7bDi0mg9e3XPR2W00NJyahwoZMHUfBJwQwqEYgPEiy7 3MGCrw2xNNTMOSzYJTjwo+tmIjRtbYwlPjud9sBS77tO54Wugx6L3vJ+W9+0/qt1/DlpGBhQ+zR fXAZWAIJQjOr2WRmsXjOriIh16yHKlkpfQ+Bp9tOld4mWidzIGOIvy7Ap2Y/4fud3XmA= X-Gm-Gg: ATEYQzzVd+cH6w3rFY//l2PLgOGypyZenKYgJpnpX+9xHHkqjm4keqvuyHyA+l4oATJ AeshalA7DU5NlY0kyDdgSnw1a7XRuSDnW3eDywMY3MctoXLlJhOG2U3cYkdTBgN58ry3r7XL6GH 0z5doANxzyIM/UqpIPnzxe0tkZ0nXV9y9WrGSlaopPFrwVg2Giq8thvOEzwB8S9MB5FXsHz0zkX Nb+QGuKi0Bk81LHWoT17lbsIQSlp9bS6Nb+z/3VSpSaJfBjfx10+DBn3P6a5/YwW0q1/Z7aYGpS iSziDIhyAMcGTDBoKRrC7vrVqyyj2S1QqyZ4mcrs4ELNKcuV5clUSoexn7PG/NDbiPCLnwL+hwc +1SJSb0UBWrab3PxNKPyLsAXj6skLmDKLUbpXszYYWCfD1znzVUGptXH6UHxOj74rPRgahHATKC LO7eSGMTivw2igcco= X-Received: by 2002:a17:903:2f82:b0:2b2:497e:3f6d with SMTP id d9443c01a7336-2b2497e4b68mr52426575ad.8.1774843228211; Sun, 29 Mar 2026 21:00:28 -0700 (PDT) X-Received: by 2002:a17:903:2f82:b0:2b2:497e:3f6d with SMTP id d9443c01a7336-2b2497e4b68mr52421765ad.8.1774843222826; Sun, 29 Mar 2026 21:00:22 -0700 (PDT) Received: from [10.133.33.66] (tpe-colo-wan-fw-bordernet.qualcomm.com. [103.229.16.4]) by smtp.gmail.com with ESMTPSA id d9443c01a7336-2b24265aa9fsm61399435ad.20.2026.03.29.21.00.19 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Sun, 29 Mar 2026 21:00:22 -0700 (PDT) Message-ID: <6eff4517-cc4b-4f2f-8e39-6cfe8b18c4dc@oss.qualcomm.com> Date: Mon, 30 Mar 2026 12:00:17 +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 v8 2/2] cpufreq: Add boost_freq_req QoS request To: "zhenglifeng (A)" , Pierre Gondois , linux-kernel@vger.kernel.org Cc: Huang Rui , "Gautham R. Shenoy" , Mario Limonciello , Perry Yuan , "Rafael J. Wysocki" , Viresh Kumar , linux-pm@vger.kernel.org, zhongqiu.han@oss.qualcomm.com References: <20260326204404.1401849-1-pierre.gondois@arm.com> <20260326204404.1401849-3-pierre.gondois@arm.com> <8261d970-ccaa-494c-91c7-6ebecce010ac@oss.qualcomm.com> Content-Language: en-US From: Zhongqiu Han In-Reply-To: Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 8bit X-Authority-Analysis: v=2.4 cv=I8dohdgg c=1 sm=1 tr=0 ts=69c9f55d cx=c_pps a=IZJwPbhc+fLeJZngyXXI0A==:117 a=nuhDOHQX5FNHPW3J6Bj6AA==:17 a=IkcTkHD0fZMA:10 a=Yq5XynenixoA:10 a=s4-Qcg_JpJYA:10 a=VkNPw1HP01LnGYTKEx00:22 a=u7WPNUs3qKkmUXheDGA7:22 a=3WHJM1ZQz_JShphwDgj5:22 a=LmuV2tqYhPxcIh0MdAwA:9 a=3ZKOabzyN94A:10 a=QEXdDO2ut3YA:10 a=uG9DUKGECoFWVXl0Dc02:22 X-Proofpoint-GUID: i3t6ERCDq4k_JQZwNgBHY_4YIJnXHez6 X-Proofpoint-ORIG-GUID: i3t6ERCDq4k_JQZwNgBHY_4YIJnXHez6 X-Proofpoint-Spam-Details-Enc: AW1haW4tMjYwMzMwMDAyNyBTYWx0ZWRfX9BjhEPoQF71+ KH4Vu1tVdviOk6I04cASvyfNcihnICtsN1BnJXDP0q2EHCqJ6kbobyAmAmNPbrnoierp1mz48Xj o4uURAOeo8AyJUXXqdDGk14+FcKeg8bVuk0N0yRKxkFO6GvrNtB0N2SfDjUrFoijvvBoqgzohQs okSvxNSGG8X/wne1kUhSKoSVQWDr2xpgrZ+lQ7MVdIRRrS1ddnDbOAebP4U+tXHSOetMNGTVgWA 60qh/8PxhK9GNtiu7h8I+Ek0xFSQHRm8P9+keFRuXJOAjr/etY6ChLXZ3cBqp0OjhUpYEoDf6n/ ekZrCC9fCplnyXiCu4rAcrUBbLuz3nBectv6K7k+sByEG0SEd6fgKqXGyer8XjzYg/4TAn85HWA tiqFrqB7J+HA89SOpE6CnkqadCb8BhGnCs4Q7f6bx8kyXmebbM84Cf2f4HTeKC1rT2v1hqy7tvv VxGZwrUhTsw8rTorC0g== 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-03-29_05,2026-03-28_01,2025-10-01_01 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 priorityscore=1501 clxscore=1015 spamscore=0 adultscore=0 suspectscore=0 malwarescore=0 lowpriorityscore=0 impostorscore=0 bulkscore=0 phishscore=0 classifier=typeunknown authscore=0 authtc= authcc= route=outbound adjust=0 reason=mlx scancount=1 engine=8.22.0-2603050001 definitions=main-2603300027 On 3/30/2026 10:10 AM, zhenglifeng (A) wrote: > On 3/29/2026 5:00 PM, Zhongqiu Han wrote: >>> @@ -1377,6 +1386,7 @@ static void cpufreq_policy_free(struct cpufreq_policy *policy) >>>       } >>>         freq_qos_remove_request(policy->min_freq_req); >>> +    freq_qos_remove_request(policy->boost_freq_req); >>>       kfree(policy->min_freq_req); >>>         cpufreq_policy_put_kobj(policy); >>> @@ -1445,26 +1455,38 @@ static int cpufreq_policy_online(struct cpufreq_policy *policy, >>>       cpumask_and(policy->cpus, policy->cpus, cpu_online_mask); >>>         if (new_policy) { >>> +        unsigned int count; >>> + >>>           for_each_cpu(j, policy->related_cpus) { >>>               per_cpu(cpufreq_cpu_data, j) = policy; >>>               add_cpu_dev_symlink(policy, j, get_cpu_device(j)); >>>           } >>>   -        policy->min_freq_req = kzalloc(2 * sizeof(*policy->min_freq_req), >>> +        count = policy->boost_supported ? 3 : 2; >>> +        policy->min_freq_req = kzalloc(count * sizeof(*policy->min_freq_req), >>>                              GFP_KERNEL); >>>           if (!policy->min_freq_req) { >>>               ret = -ENOMEM; >>>               goto out_destroy_policy; >>>           } >>>   +        if (policy->boost_supported) { >>> +            policy->boost_freq_req = policy->min_freq_req + 2; >>> + >>> +            ret = freq_qos_add_request(&policy->constraints, >>> +                           policy->boost_freq_req, >>> +                           FREQ_QOS_MAX, >>> +                           policy->cpuinfo.max_freq); >>> +            if (ret < 0) { >>> +                policy->boost_freq_req = NULL; >>> +                goto out_destroy_policy; >>> +            } >>> +        } >>> + >>>           ret = freq_qos_add_request(&policy->constraints, >>>                          policy->min_freq_req, FREQ_QOS_MIN, >>>                          FREQ_QOS_MIN_DEFAULT_VALUE); >>>           if (ret < 0) { >>> -            /* >>> -             * So we don't call freq_qos_remove_request() for an >>> -             * uninitialized request. >>> -             */ >>>               kfree(policy->min_freq_req); >>>               policy->min_freq_req = NULL; >>>               goto out_destroy_policy; >> >> Hi Pierre, Viresh, >> >> Sorry for the late follow-up on v8. While re-reading the patch, I >> noticed a potential UAF issue on an error path — I might be missing >> something, so I'd appreciate a double-check. >> >> min_freq_req, max_freq_req and boost_freq_req all point into the same >> contiguous kzalloc'd block: >> >> slot0 (min_freq_req + 0) -> min_freq_req >> slot1 (min_freq_req + 1) -> max_freq_req >> slot2 (min_freq_req + 2) -> boost_freq_req >> >> If boost_freq_req is successfully added to the QoS constraints list, but >> the subsequent freq_qos_add_request() for min_freq_req fails, the error >> path does: >> >> kfree(policy->min_freq_req); /* frees the entire block, including slot2 >> */ >> policy->min_freq_req = NULL; >> goto out_destroy_policy; >> >> policy->boost_freq_req is not set to NULL here, so it becomes a dangling >> pointer into freed memory. >> cpufreq_policy_free() is then called from cpufreq_online() and does: >> >> freq_qos_remove_request(policy->boost_freq_req); /* UAF */ >> or this boost qos req will leak. >> > > Good catch! > > How about remove the kfree() here and just leave it to > cpufreq_policy_free()? > Thanks for the suggestion — this is another fix approach we can explore, but there seems to be a small caveat. Some additional changes would still be needed; otherwise, removing the kfree() here and deferring it to cpufreq_policy_free() can lead to a warning. The reason is that we neither free policy->min_freq_req nor set policy ->min_freq_req = NULL. As a result, when cpufreq_policy_free() later calls freq_qos_remove_request(policy->min_freq_req), it hits the following warning: if (WARN(!freq_qos_request_active(req), "%s() called for unknown object\n", __func__)) return -EINVAL; -- Thx and BRs, Zhongqiu Han