Device::chip::() is a safe API that forges &Chip for an arbitrary PwmOps type, after which Chip::drvdata() reinterprets the chip private allocation as &T. Callers can therefore type-confuse drvdata from safe Rust; with a larger forged T this is a slab out-of-bounds read under KASAN. PwmOps callbacks already receive a correctly typed &Chip, and there are no in-tree callers of Device::chip. Remove the helper. Fixes: d8046cd50879 ("rust: pwm: Add complete abstraction layer") Cc: stable@vger.kernel.org Closes: https://github.com/Rust-for-Linux/linux/issues/1274 Signed-off-by: Franklin-Qi --- rust/kernel/pwm.rs | 8 -------- 1 file changed, 8 deletions(-) diff --git a/rust/kernel/pwm.rs b/rust/kernel/pwm.rs index 8aa47304bec3..4cb5a15d0d8e 100644 --- a/rust/kernel/pwm.rs +++ b/rust/kernel/pwm.rs @@ -101,14 +101,6 @@ pub fn hwpwm(&self) -> u32 { unsafe { (*self.as_raw()).hwpwm } } - /// Gets a reference to the parent `Chip` that this device belongs to. - pub fn chip(&self) -> &Chip { - // SAFETY: `self.as_raw()` provides a valid pointer. (*self.as_raw()).chip - // is assumed to be a valid pointer to `pwm_chip` managed by the kernel. - // Chip::from_raw's safety conditions must be met. - unsafe { Chip::::from_raw((*self.as_raw()).chip) } - } - /// Gets the label for this PWM device, if any. pub fn label(&self) -> Option<&CStr> { // SAFETY: self.as_raw() provides a valid pointer. -- 2.55.0