Skip to content

Commit 3e4a12a

Browse files
committed
Merge tag 'gcc-plugins-v5.9-rc1' of git://git.kernel.org/pub/scm/linux/kernel/git/kees/linux
Pull gcc plugin updates from Kees Cook: "Primarily improvements to STACKLEAK from Alexander Popov, along with some additional cleanups. - Update URLs for HTTPS scheme where available (Alexander A. Klimov) - Improve STACKLEAK code generation on x86 (Alexander Popov)" * tag 'gcc-plugins-v5.9-rc1' of git://git.kernel.org/pub/scm/linux/kernel/git/kees/linux: gcc-plugins: Replace HTTP links with HTTPS ones gcc-plugins/stackleak: Add 'verbose' plugin parameter gcc-plugins/stackleak: Use asm instrumentation to avoid useless register saving ARM: vdso: Don't use gcc plugins for building vgettimeofday.c gcc-plugins/stackleak: Don't instrument itself
2 parents 19a9382 + 496b24e commit 3e4a12a

File tree

9 files changed

+241
-47
lines changed

9 files changed

+241
-47
lines changed

arch/arm/vdso/Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ CPPFLAGS_vdso.lds += -P -C -U$(ARCH)
2929
CFLAGS_REMOVE_vdso.o = -pg
3030

3131
# Force -O2 to avoid libgcc dependencies
32-
CFLAGS_REMOVE_vgettimeofday.o = -pg -Os
32+
CFLAGS_REMOVE_vgettimeofday.o = -pg -Os $(GCC_PLUGINS_CFLAGS)
3333
ifeq ($(c-gettimeofday-y),)
3434
CFLAGS_vgettimeofday.o = -O2
3535
else

include/linux/compiler_attributes.h

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@
3737
# define __GCC4_has_attribute___copy__ 0
3838
# define __GCC4_has_attribute___designated_init__ 0
3939
# define __GCC4_has_attribute___externally_visible__ 1
40+
# define __GCC4_has_attribute___no_caller_saved_registers__ 0
4041
# define __GCC4_has_attribute___noclone__ 1
4142
# define __GCC4_has_attribute___nonstring__ 0
4243
# define __GCC4_has_attribute___no_sanitize_address__ (__GNUC_MINOR__ >= 8)
@@ -176,6 +177,18 @@
176177
*/
177178
#define __mode(x) __attribute__((__mode__(x)))
178179

180+
/*
181+
* Optional: only supported since gcc >= 7
182+
*
183+
* gcc: https://gcc.gnu.org/onlinedocs/gcc/x86-Function-Attributes.html#index-no_005fcaller_005fsaved_005fregisters-function-attribute_002c-x86
184+
* clang: https://clang.llvm.org/docs/AttributeReference.html#no-caller-saved-registers
185+
*/
186+
#if __has_attribute(__no_caller_saved_registers__)
187+
# define __no_caller_saved_registers __attribute__((__no_caller_saved_registers__))
188+
#else
189+
# define __no_caller_saved_registers
190+
#endif
191+
179192
/*
180193
* Optional: not supported by clang
181194
*

kernel/Makefile

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -125,6 +125,7 @@ obj-$(CONFIG_WATCH_QUEUE) += watch_queue.o
125125

126126
obj-$(CONFIG_SYSCTL_KUNIT_TEST) += sysctl-test.o
127127

128+
CFLAGS_stackleak.o += $(DISABLE_STACKLEAK_PLUGIN)
128129
obj-$(CONFIG_GCC_PLUGIN_STACKLEAK) += stackleak.o
129130
KASAN_SANITIZE_stackleak.o := n
130131
KCSAN_SANITIZE_stackleak.o := n

kernel/stackleak.c

Lines changed: 4 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -104,19 +104,9 @@ asmlinkage void notrace stackleak_erase(void)
104104
}
105105
NOKPROBE_SYMBOL(stackleak_erase);
106106

107-
void __used notrace stackleak_track_stack(void)
107+
void __used __no_caller_saved_registers notrace stackleak_track_stack(void)
108108
{
109-
/*
110-
* N.B. stackleak_erase() fills the kernel stack with the poison value,
111-
* which has the register width. That code assumes that the value
112-
* of 'lowest_stack' is aligned on the register width boundary.
113-
*
114-
* That is true for x86 and x86_64 because of the kernel stack
115-
* alignment on these platforms (for details, see 'cc_stack_align' in
116-
* arch/x86/Makefile). Take care of that when you port STACKLEAK to
117-
* new platforms.
118-
*/
119-
unsigned long sp = (unsigned long)&sp;
109+
unsigned long sp = current_stack_pointer;
120110

121111
/*
122112
* Having CONFIG_STACKLEAK_TRACK_MIN_SIZE larger than
@@ -125,6 +115,8 @@ void __used notrace stackleak_track_stack(void)
125115
*/
126116
BUILD_BUG_ON(CONFIG_STACKLEAK_TRACK_MIN_SIZE > STACKLEAK_SEARCH_DEPTH);
127117

118+
/* 'lowest_stack' should be aligned on the register width boundary */
119+
sp = ALIGN(sp, sizeof(unsigned long));
128120
if (sp < current->lowest_stack &&
129121
sp >= (unsigned long)task_stack_page(current) +
130122
sizeof(unsigned long)) {

scripts/Makefile.gcc-plugins

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,8 @@ gcc-plugin-cflags-$(CONFIG_GCC_PLUGIN_STACKLEAK) \
3333
+= -DSTACKLEAK_PLUGIN
3434
gcc-plugin-cflags-$(CONFIG_GCC_PLUGIN_STACKLEAK) \
3535
+= -fplugin-arg-stackleak_plugin-track-min-size=$(CONFIG_STACKLEAK_TRACK_MIN_SIZE)
36+
gcc-plugin-cflags-$(CONFIG_GCC_PLUGIN_STACKLEAK) \
37+
+= -fplugin-arg-stackleak_plugin-arch=$(SRCARCH)
3638
ifdef CONFIG_GCC_PLUGIN_STACKLEAK
3739
DISABLE_STACKLEAK_PLUGIN += -fplugin-arg-stackleak_plugin-disable
3840
endif

scripts/gcc-plugins/cyc_complexity_plugin.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
* Homepage:
66
* https://github.com/ephox-gcc-plugins/cyclomatic_complexity
77
*
8-
* http://en.wikipedia.org/wiki/Cyclomatic_complexity
8+
* https://en.wikipedia.org/wiki/Cyclomatic_complexity
99
* The complexity M is then defined as:
1010
* M = E - N + 2P
1111
* where

scripts/gcc-plugins/sancov_plugin.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
*
1212
* You can read about it more here:
1313
* https://gcc.gnu.org/viewcvs/gcc?limit_changes=0&view=revision&revision=231296
14-
* http://lwn.net/Articles/674854/
14+
* https://lwn.net/Articles/674854/
1515
* https://github.com/google/syzkaller
1616
* https://lwn.net/Articles/677764/
1717
*

0 commit comments

Comments
 (0)