Received: by 2002:ad5:4acb:0:0:0:0:0 with SMTP id n11csp4702333imw; Tue, 12 Jul 2022 12:42:14 -0700 (PDT) X-Google-Smtp-Source: AGRyM1sDKrvTdEDGa24c3dxHlctfvWlqBxlqkK5POTW+6WK3IcWXc/ReTeFgvvSPLKI9FZTAmU7j X-Received: by 2002:a17:902:f391:b0:16b:f995:437d with SMTP id f17-20020a170902f39100b0016bf995437dmr25601494ple.22.1657654934239; Tue, 12 Jul 2022 12:42:14 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1657654934; cv=none; d=google.com; s=arc-20160816; b=w8AoIO9JQmIbk54rkytpsGZRvIDyOSgkbfwBwRfD/EgKxtY7xsDEMl3lZW30iGFBkA 0hWvIlTTMq8FYjbXwke0ErSk7kCk1Jkja7h3n2ODX71AjB+S0cY91uwNXfVywZF4MC35 /JGnNy+tIgxqRvVaWsd+ryeR+IWAGGi3yd6S8Vf0Z/TmduLWz3hQApWlSTGKZCDcXx+Y hu+Kqcd3tvEyoMhdMXJ1GivVlsdde67vLxCXH3reZdHTiq5b8wxhW8BJEbrkrlkSJJFF kw3EuElgi45D7P4zcurIWxQt+wF50Bq77huOHi/CUTiyzvfjs7Ovx8cfMX8TSrCCCRc+ xYkg== 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=O4qI3l6Yzj0lcgI5X3kmFi3MQCMhHoN85VBBD1NAUNI=; b=ieixkrbDRMospI08QJ92rKcEYl//IUK9BBHTVWhFF68w0uqbafVHFS8r33mM6cUngJ cZdxA7RzZrkBmsTLuGVrMVVCj+tvTxZXS3+55R9TC/ullzz+6ykwSj9fGSBfjndMRERF iaQbc/stRMQ6Ra/bDuw6nZKFwJG967Dnxgam3XSCjhfmZdR7hESMuDnJ5XSzGg2vWFPd UMqnOqGOtyh4MUGs96b0PBa3Lkm0h9Yb//6RCg8r2SWaXhPi+xsHUSEVjheez8ZWSBuy og6EFmswlnUvf/wACR1M4Jhn3UHtRDK1JfA7L0ih9FT6sgshRqZEjWyHT5H5tlgbA3EK cEtA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=p8o70MkT; 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 x22-20020a056a00189600b0052ad02461f0si8217661pfh.88.2022.07.12.12.42.02; Tue, 12 Jul 2022 12:42:14 -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=p8o70MkT; 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 S235323AbiGLTDU (ORCPT + 99 others); Tue, 12 Jul 2022 15:03:20 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:42772 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S235209AbiGLTCI (ORCPT ); Tue, 12 Jul 2022 15:02:08 -0400 Received: from ams.source.kernel.org (ams.source.kernel.org [145.40.68.75]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 5F48513D21; Tue, 12 Jul 2022 11:49:32 -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 F13D4B81B95; Tue, 12 Jul 2022 18:49:30 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 655CFC3411C; Tue, 12 Jul 2022 18:49:29 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1657651769; bh=VCjIuSIJxECg9rUnAc+oypPNmhASe1jtnxWPtmqwl1k=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=p8o70MkTGW0W25fw9A7lb4Tm8srtqwPtvT5Nrbfs2bLhMsIHr31yZvAd/OKtJKtWy E/5ufKh/zfIEONI2ceCYoEkuPzjH487HOMvTW36ThM1s/pbkLvlhYg8tNfaeNXJE/L KSeJ33feup0D5Tx1JAy3cEqYf61lY0SmfdeDvJXE= 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.15 52/78] objtool: Update Retpoline validation Date: Tue, 12 Jul 2022 20:39:22 +0200 Message-Id: <20220712183240.986838708@linuxfoundation.org> X-Mailer: git-send-email 2.37.0 In-Reply-To: <20220712183238.844813653@linuxfoundation.org> References: <20220712183238.844813653@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.7 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,T_SCC_BODY_TEXT_LINE 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 [cascardo: conflict fixup at arch/x86/xen/xen-head.S] 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 @@ -70,6 +70,7 @@ SYM_CODE_START(hypercall_page) .rept (PAGE_SIZE / 32) UNWIND_HINT_FUNC .skip 31, 0x90 + ANNOTATE_UNRET_SAFE RET .endr --- a/tools/objtool/check.c +++ b/tools/objtool/check.c @@ -1894,8 +1894,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; } @@ -3229,7 +3230,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) @@ -3244,9 +3246,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++; }