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=1796010067; b=JtN9Xnz/pOnzxmq2zLnpsHuFKHeKiWUUl9Obo/nZ5rCaIjCFRxEusaLb2Qim2LVGUmJi Ezx6XjJY2gH5e1BlwiCoxmUwt4KNJ8nzs6ahB8Rfh4Rvb3nehSlF1aomtiRCxfpQA+78i D/AKe7J/f9BLIRHuEHHQEYUONkdVVbPZ41Ss9dAvIO6pdhYmIa3ztTGvFj7tUC2i3+cy5 lCvM7tMBxbxOCxyO/llMKvd4Mt1SpBxRSTl2uBNrbSQYW1JUkBBPCDcsVqBXZN14huyt3 D6+ntV+7j/bWwZUaxq8DVfhqj52q5ZUnftXon1A+rQx8DGmny5ouVG4D4yEmxFMFsUg== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796010067; 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-Authority-Analysis:X-Proofpoint-ORIG-GUID: X-Proofpoint-GUID:X-Proofpoint-Spam-Details-Enc: X-Proofpoint-Spam-Info:X-Proofpoint-Virus-Version: X-Proofpoint-Spam-Details; bh=mKEod3NywjmA360GuG2TSBZsafPGFU1/lmvqUrmhPYE=; b=UFk9+lmIQYgvOdVKhCGlB0CIKs1q2++Y12LyxfbkhV6qR5hSwp4eDZx1RLmcFULoSius xgfIqYSwOIP8kI/Lsma4L6InBbNZCfIjKizvpXIJfeHYzgIENLB6U4zelxcakfCwJ02t1 OcyXfV/XW5rDF5pPDahSk+rR5Ug3Zf/NsVgWb6qnzh0LP8Qe8oYDOBA+l5HvvljkrZP2B vNQRZopSGbqqwsysDga4mswl9ofHKrn3bi4DqvnnY2PPhNNjFK9ZJDkaDjO3kEyPvPzUe feqkfJ5cSku3DbxQcsTTwWojen38Uw7xNHzmccmPRmhY2wQdJYv0hBN1QsUr2b3bhfQ== 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 23A25606A333 for ; Mon, 30 Nov 2026 03:41:05 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org 23A25606A333 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 (m0279873.ppops.net [127.0.0.1]) by mx0a-0031df01.pphosted.com (8.18.1.11/8.18.1.11) with ESMTP id 6AU2QMXV3632287 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-f199.google.com (mail-pf1-f199.google.com [209.85.210.199]) by mx0a-0031df01.pphosted.com (PPS) with ESMTPS id 4j90c1r6n3-1 (version=TLSv1.3 cipher=TLS_AES_128_GCM_SHA256 bits=128 verify=NOT) for ; Mon, 30 Nov 2026 03:41:05 +0000 (GMT) Received: by mail-pf1-f199.google.com with SMTP id d2e1a72fcca58-8a0619b1fe5so8020785b3a.3 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=s4t9+TBhC5tpFwXrxL4iLUIk9h1i+hQ7Ibr3RstIeJ8U0stItZusfDARLZojlBS2Ul i7Gh1tLrz3Ppd8CcdIlqj+efqwYYu/t9rI6EF7SqJfR/XjdROR+Dr33JmTJE4E/qf51c 74MbMiT/rPdoJp+LIgFifP4+K2Aoykf+xAHnrXo1GdMqtMDKkxIoLSq5szyIrT/WZ0hA Y563n5pEwaUWKNb0rv9FqyBBpZMPtyIKdrHrTu5s35qeXO8StVdxoFVonUPQ2T6v4IJK jAaoIghV9Bglk45BoIdAiuXkFSgXDx7fTvlIUo1ghh+QubnraaJAxT+8v18+Nszw5fyq yNRQ== X-Forwarded-Encrypted: i=1; AL+hErGCB09DhYgHJYILQRhU9uO5lsQj3VJmrO/CVw2srZ13VIGEPt4dCH3K3F3O8NQoDkxIBRL7Ek3KxXWV5Io=@vger.kernel.org X-Gm-Message-State: APuU4Z+qnvVhSmBqRkHd2FK7CCdhVLtLauhP0twJHv0skUSKsrFGaxw0 YZlLEXnHwDmp0YbUpwIK573y70qqD2VI7BTgaaB0qi2xZoPZrjZA50BvsX3V7a0dKuzgJAAbmKO 4cPK05Df2ySXFdwISVFpLipi0yP98MCabxWBW1n9yJ4o35WJL6WE0CvWUjzjWC9aMO+Y= X-Gm-Gg: AZFdTZeqyC19Ygc1gDEGVa0aTBG0QY4XV4ZwSogaMVrIzbx4VMSeFzds7RH475yv1X1 novEsXpYvlKbYRf3HzGAcCif+bN2jg9gHJUBFHlx4nknYx/GzpYbNaSLkUHj0nzlUZtdwCfBAOo at9er3UES5zsjWz+ha+GxHvRg1bk6w9GyxGxOLRHPU3HgHFqLXHSvx4KxCZxOOV1/iv61Kex17t yfVs1nOwr/87VjtyKLil96X7jOo7xkXUJiUbvW1q1wcoyLTxIRJrxSG0dEEB8MOEcsqq1XfEeL6 l3wJ6W33ONnK1rkEx1ev+t+KCLLgacDkKaOeJFe4Av9tzYWfsyX8NfYhai+RStxj+hb7/KLnDEq UOrA5+yNLIUd9wyIRGWC1lTJqwR4IqyCdiMBbWhvdBBvO6YWY82Fz+BuU9qggpU8sAQnrcKYDYq SKS2VoAYmx88/ZGdCMwkOXD6qQ+ThOnskIWikUxcy4pixD X-Received: by 2002:a05:6a00:4299:b0:89e:9560:fc7a with SMTP id d2e1a72fcca58-8c87c38b456mr27619715b3a.29.1796010063994; 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: linux-kernel@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-Authority-Analysis: v=2.4 cv=R7+WitRX c=1 sm=1 tr=0 ts=6b0cf051 cx=c_pps a=WW5sKcV1LcKqjgzy2JUPuA==:117 a=nuhDOHQX5FNHPW3J6Bj6AA==:17 a=IkcTkHD0fZMA:10 a=zJRp6_cAMcgA:10 a=s4-Qcg_JpJYA:10 a=VkNPw1HP01LnGYTKEx00:22 a=u7WPNUs3qKkmUXheDGA7:22 a=rJkE3RaqiGZ5pbrm-msn:22 a=gnbuhwpKAAAA:8 a=aqzBIk_FKxqTBtLDkqwA:9 a=QEXdDO2ut3YA:10 a=OpyuDcXvxspvyRM73sMx:22 a=HL_VsaX-4L8esMsM0cMV:22 X-Proofpoint-ORIG-GUID: W5GFKPt9U5hP4vbw2HlC0xVMgjjP3U6L X-Proofpoint-GUID: W5GFKPt9U5hP4vbw2HlC0xVMgjjP3U6L X-Proofpoint-Spam-Details-Enc: AW1haW4tMjYxMTMwMDAxNCBTYWx0ZWRfXx0UINYLi4Xzm 7/R3MBIXnbfv60dGYPoUpeX6jSqe0hIzhLxLM2v7XPv4XacrCsOWrS/HpM7tdLJVdLD3Hp9G72A lEYjeF956uCXuxOFt5hv0juNHiMbceBZkzCnWaV0AGBb36vCo9XgpQpL2G9Fj8lukcDTGLt9nC2 OInAg2Pe7mdGveMjn57FV3BZqazHEZQKLBRw94tkxEYlMzWdkfKirknPvyGr22sya3W3hPTvhd1 TqCoEtnWic9i/MBT6OT2nZ0+GHDyYlfKZ+7tFL+/7XkxrGiem/Z7kYDO1nlYGsdgiT/UHtV0Wd5 9PWHbW/ctPh5dRn9tVIooggVnUvUUYivuKviz2UQTap1QPa9dJO7s++68DqtWWngt7h44Irnq1s J0MoghC8tzZo7UaZN+ORiXWClyRnyAveLYeImzN9+X0MqQP2pHFFnQmB403aE4OXO4s9Fx8Rk4s t4/Vv0ju1z3JvYEFBqA== X-Proofpoint-Spam-Info: AW1haW4tMjYxMTMwMDAxNCBTYWx0ZWRfX81cmF0Xi+SIv Z6NpHBni6gCgyjK9gLXpXc1vBWnYrNrMA6a069K0isvFuI8mLmofbcwxjNXubmZFmjs4z/nmaSZ i0kkybXI/A8n8+nBQNVCJE8ypPa0Tz0= 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 adultscore=0 lowpriorityscore=0 malwarescore=0 spamscore=0 bulkscore=0 priorityscore=1501 clxscore=1015 impostorscore=0 suspectscore=0 phishscore=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