awnumar / memguard

Secure software enclave for storage of sensitive information in memory.
Apache License 2.0
2.49k stars 124 forks source link

build fails on AIX #154

Closed jtroy closed 4 months ago

jtroy commented 7 months ago

Describe the bug memguard doesn't build on AIX because of missing support in github.com/awnumar/memcall.

To Reproduce Steps to reproduce the behaviour:

  1. build ./... either on AIX or cross-compile with GOOS=aix GOARCH=ppc64
  2. See error:
bash-4.4$ go build ./...
go: downloading lukechampine.com/frand v1.4.2
go: downloading github.com/awnumar/memcall v0.1.2
go: downloading golang.org/x/crypto v0.13.0
go: downloading github.com/aead/chacha20 v0.0.0-20180709150244-8b13a72661da
go: downloading golang.org/x/sys v0.12.0
# github.com/awnumar/memcall
../../go/pkg/mod/github.com/awnumar/memcall@v0.1.2/memcall_unix.go:15:23: undefined: unix.MADV_DONTDUMP

Expected behaviour build succeeds without error

System (please complete the following information):

Additional context I ended up here because I'm trying to build telegraf, which depends on memguard, for AIX. I've submitted a PR to add AIX support to memcall. This makes the build succeed. I will follow up with test results.

Thanks, John

jtroy commented 7 months ago

Pointing the memcall dependency to my AIX branch, I get the following test results, bearing in mind that on AIX, mlock() requires root privileges:

Without root privileges the test suite panics:

bash-4.4$ go test -count=1 -v ./...
?       github.com/awnumar/memguard/examples/stdin      [no test files]
?       github.com/awnumar/memguard/examples/streams    [no test files]
panic: runtime error: invalid memory address or nil pointer dereference
[signal SIGSEGV: segmentation violation code=0x33 addr=0x0 pc=0x100128b3c]

goroutine 1 [running]:
github.com/awnumar/memguard/core.Purge.func1(0xa000100000b5bf8)
        /home/jtroy/src/memguard/core/exit.go:23 +0x6c
github.com/awnumar/memguard/core.Purge()
        /home/jtroy/src/memguard/core/exit.go:51 +0x30
github.com/awnumar/memguard/core.Panic(...)
        /home/jtroy/src/memguard/core/exit.go:85
github.com/awnumar/memguard/core.NewBuffer(0x20)
        /home/jtroy/src/memguard/core/buffer.go:73 +0x444
github.com/awnumar/memguard/core.NewCoffer()
        /home/jtroy/src/memguard/core/coffer.go:30 +0x38
github.com/awnumar/memguard/core.init.0()
        /home/jtroy/src/memguard/core/enclave.go:15 +0x40
FAIL    github.com/awnumar/memguard     0.048s
panic: runtime error: invalid memory address or nil pointer dereference
[signal SIGSEGV: segmentation violation code=0x33 addr=0x0 pc=0x10011516c]

goroutine 1 [running]:
github.com/awnumar/memguard/core.Purge.func1(0xa000100000d3bf8)
        /home/jtroy/src/memguard/core/exit.go:23 +0x6c
github.com/awnumar/memguard/core.Purge()
        /home/jtroy/src/memguard/core/exit.go:51 +0x30
github.com/awnumar/memguard/core.Panic(...)
        /home/jtroy/src/memguard/core/exit.go:85
github.com/awnumar/memguard/core.NewBuffer(0x20)
        /home/jtroy/src/memguard/core/buffer.go:73 +0x444
github.com/awnumar/memguard/core.NewCoffer()
        /home/jtroy/src/memguard/core/coffer.go:30 +0x38
github.com/awnumar/memguard/core.init.0()
        /home/jtroy/src/memguard/core/enclave.go:15 +0x40
FAIL    github.com/awnumar/memguard/core        0.044s
panic: runtime error: invalid memory address or nil pointer dereference
[signal SIGSEGV: segmentation violation code=0x33 addr=0x0 pc=0x1001119cc]

goroutine 1 [running]:
github.com/awnumar/memguard/core.Purge.func1(0xa000100000bdbf8)
        /home/jtroy/src/memguard/core/exit.go:23 +0x6c
github.com/awnumar/memguard/core.Purge()
        /home/jtroy/src/memguard/core/exit.go:51 +0x30
