Bug 219456
Summary: | libpsx and libcap requires -wrap'ing of pthread_create() | ||
---|---|---|---|
Product: | Tools | Reporter: | Andrew G. Morgan (morgan) |
Component: | libcap | Assignee: | Andrew G. Morgan (morgan) |
Status: | RESOLVED CODE_FIX | ||
Severity: | enhancement | CC: | sam |
Priority: | P3 | ||
Hardware: | All | ||
OS: | Linux | ||
Kernel Version: | Subsystem: | ||
Regression: | No | Bisected commit-id: |
Description
Andrew G. Morgan
2024-11-02 01:38:50 UTC
https://stackoverflow.com/questions/35425185/is-it-possible-to-determine-at-runtime-if-a-function-has-been-implemented looks interesting. This seems to explain what I see with the static link: https://stackoverflow.com/a/37191811/14760867 Namely, with --- a/Make.Rules +++ b/Make.Rules @@ -107,7 +107,7 @@ endif USE_GPERF ?= $(shell which gperf >/dev/null 2>/dev/null && echo yes) LIBCAPLIB := -L$(topdir)/libcap -lcap -PSXLINKFLAGS := -lpthread -Wl,-wrap,pthread_create +PSXLINKFLAGS := -lpthread LIBPSXLIB := -L$(topdir)/libcap -lpsx $(PSXLINKFLAGS) INCS=$(topdir)/libcap/include/sys/capability.h $ make clean all test sudotest [...] sudo ./noexploit ; if [ $? -eq 0 ]; then exit 0; else exit 1 ; fi program starting started privileged thread dropping privilege from main process thread no privilege in main process thread: len:1, caps:"=" greatest privilege in main process thread: len:3, caps:"=ep" exploit succeeded So, without the wrapping the exploit succeeds. The reason appears to be that nothing is forcing the linking of libpsx.a in this static link case. If I manually run: $ cd tests $ gcc -O2 -Wall -Wwrite-strings -Wpointer-arith -Wcast-qual -Wcast-align -Wstrict-prototypes -Wmissing-prototypes -Wnested-externs -Winline -Wshadow -Wunreachable-code --static exploit.o -o noexploit -L/home/andrew/gits/libcap/tests/../libcap -lcap -Wl,--whole-archive -lpsx -Wl,--no-whole-archive -lpthread $ sudo ./noexploit program starting started privileged thread dropping privilege from main process thread no privilege in main process thread: len:1, caps:"=" greatest privilege in main process thread: len:1, caps:"=" exploit failed Evidently the `-Wl,--whole-archive -lpsx -Wl,--no-whole-archive` flags seem to force the linking I want. This is an interesting detail that may help with shared libraries: https://stackoverflow.com/a/27973583/14760867 I think I may have a new linkage strategy. More with the commits when I have more completely tested them. |