From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-13.9 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI, NICE_REPLY_A,SPF_HELO_NONE,SPF_PASS,USER_AGENT_SANE_1,USER_IN_DEF_DKIM_WL autolearn=no autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 99393C433DF for ; Tue, 28 Jul 2020 18:52:06 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 7B1D020825 for ; Tue, 28 Jul 2020 18:52:06 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (1024-bit key) header.d=linux.microsoft.com header.i=@linux.microsoft.com header.b="N5ASgrJb" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1732522AbgG1SwE (ORCPT ); Tue, 28 Jul 2020 14:52:04 -0400 Received: from linux.microsoft.com ([13.77.154.182]:54666 "EHLO linux.microsoft.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728782AbgG1SwE (ORCPT ); Tue, 28 Jul 2020 14:52:04 -0400 Received: from [192.168.254.32] (unknown [47.187.206.220]) by linux.microsoft.com (Postfix) with ESMTPSA id D9CA720B4908; Tue, 28 Jul 2020 11:52:02 -0700 (PDT) DKIM-Filter: OpenDKIM Filter v2.11.0 linux.microsoft.com D9CA720B4908 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.microsoft.com; s=default; t=1595962323; bh=4VqGIlTMQb0KmRbW1ECdJsuWGdo+ykQfeo4qSABGj8g=; h=Subject:To:Cc:References:From:Date:In-Reply-To:From; b=N5ASgrJbpo8ewcnejqNlOMHW1LlvWw6Pa2UCzET1NHRPpRnwTSki0Dk44+lBNhwyc 0Oczcbp+TB0JMzyxyK22fLDJcHQra90UOmtWziVf9oqC+T8MJc1Dn+vnJuvj0FVugv h+6UG1h/10vIpOjMBqWpPTkZqsk7ZujJKLdE1AKo= Subject: Re: [PATCH v1 0/4] [RFC] Implement Trampoline File Descriptor To: Andy Lutomirski Cc: David Laight , "kernel-hardening@lists.openwall.com" , "linux-api@vger.kernel.org" , "linux-arm-kernel@lists.infradead.org" , "linux-fsdevel@vger.kernel.org" , "linux-integrity@vger.kernel.org" , "linux-kernel@vger.kernel.org" , "linux-security-module@vger.kernel.org" , "oleg@redhat.com" , "x86@kernel.org" References: <20200728131050.24443-1-madvenka@linux.microsoft.com> From: "Madhavan T. Venkataraman" Message-ID: <59246260-e535-a9f1-d89e-4e953288b977@linux.microsoft.com> Date: Tue, 28 Jul 2020 13:52:01 -0500 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:68.0) Gecko/20100101 Thunderbird/68.10.0 MIME-Version: 1.0 In-Reply-To: Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit Content-Language: en-US Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On 7/28/20 12:16 PM, Andy Lutomirski wrote: > On Tue, Jul 28, 2020 at 9:32 AM Madhavan T. Venkataraman > wrote: >> Thanks. See inline.. >> >> On 7/28/20 10:13 AM, David Laight wrote: >>> From: madvenka@linux.microsoft.com >>>> Sent: 28 July 2020 14:11 >>> ... >>>> The kernel creates the trampoline mapping without any permissions. When >>>> the trampoline is executed by user code, a page fault happens and the >>>> kernel gets control. The kernel recognizes that this is a trampoline >>>> invocation. It sets up the user registers based on the specified >>>> register context, and/or pushes values on the user stack based on the >>>> specified stack context, and sets the user PC to the requested target >>>> PC. When the kernel returns, execution continues at the target PC. >>>> So, the kernel does the work of the trampoline on behalf of the >>>> application. >>> Isn't the performance of this going to be horrid? >> It takes about the same amount of time as getpid(). So, it is >> one quick trip into the kernel. I expect that applications will >> typically not care about this extra overhead as long as >> they are able to run. > What did you test this on? A page fault on any modern x86_64 system > is much, much, much, much slower than a syscall. I sent a response to this. But the mail was returned to me. I am resending. I tested it in on a KVM guest running Ubuntu. So, when you say that a page fault is much slower, do you mean a regular page fault that is handled through the VM layer? Here is the relevant code in do_user_addr_fault():         if (unlikely(access_error(hw_error_code, vma))) {                 /*                                   * If it is a user execute fault, it could be a trampoline                  * invocation.                  */                 if ((hw_error_code & tflags) == tflags &&                      trampfd_fault(vma, regs)) {                          up_read(&mm->mmap_sem);                          return;                  }                  bad_area_access_error(regs, hw_error_code, address, vma);                  return;          }          ...          fault = handle_mm_fault(vma, address, flags); trampfd faults are instruction faults that go through a different code path than the one that calls handle_mm_fault(). Perhaps, it is the handle_mm_fault() that is time consuming. Could you clarify? Thanks. Madhavan From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-6.3 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI, NICE_REPLY_A,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED,USER_AGENT_SANE_1 autolearn=no autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 4D31BC433E5 for ; Tue, 28 Jul 2020 18:53:44 +0000 (UTC) Received: from merlin.infradead.org (merlin.infradead.org [205.233.59.134]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 1E553207F5 for ; Tue, 28 Jul 2020 18:53:44 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=lists.infradead.org header.i=@lists.infradead.org header.b="cUEet9v0"; dkim=fail reason="signature verification failed" (1024-bit key) header.d=linux.microsoft.com header.i=@linux.microsoft.com header.b="N5ASgrJb" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 1E553207F5 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=linux.microsoft.com Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=merlin.20170209; h=Sender:Content-Transfer-Encoding: Content-Type:Cc:List-Subscribe:List-Help:List-Post:List-Archive: List-Unsubscribe:List-Id:In-Reply-To:MIME-Version:Date:Message-ID:From: References:To:Subject:Reply-To:Content-ID:Content-Description:Resent-Date: Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Owner; bh=k/2rspWha20vBc2i0jl3+DMdTBC8h7lnoQqEDPxG8pc=; b=cUEet9v0rTsRJqvdkAifQUztU 1ykbYrUDXemhpBGA3yiPx3rDb6FYvf8VyfyckjFe/XbRrgDoRRiwnfeSkkznDWh57Q/7ORYe81Ch6 fML48Y1nSPunnKMhhmChgaZxXWHJRZzWpdW7EsZzdL0gpfVyx8UP6Jxg+54LeeJTGYMaeNonuX/1F qcw/YfcaYSFXzAbkyjfgjKM9CtZPh5vnp5N4swk9VlBvr1lKUJLKNq1tz1uhyDYQzffXn9XwYQJ5V AsnmBq3OqAQjKfZexz7PqqKV5Qd+m417mzLOPH1tw9otp45w58eEzLsZyGOXu49kt1tdXp8ayhsMM iw465os5A==; Received: from localhost ([::1] helo=merlin.infradead.org) by merlin.infradead.org with esmtp (Exim 4.92.3 #3 (Red Hat Linux)) id 1k0Uhq-0001u1-SE; Tue, 28 Jul 2020 18:52:06 +0000 Received: from linux.microsoft.com ([13.77.154.182]) by merlin.infradead.org with esmtp (Exim 4.92.3 #3 (Red Hat Linux)) id 1k0Uhp-0001t2-5I for linux-arm-kernel@lists.infradead.org; Tue, 28 Jul 2020 18:52:06 +0000 Received: from [192.168.254.32] (unknown [47.187.206.220]) by linux.microsoft.com (Postfix) with ESMTPSA id D9CA720B4908; Tue, 28 Jul 2020 11:52:02 -0700 (PDT) DKIM-Filter: OpenDKIM Filter v2.11.0 linux.microsoft.com D9CA720B4908 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.microsoft.com; s=default; t=1595962323; bh=4VqGIlTMQb0KmRbW1ECdJsuWGdo+ykQfeo4qSABGj8g=; h=Subject:To:Cc:References:From:Date:In-Reply-To:From; b=N5ASgrJbpo8ewcnejqNlOMHW1LlvWw6Pa2UCzET1NHRPpRnwTSki0Dk44+lBNhwyc 0Oczcbp+TB0JMzyxyK22fLDJcHQra90UOmtWziVf9oqC+T8MJc1Dn+vnJuvj0FVugv h+6UG1h/10vIpOjMBqWpPTkZqsk7ZujJKLdE1AKo= Subject: Re: [PATCH v1 0/4] [RFC] Implement Trampoline File Descriptor To: Andy Lutomirski References: <20200728131050.24443-1-madvenka@linux.microsoft.com> From: "Madhavan T. Venkataraman" Message-ID: <59246260-e535-a9f1-d89e-4e953288b977@linux.microsoft.com> Date: Tue, 28 Jul 2020 13:52:01 -0500 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:68.0) Gecko/20100101 Thunderbird/68.10.0 MIME-Version: 1.0 In-Reply-To: Content-Language: en-US X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20200728_145205_426696_B2C7513B X-CRM114-Status: GOOD ( 18.39 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: "kernel-hardening@lists.openwall.com" , "linux-api@vger.kernel.org" , "x86@kernel.org" , "linux-kernel@vger.kernel.org" , "oleg@redhat.com" , "linux-security-module@vger.kernel.org" , David Laight , "linux-fsdevel@vger.kernel.org" , "linux-integrity@vger.kernel.org" , "linux-arm-kernel@lists.infradead.org" Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: base64 Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org CgpPbiA3LzI4LzIwIDEyOjE2IFBNLCBBbmR5IEx1dG9taXJza2kgd3JvdGU6Cj4gT24gVHVlLCBK dWwgMjgsIDIwMjAgYXQgOTozMiBBTSBNYWRoYXZhbiBULiBWZW5rYXRhcmFtYW4KPiA8bWFkdmVu a2FAbGludXgubWljcm9zb2Z0LmNvbT4gd3JvdGU6Cj4+IFRoYW5rcy4gU2VlIGlubGluZS4uCj4+ Cj4+IE9uIDcvMjgvMjAgMTA6MTMgQU0sIERhdmlkIExhaWdodCB3cm90ZToKPj4+IEZyb206ICBt YWR2ZW5rYUBsaW51eC5taWNyb3NvZnQuY29tCj4+Pj4gU2VudDogMjggSnVseSAyMDIwIDE0OjEx Cj4+PiAuLi4KPj4+PiBUaGUga2VybmVsIGNyZWF0ZXMgdGhlIHRyYW1wb2xpbmUgbWFwcGluZyB3 aXRob3V0IGFueSBwZXJtaXNzaW9ucy4gV2hlbgo+Pj4+IHRoZSB0cmFtcG9saW5lIGlzIGV4ZWN1 dGVkIGJ5IHVzZXIgY29kZSwgYSBwYWdlIGZhdWx0IGhhcHBlbnMgYW5kIHRoZQo+Pj4+IGtlcm5l bCBnZXRzIGNvbnRyb2wuIFRoZSBrZXJuZWwgcmVjb2duaXplcyB0aGF0IHRoaXMgaXMgYSB0cmFt cG9saW5lCj4+Pj4gaW52b2NhdGlvbi4gSXQgc2V0cyB1cCB0aGUgdXNlciByZWdpc3RlcnMgYmFz ZWQgb24gdGhlIHNwZWNpZmllZAo+Pj4+IHJlZ2lzdGVyIGNvbnRleHQsIGFuZC9vciBwdXNoZXMg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MKgwqDCoMKgwqDCoMKgwqDCoCB9CsKgwqDCoMKgwqDCoMKgwqDCoMKgwqDC oMKgwqDCoMKgIGJhZF9hcmVhX2FjY2Vzc19lcnJvcihyZWdzLCBod19lcnJvcl9jb2RlLCBhZGRy ZXNzLCB2bWEpOwrCoMKgwqDCoMKgwqDCoMKgwqDCoMKgwqDCoMKgwqDCoCByZXR1cm47CsKgwqDC oMKgwqDCoMKgwqAgfQrCoMKgwqDCoMKgwqDCoMKgIC4uLgrCoMKgwqDCoMKgwqDCoMKgIGZhdWx0 ID0gaGFuZGxlX21tX2ZhdWx0KHZtYSwgYWRkcmVzcywgZmxhZ3MpOwoKdHJhbXBmZCBmYXVsdHMg YXJlIGluc3RydWN0aW9uIGZhdWx0cyB0aGF0IGdvIHRocm91Z2ggYSBkaWZmZXJlbnQgY29kZSBw YXRoIHRoYW4KdGhlIG9uZSB0aGF0IGNhbGxzIGhhbmRsZV9tbV9mYXVsdCgpLiBQZXJoYXBzLCBp dCBpcyB0aGUgaGFuZGxlX21tX2ZhdWx0KCkgdGhhdAppcyB0aW1lIGNvbnN1bWluZy4gQ291bGQg eW91IGNsYXJpZnk/CgpUaGFua3MuCgpNYWRoYXZhbgoKX19fX19fX19fX19fX19fX19fX19fX19f X19fX19fX19fX19fX19fX19fX19fX18KbGludXgtYXJtLWtlcm5lbCBtYWlsaW5nIGxpc3QKbGlu dXgtYXJtLWtlcm5lbEBsaXN0cy5pbmZyYWRlYWQub3JnCmh0dHA6Ly9saXN0cy5pbmZyYWRlYWQu b3JnL21haWxtYW4vbGlzdGluZm8vbGludXgtYXJtLWtlcm5lbAo= From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-13.9 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI, NICE_REPLY_A,SPF_HELO_NONE,SPF_PASS,USER_AGENT_SANE_1,USER_IN_DEF_DKIM_WL autolearn=no autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id CE79FC433E8 for ; Tue, 28 Jul 2020 18:52:24 +0000 (UTC) Received: from mother.openwall.net (mother.openwall.net [195.42.179.200]) by mail.kernel.org (Postfix) with SMTP id 2AC5C207F5 for ; Tue, 28 Jul 2020 18:52:23 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (1024-bit key) header.d=linux.microsoft.com header.i=@linux.microsoft.com header.b="N5ASgrJb" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 2AC5C207F5 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=linux.microsoft.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=kernel-hardening-return-19483-kernel-hardening=archiver.kernel.org@lists.openwall.com Received: (qmail 16035 invoked by uid 550); 28 Jul 2020 18:52:16 -0000 Mailing-List: contact kernel-hardening-help@lists.openwall.com; run by ezmlm Precedence: bulk List-Post: List-Help: List-Unsubscribe: List-Subscribe: List-ID: Received: (qmail 16015 invoked from network); 28 Jul 2020 18:52:15 -0000 DKIM-Filter: OpenDKIM Filter v2.11.0 linux.microsoft.com D9CA720B4908 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.microsoft.com; s=default; t=1595962323; bh=4VqGIlTMQb0KmRbW1ECdJsuWGdo+ykQfeo4qSABGj8g=; h=Subject:To:Cc:References:From:Date:In-Reply-To:From; b=N5ASgrJbpo8ewcnejqNlOMHW1LlvWw6Pa2UCzET1NHRPpRnwTSki0Dk44+lBNhwyc 0Oczcbp+TB0JMzyxyK22fLDJcHQra90UOmtWziVf9oqC+T8MJc1Dn+vnJuvj0FVugv h+6UG1h/10vIpOjMBqWpPTkZqsk7ZujJKLdE1AKo= Subject: Re: [PATCH v1 0/4] [RFC] Implement Trampoline File Descriptor To: Andy Lutomirski Cc: David Laight , "kernel-hardening@lists.openwall.com" , "linux-api@vger.kernel.org" , "linux-arm-kernel@lists.infradead.org" , "linux-fsdevel@vger.kernel.org" , "linux-integrity@vger.kernel.org" , "linux-kernel@vger.kernel.org" , "linux-security-module@vger.kernel.org" , "oleg@redhat.com" , "x86@kernel.org" References: <20200728131050.24443-1-madvenka@linux.microsoft.com> From: "Madhavan T. Venkataraman" Message-ID: <59246260-e535-a9f1-d89e-4e953288b977@linux.microsoft.com> Date: Tue, 28 Jul 2020 13:52:01 -0500 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:68.0) Gecko/20100101 Thunderbird/68.10.0 MIME-Version: 1.0 In-Reply-To: Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit Content-Language: en-US On 7/28/20 12:16 PM, Andy Lutomirski wrote: > On Tue, Jul 28, 2020 at 9:32 AM Madhavan T. Venkataraman > wrote: >> Thanks. See inline.. >> >> On 7/28/20 10:13 AM, David Laight wrote: >>> From: madvenka@linux.microsoft.com >>>> Sent: 28 July 2020 14:11 >>> ... >>>> The kernel creates the trampoline mapping without any permissions. When >>>> the trampoline is executed by user code, a page fault happens and the >>>> kernel gets control. The kernel recognizes that this is a trampoline >>>> invocation. It sets up the user registers based on the specified >>>> register context, and/or pushes values on the user stack based on the >>>> specified stack context, and sets the user PC to the requested target >>>> PC. When the kernel returns, execution continues at the target PC. >>>> So, the kernel does the work of the trampoline on behalf of the >>>> application. >>> Isn't the performance of this going to be horrid? >> It takes about the same amount of time as getpid(). So, it is >> one quick trip into the kernel. I expect that applications will >> typically not care about this extra overhead as long as >> they are able to run. > What did you test this on? A page fault on any modern x86_64 system > is much, much, much, much slower than a syscall. I sent a response to this. But the mail was returned to me. I am resending. I tested it in on a KVM guest running Ubuntu. So, when you say that a page fault is much slower, do you mean a regular page fault that is handled through the VM layer? Here is the relevant code in do_user_addr_fault():         if (unlikely(access_error(hw_error_code, vma))) {                 /*                                   * If it is a user execute fault, it could be a trampoline                  * invocation.                  */                 if ((hw_error_code & tflags) == tflags &&                      trampfd_fault(vma, regs)) {                          up_read(&mm->mmap_sem);                          return;                  }                  bad_area_access_error(regs, hw_error_code, address, vma);                  return;          }          ...          fault = handle_mm_fault(vma, address, flags); trampfd faults are instruction faults that go through a different code path than the one that calls handle_mm_fault(). Perhaps, it is the handle_mm_fault() that is time consuming. Could you clarify? Thanks. Madhavan