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

build: Build with sanitizers #368

Open
1 of 2 tasks
javierhonduco opened this issue Apr 21, 2022 · 1 comment
Open
1 of 2 tasks

build: Build with sanitizers #368

javierhonduco opened this issue Apr 21, 2022 · 1 comment
Labels
area/build-pipeline Something to do with CI and build pipeline area/quailty-assurance Quality matters enhancement New feature or request

Comments

@javierhonduco
Copy link
Contributor

javierhonduco commented Apr 21, 2022

As we use some C library wrappers and Golang can't prove the lifetime of objects at compile-time, it's possible that parca-agent is not memory safe.

It's very important that we have as many safeguards as possible as we run in privileged mode which we need to interact with the BPF subsystem.

Let's add memory sanitisers to parca-agent!

  • We can first start with dev builds with ASAN (will take a look at this)
  • Adding it in CI (for example integration tests) next

cc @Sylfrena

@javierhonduco
Copy link
Contributor Author

Trying now with

diff --git a/Makefile b/Makefile
index e00bbc8..e2cf2d5 100644
--- a/Makefile
+++ b/Makefile
@@ -77,7 +77,7 @@ go_env := GOOS=linux GOARCH=$(ARCH:x86_64=amd64) CC=$(CMD_CLANG) CGO_CFLAGS="-I
 ifndef DOCKER
 $(OUT_BIN): $(LIBBPF_HEADERS) $(LIBBPF_OBJ) $(filter-out *_test.go,$(GO_SRC)) $(BPF_BUNDLE) go/deps | $(OUT_DIR)
        find dist -exec touch -t 202101010000.00 {} +
-       $(go_env) go build -trimpath -v -o $(OUT_BIN) ./cmd/parca-agent
+       $(go_env) go build -asan -trimpath -v -o $(OUT_BIN) ./cmd/parca-agent
 else
 $(OUT_BIN): $(DOCKER_BUILDER) | $(OUT_DIR)
        $(call docker_builder_make,$@ VERSION=$(VERSION))
@@ -86,7 +86,7 @@ endif
 ifndef DOCKER
 $(OUT_BIN_DEBUG_INFO): go/deps
        find dist -exec touch -t 202101010000.00 {} +
-       go build -trimpath -v -o $(OUT_BIN_DEBUG_INFO) ./cmd/debug-info
+       go build -asan -trimpath -v -o $(OUT_BIN_DEBUG_INFO) ./cmd/debug-info
 else
 $(OUT_BIN_DEBUG_INFO): $(DOCKER_BUILDER) go/deps | $(OUT_DIR)
        $(call docker_builder_make,$@ VERSION=$(VERSION))

Reports:

AddressSanitizer:DEADLYSIGNAL
=================================================================
==152265==ERROR: AddressSanitizer: BUS on unknown address (pc 0x000200800001 bp 0xffff88f9e530 sp 0xffff88f9e530 T2)
==152265==The signal is caused by a READ memory access.
==152265==Hint: this fault was caused by a dereference of a high value address (see register values below).  Disassemble the provided pc to learn which register was used.
    #0 0x200800001  (<unknown module>)
    #1 0x1f5ffac in _cgo_bf053d5b1c7b_Cfunc_bpf_link__destroy (/home/vagrant/work/parca-agent/dist/parca-agent+0x1f5ffac)
    #2 0x561678 in runtime.asmcgocall.abi0 runtime/asm_arm64.s:1060

AddressSanitizer can not provide additional info.
SUMMARY: AddressSanitizer: BUS (<unknown module>)

This is likely the error we saw in #367. I should have started with enabling sanitisers 😁

@kakkoyun kakkoyun added enhancement New feature or request area/build-pipeline Something to do with CI and build pipeline labels Jun 8, 2022
@javierhonduco javierhonduco mentioned this issue Jun 8, 2022
2 tasks
@kakkoyun kakkoyun added the area/quailty-assurance Quality matters label Jul 7, 2022
@kakkoyun kakkoyun changed the title Build with sanitizers chore: Build with sanitizers Jul 7, 2022
@kakkoyun kakkoyun changed the title chore: Build with sanitizers build: Build with sanitizers Aug 4, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area/build-pipeline Something to do with CI and build pipeline area/quailty-assurance Quality matters enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants