Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

virter vm ls segmentation fault when other non-virter libvirt VMs exist #33

Closed
mmguero opened this issue Nov 22, 2024 · 6 comments · Fixed by #34
Closed

virter vm ls segmentation fault when other non-virter libvirt VMs exist #33

mmguero opened this issue Nov 22, 2024 · 6 comments · Fixed by #34

Comments

@mmguero
Copy link
Contributor

mmguero commented Nov 22, 2024

Not sure exactly when this started happening, but:

$ virter vm ls
panic: runtime error: invalid memory address or nil pointer dereference
[signal SIGSEGV: segmentation violation code=0x1 addr=0x0 pc=0xa5ac5c]

goroutine 1 [running]:
github.com/LINBIT/virter/internal/virter.(*Virter).VMInfo(0xc000312180, {0xc0003262d0, 0x24})
    /home/user/devel/github/virter/internal/virter/vm.go:110 +0x29c
github.com/LINBIT/virter/cmd.vmCommand.vmListCommand.func1(0xc0002ba100?, {0x12e69a0?, 0x4?, 0xc94ed8?})
    /home/user/devel/github/virter/cmd/vm_list.go:35 +0x17a
github.com/spf13/cobra.(*Command).execute(0xc0002a8f08, {0x12e69a0, 0x0, 0x0})
    /home/user/.asdf/installs/golang/1.23.3/packages/pkg/mod/github.com/spf13/[email protected]/command.go:989 +0xa91
github.com/spf13/cobra.(*Command).ExecuteC(0xc000292308)
    /home/user/.asdf/installs/golang/1.23.3/packages/pkg/mod/github.com/spf13/[email protected]/command.go:1117 +0x3ff
github.com/spf13/cobra.(*Command).Execute(...)
    /home/user/.asdf/installs/golang/1.23.3/packages/pkg/mod/github.com/spf13/[email protected]/command.go:1041
github.com/spf13/cobra.(*Command).ExecuteContext(...)
    /home/user/.asdf/installs/golang/1.23.3/packages/pkg/mod/github.com/spf13/[email protected]/command.go:1034
github.com/LINBIT/virter/cmd.Execute()
    /home/user/devel/github/virter/cmd/root.go:86 +0x1ca
main.main()
    /home/user/devel/github/virter/main.go:8 +0xf

I was running v0.28.0 then checked out the latest revision and built from there (e36b0ba) but am getting the same issue.

$ apt-cache policy libvirt0:amd64
libvirt0:
  Installed: 9.0.0-4+deb12u2
  Candidate: 9.0.0-4+deb12u2
  Version table:
 *** 9.0.0-4+deb12u2 500
        500 http://ftp.debian.org/debian bookworm/main amd64 Packages
        100 /var/lib/dpkg/status
@mmguero
Copy link
Contributor Author

mmguero commented Nov 22, 2024

If this helps:

I have some other vagrant-libvirt machines (not started by virter) on this machine:

id       name                         provider state   directory                                                               
-------------------------------------------------------------------------------------------------------------------------------
db905b0  vagrant-hedgehog-raspi-build libvirt shutoff /home/user/devel/github/Malcolm/hedgehog-raspi/vagrant 

in GDB at the point of the crash:

info local
&desc = 0xc0001d8400
&meta = 0xc000406960
dom = {
  Name = "vagrant_vagrant-hedgehog-raspi-build",
  UUID = "$$\234S \303LN\221\355\327!\"\263N\214",
  ID = -1
}
err = {
  tab = 0x0,
  data = 0x0
}
network = 0xc000184008
vmMac = {
  array = 0x120 <error: Cannot access memory at address 0x120>,
  len = 824635409536,
  cap = 6
}
xmldesc = "<domain type='kvm'>\n  <name>vagrant_vagrant-hedgehog-raspi-build ...

It looks like it's trying to list some information about this other non-virter libvirt VM, and vmMac is uninitialized?

@mmguero
Copy link
Contributor Author

mmguero commented Nov 22, 2024

Also, for what it's worth, removing this other non-virter VM, the segfault does go away.

@mmguero mmguero changed the title virter vm ls segmentation fault virter vm ls segmentation fault when other non-virter libvirt VMs exist Nov 22, 2024
@JoelColledge
Copy link
Member

The crash occurs on this line:

err = xml.Unmarshal([]byte(desc.Metadata.XML), &meta)

I'm guessing desc.Metadata is nil. We probably just need a

	if desc.Metadata == nil {
		// not a virter VM
		return &VMInfo{Name: vmName}, nil
	}

Preceding the meta unmarshaling. Does that work?

mmguero added a commit to mmguero-dev/virter that referenced this issue Nov 25, 2024
mmguero added a commit to mmguero-dev/virter that referenced this issue Nov 25, 2024
@mmguero
Copy link
Contributor Author

mmguero commented Nov 25, 2024

Thanks, that does indeed solve the problem! I've opened #34 with that check.

JoelColledge pushed a commit that referenced this issue Nov 25, 2024
@mmguero
Copy link
Contributor Author

mmguero commented Nov 25, 2024

Thanks for merging! Not to be a hassle, but if it's convenient for you sometime to put out a release out containing the fix I'd appreciate it. And thanks again for looking at this.

@JoelColledge
Copy link
Member

Released: https://github.com/LINBIT/virter/releases/tag/v0.28.1

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
2 participants