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

add some secure compilation options #658

Merged
merged 1 commit into from
Aug 2, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 4 additions & 3 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ LDFLAGS := "-X google.golang.org/protobuf/reflect/protoregistry.conflictPolicy=w
-X kmesh.net/kmesh/pkg/version.gitCommit=$(GIT_COMMIT_HASH) \
-X kmesh.net/kmesh/pkg/version.gitTreeState=$(GIT_TREESTATE) \
-X kmesh.net/kmesh/pkg/version.buildDate=$(BUILD_DATE)"
EXTLDFLAGS := '-fPIE -pie -Wl,-z,relro -Wl,-z,now -Wl,-z,noexecstack'

# target
APPS1 := kmesh-daemon
Expand Down Expand Up @@ -79,7 +80,7 @@ all:

$(call printlog, BUILD, $(APPS1))
$(QUIET) (export PKG_CONFIG_PATH=$(PKG_CONFIG_PATH):$(ROOT_DIR)mk; \
$(GO) build -ldflags $(LDFLAGS) -tags $(ENHANCED_KERNEL) -o $(APPS1) $(GOFLAGS) ./daemon/main.go)
$(GO) build -ldflags $(LDFLAGS) -ldflags "-linkmode=external -extldflags $(EXTLDFLAGS)" -tags $(ENHANCED_KERNEL) -o $(APPS1) $(GOFLAGS) ./daemon/main.go)

$(call printlog, BUILD, "kernel")
$(QUIET) make -C kernel/ko_src
Expand All @@ -89,7 +90,7 @@ all:

$(call printlog, BUILD, $(APPS3))
$(QUIET) (export PKG_CONFIG_PATH=$(PKG_CONFIG_PATH):$(ROOT_DIR)mk; \
$(GO) build -ldflags $(LDFLAGS) -tags $(ENHANCED_KERNEL) -o $(APPS3) $(GOFLAGS) ./cniplugin/main.go)
$(GO) build -ldflags $(LDFLAGS) -ldflags "-linkmode=external -extldflags $(EXTLDFLAGS)" -tags $(ENHANCED_KERNEL) -o $(APPS3) $(GOFLAGS) ./cniplugin/main.go)

.PHONY: gen-proto
gen-proto:
Expand Down Expand Up @@ -186,4 +187,4 @@ clean:

$(QUIET) if docker ps -a -q -f name=kmesh-build | grep -q .; then \
docker rm -f kmesh-build; \
fi
fi
4 changes: 3 additions & 1 deletion api/v2-c/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,11 @@ INCLUDES = -I./

# compiler flags
LDFLAGS := -lprotobuf-c
LDFLAGS += -Wl,-z,relro -Wl,-z,now -Wl,-z,noexecstack
CFLAGS := $(EXTRA_CFLAGS) $(EXTRA_CDEFINE)
CFLAGS += -fstack-protector -fPIC
CFLAGS += -fstack-protector-strong -fPIC
CFLAGS += -Wall -Werror
CFLAGS += -D_FORTIFY_SOURCE=2 -O2

SOURCES = $(wildcard */*.c)
OBJECTS = $(subst .c,.o,$(SOURCES))
Expand Down
4 changes: 3 additions & 1 deletion bpf/deserialization_to_bpf_map/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,11 @@ INCLUDES =

# compiler flags
LDFLAGS := -lbpf -lboundscheck
LDFLAGS += -Wl,-z,relro -Wl,-z,now -Wl,-z,noexecstack
CFLAGS := $(EXTRA_CFLAGS) $(EXTRA_CDEFINE)
CFLAGS += -fstack-protector -fPIC
CFLAGS += -fstack-protector-strong -fPIC
CFLAGS += -Wall -Werror
CFLAGS += -D_FORTIFY_SOURCE=2 -O2

SOURCES = $(wildcard *.c)
OBJECTS = $(subst .c,.o,$(SOURCES))
Expand Down
Loading