open-amt-cloud-toolkit / rpc-go

The Remote Provisioning Client (RPC) communicates with the Manageability Engine Interface (MEI) and Remote Provisioning Service (RPS) interfaces.
https://open-amt-cloud-toolkit.github.io/docs/
Apache License 2.0
13 stars 15 forks source link

Nil Pointer deferences on configure amtfeatures all #548

Closed bkgoodman closed 5 months ago

bkgoodman commented 5 months ago

I do: ./rpc configure amtfeatures all

With version:

RPC
Version Development Build
Protocol 4.0.0

Running on: Ubuntu 22.04.1 LTS with 5.19.0-41-generic

Built from go version go1.18.1 linux/amd64

with:
```
commit a73486d (HEAD -> main, origin/main, origin/HEAD)
Author: Mike \michael.johanson@intel.com
Date:   Mon Jun 3 10:34:24 2024 -0700

   ci: move permissions to job level (#541)
```

I get:

root@xxxxxx:/home/xxxx/rpc-go# ./rpc configure amtfeatures all
Please enter AMT Password:
time="2024-06-05T13:08:06-04:00" level=info msg="configuring AMT Features"
panic: runtime error: invalid memory address or nil pointer dereference
[signal SIGSEGV: segmentation violation code=0x1 addr=0x40 pc=0x6c0422]

goroutine 1 [running]:
github.com/open-amt-cloud-toolkit/go-wsman-messages/v2/pkg/wsman/client.(*Target).Post(0xc0000c2420, {0xc00016e000, 0x2d1})
        /root/go/pkg/mod/github.com/open-amt-cloud-toolkit/go-wsman-messages/v2@v2.5.2/pkg/wsman/client/wsman.go:133 +0xe82
github.com/open-amt-cloud-toolkit/go-wsman-messages/v2/internal/message.(*Base).Execute(0xc0000eac58?, 0xc0000c0400)
        /root/go/pkg/mod/github.com/open-amt-cloud-toolkit/go-wsman-messages/v2@v2.5.2/internal/message/base.go:95 +0x3a
github.com/open-amt-cloud-toolkit/go-wsman-messages/v2/pkg/wsman/amt/redirection.Service.Get({{_, {_, _}, {_, _}}})
        /root/go/pkg/mod/github.com/open-amt-cloud-toolkit/go-wsman-messages/v2@v2.5.2/pkg/wsman/amt/redirection/service.go:35 +0x165
rpc/internal/local/amt.(*GoWSMANMessages).GetRedirectionService(_)
        /home/bkg/rpc-go/internal/local/amt/wsman.go:358 +0xd7
rpc/internal/local.(*ProvisioningService).SetAMTFeatures(0xc0000ebea0)
        /home/bkg/rpc-go/internal/local/features.go:24 +0xea
rpc/internal/local.(*ProvisioningService).Configure(0xc0000ebea0)
        /home/bkg/rpc-go/internal/local/configure.go:53 +0x2be
rpc/internal/local.ExecuteCommand(0xc0000fcd80)
        /home/bkg/rpc-go/internal/local/lps.go:62 +0x2d1
main.runRPC({0xc0000a6000?, 0xc0000ebf70?, 0x407999?})
        /home/bkg/rpc-go/cmd/main.go:38 +0x33
main.main()
        /home/bkg/rpc-go/cmd/main.go:82 +0x94
bkgoodman commented 5 months ago

Clarified build

graikhel-intel commented 5 months ago

Do you get a similar error when you do this ./rpc configure amtfeatures -kvm -sol -ider -userConsent none?

bkgoodman commented 5 months ago

Yes. Same backtrace. But also when I enter an incorrect password...? And on almost any command I try - configure syncclock configure amtpassword etc:

./rpc configure syncclock
Please enter AMT Password:
time="2024-06-05T13:45:49-04:00" level=info msg="synchronizing time"
time="2024-06-05T13:45:49-04:00" level=info msg="getting low accuracy time"
panic: runtime error: invalid memory address or nil pointer dereference
[signal SIGSEGV: segmentation violation code=0x1 addr=0x40 pc=0x6c0422]

github.com/open-amt-cloud-toolkit/go-wsman-messages/v2/pkg/wsman/client.(*Target).Post(0xc00007a000, {0xc000190000, 0x2ce})
        /root/go/pkg/mod/github.com/open-amt-cloud-toolkit/go-wsman-messages/v2@v2.5.2/pkg/wsman/client/wsman.go:133 +0xe82
github.com/open-amt-cloud-toolkit/go-wsman-messages/v2/internal/message.(*Base).Execute(0xc0000e8d58?, 0xc000022040)
        /root/go/pkg/mod/github.com/open-amt-cloud-toolkit/go-wsman-messages/v2@v2.5.2/internal/message/base.go:95 +0x3a
github.com/open-amt-cloud-toolkit/go-wsman-messages/v2/pkg/wsman/amt/general.Settings.Get({{_, {_, _}, {_, _}}})
        /root/go/pkg/mod/github.com/open-amt-cloud-toolkit/go-wsman-messages/v2@v2.5.2/pkg/wsman/amt/general/settings.go:31 +0x147
rpc/internal/local/amt.(*GoWSMANMessages).GetGeneralSettings(_)
        /home/bkg/rpc-go/internal/local/amt/wsman.go:110 +0xcf
rpc/internal/local.(*ProvisioningService).ChangeAMTPassword(0xc0000e9ea0)
        /home/bkg/rpc-go/internal/local/amtPassword.go:19 +0x67
rpc/internal/local.(*ProvisioningService).Configure(0xc0000e9ea0)
        /home/bkg/rpc-go/internal/local/configure.go:47 +0x2f8
