Received: by 2002:a25:4158:0:0:0:0:0 with SMTP id o85csp3941761yba; Tue, 23 Apr 2019 12:09:17 -0700 (PDT) X-Google-Smtp-Source: APXvYqwienjEtaGz6vb6osPdZw2KRATmAzqRFHO2jcGso0CnEB3ertDHYvbedlwxEQnSRKPDOewn X-Received: by 2002:a17:902:e101:: with SMTP id cc1mr28057037plb.129.1556046557474; Tue, 23 Apr 2019 12:09:17 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1556046557; cv=none; d=google.com; s=arc-20160816; b=zELe86UXN/UlrmZ+LklKz33Nlg1/8Sk9mmjwCLM0Akrk3RRw4ksJnYX+xv7tjUJG11 3K9ycRI6NrOlGwZcJCi68sXabfKhBmV3WulWACtFddQmwFGXKlJTJPfBwKdBXd6wMcLd bdFDnIrTjIarhrgxixycdOKgLbKrywIn7DjRxHfrKJipGd+0DGt4DDAzQwvp+zHGkevd 9+qIghxa2Q+K+B3A9ji+4skx2l96/s8zKjHwuygrjTDXdy4/y/fc1OZJL8PDaOuwin5T q7Su+rTzLetIj+hipqobvWJeXlwnfn9t6tCa6ApV2Hv90z43iti7OtCSrZp7+hQCv0fQ KNzw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:dkim-signature; bh=egucgrMMZELAy+vrFfUGqz7+MoTBVNeK4Z5lhEUHWSE=; b=ljp2QFOlA9JCuuHsnGaUTydfo9pM1KWZMxE/KA9xg8dNufYYo4ufWDPIege1N/PgBy UpduyLdZ9/chwlrNlDyQxJ8Cx3wfkamssmca49Iaa4ZMFMF3eHEjTC5YDdClkUxiDUlM B7Zt0d8HsM/2y4qQYtz7Ixy8az7PG6oTdxZPcoq1v2jItNAoL3UMreG8MGmP91G9omO9 7vk+HwlTrQdbzDZtxs8nMIYPIUAxGHoIeGssrXcJTSAm1gZZmZojgc7lb2HNWJmFvNeD O0jFAwhPjO8gMzWYSnlbm2Cthqg/nAyN88joY+V97O68WDD+10pjlSRjlvOhL9/nHJ4O fF6A== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=tE8EDMvH; 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; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id m3si8950948pgp.562.2019.04.23.12.09.01; Tue, 23 Apr 2019 12:09:17 -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; dkim=pass header.i=@kernel.org header.s=default header.b=tE8EDMvH; 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; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726626AbfDWTHk (ORCPT + 99 others); Tue, 23 Apr 2019 15:07:40 -0400 Received: from mail.kernel.org ([198.145.29.99]:40232 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726029AbfDWTHk (ORCPT ); Tue, 23 Apr 2019 15:07:40 -0400 Received: from mail-wr1-f42.google.com (mail-wr1-f42.google.com [209.85.221.42]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id 32FDE218DA for ; Tue, 23 Apr 2019 19:07:39 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1556046459; bh=9GSdW1aq+r9nV1/Bl6Pg8a6JY989aBpJAknNyTYBqWU=; h=References:In-Reply-To:From:Date:Subject:To:Cc:From; b=tE8EDMvHYUZdISI2w7FGpF/jSAL/HeobSnoquVCzOrUVjswzg9Awgrk1G5e6HJfKh D38PlZAo5bubEBtS7r0JqfnbpEm0KKC+t8JJxprba6+iU7b7wInB+aTsVdeQDt/OWy ojIsREI7tc6k86ypF0gvGwKIHlBp4QVJ8BnLCfKU= Received: by mail-wr1-f42.google.com with SMTP id c12so15461428wrt.8 for ; Tue, 23 Apr 2019 12:07:39 -0700 (PDT) X-Gm-Message-State: APjAAAVFPXF4OIdOHkExtHWfL2Q28eBHa4wKGQRaXkJTXO/j25OKjcAu nHQOkqGxBdM/5EdBOgHHgYxsdTW2RTx96KLC6a8yMQ== X-Received: by 2002:adf:ed82:: with SMTP id c2mr17544533wro.176.1556046457760; Tue, 23 Apr 2019 12:07:37 -0700 (PDT) MIME-Version: 1.0 References: <20190417103938.7762-1-jarkko.sakkinen@linux.intel.com> <20190423185937.GD10720@linux.intel.com> In-Reply-To: <20190423185937.GD10720@linux.intel.com> From: Andy Lutomirski Date: Tue, 23 Apr 2019 12:07:26 -0700 X-Gmail-Original-Message-ID: Message-ID: Subject: Re: [RFC PATCH v1 3/3] selftests/x86: Augment SGX selftest to test new __vdso_sgx_enter_enclave() and its callback interface To: Sean Christopherson Cc: Andy Lutomirski , Cedric Xing , LKML , X86 ML , linux-sgx@vger.kernel.org, Andrew Morton , Dave , nhorman@redhat.com, npmccallum@redhat.com, Serge , Shay , Haitao , Andy Shevchenko , Thomas Gleixner , Kai , Borislav Petkov , Josh Triplett , Kai , David Rientjes , Jarkko Sakkinen Content-Type: text/plain; charset="UTF-8" Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Tue, Apr 23, 2019 at 11:59 AM Sean Christopherson wrote: > > On Mon, Apr 22, 2019 at 06:29:06PM -0700, Andy Lutomirski wrote: > > What's not tested here is running this code with EFLAGS.TF set and > > making sure that it unwinds correctly. Also, Jarkko, unless I missed > > something, the vDSO extable code likely has a bug. If you run the > > instruction right before ENCLU with EFLAGS.TF set, then do_debug() > > will eat the SIGTRAP and skip to the exception handler. Similarly, if > > you put an instruction breakpoint on ENCLU, it'll get skipped. Or is > > the code actually correct and am I just remembering wrong? > > The code is indeed broken, and I don't see a sane way to make it not > broken other than to never do vDSO fixup on #DB or #BP. But that's > probably the right thing to do anyways since an attached debugger is > likely the intended recipient the 99.9999999% of the time. > > The crux of the matter is that it's impossible to identify whether or > not a #DB/#BP originated from within an enclave, e.g. an INT3 in an > enclave will look identical to an INT3 at the AEP. Even if hardware > provided a magic flag, #DB still has scenarios where the intended > recipient is ambiguous, e.g. data breakpoint encountered in the enclave > but on an address outside of the enclave, breakpoint encountered in the > enclave and a code breakpoint on the AEP, etc... Ugh. It sounds like ignoring the fixup for #DB is the right call. But what happens if the enclave contains an INT3 or ICEBP instruction? Are they magically promoted to #GP, perhaps? As a maybe possible alternative, if we made it so that the AEX address was not the same as the ENCLU, could we usefully distinguish these exceptions based on RIP? I suppose it's also worth considering whether page faults from *inside* the enclave should result in SIGSEGV or result in a fixup. We certainly want page faults from the ENCLU instruction itself to get fixed up, but maybe we want most exceptions inside the enclave to work a bit differently. Of course, if we do this, we need to make sure that the semantics of returning from the signal handler are reasonable.