Received: by 2002:ac0:a5a7:0:0:0:0:0 with SMTP id m36-v6csp221842imm; Fri, 13 Jul 2018 22:22:38 -0700 (PDT) X-Google-Smtp-Source: AAOMgpczCADtJYuwr38dgfi1tBdRfWYIwXVuHlWl/H97juqRy9Hv9o4DT79Q6A1IwyAf0TZlZwu0 X-Received: by 2002:a17:902:bd07:: with SMTP id p7-v6mr9108160pls.32.1531545758560; Fri, 13 Jul 2018 22:22:38 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1531545758; cv=none; d=google.com; s=arc-20160816; b=AQDgeh2fNPS7FklKrY6Lg+s3z3Y2RYF4irjTsDqpe7lwR4t5Any1LO4r3K5lGqICdT ihtVRzH2pq5z11e5/O/FZup+mGcn4TXdUEIVYe67E5vR/My+6+N8KYCUpdnSjADgrK5Y uB8CoWxR/LpDx4bBKFFW0I+WkUNNexBcDPdIQhpUpepzgmYc9N42fXfj5FYIziZsEBRQ OWt/4Gxre9u4wC/XKLHXf7uHFEi8JRKCje/XQ+K9MsV5MYjCXNk4VvasD2MK0GDXSqoY FENvWPNPqfJig6xR75s4lySjTHUHS+tfeUj1KIQfAmPB+PwZ10uMdPZ/nLNtQuT4Jo+O BtcA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:user-agent:in-reply-to :content-disposition:mime-version:references:message-id:subject:cc :to:from:date:arc-authentication-results; bh=0yccEu6xS0WXaEFcKDO8jzLNKTwopAJEyp8MGi6fzds=; b=yXE/dF75EeJaXB25RGUQkIfcBN0t69ulXAF8ZY/XMriMLuXq2bx5F7Re2BQ+YleibU azSVw8nDTpXtFNPI4oXhyxpnQrXDm1Rb3h0qs12RNVnIU0pHsyd+3b0BsENWC3xszakR xnesRMnx+xsO/Oj7QXv5VPjzMWcvRoDdh3dzomRfj829UtaQoYd4vcvtOt3mojQtMFIs 7z3dzDSltRbFrQTiVQrQVTAE601ZzFgZHDtDPbp9ONTMxA/J0n6ta1jRDoTetADh2KNO RT8Fl7hpOCIgdYdz2MP3Jzp0o/aX3fgPefZ7MBu8koAZFzC5qb/J0DzOFMzV+i1KSTun 3mWQ== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id f67-v6si26343507plb.460.2018.07.13.22.22.11; Fri, 13 Jul 2018 22:22:38 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1725978AbeGNFi7 (ORCPT + 99 others); Sat, 14 Jul 2018 01:38:59 -0400 Received: from mx2.suse.de ([195.135.220.15]:35884 "EHLO mx1.suse.de" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1725880AbeGNFi7 (ORCPT ); Sat, 14 Jul 2018 01:38:59 -0400 X-Virus-Scanned: by amavisd-new at test-mx.suse.de Received: from relay2.suse.de (unknown [195.135.220.254]) by mx1.suse.de (Postfix) with ESMTP id 13FE4AE07; Sat, 14 Jul 2018 05:21:14 +0000 (UTC) Date: Sat, 14 Jul 2018 07:21:10 +0200 From: Joerg Roedel To: Andy Lutomirski Cc: Joerg Roedel , Thomas Gleixner , Ingo Molnar , "H . Peter Anvin" , X86 ML , LKML , Linux-MM , Linus Torvalds , Dave Hansen , Josh Poimboeuf , Juergen Gross , Peter Zijlstra , Borislav Petkov , Jiri Kosina , Boris Ostrovsky , Brian Gerst , David Laight , Denys Vlasenko , Eduardo Valentin , Greg KH , Will Deacon , "Liguori, Anthony" , Daniel Gruss , Hugh Dickins , Kees Cook , Andrea Arcangeli , Waiman Long , Pavel Machek , "David H . Gutteridge" Subject: Re: [PATCH 10/39] x86/entry/32: Handle Entry from Kernel-Mode on Entry-Stack Message-ID: <20180714052110.cobtew6rms23ih37@suse.de> References: <1531308586-29340-1-git-send-email-joro@8bytes.org> <1531308586-29340-11-git-send-email-joro@8bytes.org> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: User-Agent: NeoMutt/20170421 (1.8.2) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Fri, Jul 13, 2018 at 04:31:02PM -0700, Andy Lutomirski wrote: > What you're really doing is keeping it available for an extra flag. > Please update the comment as such. But see below. Thanks, will do. > > +.macro PARANOID_EXIT_TO_KERNEL_MODE > > + > > + /* > > + * Test if we entered the kernel with the entry-stack. Most > > + * likely we did not, because this code only runs on the > > + * return-to-kernel path. > > + */ > > + testl $CS_FROM_ENTRY_STACK, PT_CS(%esp) > > + jz .Lend_\@ > > + > > + /* Unlikely slow-path */ > > + > > + /* Clear marker from stack-frame */ > > + andl $(~CS_FROM_ENTRY_STACK), PT_CS(%esp) > > + > > + /* Copy the remaining task-stack contents to entry-stack */ > > + movl %esp, %esi > > + movl PER_CPU_VAR(cpu_tss_rw + TSS_sp0), %edi > > I'm confused. Why do we need any special handling here at all? How > could we end up with the contents of the stack frame we interrupted in > a corrupt state? > > I guess I don't understand why this patch is needed. The patch is needed because we can get exceptions in kernel-mode while we are already on user-cr3 and entry-stack. In this case we need to return with user-cr3 and entry-stack to the kernel too, otherwise we would go to user-space with kernel-cr3. So based on that, I did the above because the entry-stack is a per-cpu data structure and I am not sure that we always return from the exception on the same CPU where we got it. Therefore the path is called PARANOID_... :) Regards, Joerg