54 lines
2 KiB
Diff
54 lines
2 KiB
Diff
From 6838387d66f76e8acb227102d46549a26e7b217c Mon Sep 17 00:00:00 2001
|
|
From: Enrico Scholz <enrico.scholz@informatik.tu-chemnitz.de>
|
|
Date: Sat, 19 Apr 2008 17:56:07 +0200
|
|
Subject: [PATCH 08/18] Enhanced __stack_chk_fail
|
|
|
|
* modified __stack_chk_fail() to trigger a segfault by accessing
|
|
address 0x0. Every system with an MMU known by me, segfaults
|
|
by dereferencing a NULL pointer.
|
|
|
|
* added hack to compile stack_smash_handler2 with
|
|
'--fno-omit-frame-pointer'.
|
|
---
|
|
Makefile | 3 ++-
|
|
lib/stack_smash_handler2.c | 10 +++++++++-
|
|
2 files changed, 11 insertions(+), 2 deletions(-)
|
|
|
|
diff --git a/Makefile b/Makefile
|
|
index ec97fe9..9ea5078 100644
|
|
--- a/Makefile
|
|
+++ b/Makefile
|
|
@@ -175,9 +175,10 @@ $(OBJDIR)/%.o: %.S $(ARCH)/syscalls.h $(OBJDIR)/.dirstamp
|
|
$(OBJDIR)/pthread_%.o: libpthread/pthread_%.c $(OBJDIR)/.dirstamp
|
|
$(CROSS)$(CC) $(INC) $(CFLAGS) -c $< -o $@
|
|
$(COMMENT) -$(STRIP) -x -R .comment -R .note $@
|
|
+$(OBJDIR)/stack_smash_handler2.o: XCFLAGS:=-fno-omit-frame-pointer
|
|
|
|
$(OBJDIR)/%.o: %.c $(OBJDIR)/.dirstamp
|
|
- $(CROSS)$(CC) $(INC) $(CFLAGS) -c $< -o $@ -D__dietlibc__
|
|
+ $(CROSS)$(CC) $(INC) $(CFLAGS) $(XCFLAGS) -c $< -o $@ -D__dietlibc__
|
|
$(COMMENT) -$(STRIP) -x -R .comment -R .note $@
|
|
|
|
$(addprefix $(OBJDIR)/,$(NO_STACK_PROTECTOR)): XCFLAGS+=-fno-stack-protector
|
|
diff --git a/lib/stack_smash_handler2.c b/lib/stack_smash_handler2.c
|
|
index 9e85099..ecefeb8 100644
|
|
--- a/lib/stack_smash_handler2.c
|
|
+++ b/lib/stack_smash_handler2.c
|
|
@@ -8,5 +8,13 @@ void __stack_chk_fail(void);
|
|
* diagnostics. No more. :-( */
|
|
void __stack_chk_fail(void) {
|
|
__write2("smashed stack detected, program terminated.\n");
|
|
- _exit(127);
|
|
+
|
|
+ /* trigger a segfault which can be inspected within a debugger (inclusive
|
|
+ * stack-trace). 'abort(3)' at this place would be too heavy weighted.
|
|
+ *
|
|
+ * TODO: limit this to systems which are known to have an MMU (resp. is
|
|
+ * dietlibc with stack-protector used on systems without an MMU?)
|
|
+ */
|
|
+ while (1)
|
|
+ *(char *)0 = 0;
|
|
}
|
|
--
|
|
1.6.2.5
|
|
|