rpc/internal/local.ExecuteCommand(0xc0000f8d80)
        /home/bkg/rpc-go/internal/local/lps.go:62 +0x2d1
main.runRPC({0xc00009c060?, 0xc0000e9f70?, 0x407999?})
        /home/bkg/rpc-go/cmd/main.go:38 +0x33
main.main()
        /home/bkg/rpc-go/cmd/main.go:82 +0x94
 ./rpc configure amtpassword
Please enter AMT Password:
Please enter New AMT Password:
Please confirm New AMT Password:
panic: runtime error: invalid memory address or nil pointer dereference
[signal SIGSEGV: segmentation violation code=0x1 addr=0x40 pc=0x6c0422]

time="2024-06-05T13:45:58-04:00" level=info msg="synchronizing time"
time="2024-06-05T13:45:58-04:00" level=info msg="getting low accuracy time"
panic: runtime error: invalid memory address or nil pointer dereference
[signal SIGSEGV: segmentation violation code=0x1 addr=0x40 pc=0x6c0422]

goroutine 1 [running]:
github.com/open-amt-cloud-toolkit/go-wsman-messages/v2/pkg/wsman/client.(*Target).Post(0xc0000c0420, {0xc000104400, 0x39f})
        /root/go/pkg/mod/github.com/open-amt-cloud-toolkit/go-wsman-messages/v2@v2.5.2/pkg/wsman/client/wsman.go:133 +0xe82
github.com/open-amt-cloud-toolkit/go-wsman-messages/v2/internal/message.(*Base).Execute(0x1?, 0xc0000be400)
        /root/go/pkg/mod/github.com/open-amt-cloud-toolkit/go-wsman-messages/v2@v2.5.2/internal/message/base.go:95 +0x3a
github.com/open-amt-cloud-toolkit/go-wsman-messages/v2/pkg/wsman/amt/timesynchronization.Service.GetLowAccuracyTimeSynch({{_, {_, _}, {_, _}}})
        /root/go/pkg/mod/github.com/open-amt-cloud-toolkit/go-wsman-messages/v2@v2.5.2/pkg/wsman/amt/timesynchronization/service.go:135 +0x389
rpc/internal/local/amt.(*GoWSMANMessages).GetLowAccuracyTimeSynch(_)
        /home/bkg/rpc-go/internal/local/amt/wsman.go:313 +0xcf
rpc/internal/local.(*ProvisioningService).GetLowAccuracyTimeSynch(0xc0000e9ea0)
        /home/bkg/rpc-go/internal/local/time.go:30 +0xb4
rpc/internal/local.(*ProvisioningService).SynchronizeTime(0xc000162000?)
        /home/bkg/rpc-go/internal/local/time.go:17 +0x66
rpc/internal/local.(*ProvisioningService).Configure(0xc0000e9ea0)
        /home/bkg/rpc-go/internal/local/configure.go:45 +0x205
rpc/internal/local.ExecuteCommand(0xc0000f8d80)
        /home/bkg/rpc-go/internal/local/lps.go:62 +0x2d1
main.runRPC({0xc0000a6000?, 0xc0000e9f70?, 0x407999?})
        /home/bkg/rpc-go/cmd/main.go:38 +0x33
main.main()
        /home/bkg/rpc-go/cmd/main.go:82 +0x94
root@edge5200:/home/bkg/rpc-go# ./rpc configure
bkgoodman commented 5 months ago

(But the rpc amtinfo command does work.)

graikhel-intel commented 5 months ago

Thanks @bkgoodman. We will look into this.

bkgoodman commented 5 months ago

Seems that the offending lines are just wrong.

If an error was returned, you'd expect that will often be nil.

I will try to debug why there was an error here...

       res, err := t.Do(req)
        if err != nil {
                res.Body.Close()

                return nil, err
        }
rsdmike commented 5 months ago

Yes, I came across this as well the other day as it was causing all sorts of problems, I fixed it in our https://github.com/open-amt-cloud-toolkit/go-wsman-messages/releases/tag/v2.7.1 release of go-wsman-messages yesterday. I will update rpc-go shortly.

bkgoodman commented 5 months ago

It was being caused by the connection getting:

Post "http://localhost:16992/wsman": dial tcp 127.0.0.1:16992: connect: connection refused

I am not 100% sure why. I mean - i cannot connect to this from the local machine, though it works from a remote machine. I am not exactly sure if this is the way AMT network connectivity is supposed to work?

That said, amtinfo works - I would assume it is using a different connectivity method?

rsdmike commented 5 months ago

At a high level, amtinfo uses local driver calls to get information and doesn't use localhost:16992 (which is the LMS service). When using configure commands, as of today, those commands don't have equivalent driver calls and need to talk to AMT using LMS. This is something we plan to address in the future to eliminate the LMS requirement. But for now, running snap install lms for example, should fix the connection issue. Nonetheless, the app shouldn't panic and we'll get a fix out for that. You can track the progress of the LMS requirement with this task https://github.com/open-amt-cloud-toolkit/rpc-go/issues/246 . This is assuming you do not want to have RPS running, you could do remote configuration if you don't wish to use LMS for local configuration.

rsdmike commented 5 months ago

@bkgoodman give it a try now, the panic should be fixed with https://github.com/open-amt-cloud-toolkit/rpc-go/releases/tag/v2.34.2

bkgoodman commented 5 months ago

Yep - returns actual error. Thanks!

time="2024-06-06T07:49:06-04:00" level=info msg="synchronizing time"
time="2024-06-06T07:49:06-04:00" level=info msg="getting low accuracy time"
time="2024-06-06T07:49:06-04:00" level=error msg="failed GetTimeOffset"
time="2024-06-06T07:49:06-04:00" level=error msg="Post \"http://localhost:16992/wsman\": dial tcp 127.0.0.1:16992: connect: connection refused"