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 Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id C3D65C4332F for ; Tue, 4 Jan 2022 14:22:15 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id CD2206B0071; Tue, 4 Jan 2022 09:22:14 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id C80EB6B0072; Tue, 4 Jan 2022 09:22:14 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id B21546B0073; Tue, 4 Jan 2022 09:22:14 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0143.hostedemail.com [216.40.44.143]) by kanga.kvack.org (Postfix) with ESMTP id A01AD6B0071 for ; Tue, 4 Jan 2022 09:22:14 -0500 (EST) Received: from smtpin03.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay01.hostedemail.com (Postfix) with ESMTP id 56B28181D2FC9 for ; Tue, 4 Jan 2022 14:22:14 +0000 (UTC) X-FDA: 78992819388.03.C11CA1C Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by imf19.hostedemail.com (Postfix) with ESMTP id 990A21A000B for ; Tue, 4 Jan 2022 14:22:12 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1641306132; 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=Kd7NsJXI8gYpybe5mVP7ztpJR15QwvvZgvb8pedcJXM=; b=axoRBK6p3Lp99Int9sYSISRZcVBIdf6hNqcTxmkQHN0A7etKV1aoblUsGk8fa4eZNJfamm paP0xkktK/gtvMLmSnYunPARdTdSKwT29vMe7Ix9gB40WKECnKuvAvUC3szlgAvgfGNAkQ u6jx0mmr3Pc02UjB2lFnq6xslgjVSAU= Received: from mail-wm1-f72.google.com (mail-wm1-f72.google.com [209.85.128.72]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-18-4FJkSsM9MLGe3bYMXVdt3Q-1; Tue, 04 Jan 2022 09:22:11 -0500 X-MC-Unique: 4FJkSsM9MLGe3bYMXVdt3Q-1 Received: by mail-wm1-f72.google.com with SMTP id e19-20020a05600c4e5300b003458be97976so355958wmq.7 for ; Tue, 04 Jan 2022 06:22:10 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:message-id:date:mime-version:user-agent:subject :content-language:to:cc:references:from:organization:in-reply-to :content-transfer-encoding; bh=Kd7NsJXI8gYpybe5mVP7ztpJR15QwvvZgvb8pedcJXM=; b=up8LGrHVBB9iBPQjPcyR4KHqy3VptXpMl9TVY8E5YxQqfw0hkbhxwcLt9oodubV468 J5GNfuPrcfzDHRbQS8S2D3rDai7CsGk0LFS3/8fp2BNHIx+hMkG/k52rgCZlrGjV7QqL Gfi4Bsq/pslv7jjerXeBTLlzYLg/apO77V9QIp3UMbxR50HUpcCz/4zGgSj3/nSvdnyB +hzwhbLZL1yBPP1TRt6ishr0m+/x5kRTflyReo8UZ5F9WojmDYvr737/R9ZBg0s2y4W0 hdIcezwaspoQYtjtkn3pY0oEqoD3HAueR4uOtTxPWT4ghzk1oiu35yWYKD8wsjdT4iSd UU1g== X-Gm-Message-State: AOAM530OdtFc3a4CIU/nVZLa1de09Ud/qk83NxZTEdN4sLoAxGcxNM3Z T9jZAQSqupXtktNaqxxAMxSxQ+DNVuXnulsUNOMxmHIvEH+dJoqGPYFWVevC9KoAdvAqp+M+cm6 hQS9U2Z0zhvM= X-Received: by 2002:a05:600c:3589:: with SMTP id p9mr43117676wmq.109.1641306129989; Tue, 04 Jan 2022 06:22:09 -0800 (PST) X-Google-Smtp-Source: ABdhPJw32qpFKWD69dT7hryNwrsfqQlIKMprgz5fqX/4Bi/8nva34KM25ikuyModAt0N7b2C0ORoeQ== X-Received: by 2002:a05:600c:3589:: with SMTP id p9mr43117653wmq.109.1641306129690; Tue, 04 Jan 2022 06:22:09 -0800 (PST) Received: from [192.168.3.132] (p5b0c62bd.dip0.t-ipconnect.de. [91.12.98.189]) by smtp.gmail.com with ESMTPSA id r11sm38357940wrw.5.2022.01.04.06.22.07 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Tue, 04 Jan 2022 06:22:09 -0800 (PST) Message-ID: <7eb40902-45dd-9193-37f1-efaca381529b@redhat.com> Date: Tue, 4 Jan 2022 15:22:07 +0100 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:91.0) Gecko/20100101 Thunderbird/91.4.0 Subject: Re: [PATCH v3 kvm/queue 01/16] mm/shmem: Introduce F_SEAL_INACCESSIBLE To: Chao Peng , kvm@vger.kernel.org, linux-kernel@vger.kernel.org, linux-mm@kvack.org, linux-fsdevel@vger.kernel.org, qemu-devel@nongnu.org Cc: Paolo Bonzini , Jonathan Corbet , Sean Christopherson , Vitaly Kuznetsov , Wanpeng Li , Jim Mattson , Joerg Roedel , Thomas Gleixner , Ingo Molnar , Borislav Petkov , x86@kernel.org, "H . Peter Anvin" , Hugh Dickins , Jeff Layton , "J . Bruce Fields" , Andrew Morton , Yu Zhang , "Kirill A . Shutemov" , luto@kernel.org, john.ji@intel.com, susie.li@intel.com, jun.nakajima@intel.com, dave.hansen@intel.com, ak@linux.intel.com References: <20211223123011.41044-1-chao.p.peng@linux.intel.com> <20211223123011.41044-2-chao.p.peng@linux.intel.com> From: David Hildenbrand Organization: Red Hat In-Reply-To: <20211223123011.41044-2-chao.p.peng@linux.intel.com> X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Language: en-US Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 7bit Authentication-Results: imf19.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=axoRBK6p; spf=none (imf19.hostedemail.com: domain of david@redhat.com has no SPF policy when checking 170.10.133.124) smtp.mailfrom=david@redhat.com; dmarc=pass (policy=none) header.from=redhat.com X-Rspamd-Queue-Id: 990A21A000B X-Stat-Signature: opudso3bkh84y5zsan51yjhw19gjz5m6 X-Rspamd-Server: rspam04 X-HE-Tag: 1641306132-29232 X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: On 23.12.21 13:29, Chao Peng wrote: > From: "Kirill A. Shutemov" > > Introduce a new seal F_SEAL_INACCESSIBLE indicating the content of > the file is inaccessible from userspace in any possible ways like > read(),write() or mmap() etc. > > It provides semantics required for KVM guest private memory support > that a file descriptor with this seal set is going to be used as the > source of guest memory in confidential computing environments such > as Intel TDX/AMD SEV but may not be accessible from host userspace. > > At this time only shmem implements this seal. > > Signed-off-by: Kirill A. Shutemov > Signed-off-by: Chao Peng > --- > include/uapi/linux/fcntl.h | 1 + > mm/shmem.c | 37 +++++++++++++++++++++++++++++++++++-- > 2 files changed, 36 insertions(+), 2 deletions(-) > > diff --git a/include/uapi/linux/fcntl.h b/include/uapi/linux/fcntl.h > index 2f86b2ad6d7e..e2bad051936f 100644 > --- a/include/uapi/linux/fcntl.h > +++ b/include/uapi/linux/fcntl.h > @@ -43,6 +43,7 @@ > #define F_SEAL_GROW 0x0004 /* prevent file from growing */ > #define F_SEAL_WRITE 0x0008 /* prevent writes */ > #define F_SEAL_FUTURE_WRITE 0x0010 /* prevent future writes while mapped */ > +#define F_SEAL_INACCESSIBLE 0x0020 /* prevent file from accessing */ I think this needs more clarification: the file content can still be accessed using in-kernel mechanisms such as MEMFD_OPS for KVM. It effectively disallows traditional access to a file (read/write/mmap) that will result in ordinary MMU access to file content. Not sure how to best clarify that: maybe, prevent ordinary MMU access (e.g., read/write/mmap) to file content? > /* (1U << 31) is reserved for signed error codes */ > > /* > diff --git a/mm/shmem.c b/mm/shmem.c > index 18f93c2d68f1..faa7e9b1b9bc 100644 > --- a/mm/shmem.c > +++ b/mm/shmem.c > @@ -1098,6 +1098,10 @@ static int shmem_setattr(struct user_namespace *mnt_userns, > (newsize > oldsize && (info->seals & F_SEAL_GROW))) > return -EPERM; > > + if ((info->seals & F_SEAL_INACCESSIBLE) && > + (newsize & ~PAGE_MASK)) > + return -EINVAL; > + What happens when sealing and there are existing mmaps? -- Thanks, David / dhildenb