Received: by 2002:ad5:4acb:0:0:0:0:0 with SMTP id n11csp3372imw; Tue, 12 Jul 2022 13:20:28 -0700 (PDT) X-Google-Smtp-Source: AGRyM1t+JxD/Ffg/STngANjAc25QDx66/lJVsMLzYVnXTm4e3i1QC1Cl9on0lpAimRSl05HsJ7GL X-Received: by 2002:a05:6402:847:b0:437:62bd:bbc0 with SMTP id b7-20020a056402084700b0043762bdbbc0mr34240737edz.285.1657657228338; Tue, 12 Jul 2022 13:20:28 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1657657228; cv=none; d=google.com; s=arc-20160816; b=Jxy85KUrFVR+QT0UY2bLERrbrkiep8O+i9o8WgT+lC7iAvmjQni252IRfGfW3lfi4g El/fcSeu2SddKy3vouWCouBPSQkoqfWWAamsCWA/3zr40Nzd/U5vLNoSzIaC6A0jAJ2K RgRmb5p1Kks4eASdrEeDkHqCyCnazO2hoMaWg5lpq8mt7vsBw6ACYojaw40i56dG5JUg b71aahlFazcqUriGRkue4n0ghXg1Avl2z9seru3iCsBN+qiK2yaNWDo4T6gz7KlIeX63 QPLNUR+Zdwp0GBXvpVXjr5S4NRjxFO7YruS4eh1zigbnQyZizbPxgoHWgPZp/m18fTFt tH/w== 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=xRV6S+irdxcgF85VP6WmEVynNTv3JZmK1xkQiBBcwqQ=; b=E7bkyTwb8fLiYMB0h0PFycYiHiyrfHfu3D60qbE8RotLLg+8oUIVTaJCEWLHoigv+V Upcya2bwuhY//Lw2B1dpkXMVH24dVuktlZ888ESyevM8mEdFHaHY7Geo2oBjCgBdvvCb DUzJX2dYjM0k0lI/Yi0RPI+wlcSaH2Q2CUr0ERcTRVaZ7rIlTVyNGpbpEh//l4dGq9QH 7gT+CXBF0jleep7ZVe/9gOq6yOKNM7MJhGxSvoDUOAppT3GnNXePXK3ogfLTZpwcj63b y7yYgth/q+6m6+UkYDqGQWX6OftyF7+Q8pb/2gLTZsiFvP2CxQSBKwQWQQ+eImLVOls9 5MRA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=oD+hXsPA; 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 p1-20020a1709060dc100b0072a9d2d2d37si13896734eji.116.2022.07.12.13.20.03; Tue, 12 Jul 2022 13:20:28 -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=oD+hXsPA; 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 S235283AbiGLTHS (ORCPT + 99 others); Tue, 12 Jul 2022 15:07:18 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:52816 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S235553AbiGLTGo (ORCPT ); Tue, 12 Jul 2022 15:06:44 -0400 Received: from ams.source.kernel.org (ams.source.kernel.org [145.40.68.75]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id C0D52E43DD; Tue, 12 Jul 2022 11:51:18 -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 625AAB81BAC; Tue, 12 Jul 2022 18:51:18 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id B0657C3411C; Tue, 12 Jul 2022 18:51:16 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1657651877; bh=jDpMnYgcH7UnQztEqT8kiAI+E3ewRMxCZVGmCwMRwB0=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=oD+hXsPAfWMTNndmWPagZl0ksDJncdCz6WQjPDZAycBaV681XS6xKWKPPcZCTM2nw 5pbOvupJqxwgZtOpmkdGx495yu2D5+vevR4zQ/1HbHoxML19vzQ4vYLyFEp4DngZML m0ScwAFT4ES8HokAuGkK8qOMJta3dOVvxjGQSmjA= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Lai Jiangshan , Borislav Petkov , Thadeu Lima de Souza Cascardo Subject: [PATCH 5.18 01/61] x86/traps: Use pt_regs directly in fixup_bad_iret() Date: Tue, 12 Jul 2022 20:38:58 +0200 Message-Id: <20220712183236.995062581@linuxfoundation.org> X-Mailer: git-send-email 2.37.0 In-Reply-To: <20220712183236.931648980@linuxfoundation.org> References: <20220712183236.931648980@linuxfoundation.org> User-Agent: quilt/0.66 X-stable: review X-Patchwork-Hint: ignore 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: Lai Jiangshan commit 0aca53c6b522f8d6e2681ca875acbbe105f5fdcf upstream. Always stash the address error_entry() is going to return to, in %r12 and get rid of the void *error_entry_ret; slot in struct bad_iret_stack which was supposed to account for it and pt_regs pushed on the stack. After this, both fixup_bad_iret() and sync_regs() can work on a struct pt_regs pointer directly. [ bp: Rewrite commit message, touch ups. ] Signed-off-by: Lai Jiangshan Signed-off-by: Borislav Petkov Link: https://lore.kernel.org/r/20220503032107.680190-2-jiangshanlai@gmail.com Signed-off-by: Thadeu Lima de Souza Cascardo Signed-off-by: Greg Kroah-Hartman --- arch/x86/entry/entry_64.S | 5 ++++- arch/x86/include/asm/traps.h | 2 +- arch/x86/kernel/traps.c | 19 +++++++------------ 3 files changed, 12 insertions(+), 14 deletions(-) --- a/arch/x86/entry/entry_64.S +++ b/arch/x86/entry/entry_64.S @@ -1062,9 +1062,12 @@ SYM_CODE_START_LOCAL(error_entry) * Pretend that the exception came from user mode: set up pt_regs * as if we faulted immediately after IRET. */ - mov %rsp, %rdi + popq %r12 /* save return addr in %12 */ + movq %rsp, %rdi /* arg0 = pt_regs pointer */ call fixup_bad_iret mov %rax, %rsp + ENCODE_FRAME_POINTER + pushq %r12 jmp .Lerror_entry_from_usermode_after_swapgs SYM_CODE_END(error_entry) --- a/arch/x86/include/asm/traps.h +++ b/arch/x86/include/asm/traps.h @@ -13,7 +13,7 @@ #ifdef CONFIG_X86_64 asmlinkage __visible notrace struct pt_regs *sync_regs(struct pt_regs *eregs); asmlinkage __visible notrace -struct bad_iret_stack *fixup_bad_iret(struct bad_iret_stack *s); +struct pt_regs *fixup_bad_iret(struct pt_regs *bad_regs); void __init trap_init(void); asmlinkage __visible noinstr struct pt_regs *vc_switch_off_ist(struct pt_regs *eregs); #endif --- a/arch/x86/kernel/traps.c +++ b/arch/x86/kernel/traps.c @@ -892,14 +892,10 @@ sync: } #endif -struct bad_iret_stack { - void *error_entry_ret; - struct pt_regs regs; -}; - -asmlinkage __visible noinstr -struct bad_iret_stack *fixup_bad_iret(struct bad_iret_stack *s) +asmlinkage __visible noinstr struct pt_regs *fixup_bad_iret(struct pt_regs *bad_regs) { + struct pt_regs tmp, *new_stack; + /* * This is called from entry_64.S early in handling a fault * caused by a bad iret to user mode. To handle the fault @@ -908,19 +904,18 @@ struct bad_iret_stack *fixup_bad_iret(st * just below the IRET frame) and we want to pretend that the * exception came from the IRET target. */ - struct bad_iret_stack tmp, *new_stack = - (struct bad_iret_stack *)__this_cpu_read(cpu_tss_rw.x86_tss.sp0) - 1; + new_stack = (struct pt_regs *)__this_cpu_read(cpu_tss_rw.x86_tss.sp0) - 1; /* Copy the IRET target to the temporary storage. */ - __memcpy(&tmp.regs.ip, (void *)s->regs.sp, 5*8); + __memcpy(&tmp.ip, (void *)bad_regs->sp, 5*8); /* Copy the remainder of the stack from the current stack. */ - __memcpy(&tmp, s, offsetof(struct bad_iret_stack, regs.ip)); + __memcpy(&tmp, bad_regs, offsetof(struct pt_regs, ip)); /* Update the entry stack */ __memcpy(new_stack, &tmp, sizeof(tmp)); - BUG_ON(!user_mode(&new_stack->regs)); + BUG_ON(!user_mode(new_stack)); return new_stack; } #endif