2022-09-27 13:49:39

by Miguel Ojeda

[permalink] [raw]
Subject: [PATCH v10 13/27] rust: export generated symbols

All symbols are reexported reusing the `EXPORT_SYMBOL_GPL` macro
from C. The lists of symbols are generated on the fly.

There are three main sets of symbols to distinguish:

- The ones from the `core` and `alloc` crates (from the Rust
standard library). The code is licensed as Apache/MIT.

- The ones from our abstractions in the `kernel` crate.

- The helpers (already exported since they are not generated).

We export everything as GPL. This ensures we do not mistakenly
expose GPL kernel symbols/features as non-GPL, even indirectly.

Reviewed-by: Kees Cook <[email protected]>
Co-developed-by: Alex Gaynor <[email protected]>
Signed-off-by: Alex Gaynor <[email protected]>
Co-developed-by: Wedson Almeida Filho <[email protected]>
Signed-off-by: Wedson Almeida Filho <[email protected]>
Co-developed-by: Björn Roy Baron <[email protected]>
Signed-off-by: Björn Roy Baron <[email protected]>
Signed-off-by: Miguel Ojeda <[email protected]>
---
rust/exports.c | 21 +++++++++++++++++++++
1 file changed, 21 insertions(+)
create mode 100644 rust/exports.c

diff --git a/rust/exports.c b/rust/exports.c
new file mode 100644
index 000000000000..bb7cc64cecd0
--- /dev/null
+++ b/rust/exports.c
@@ -0,0 +1,21 @@
+// SPDX-License-Identifier: GPL-2.0
+/*
+ * A hack to export Rust symbols for loadable modules without having to redo
+ * the entire `include/linux/export.h` logic in Rust.
+ *
+ * This requires the Rust's new/future `v0` mangling scheme because the default
+ * one ("legacy") uses invalid characters for C identifiers (thus we cannot use
+ * the `EXPORT_SYMBOL_*` macros).
+ *
+ * All symbols are exported as GPL-only to guarantee no GPL-only feature is
+ * accidentally exposed.
+ */
+
+#include <linux/module.h>
+
+#define EXPORT_SYMBOL_RUST_GPL(sym) extern int sym; EXPORT_SYMBOL_GPL(sym)
+
+#include "exports_core_generated.h"
+#include "exports_alloc_generated.h"
+#include "exports_bindings_generated.h"
+#include "exports_kernel_generated.h"
--
2.37.3


2022-09-27 15:36:38

by Greg Kroah-Hartman

[permalink] [raw]
Subject: Re: [PATCH v10 13/27] rust: export generated symbols

On Tue, Sep 27, 2022 at 03:14:44PM +0200, Miguel Ojeda wrote:
> All symbols are reexported reusing the `EXPORT_SYMBOL_GPL` macro
> from C. The lists of symbols are generated on the fly.
>
> There are three main sets of symbols to distinguish:
>
> - The ones from the `core` and `alloc` crates (from the Rust
> standard library). The code is licensed as Apache/MIT.
>
> - The ones from our abstractions in the `kernel` crate.
>
> - The helpers (already exported since they are not generated).
>
> We export everything as GPL. This ensures we do not mistakenly
> expose GPL kernel symbols/features as non-GPL, even indirectly.
>
> Reviewed-by: Kees Cook <[email protected]>
> Co-developed-by: Alex Gaynor <[email protected]>
> Signed-off-by: Alex Gaynor <[email protected]>
> Co-developed-by: Wedson Almeida Filho <[email protected]>
> Signed-off-by: Wedson Almeida Filho <[email protected]>
> Co-developed-by: Bj?rn Roy Baron <[email protected]>
> Signed-off-by: Bj?rn Roy Baron <[email protected]>
> Signed-off-by: Miguel Ojeda <[email protected]>
> ---
> rust/exports.c | 21 +++++++++++++++++++++
> 1 file changed, 21 insertions(+)
> create mode 100644 rust/exports.c
>
> diff --git a/rust/exports.c b/rust/exports.c
> new file mode 100644
> index 000000000000..bb7cc64cecd0
> --- /dev/null
> +++ b/rust/exports.c
> @@ -0,0 +1,21 @@
> +// SPDX-License-Identifier: GPL-2.0
> +/*
> + * A hack to export Rust symbols for loadable modules without having to redo
> + * the entire `include/linux/export.h` logic in Rust.
> + *
> + * This requires the Rust's new/future `v0` mangling scheme because the default
> + * one ("legacy") uses invalid characters for C identifiers (thus we cannot use
> + * the `EXPORT_SYMBOL_*` macros).
> + *
> + * All symbols are exported as GPL-only to guarantee no GPL-only feature is
> + * accidentally exposed.
> + */
> +
> +#include <linux/module.h>
> +
> +#define EXPORT_SYMBOL_RUST_GPL(sym) extern int sym; EXPORT_SYMBOL_GPL(sym)
> +
> +#include "exports_core_generated.h"
> +#include "exports_alloc_generated.h"
> +#include "exports_bindings_generated.h"
> +#include "exports_kernel_generated.h"
> --
> 2.37.3

Reviewed-by: Greg Kroah-Hartman <[email protected]>