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

debug/elf: don't check section size #33121

Open
gregory-m opened this issue Jul 15, 2019 · 3 comments
Open

debug/elf: don't check section size #33121

gregory-m opened this issue Jul 15, 2019 · 3 comments

Comments

@gregory-m
Copy link
Contributor

@gregory-m gregory-m commented Jul 15, 2019

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

go1.12.7
also reproducible on tip

Does this issue reproduce with the latest release?

yes

What did you do?

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

package main

import (
	"debug/elf"
	"fmt"
	"strings"
)

func main() {
	data := "\u007fELF\x02\x01\x010000000000000" +
		"\x010000000000000000000" +
		"\x02\x00\x00\x00\x00\x00\x00\x0000000000\x00\x00\x00\x00" +
		"000\x0000"

	_, err := elf.NewFile(strings.NewReader(data))
	if err != nil {
		fmt.Println(err)
	}
}

What did you expect to see?

no panic

What did you see instead?

panic: runtime error: makeslice: len out of range

goroutine 1 [running]:
debug/elf.(*Section).Data(0x44b2c0, 0x43e300, 0x7f6900, 0x206590, 0x109440, 0x7fb880, 0x0, 0x0)
	/usr/local/go/src/debug/elf/file.go:105 +0x40
debug/elf.NewFile(0x15d640, 0x43e2e0, 0x43e2e0, 0x1293, 0x432070, 0x11)
	/usr/local/go/src/debug/elf/file.go:448 +0x1660
main.main()
	/tmp/sandbox898898450/prog.go:15 +0xa0

Fund with https://github.com/dvyukov/go-fuzz

@odeke-em odeke-em changed the title debug/elf don't check section size debug/elf: don't check section size Jul 15, 2019
@odeke-em

This comment has been minimized.

Copy link
Member

@odeke-em odeke-em commented Jul 15, 2019

Thank you for this report @gregory-m!

Kindly paging @tklauser @heschik @aclements.

@ianlancetaylor

This comment has been minimized.

Copy link
Contributor

@ianlancetaylor ianlancetaylor commented Jul 15, 2019

I'm not really sure how hard debug/elf should work to handle invalid input files.

@gregory-m

This comment has been minimized.

Copy link
Contributor Author

@gregory-m gregory-m commented Jul 16, 2019

I have same question as @ianlancetaylor, because I have 2 more panics in different places.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Linked pull requests

Successfully merging a pull request may close this issue.

None yet
3 participants
You can’t perform that action at this time.