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

x/crypto/argon2: panic if keyLen == 0 #33583

Open
guidovranken opened this issue Aug 11, 2019 · 2 comments · May be fixed by golang/crypto#95
Open

x/crypto/argon2: panic if keyLen == 0 #33583

guidovranken opened this issue Aug 11, 2019 · 2 comments · May be fixed by golang/crypto#95
Labels
help wanted NeedsFix The path to resolution is known, but the work has not been done.
Milestone

Comments

@guidovranken
Copy link

What version of Go are you using (go version)?

Does this issue reproduce with the latest release?

Assuming Playground uses the latest Go version, yes.

What operating system and processor architecture are you using (go env)?

What did you do?

https://play.golang.org/p/k07nWDYZ7Zk

What did you expect to see?

Should return empty byte slice

What did you see instead?

panic: runtime error: invalid memory address or nil pointer dereference
[signal SIGSEGV: segmentation violation code=0xffffffff addr=0x0 pc=0xab662]

goroutine 1 [running]:
golang.org/x/crypto/blake2b.(*digest).Write(0x0, 0x432240, 0x4, 0x40, 0x0, 0xf0520, 0x40c080, 0xce380)
	/tmp/gopath522840708/pkg/mod/golang.org/x/crypto@v0.0.0-20190701094942-4def268fd1a4/blake2b/blake2b.go:216 +0x22
golang.org/x/crypto/argon2.blake2bHash(0x15ee7c, 0x0, 0x0, 0x44e400, 0x400, 0x400)
	/tmp/gopath522840708/pkg/mod/golang.org/x/crypto@v0.0.0-20190701094942-4def268fd1a4/argon2/blake2b.go:26 +0xc0
golang.org/x/crypto/argon2.extractKey(0x800000, 0x10000, 0x10000, 0x10000, 0x4, 0x0, 0x1, 0x0, 0x0, 0x0)
	/tmp/gopath522840708/pkg/mod/golang.org/x/crypto@v0.0.0-20190701094942-4def268fd1a4/argon2/argon2.go:255 +0x2c0
golang.org/x/crypto/argon2.deriveKey(0x1, 0x414008, 0x1, 0x1, 0x414009, 0x1, 0x1, 0x0, 0x0, 0x0, ...)
	/tmp/gopath522840708/pkg/mod/golang.org/x/crypto@v0.0.0-20190701094942-4def268fd1a4/argon2/argon2.go:117 +0x2e0
golang.org/x/crypto/argon2.Key(...)
	/tmp/gopath522840708/pkg/mod/golang.org/x/crypto@v0.0.0-20190701094942-4def268fd1a4/argon2/argon2.go:75
main.main()
	/tmp/sandbox040143225/prog.go:9 +0x100
@FiloSottile FiloSottile changed the title golang.org/x/crypto/argon2 SIGSEGV if keyLen == 0 x/crypto/argon2: panic if keyLen == 0 Aug 11, 2019
@gopherbot gopherbot added this to the Unreleased milestone Aug 11, 2019
@FiloSottile FiloSottile added help wanted NeedsFix The path to resolution is known, but the work has not been done. labels Aug 11, 2019
@gopherbot
Copy link

Change https://golang.org/cl/189878 mentions this issue: x/crypto/argon2: fix panic when keyLen == 0

@smasher164
Copy link
Member

I may have misread the spec, but doesn't argon2 expect a minimum keyLen of 4?
https://tools.ietf.org/html/draft-irtf-cfrg-argon2-03#section-3.1

In that case, how about intentionally panicking on a keyLen < 4? Something like,

if keyLen < 4 {
	panic("argon2: tag length is too small")
}

If it's any indication, the panic is currently happening because blake2b expects a hash size of at least 1, so maybe we should error out instead.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
help wanted NeedsFix The path to resolution is known, but the work has not been done.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants