Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753208AbeAQOAK (ORCPT + 1 other); Wed, 17 Jan 2018 09:00:10 -0500 Received: from mail-io0-f173.google.com ([209.85.223.173]:36645 "EHLO mail-io0-f173.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752941AbeAQOAI (ORCPT ); Wed, 17 Jan 2018 09:00:08 -0500 X-Google-Smtp-Source: ACJfBovP0JNWTe7twaEZMDprFyn7cs3FfXqoYbh8rdaVLwuxPUBkmqBrE4zkYJ+owPHCa7QgnM11yxtFYE0/OXgRrZc= MIME-Version: 1.0 In-Reply-To: References: <1516120619-1159-1-git-send-email-joro@8bytes.org> <1516120619-1159-4-git-send-email-joro@8bytes.org> <20180117092442.GJ28161@8bytes.org> From: Brian Gerst Date: Wed, 17 Jan 2018 06:00:07 -0800 Message-ID: Subject: Re: [PATCH 03/16] x86/entry/32: Leave the kernel via the trampoline stack To: Joerg Roedel Cc: Andy Lutomirski , 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 , David Laight , Denys Vlasenko , Eduardo Valentin , Greg KH , Will Deacon , "Liguori, Anthony" , Daniel Gruss , Hugh Dickins , Kees Cook , Andrea Arcangeli , Waiman Long , Joerg Roedel Content-Type: text/plain; charset="UTF-8" Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Return-Path: On Wed, Jan 17, 2018 at 5:57 AM, Brian Gerst wrote: > On Wed, Jan 17, 2018 at 1:24 AM, Joerg Roedel wrote: >> On Tue, Jan 16, 2018 at 02:48:43PM -0800, Andy Lutomirski wrote: >>> On Tue, Jan 16, 2018 at 8:36 AM, Joerg Roedel wrote: >>> > + /* Restore user %edi and user %fs */ >>> > + movl (%edi), %edi >>> > + popl %fs >>> >>> Yikes! We're not *supposed* to be able to observe an asynchronous >>> descriptor table change, but if the LDT changes out from under you, >>> this is going to blow up badly. It would be really nice if you could >>> pull this off without percpu access or without needing to do this >>> dance where you load user FS, then kernel FS, then user FS. If that's >>> not doable, then you should at least add exception handling -- look at >>> the other 'pop %fs' instructions in entry_32.S. >> >> You are right! This also means I need to do the 'popl %fs' before the >> cr3-switch. I'll fix it in the next version. >> >> I have no real idea on how to switch back to the entry stack without >> access to per_cpu variables. I also can't access the cpu_entry_area for >> the cpu yet, because for that we need to be on the entry stack already. > > Switch to the trampoline stack before loading user segments. But then again, you could take a fault on the trampoline stack if you get a bad segment. Perhaps just pushing the new stack pointer onto the process stack before user segment loads will be the right move. -- Brian Gerst