Received: by 2002:a6b:500f:0:0:0:0:0 with SMTP id e15csp999805iob; Fri, 13 May 2022 19:09:02 -0700 (PDT) X-Google-Smtp-Source: ABdhPJz/t2iA1WYzxaU5g6anNzDT1nzG9S2KIuJcf+QGFNNXSSWnoZJs72X6aOfUUngkjaJImcZr X-Received: by 2002:a1c:2b86:0:b0:392:ae97:2fec with SMTP id r128-20020a1c2b86000000b00392ae972fecmr6760741wmr.165.1652494141997; Fri, 13 May 2022 19:09:01 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1652494141; cv=none; d=google.com; s=arc-20160816; b=SrngvAyLvXLTQWSczX6YBVaAo7RlB/9x4U6DinRf1NY1HhlXy+XzlU+GXAX8VACHZr O8os3+2suovGDxrrMgG7uETtqXRLIVWkLMRFvUEKTS21l9EWBUiqR2Hy/C2yAfFddzKk FC+zLGhw7bOviZUFkv/OmaiVVysNQU2kOdktdeHPTPaGOQyTFznsHGUu4kUSfVuVJfJZ Mz8ApWcq7gaAI+9OBM621NTluXwTmeOI1pq3/7Ci3ZZE0YgEvoM4GIcrCjUpy8yKkbBl fd46/hVkPiWfBEEgu+2KbSd+XyuwpteMvHwcvrOLr8rAuEb7rX0Uej+OOgpz/au/rLvi bncg== 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=ej2gmdntaCE2R5H0uTUOOpoQxhEsF415I0ZFckw96wg=; b=yELZlzv4/O5zgyuj4xo3eKPzvUEGJHW5fdEHMRW9Wzk2edWUUcVG7sqvD1/AwS1JR6 fjFD8OnYrRCYhAyeDG3dNehIyglI6kuSEu2ByZ7rggbbEiOXW4jW+nD8IBvmf1sasux/ wr4nbZdsWbPNaXZbn03nnjurr7Po71N24H2IMISt7iffL8UUrrVbecprzjjzIlzydOLm cBPX6/2KLsDq+HZ7jkrKl9UrzHbF3AG1JENN/TDWhqw6wDrCJ3XK4CToi9cnG3ydUlkr ktmPEStMgYhbI0HCihH0KC9EeoVJ2aj9yj3Y8K7H9MvOuFyMT8mQPUD6asQFFwY4HOoV gQQQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b="IGVnrf/G"; spf=softfail (google.com: domain of transitioning linux-kernel-owner@vger.kernel.org does not designate 23.128.96.19 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 lindbergh.monkeyblade.net (lindbergh.monkeyblade.net. [23.128.96.19]) by mx.google.com with ESMTPS id q5-20020a7bce85000000b00393ea849690si6622002wmj.203.2022.05.13.19.09.01 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 13 May 2022 19:09:01 -0700 (PDT) Received-SPF: softfail (google.com: domain of transitioning linux-kernel-owner@vger.kernel.org does not designate 23.128.96.19 as permitted sender) client-ip=23.128.96.19; Authentication-Results: mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b="IGVnrf/G"; spf=softfail (google.com: domain of transitioning linux-kernel-owner@vger.kernel.org does not designate 23.128.96.19 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id 669C2491B43; Fri, 13 May 2022 17:28:28 -0700 (PDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1381498AbiEMOb2 (ORCPT + 99 others); Fri, 13 May 2022 10:31:28 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:40056 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1380910AbiEMO0P (ORCPT ); Fri, 13 May 2022 10:26:15 -0400 Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 279D951318; Fri, 13 May 2022 07:25:48 -0700 (PDT) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by dfw.source.kernel.org (Postfix) with ESMTPS id B7D3962159; Fri, 13 May 2022 14:25:47 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 90954C34115; Fri, 13 May 2022 14:25:46 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1652451947; bh=uzEHjHDWLguBXYjfTqs0u3kFAhT29DbpDmBLr/hjc1E=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=IGVnrf/GlZMe7iJJQfNwZKoSAcurS94cL0Q0NSXFikZYZMjjtGLWjAI2izu/+hFA8 OmJMZQ173EiICKYeukNCCTQmqKCNM4/8w8PmPyW7e3K9o1w0IKXLMAh/mT7MSiEk17 qOzOdB7UQ7kiPd9wssUf+e3UzgOMtdouGMlxxnlI= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Muchun Song , Axel Rasmussen , David Rientjes , Fam Zheng , "Kirill A. Shutemov" , Lars Persson , Mike Kravetz , Peter Xu , Xiongchun Duan , Zi Yan , Andrew Morton , Linus Torvalds Subject: [PATCH 4.19 14/15] mm: userfaultfd: fix missing cache flush in mcopy_atomic_pte() and __mcopy_atomic() Date: Fri, 13 May 2022 16:23:36 +0200 Message-Id: <20220513142228.318854560@linuxfoundation.org> X-Mailer: git-send-email 2.36.1 In-Reply-To: <20220513142227.897535454@linuxfoundation.org> References: <20220513142227.897535454@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-2.6 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,RDNS_NONE,SPF_HELO_NONE,T_SCC_BODY_TEXT_LINE autolearn=unavailable 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 From: Muchun Song commit 7c25a0b89a487878b0691e6524fb5a8827322194 upstream. 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. Link: https://lkml.kernel.org/r/20220210123058.79206-7-songmuchun@bytedance.com 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 Cc: Axel Rasmussen Cc: David Rientjes Cc: Fam Zheng Cc: Kirill A. Shutemov Cc: Lars Persson Cc: Mike Kravetz Cc: Peter Xu Cc: Xiongchun Duan Cc: Zi Yan Signed-off-by: Andrew Morton Signed-off-by: Linus Torvalds Signed-off-by: Greg Kroah-Hartman --- mm/userfaultfd.c | 3 +++ 1 file changed, 3 insertions(+) --- a/mm/userfaultfd.c +++ b/mm/userfaultfd.c @@ -55,6 +55,8 @@ static int mcopy_atomic_pte(struct mm_st /* don't free the page */ goto out; } + + flush_dcache_page(page); } else { page = *pagep; *pagep = NULL; @@ -574,6 +576,7 @@ retry: err = -EFAULT; goto out; } + flush_dcache_page(page); goto retry; } else BUG_ON(page);