Re: Clang patch stacks for LTS kernels (v4.4 and v4.9) and status update

From: Sedat Dilek
Date: Tue May 22 2018 - 03:10:45 EST


On Tue, May 22, 2018 at 9:39 AM, Sedat Dilek <sedat.dilek@xxxxxxxxx> wrote:
> On Sat, May 19, 2018 at 12:54 AM, Nick Desaulniers
> <nick.desaulniers@xxxxxxxxx> wrote:
>> Sedat,
>> Thanks for the report. We have a fix ready in
>> https://bugs.llvm.org/show_bug.cgi?id=37512. Can you report what
>> version of clang you were using and if earlier versions of clang have
>> this issue?
>> Thanks,
>
> Can you give some advices on how to implement
> "attribute((no_stack_protector))" for Clang?
>
> I looked on how this is done for GCC...
>
> [ include/linux/compiler-gcc.h ]
>
> #if GCC_VERSION >= 40400
> #define __optimize(level) __attribute__((__optimize__(level)))
> #define __nostackprotector __optimize("no-stack-protector")
> #endif /* GCC_VERSION >= 40400 */
>
> [ include/linux/compiler_types.h ]
>
> #ifndef __nostackprotector
> # define __nostackprotector
> #endif
>
> LLVM-bug #37512 says:
>
> "GCC option for this is: attribute((optimize("no-stack-protector")))
> and the equivalent clang syntax would be: attribute((no_stack_protector))"
>
> So, there should be a define in "include/linux/compiler-clang.h" for this?
>
> [ include/linux/compiler-clang.h ]
>
> #define __nostackprotector attribute((no_stack_protector))
>
> Looks that good to you?
>

I am trying with the attached files and...

CONFIG_PARAVIRT=y
CONFIG_CC_STACKPROTECTOR_STRONG=y

- Sedat -
From ed07ff36ae7ae121e48d6c0579ff3fd5796bf57a Mon Sep 17 00:00:00 2001
From: Sedat Dilek <sedat.dilek@xxxxxxxxxxx>
Date: Tue, 22 May 2018 09:46:18 +0200
Subject: [PATCH 1/2] compiler-clang.h: Add __nostackprotector function
attribute

---
include/linux/compiler-clang.h | 5 +++++
1 file changed, 5 insertions(+)

diff --git a/include/linux/compiler-clang.h b/include/linux/compiler-clang.h
index 070f85d92c15..1da957c33140 100644
--- a/include/linux/compiler-clang.h
+++ b/include/linux/compiler-clang.h
@@ -21,3 +21,8 @@
#ifdef __noretpoline
#undef __noretpoline
#endif
+
+/* For details see <https://bugs.llvm.org/show_bug.cgi?id=37512>.
+ * This feature requires Clang version 7 >= svn331925.
+ */
+#define __nostackprotector attribute((no_stack_protector))
--
2.17.0

From 6ff43719d2f225ee90364ce054a955590a07e911 Mon Sep 17 00:00:00 2001
From: Sedat Dilek <sedat.dilek@xxxxxxxxxxx>
Date: Tue, 22 May 2018 09:52:15 +0200
Subject: [PATCH 2/2] x86/paravirt: Mark native_save_fl() with
__nostackprotector attribute

---
arch/x86/include/asm/irqflags.h | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/arch/x86/include/asm/irqflags.h b/arch/x86/include/asm/irqflags.h
index 89f08955fff7..6def04321181 100644
--- a/arch/x86/include/asm/irqflags.h
+++ b/arch/x86/include/asm/irqflags.h
@@ -13,7 +13,7 @@
* Interrupt control:
*/

-static inline unsigned long native_save_fl(void)
+static inline unsigned long __nostackprotector native_save_fl(void)
{
unsigned long flags;

--
2.17.0