mailing list of musl libc
 help / color / mirror / code / Atom feed
* [musl] [PATCH] Add support for LLVM's Control Flow Integrity
@ 2020-12-27 17:53 Charlotte Delenk
  2020-12-27 23:05 ` Fangrui Song
  0 siblings, 1 reply; 10+ messages in thread
From: Charlotte Delenk @ 2020-12-27 17:53 UTC (permalink / raw)
  To: musl

Hi,

I have attempted to use musl HEAD together with clang's -fsanitize=cfi,
but currently it requires the main function to take all 3 arguments and
return an int.

After this patch is applied, clang will no longer try to add CFI
sanitization to the libc_start_main_stage2 function, allowing programs
to get to main().

I have tested CFI sanitization for both regular indirect functions
(qsort()) and thread creation and validly typed function pointers cause
no runtime aborts with CFI enabled for the whole program.

---

  src/env/__libc_start_main.c | 3 +++
  1 file changed, 3 insertions(+)

diff --git a/src/env/__libc_start_main.c b/src/env/__libc_start_main.c
index 8fbe5262..af61fb7c 100644
--- a/src/env/__libc_start_main.c
+++ b/src/env/__libc_start_main.c
@@ -85,6 +85,9 @@ int __libc_start_main(int (*main)(int,char **,char 
**), int argc, char **argv)
      return stage2(main, argc, argv);
  }

+#ifdef __clang__
+__attribute__((no_sanitize("cfi")))
+#endif
  static int libc_start_main_stage2(int (*main)(int,char **,char **), 
int argc, char **argv)
  {
      char **envp = argv+argc+1;
-- 
2.29.2


^ permalink raw reply	[flat|nested] 10+ messages in thread

end of thread, other threads:[~2020-12-29 11:59 UTC | newest]

Thread overview: 10+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-12-27 17:53 [musl] [PATCH] Add support for LLVM's Control Flow Integrity Charlotte Delenk
2020-12-27 23:05 ` Fangrui Song
2020-12-28  0:56   ` Fangrui Song
2020-12-28  9:20     ` Charlotte Delenk
2020-12-28 13:17       ` [musl] [PATCH] Add support for LLVM's Control Flow Integrity (V2) Charlotte Delenk
2020-12-28 17:01         ` Shiz
2020-12-29  1:26           ` Rich Felker
2020-12-29 10:20           ` Charlotte Delenk
2020-12-29 11:56             ` [musl] [PATCH 1/2] Fix LTO shared library build on GCC and Clang Charlotte Delenk
2020-12-29 11:59             ` [musl] [PATCH 2/2] Add support for LLVM's Control Flow Integrity Charlotte Delenk

Code repositories for project(s) associated with this public inbox

	https://git.vuxu.org/mirror/musl/

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).