Received: by 2002:ac0:98c7:0:0:0:0:0 with SMTP id g7-v6csp1168041imd; Thu, 1 Nov 2018 11:13:26 -0700 (PDT) X-Google-Smtp-Source: AJdET5epUtCDcvI8G0qg+hTCu6UcNm/RQmByDAr76qFq16hBOFVmDynkVJ54gBOUlTJiJ2EqJWkS X-Received: by 2002:a17:902:2ac3:: with SMTP id j61-v6mr8520756plb.139.1541096006596; Thu, 01 Nov 2018 11:13:26 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1541096006; cv=none; d=google.com; s=arc-20160816; b=qy52eLbi4l09ZRBgoU1wHAC70qURmUo17bVy4nWptid8/VBtkfvLmPhovI8Yk2em2d umigetsnFxXMmM8/4qjiy8z13CeKCA8AxlwFLzhRf/qBwcYiAwIGHv9Tr4QUtwscKNBC D5TuWgs8nGmdD+RtTJmvA19i4Hu2sk4CdUUh2FuAN/FfWqdqUMcRuUbGpTS4e8ka6jdE RBmebn0muMITQiBL6Uye6FCZeSrLCKd1TLXkkj7LziZ3gt0ul+FiHxwqrbmcXr/yvTP1 uYmAg1B50JpMwj0cONe0npVNAMV1GL3WoUqCNgH+nex75fePOpR/Xcw1yr0jE5GSZUv/ LRUA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:mime-version:user-agent:message-id :in-reply-to:date:references:subject:cc:to:from; bh=BPjFol6Sr0EvCdi2+FAwc9g/2YTMMLLz5UQqTBe5wPk=; b=ZK9zubokFtgmBGN3n9S/qTegRWkT3kxK+UBF2yKKxyT3DyM37t7JcMUuq6M0icE+yM KiXphv8EhVe4dhfiyCIEEgW84laEXEXcSH1racda0Iwsnug2CGchbaLeo7f9H6IoOGRd BcQ46ANJm5qpg6BgGkE26jYoM4E8tBtxUs76Gpuwa4wvPTE6DwpmJHW4FpXePchEtPy1 Qu8g1H+btiYrWzfCXQDP/8oWJSeWR+YxQpg0Qb3uaZrFdVWl5tz9tge4th+8C2eICRG5 jY1BERAyAxz+/6OYwMTrYaH79NWtYp8Q6Ngq1VXEjEXSbDdca06P6Uuycjjwrk12TVyy v9LQ== 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; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=redhat.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id a31-v6si29605505pgl.280.2018.11.01.11.13.04; Thu, 01 Nov 2018 11:13:26 -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; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=redhat.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727704AbeKBDNh (ORCPT + 99 others); Thu, 1 Nov 2018 23:13:37 -0400 Received: from mx1.redhat.com ([209.132.183.28]:52488 "EHLO mx1.redhat.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726242AbeKBDNh (ORCPT ); Thu, 1 Nov 2018 23:13:37 -0400 Received: from smtp.corp.redhat.com (int-mx07.intmail.prod.int.phx2.redhat.com [10.5.11.22]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id EAE51308A948; Thu, 1 Nov 2018 18:09:33 +0000 (UTC) Received: from oldenburg.str.redhat.com (ovpn-116-136.ams2.redhat.com [10.36.116.136]) by smtp.corp.redhat.com (Postfix) with ESMTPS id B8872105705E; Thu, 1 Nov 2018 18:09:20 +0000 (UTC) From: Florian Weimer To: Andy Lutomirski Cc: Dave Hansen , "Christopherson\, Sean J" , Jethro Beekman , Jarkko Sakkinen , Linux API , Jann Horn , Linus Torvalds , X86 ML , linux-arch , LKML , Peter Zijlstra , Rich Felker , nhorman@redhat.com, npmccallum@redhat.com, "Ayoun\, Serge" , shay.katz-zamir@intel.com, linux-sgx@vger.kernel.org, Andy Shevchenko , Thomas Gleixner , Ingo Molnar , Borislav Petkov , Adhemerval Zanella , carlos@redhat.com Subject: Re: RFC: userspace exception fixups References: Date: Thu, 01 Nov 2018 19:09:17 +0100 In-Reply-To: (Andy Lutomirski's message of "Thu, 1 Nov 2018 10:53:40 -0700") Message-ID: <877ehwisaa.fsf@oldenburg.str.redhat.com> User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/25.3 (gnu/linux) MIME-Version: 1.0 Content-Type: text/plain X-Scanned-By: MIMEDefang 2.84 on 10.5.11.22 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.41]); Thu, 01 Nov 2018 18:09:34 +0000 (UTC) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org * Andy Lutomirski: > The basic idea would be to allow libc, or maybe even any library, to > register a handler that gets a chance to act on an exception caused by > a user instruction before a signal is delivered. As a straw-man > example for how this could work, there could be a new syscall: > > long register_exception_handler(void (*handler)(int, siginfo_t *, void *)); > > If a handler is registered, then, if a synchronous exception happens > (page fault, etc), the kernel would set up an exception frame as usual > but, rather than checking for signal handlers, it would just call the > registered handler. That handler is expected to either handle the > exception entirely on its own or to call one of two new syscalls to > ask for normal signal delivery or to ask to retry the faulting > instruction. Would the exception handler be a per-thread resource? If it is: Would the setup and teardown overhead be prohibitive for many use cases (at least those do not expect a fault)? Something peripherally related to this interface: Wrappers for signal handlers (and not just CPU exceptions). Ideally, we want to maintain a flag that indicates whether we are in a signal handler, and save and restore errno around the installed handler. > Alternatively, we could do something a lot more like the kernel's > internal fixups where there's a table in user memory that maps > potentially faulting instructions to landing pads that handle > exceptions. GCC already supports that on most Linux targets. You can unwind from synchronously invoked signal handlers if you compile with -fnon-call-exceptions. However, it's tough to set up a temporary signal handler to trigger such unwinding because those aren't per-thread. > On Windows, you can use SEH to do crazy things like running > known-buggy code and eating the page faults. I don't think we want to > go there. The original SEH was also a rich target for exploiting vulnerabilities. That's something we really should avoid as well. I wonder if it would be possible to tack this function onto rseq. Thanks, Florian