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

When creating a large perf map, a null pointer error is encountered #1281

Closed
1 task done
cfc4n opened this issue Dec 22, 2023 · 0 comments · Fixed by #1282
Closed
1 task done

When creating a large perf map, a null pointer error is encountered #1281

cfc4n opened this issue Dec 22, 2023 · 0 comments · Fixed by #1282
Labels
bug Something isn't working

Comments

@cfc4n
Copy link
Contributor

cfc4n commented Dec 22, 2023

Describe the bug

Use perf.NewReader to create an ebpf map. If the perCPUBuffer exceeds the threshold of the kernel, creation will fail and a null pointer error will occur.

error logs:

root@vm-server:/home/cfc4n/project/ecapture# bin/ecapture tls --mapsize=409600
tls_2023/12/22 11:43:59 ECAPTURE :: ecapture Version : linux_x86_64:--:[CORE]
tls_2023/12/22 11:43:59 ECAPTURE :: Pid Info : 14867
tls_2023/12/22 11:43:59 ECAPTURE :: Kernel Info : 5.15.131
tls_2023/12/22 11:43:59 cmd tls.go: mapSizeKB:1638400
tls_2023/12/22 11:43:59 EBPFProbeOPENSSL	module initialization
tls_2023/12/22 11:43:59 EBPFProbeOPENSSL	master key keylogger:
tls_2023/12/22 11:43:59 ECAPTURE ::	Module.Run()
tls_2023/12/22 11:43:59 EBPFProbeOPENSSL	Text MODEL
tls_2023/12/22 11:43:59 EBPFProbeOPENSSL	OpenSSL/BoringSSL version not found from shared library file, used default version:linux_default_3_0
tls_2023/12/22 11:43:59 EBPFProbeOPENSSL	HOOK type:2, binrayPath:/lib/x86_64-linux-gnu/libssl.so.3
tls_2023/12/22 11:43:59 EBPFProbeOPENSSL	Hook masterKey function:SSL_write
tls_2023/12/22 11:43:59 EBPFProbeOPENSSL	libPthread:/lib/x86_64-linux-gnu/libc.so.6
tls_2023/12/22 11:43:59 EBPFProbeOPENSSL	target all process.
tls_2023/12/22 11:43:59 EBPFProbeOPENSSL	target all users.
tls_2023/12/22 11:43:59 EBPFProbeOPENSSL	BPF bytecode filename:user/bytecode/openssl_3_0_0_kern.o
tls_2023/12/22 11:43:59 EBPFProbeOPENSSL	perfEventReader created. mapSize:1600 MB
panic: runtime error: invalid memory address or nil pointer dereference
[signal SIGSEGV: segmentation violation code=0x1 addr=0x28 pc=0x6e22e5]

goroutine 1 [running]:
github.com/cilium/ebpf/perf.NewReaderWithOptions(0xc000073680, 0x64000000, {0x97481c?, 0x70?})
	/home/cfc4n/gopath/pkg/mod/github.com/cilium/ebpf@v0.12.3/perf/reader.go:234 +0x345
github.com/cilium/ebpf/perf.NewReader(...)
	/home/cfc4n/gopath/pkg/mod/github.com/cilium/ebpf@v0.12.3/perf/reader.go:187
ecapture/user/module.(*Module).perfEventReader(0xc0000d8580, 0xc0022fc960, 0xc000073680)
	/home/cfc4n/project/ecapture/user/module/imodule.go:193 +0x1b5
ecapture/user/module.(*Module).readEvents(0xc0000d8580)
	/home/cfc4n/project/ecapture/user/module/imodule.go:181 +0x114
ecapture/user/module.(*Module).Run(0xc0000d8580)
	/home/cfc4n/project/ecapture/user/module/imodule.go:140 +0x10f
ecapture/cli/cmd.openSSLCommandFunc(0xc0000b1100?, {0x9748d4?, 0x4?, 0x974818?})
	/home/cfc4n/project/ecapture/cli/cmd/tls.go:132 +0xa50
github.com/spf13/cobra.(*Command).execute(0x1372ae0, {0xc000082cd0, 0x1, 0x1})
	/home/cfc4n/gopath/pkg/mod/github.com/spf13/cobra@v1.4.0/command.go:860 +0x67b
github.com/spf13/cobra.(*Command).ExecuteC(0x1372860)
	/home/cfc4n/gopath/pkg/mod/github.com/spf13/cobra@v1.4.0/command.go:974 +0x38d
github.com/spf13/cobra.(*Command).Execute(...)
	/home/cfc4n/gopath/pkg/mod/github.com/spf13/cobra@v1.4.0/command.go:902
ecapture/cli/cmd.Execute()
	/home/cfc4n/project/ecapture/cli/cmd/root.go:75 +0x10b
ecapture/cli.Start(...)
	/home/cfc4n/project/ecapture/cli/main.go:22
main.main()
	/home/cfc4n/project/ecapture/main.go:73 +0x28e

ref: eCapture run failed, error log: invalid memory address or nil pointer dereference

How to reproduce

var perCpuSize int = 4096 * 1024 * 1024 // 4GB
	events, err := ebpf.NewMap(&ebpf.MapSpec{
		Type: ebpf.PerfEventArray,
	})
	if err != nil {
		log.Fatal(err)
	}
	
	rd, err := NewReader(events, perCpuSize)
	if err != nil {
		log.Fatal(err)
	}

Version information

github.com/cilium/ebpf v0.12.3

Tasks

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant