Received: from list by lists.gnu.org with archive (Exim 4.90_1) id 1mIlYP-00079r-SW for mharc-grub-devel@gnu.org; Wed, 25 Aug 2021 01:34:25 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:36092) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1mIlYN-00078r-T2 for grub-devel@gnu.org; Wed, 25 Aug 2021 01:34:23 -0400 Received: from mout.gmx.net ([212.227.17.22]:38009) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1mIlYL-0001Hz-Bj for grub-devel@gnu.org; Wed, 25 Aug 2021 01:34:23 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=gmx.net; s=badeba3b8450; t=1629869657; bh=CB60EqZ18VVATOCLkL6ZCQQuultV9s2aX0i2rKcQbzc=; h=X-UI-Sender-Class:Subject:To:References:From:Date:In-Reply-To; b=C/L6NKRlSZlJlHJg0GoVz0yk4ylmG+QBAH8L3Gu1ajeT1jmHzjcfAfghoLgcJ6Lbx MXwDu+0fxcRMPYTiH0n/H6qapc/qizIvodxIba/ZNYtbhOm3BxzA21hW+BSwogkh2N WVO4AliSrF3hwghUkuaaGBh0Zka53YgRusCAXbPM= X-UI-Sender-Class: 01bb95c1-4bf8-414a-932a-4f6e2808ef9c Received: from [192.168.123.35] ([88.152.144.157]) by mail.gmx.net (mrgmx105 [212.227.17.168]) with ESMTPSA (Nemesis) id 1MowKc-1mp62B0tSQ-00qQt9; Wed, 25 Aug 2021 07:34:17 +0200 Subject: Re: [RFC PATCH 0/7] Support writing grub modules in Rust To: The development of GNU GRUB , Daniel Axtens References: <20210824133243.3296813-1-dja@axtens.net> From: Heinrich Schuchardt Message-ID: <6a29dff2-0361-b252-2da8-0d2e5d3ced8f@gmx.de> Date: Wed, 25 Aug 2021 07:34:16 +0200 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:78.0) Gecko/20100101 Thunderbird/78.13.0 MIME-Version: 1.0 In-Reply-To: <20210824133243.3296813-1-dja@axtens.net> Content-Type: text/plain; charset=utf-8; format=flowed Content-Language: en-US Content-Transfer-Encoding: quoted-printable X-Provags-ID: V03:K1:+wszJSpjnuBC8gIaHRHh4ANQrSYnCdftow/7R8OyIHf0SVmEk0g lmIVrmRwj8od/HIArWhxrLOKrKNo4ht3ST7AcZK1B4YmnFnwO7EebZzWBgKxLW0ilOB5HY6 mPPXPmV9przcOmbc6e0QHSLDo14eaCCp/kGIa+Hv+wG+Bljrck7eG/aBuaRcrPJ6kU59aMv hhkixlmVZ26N3eXUt2WtA== X-UI-Out-Filterresults: notjunk:1;V03:K0:/hzIq7YAlVc=:Mun9oW7rYR8AZCJoIjbJ8r ueBtaw2so+dmrMjtodXcwWo+PVVGSVMzRw1gp7S0p/kULxRoEsVcCW2nOVr8xCBAFFAuq1EU9 7ZuERd328bMfIzheFjOqFXs2faehKewCC66hDJvUiGUEgFN6YdD5aFKB3X2Iq2OrgtPRAZsyf 8dskCV0gZMz3tTAJEUEArBNJ4vIe6VcIKCZUJUf6y+/KVi8xSFK20MQnMuwCnvkypNzFswJhi RwIt0NmrGR8Y8H6QWGJ4dosQf354VWDr79Geo1BVBYdwQO8KEP8lLgt2qJB9TRgEh0gL505/7 ZcRhDAoE4vWdj6V4UYmn457iyz4s3aOFGKp3FQpuHwq4AcB0HlERxRICBgvrXkMQwg8nVo32l sGdAgBJYy/jC+wD8h4Nk5o6xH0Ygn9JiLYlxHvMt6zhfs9uh7aipn0Ra3aH1Tig86yZy7AdF9 K7XvcGuzZYAaAppZWk0OLbPkkxvXKL9Hw3yLYJXZOJjWG0HAYuQqzGHxXTAXwp+RPBIoCNHN7 cd3toPIpAIJdszjJWxup3qzLw4ZlHMGi1MekZwToDVPsctlOeFQo09IpO08hbeP7HQZ7/TPju chJYpYwCarP2NXxGPWz9Nxwi/OH7v1VDqdO69XHhKwa1TczBB2/pOznDA2GWsVhAWcsPOVasH GgH2LxDx/Jq00/yJjA1pi/v/riuMDX34V7/LyqRTajY7THEKUYzCZODgi9BdPlD1VB/Ox15Tv QEppvdiaIDFtYkcy87ftWbolr0GguIhgz8wh40aL3ziwHwsb+1nSEiWI34qW+RMTD0aE49Qj+ zYKPUxc7IGZbaoPJ7fRXkKuRIudE3RZ/LJ5RGRholgpy6jK/06/jcQeQP6oTJ1RjJmPLzqoB4 eznC2IzS89FwwTXg8x81SVI/zLTfDE96gjarDjpqHkFE2CcA2dSGMeIRew0AcHboA3D60/G1a aE4ELJ6K/ep8Dw/iUq2mKtXyYxScMXwE/2s02RApNfc2ZKDOuwGi4JMS1eFV86RT4R2BTRYIf 4bHV2l0chv4ir1P/otf0cPm2uefzg+mVDz8WEaonJb7cX9/z5Ov82+hI/aEjxAASQFkyR0WId WRQeU02A9EyPPO+eOL609qpb7X7v2egXdncbcOJmqUVWKqhnEGbwOsAQw== Received-SPF: pass client-ip=212.227.17.22; envelope-from=xypron.glpk@gmx.de; helo=mout.gmx.net X-Spam_score_int: -31 X-Spam_score: -3.2 X-Spam_bar: --- X-Spam_report: (-3.2 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, FREEMAIL_FROM=0.001, NICE_REPLY_A=-1.305, RCVD_IN_MSPIKE_H2=-0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: grub-devel@gnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: The development of GNU GRUB List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Wed, 25 Aug 2021 05:34:24 -0000 On 8/24/21 3:32 PM, Daniel Axtens wrote: > grub is a trusted component of the secure boot process, including > "traditional" GPG-based secure boot, UEFI-based secure boot, and the > WIP secure boot process using appended signatures. Most of grub is > written in C and has suffered from a number of memory-unsafety issues > in the past, something about which many of us have very distinct and > unpleasant memories! > > Rust is a systems programming language suitable for low-level > code. Rust can provide strong compile-time guarantees about memory > safety. It also is reasonably easy for Rust code to interoperate with > C. > > Grub's modular design may work in our favour here. Potentially > vulnerable components such as image and file-system parsers are > written as individual modules. Can we progressively rewrite these > modules in a safer language? > > This patch set provides my efforts so far in making this possible. > > It allows a module written almost entirely in Rust to be built and > run (in qemu) on x86_64-{emu,efi}, arm64-efi and powerpc-ieee1275. > > It still needs work, but it's at the stage where it's not entirely > trivial, and where I want to start getting more feedback on it. > > There are a few comments on things that need to be changed further on > in the series, but I think the biggest overarching change we probably > want to move towards doing more of what the Rust for Linux (kernel) > project has done: drop Cargo and build everything (except tests) > directly with rustc. This is a pain because Cargo is magic, but it > will resolve some hairy issues. > > (For example, currently on x86_64 platforms you can't have multiple > Rust modules because each defines a __rust_probestack intrinsic > despite my attempts to disable it. IMO that's a rustc bug and I have > reported it. But, there are other intrinsics that Rust code could > validly call, and we don't want implementations linked into each > module, we want the modules to call into the kernel. This is - as far > as I can tell - impossible to do with Cargo builds; we need finer > control.) > > Another big issue where we want to follow the Rust for Linux project > is how to handle failing allocations: by default in Rust that kills > your program (!), a situation which is entirely unacceptable for the > linux kernel. It's also unacceptable in Grub, so we should figure out > how they avoid it and learn from them. > > I have proposed a Linux Plumbers talk in the systems boot stream to > discuss this further. I'd also welcome on-list discussions. > > (Now, back to addressing the review comments on my previous patch > series!) Hello Daniel, riscv64 is one of the architectures supported by GRUB. Why is it missing in your series? Best regards Heinrich > > Daniel Axtens (7): > emu: support grub_memalign > Rust: module build infrastructure > Rust: add a slightly more idiomatic wrapper around command handling > Rust: add the rust_hello module > powerpc: Support Rust > x86_64-efi: Support Rust > arm64-efi: Support Rust > > .gitignore | 1 + > Makefile.util.def | 6 ++ > conf/Makefile.common | 1 + > configure.ac | 71 +++++++++++++++++++ > gentpl.py | 28 +++++++- > grub-core/Makefile.am | 20 ++++++ > grub-core/Makefile.core.def | 9 +++ > grub-core/commands/rust-hello/.gitignore | 1 + > grub-core/commands/rust-hello/Cargo.lock | 24 +++++++ > grub-core/commands/rust-hello/Cargo.toml | 16 +++++ > grub-core/commands/rust-hello/src/lib.rs | 57 +++++++++++++++ > grub-core/commands/rust-hello/wrap.c | 8 +++ > grub-core/kern/emu/mm.c | 6 ++ > grub-core/lib/rust/bindings.h | 4 ++ > grub-core/lib/rust/conftest/Cargo.lock | 7 ++ > grub-core/lib/rust/conftest/Cargo.toml | 10 +++ > grub-core/lib/rust/conftest/src/lib.rs | 10 +++ > grub-core/lib/rust/grub/.gitignore | 1 + > grub-core/lib/rust/grub/Cargo.toml | 8 +++ > grub-core/lib/rust/grub/src/command.rs | 50 +++++++++++++ > grub-core/lib/rust/grub/src/lib.rs | 64 +++++++++++++++++ > grub-core/lib/rust/targets/arm64-efi.json | 27 +++++++ > .../lib/rust/targets/powerpc-ieee1275.json | 28 ++++++++ > grub-core/lib/rust/targets/x86_64-efi.json | 27 +++++++ > grub-core/lib/rust/targets/x86_64-emu.json | 27 +++++++ > include/grub/dl.h | 21 +++++- > include/grub/mm.h | 2 - > tests/test_rust.in | 19 +++++ > 28 files changed, 547 insertions(+), 6 deletions(-) > create mode 100644 grub-core/commands/rust-hello/.gitignore > create mode 100644 grub-core/commands/rust-hello/Cargo.lock > create mode 100644 grub-core/commands/rust-hello/Cargo.toml > create mode 100644 grub-core/commands/rust-hello/src/lib.rs > create mode 100644 grub-core/commands/rust-hello/wrap.c > create mode 100644 grub-core/lib/rust/bindings.h > create mode 100644 grub-core/lib/rust/conftest/Cargo.lock > create mode 100644 grub-core/lib/rust/conftest/Cargo.toml > create mode 100644 grub-core/lib/rust/conftest/src/lib.rs > create mode 100644 grub-core/lib/rust/grub/.gitignore > create mode 100644 grub-core/lib/rust/grub/Cargo.toml > create mode 100644 grub-core/lib/rust/grub/src/command.rs > create mode 100644 grub-core/lib/rust/grub/src/lib.rs > create mode 100644 grub-core/lib/rust/targets/arm64-efi.json > create mode 100644 grub-core/lib/rust/targets/powerpc-ieee1275.json > create mode 100644 grub-core/lib/rust/targets/x86_64-efi.json > create mode 100644 grub-core/lib/rust/targets/x86_64-emu.json > create mode 100644 tests/test_rust.in >