Received: by 2002:a05:6a10:1a4d:0:0:0:0 with SMTP id nk13csp3085194pxb; Thu, 10 Feb 2022 11:54:47 -0800 (PST) X-Google-Smtp-Source: ABdhPJzdAKHOWm4l8eRE2neSsFwQhloEUJSOeXS51wAptflIM3ROGKuTerydpVpvC1KmncY8I+9q X-Received: by 2002:a05:6402:1769:: with SMTP id da9mr9992385edb.376.1644522886891; Thu, 10 Feb 2022 11:54:46 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1644522886; cv=none; d=google.com; s=arc-20160816; b=F/S0F5ZhCj5VdPgIio1ISYO/XvReSAap1UA1CMWBpYc3GYsFr8zwzzHezUsF3Hjk5E mMpjf/D9COjSyAA0S6Dnbq46kRHvsvoCpCEmlhx2WAWXVVwxE/WVmsIa3CFla2/rpE8G 479GygI6OLVw8N3O8wLxVlFHUym8acMWcY+XBtZU2DhEUioNub9cwLEZjrqk+KbHYCX/ 0atXwo3ZLfeSEyd2czopu15PP8SPujembzXhIjqPEKDDmRwcH1FAMQTU1Ia6YHC4XacC l1+e2ENRVqUW3CjKiN9p2LtJsGNdlYWwUSRT6gUobFCzU4oh570rJVnurpHEVY36ex0j iJPg== 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 :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=kGvpK6UTEMeGdDCg9a68QTimGRB3Wg5V4hLO/H8ovOk=; b=iHoOnkE/q2uI8In1rOoGmkbjNzX0pRGiXhT4zPUOjTZzsz3PmvZV84vA3kVQmnUxpO qSa+WawG8HTRIvVHIv7XXHIXYCqFMnehBJQ3CpRCm39j72gbn9hKhaoaa9KL/ggj+qDl 09MpCy+5ZL832d38tlyvnulgB9e/b31LfGVkNFSafT2IYRJ2tblkZ9WzLvkrKaERJTe6 BdsiKUqlQpZunOMKWdDqG/skw5FlisP3sEvS+HL2JUtI/K7RPSE5ypxV3RWc5LWvM9T9 YesMZaEg+/cK0PbpqmGnCI9xTuRlD3Eshj3QCWI76alJ3S3ikREA+VmTHoY0l+L+uP0G RZCQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@bytedance-com.20210112.gappssmtp.com header.s=20210112 header.b=8R2KQc0V; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=bytedance.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id i4si16575907edc.196.2022.02.10.11.54.22; Thu, 10 Feb 2022 11:54:46 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@bytedance-com.20210112.gappssmtp.com header.s=20210112 header.b=8R2KQc0V; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=bytedance.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S241645AbiBJMhu (ORCPT + 99 others); Thu, 10 Feb 2022 07:37:50 -0500 Received: from mxb-00190b01.gslb.pphosted.com ([23.128.96.19]:55346 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S240214AbiBJMhr (ORCPT ); Thu, 10 Feb 2022 07:37:47 -0500 Received: from mail-pf1-x433.google.com (mail-pf1-x433.google.com [IPv6:2607:f8b0:4864:20::433]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id CAAB5DF5 for ; Thu, 10 Feb 2022 04:37:48 -0800 (PST) Received: by mail-pf1-x433.google.com with SMTP id x15so7547782pfr.5 for ; Thu, 10 Feb 2022 04:37:48 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bytedance-com.20210112.gappssmtp.com; s=20210112; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=kGvpK6UTEMeGdDCg9a68QTimGRB3Wg5V4hLO/H8ovOk=; b=8R2KQc0VHwfvgfFLuPp0xcs/i0bFi3ZpoOvzA4bg66nMtTPqQzqxTX+Hj1tWbZt+HU 01u5lq16jDHas70gMpnZO5BBiMuTF+W5pva0r6kivMj+a2RM3QWGQAUXznhUqBxpKPkf Vv/Tu1P5u0Zi/cQioKebx7XyAGlUXUXMibP1SqIBSj3UGsVQaJUelPy5p4+rwTHdnNhy imoRrsXIOlM97bvi9gNvPrSM9JSeP4ZkPvsAYpxNIA9hXjYHh50pMLoZIGcA0ttGpuMA Y/Xsnao5EZKEuqby/5+bnXTVOdcLa1PFjq8mBuhVnryqOZu7iQRstCzev9b3DNb+X1dy uUqA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=kGvpK6UTEMeGdDCg9a68QTimGRB3Wg5V4hLO/H8ovOk=; b=I8gk0jyGWPahOJo5fSOK72IWtfoKYVLUeDjoaT5p6u5E/Y3ZAl0V+0N891Ukjkmudd mRByGzFkLm+m1oCyc4CGBZ97TTPD35a1pSdoEoHOl5PUKIhUX3ha35d8DEfONrtV4QSg 4xqCAG/2af44cOrwo6WxhmoXWMEfG2jTA+NI4bYlQmYmwqeh+OxhIwiJNxFwPCt9DezB gtXMsYuR9QdmONLaiya4MEF6l8j3mFhanVvrs70NXR4dtObOAQmQ74+Eau50b+gf427h fH19UEkboW+mdINrCu1rXO6VyeBuXSgVX+C+nODwVQsJo7B86AuXMlo0wxv+oCg2Gcq6 GNMA== X-Gm-Message-State: AOAM530NmLw1DhSP/KRcTdw9EkWu+Y5RiKXtja00VMn+LdyFQDyJPyCG jy8OLnlPYP5pBPNWTkYropToJA== X-Received: by 2002:a63:4e0e:: with SMTP id c14mr6120150pgb.490.1644496668324; Thu, 10 Feb 2022 04:37:48 -0800 (PST) Received: from FVFYT0MHHV2J.tiktokcdn.com ([139.177.225.237]) by smtp.gmail.com with ESMTPSA id i8sm11767812pgf.94.2022.02.10.04.37.43 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 10 Feb 2022 04:37:48 -0800 (PST) From: Muchun Song To: akpm@linux-foundation.org, zi.yan@cs.rutgers.edu, kirill.shutemov@linux.intel.com, rientjes@google.com, lars.persson@axis.com, mike.kravetz@oracle.com, ziy@nvidia.com Cc: linux-mm@kvack.org, linux-kernel@vger.kernel.org, duanxiongchun@bytedance.com, fam.zheng@bytedance.com, Muchun Song Subject: [PATCH v5 6/7] mm: userfaultfd: fix missing cache flush in mcopy_atomic_pte() and __mcopy_atomic() Date: Thu, 10 Feb 2022 20:30:57 +0800 Message-Id: <20220210123058.79206-7-songmuchun@bytedance.com> X-Mailer: git-send-email 2.32.0 (Apple Git-132) In-Reply-To: <20220210123058.79206-1-songmuchun@bytedance.com> References: <20220210123058.79206-1-songmuchun@bytedance.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,RCVD_IN_DNSWL_NONE,SPF_HELO_NONE,SPF_NONE, T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org The userfaultfd calls mcopy_atomic_pte() and __mcopy_atomic() which do not do any cache flushing for the target page. Then the target page will be mapped to the user space with a different address (user address), which might have an alias issue with the kernel address used to copy the data from the user to. Fix this by insert flush_dcache_page() after copy_from_user() succeeds. Fixes: b6ebaedb4cb1 ("userfaultfd: avoid mmap_sem read recursion in mcopy_atomic") Fixes: c1a4de99fada ("userfaultfd: mcopy_atomic|mfill_zeropage: UFFDIO_COPY|UFFDIO_ZEROPAGE preparation") Signed-off-by: Muchun Song --- mm/userfaultfd.c | 3 +++ 1 file changed, 3 insertions(+) diff --git a/mm/userfaultfd.c b/mm/userfaultfd.c index 0780c2a57ff1..6ccc534d1c1c 100644 --- a/mm/userfaultfd.c +++ b/mm/userfaultfd.c @@ -150,6 +150,8 @@ static int mcopy_atomic_pte(struct mm_struct *dst_mm, /* don't free the page */ goto out; } + + flush_dcache_page(page); } else { page = *pagep; *pagep = NULL; @@ -625,6 +627,7 @@ static __always_inline ssize_t __mcopy_atomic(struct mm_struct *dst_mm, err = -EFAULT; goto out; } + flush_dcache_page(page); goto retry; } else BUG_ON(page); -- 2.11.0