yggdrasil-network / yggdrasil-go

An experiment in scalable routing as an encrypted IPv6 overlay network
https://yggdrasil-network.github.io
Other
3.61k stars 243 forks source link

signal SIGSEGV: segmentation violation code=0x1 addr=0x700 pc=0x65d48f #671

Closed neilalexander closed 3 years ago

neilalexander commented 4 years ago

Reported by @kravietz, reposted without private keys and other potentially sensitive data.

# yggdrasil -useconffile /etc/yggdrasil.conf
2020/03/31 10:39:50 Build name: yggdrasil
2020/03/31 10:39:50 Build version: 0.3.13
2020/03/31 10:39:50 Starting up...
panic: runtime error: invalid memory address or nil pointer dereference
[signal SIGSEGV: segmentation violation code=0x1 addr=0x700 pc=0x65d48f]

goroutine 16 [running]:
github.com/yggdrasil-network/yggdrasil-go/src/yggdrasil.(*switchTable).start(...)
        /home/circleci/project/src/yggdrasil/switch.go:582
github.com/yggdrasil-network/yggdrasil-go/src/yggdrasil.(*Core)._start(0xc000116800, 0xc0000ce900, 0xc00006ea20, 0x0, 0x0, 0x0)
        /home/circleci/project/src/yggdrasil/core.go:170 +0x30f
github.com/yggdrasil-network/yggdrasil-go/src/yggdrasil.(*Core).Start.func1()
        /home/circleci/project/src/yggdrasil/core.go:141 +0x52
github.com/Arceliar/phony.Block.func1()
        /go/pkg/mod/github.com/!arceliar/phony@v0.0.0-20191006174943-d0c68492aca0/actor.go:89
+0x2f
github.com/Arceliar/phony.(*Inbox).run(0xc000116800)
        /go/pkg/mod/github.com/!arceliar/phony@v0.0.0-20191006174943-d0c68492aca0/actor.go:104 +0x8d
created by github.com/Arceliar/phony.(*Inbox).restart
        /go/pkg/mod/github.com/!arceliar/phony@v0.0.0-20191006174943-d0c68492aca0/actor.go:130 +0x3f

With the following config file (perhaps some syntax errors are causing it but it shouldn't SIGSEGV anyway):

{
  "Peers": [],
  "InterfacePeers": {},
  "Listen": [
        "tcp://[::]:8082"
  ],
  "AdminListen": "unix:///var/run/yggdrasil.sock",
  "MulticastInterfaces": [
        ".*"
  ],
  "AllowedEncryptionPublicKeys": [],
  "EncryptionPublicKey": "53fe55fd1daab470936f85e1aa1f4b16190b541c6daa6feb41bcc70a63000f5b",
  "EncryptionPrivateKey": "xxxx",
  "SigningPublicKey": "95b61c31f3c0e04eba6dbc97686d8f3f39c21fee7728053c5ed0e4bd022868a2",
  "SigningPrivateKey": "xxxx",
  "LinkLocalTCPPort": 8081,
  "IfName": "auto",
  "IfTAPMode": false,
  "IfMTU": 65535,
  "SessionFirewall": {
    "Enable": false,
    "AllowFromDirect": true,
    "AllowFromRemote": true,
    "AlwaysAllowOutbound": true,
    "WhitelistEncryptionPublicKeys": [],
    "BlacklistEncryptionPublicKeys": []
  },
  "TunnelRouting": {
    "Enable": false,
    "IPv6Destinations": {},
    "IPv6Sources": [],
    "IPv4Destinations": {},
    "IPv4Sources": []
  },
  "SwitchOptions": {
    "MaxTotalQueueSize": 4194304
  },
  "NodeInfoPrivacy": false,
  "NodeInfo": {
    "name": "xxx"
  }
}
kravietz commented 4 years ago

This is fine, these are disposable keys and it doesn't make sense to diagnose SIGSEGV if half of the data is redacted :)

neilalexander commented 4 years ago

This is fine, these are disposable keys and it doesn't make sense to diagnose SIGSEGV if half of the data is redacted :)

Best to let us know if they are throwaway keys so that we won’t redact them :-)

kravietz commented 4 years ago

Ok no problem. This might be related to private/public key formatting or mismatch (we had one issue like this in the past if you remember). I've added the whole offending config here https://paste.sr.ht/%7Ekravietz/5235f773912d2e06072ef9a24fae0aecf9fb9044 all keys are disposable :)

Arceliar commented 4 years ago

Thanks @kravietz, this seems to be caused by a mismatch in private/public encryption keys. If I make a config with only those keys (and nothing else), it crashes. If I use the config and comment out those lines (so it generates new keys), there's no crash.

But that's not a helpful error message. Our problem is here: https://github.com/yggdrasil-network/yggdrasil-go/blob/d160eccab00443187e2343c707c60f37c7fbcfde/src/yggdrasil/core.go#L163

If Core._init returns an error (due to bad keys, I guess) then it doesn't make it far enough to run switchTable.init, so switchTable.core remains nil. Then when we segfault when we try to reach the logger via the (nil) core here: https://github.com/yggdrasil-network/yggdrasil-go/blob/d160eccab00443187e2343c707c60f37c7fbcfde/src/yggdrasil/switch.go#L582

So I think all we can do here is check for an error from Core._init, log it better, and shut down gracefully somehow.