From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=205.220.180.131 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796010066; b=gNq2+f4eKwEnJCnz9GzJEISZOE1g/S6ghqfivzBVppObjiceSi3AFMP422/eDviPe9fQ sQeLTYc/VF+LZgHrhXrx8DPgUAqgUnRF+QdKi3b0Jfh+lM1kmblvZto4kYFRn5PDZ1dpR 2OB/W+znQnj15+5ib1xZYzJv9EQNe9x5c9tgcr+O60APl3CZ2Bm7ZRvguudmxOghleG0x kdkkv078tF3CzecugBh3T8zb23JKVE9vBeR7fXFGLeyZ9ti/BCpsT0giTfqRZuUttfbw8 +2OKe6oJJL1Hhx5WBJfewzqovswOENjmprfZ4Aa5OJGNYKdkA9kzLAUETHDF1StTZrg== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796010066; 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-Authority-Analysis:X-Proofpoint-Spam-Info:X-Proofpoint-GUID: X-Proofpoint-ORIG-GUID:X-Proofpoint-Virus-Version: X-Proofpoint-Spam-Details; bh=mKEod3NywjmA360GuG2TSBZsafPGFU1/lmvqUrmhPYE=; b=D/eAcPBNLK+rcLS7cGk5yBK+bvqMJGJoL1g+iwTV3bJ69JoRu6FW/F/fHBI3uspLDJOL y/phI1fWnuYcwjbz4g4NO3Yr78R5fHQCaNKxk2UEILqgcLubyNnMdkVjKEnZoHb122XU+ 1h2U3BQAsjTX9EdYqiUhU1Rya3xyn6pOVzWvdtDnbil6XmH6+FB3I/PK6XzlUc0Q3f0oh SHeODVs6zil3iXJGosg+Slo+xngiYHRG/kWJyo2eMvYdiuetWq4v8H3tIOav7FZLaYt+R 2+K+2eKC6k//YgvRmSZvozTx1ZYc8yR2R9DXkuPCwEAZHs6NH/eKKwCKX8h1TMBVAIQ== 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=RpbG6+qx; dkim=pass header.d=oss.qualcomm.com header.i=@oss.qualcomm.com header.a=rsa-sha256 header.s=google header.b=gIqGlEyp; arc=none smtp.remote-ip=205.220.180.131 Received: from mx0b-0031df01.pphosted.com (mx0b-0031df01.pphosted.com [205.220.180.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 23886606A327 for ; Mon, 30 Nov 2026 03:41:05 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org 23886606A327 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=RpbG6+qx; dkim=pass (2048-bit key) header.d=oss.qualcomm.com header.i=@oss.qualcomm.com header.a=rsa-sha256 header.s=google header.b=gIqGlEyp Received: from pps.filterd (m0279870.ppops.net [127.0.0.1]) by mx0a-0031df01.pphosted.com (8.18.1.11/8.18.1.11) with ESMTP id 6AU0k1No1238950 for ; Mon, 30 Nov 2026 03:41:05 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= mKEod3NywjmA360GuG2TSBZsafPGFU1/lmvqUrmhPYE=; b=RpbG6+qx5AQ0QNxc LSWLhzWmjENvBWoKuG+B8F5zYWYmVTrROToRjv3nSctj5VHHbBFkXDVfBMHmkZB1 t0TGOCxxX+kb4B1mQ6ToIxhlXAg/MaJ20CMv8tHZyfyO0XSCM3bS4OZTQNXUyP84 ygPBJ7D4DWMMNBHI7kgo/u7+5eHFmsLj0SAwFqc/z0pswJP6nGlvL5VPVPjH+yO+ t0HAEnSJPPY5sLSri6S9CRjePIVBJejHllenK+WNaECVw7SSHISrlj0EefU6VXv3 GvlxXgnFz+5ktHFe/fuLSwxtatJvuCDBSgMumF+pTFj6qeHYX33CaUvsL075W2iq 9+pmnw== Received: from mail-pf1-f198.google.com (mail-pf1-f198.google.com [209.85.210.198]) by mx0a-0031df01.pphosted.com (PPS) with ESMTPS id 4j7q1u4g0b-1 (version=TLSv1.3 cipher=TLS_AES_128_GCM_SHA256 bits=128 verify=NOT) for ; Mon, 30 Nov 2026 03:41:04 +0000 (GMT) Received: by mail-pf1-f198.google.com with SMTP id d2e1a72fcca58-8b7614e9762so7056906b3a.2 for ; Sun, 29 Nov 2026 19:41:04 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=oss.qualcomm.com; s=google; t=1796010064; x=1796614864; 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=mKEod3NywjmA360GuG2TSBZsafPGFU1/lmvqUrmhPYE=; b=gIqGlEyp7Hjwg1izU5YAaph0ke0QTIeig8yt87d6hK+/TW/w4Yn+ZlQVyJ7snF4QLz tXLbLlWRIUcNr/7j6ei6+rZY35RbJBoCXte/xdUX4oo4UPSQY2WC8yvTAJZNykEgNZXQ vkk8cteRkJcBEdFGdt97mTWw63Y545slnBuOIvKsaumh2TH4IGF19EZYhnb69DJBwosT OAjh6ZgUl4OGtRB1fcCxYcCQB1YRf7Twwtmesbtzvsn6w04+Uk4OtlPWmlkmoU0UdPUU r16r4ACRYA9HD5Ik3EzGJkDXPWA5GCTHdrJRO8zgOQALTFpR9pkOzESLngCMfHMNcswV kqDw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20260707; t=1796010064; x=1796614864; 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=mKEod3NywjmA360GuG2TSBZsafPGFU1/lmvqUrmhPYE=; b=G+xLfztBaBEWB9jbtEzAVkwg/17gaVoC8KpFy8a4B5SWQMVlDq1IJOjfbRTb76lAJh qfJB4p8moYYMeinujzBzrTI7iFQ3k2qsXa3DZFLUzV7VzTJo/HTSG1Gw1tuiUGzPm2cX ErB7f2VOPoszI9vzHTfnhDm3nHHATBdpm20nNMlat2YQdM0cRoIaL0rkXez1whFQqUu7 h50b/bKyog0MPPxH/g5FO0Z48540EuXBhdERBw9SQ7/oXs+g9tRXi9BD5iBLzAjkuSLd 2ytU+IOVz5AwZRsygyVGS4dJOCYVtiON8U3znx1JGJ6Ns9Ipf55gQyiP6+PwHx+oZeOq fvYA== X-Forwarded-Encrypted: i=1; AL+hErGXEe8+MciVOujHVNgEFEG0wxk58+mI1yPjJyaMWtx5LYWsmZC1oFtpCWHsiY+JuhDVRM0lOLWSLMi8um5vLQ==@vger.kernel.org X-Gm-Message-State: APuU4Z/5dRtfDjfqU/XqwCJnpDasLGnJ9pcUv3yKbAQBg0JC8wfp5Qpc 6PdTMi8sYpdf8h4CH8tYsUhHHaEDYzNpwaRkJGDLlGqmreMXjO1KrI4vMh3Fx/MUmPThK1uS8/Q ccC2Rqls3gjNxvD1DoFmmxdDPaoMDXh84A57ZYkZxSIwFMU3zGZYOSQLDho0YNDTQ4wtK8Zge8l hH8+7G X-Gm-Gg: AZFdTZcpUFTeUDeyIEKb75kfYDm/T5/N81vQlb+Eep9pnkaIAvZWD46rgJ0N1UY8S2X ZMap+bd340YXKSIkpvW33L2+6miKKtuTFKi9lGi9nrkFve6CZXHGYi5Dbw/e5mz6sfiO3LV49tO ryeKOOft7ABghfeY3i6MFqdbdAOZ82bBJcBaEwh6UtTIhzHTAiavKWuJeMw6CPcWPBAunyTwgiK aXmFVjMw0rqi8YZ+LsP4LIMmQOMcgljUS0ntMherTEn9+0Pig4eDYJ3yzu9NoDuly7ylWsOLPbm oJXTNuWGZ75lsOyeazgvBn6w+Um3kKwL58HEEM3V3F02fSX5grIC0OsoQZeWp6aDmjbvePajL5M FRISMsWzv8TzIoPKN3k3GUa/mGubWQw+OSZlhQ4LX3WpDQsJXlzXVikjhuBvwzNuLM+6twnAHAZ O3g9d5mBo7zaZn2uPZU6x/h7Qv3MEHOwdXUMRVcibeTLcm X-Received: by 2002:a05:6a00:4299:b0:89e:9560:fc7a with SMTP id d2e1a72fcca58-8c87c38b456mr27619705b3a.29.1796010063962; Sun, 29 Nov 2026 19:41:03 -0800 (PST) X-Received: by 2002:a05:6a00:4299:b0:89e:9560:fc7a with SMTP id d2e1a72fcca58-8c87c38b456mr27619684b3a.29.1796010063484; Sun, 29 Nov 2026 19:41:03 -0800 (PST) Received: from [10.133.33.226] (tpe-colo-wan-fw-bordernet.qualcomm.com. [103.229.16.4]) by smtp.gmail.com with ESMTPSA id d2e1a72fcca58-8c87285c05fsm16908488b3a.17.2026.11.29.19.41.01 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Sun, 29 Nov 2026 19:41:03 -0800 (PST) Message-ID: <4e89e29a-ac24-488d-bad8-782c12ffdf1c@oss.qualcomm.com> Date: Mon, 30 Nov 2026 11:40:59 +0800 X-Mailing-List: rust-for-linux@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 v2] rust: cpufreq: mark Policy::data() as unsafe To: Bilal Hashim , Viresh Kumar , "Rafael J . Wysocki" Cc: Miguel Ojeda , Alice Ryhl , linux-pm@vger.kernel.org, rust-for-linux@vger.kernel.org, linux-kernel@vger.kernel.org, Zhongqiu Han References: <20261128140253.1927-1-AeeSec@126.com> Content-Language: en-US From: Zhongqiu Han In-Reply-To: <20261128140253.1927-1-AeeSec@126.com> Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit X-Proofpoint-Spam-Details-Enc: AW1haW4tMjYxMTMwMDAxNCBTYWx0ZWRfX71qvi39QOL5M JsLeBBRfz8Y8Zy4k7D2c0hibgJj3Tz4Jhs/ifX4ZOC9fDBdp4fIPAAV4bEVkkrXP0JskIvXAkJE e2VfJyZrizG9curX70F2sa6+GiGiaCIFLrTGCvOsvUw4qlK2mIbVv7feh+sP/A97kA5e1DQ7kGC PcHVLkl2FWa+htCGe1XRgaDtdNADm2CPQ2LBenBBshk7tWdvKN0r7rAiaOQKXAoO7PFb2mXHQ4d 5zZRSI37cSm8urwG2o58F+efpRbflmysWdhNiWB7kd0fBKX5VvJlZwIa05D6bATWx6KK7VRC4x7 Uo4ti5UUL8WaNDB0ps8vq6nl1r4e9xyZq3bu0Zwe2lxTeQmIQD+f8rwANrckOkqstg67dcijDCZ ciC21ED3ZqjAkqv0fb0viRNoMeAT5FBpU9yHng7VXr1V1DvEpFUFXRuD2X0Dm+Es8YRI1PxhAuU TxIpbOGWuvxdEbyZTTA== X-Authority-Analysis: v=2.4 cv=Dv3Da2/+ c=1 sm=1 tr=0 ts=6b0cf050 cx=c_pps a=m5Vt/hrsBiPMCU0y4gIsQw==:117 a=nuhDOHQX5FNHPW3J6Bj6AA==:17 a=IkcTkHD0fZMA:10 a=zJRp6_cAMcgA:10 a=s4-Qcg_JpJYA:10 a=VkNPw1HP01LnGYTKEx00:22 a=u7WPNUs3qKkmUXheDGA7:22 a=gowsoOTTUOVcmtlkKump:22 a=gnbuhwpKAAAA:8 a=aqzBIk_FKxqTBtLDkqwA:9 a=QEXdDO2ut3YA:10 a=IoOABgeZipijB_acs4fv:22 a=HL_VsaX-4L8esMsM0cMV:22 X-Proofpoint-Spam-Info: AW1haW4tMjYxMTMwMDAxNCBTYWx0ZWRfX2aZuLymQu9KB leH9sS/IxDoY0TDdqjJ1vdKtLaK++lyVNoMi6pGs6mHpEC9jxxty96N+A1OynVYqnmK18cUkMDm yotNhQT2Fhqd+cFtIXM5CFQoqUYYC0c= X-Proofpoint-GUID: pOxteu9W2NbT-jrATW61YfYL02O8EVef X-Proofpoint-ORIG-GUID: pOxteu9W2NbT-jrATW61YfYL02O8EVef 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_01,2026-11-27_03,2025-10-01_01 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 priorityscore=1501 spamscore=0 malwarescore=0 adultscore=0 bulkscore=0 phishscore=0 clxscore=1015 lowpriorityscore=0 impostorscore=0 suspectscore=0 classifier=typeunknown authscore=0 authtc= authcc= route=outbound adjust=0 reason=mlx scancount=1 engine=8.22.0-2611040001 definitions=main-2611300014 On 11/28/2026 10:02 PM, Bilal Hashim wrote: > Policy::data(&mut self) is currently a safe public > method that casts the untyped C pointer `policy->driver_data` via > `T::borrow(...)` for any caller-chosen type `T`. > > Because `Policy` is not parameterized by `Driver::PData` and performs no > runtime type verification, any safe Rust caller with `&mut Policy` can > invoke `policy.data::()` and reinterpret `driver_data` as an > arbitrary `ForeignOwnable` type, causing type confusion and undefined > behavior in safe Rust. > > Mark Policy::data() as `unsafe`, document the safety precondition that > `T` must match the exact `ForeignOwnable` type previously stored in the > policy's `driver_data`, and update the in-tree caller in > drivers/cpufreq/rcpufreq_dt.rs. > > Fixes: 6ebdd7c93177 ("rust: cpufreq: Extend abstractions for policy and driver ops") > Signed-off-by: Bilal Hashim > --- > Changes in v2: > - Update caller in drivers/cpufreq/rcpufreq_dt.rs to wrap > policy.data::() in an unsafe block with a SAFETY comment. > - Add Fixes: tag. > --- > --- a/drivers/cpufreq/rcpufreq_dt.rs > +++ b/drivers/cpufreq/rcpufreq_dt.rs > @@ -178,7 +178,9 @@ impl cpufreq::Driver for CPUFreqDTDriver { > } The patch does not apply: $ git apply 0001-...patch error: corrupt patch at line 43 The first hunk header is wrong: @@ -178,7 +178,9 @@ impl cpufreq::Driver for CPUFreqDTDriver { This hunk removes one line and adds two, so the new side has 7 - 1 + 2 = 8 lines, not 9. > > fn target_index(policy: &mut cpufreq::Policy, index: cpufreq::TableIndex) -> Result { > - let Some(data) = policy.data::() else { > + // SAFETY: `policy`'s private data was initialized with `Self::PData` in `Self::init()`. > + let Some(data) = (unsafe { policy.data::() }) else { > return Err(ENOENT); > }; > > --- a/rust/kernel/cpufreq.rs > +++ b/rust/kernel/cpufreq.rs > @@ -648,9 +648,15 @@ impl Policy { > /// Returns the [`Policy`]'s private data. > - pub fn data(&mut self) -> Option<::Borrowed<'_>> { > + /// > + /// # Safety > + /// > + /// The caller must ensure that `T` is the exact [`ForeignOwnable`] type previously stored in > + /// this [`Policy`]'s `driver_data`. > + pub unsafe fn data(&mut self) -> Option<::Borrowed<'_>> { > if self.as_ref().driver_data.is_null() { > None > } else { > - // SAFETY: The data is earlier set from [`set_data`]. > + // SAFETY: The caller guarantees that `T` matches the type previously stored via > + // [`set_data`]. > Some(unsafe { T::borrow(self.as_ref().driver_data.cast()) }) > } > } > > -- Thx and BRs, Zhongqiu Han