Received: by 2002:a05:6358:53a8:b0:117:f937:c515 with SMTP id z40csp4571934rwe; Mon, 17 Apr 2023 15:03:17 -0700 (PDT) X-Google-Smtp-Source: AKy350bMJc2gadBeYGfNg75qO8YIfvtWFsMZJmO/q1JWXT/FS9g/SflcYcmpA0vRYQHuojfRQNYv X-Received: by 2002:a17:903:1107:b0:1a6:3b04:92bb with SMTP id n7-20020a170903110700b001a63b0492bbmr355815plh.18.1681768997260; Mon, 17 Apr 2023 15:03:17 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1681768997; cv=none; d=google.com; s=arc-20160816; b=PmEsRMCN2SKAuSfJZ9I7+fupUHLbJ5m9Sp+Kqk3hIr6B0Pft8G2pf3IcnUlEkLRKxG eWrdFChTL4o+B3AnHHRGkTLdmXWOPlUu0Qkrklo1jFvEbuswz5i6zt9UPRgSJ1CR5SoE rwie8qx43tmj/IJxjkJ9l1lO0uLYUOV9BydnAmyxjEzk3zmxQ9Y38aCzpS7nlt5RRmYK fxJGg+CP76XrCuGIZG+1EKzddsupXyKcPp89NS87zO+0uKFjcSsy7WVE+BrETIdJAHRg 6rt1eYIMG0fW+rOoz7FGEmVXKcT/kslnVHsaWaiBhtkPEl7XkTzux273Dv11fi26zAVI I49Q== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:cc:to:from:subject:message-id:references :mime-version:in-reply-to:date:dkim-signature; bh=1ROFbMOV6yOo0pF0esK8s0D/4X+P3zglkAv5TCX1cqs=; b=ZGT27wK9UM4nLgCvNHFdHkdACrKO9DScDxQn6G+4jOrVdqUOyzZ6LKmo13K1TVHHXG Tj4GU9VxdPo7z3ZFdjMhuy+fk9AthMzemLuk10FhoyajLZHBF9ZJMUkKWo9042hjxZ0B t7DMb/T2Pr9YfdWkss5WKwOdhDWgMsSH0sfmU5u312YT1oe4TEcLEByJxRqa9K3lXApD tSGgVETkL7Bk3VZ7hMamoFXsxZcUr93SBgY/AKdNDhapyzBKFbrnbzNMBkz3sA+dnP+c vMLFeDbmC/FLKz2vvyx+zBYbi1f3khu6UZVLuN3GLRfaZtwFZpjdDCM3HYBWWlpkTlwz TY2w== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20221208 header.b="a//CU5GA"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id h11-20020a63574b000000b005073e333addsi12005718pgm.390.2023.04.17.15.03.02; Mon, 17 Apr 2023 15:03:17 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@google.com header.s=20221208 header.b="a//CU5GA"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229863AbjDQWAT (ORCPT + 99 others); Mon, 17 Apr 2023 18:00:19 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:51028 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229658AbjDQWAR (ORCPT ); Mon, 17 Apr 2023 18:00:17 -0400 Received: from mail-yw1-x1149.google.com (mail-yw1-x1149.google.com [IPv6:2607:f8b0:4864:20::1149]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 000D3E7B for ; Mon, 17 Apr 2023 15:00:14 -0700 (PDT) Received: by mail-yw1-x1149.google.com with SMTP id 00721157ae682-54be7584b28so364119557b3.16 for ; Mon, 17 Apr 2023 15:00:14 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20221208; t=1681768814; x=1684360814; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:from:to:cc:subject:date:message-id:reply-to; bh=1ROFbMOV6yOo0pF0esK8s0D/4X+P3zglkAv5TCX1cqs=; b=a//CU5GAM8cMAJg0CXk4u7gyVLyPhgoZa7x1mGzF/rQPaDLgId/wanEXVqOxXOn+kM nYLD5qN/wOUNiFXB0cOc5R3SjZ2OTsHezj0xJbZPmD04sovR1oR5JJGJ/aDfV/cxg3Vd LgqjpqZPYfBA1ZhN1IOrM/axxWBCDvl7JA0F8QM1Y1Uc2mEqoG5u1bxgNIRw334OOzg3 u80lcm6pZMmZoeqG/pLfdVpQafV6hDgyAOCWGYImDTzb2WmqZExgTAbnR58VnCZyCFuV TOvJZzJ4Y16C0wl8Sww6Vf9mTUlZvH9no4BT2ZF4AVgExEoUSCU0mCL3ElUO8LkHYyDU qENQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1681768814; x=1684360814; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=1ROFbMOV6yOo0pF0esK8s0D/4X+P3zglkAv5TCX1cqs=; b=ZMkO2Drw1encN/XwaELgqsFQvspCnvmh9MwC8W3fZ7ws1cMH7DSmd+bqewiyMCwj8+ nrm3Ix9iSbOSh/0Bxmo8HuZoAyuGRj/4jp+TCI3XtlYLGSykUIIVoMeH2swp9/mKNlve 5u+YGN8sK8mEmxzW+Z7yAwqQQ/DzyCcp83dCgDx1AXqCP7nS/MmeiVPZj7zX3Goj4Bu4 zMHXsA5k7hS5M3IEn8U5e7MDqsY34wlg4tVvsphrZE8j0ZN6tWs9E4OoPEG8UdTeI7Z7 PI4rmrg/dQo75bTmnFqMdwTmiGxOqVhjecerPTdoJhNB74INygW98eep5g8mn2rdlSPk Sjug== X-Gm-Message-State: AAQBX9cUJalrkapOr79JBbG0QGLgo3Iw0pCWsSzooPuq9N9ltzeItJCw DbIIM7d6b4BW9zai0WDy2G7zy8Kfop/C7D8SHBM= X-Received: from ndesaulniers-desktop.svl.corp.google.com ([2620:15c:2d1:203:e8f1:df30:2fb2:cf8a]) (user=ndesaulniers job=sendgmr) by 2002:a25:d24e:0:b0:b8b:eea7:525b with SMTP id j75-20020a25d24e000000b00b8beea7525bmr10333781ybg.7.1681768814180; Mon, 17 Apr 2023 15:00:14 -0700 (PDT) Date: Mon, 17 Apr 2023 15:00:05 -0700 In-Reply-To: <20230412-no_stackp-v2-0-116f9fe4bbe7@google.com> Mime-Version: 1.0 References: <20230412-no_stackp-v2-0-116f9fe4bbe7@google.com> X-Developer-Key: i=ndesaulniers@google.com; a=ed25519; pk=UIrHvErwpgNbhCkRZAYSX0CFd/XFEwqX3D0xqtqjNug= X-Developer-Signature: v=1; a=ed25519-sha256; t=1681768810; l=3068; i=ndesaulniers@google.com; s=20220923; h=from:subject:message-id; bh=Y+mVeYQgxmjVxZ8TAgHiUAti6DIYAGqhexs7SrW7nh8=; b=k+bDSjx2YwwBdTyaFSoJ/8gMZw5tWZUIXNTaKWaFoZOH6WdmTdy6AGNiUQAbqdFMIvIdWAOy0t2k GvvIDyIJAK3E9qe3zp8TVxxLQwxMwt4iYQrdD0fLqDyjKVw0SXFx X-Mailer: b4 0.12.2 Message-ID: <20230412-no_stackp-v2-1-116f9fe4bbe7@google.com> Subject: [PATCH v2 1/2] start_kernel: add no_stack_protector fn attr From: ndesaulniers@google.com To: "Borislav Petkov (AMD)" Cc: Peter Zijlstra , Josh Poimboeuf , x86@kernel.org, Michael Ellerman , Nicholas Piggin , Christophe Leroy , Miguel Ojeda , Nathan Chancellor , Tom Rix , linuxppc-dev@lists.ozlabs.org, linux-kernel@vger.kernel.org, llvm@lists.linux.dev, Nick Desaulniers Content-Type: text/plain; charset="utf-8" X-Spam-Status: No, score=-9.6 required=5.0 tests=BAYES_00,DKIMWL_WL_MED, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_NONE, SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE,USER_IN_DEF_DKIM_WL autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Back during the discussion of commit a9a3ed1eff36 ("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 Acked-by: Michael Ellerman (powerpc) Acked-by: Miguel Ojeda Acked-by: Peter Zijlstra (Intel) Signed-off-by: Nick Desaulniers --- arch/powerpc/kernel/smp.c | 1 + include/linux/compiler_attributes.h | 12 ++++++++++++ init/main.c | 3 ++- 3 files changed, 15 insertions(+), 1 deletion(-) diff --git a/arch/powerpc/kernel/smp.c b/arch/powerpc/kernel/smp.c index f62e5e651bcd..48acae0da034 100644 --- a/arch/powerpc/kernel/smp.c +++ b/arch/powerpc/kernel/smp.c @@ -1603,6 +1603,7 @@ static void add_cpu_to_masks(int cpu) } /* Activate a secondary processor. */ +__no_stack_protector void start_secondary(void *unused) { unsigned int cpu = raw_smp_processor_id(); diff --git a/include/linux/compiler_attributes.h b/include/linux/compiler_attributes.h index e659cb6fded3..84864767a56a 100644 --- a/include/linux/compiler_attributes.h +++ b/include/linux/compiler_attributes.h @@ -255,6 +255,18 @@ */ #define __noreturn __attribute__((__noreturn__)) +/* + * Optional: only supported since GCC >= 11.1, clang >= 7.0. + * + * gcc: https://gcc.gnu.org/onlinedocs/gcc/Common-Function-Attributes.html#index-no_005fstack_005fprotector-function-attribute + * clang: https://clang.llvm.org/docs/AttributeReference.html#no-stack-protector-safebuffers + */ +#if __has_attribute(__no_stack_protector__) +# define __no_stack_protector __attribute__((__no_stack_protector__)) +#else +# define __no_stack_protector +#endif + /* * Optional: not supported by gcc. * diff --git a/init/main.c b/init/main.c index 5d6365510173..1265c8d11052 100644 --- a/init/main.c +++ b/init/main.c @@ -941,7 +941,8 @@ static void __init print_unknown_bootoptions(void) memblock_free(unknown_options, len); } -asmlinkage __visible void __init __no_sanitize_address __noreturn start_kernel(void) +asmlinkage __visible __init __no_sanitize_address __noreturn __no_stack_protector +void start_kernel(void) { char *command_line; char *after_dashes; -- 2.40.0.634.g4ca3ef3211-goog