bootupd: Fix /sys read-only mount issue#1974
bootupd: Fix /sys read-only mount issue#1974henrywang wants to merge 1 commit intobootc-dev:mainfrom
Conversation
efibootmgr needs write access to /sys/firmware/efi/efivars to modify EFI boot variables (like deleting boot entries with -B) Signed-off-by: Xiaofeng Wang <henrywangxf@me.com>
There was a problem hiding this comment.
Code Review
This pull request fixes an issue where efibootmgr fails due to a read-only /sys mount inside a bwrap sandbox. The change makes the /sys mount read-write, which resolves the immediate problem. However, this change affects all users of the BwrapCmd utility, potentially weakening the sandbox for commands that do not require write access to /sys. My review includes a suggestion to make this behavior configurable to adhere to the principle of least privilege.
| cmd.args(["--proc", "/proc"]); | ||
| cmd.args(["--dev", "/dev"]); | ||
| cmd.args(["--ro-bind", "/sys", "/sys"]); | ||
| cmd.args(["--bind", "/sys", "/sys"]); |
There was a problem hiding this comment.
While this change fixes the issue with efibootmgr, it makes /sys writable for all commands executed via BwrapCmd. This could be a security concern as it weakens the sandbox for commands that don't require write access to /sys, violating the principle of least privilege.
A more robust approach would be to make this configurable. For example, you could add a field to BwrapCmd to control this behavior, and default to read-only. Callers that need a writable /sys would then explicitly opt-in.
Here's an example of how you could implement this:
// In BwrapCmd struct:
sys_rw: bool,
// In BwrapCmd::new():
// ...
sys_rw: false,
// Add a new builder method:
pub fn sys_rw(mut self, rw: bool) -> Self {
self.sys_rw = rw;
self
}
// In BwrapCmd::run():
if self.sys_rw {
cmd.args(["--bind", "/sys", "/sys"]);
} else {
cmd.args(["--ro-bind", "/sys", "/sys"]);
}Could you please consider refactoring to this approach for better security?
There was a problem hiding this comment.
Yeah, could be a followup
There was a problem hiding this comment.
Or I can mount /sys read-only but add a read-write bind mount for /sys/firmware/efi/efivars. This should be more secure, I think.
There was a problem hiding this comment.
Yeah in this specific case I think that's the right thing to do.
Bootc daily CI test failed on bootc install to-existing-root test on RHEL 9.x and 10.x with the following error. The failure comes from bootc commit
0a757685ee631ca9d53df6941af4fb71e4ac1bf3or0a757685ee631ca9d53df6941af4fb71e4ac1bf3, because commit51dabaa5cb7b6313b8cd75a002862c64de3c7b85passed.efibootmgr needs write access to /sys/firmware/efi/efivars to modify EFI boot variables (like deleting boot entries with -B)
This PR is a simple fix, mount /sys as read-write.