Received: by 2002:a05:6a10:16a7:0:0:0:0 with SMTP id gp39csp1036520pxb; Fri, 13 Nov 2020 02:28:14 -0800 (PST) X-Google-Smtp-Source: ABdhPJzjozGT/+50eN7BytMAlFyIoBjhefHjMkvpJAZoNoFG3vS6gMinSaotyZeOUfc/t76ZdeaY X-Received: by 2002:a17:906:f148:: with SMTP id gw8mr1225779ejb.192.1605263293846; Fri, 13 Nov 2020 02:28:13 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1605263293; cv=none; d=google.com; s=arc-20160816; b=QyAvNu108BLdap7KSybwRiC/NgRkIc+zaUODcKcNB+MvTbzm8nlTMGUXBY1qNpAvN2 HKdUlcQdi40uMoedsKdGuMV6yXLWyJP2YxYB/zAheHkFlRd4kLWe7RCBSm/OVVPrIMJS vgScXT61S473/Qis0yHD3qDzW8L/MeuAIU8MprDXeC8iKICfwhxoWVtvMnQdQGxK9+Tm enYAxTu+IcFEXSvEYLwsur3U4XvIfcHsYSX7oXxy3Jh0LbeiQ0a5rKzovHsJT3p/7cCO VA/fmpsQvEybxGXWvxFL+IcKKqokxeVs7mt0b0eFH+5Okm8exGETcC56n4C5JjgHvgAB lAxQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:user-agent:in-reply-to:content-disposition :mime-version:references:message-id:subject:cc:to:from:date; bh=22NrZ97pcMoZQvs8MM4OfHgIli3e82B4lFmxP2pkG3c=; b=efHitKAHKR3iBiDKe0rlPd8zkSHqvwe+Dg7SISnuWXAVTRYdD+JFQ5FTTJPpJooH8W XOTFRRZESMgmW2w0jFKTHM1tIPy8TYXkobnu6wEqGtMKfaIrteGRs4I6ADr16DepNGss +aMRRHcupWegKjM7nr45CMXmfjn+h/42lhxiGSyhRgY49oqMjrGVvI0rlxtRcIQVLP+p EOA895c1FBryZK1gABkKdnBMswSGLK2NIIuoP9F4c5DVfbdUSO1sj98GzVHMSXohGnvo vdIHZI1W2XspOfkzJtOBzqyemtT112wCIyXiB9Y7YzDY6K95OLw4SeHjoLdz4S+h+VUI okhw== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id bq23si5416061ejb.529.2020.11.13.02.27.49; Fri, 13 Nov 2020 02:28:13 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726288AbgKMKZv (ORCPT + 99 others); Fri, 13 Nov 2020 05:25:51 -0500 Received: from outbound-smtp33.blacknight.com ([81.17.249.66]:43349 "EHLO outbound-smtp33.blacknight.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726176AbgKMKZv (ORCPT ); Fri, 13 Nov 2020 05:25:51 -0500 Received: from mail.blacknight.com (pemlinmail05.blacknight.ie [81.17.254.26]) by outbound-smtp33.blacknight.com (Postfix) with ESMTPS id 277FFBAED0 for ; Fri, 13 Nov 2020 10:25:49 +0000 (GMT) Received: (qmail 5515 invoked from network); 13 Nov 2020 10:25:48 -0000 Received: from unknown (HELO techsingularity.net) (mgorman@techsingularity.net@[84.203.22.4]) by 81.17.254.9 with ESMTPSA (AES256-SHA encrypted, authenticated); 13 Nov 2020 10:25:48 -0000 Date: Fri, 13 Nov 2020 10:25:43 +0000 From: Mel Gorman To: Jarkko Sakkinen Cc: x86@kernel.org, linux-sgx@vger.kernel.org, linux-kernel@vger.kernel.org, Sean Christopherson , linux-mm@kvack.org, Andrew Morton , Matthew Wilcox , Jethro Beekman , Dave Hansen , andriy.shevchenko@linux.intel.com, asapek@google.com, bp@alien8.de, cedric.xing@intel.com, chenalexchen@google.com, conradparker@google.com, cyhanish@google.com, haitao.huang@intel.com, kai.huang@intel.com, kai.svahn@intel.com, kmoy@google.com, ludloff@google.com, luto@kernel.org, nhorman@redhat.com, npmccallum@redhat.com, puiterwijk@redhat.com, rientjes@google.com, tglx@linutronix.de, yaozhangx@google.com, mikko.ylinen@intel.com Subject: Re: [PATCH v41 10/24] mm: Add 'mprotect' hook to struct vm_operations_struct Message-ID: <20201113102543.GK3371@techsingularity.net> References: <20201112220135.165028-1-jarkko@kernel.org> <20201112220135.165028-11-jarkko@kernel.org> MIME-Version: 1.0 Content-Type: text/plain; charset=iso-8859-15 Content-Disposition: inline In-Reply-To: <20201112220135.165028-11-jarkko@kernel.org> User-Agent: Mutt/1.10.1 (2018-07-13) Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Fri, Nov 13, 2020 at 12:01:21AM +0200, Jarkko Sakkinen wrote: > From: Sean Christopherson > > Background > ========== > > 1. SGX enclave pages are populated with data by copying from normal memory > via ioctl() (SGX_IOC_ENCLAVE_ADD_PAGES), which will be added later in > this series. > 2. It is desirable to be able to restrict those normal memory data sources. > For instance, to ensure that the source data is executable before > copying data to an executable enclave page. > 3. Enclave page permissions are dynamic (just like normal permissions) and > can be adjusted at runtime with mprotect(). > > This creates a problem because the original data source may have long since > vanished at the time when enclave page permissions are established (mmap() > or mprotect()). > > The solution (elsewhere in this series) is to force enclaves creators to > declare their paging permission *intent* up front to the ioctl(). This > intent can be immediately compared to the source data???s mapping and > rejected if necessary. > > The ???intent??? is also stashed off for later comparison with enclave > PTEs. This ensures that any future mmap()/mprotect() operations > performed by the enclave creator or done on behalf of the enclave > can be compared with the earlier declared permissions. > > Problem > ======= > > There is an existing mmap() hook which allows SGX to perform this > permission comparison at mmap() time. However, there is no corresponding > ->mprotect() hook. > > Solution > ======== > > Add a vm_ops->mprotect() hook so that mprotect() operations which are > inconsistent with any page's stashed intent can be rejected by the driver. > > Cc: linux-mm@kvack.org > Cc: Andrew Morton > Cc: Matthew Wilcox > Cc: Mel Gorman > Acked-by: Jethro Beekman # v40 > Acked-by: Dave Hansen # v40 > # Signed-off-by: Sean Christopherson > Co-developed-by: Jarkko Sakkinen > Signed-off-by: Jarkko Sakkinen Acked-by: Mel Gorman -- Mel Gorman SUSE Labs