From patchwork Wed Oct 19 08:25:13 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Greg KH X-Patchwork-Id: 5104 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:4ac7:0:0:0:0:0 with SMTP id y7csp250317wrs; Wed, 19 Oct 2022 03:48:45 -0700 (PDT) X-Google-Smtp-Source: AMsMyM4eb/Thuq14LQlIJGYbffSWPhR/OE1QzhlWGOJNazEPhLvmdgV7tUy25/V63BH++LbCvxwg X-Received: by 2002:a17:907:75ed:b0:78d:97ed:2894 with SMTP id jz13-20020a17090775ed00b0078d97ed2894mr5972021ejc.739.1666176524858; Wed, 19 Oct 2022 03:48:44 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1666176524; cv=none; d=google.com; s=arc-20160816; b=O0HmJmPeuPLMtbTy0e5tGD7L1R1WCDlmn+IQLFLH3//sIAmJqPA/pfZ1aCTRPRgXUm mYjcYY5cPUd8utCx/0heqMKt3OvwhCPRC4mL3xnQQ9YzSg4DjGX0nga+BzGh8yu4xRga imAs1ztULBsBSNT6jcHgE0O8z7pazYpl3iR43mrMdELo0LiHH1EfCKJaqPq4t8iHowZe M7xuRcP31iBqeZLM6GdQZ4/606C6Q+IV3rseAuqnmLhyKX/ogcxyFrxH/boHGiV+hiXu DJKQ0bU6LchtLyReh72o+gYkZ8gavCUT9SheHEZlwwLfEEWCly1H09fa3JkCfI+yLnr2 oYvw== 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 Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id o25-20020a170906289900b0078d4dcceb5dsi11961922ejd.717.2022.10.19.03.48.19; Wed, 19 Oct 2022 03:48:44 -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 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 X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1747112715759380002?= X-GMAIL-MSGID: =?utf-8?q?1747112715759380002?= 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"