Received: by 2002:a05:6a10:206:0:0:0:0 with SMTP id 6csp1025993pxj; Sat, 29 May 2021 00:35:53 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyI4J2zft6RVzcxwROqNmgyvxL5VklUJa0Kia0nwZl+PxY/D8J9Dr9BynP2qC+srvWGKp2K X-Received: by 2002:a92:d8c8:: with SMTP id l8mr10710188ilo.197.1622273753500; Sat, 29 May 2021 00:35:53 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1622273753; cv=none; d=google.com; s=arc-20160816; b=qDPKiQHhEi7yNw5z2XkSwqTUH6+8cyzzCliSpXF63D7qO50d9ztLnd3SoWOEd4Yx/s pBZs6lAOiTQ4yfOkm0/eCShuCeBPtJSPmLAU1Pn9UxrLkv4DdfP6aksQRJwIxqcfdgnN faF2v3Ly+yT92W57VloYuP+NJJYaHCAkNvPnX7iWTa7Rclwq4WfEw3xZE9iMUIm3hr6E KxkmdFgnQ9zyVW2AifGtycElBiJ+mFJJz6qxAlaMvyzZFqaQ1jwvf9/T8Eyz0XcgSxBX xsx4yY8mawYLQ3oidYV2kAIawaHQfmIhQBwNU2vzmy/n7hEci5I8Z+LvSqmyFPuUZiki GOkQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:content-language :in-reply-to:mime-version:user-agent:date:message-id:from:references :cc:to:subject:dkim-signature; bh=S8hnKQslTlCFAXMU0SU12N+3wAln8HGC0k1kgerLe04=; b=iWKjaRz+9tuDG04fjjS3qpQCI+/MsWDJ7sLqM1xKg2nXUOm/0HssokgProJhaFr+B5 cyCv1HXeyxdLFSwN/Vdsv78EKpjGoeqZPB8CuJh1zjeFJboA62AZt2u/KjqoIsLk5Es0 KXJjtycIwhQrOSMkqXWmPwcSemeCYUSrAbu3v4q23yaZQezRqayRriOmagXXi/E5zg9i 3UfbNI3g1NF7rw78GnGj2n9wXDfPKtF1tTL/eEbTYnEp2uFro3Gp/Ni2K/7gG7moH1uN PkRa6LKv9+r01Hi00GztsKMgu2dfebcxr3yQ2sfdXRTwc5t9a171m7xsCCrumJndfsnX myKw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=g07la02V; 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=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id v7si8025475jal.113.2021.05.29.00.35.40; Sat, 29 May 2021 00:35:53 -0700 (PDT) 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=@gmail.com header.s=20161025 header.b=g07la02V; 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=QUARANTINE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229642AbhE2HdY (ORCPT + 99 others); Sat, 29 May 2021 03:33:24 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:58906 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229549AbhE2HdW (ORCPT ); Sat, 29 May 2021 03:33:22 -0400 Received: from mail-pj1-x1035.google.com (mail-pj1-x1035.google.com [IPv6:2607:f8b0:4864:20::1035]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id D3F9AC061574 for ; Sat, 29 May 2021 00:31:45 -0700 (PDT) Received: by mail-pj1-x1035.google.com with SMTP id o17-20020a17090a9f91b029015cef5b3c50so5795802pjp.4 for ; Sat, 29 May 2021 00:31:45 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=subject:to:cc:references:from:message-id:date:user-agent :mime-version:in-reply-to:content-language:content-transfer-encoding; bh=S8hnKQslTlCFAXMU0SU12N+3wAln8HGC0k1kgerLe04=; b=g07la02VDigfQGfYXusUErVBXEqW/nfiNlA6+fhu+MDLl8T9bRG86a5I52sQrawM5f p8EKm0gxCqX8GVdxztfGa0CPWuTyVDV2FNHQj2kx/2rNeOSam+uVeGF2GtkbGL/DEzWg YKVS4/T4mNmc1g/yF5LIIqMsrNDNT8V1B6V9VlXG2VwjOxlZdPhj2slDSphOR9UpXNrH 82OLTi+9oS3QDig9OO5wI5Ywo9UlDk2mIChqUjMjNph8OwbdBJHhPDyJa3jv1od9/LAA yNK9Vsv+jEk2fFMJlL2DL2z/Q7e08an9YPBfjjCEYTku17T9Z3hAlKk9WNhaQXMELqW2 T8YA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:subject:to:cc:references:from:message-id:date :user-agent:mime-version:in-reply-to:content-language :content-transfer-encoding; bh=S8hnKQslTlCFAXMU0SU12N+3wAln8HGC0k1kgerLe04=; b=DgePXavN2TLHd2DXePv2EN4MONjZoKF381zMW1I6ZxUMf/KHIX9oWHwQKwKthekfGq sWcbQnlzQ0GrTozG4arrRkVyOddGePJYwKQ9yhc53zaQcxDim3kwb/1XkPsP4TnqbJOb u6Cy1AjSOyoEtrvRW/WA3YJ+m8BXy/V2lFasGQ5nPSjigAh+rueez3clEcGLd4/mPmWs 3B2WfBhPZUBdweUgqCLW54hkivVcnbBZvZOV8IBvwL+LQBs+8mloeE2dDIRGAUKD1gVH h9D3c3ytIS76tWszvjZ2fKBJGhrgom/ycY8y64Xki7ak6XlutN6BK9jcTDHC/CVi6DIR 1QkA== X-Gm-Message-State: AOAM530y/ZL1ZoA++MJKgYfR/WohYVwqzul5uM/bY6Haq1rLa+haHEx3 YQuAyrT9qGUWaG/kSq7sNHi17JwFaIsPqgo6 X-Received: by 2002:a17:90a:5995:: with SMTP id l21mr8404304pji.79.1622273505234; Sat, 29 May 2021 00:31:45 -0700 (PDT) Received: from ?IPv6:2601:647:5380:8c0:858e:9ae5:3ea5:20eb? ([2601:647:5380:8c0:858e:9ae5:3ea5:20eb]) by smtp.gmail.com with ESMTPSA id t19sm6195113pfg.70.2021.05.29.00.31.40 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Sat, 29 May 2021 00:31:44 -0700 (PDT) Subject: Re: Sealed memfd & no-fault mmap To: Linus Torvalds , Hugh Dickins Cc: Simon Ser , Peter Xu , "Kirill A. Shutemov" , Matthew Wilcox , Dan Williams , "Kirill A. Shutemov" , Will Deacon , Linux Kernel Mailing List , David Herrmann , "linux-mm@kvack.org" , Greg Kroah-Hartman , "tytso@mit.edu" References: <20210429154807.hptls4vnmq2svuea@box> <20210429183836.GF8339@xz-x1> <7718ec5b-0a9e-ffa6-16f2-bc0b6afbd9ab@gmail.com> From: "Lin, Ming" Message-ID: <80c87e6b-6050-bf23-2185-ded408df4d0f@gmail.com> Date: Sat, 29 May 2021 00:31:39 -0700 User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:78.0) Gecko/20100101 Thunderbird/78.10.2 MIME-Version: 1.0 In-Reply-To: Content-Type: text/plain; charset=utf-8; format=flowed Content-Language: en-US Content-Transfer-Encoding: 7bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On 5/28/2021 6:03 PM, Linus Torvalds wrote: > On Fri, May 28, 2021 at 7:07 AM Lin, Ming wrote: >> >> Does something like following draft patch on the right track? > > No, I don't think this can work: > >> + _dst_pte = pte_mkspecial(pfn_pte(my_zero_pfn(dst_addr), >> + vma->vm_page_prot)); > > You can't just blindly insert the zero pfn - for a shared write > mapping, that would actually allow writes to the zeropage. That would > be horrible. I should check the vma is not writable. diff --git a/mm/shmem.c b/mm/shmem.c index 856d2d8d4cdf..fa23e38bc692 100644 --- a/mm/shmem.c +++ b/mm/shmem.c @@ -1820,7 +1820,7 @@ static int shmem_getpage_gfp(struct inode *inode, pgoff_t index, spinlock_t *ptl; int ret; - if (!IS_NOFAULT(inode)) + if (!IS_NOFAULT(inode) || (vma->vm_flags & VM_WRITE)) return -EINVAL; _dst_pte = pte_mkspecial(pfn_pte(my_zero_pfn(dst_addr)