From patchwork Wed Dec 14 20:04:52 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Peter Xu X-Patchwork-Id: 13073492 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 DC9C0C001B2 for ; Wed, 14 Dec 2022 20:05:05 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 7E36E8E0014; Wed, 14 Dec 2022 15:05:05 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 76DCA8E0002; Wed, 14 Dec 2022 15:05:05 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 5737E8E0014; Wed, 14 Dec 2022 15:05:05 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0013.hostedemail.com [216.40.44.13]) by kanga.kvack.org (Postfix) with ESMTP id 3B3F38E0002 for ; Wed, 14 Dec 2022 15:05:05 -0500 (EST) Received: from smtpin14.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay07.hostedemail.com (Postfix) with ESMTP id B910C160F5E for ; Wed, 14 Dec 2022 20:05:02 +0000 (UTC) X-FDA: 80241990444.14.F05030B Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by imf02.hostedemail.com (Postfix) with ESMTP id C67EB80009 for ; Wed, 14 Dec 2022 20:05:00 +0000 (UTC) Authentication-Results: imf02.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b="evzzPs/W"; spf=pass (imf02.hostedemail.com: domain of peterx@redhat.com designates 170.10.133.124 as permitted sender) smtp.mailfrom=peterx@redhat.com; dmarc=pass (policy=none) header.from=redhat.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1671048300; h=from:from:sender: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:dkim-signature; bh=OjnVrIvGwtoddEojvu7v3r8jpkJLbQV8Ta0gkZnxU7g=; b=6x9XDHX08FGQ0c8kbCSZTB4l881fu4Cg9bjxhx/jPKQ7HlHWNKHriP1sUAwzA6JnvXmCoD G7YL6HV2pUA/Mbnj1GaBI322GoS/FvXO5vGGkvY9oMnifx5+knL0/jNAluvFpbMHyq6ARP qpF3fTJ2J4AoQB3Nfq7qLzb3s7mQFAw= ARC-Authentication-Results: i=1; imf02.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b="evzzPs/W"; spf=pass (imf02.hostedemail.com: domain of peterx@redhat.com designates 170.10.133.124 as permitted sender) smtp.mailfrom=peterx@redhat.com; dmarc=pass (policy=none) header.from=redhat.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1671048300; a=rsa-sha256; cv=none; b=MgOehYGghVsjLOtbXMzAn5CREfjDVOifIKVSqzViSeW0LqCy4VEkYxpI0Ads63a2hNO9iT 1bhrYOpFhIYDyII1AAYJlgA2mkpgp7BX44AEgsi6D2ohB5EXNdW9oIuuFinfHnN3ZFbxVu V1vgz5r252xMoUa6jQPI+NA4VLgTy9U= DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1671048300; 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=OjnVrIvGwtoddEojvu7v3r8jpkJLbQV8Ta0gkZnxU7g=; b=evzzPs/WKBueagFhMrOu8+U594VoiwTwypnbb8GDIT/N71YFMYUTEdiVI9LgVu2zLfbsWu RxSIRLfuRoRM79PSaIKGiOQQRPSQxp0oQbj6CugdMKSDnmmdOq142PEjXN9sHRJEuQIoe2 on2kBsoz8eri41nLFxeYkAl1u260cUU= Received: from mail-qt1-f199.google.com (mail-qt1-f199.google.com [209.85.160.199]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_128_GCM_SHA256) id us-mta-638-yMXl1ScgO7GbbPCGol_8zg-1; Wed, 14 Dec 2022 15:04:58 -0500 X-MC-Unique: yMXl1ScgO7GbbPCGol_8zg-1 Received: by mail-qt1-f199.google.com with SMTP id i3-20020ac87643000000b003a816421776so3094884qtr.22 for ; Wed, 14 Dec 2022 12:04:58 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=OjnVrIvGwtoddEojvu7v3r8jpkJLbQV8Ta0gkZnxU7g=; b=k9tEHTvBRbiLWBgDd15i4jsyZ4QFmeUaAw361c461w3JKAA4OLXKVK3lGQTqntKDuJ LQdkk6Dcl7hmgza/r1JOLReEiWlGtwXuQSyeq8Ia5WLsf5/FS5EwfNlDa4PP377LbGxy rHnPEn2vVAhnca+YQkLsesN0/Vpyq1nCNSyqwXFG8anKv08T0nLmaRRkbcBrjfa7LjaQ V9FkV+DS+cHGEwMybURYd+zkN/DVxa05I6iV3XT21vR3FN53hhRQHsXj4XIrqVu38UVL X3lMWjY0nsNYqB0JIUKe+9JWIcDeydQ4i0o4mGe4uUZdzXdEKMtOjc1pQzOWk4h7sVM6 AppA== X-Gm-Message-State: ANoB5pkYDfdOk/IwSSPJJ67GXnTLSuM5HwnZtUyohjPncTOnL5y+PNUp JRVobUfABfQM1gbcFya8Q+srYXNA6E9GkO00aw16M9ivuOmRyxWlYJuZnbP5eFdzL+MQn523rBx aLla0uzeHXyI= X-Received: by 2002:ac8:7a92:0:b0:3a8:234a:3204 with SMTP id x18-20020ac87a92000000b003a8234a3204mr11410971qtr.23.1671048298360; Wed, 14 Dec 2022 12:04:58 -0800 (PST) X-Google-Smtp-Source: AA0mqf6Nke0YvpERN8PSGIEPS7iAy63OPrfTbIIMSElRjL9bJJczmgiRGIt2KezRj+ugUt12mbA1aQ== X-Received: by 2002:ac8:7a92:0:b0:3a8:234a:3204 with SMTP id x18-20020ac87a92000000b003a8234a3204mr11410949qtr.23.1671048298123; Wed, 14 Dec 2022 12:04:58 -0800 (PST) Received: from x1n.redhat.com (bras-base-aurron9127w-grc-45-70-31-26-132.dsl.bell.ca. [70.31.26.132]) by smtp.gmail.com with ESMTPSA id l11-20020ac848cb000000b003a689a5b177sm2199352qtr.8.2022.12.14.12.04.56 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 14 Dec 2022 12:04:57 -0800 (PST) From: Peter Xu To: linux-kernel@vger.kernel.org, linux-mm@kvack.org Cc: Andrea Arcangeli , Pengfei Xu , peterx@redhat.com, Nadav Amit , David Hildenbrand , Andrew Morton , Miaohe Lin , Huang Ying , stable@vger.kernel.org Subject: [PATCH 1/2] mm/uffd: Fix pte marker when fork() without fork event Date: Wed, 14 Dec 2022 15:04:52 -0500 Message-Id: <20221214200453.1772655-2-peterx@redhat.com> X-Mailer: git-send-email 2.37.3 In-Reply-To: <20221214200453.1772655-1-peterx@redhat.com> References: <20221214200453.1772655-1-peterx@redhat.com> MIME-Version: 1.0 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-type: text/plain X-Rspamd-Server: rspam07 X-Rspamd-Queue-Id: C67EB80009 X-Rspam-User: X-Stat-Signature: yn9pe36udn7do93k1ne1e9g5zronzds9 X-HE-Tag: 1671048300-95277 X-HE-Meta: U2FsdGVkX19qPpqu079QoTvVeVwCvVEs/xtyQLg2E6Mh0BTMYFzQ0/HpAU9W5jn1UBYIU6D0eusRUEPiUS+M2lGNB9A1xJamxj1yi/zJuUIC3Ep0A91NRHE0NR0S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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: When fork(), dst_vma is not guaranteed to have VM_UFFD_WP even if src may have it and has pte marker installed. The warning is improper along with the comment. The right thing is to inherit the pte marker when needed, or keep the dst pte empty. A vague guess is this happened by an accident when there's the prior patch to introduce src/dst vma into this helper during the uffd-wp feature got developed and I probably messed up in the rebase, since if we replace dst_vma with src_vma the warning & comment it all makes sense too. Hugetlb did exactly the right here (copy_hugetlb_page_range()). Fix the general path. Reproducer: https://github.com/xupengfe/syzkaller_logs/blob/main/221208_115556_copy_page_range/repro.c Cc: # 5.19+ Fixes: c56d1b62cce8 ("mm/shmem: handle uffd-wp during fork()") Bugzilla: https://bugzilla.kernel.org/show_bug.cgi?id=216808 Reported-by: Pengfei Xu Signed-off-by: Peter Xu Acked-by: David Hildenbrand Reviewed-by: Miaohe Lin --- mm/memory.c | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-) diff --git a/mm/memory.c b/mm/memory.c index aad226daf41b..032ef700c3e8 100644 --- a/mm/memory.c +++ b/mm/memory.c @@ -828,12 +828,8 @@ copy_nonpresent_pte(struct mm_struct *dst_mm, struct mm_struct *src_mm, return -EBUSY; return -ENOENT; } else if (is_pte_marker_entry(entry)) { - /* - * We're copying the pgtable should only because dst_vma has - * uffd-wp enabled, do sanity check. - */ - WARN_ON_ONCE(!userfaultfd_wp(dst_vma)); - set_pte_at(dst_mm, addr, dst_pte, pte); + if (userfaultfd_wp(dst_vma)) + set_pte_at(dst_mm, addr, dst_pte, pte); return 0; } if (!userfaultfd_wp(dst_vma))