github.com/awnumar/memguard/core.Panic(...)
        /home/jtroy/src/memguard/core/exit.go:85
github.com/awnumar/memguard/core.NewBuffer(0x20)
        /home/jtroy/src/memguard/core/buffer.go:73 +0x444
github.com/awnumar/memguard/core.NewCoffer()
        /home/jtroy/src/memguard/core/coffer.go:30 +0x38
github.com/awnumar/memguard/core.init.0()
        /home/jtroy/src/memguard/core/enclave.go:15 +0x40
FAIL    github.com/awnumar/memguard/examples/casting    0.027s
panic: runtime error: invalid memory address or nil pointer dereference
[signal SIGSEGV: segmentation violation code=0x33 addr=0x0 pc=0x10011979c]

goroutine 1 [running]:
github.com/awnumar/memguard/core.Purge.func1(0xa00010000123bf8)
        /home/jtroy/src/memguard/core/exit.go:23 +0x6c
github.com/awnumar/memguard/core.Purge()
        /home/jtroy/src/memguard/core/exit.go:51 +0x30
github.com/awnumar/memguard/core.Panic(...)
        /home/jtroy/src/memguard/core/exit.go:85
github.com/awnumar/memguard/core.NewBuffer(0x20)
        /home/jtroy/src/memguard/core/buffer.go:73 +0x444
github.com/awnumar/memguard/core.NewCoffer()
        /home/jtroy/src/memguard/core/coffer.go:30 +0x38
github.com/awnumar/memguard/core.init.0()
        /home/jtroy/src/memguard/core/enclave.go:15 +0x40
FAIL    github.com/awnumar/memguard/examples/deadlock   0.028s
panic: runtime error: invalid memory address or nil pointer dereference
[signal SIGSEGV: segmentation violation code=0x33 addr=0x0 pc=0x10014b83c]

goroutine 1 [running]:
github.com/awnumar/memguard/core.Purge.func1(0xa000100000a5bf8)
        /home/jtroy/src/memguard/core/exit.go:23 +0x6c
github.com/awnumar/memguard/core.Purge()
        /home/jtroy/src/memguard/core/exit.go:51 +0x30
github.com/awnumar/memguard/core.Panic(...)
        /home/jtroy/src/memguard/core/exit.go:85
github.com/awnumar/memguard/core.NewBuffer(0x20)
        /home/jtroy/src/memguard/core/buffer.go:73 +0x444
github.com/awnumar/memguard/core.NewCoffer()
        /home/jtroy/src/memguard/core/coffer.go:30 +0x38
github.com/awnumar/memguard/core.init.0()
        /home/jtroy/src/memguard/core/enclave.go:15 +0x40
FAIL    github.com/awnumar/memguard/examples/socketkey  0.027s
panic: runtime error: invalid memory address or nil pointer dereference
[signal SIGSEGV: segmentation violation code=0x33 addr=0x0 pc=0x10011480c]

goroutine 1 [running]:
github.com/awnumar/memguard/core.Purge.func1(0xa00010000187bf8)
        /home/jtroy/src/memguard/core/exit.go:23 +0x6c
github.com/awnumar/memguard/core.Purge()
        /home/jtroy/src/memguard/core/exit.go:51 +0x30
github.com/awnumar/memguard/core.Panic(...)
        /home/jtroy/src/memguard/core/exit.go:85
github.com/awnumar/memguard/core.NewBuffer(0x20)
        /home/jtroy/src/memguard/core/buffer.go:73 +0x444
github.com/awnumar/memguard/core.NewCoffer()
        /home/jtroy/src/memguard/core/coffer.go:30 +0x38
github.com/awnumar/memguard/core.init.0()
        /home/jtroy/src/memguard/core/enclave.go:15 +0x40
FAIL    github.com/awnumar/memguard/examples/stream     0.028s
FAIL

With root privileges the test suite passes except for examples/casting

