Received: by 2002:a05:6a10:206:0:0:0:0 with SMTP id 6csp3129091pxj; Mon, 17 May 2021 18:32:55 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyNdg6u9rnLNyl/73tEr/YOirIwPBoe8cAa6sWWc1S2xrZbsdxPS5Kxzdjhdl+gIRgfY/pY X-Received: by 2002:a5e:8a42:: with SMTP id o2mr2245827iom.144.1621301575746; Mon, 17 May 2021 18:32:55 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1621301575; cv=none; d=google.com; s=arc-20160816; b=WOP5t1Z5DCPrX3E+lj3K+ipK3sP5PLHosa7rWXXpjNYMVvPhS7Sbq0q5j3sVAmoWpf qImaQwd+JWY508skVV/zW0sF41qM8iR5zL2Roonfny5zqNH49XitLMyB41uE7rh6Xybk s2j46M7lBlH7FkXHzHjTfuNoJbKtz+OIUUKbnQTUjNChecMdiyLR5rlGj/Lxc+7/zMLj EnUqg2BNEGApFopBasqp4ftDoxpNbzO1OshLKa/8Dm7ml78w0dAZ59BYLGmKY1b713wV mPoJ2S0dP1MjHBQobTOebPVXD/F+QYgBK40u0ConH3YroiVpBlAoAVyUmywKtf8cWxh+ qxcw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=NNWbtjsGh+CMG4uzWmtdxsNzajTGtoRbqYf0uxKvNAw=; b=Etzm5L36BVpFW4tXrDhpa7RkgW39jpixEKseNbUPFKxOX4+m8b6A8Bf1b3HSEvGzRJ 36ioteXm3JPi85nCmrmNXNUDbNpA/zhNYe5OsinHoGc7l+Gi8eEwZqx/W7guobmF5BHO fV+DUBoo6NtAkov/8z0GkCDzK5RWuzuOzg3l5z5wqa6Ot7JG/Nk/9IkL1m8ORGzS9AXv NpAlgnMB4UuigioHcqfmGYPUrYFzu+tSKehsnnxq+vCM6ukLf+Q/gJmF9krybpWQuexB IGIYmFs0MNm9e9T5uXisgAWkzjNcurQT4qQ3naRjmxhb0Gy7h9putz3EuxPv4+qsqqZM cIrQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b="R3/v6bY3"; 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=linuxfoundation.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id r2si20703290jak.13.2021.05.17.18.32.42; Mon, 17 May 2021 18:32:55 -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=@linuxfoundation.org header.s=korg header.b="R3/v6bY3"; 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=linuxfoundation.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S240528AbhEQOen (ORCPT + 99 others); Mon, 17 May 2021 10:34:43 -0400 Received: from mail.kernel.org ([198.145.29.99]:43164 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S239932AbhEQO3i (ORCPT ); Mon, 17 May 2021 10:29:38 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id 40BBE6162F; Mon, 17 May 2021 14:14:42 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1621260882; bh=jZg9Nfkp6NaT9j+pNjhQadU8Qkt9QEg7dV8blh+bJ6k=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=R3/v6bY3JWo7CJm5h0oI4Bwn5q1+xkN/fdbkGAYDbIp0ziF6tT34/Pq5jRQ0wyPNo 6S++9QzX0ezBbDwfXCx3nJmSaBH4Xd7VLqs3jo0o1jTiXGPRRYJySM0LWUnTkZFvGj /c68jcnLzF3wzXuqqUGMEn8UEjMXmNPZDcqJTgtY= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Peter Xu , Mike Kravetz , Hugh Dickins , "Joel Fernandes (Google)" , Andrew Morton , Linus Torvalds Subject: [PATCH 5.12 259/363] mm/hugetlb: fix cow where page writtable in child Date: Mon, 17 May 2021 16:02:05 +0200 Message-Id: <20210517140311.350695394@linuxfoundation.org> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20210517140302.508966430@linuxfoundation.org> References: <20210517140302.508966430@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Peter Xu commit 84894e1c42e9f25c17f2888e0c0e1505cb727538 upstream. When rework early cow of pinned hugetlb pages, we moved huge_ptep_get() upper but overlooked a side effect that the huge_ptep_get() will fetch the pte after wr-protection. After moving it upwards, we need explicit wr-protect of child pte or we will keep the write bit set in the child process, which could cause data corrution where the child can write to the original page directly. This issue can also be exposed by "memfd_test hugetlbfs" kselftest. Link: https://lkml.kernel.org/r/20210503234356.9097-3-peterx@redhat.com Fixes: 4eae4efa2c299 ("hugetlb: do early cow when page pinned on src mm") Signed-off-by: Peter Xu Reviewed-by: Mike Kravetz Cc: Hugh Dickins Cc: Joel Fernandes (Google) Cc: Signed-off-by: Andrew Morton Signed-off-by: Linus Torvalds Signed-off-by: Greg Kroah-Hartman --- mm/hugetlb.c | 1 + 1 file changed, 1 insertion(+) --- a/mm/hugetlb.c +++ b/mm/hugetlb.c @@ -3905,6 +3905,7 @@ again: * See Documentation/vm/mmu_notifier.rst */ huge_ptep_set_wrprotect(src, addr, src_pte); + entry = huge_pte_wrprotect(entry); } page_dup_rmap(ptepage, true);