From 4706e25644d32edb5a7a9ef5cb81df40a416d12f Mon Sep 17 00:00:00 2001 From: AlexSSD7 Date: Tue, 29 Aug 2023 15:37:09 +0100 Subject: [PATCH] Double-mount prevention enhancements --- vm/vm.go | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/vm/vm.go b/vm/vm.go index 9d627a8..8322529 100644 --- a/vm/vm.go +++ b/vm/vm.go @@ -173,6 +173,10 @@ func NewVM(logger *slog.Logger, cfg VMConfig) (*VM, error) { } } + if len(cfg.PassthroughConfig.Block) != 0 { + logger.Warn("Detected raw block device passthrough, please note that it's YOUR responsibility to ensure that no device is mounted in your OS and the VM at the same time") + } + for _, dev := range cfg.PassthroughConfig.Block { // It's always a user's responsibility to ensure that no drives are mounted // in both host and guest system. This should serve as the last resort. @@ -183,7 +187,7 @@ func NewVM(logger *slog.Logger, cfg VMConfig) (*VM, error) { } if seemsMounted { - return nil, fmt.Errorf("device '%v' is already mounted in the host system", dev.Path) + return nil, fmt.Errorf("device '%v' seems to be already mounted in the host system", dev.Path) } } @@ -543,6 +547,7 @@ func (vm *VM) runPeriodicHostMountChecker() { } if seemsMounted { + _ = vm.cmd.Process.Kill() panic(fmt.Sprintf("CRITICAL: Passed-through device '%v' appears to have been mounted on the host OS. Forcefully exiting now to prevent data corruption.", dev.Path)) } }