 start_kernel: Add __no_stack_protector function attribute · gregkh/linux@25e7301 · GitHub Skip to content Navigation Menu Toggle navigation Sign in Appearance settings Platform AI CODE CREATION GitHub Copilot Write better code with AI GitHub Spark Build and deploy intelligent apps GitHub Models Manage and compare prompts MCP Registry New Integrate external tools DEVELOPER WORKFLOWS Actions Automate any workflow Codespaces Instant dev environments Issues Plan and track work Code Review Manage code changes APPLICATION SECURITY GitHub Advanced Security Find and fix vulnerabilities Code security Secure your code as you build Secret protection  EXPLORE Why GitHub Documentation Blog Changelog Marketplace View all features Solutions BY COMPANY SIZE Enterprises Small and medium teams Startups Nonprofits BY USE CASE App Modernization DevSecOps DevOps CI/CD View all use cases BY INDUSTRY Healthcare Financial services Manufacturing Government View all industries View all solutions Resources EXPLORE BY TOPIC AI Software Development DevOps Security View all topics EXPLORE BY TYPE Customer stories Events &amp; webinars Ebooks &amp; reports Business insights GitHub Skills SUPPORT &amp; SERVICES Documentation Customer support Community forum Trust center Partners View all resources Open Source COMMUNITY GitHub Sponsors Fund open source developers PROGRAMS Security Lab Maintainer Community Accelerator GitHub Stars Archive Program REPOSITORIES Topics Trending Collections Enterprise ENTERPRISE SOLUTIONS Enterprise platform AI-powered developer platform AVAILABLE ADD-ONS GitHub Advanced Security Enterprise-grade security features Copilot for Business Enterprise-grade AI features Premium Support Enterprise-grade 24/7 support Pricing Search or jump to... Search code, repositories, users, issues, pull requests... --> Search Clear Search syntax tips Provide feedback --> We read every piece of feedback, and take your input very seriously.  Cancel Submit feedback Saved searches Use saved searches to filter your results more quickly --> Name Query To see all available qualifiers, see our documentation . Cancel Create saved search Sign in Sign up Appearance settings Resetting focus You signed in with another tab or window. Reload to refresh your session. You signed out in another tab or window. Reload to refresh your session. You switched accounts on another tab or window. Reload to refresh your session. Dismiss alert {{ message }} gregkh / linux Public Notifications You must be signed in to change notification settings Fork 686 Star 644 Code Actions Security and quality 0 Insights Additional navigation options Code Actions Security and quality Insights Commit 25e7301 Browse files Browse files nickdesaulniers authored and gregkh committed start_kernel: Add __no_stack_protector function attribute commit 514ca14 upstream. Back during the discussion of commit a9a3ed1 ("x86: Fix early boot crash on gcc-10, third try") we discussed the need for a function attribute to control the omission of stack protectors on a per-function basis; at the time Clang had support for no_stack_protector but GCC did not. This was fixed in gcc-11. Now that the function attribute is available, let's start using it. Callers of boot_init_stack_canary need to use this function attribute unless they're compiled with -fno-stack-protector, otherwise the canary stored in the stack slot of the caller will differ upon the call to boot_init_stack_canary. This will lead to a call to __stack_chk_fail() then panic. Link: https://gcc.gnu.org/bugzilla/show_bug.cgi?id=94722 Link: https://lore.kernel.org/all/20200316130414.GC12561@hirez.programming.kicks-ass.net/ Tested-by: Nathan Chancellor &lt;nathan@kernel.org&gt; Acked-by: Michael Ellerman &lt;mpe@ellerman.id.au&gt; (powerpc) Acked-by: Miguel Ojeda &lt;ojeda@kernel.org&gt; Acked-by: Peter Zijlstra (Intel) &lt;peterz@infradead.org&gt; Signed-off-by: Nick Desaulniers &lt;ndesaulniers@google.com&gt; Link: https://lore.kernel.org/r/20230412-no_stackp-v2-1-116f9fe4bbe7@google.com Signed-off-by: Josh Poimboeuf &lt;jpoimboe@kernel.org&gt; Signed-off-by: Greg Kroah-Hartman &lt;gregkh@linuxfoundation.org&gt; Signed-off-by: ndesaulniers@google.com &lt;ndesaulniers@google.com&gt; 1 parent 160f412 commit 25e7301 Copy full SHA for 25e7301 3 file s changed + 15 - 1 Lines changed: 15 additions &amp; 1 deletion File tree Expand file tree Collapse file tree Open diff view settings Filter options arch/powerpc/kernel smp.c include/linux compiler_attributes.h init main.c Expand file tree Collapse file tree Open diff view settings Collapse file ‎ arch/powerpc/kernel/smp.c ‎ Copy file name to clipboard Expand all lines: arch/powerpc/kernel/smp.c + 1 Lines changed: 1 addition &amp; 0 deletions Original file line number Diff line number Diff line change @@ -1605,6 +1605,7 @@ static void add_cpu_to_masks(int cpu) 1605 1605 } 1606 1606 1607 1607 /* Activate a secondary processor. */ 1608 + __no_stack_protector 1608 1609 void start_secondary ( void * unused ) 1609 1610 { 1610 1611 unsigned int cpu = raw_smp_processor_id (); Collapse file ‎ include/linux/compiler_attributes.h ‎ Copy file name to clipboard Expand all lines: include/linux/compiler_attributes.h + 12 Lines changed: 12 additions &amp; 0 deletions Original file line number Diff line number Diff line change @@ -255,6 +255,18 @@ 255 255 */ 256 256 #define __noreturn __attribute__((__noreturn__)) 257 257 258 + /* 259 + * Optional: only supported since GCC &gt;= 11.1, clang &gt;= 7.0. 260 + * 261 + * gcc: https://gcc.gnu.org/onlinedocs/gcc/Common-Function-Attributes.html#index-no_005fstack_005fprotector-function-attribute 262 + * clang: https://clang.llvm.org/docs/AttributeReference.html#no-stack-protector-safebuffers 263 + */ 264 + #if __has_attribute ( __no_stack_protector__ ) 265 + # define __no_stack_protector __attribute__((__no_stack_protector__)) 266 + #else 267 + # define __no_stack_protector 268 + #endif 269 + 258 270 /* 259 271 * Optional: not supported by gcc. 260 272 * Collapse file ‎ init/main.c ‎ Copy file name to clipboard Expand all lines: init/main.c + 2 - 1 Lines changed: 2 additions &amp; 1 deletion Original file line number Diff line number Diff line change @@ -877,7 +877,8 @@ static void __init print_unknown_bootoptions(void) 877 877 memblock_free ( unknown_options , len ); 878 878 } 879 879 880 - asmlinkage __visible void __init __no_sanitize_address __noreturn start_kernel ( void ) 880 + asmlinkage __visible __init __no_sanitize_address __noreturn __no_stack_protector 881 + void start_kernel ( void ) 881 882 { 882 883 char * command_line ; 883 884 char * after_dashes ; 0 commit comments Comments 0 ( 0 ) Footer &copy; 2026 GitHub,&nbsp;Inc. Footer navigation Terms Privacy Security Status Community Docs Contact Manage cookies Do not share my personal information You can’t perform that action at this time. 