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=-16.4 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_CR_TRAILER,INCLUDES_PATCH,MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS autolearn=ham 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 6C997C433ED for ; Mon, 3 May 2021 22:24:44 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id F00BF61157 for ; Mon, 3 May 2021 22:24:43 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org F00BF61157 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=redhat.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=owner-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix) id 873726B0036; Mon, 3 May 2021 18:24:43 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 849BB6B0071; Mon, 3 May 2021 18:24:43 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 6EACC6B0072; Mon, 3 May 2021 18:24:43 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0093.hostedemail.com [216.40.44.93]) by kanga.kvack.org (Postfix) with ESMTP id 563266B0036 for ; Mon, 3 May 2021 18:24:43 -0400 (EDT) Received: from smtpin18.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay04.hostedemail.com (Postfix) with ESMTP id 1BF268790 for ; Mon, 3 May 2021 22:24:43 +0000 (UTC) X-FDA: 78101350446.18.A1F6DBC Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by imf06.hostedemail.com (Postfix) with ESMTP id 702BBC0007C4 for ; Mon, 3 May 2021 22:24:44 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1620080682; 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: in-reply-to:in-reply-to:references:references; bh=jfXlABNT0XMdR0g/quQP485ZWtoQvq/HkgRK7ZDKv9o=; b=czIxfw0FhF4Y/HKL/cP0b4qgVn4zf2dHRJ12+VdyAe0gKbaGhVYIHpE1x47uyUbNBKxqhS chxnVw8/z1hRkzhcMMD+X6cZKAtqlY0QWxpJgzePykT2VUwEjsl9mKm1YHQXZK5BpI25gW bX+sbubaEBKCbhiWzPs7KJ3gWg6nQHw= Received: from mail-qk1-f197.google.com (mail-qk1-f197.google.com [209.85.222.197]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-518-UOkYnvCdPJCnuWEvOxZhDg-1; Mon, 03 May 2021 18:24:40 -0400 X-MC-Unique: UOkYnvCdPJCnuWEvOxZhDg-1 Received: by mail-qk1-f197.google.com with SMTP id g184-20020a3784c10000b02902e385de9adaso6251318qkd.3 for ; Mon, 03 May 2021 15:24:40 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:from:to:cc:subject:message-id:references :mime-version:content-disposition:in-reply-to; bh=jfXlABNT0XMdR0g/quQP485ZWtoQvq/HkgRK7ZDKv9o=; b=qEjl5w0yDSLjxzv87LixrnZmmXNU1E0Tg15b5gLg1DoUkxxSkXn/O6Mk2yEaj+igw9 hpNkC9OrGzx6aD0/o074DeEJi+8s6gDNFMadkMgpbKnXqYwiqGctKhD7Zr5y/sOwElef SdCLre91IA1/y5HnwF3Xi9B6AiA9UpmKRkhI+LHGbFe/fHauryaKv1PaVTktdIwzZ9/i 7rlEVILpNl+TbJPMx2mdc1QCSeqIDfg4XsNbP4Z2Hqs6WjGHjPHba8EbG2coMUzIaL87 +JKEZ7rupAAwISx8r9YFi8AegX6TPw3hbzDL6UllvchZ6PSd3XXjDRCJBACU25bRUSNt Ah8Q== X-Gm-Message-State: AOAM532tOJFwIl/0arnZLEgYsZQw1MoQ0OnpQ95B/YBv1ZXAmgaHEcom PZl/w3I2Fy+ynBQ5QYqjmOr+UGcHQRUt5SNIYBJDFGZV3lKKp7AO5frI0MuJnu1ePURKsEGWMCa mmqnGdOH4lvM= X-Received: by 2002:ac8:794a:: with SMTP id r10mr6978090qtt.269.1620080680259; Mon, 03 May 2021 15:24:40 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxVZ4Mb52E5DKFssQjCxbqFKR7FfysyNzYLDwdTFRUFL6hA2eyD9w5BXrKbwWLIcLnyESj7qA== X-Received: by 2002:ac8:794a:: with SMTP id r10mr6978064qtt.269.1620080679984; Mon, 03 May 2021 15:24:39 -0700 (PDT) Received: from t490s (bras-base-toroon474qw-grc-72-184-145-4-219.dsl.bell.ca. [184.145.4.219]) by smtp.gmail.com with ESMTPSA id 189sm6971846qkh.99.2021.05.03.15.24.38 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 03 May 2021 15:24:39 -0700 (PDT) Date: Mon, 3 May 2021 18:24:38 -0400 From: Peter Xu To: Mike Kravetz Cc: linux-mm@kvack.org, linux-kernel@vger.kernel.org, Hugh Dickins , Andrew Morton , Andrea Arcangeli , Axel Rasmussen Subject: Re: [PATCH 2/2] mm/hugetlb: Fix cow where page writtable in child Message-ID: References: <20210501144110.8784-1-peterx@redhat.com> <20210501144110.8784-3-peterx@redhat.com> MIME-Version: 1.0 In-Reply-To: X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Type: text/plain; charset=utf-8 Content-Disposition: inline Authentication-Results: imf06.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=czIxfw0F; spf=none (imf06.hostedemail.com: domain of peterx@redhat.com has no SPF policy when checking 170.10.133.124) smtp.mailfrom=peterx@redhat.com; dmarc=pass (policy=none) header.from=redhat.com X-Rspamd-Server: rspam03 X-Rspamd-Queue-Id: 702BBC0007C4 X-Stat-Signature: i8rbbtqjsi48t6fisgp4beppwpsnup8q Received-SPF: none (redhat.com>: No applicable sender policy available) receiver=imf06; identity=mailfrom; envelope-from=""; helo=us-smtp-delivery-124.mimecast.com; client-ip=170.10.133.124 X-HE-DKIM-Result: pass/pass X-HE-Tag: 1620080684-222630 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 Mon, May 03, 2021 at 03:10:04PM -0700, Mike Kravetz wrote: > On 5/3/21 2:41 PM, Peter Xu wrote: > > On Mon, May 03, 2021 at 01:53:03PM -0700, Mike Kravetz wrote: > >> On 5/1/21 7:41 AM, Peter Xu wrote: > >>> When fork() and copy hugetlb page range, we'll remember to wrprotect src pte if > >>> needed, however we forget about the child! Without it, the child will be able > >>> to write to parent's pages when mapped as PROT_READ|PROT_WRITE and MAP_PRIVATE, > >>> which will cause data corruption in the parent process. > >>> > >>> This issue can also be exposed by "memfd_test hugetlbfs" kselftest (if it can > >>> pass the F_SEAL_FUTURE_WRITE test first, though). > >>> > >>> Signed-off-by: Peter Xu > >>> --- > >>> mm/hugetlb.c | 2 ++ > >>> 1 file changed, 2 insertions(+) > >> > >> Reviewed-by: Mike Kravetz > > > > Thanks! > > > >> > >> I think we need to add, "Fixes: 4eae4efa2c29" as this is now in v5.12 > > > > I could be mistaken, but my understanding is it's broken from the most initial > > cow support of hugetlbfs in 2006... So if we want a fixes tag, maybe this? > > > > Fixes: 1e8f889b10d8d ("[PATCH] Hugetlb: Copy on Write support") > > > > Here is why I think it was broken in 4eae4efa2c29. Prior to that commit > the code looked like this: > > if (cow) { > /* > * No need to notify as we are downgrading page > * table protection not changing it to point > * to a new page. > * > * See Documentation/vm/mmu_notifier.rst > */ > huge_ptep_set_wrprotect(src, addr, src_pte); > } > entry = huge_ptep_get(src_pte); > ptepage = pte_page(entry); > get_page(ptepage); > page_dup_rmap(ptepage, true); > set_huge_pte_at(dst, addr, dst_pte, entry); > hugetlb_count_add(pages_per_huge_page(h), dst); > > After setting the wrprotect in the source pte, we 'huge_ptep_get' the > source to create the destination. Hence, wrprotect will be set in the > destination as well. It is perhaps not the most efficient, but > I think it 'works'. > > It is subtle, or am I missing something? You're right, thanks Mike. I'll repost and add correct fixes tag. -- Peter Xu