Received: by 2002:ac0:da4c:0:0:0:0:0 with SMTP id a12csp1366465imi; Sat, 23 Jul 2022 03:49:03 -0700 (PDT) X-Google-Smtp-Source: AGRyM1vDhSBZkORBcQiMR6Z5E9NWIWbY2xtmrU3L/+qYvXQb6rf7fcm4bW36bOe6YyM2GhW1EIu7 X-Received: by 2002:a05:6402:1f13:b0:43b:c521:8de7 with SMTP id b19-20020a0564021f1300b0043bc5218de7mr3736556edb.79.1658573343496; Sat, 23 Jul 2022 03:49:03 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1658573343; cv=none; d=google.com; s=arc-20160816; b=0l2mrpYP6bk64YMjYkUfZ5jAkq+wfLCLemZtP2UHvE4XULcqVwXdEL5s6l8MY0f7i4 rKD97ArbD00EuALbRO8c2cKgTP6C/cRgT7iMjeSzOi8CHN2zmpplxzMy4ByNEsYETAjs rKAa2FCCoVaGVWOlxXRKDAK+EeMDF6aTSEmGlhRk2EmWppbEe4WotSFh+n37nhjwBQH8 lhurluyiA/AfGthEZYzoDIwBe3hJDiZp3ReXq6K+jbR/04zJs7x75LrpkqYRx1vaXS6I HDGv1dblP7NSchX72aw0kKfDEsPC5RuwuY13/47tEAWPO8f0icdHCW/k7UC9tlg0BDqg qkew== 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=UyhzfF+IcVMv6mvwGaiCcVfpp4ltzU8327gFKjHzDk8=; b=ODXY7uHdFyE1Hho+HrQBVA1qs7ZVTETGlNxcCPRHy3vWVZFUc84V5yicBnvP3jrRJ3 Z+67HclrYSRvMo9i6eUAxdBMwmwl+piC2E50OjlD/9nD7n1qeTl/C9pFW1WxigqzCxKP 6oTqdaK2Kr+N42f81dPl/WmxZ65Wnf6t3wcs6UTe/wojTAju0ucqeNnE2J7yluWn+K3S bDE2opKqh8Oa81zYldeeL08EgMHNbWRjCpAuMIrwLR9FtN9XgSLxucE/N1oqQVlfsgeP 9JG9ZkZGYctGcsEb7bS9oRCdjEipWXHWlfrbXfOaJnKHwNSN9UTMFynW7y+n/GJfBXd0 Mbzg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=N0vlzdrp; 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 y10-20020a170906524a00b0072642bbc8cfsi7188816ejm.914.2022.07.23.03.48.38; Sat, 23 Jul 2022 03:49:03 -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=N0vlzdrp; 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 S239066AbiGWKKM (ORCPT + 99 others); Sat, 23 Jul 2022 06:10:12 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:43168 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S238748AbiGWKIu (ORCPT ); Sat, 23 Jul 2022 06:08:50 -0400 Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 96821C9E7A; Sat, 23 Jul 2022 03:01:59 -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 dfw.source.kernel.org (Postfix) with ESMTPS id 4312D6116A; Sat, 23 Jul 2022 10:01:36 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 526D7C341C0; Sat, 23 Jul 2022 10:01:35 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1658570495; bh=s9BBdXTRzWO6rilbhoZPvTfn8C7dwgczJt4XxU408Fs=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=N0vlzdrpULs29z6OTQr+6AENsrGvpG29z0KA0Q9NisG0a+m+wuAhRa1mI/asybxd8 WEMhVAOg57tkEENHeDyFsTeb8jDhlnkM4+sdbubVhsXAmgSzuWbJ16GXctX0BFfmSP XuOopOHyhlR4g1cvnHC/NmZp+oDGdEezAfHG1TKs= 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 , Ben Hutchings Subject: [PATCH 5.10 106/148] objtool: Update Retpoline validation Date: Sat, 23 Jul 2022 11:55:18 +0200 Message-Id: <20220723095254.035382699@linuxfoundation.org> X-Mailer: git-send-email 2.37.1 In-Reply-To: <20220723095224.302504400@linuxfoundation.org> References: <20220723095224.302504400@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 [cascardo: conflict fixup at arch/x86/xen/xen-head.S] Signed-off-by: Thadeu Lima de Souza Cascardo Signed-off-by: Ben Hutchings 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 @@ -1799,8 +1799,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; } @@ -3051,7 +3052,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) @@ -3066,9 +3068,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++; }