Received: by 2002:a05:6358:1087:b0:cb:c9d3:cd90 with SMTP id j7csp876573rwi; Wed, 19 Oct 2022 04:12:12 -0700 (PDT) X-Google-Smtp-Source: AMsMyM5rLW3zen2RF7wA+S4oFaEA1l01kJ6HEvIUc++iKIirvHPmofT5WFUTEQPNtYRxsykqvL80 X-Received: by 2002:a17:90b:388c:b0:20a:9c33:dd2b with SMTP id mu12-20020a17090b388c00b0020a9c33dd2bmr43328084pjb.225.1666177921973; Wed, 19 Oct 2022 04:12:01 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1666177921; cv=none; d=google.com; s=arc-20160816; b=GjeE5PZrpk7vNgj8TFYYQ5bWfwPLnTX/SL+aZq7kxz6kzF5oRajMwR+GVFAMkOZaOy txLQNqa6P+bAo3fRkaXv92XOwUqPt3fV3JIvS7Dus/rxKgeUlwaY32dImQrcwwdMfRov lhm0x2w+Ez7f3n4JoXGApPgIKuJA3kTNxyhkuETudPAqmiPdMG7JZJx0UPxmzX1p154F n4SalGmHI4IIcl7KaGQ91sPR5TDYfbNWPsFMmFszCBo0KrxIuYLdALD//KH5YDsXr/me VOfT2SVgFtP0tyOzy+qmk7eudEZ7H4spRHFqagjEHsGrQWzTQqd8pQJoKT5jCZ9PTXgd 2+HQ== 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=IjR25XfV5KRSyAKhUBWqq1cHW1d+VRQw41yHn52s0AQ=; b=ALjoV0ir/IVqa4Az5D0iRShFxBngOVtcx/yFeymcaZVLToYvWwTNBkHJP9tEBqlKAD 6SdHWHwinxlbZPD76mnvuf6iWxTMvZbdn9hKYBmsjZYSnMbVRRuwLazawPi2lbLjPH6L 8OacAGxTyV4pI3G4a5tS4iU/h/n5d3CJBCjr9+ev5hxDFiqcmvhvcjEPVUbYsvxWSYHu 9nc1jwGLaJ60FcreimatpBR+EBovvzYtF18qT3fQTSuP42mgQlTkB5RgsCAxEGeHjhLZ wcvgaSec4oVTyL3+PK4LFo5jdAfYRLoabv5sJLYQ4nSgHYs8talbwoJA0aq+9QXm8i0r umnA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=YmS35Zbm; 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 e15-20020aa7980f000000b00562e898af18si18103249pfl.119.2022.10.19.04.11.45; Wed, 19 Oct 2022 04:12:01 -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=YmS35Zbm; 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 S233391AbiJSKr4 (ORCPT + 99 others); Wed, 19 Oct 2022 06:47:56 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:49688 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232968AbiJSKpc (ORCPT ); Wed, 19 Oct 2022 06:45:32 -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 B4DF211D99E; Wed, 19 Oct 2022 03:21:22 -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 7E376B82324; Wed, 19 Oct 2022 08:48:23 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id E713FC4314E; Wed, 19 Oct 2022 08:48:21 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1666169302; bh=2eafooLCWzYB3jrawTGKwYMxHojxlE96ckfg/2CLZiY=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=YmS35ZbmV9I0KbiFZU06/eh+K1Jk+YSccScUaqgJ9coNpuYhycQheLvnAzbCDjqvf 1RMmUWyDM7h52ZqIlnHiw4Tsnl0STUAOKSMuP28tKyY9TdIteBNxsooqp+yuKD8tYw XAvA92NDM06P7UXItWZL+ti79rIDGTkCvwGcyMow= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Bill Wendling , Juergen Gross , Kees Cook , Sasha Levin , Nathan Chancellor Subject: [PATCH 6.0 226/862] x86/paravirt: add extra clobbers with ZERO_CALL_USED_REGS enabled Date: Wed, 19 Oct 2022 10:25:13 +0200 Message-Id: <20221019083300.040763886@linuxfoundation.org> X-Mailer: git-send-email 2.38.0 In-Reply-To: <20221019083249.951566199@linuxfoundation.org> References: <20221019083249.951566199@linuxfoundation.org> User-Agent: quilt/0.67 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-7.4 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: Bill Wendling [ Upstream commit 8c86f29bfb18465d15b05cfd26a6454ec787b793 ] The ZERO_CALL_USED_REGS feature may zero out caller-saved registers before returning. In spurious_kernel_fault(), the "pte_offset_kernel()" call results in this assembly code: .Ltmp151: #APP # ALT: oldnstr .Ltmp152: .Ltmp153: .Ltmp154: .section .discard.retpoline_safe,"",@progbits .quad .Ltmp154 .text callq *pv_ops+536(%rip) .Ltmp155: .section .parainstructions,"a",@progbits .p2align 3, 0x0 .quad .Ltmp153 .byte 67 .byte .Ltmp155-.Ltmp153 .short 1 .text .Ltmp156: # ALT: padding .zero (-(((.Ltmp157-.Ltmp158)-(.Ltmp156-.Ltmp152))>0))*((.Ltmp157-.Ltmp158)-(.Ltmp156-.Ltmp152)),144 .Ltmp159: .section .altinstructions,"a",@progbits .Ltmp160: .long .Ltmp152-.Ltmp160 .Ltmp161: .long .Ltmp158-.Ltmp161 .short 33040 .byte .Ltmp159-.Ltmp152 .byte .Ltmp157-.Ltmp158 .text .section .altinstr_replacement,"ax",@progbits # ALT: replacement 1 .Ltmp158: movq %rdi, %rax .Ltmp157: .text #NO_APP .Ltmp162: testb $-128, %dil The "testb" here is using %dil, but the %rdi register was cleared before returning from "callq *pv_ops+536(%rip)". Adding the proper constraints results in the use of a different register: movq %r11, %rdi # Similar to above. testb $-128, %r11b Link: https://github.com/KSPP/linux/issues/192 Signed-off-by: Bill Wendling Reported-and-tested-by: Nathan Chancellor Fixes: 035f7f87b729 ("randstruct: Enable Clang support") Reviewed-by: Juergen Gross Link: https://lore.kernel.org/lkml/fa6df43b-8a1a-8ad1-0236-94d2a0b588fa@suse.com/ Signed-off-by: Kees Cook Link: https://lore.kernel.org/r/20220902213750.1124421-3-morbo@google.com Signed-off-by: Sasha Levin --- arch/x86/include/asm/paravirt_types.h | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/arch/x86/include/asm/paravirt_types.h b/arch/x86/include/asm/paravirt_types.h index 89df6c6617f5..bc2e1b67319d 100644 --- a/arch/x86/include/asm/paravirt_types.h +++ b/arch/x86/include/asm/paravirt_types.h @@ -414,8 +414,17 @@ int paravirt_disable_iospace(void); "=c" (__ecx) #define PVOP_CALL_CLOBBERS PVOP_VCALL_CLOBBERS, "=a" (__eax) -/* void functions are still allowed [re]ax for scratch */ +/* + * void functions are still allowed [re]ax for scratch. + * + * The ZERO_CALL_USED REGS feature may end up zeroing out callee-saved + * registers. Make sure we model this with the appropriate clobbers. + */ +#ifdef CONFIG_ZERO_CALL_USED_REGS +#define PVOP_VCALLEE_CLOBBERS "=a" (__eax), PVOP_VCALL_CLOBBERS +#else #define PVOP_VCALLEE_CLOBBERS "=a" (__eax) +#endif #define PVOP_CALLEE_CLOBBERS PVOP_VCALLEE_CLOBBERS #define EXTRA_CLOBBERS , "r8", "r9", "r10", "r11" -- 2.35.1