Received: by 2002:a05:6a10:16a7:0:0:0:0 with SMTP id gp39csp596629pxb; Thu, 5 Nov 2020 08:07:09 -0800 (PST) X-Google-Smtp-Source: ABdhPJz/gtPFsp0Qbyg8dMPxAkBebCW3OSs7ZAcTmbx56C6xqdA+JbtdDfKaweL31a+QLHPrh74U X-Received: by 2002:a05:6402:1f0:: with SMTP id i16mr3225476edy.122.1604592429266; Thu, 05 Nov 2020 08:07:09 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1604592429; cv=none; d=google.com; s=arc-20160816; b=dpvDAlg+6pqc3LcbzV7/zjuGZuAHNNLZC1YAocBWPrDD+1dMxi2vis1I3huGnPUqEV pWPzX0mILCuACGwfPg2SEKE4cTx0AZVwfImwpslEHzfckr2co42+vG57xNy3pXXxHZWd Js66sKTUnk8PtbYp9DXcrCHZpbC5ZAViS3stx2LaPnSTEeZMZg+ejO/s/oGz84YrUAVQ LqiGkw78+ssplXOj4UUjD+z+jQT3yX1h5IUU1vPdabGP97auZ3Z0d5NTRiFSWEKaupn/ qI34dJsKQrhG4YKnDH5NelGx7P3Hw1VvznUcsOvywCNZAD2NRj4nEoLZRar5vzBGXmud qrbQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:in-reply-to:content-transfer-encoding :content-disposition:mime-version:references:message-id:subject:cc :to:from:date:dkim-signature; bh=SzsXHWOTotG9TSv9RImL2IoAhUNP7oiQrY5qi5tuMzg=; b=pSmRbVojo6UTpF0xcsTGcV8s/A3ogcj9vEHooTUHtAmvgHFum2XtuntUVkBfs5xuQg MvGYTLrHyo1E3RbKrQIkJqjdH0DdT4nZDCqPpgIJaJk8zZsp/TljjNfGnH+XFZLbn8wa hr5ebRscNIeqOG1nE7vXPHCm+2ohtGV06isAYI2Cx9LP3gIhjpQV1HbUxGb4cTEWmdtO +ItuqIV/90L0YCid9UAJGzZ5igol25aai0kmQCgJPL187PTKPnWObI6/38+WaIGFg0oZ uiS6dcU7IsDkDLozuxZRq0JR6zM2ZUfLNSqOxlL6b1GJwahDL7ozOPTrFiXUwBLNpczP 1rpw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@alien8.de header.s=dkim header.b=TTyCVstW; 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; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=alien8.de Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id s9si1436021edu.457.2020.11.05.08.06.42; Thu, 05 Nov 2020 08:07:09 -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; dkim=pass header.i=@alien8.de header.s=dkim header.b=TTyCVstW; 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; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=alien8.de Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728523AbgKEQEl (ORCPT + 99 others); Thu, 5 Nov 2020 11:04:41 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:59540 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725308AbgKEQEl (ORCPT ); Thu, 5 Nov 2020 11:04:41 -0500 Received: from mail.skyhub.de (mail.skyhub.de [IPv6:2a01:4f8:190:11c2::b:1457]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id E7010C0613CF; Thu, 5 Nov 2020 08:04:40 -0800 (PST) Received: from zn.tnic (p200300ec2f0ee5006c78cd15f1739a31.dip0.t-ipconnect.de [IPv6:2003:ec:2f0e:e500:6c78:cd15:f173:9a31]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.skyhub.de (SuperMail on ZX Spectrum 128k) with ESMTPSA id 0EE661EC03A0; Thu, 5 Nov 2020 17:04:39 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=alien8.de; s=dkim; t=1604592279; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=SzsXHWOTotG9TSv9RImL2IoAhUNP7oiQrY5qi5tuMzg=; b=TTyCVstWqebTE3827G5LtgKLGpokNNaaiDLK72NkKv8n4FR4eGLhoqG67GosMAQP+nAxyu 8FHp+h1yYv1jkvGiKjeYd2WFJhZ9ElQ6sGBygTGjiO1EcfEqVqwPfxSoh9C/vSE+6N3Tqh a7tj641Cq/hxAICh/LzykJUSICAenIw= Date: Thu, 5 Nov 2020 17:04:24 +0100 From: Borislav Petkov 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 , Darren Kenny , andriy.shevchenko@linux.intel.com, asapek@google.com, cedric.xing@intel.com, chenalexchen@google.com, conradparker@google.com, cyhanish@google.com, dave.hansen@intel.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 v40 10/24] mm: Add 'mprotect' hook to struct vm_operations_struct Message-ID: <20201105160424.GC25636@zn.tnic> References: <20201104145430.300542-1-jarkko.sakkinen@linux.intel.com> <20201104145430.300542-11-jarkko.sakkinen@linux.intel.com> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: <20201104145430.300542-11-jarkko.sakkinen@linux.intel.com> Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Wed, Nov 04, 2020 at 04:54:16PM +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 me 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 > Acked-by: Jethro Beekman > Reviewed-by: Darren Kenny > Signed-off-by: Sean Christopherson > Co-developed-by: Jarkko Sakkinen > Signed-off-by: Jarkko Sakkinen > --- > include/linux/mm.h | 3 +++ > mm/mprotect.c | 5 ++++- > 2 files changed, 7 insertions(+), 1 deletion(-) This needs an ACK from an mm person. -- Regards/Gruss, Boris. https://people.kernel.org/tglx/notes-about-netiquette