Skip to contentSkip to conversation

stack_clash: Guard functions used only in 64bit

PATCH In review Petr Vorel 2 participants 8 messages Oct 24, 2023 – Oct 26, 2023

lore
Share & tools
lore

Petr Vorel

author
#0 lore raw

PATCH 1/2 stack_clash: Guard functions used only in 64bit

To avoid "defined but not used" warnings when compiled on 32bit.

---
 testcases/cve/stack_clash.c | 4 ++++
 1 file changed, 4 insertions(+)
testcases/cve/stack_clash.c +4 -0
index 3a99c49bb..56b970a1b 100644
@@ -92,6 +92,7 @@ void segv_handler(int sig, siginfo_t *info, void *data LTP_ATTRIBUTE_UNUSED)
 		_exit(EXIT_SUCCESS);
 }
 
+#ifdef __x86_64__
 static void force_bottom_up(void)
 {
 	FILE *fh;
@@ -134,6 +135,7 @@ static void force_bottom_up(void)
 out:
 	SAFE_FCLOSE(fh);
 }
+#endif
 
 unsigned long read_stack_addr_from_proc(unsigned long *stack_size)
 {
@@ -187,6 +189,7 @@ void __attribute__((noinline)) preallocate_stack(unsigned long required)
 	garbage[0] = garbage[required - 1] = '\0';
 }
 
+#ifdef __x86_64__
 static void do_mmap_placement_test(unsigned long stack_addr, unsigned long gap)
 {
 	void *map_test_gap;
@@ -208,6 +211,7 @@ static void do_mmap_placement_test(unsigned long stack_addr, unsigned long gap)
 		SAFE_MUNMAP(map_test_gap, MAPPED_LEN);
 	}
 }
+#endif
 
 void do_child(void)
 {
Signature · 5 lines
2.42.0


-- 
Mailing list info: https://lists.linux.it/listinfo/ltp
author
#1 lore raw

PATCH 2/2 stack_clash: Compile with -Wno-infinite-recursion

The algorithm is based on recursive calling of exhaust_stack_into_sigsegv(), remove the warning.

---
 testcases/cve/Makefile | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
testcases/cve/Makefile +1 -1
index c5308794d..01b9b9ccb 100644
@@ -7,7 +7,7 @@ include $(top_srcdir)/include/mk/testcases.mk
 
 CFLAGS			+= -D_GNU_SOURCE
 
-stack_clash:	CFLAGS += -fno-optimize-sibling-calls
+stack_clash:	CFLAGS += -fno-optimize-sibling-calls -Wno-infinite-recursion
 
 cve-2016-7042:	LDLIBS += $(KEYUTILS_LIBS)
 
Signature · 5 lines
2.42.0


-- 
Mailing list info: https://lists.linux.it/listinfo/ltp
author
#3 lore raw

Re: [LTP] [PATCH 2/2] stack_clash: Compile with -Wno-infinite-recursion

Hi Cyril,

thanks, merged!

Kind regards,
Petr

Signature · 1 line
Mailing list info: https://lists.linux.it/listinfo/ltp
#4 lore raw
In reply to Petr Vorel

Hi!

Quoted 20 lines

To avoid "defined but not used" warnings when compiled on 32bit.

---
 testcases/cve/stack_clash.c | 4 ++++
 1 file changed, 4 insertions(+)
testcases/cve/stack_clash.c +1 -0
index 3a99c49bb..56b970a1b 100644
@@ -92,6 +92,7 @@ void segv_handler(int sig, siginfo_t *info, void *data LTP_ATTRIBUTE_UNUSED)
 		_exit(EXIT_SUCCESS);
 }
 
+#ifdef __x86_64__
 static void force_bottom_up(void)
 {
 	FILE *fh;

testcases/cve/stack_clash.c static void force_bottom_up(void) · line 138

Quoted 4 lines
testcases/cve/stack_clash.c +1 -0
@@ -134,6 +135,7 @@ static void force_bottom_up(void)
 out:
 	SAFE_FCLOSE(fh);
 }
+#endif

Maybe I'm blind but this function does not seem to be called from inside of #ifdef __x86_64__.

Quoted 11 lines
testcases/cve/stack_clash.c +1 -0
 unsigned long read_stack_addr_from_proc(unsigned long *stack_size)
 {
@@ -187,6 +189,7 @@ void __attribute__((noinline)) preallocate_stack(unsigned long required)
 	garbage[0] = garbage[required - 1] = '\0';
 }
 
+#ifdef __x86_64__
 static void do_mmap_placement_test(unsigned long stack_addr, unsigned long gap)
 {
 	void *map_test_gap;

testcases/cve/stack_clash.c static void do_mmap_placement_test(unsigned long stack_addr, unsigned long gap) · line 214

Quoted 4 lines
testcases/cve/stack_clash.c +1 -0
@@ -208,6 +211,7 @@ static void do_mmap_placement_test(unsigned long stack_addr, unsigned long gap)
 		SAFE_MUNMAP(map_test_gap, MAPPED_LEN);
 	}
 }
+#endif

This part looks good.

Signature · 5 lines
Cyril Hrubis
[email protected]

-- 
Mailing list info: https://lists.linux.it/listinfo/ltp
author
#5 lore raw

Hi Cyril,

Quoted 9 lines

Hi!

testcases/cve/stack_clash.c

Quoted 8 lines

To avoid "defined but not used" warnings when compiled on 32bit.

---
 testcases/cve/stack_clash.c | 4 ++++
 1 file changed, 4 insertions(+)
testcases/cve/stack_clash.c +0 -0

Hi Cyril,

Quoted 4 lines
Quoted 4 lines
testcases/cve/stack_clash.c +1 -0
+#ifdef __x86_64__
 static void force_bottom_up(void)
 {
 	FILE *fh;
Quoted 8 lines

testcases/cve/stack_clash.c static void force_bottom_up(void) · line 138

Quoted 5 lines
testcases/cve/stack_clash.c +1 -0
@@ -134,6 +135,7 @@ static void force_bottom_up(void)
 out:
 	SAFE_FCLOSE(fh);
 }
+#endif

Maybe I'm blind but this function does not seem to be called from inside of #ifdef __x86_64__.

force_bottom_up() is called only inside do_mmap_placement_test(), which is also wrapped with #ifdef __x86_64_.

I did not notice that, compiler pointed it out :).

Can I merge with your RBT?

Kind regards,
Petr

Signature · 1 line
Mailing list info: https://lists.linux.it/listinfo/ltp
#6 lore raw

Hi!

Quoted 4 lines

force_bottom_up() is called only inside do_mmap_placement_test(), which is also wrapped with #ifdef __x86_64_.

I did not notice that, compiler pointed it out :).

Ah I was blind yesterday, sorry.

Quoted 1 line

Can I merge with your RBT?

Of course.

Signature · 5 lines
Cyril Hrubis
[email protected]

-- 
Mailing list info: https://lists.linux.it/listinfo/ltp
author
#7 lore raw

Hi Cyril,

Quoted 7 lines

Hi!

Quoted 4 lines

force_bottom_up() is called only inside do_mmap_placement_test(), which is also wrapped with #ifdef __x86_64_.

I did not notice that, compiler pointed it out :).

Ah I was blind yesterday, sorry.

No problem, thanks for a review, merged.

Kind regards,
Petr

Quoted 3 lines
Quoted 1 line

Can I merge with your RBT?

Of course.

Signature · 1 line
Mailing list info: https://lists.linux.it/listinfo/ltp