Received: from list by lists.gnu.org with archive (Exim 4.90_1) id 1mIWXx-0007R7-RV for mharc-grub-devel@gnu.org; Tue, 24 Aug 2021 09:32:57 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:40658) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1mIWXw-0007Pw-OV for grub-devel@gnu.org; Tue, 24 Aug 2021 09:32:56 -0400 Received: from mail-pg1-x530.google.com ([2607:f8b0:4864:20::530]:46922) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1mIWXq-000339-MG for grub-devel@gnu.org; Tue, 24 Aug 2021 09:32:56 -0400 Received: by mail-pg1-x530.google.com with SMTP id k14so19795646pga.13 for ; Tue, 24 Aug 2021 06:32:49 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=axtens.net; s=google; h=from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=Fr8pLhYEEDDjcD7SR2CbTrLnDCv5pJcwR2BIkRuc+0Y=; b=XTftZC3BjBmlSJqL6vlGD55MC29EWQ9+0tNxtKBBSHmq2bmvJ8gC7D9J/2tY6O7Y7e 1E8lnfqBBSUyLT0wUJ7cjDXO4u2YMwun+hQ7iZ7jRnqIMaXb2J2bIjUTdc87q1H65Lw3 lIeFveZNVl2FDQwDaOqNcrD+izOoFDaCy5CBY= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=Fr8pLhYEEDDjcD7SR2CbTrLnDCv5pJcwR2BIkRuc+0Y=; b=MrDz7jeRnOREyu9PWfbeybHhAkz+bHh75Tw8W1RBZtm917z+gVrfnVJrj4y7tx9+P4 ctDDijf0MNn4/alMelPOjrqpwf4cGTfDIwKGoQ/kMGWgDXlztG6exs1eV319tkkhVM/u upJVw0eYdhAs40UT2sDL4RCA7q9c5xmFdz8PrtRGaOqOz0YDJJBmH94baVhhALg0d2S/ 4fbXCjQiRpihwMrEGLKLI/lx1D5LKO49sJBGYFH6GJU51wl0cJf2WMrMirZ2+cjLwRnu 3EcSQTY17esvngMrQ9/uf+KURmk1Hg662P59pfsEx2zKN7dJkQqoq1SMAxGk6REB90BQ xK5A== X-Gm-Message-State: AOAM533sdoalPYgRIOczWHP26/bhzdYKJ0WR+q2G5oGQNq2OqmfWAYL0 /SZ3p2Skis2XoEMPjscsOGBFFQVJA/+1dQ== X-Google-Smtp-Source: ABdhPJx83Ty0DlyyB0UC6puKzyYwZ7MrAaeZ87EklROfcj4em6Mk/fAbFHYYJ5YnPsj4EUSVrWhlCQ== X-Received: by 2002:a62:1852:0:b0:3e1:43ea:c56b with SMTP id 79-20020a621852000000b003e143eac56bmr39882985pfy.75.1629811967647; Tue, 24 Aug 2021 06:32:47 -0700 (PDT) Received: from localhost ([2001:4479:e200:df00:90ee:2749:b9b1:fb92]) by smtp.gmail.com with ESMTPSA id pc11sm2588412pjb.17.2021.08.24.06.32.46 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 24 Aug 2021 06:32:47 -0700 (PDT) From: Daniel Axtens To: grub-devel@gnu.org Cc: Daniel Axtens Subject: [RFC PATCH 0/7] Support writing grub modules in Rust Date: Tue, 24 Aug 2021 23:32:36 +1000 Message-Id: <20210824133243.3296813-1-dja@axtens.net> X-Mailer: git-send-email 2.30.2 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Received-SPF: pass client-ip=2607:f8b0:4864:20::530; envelope-from=dja@axtens.net; helo=mail-pg1-x530.google.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, 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: Tue, 24 Aug 2021 13:32:57 -0000 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!) 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 -- 2.30.2