bash-4.4$ go test -count=1 -v ./...
?       github.com/awnumar/memguard/examples/stdin      [no test files]
?       github.com/awnumar/memguard/examples/streams    [no test files]
=== RUN   TestFinalizer
--- PASS: TestFinalizer (0.00s)
=== RUN   TestNewBuffer
--- PASS: TestNewBuffer (0.00s)
=== RUN   TestNewBufferFromBytes
--- PASS: TestNewBufferFromBytes (0.00s)
=== RUN   TestNewBufferFromReader
--- PASS: TestNewBufferFromReader (0.00s)
=== RUN   TestNewBufferFromReaderUntil
--- PASS: TestNewBufferFromReaderUntil (0.00s)
=== RUN   TestNewBufferFromEntireReader
--- PASS: TestNewBufferFromEntireReader (0.01s)
=== RUN   TestNewBufferRandom
--- PASS: TestNewBufferRandom (0.00s)
=== RUN   TestFreeze
--- PASS: TestFreeze (0.00s)
=== RUN   TestMelt
--- PASS: TestMelt (0.00s)
=== RUN   TestSeal
--- PASS: TestSeal (0.00s)
=== RUN   TestCopy
--- PASS: TestCopy (0.00s)
=== RUN   TestCopyAt
--- PASS: TestCopyAt (0.00s)
=== RUN   TestMove
--- PASS: TestMove (0.00s)
=== RUN   TestMoveAt
--- PASS: TestMoveAt (0.00s)
=== RUN   TestScramble
--- PASS: TestScramble (0.00s)
=== RUN   TestWipe
--- PASS: TestWipe (0.00s)
=== RUN   TestSize
--- PASS: TestSize (0.00s)
=== RUN   TestDestroy
--- PASS: TestDestroy (0.00s)
=== RUN   TestIsAlive
--- PASS: TestIsAlive (0.00s)
=== RUN   TestIsMutable
--- PASS: TestIsMutable (0.00s)
=== RUN   TestEqualTo
--- PASS: TestEqualTo (0.00s)
=== RUN   TestBytes
--- PASS: TestBytes (0.00s)
=== RUN   TestReader
--- PASS: TestReader (0.00s)
=== RUN   TestString
--- PASS: TestString (0.00s)
=== RUN   TestUint16
--- PASS: TestUint16 (0.00s)
=== RUN   TestUint32
--- PASS: TestUint32 (0.00s)
=== RUN   TestUint64
--- PASS: TestUint64 (0.00s)
=== RUN   TestInt8
--- PASS: TestInt8 (0.00s)
=== RUN   TestInt16
--- PASS: TestInt16 (0.00s)
=== RUN   TestInt32
--- PASS: TestInt32 (0.00s)
=== RUN   TestInt64
--- PASS: TestInt64 (0.00s)
=== RUN   TestByteArray8
--- PASS: TestByteArray8 (0.00s)
=== RUN   TestByteArray16
--- PASS: TestByteArray16 (0.00s)
=== RUN   TestByteArray32
--- PASS: TestByteArray32 (0.00s)
=== RUN   TestByteArray64
--- PASS: TestByteArray64 (0.00s)
=== RUN   TestNewEnclave
--- PASS: TestNewEnclave (0.00s)
=== RUN   TestNewEnclaveRandom
--- PASS: TestNewEnclaveRandom (0.00s)
=== RUN   TestOpen
--- PASS: TestOpen (0.01s)
=== RUN   TestScrambleBytes
--- PASS: TestScrambleBytes (0.00s)
=== RUN   TestWipeBytes
--- PASS: TestWipeBytes (0.00s)
=== RUN   TestPurge
--- PASS: TestPurge (0.01s)
=== RUN   TestCatchSignal
--- PASS: TestCatchSignal (0.02s)
=== RUN   TestCatchInterrupt
--- PASS: TestCatchInterrupt (0.01s)
=== RUN   TestStreamNextFlush
--- PASS: TestStreamNextFlush (0.02s)
=== RUN   TestStreamReadWrite
--- PASS: TestStreamReadWrite (0.03s)
=== RUN   TestStreamingSanity
--- PASS: TestStreamingSanity (12.31s)
=== RUN   TestStreamSize
--- PASS: TestStreamSize (0.00s)
PASS
ok      github.com/awnumar/memguard     12.514s
=== RUN   TestRoundToPageSize
System page size: 4096 bytes
--- PASS: TestRoundToPageSize (0.00s)
=== RUN   TestGetBytes
--- PASS: TestGetBytes (0.00s)
=== RUN   TestNewBuffer
--- PASS: TestNewBuffer (0.00s)
=== RUN   TestLotsOfAllocs
--- PASS: TestLotsOfAllocs (7.95s)
=== RUN   TestData
--- PASS: TestData (0.00s)
=== RUN   TestBufferState
--- PASS: TestBufferState (0.00s)
=== RUN   TestDestroy
--- PASS: TestDestroy (0.00s)
=== RUN   TestBufferList
--- PASS: TestBufferList (0.00s)
=== RUN   TestNewCoffer
--- PASS: TestNewCoffer (0.00s)
=== RUN   TestCofferInit
--- PASS: TestCofferInit (0.00s)
=== RUN   TestCofferView
--- PASS: TestCofferView (0.00s)
=== RUN   TestCofferRekey
--- PASS: TestCofferRekey (0.00s)
=== RUN   TestCofferDestroy
--- PASS: TestCofferDestroy (0.00s)
=== RUN   TestCopy
--- PASS: TestCopy (0.00s)
=== RUN   TestMove
--- PASS: TestMove (0.00s)
=== RUN   TestCompare
--- PASS: TestCompare (0.00s)
=== RUN   TestScramble
--- PASS: TestScramble (0.00s)
=== RUN   TestHash
--- PASS: TestHash (0.00s)
=== RUN   TestWipe
--- PASS: TestWipe (0.00s)
=== RUN   TestEncryptDecrypt
--- PASS: TestEncryptDecrypt (0.00s)
=== RUN   TestEnclaveInit
--- PASS: TestEnclaveInit (0.00s)
=== RUN   TestNewEnclave
--- PASS: TestNewEnclave (0.00s)
=== RUN   TestSeal
--- PASS: TestSeal (0.00s)
=== RUN   TestOpen
--- PASS: TestOpen (0.00s)
=== RUN   TestEnclaveSize
--- PASS: TestEnclaveSize (0.00s)
=== RUN   TestPurge
--- PASS: TestPurge (0.01s)
=== RUN   TestPanic
--- PASS: TestPanic (0.00s)
PASS
ok      github.com/awnumar/memguard/core        8.013s
=== RUN   TestByteArray10
--- PASS: TestByteArray10 (0.00s)
=== RUN   TestUint64Array4
    casting_test.go:27: incorrect alignment [0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0] &[0 0 0 72057594037927936]
