Received: by 2002:ac0:da4c:0:0:0:0:0 with SMTP id a12csp458227imi; Fri, 22 Jul 2022 02:50:00 -0700 (PDT) X-Google-Smtp-Source: AGRyM1s6f6R6yJ0iMCclY1MaCWQV0RkPNNDuO1RUGRS+5+yYqB8kXibNaksZ6r0Yl9EN4tCa8uNA X-Received: by 2002:a63:3d1:0:b0:41a:390e:c0c0 with SMTP id 200-20020a6303d1000000b0041a390ec0c0mr2414016pgd.609.1658483400046; Fri, 22 Jul 2022 02:50:00 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1658483400; cv=none; d=google.com; s=arc-20160816; b=tWRfvCy2CTYwDBousJlf6wE9gAxMLErpddZydsCp5uPWTGQsUom4+k+AnxthIlCLgL PQrgetFDBWrquS3OxSyLPC6NR6dxGb2TjwqIFyV+OtqzDw8OY66tcU9I3cGtuVI5vsvL Jns4H02TgSNzjHqUTMgzZBZa8WxacoIVr1npnabeE1VnN0JeVCwIeQpi8IO/2w4SdO/0 Zvs+urLBAP6wNPg3qUXtax3ZakNxxg1G8N8B1Oh+K2TxmUbWwN182sv4hECOkwafHTTo 8v55kOsLJwvrQ9RAHSXLga0NLoHi3OuUC4jYDN1FpiX9V+tLu2N893jhIeFjiKSuBbqq 0T0Q== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=PsEwFkqNZ65i1S1BtiGxC3T0RwJfbjxjMvU3m5ga1xQ=; b=MOqmFHYW3h4QkS4c1G9kdAYiGpE84UsteW/QZ7uhWsgIFNDQCD9bosZIB+gC3dgsB0 HFZSTsg1bxNfFrwBSPciVAjSj9MGT0R9OQMhIz+4jhCaGTNsIhM2poZIT6F1TfyZrb6z YoB2N/h8iEHH1pJzGxrj/Tpv3kd6TSyJhOATL9+Xb9XONiCz21A17CFWwkho5Mj2eTuX nByg5neB8g8jcUPQGGKlEZqZt1zVot3Dp3Xvlyhnt0ceYaHPbf80ENdgz7m6U5HwBuTd gQrbK+xd0Z1B5UOoN7u3Gx4Bw9t4nwQzlcH1edOxDHOzoo9nuCnhJ7vJwuhEWL5jRJiL 2jrQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=LgVQAksr; 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=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id e4-20020a63aa04000000b0040d436645f7si5055320pgf.765.2022.07.22.02.49.45; Fri, 22 Jul 2022 02:50:00 -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=@linuxfoundation.org header.s=korg header.b=LgVQAksr; 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=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S235300AbiGVJO2 (ORCPT + 99 others); Fri, 22 Jul 2022 05:14:28 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:39316 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S235403AbiGVJN0 (ORCPT ); Fri, 22 Jul 2022 05:13:26 -0400 Received: from ams.source.kernel.org (ams.source.kernel.org [145.40.68.75]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id A6BCBA721B; Fri, 22 Jul 2022 02:10:46 -0700 (PDT) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ams.source.kernel.org (Postfix) with ESMTPS id 4D91EB827BB; Fri, 22 Jul 2022 09:10:45 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 92EA1C341C6; Fri, 22 Jul 2022 09:10:43 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1658481044; bh=hoHz08tC6oiQQAdYnqJuaTV4rl7eX2oX/fx/GpRDRro=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=LgVQAksrkgEbGBkbVRUq7ndLV7jYT23jSVzMJGXgFn5De4FzJm0nDuGEhUNpEpjmt a8pC3GXj+n/x3P7PK+meR4EvQNT9WQjhkCHHOwwYy2opCoD7l433xkyt0Vss5NVxlI 9ChX9TAtEWNQgE+L5CzzZHDw17ogV2DG07iLTYf0= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, "Peter Zijlstra (Intel)" , Borislav Petkov , Josh Poimboeuf , Thadeu Lima de Souza Cascardo Subject: [PATCH 5.18 34/70] objtool: Update Retpoline validation Date: Fri, 22 Jul 2022 11:07:29 +0200 Message-Id: <20220722090652.628895953@linuxfoundation.org> X-Mailer: git-send-email 2.37.1 In-Reply-To: <20220722090650.665513668@linuxfoundation.org> References: <20220722090650.665513668@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-7.8 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_HI, SPF_HELO_NONE,SPF_PASS 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 From: Peter Zijlstra commit 9bb2ec608a209018080ca262f771e6a9ff203b6f upstream. Update retpoline validation with the new CONFIG_RETPOLINE requirement of not having bare naked RET instructions. Signed-off-by: Peter Zijlstra (Intel) Signed-off-by: Borislav Petkov Reviewed-by: Josh Poimboeuf Signed-off-by: Borislav Petkov Signed-off-by: Thadeu Lima de Souza Cascardo Signed-off-by: Greg Kroah-Hartman --- arch/x86/include/asm/nospec-branch.h | 6 ++++++ arch/x86/mm/mem_encrypt_boot.S | 2 ++ arch/x86/xen/xen-head.S | 1 + tools/objtool/check.c | 19 +++++++++++++------ 4 files changed, 22 insertions(+), 6 deletions(-) --- a/arch/x86/include/asm/nospec-branch.h +++ b/arch/x86/include/asm/nospec-branch.h @@ -76,6 +76,12 @@ .endm /* + * (ab)use RETPOLINE_SAFE on RET to annotate away 'bare' RET instructions + * vs RETBleed validation. + */ +#define ANNOTATE_UNRET_SAFE ANNOTATE_RETPOLINE_SAFE + +/* * JMP_NOSPEC and CALL_NOSPEC macros can be used instead of a simple * indirect jmp/call which may be susceptible to the Spectre variant 2 * attack. --- a/arch/x86/mm/mem_encrypt_boot.S +++ b/arch/x86/mm/mem_encrypt_boot.S @@ -66,6 +66,7 @@ SYM_FUNC_START(sme_encrypt_execute) pop %rbp /* Offset to __x86_return_thunk would be wrong here */ + ANNOTATE_UNRET_SAFE ret int3 SYM_FUNC_END(sme_encrypt_execute) @@ -154,6 +155,7 @@ SYM_FUNC_START(__enc_copy) pop %r15 /* Offset to __x86_return_thunk would be wrong here */ + ANNOTATE_UNRET_SAFE ret int3 .L__enc_copy_end: --- a/arch/x86/xen/xen-head.S +++ b/arch/x86/xen/xen-head.S @@ -26,6 +26,7 @@ SYM_CODE_START(hypercall_page) .rept (PAGE_SIZE / 32) UNWIND_HINT_FUNC ANNOTATE_NOENDBR + ANNOTATE_UNRET_SAFE ret /* * Xen will write the hypercall page, and sort out ENDBR. --- a/tools/objtool/check.c +++ b/tools/objtool/check.c @@ -2114,8 +2114,9 @@ static int read_retpoline_hints(struct o } if (insn->type != INSN_JUMP_DYNAMIC && - insn->type != INSN_CALL_DYNAMIC) { - WARN_FUNC("retpoline_safe hint not an indirect jump/call", + insn->type != INSN_CALL_DYNAMIC && + insn->type != INSN_RETURN) { + WARN_FUNC("retpoline_safe hint not an indirect jump/call/ret", insn->sec, insn->offset); return -1; } @@ -3648,7 +3649,8 @@ static int validate_retpoline(struct obj for_each_insn(file, insn) { if (insn->type != INSN_JUMP_DYNAMIC && - insn->type != INSN_CALL_DYNAMIC) + insn->type != INSN_CALL_DYNAMIC && + insn->type != INSN_RETURN) continue; if (insn->retpoline_safe) @@ -3663,9 +3665,14 @@ static int validate_retpoline(struct obj if (!strcmp(insn->sec->name, ".init.text") && !module) continue; - WARN_FUNC("indirect %s found in RETPOLINE build", - insn->sec, insn->offset, - insn->type == INSN_JUMP_DYNAMIC ? "jump" : "call"); + if (insn->type == INSN_RETURN) { + WARN_FUNC("'naked' return found in RETPOLINE build", + insn->sec, insn->offset); + } else { + WARN_FUNC("indirect %s found in RETPOLINE build", + insn->sec, insn->offset, + insn->type == INSN_JUMP_DYNAMIC ? "jump" : "call"); + } warnings++; }