From nobody Mon Feb 9 08:29:46 2026 Received: from mail-lf1-f45.google.com (mail-lf1-f45.google.com [209.85.167.45]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 8D1D1314A7C for ; Tue, 6 Jan 2026 16:13:15 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.167.45 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1767715998; cv=none; b=TN8b4hNN5foViGlFmFKTSFoHRuPza8syWL09WGnfdQIakTOKYP7XKmnbVa256qJL8UwSNoFRTrQfApKWEtF2+J4uXsz/43Qxlxrzr1JSb45wuVQUrRrZNylxZSXeBzmuUCKIA1ApI0TR0kefH1Aj3Gnzyg3y2V5nmAj8CmpP7ME= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1767715998; c=relaxed/simple; bh=PsulVulBYOKVhtxVFsqQzoL1KhSmhEASbJ2jTpxpE5M=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=DObUR2hK2GiZvPZ0jb8MgdHmRka4JxeaSQFqNiSnZUHj1b48yXy55whWxqg8fHoFFaFwmBjveNOhToBr8gAACvtqndh9t1feTBaBBa+pOehIKPu62EX0XgzmgE6YUK+XQKxzZxJ+ZRFNzDhzjLWcZ2expaVsGqriWs5eWH1navA= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=Vx/Dd30h; arc=none smtp.client-ip=209.85.167.45 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="Vx/Dd30h" Received: by mail-lf1-f45.google.com with SMTP id 2adb3069b0e04-5959105629bso1143167e87.2 for ; Tue, 06 Jan 2026 08:13:15 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1767715994; x=1768320794; darn=vger.kernel.org; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:from:to:cc:subject:date:message-id :reply-to; bh=6p/TE1++7w8lcKdQTf98fxRYGObQ9N/7Fpqo/Gx8pUA=; b=Vx/Dd30hnwaEdbq6aIK9ps8AGmAxf/UPpSwLSUTf0lp9HK4KuqDiWITdNOGhsAxy5t DRtY8UTwWoESQ8IRS0LbzgJ5vR5qFN1vfu80XtDbCjCvKCq45qDe5tW0wiFjNvlCfjpG BTGMN9BQsBgeDWStL5Pmjo6jvXUw7vKzFqc+dU95t/HsMgkLqEEcyZqG5EOrDnI/WHBH I3gH0UjlruQaZqdOIX+XeF2eZr4LewNsPcm4Y7qsoFnUS7SC0mcRa26d7aL4NDL6FUEi EXmDRy9IONAz2bWD6NTqqGRDBtkGGnFdBisO8LA7wswSVhwzGuSHCDHz0UqjKn01YQiW fXAA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1767715994; x=1768320794; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:x-gm-gg:x-gm-message-state:from:to :cc:subject:date:message-id:reply-to; bh=6p/TE1++7w8lcKdQTf98fxRYGObQ9N/7Fpqo/Gx8pUA=; b=rtbi9VqQaQ1UtBWAQw4YK48tz+rYrLZ3NNr82R6yPWGC/GCFjKjIv0SSec6BwR3Bfa 9dRyU70oqczJQf0IWaa36DdjzX/BAxp8JWYVzbzPZjGSY3CneNQWht8ExoKnexuPmEw4 IJN64MwmeYwKcCtRh1wMjvvWkNxBWQpcYYsozLMLvPSCMkLJcadlt0PTIVpHPDjx+iub THa3NFIaQ1YxwrP+iigVaFRKMSuZ4lEBEnQDuqhXI42MUReypMF3gT1hdRxGycYl4WDC Ilvmo9uPMM/b+ZotC4DBWWrQtTNmtTdfde4010xE4agBJUYMrVD25vNTZTpEVVBkmw5p G1wg== X-Forwarded-Encrypted: i=1; AJvYcCXjmMeqqB72XB/8xCqwLfHBx6RODhIkHZDs7oJMZTVo7zaIurXZ+QYn37iA+JAbBe6bq6+r6NoTgViGoBM=@vger.kernel.org X-Gm-Message-State: AOJu0Ywa+bSe9QVsnYB8CjBTUE1+wLkDBOcysNE3UaASlnlVdDipzIHB gitfttRaP3/X9ShM3eDVQu5VC0Y+vv+0dqGgISCxrY/yzPMLQE19KKc6 X-Gm-Gg: AY/fxX5y91a47SvJ7ZnWwLxNMs34aak7Kx10XEHCwzBg/NNcPJRqsJVeeG2NYXDyajP vjCSUSMSSM1u05IwJlgHTHm4AjPh+r0tQryQnfT+1F1Vms7i32XKDpSWSBn0jjepyCvbczjn3xd +2evMqGtxdBW1C+5aB7+OjqbLBg/8LOI5aYAYkp8tOtmLHbtpua95LuV7v4z/9ne0oRgHSLKgyV db4VWuW2NjRR2l4GXDGmgKnQRG7e52hXz75bs/By1U2+FrCG0DEBZO2JT7XwyX0UbodXqFY7dL9 8cWlT06yY/IJ0slaZdJXKhUzLOnCUf7FwyuD1JL8jn25yAgaE96yW81B0hzNwGe3C21x+8pIba2 BGFwzXYZ7HXXLDpd2M4XUbq2wKn9ow4Bax/e+YoQ5WksKpUfsC2NEUTAiKDGfQqBZ6FDclT6uZ1 NQEp+mo9GPduO1PuFe68LxeM9GgfDulJhF/sOSsRHshj5MHsMnvwwceUB0YIf20ooZPoIJd+6y4 oqLBLgmo+seZM+y X-Google-Smtp-Source: AGHT+IGlXyOOqsVxrzerdqZLWzRZbo1sVTEEFXJL0FcS8CHueTTVetp3Ab+FGNQAORlulzN0p9Q48g== X-Received: by 2002:a05:6512:124a:b0:596:9c01:aeb4 with SMTP id 2adb3069b0e04-59b6528578bmr1179647e87.18.1767715993393; Tue, 06 Jan 2026 08:13:13 -0800 (PST) Received: from LT-5CG5341NQ4.nordic.imtech.com (37-33-180-149.bb.dnainternet.fi. [37.33.180.149]) by smtp.gmail.com with ESMTPSA id 38308e7fff4ca-382eb91dfbdsm5256091fa.44.2026.01.06.08.13.11 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 06 Jan 2026 08:13:12 -0800 (PST) From: Kari Argillander Date: Tue, 06 Jan 2026 18:11:42 +0200 Subject: [PATCH RFC v2 04/11] rust: block: fix missing owner field in block_device_operations Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Message-Id: <20260106-this_module_fix-v2-4-842ac026f00b@gmail.com> References: <20260106-this_module_fix-v2-0-842ac026f00b@gmail.com> In-Reply-To: <20260106-this_module_fix-v2-0-842ac026f00b@gmail.com> To: Miguel Ojeda , Boqun Feng , Gary Guo , =?utf-8?q?Bj=C3=B6rn_Roy_Baron?= , Benno Lossin , Andreas Hindborg , Alice Ryhl , Trevor Gross , Danilo Krummrich , Alexandre Courbot Cc: Greg Kroah-Hartman , rust-for-linux@vger.kernel.org, linux-kernel@vger.kernel.org, linux-modules@vger.kernel.org, Luis Chamberlain , Petr Pavlu , Daniel Gomez , Sami Tolvanen , Aaron Tomlin , Kari Argillander X-Mailer: b4 0.14.3 X-Developer-Signature: v=1; a=ed25519-sha256; t=1767715983; l=5351; i=kari.argillander@gmail.com; s=20251219; h=from:subject:message-id; bh=PsulVulBYOKVhtxVFsqQzoL1KhSmhEASbJ2jTpxpE5M=; b=Sim91oPpd8l6p0q1O5Xp6fchcI+KFs0dqtVx/nb6eTqylSjcfpMwGbx1MCNvuwMzNycLZHSXT 6GC7B7fd+dUDmk1/IvWKXSPc9zWnTh8NkP6D1PwidvIhL6AfTpdTZRi X-Developer-Key: i=kari.argillander@gmail.com; a=ed25519; pk=RwSxyhTpE3z4sywdDbIkC3q33ZQLNyhYWxT44iTY6r4= Kernel has now enabled "const_refs_to_static" feature. We can fix TODO item now. Fix this by defining owner in vtable so we can read it from there. As this table needs to be const we need to define it in operations so we do not need pass THIS_MODULE alongside with GenDiskBuilder::build(). This will probably fix some use after free. Fixes: 3253aba3408a ("rust: block: introduce `kernel::block::mq` module") Signed-off-by: Kari Argillander --- drivers/block/rnull/rnull.rs | 1 + rust/kernel/block/mq.rs | 1 + rust/kernel/block/mq/gen_disk.rs | 30 ++++-------------------------- rust/kernel/block/mq/operations.rs | 30 ++++++++++++++++++++++++++++++ 4 files changed, 36 insertions(+), 26 deletions(-) diff --git a/drivers/block/rnull/rnull.rs b/drivers/block/rnull/rnull.rs index a9d5e575a2c4..862369ab9b5c 100644 --- a/drivers/block/rnull/rnull.rs +++ b/drivers/block/rnull/rnull.rs @@ -74,6 +74,7 @@ struct QueueData { =20 #[vtable] impl Operations for NullBlkDevice { + type ThisModule =3D THIS_MODULE; type QueueData =3D KBox; =20 #[inline(always)] diff --git a/rust/kernel/block/mq.rs b/rust/kernel/block/mq.rs index 1fd0d54dd549..0c8e9e316952 100644 --- a/rust/kernel/block/mq.rs +++ b/rust/kernel/block/mq.rs @@ -68,6 +68,7 @@ //! //! #[vtable] //! impl Operations for MyBlkDevice { +//! type ThisModule =3D THIS_MODULE; //! type QueueData =3D (); //! //! fn queue_rq(_queue_data: (), rq: ARef>, _is_last: bo= ol) -> Result { diff --git a/rust/kernel/block/mq/gen_disk.rs b/rust/kernel/block/mq/gen_di= sk.rs index 1ce815c8cdab..4d5d378577ec 100644 --- a/rust/kernel/block/mq/gen_disk.rs +++ b/rust/kernel/block/mq/gen_disk.rs @@ -7,7 +7,7 @@ =20 use crate::{ bindings, - block::mq::{Operations, TagSet}, + block::mq::{operations::OperationsVTable, Operations, TagSet}, error::{self, from_err_ptr, Result}, fmt::{self, Write}, prelude::*, @@ -126,32 +126,10 @@ pub fn build( ) })?; =20 - const TABLE: bindings::block_device_operations =3D bindings::block= _device_operations { - submit_bio: None, - open: None, - release: None, - ioctl: None, - compat_ioctl: None, - check_events: None, - unlock_native_capacity: None, - getgeo: None, - set_read_only: None, - swap_slot_free_notify: None, - report_zones: None, - devnode: None, - alternative_gpt_sector: None, - get_unique_id: None, - // TODO: Set to THIS_MODULE. Waiting for const_refs_to_static = feature to - // be merged (unstable in rustc 1.78 which is staged for linux= 6.10) - // - owner: core::ptr::null_mut(), - pr_ops: core::ptr::null_mut(), - free_disk: None, - poll_bio: None, - }; - // SAFETY: `gendisk` is a valid pointer as we initialized it above - unsafe { (*gendisk).fops =3D &TABLE }; + unsafe { + (*gendisk).fops =3D OperationsVTable::::build_block_device_= operations(); + } =20 let mut writer =3D NullTerminatedFormatter::new( // SAFETY: `gendisk` points to a valid and initialized instanc= e. We diff --git a/rust/kernel/block/mq/operations.rs b/rust/kernel/block/mq/oper= ations.rs index 8ad46129a52c..0f8f616590fb 100644 --- a/rust/kernel/block/mq/operations.rs +++ b/rust/kernel/block/mq/operations.rs @@ -10,6 +10,7 @@ error::{from_result, Result}, prelude::*, sync::{aref::ARef, Refcount}, + this_module::ThisModule, types::ForeignOwnable, }; use core::marker::PhantomData; @@ -28,6 +29,9 @@ /// [module level documentation]: kernel::block::mq #[macros::vtable] pub trait Operations: Sized { + /// Module ownership for this device, provided via `THIS_MODULE`. + type ThisModule: ThisModule; + /// Data associated with the `struct request_queue` that is allocated = for /// the `GenDisk` associated with this `Operations` implementation. type QueueData: ForeignOwnable; @@ -280,7 +284,33 @@ impl OperationsVTable { show_rq: None, }; =20 + const BLOCK_OPS: bindings::block_device_operations =3D bindings::block= _device_operations { + submit_bio: None, + open: None, + release: None, + ioctl: None, + compat_ioctl: None, + check_events: None, + unlock_native_capacity: None, + getgeo: None, + set_read_only: None, + swap_slot_free_notify: None, + report_zones: None, + devnode: None, + alternative_gpt_sector: None, + get_unique_id: None, + owner: T::ThisModule::OWNER.as_ptr(), + pr_ops: core::ptr::null_mut(), + free_disk: None, + poll_bio: None, + }; + pub(crate) const fn build() -> &'static bindings::blk_mq_ops { &Self::VTABLE } + + pub(crate) const fn build_block_device_operations() -> &'static bindin= gs::block_device_operations + { + &Self::BLOCK_OPS + } } --=20 2.43.0