From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=209.85.210.43 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1795207322; b=hg4zSZqw3LZ15jzb3vF1OWGyCnjqA/DRTh/JhN6XDd6aR0R4+NQC2YYi/AaxM08dNsRP 4PVf3FWaZGbTTvp7qDz65O0hZhEcsjnPX1BKspMXffXiYIlpylQ6vCgQ91aOF5Jr28lHe tf3yP/ZHu24k8T0L2QGT80G8iejBdK64HKrpOra9RVNaxg5P3ef+RBOLJPZjtQxIzJ4sb gCn8aAyAP10yER9T+qPfwmShCR5rrtunIMi0Mx9Hyj1HnqCdtueoW13uRy76l8GQAzmmu vj1ZR0qT31P4W8Ulc6eTcpafuTeA34DM1KX808H5xlY0krR2AzlsarbbL/ZL7pGZxag== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1795207322; h=DMARC-Filter:Received:DKIM-Signature:X-Google-DKIM-Signature: X-Gm-Message-State:X-Gm-Gg: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; bh=5QxBvONaph7bgEQd2yve9sMSGV8Ex3XSmsjoj7Q3FaE=; b=fLb3ufD8WiFFGmZl8Xnq6Pnia+S/AQAGTpsNxrR1ABvk61jXGxGz6bS6Jywy74iTUgzH eTiHjmZrTGfNHyN5hjzk1UyOj6fYR1gQpVlKy86WgwVr6N+X/Z9rLQx8a2dOISm1VRt4Q bdaD/8KDE7dNwaHOW2aPHh/qUYj5m/Lc+mMLBL5Q7VaM2ppE+5nIgKIjIzHsE1ZzMW4wD Im2aw8EdqxEekoSiN0JfdAV2oFhzU446SpSFZZkSQRiRsJElQA6SxooT6/eJIeM3oTXqD 1U38tgp4bkx60ZwGId4FscZYJZfX8YZ7/oXXn4duyCkXrcLikXfc47ICx3+u4ocaidA== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass header.from=linuxfoundation.org; spf=pass smtp.mailfrom=linuxfoundation.org; dkim=pass header.d=linuxfoundation.org header.i=@linuxfoundation.org header.a=rsa-sha256 header.s=google header.b=Vl1HSM5D; arc=none smtp.remote-ip=209.85.210.43 Received: from mail-ot1-f43.google.com (mail-ot1-f43.google.com [209.85.210.43]) (using TLSv1.3 with cipher TLS_AES_128_GCM_SHA256 (128/128 bits) key-exchange X25519 server-signature ECDSA (prime256v1) server-digest SHA256) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id EDBA5606A6E9 for ; Fri, 20 Nov 2026 20:41:57 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org EDBA5606A6E9 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=linuxfoundation.org Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linuxfoundation.org Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.a=rsa-sha256 header.s=google header.b=Vl1HSM5D Received: by mail-ot1-f43.google.com with SMTP id 46e09a7af769-843cf077f10so1745033a34.1 for ; Fri, 20 Nov 2026 12:41:57 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linuxfoundation.org; s=google; t=1795207317; x=1795812117; 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=5QxBvONaph7bgEQd2yve9sMSGV8Ex3XSmsjoj7Q3FaE=; b=Vl1HSM5Dg4a6MsPM4I93FkkgPRtjc3rWi3iATtBxbHp8Z4tHYt5JXwo9uspigYOcxu z/MeFF8aE4OfqsXT/npJlnN1NlT52TAgI0le4F3aEw6KDXZ1Wf7QWnqYPD47wOt75BZA MfAU2R20N+oMrvmqb8HYRH9jqlkY17mZzgQJs= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20260707; t=1795207317; x=1795812117; 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=5QxBvONaph7bgEQd2yve9sMSGV8Ex3XSmsjoj7Q3FaE=; b=M3/Lekwdz1Wg6peMJSh0N7Ojgd4CSU+SvSodjVS6FlZSWtVr3nAlwcbZgrERIVNvrc wWZnxfVD4tI67A+ZyFr2zhtIkcJEUAYYiWPgeDIcj/Pp9vTKXSRiEnlTWhQK7U1ZuL2f 7pKss5odkQEewnFydOOragy3YB6Myalgu40qHPArEa47RVHZPv7wzO+2UlZpz7JrsnxE Zz8XXoZ/jJb+YN//mFheHHhbS6AQ6zbKEOuP77XQsF99dqMHzRiGgivhBXCUUdTfM1ze 2HRsuM9YwaRd56Wbfjl+ST9RKyQ1EC4sgMWpx8fyjt5ddN2u+23v980jIthPx6wBiUpQ oPAQ== X-Gm-Message-State: APuU4Z9ukrjO8nUaPUosIz5bLWm11XLsPCZlGsg+4XUxTMd1snW1qiIe zWcHNYQv0GVBryKf2MMbbb5NEKZ5NOk8UnSqFnD/mTEeQaVbGUC4wa90OZyJJGPrkQPntqbEGiJ 6+OXv15Q= X-Gm-Gg: AYBFou39EB1CEPScMCNiIA0i0YqYre0OBIMZcwMMUTJAu90ZMtNx7CxeUJGhdnw9ww7 G3NOYi06TECBTEhLvP9Ohx2jAgRIO3kQWQnCmpyjWM61D8RYOnhueQsXxPNNGmbibd1LBLaUcny 9yhnSmvT4enG6S+o+hoxdjz8mtly12Zj9Ja/B7d9keECoMVGMancaY/6jz5nH9aBsgIC/XbBf+X q0FrX1y57b6AxAJAYCTL6vDC3k6Y14GqPFhphOtO7zWD4eG0kD9QKUMGmwRSK5NAi+t4S2zLEhO Cfo4pn6PCAsLfEXntvBAWHsHCNPkUoHDE7S7NY2JJt3LMckJuZksLf0A327+LJoNcqnFBaXkQny 3KAnAAcNpfvKBcIg8MFsrAFdq52E0J+RLVfwfPEKDpeoPPa2mLfR4j1sxAxwCoJbh4n0mz5d4FG eDzwYTek9D9bp35vhQlU0C/cSgrYPVZ3MtX0wM0ElWEMzCB8wz3Fy/W+fNMNTkN3mckX9HLWjcS 33VZiWk7FqLc1SK6azVs2r6TXJIHAfyfZJ9ik7RiYwNxpiu3JSM3geVppdzBuOZ3lNJJpQ/xYpG gHiXHANFNbB2rGk0k8qC7rjx/veyuE+K2CpLL2w= X-Received: by 2002:a05:6820:55da:20b0:71a:f228:3222 with SMTP id 006d021491bc7-71b3957e687mr3021698eaf.77.1795207316762; Fri, 20 Nov 2026 12:41:56 -0800 (PST) Received: from [192.168.1.128] ([38.15.57.99]) by smtp.gmail.com with ESMTPSA id 46e09a7af769-863168dd6e7sm3198832a34.12.2026.11.20.12.41.53 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Fri, 20 Nov 2026 12:41:55 -0800 (PST) Message-ID: <69cde473-bd68-4bf5-be03-c68f411ec116@linuxfoundation.org> Date: Fri, 20 Nov 2026 13:41:52 -0700 X-Mailing-List: linux-pm@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 v3] cpupower: fix use-after-free and stale limits in frequency-set To: Lukas Beckmann , Thomas Renninger , Shuah Khan , "John B. Wyatt IV" , John Kacur , Dominik Brodowski Cc: linux-pm@vger.kernel.org, linux-kernel@vger.kernel.org, stable@vger.kernel.org, Shuah Khan References: <20261118-cpupower-freq-set-use-after-free-v3-1-3e021315b579@mailbox.org> Content-Language: en-US From: Shuah Khan In-Reply-To: <20261118-cpupower-freq-set-use-after-free-v3-1-3e021315b579@mailbox.org> Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit On 11/18/26 13:06, Lukas Beckmann wrote: > do_new_policy() directly fills the unset fields of new_pol from the > current CPU's policy. This is problematic because do_new_policy() is > called with the same new_pol for multiple CPUs by do_one_cpu() in the > slow path. This results in stale values in new_pol being applied > (starting from the second CPU that should be changed), and even a > use-after-free (for the governor string). > > Fix this by building the target policy from new_pol and the current > policy in do_new_policy() instead of filling the missing values into > new_pol. > > Fixes: 7fe2f6399a84 ("cpupowerutils - cpufrequtils extended with quite some features") > Cc: stable@vger.kernel.org > Signed-off-by: Lukas Beckmann > --- > Testing and minimal reproducer: > > Running the command > > ./cpupower frequency-set --max 2500MHz --min 2500MHz > > with ASAN reports the use-after-free before, but not after the patch. > > Run the following commands: > > # set CPU 0 to a different maximum than CPU 1 > echo 2000000 > /sys/devices/system/cpu/cpu0/cpufreq/scaling_max_freq > echo 3000000 > /sys/devices/system/cpu/cpu1/cpufreq/scaling_max_freq > > # Change min and governor (but not max) of CPU 0 and 1 > ./cpupower -c 0,1 frequency-set --min 1GHz -g performance > > # See if max got changed > cat /sys/devices/system/cpu/cpu[0,1]/cpufreq/scaling_max_freq > > This shows that the stale maximum of CPU0 is used for CPU1 before the > patch, but not after the patch. > --- > Changes in v3: > - Keep the original if conditions (no functional change) > - Link to v2: https://patch.msgid.link/20261115-cpupower-freq-set-use-after-free-v2-1-6b91f1630165@mailbox.org > > Changes in v2: > - use a shorter changelog and testing section > - build temp_pol from new_pol and cur_pol instead of copying new_pol > - Link to v1: https://patch.msgid.link/20261112-cpupower-freq-set-use-after-free-v1-1-4e0034927b3f@mailbox.org > --- > tools/power/cpupower/utils/cpufreq-set.c | 17 ++++++++++++----- > 1 file changed, 12 insertions(+), 5 deletions(-) > > diff --git a/tools/power/cpupower/utils/cpufreq-set.c b/tools/power/cpupower/utils/cpufreq-set.c > index 06cd4b280132..0bbf303d3317 100644 > --- a/tools/power/cpupower/utils/cpufreq-set.c > +++ b/tools/power/cpupower/utils/cpufreq-set.c > @@ -141,9 +141,10 @@ static unsigned long string_to_frequency(const char *str) > } > } > > -static int do_new_policy(unsigned int cpu, struct cpufreq_policy *new_pol) > +static int do_new_policy(unsigned int cpu, const struct cpufreq_policy *new_pol) Why do you need the above change? > { > struct cpufreq_policy *cur_pol = cpufreq_get_policy(cpu); > + struct cpufreq_policy temp_pol; > int ret; > > if (!cur_pol) { > @@ -152,15 +153,21 @@ static int do_new_policy(unsigned int cpu, struct cpufreq_policy *new_pol) > } > > if (!new_pol->min) > - new_pol->min = cur_pol->min; > + temp_pol.min = cur_pol->min; > + else > + temp_pol.min = new_pol->min; > > if (!new_pol->max) > - new_pol->max = cur_pol->max; > + temp_pol.max = cur_pol->max; > + else > + temp_pol.max = new_pol->max; > > if (!new_pol->governor) > - new_pol->governor = cur_pol->governor; > + temp_pol.governor = cur_pol->governor; > + else > + temp_pol.governor = new_pol->governor; > > - ret = cpufreq_set_policy(cpu, new_pol); > + ret = cpufreq_set_policy(cpu, &temp_pol); > > cpufreq_put_policy(cur_pol); > > thanks, -- Shuah