Received: by 2002:ad5:4acb:0:0:0:0:0 with SMTP id n11csp4469240imw; Tue, 19 Jul 2022 07:12:12 -0700 (PDT) X-Google-Smtp-Source: AGRyM1t0kimD839HaTTSoKqMW0o5w3tsaea8LgHq5s08hVhnmcGShq+2J4WlVOH6igQI6kvYHV/U X-Received: by 2002:aca:de42:0:b0:33a:4c62:8de1 with SMTP id v63-20020acade42000000b0033a4c628de1mr10603877oig.211.1658239932361; Tue, 19 Jul 2022 07:12:12 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1658239932; cv=none; d=google.com; s=arc-20160816; b=NeI20W9wdmrYQnFYd6TkiZ0CkN1xtRm2ZjnkmO20BIF0KHYn0/xrd/AB7IrPBb89Pk iw+noi8KIza+cMRpQWl1po/wxdEJRWBpxjVumLRF0JYgxnPeR4kBs7U8g59iWbxCkUKm FKXMQCRJcvAWciav6A+YrGOoYwSMmBWZb8s44rejAdoMmJ9XqQQ8FEAc6oW2d3EUatMm C/FEUEWJ8dePKYPjXY9VeGIQc/5oS3HhdqrL6mghrF1p9qwm8QPcbFHtqA+lzX6UuNVX C7wUzrztKjtnZB6+LDF9/8Lc2rhsYjwD1J32q3sRSZcPb2sgPffM44lRvG510fReVe6U NFvw== 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=pThbJGka6L1TkGur/JOIo2J9MfmCxhsjmjMaYzGfCcg=; b=sVzeRmP0BsGc3+BZsL3/pDnPJK94qPr8C85wJA9jTDP0/gbD80/1FwDZu3LEnXNA04 C++yxXeHomrrI5m7V8gNY7UG66ZwfOREMLqi+HhZRX6ofBEjvtV8vtIWwOBb319QeOOd 9hHTvzkSB68CGL8HOWiNCvk/QntkuUItikOKp1WESySh7j7HNKzKgjcxwRJVmDDhBMoJ +ND3u6eHeflHAnth8nwqx4Zngf/gL5dMF8hpIYjMaswqCcSMK+PcMFbqOJMiC7tW/RED oFCTwwXZkiksm2gVtV0EfM7hc1x3rrdQ3eQh3ZDHXtcCtv+aO1SmUCX79Qj9h50Pw2Ox +IQg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=A0Mw8JjA; 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 o15-20020a056808124f00b00339e7ca9dfdsi16287112oiv.27.2022.07.19.07.11.57; Tue, 19 Jul 2022 07:12:12 -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=A0Mw8JjA; 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 S242477AbiGSNFu (ORCPT + 99 others); Tue, 19 Jul 2022 09:05:50 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:39948 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S243160AbiGSNEr (ORCPT ); Tue, 19 Jul 2022 09:04:47 -0400 Received: from ams.source.kernel.org (ams.source.kernel.org [IPv6:2604:1380:4601:e00::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id AE2FC9DEF9; Tue, 19 Jul 2022 05:26:39 -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 22EACB81B10; Tue, 19 Jul 2022 12:26:37 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 58133C341C6; Tue, 19 Jul 2022 12:26:35 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1658233595; bh=eiHQRO2eTKAg/yVdtMzvxSG5jzk8ywMUzDNQLp/ZplQ=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=A0Mw8JjApDAF4JXTvTg4D+aju8NLYWrXNHpipyJluGLeFMTr5dEaS6ZHuTZzPwB2i DTjaDfFCWoEUjTgAJEesx5y4rTTE60hQNApU1fCFVuwnV6pMh/LwZhVg6OeJfZT2Om 4c/4uZPqexYChDuDdtM4zIm3xLv6Tci8t5SIxUV0= 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 , Sasha Levin Subject: [PATCH 5.18 148/231] objtool: Update Retpoline validation Date: Tue, 19 Jul 2022 13:53:53 +0200 Message-Id: <20220719114726.776451398@linuxfoundation.org> X-Mailer: git-send-email 2.37.1 In-Reply-To: <20220719114714.247441733@linuxfoundation.org> References: <20220719114714.247441733@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 [ Upstream commit 9bb2ec608a209018080ca262f771e6a9ff203b6f ] 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: Sasha Levin --- 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(-) diff --git a/arch/x86/include/asm/nospec-branch.h b/arch/x86/include/asm/nospec-branch.h index da251a5645b0..f1a7ecd0a7c7 100644 --- a/arch/x86/include/asm/nospec-branch.h +++ b/arch/x86/include/asm/nospec-branch.h @@ -75,6 +75,12 @@ .popsection .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 diff --git a/arch/x86/mm/mem_encrypt_boot.S b/arch/x86/mm/mem_encrypt_boot.S index d94dea450fa6..9de3d900bc92 100644 --- 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: diff --git a/arch/x86/xen/xen-head.S b/arch/x86/xen/xen-head.S index 13af6fe453e3..ffaa62167f6e 100644 --- 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. diff --git a/tools/objtool/check.c b/tools/objtool/check.c index f66e4ac0af94..fbe41203fc9b 100644 --- a/tools/objtool/check.c +++ b/tools/objtool/check.c @@ -2030,8 +2030,9 @@ static int read_retpoline_hints(struct objtool_file *file) } 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; } @@ -3561,7 +3562,8 @@ static int validate_retpoline(struct objtool_file *file) 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) @@ -3576,9 +3578,14 @@ static int validate_retpoline(struct objtool_file *file) 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++; } -- 2.35.1