Skip to contentSkip to conversation

libsepol: harden availability check against user CFLAGS

PATCH In review Christian Göttsche 2 participants 4 messages Nov 20, 2024 – Dec 4, 2024 SELinux security module

lore
Share & tools
lore
#0 lore raw

PATCH 1/2 libsepol: harden availability check against user CFLAGS

From: Christian Göttsche <[email protected]>

If CFLAGS set by the user contains the warnings override -Wno-error=implicit-function-declaration the availability check does not work properly. Explicitly enable and treat this warnings as failure by appending the appropriate flag.

Also include CPPFLAGS in the check.

---
 libsepol/src/Makefile | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
libsepol/src/Makefile +1 -1
index 7b0e8446..71fa3ed7 100644
@@ -31,7 +31,7 @@ endif
 
 # check for reallocarray(3) availability
 H := \#
-ifeq (yes,$(shell printf '${H}include <stdlib.h>\nint main(void){return reallocarray(NULL,0,0)==NULL;}' | $(CC) $(CFLAGS) $(LDFLAGS) -x c -o /dev/null - >/dev/null 2>&1 && echo yes))
+ifeq (yes,$(shell printf '${H}include <stdlib.h>\nint main(void){return reallocarray(NULL,0,0)==NULL;}' | $(CC) $(CPPFLAGS) $(CFLAGS) $(LDFLAGS) -Werror=implicit-function-declaration -x c -o /dev/null - >/dev/null 2>&1 && echo yes))
 override CFLAGS += -DHAVE_REALLOCARRAY
 endif
 
Signature · 1 line
2.45.2
#1 lore raw

PATCH 2/2 libselinux: harden availability check against user CFLAGS

From: Christian Göttsche <[email protected]>

If CFLAGS set by the user contains the warnings override -Wno-error=implicit-function-declaration the availability check does not work properly. Explicitly enable and treat this warnings as failure by appending the appropriate flag.

Also include CPPFLAGS in the check.

---
Triggered by oss-fuzz which uses

afl-clang-fast -O1 -fno-omit-frame-pointer -gline-tables-only -Wno-error=enum-constexpr-conversion -Wno-error=incompatible-function-pointer-types -Wno-error=int-conversion -Wno-error=deprecated-declarations -Wno-error=implicit-function-declaration -Wno-error=implicit-int -Wno-error=vla-cxx-extension -DFUZZING_BUILD_MODE_UNSAFE_FOR_PRODUCTION -fsanitize=address -fsanitize-address-use-after-scope

Build log:
https://oss-fuzz-build-logs.storage.googleapis.com/log-88d68963-9439-4745-9541-840f6e1f7307.txt

---
 libselinux/src/Makefile | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
libselinux/src/Makefile +2 -2
index 41cfbdca..d73df767 100644
@@ -104,13 +104,13 @@ override CFLAGS += -I../include -D_GNU_SOURCE $(DISABLE_FLAGS) $(PCRE_CFLAGS)
 
 # check for strlcpy(3) availability
 H := \#
-ifeq (yes,$(shell printf '${H}include <string.h>\nint main(void){char d[2];const char *s="a";return (size_t)strlcpy(d,s,sizeof(d))>=sizeof(d);}' | $(CC) $(CFLAGS) $(LDFLAGS) -x c -o /dev/null - >/dev/null 2>&1 && echo yes))
+ifeq (yes,$(shell printf '${H}include <string.h>\nint main(void){char d[2];const char *s="a";return (size_t)strlcpy(d,s,sizeof(d))>=sizeof(d);}' | $(CC) $(CPPFLAGS) $(CFLAGS) $(LDFLAGS) -Werror=implicit-function-declaration -x c -o /dev/null - >/dev/null 2>&1 && echo yes))
 override CFLAGS += -DHAVE_STRLCPY
 endif
 
 # check for reallocarray(3) availability
 H := \#
-ifeq (yes,$(shell printf '${H}include <stdlib.h>\nint main(void){return reallocarray(NULL,0,0)==NULL;}' | $(CC) $(CFLAGS) $(LDFLAGS) -x c -o /dev/null - >/dev/null 2>&1 && echo yes))
+ifeq (yes,$(shell printf '${H}include <stdlib.h>\nint main(void){return reallocarray(NULL,0,0)==NULL;}' | $(CC) $(CPPFLAGS) $(CFLAGS) $(LDFLAGS) -Werror=implicit-function-declaration -x c -o /dev/null - >/dev/null 2>&1 && echo yes))
 override CFLAGS += -DHAVE_REALLOCARRAY
 endif
 
Signature · 1 line
2.45.2
Acked-by on v1 1/2
#2 lore raw
In reply to Christian Göttsche
Quoted 11 lines · Christian Göttsche

From: Christian Göttsche <[email protected]>

If CFLAGS set by the user contains the warnings override -Wno-error=implicit-function-declaration the availability check does not work properly. Explicitly enable and treat this warnings as failure by appending the appropriate flag.

Also include CPPFLAGS in the check.

For these two patches:

Quoted 21 lines
---
 libsepol/src/Makefile | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
libsepol/src/Makefile +1 -2
index 7b0e8446..71fa3ed7 100644
@@ -31,7 +31,7 @@ endif
 
 # check for reallocarray(3) availability
 H := \#
-ifeq (yes,$(shell printf '${H}include <stdlib.h>\nint main(void){return reallocarray(NULL,0,0)==NULL;}' | $(CC) $(CFLAGS) $(LDFLAGS) -x c -o /dev/null - >/dev/null 2>&1 && echo yes))
+ifeq (yes,$(shell printf '${H}include <stdlib.h>\nint main(void){return reallocarray(NULL,0,0)==NULL;}' | $(CC) $(CPPFLAGS) $(CFLAGS) $(LDFLAGS) -Werror=implicit-function-declaration -x c -o /dev/null - >/dev/null 2>&1 && echo yes))
 override CFLAGS += -DHAVE_REALLOCARRAY
 endif
 
--

2.45.2

#3 lore raw
Quoted 11 lines · James Carter
Quoted 8 lines · Christian Göttsche

From: Christian Göttsche <[email protected]>

If CFLAGS set by the user contains the warnings override -Wno-error=implicit-function-declaration the availability check does not work properly. Explicitly enable and treat this warnings as failure by appending the appropriate flag.

Quoted 7 lines
Quoted 3 lines

Also include CPPFLAGS in the check.

For these two patches:

These two patches have been merged.
Thanks,
Jim

Quoted 21 lines
Quoted 21 lines
---
 libsepol/src/Makefile | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
libsepol/src/Makefile +1 -2
index 7b0e8446..71fa3ed7 100644
@@ -31,7 +31,7 @@ endif
 
 # check for reallocarray(3) availability
 H := \#
-ifeq (yes,$(shell printf '${H}include <stdlib.h>\nint main(void){return reallocarray(NULL,0,0)==NULL;}' | $(CC) $(CFLAGS) $(LDFLAGS) -x c -o /dev/null - >/dev/null 2>&1 && echo yes))
+ifeq (yes,$(shell printf '${H}include <stdlib.h>\nint main(void){return reallocarray(NULL,0,0)==NULL;}' | $(CC) $(CPPFLAGS) $(CFLAGS) $(LDFLAGS) -Werror=implicit-function-declaration -x c -o /dev/null - >/dev/null 2>&1 && echo yes))
 override CFLAGS += -DHAVE_REALLOCARRAY
 endif
 
--

2.45.2