lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  linux-cve-announce  PHC 
Open Source and information security mailing list archives
 
Hash Suite: Windows password security audit tool. GUI, reports in PDF.
[<prev] [next>] [day] [month] [year] [list]
Message-ID: <20231108022651.645950-6-mmaurer@google.com>
Date:   Wed,  8 Nov 2023 02:26:25 +0000
From:   Matthew Maurer <mmaurer@...gle.com>
To:     Masahiro Yamada <masahiroy@...nel.org>,
        Luis Chamberlain <mcgrof@...nel.org>,
        Miguel Ojeda <ojeda@...nel.org>,
        Alex Gaynor <alex.gaynor@...il.com>,
        Wedson Almeida Filho <wedsonaf@...il.com>,
        Andrew Morton <akpm@...ux-foundation.org>,
        "Masami Hiramatsu (Google)" <mhiramat@...nel.org>,
        "Paul E. McKenney" <paulmck@...nel.org>,
        John Ogness <john.ogness@...utronix.de>,
        Randy Dunlap <rdunlap@...radead.org>,
        Matthew Maurer <mmaurer@...gle.com>,
        Zhen Lei <thunder.leizhen@...wei.com>,
        Nhat Pham <nphamcs@...il.com>,
        Greg Kroah-Hartman <gregkh@...uxfoundation.org>,
        "Marc Aurèle La France" <tsi@...oix.net>
Cc:     linux-kbuild@...r.kernel.org, Boqun Feng <boqun.feng@...il.com>,
        Gary Guo <gary@...yguo.net>,
        "Björn Roy Baron" <bjorn3_gh@...tonmail.com>,
        Benno Lossin <benno.lossin@...ton.me>,
        Andreas Hindborg <a.hindborg@...sung.com>,
        Alice Ryhl <aliceryhl@...gle.com>,
        Nick Desaulniers <ndesaulniers@...gle.com>,
        linux-kernel@...r.kernel.org, linux-modules@...r.kernel.org,
        rust-for-linux@...r.kernel.org
Subject: [PATCH 3/3] rust: Require RUST_MODULES for module support

Currently, we don't support MODVERSIONS for Rust symbols. For users that
want to use Rust in the kernel but for whom MODVERSIONS is required,
this allows the use of built-in Rust code even with MODVERSIONS enabled.
It may additionally allow code-size reduction by avoiding exporting
symbols that won't be used without Rust modules.

Signed-off-by: Matthew Maurer <mmaurer@...gle.com>
---
 init/Kconfig          | 21 +++++++++++++++++----
 kernel/module/Kconfig |  1 +
 rust/exports.c        |  4 ++++
 3 files changed, 22 insertions(+), 4 deletions(-)

diff --git a/init/Kconfig b/init/Kconfig
index 9ffb103fc927..6912dbbee3f1 100644
--- a/init/Kconfig
+++ b/init/Kconfig
@@ -1885,7 +1885,6 @@ config RUST
 	bool "Rust support"
 	depends on HAVE_RUST
 	depends on RUST_IS_AVAILABLE
-	depends on !MODVERSIONS
 	depends on !GCC_PLUGINS
 	depends on !RANDSTRUCT
 	depends on !DEBUG_INFO_BTF || PAHOLE_HAS_LANG_EXCLUDE
@@ -1896,13 +1895,27 @@ config RUST
 	  This allows other Rust-related options, like drivers written in Rust,
 	  to be selected.
 
-	  It is also required to be able to load external kernel modules
-	  written in Rust.
-
 	  See Documentation/rust/ for more information.
 
 	  If unsure, say N.
 
+config RUST_MODULES
+	bool "Rust Module Support"
+	depends on RUST
+	depends on MODULES
+	rust_modules
+	help
+	  Enables support for Rust Modules in the kernel.
+
+	  This is required to load external kernel modules written in Rust.
+
+	  The two primary reasons to consider disabling this are:
+	  * Allow MODVERSIONS support
+	  * Allow additional code to be optimized out by the compiler if you
+	    know that you'll only be using built-in Rust code.
+
+	  If unsure, say Y.
+
 config RUSTC_VERSION_TEXT
 	string
 	depends on RUST
diff --git a/kernel/module/Kconfig b/kernel/module/Kconfig
index 0ea1b2970a23..a76128887618 100644
--- a/kernel/module/Kconfig
+++ b/kernel/module/Kconfig
@@ -158,6 +158,7 @@ config MODULE_UNLOAD_TAINT_TRACKING
 	  shown. If unsure, say N.
 
 config MODVERSIONS
+	depends on !RUST_MODULES
 	bool "Module versioning support"
 	help
 	  Usually, you have to use modules compiled with your kernel.
diff --git a/rust/exports.c b/rust/exports.c
index 83e2a7070cae..96b706048ed4 100644
--- a/rust/exports.c
+++ b/rust/exports.c
@@ -13,7 +13,11 @@
 
 #include <linux/module.h>
 
+#ifdef CONFIG_RUST_MODULES
 #define EXPORT_SYMBOL_RUST_GPL(sym) extern int sym; EXPORT_SYMBOL_GPL(sym)
+#else
+#define EXPORT_SYMBOL_RUST_GPL(sym)
+#endif
 
 #include "exports_core_generated.h"
 #include "exports_alloc_generated.h"
-- 
2.42.0.869.gea05f2083d-goog

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