--- FAIL: TestUint64Array4 (0.00s)
=== RUN   TestSecureStruct
    casting_test.go:43: salt doesn't match
    casting_test.go:47: counter doesn't match
--- FAIL: TestSecureStruct (0.00s)
=== RUN   TestSecureStructArray
    casting_test.go:43: salt doesn't match
    casting_test.go:47: counter doesn't match
    casting_test.go:43: salt doesn't match
    casting_test.go:47: counter doesn't match
--- FAIL: TestSecureStructArray (0.00s)
=== RUN   TestSecureStructSlice
    casting_test.go:43: salt doesn't match
    casting_test.go:47: counter doesn't match
    casting_test.go:43: salt doesn't match
    casting_test.go:47: counter doesn't match
    casting_test.go:43: salt doesn't match
    casting_test.go:47: counter doesn't match
--- FAIL: TestSecureStructSlice (0.00s)
FAIL
FAIL    github.com/awnumar/memguard/examples/casting    0.056s

=== RUN   TestPanicsPoC
--- PASS: TestPanicsPoC (61.00s)
PASS
ok      github.com/awnumar/memguard/examples/deadlock   61.058s
=== RUN   TestSocketKey
--- PASS: TestSocketKey (0.01s)
PASS
ok      github.com/awnumar/memguard/examples/socketkey  0.068s
=== RUN   TestSlowRandByte
Random byte: 253
--- PASS: TestSlowRandByte (0.01s)
PASS
ok      github.com/awnumar/memguard/examples/stream     0.031s
FAIL

I haven't dug into these failures yet, but I welcome feedback or direction at this point. If I can figure out how to get the tests to pass I'll submit a PR. Thanks!

awnumar commented 6 months ago

Thanks for the PR!

Does the casting test only fail for you on AIX or in general?

awnumar commented 4 months ago

Closing because of https://github.com/awnumar/memguard/commit/78a7ad6afa56e665c0e183d68f05601cc551e798