From mboxrd@z Thu Jan 1 00:00:00 1970 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on inbox.vuxu.org X-Spam-Level: X-Spam-Status: No, score=-3.1 required=5.0 tests=DKIM_INVALID,DKIM_SIGNED, MAILING_LIST_MULTI,RCVD_IN_DNSWL_MED,RCVD_IN_MSPIKE_H3, RCVD_IN_MSPIKE_WL autolearn=ham autolearn_force=no version=3.4.4 Received: (qmail 25561 invoked from network); 27 Dec 2020 17:54:10 -0000 Received: from mother.openwall.net (195.42.179.200) by inbox.vuxu.org with ESMTPUTF8; 27 Dec 2020 17:54:10 -0000 Received: (qmail 21972 invoked by uid 550); 27 Dec 2020 17:54:05 -0000 Mailing-List: contact musl-help@lists.openwall.com; run by ezmlm Precedence: bulk List-Post: List-Help: List-Unsubscribe: List-Subscribe: List-ID: Reply-To: musl@lists.openwall.com Received: (qmail 21942 invoked from network); 27 Dec 2020 17:54:04 -0000 DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=darkkirb.de; s=mail; t=1609091633; bh=vxElPCyAFeKSB22bR2DYZqDrB9i+ocEcFQHEQpzAM/s=; h=To:From:Subject:Date; b=iXokURVmPX6yK0Gd1tv94p4D6lsHSxvC+NGvvOswc3ynJxElXy3CMWzrmW+Fi69l+ DQz+i7K7X6rB3m87s8lr0mZaI8XN5Hrd0j1N5SL+hWY5AZrvYZTb2grTCZ3/qgOKHO iXj9xSfgGX7FxqTCuMg+ARA3JwFriZSJ7ffPx8K8= To: musl@lists.openwall.com From: Charlotte Delenk Message-ID: <6106be97-2c82-75c0-ad88-2e49b17c68ee@darkkirb.de> Date: Sun, 27 Dec 2020 18:53:01 +0100 User-Agent: Mozilla/5.0 (X11; Linux aarch64; rv:78.0) Gecko/20100101 Thunderbird/78.4.3 MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8; format=flowed Content-Transfer-Encoding: 8bit Content-Language: en-US Subject: [musl] [PATCH] Add support for LLVM's Control Flow Integrity 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