Received: by 2002:ad5:474a:0:0:0:0:0 with SMTP id i10csp2001820imu; Fri, 14 Dec 2018 04:19:23 -0800 (PST) X-Google-Smtp-Source: AFSGD/VG32GGEReeMzKSdmfc2yV0VaZs3plnn/szgtEI3QTNCC4SB1m1FZm7Jnwx9OONB18uQvQD X-Received: by 2002:a62:69c4:: with SMTP id e187mr2688249pfc.50.1544789963019; Fri, 14 Dec 2018 04:19:23 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1544789962; cv=none; d=google.com; s=arc-20160816; b=k1/l6zeImTm1igtvVlpUMR5l8lL7b5kqzqbWY5RJbA5D0iFhKnuS+MU9zgamC6TjMq B9EnAJYXhm0Tf557R/BWFkk3WUAMCcSHyjhnYT++on2XBPeulfy1p+ImrHTKTE2s9cjl eGZypzY4AUWbp+8hNkZuCosLpm5/nnHI/21lXKCuoLsNl+aXwJgIlWr8exADsQNK4riR x8KpM4nvnJacBNnkM/x293Zb8xt1LoO56llCKCvhx0uBB/cn4OVdkTZspAnl8FrCVT2+ ghA6eFeQ16uBJ7g3ISyuYgJhwi4MroiLMOfZNYvh+CH+ZA/HQ5GoWjdNuhd7WZk7ksIZ gxUA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=p2LKLUy1fES+AC+sYctdAA2iBRDiIzk9DF7rSqE/DFI=; b=zuATB8DS+u1pw4nTKFvfj+VwVTHGmvprVY4eXmEa6MMU7etMxFiBcZxrn48hE3xlHN y4sJ/OOEEVJk2lGdRLTS1KC9pgdSZA+Ne7gCleHJy2jVa8mZzw66RUznPSrorLdshSMV lYV/f8WYj7chB5lKN+fEBSM1IsAwwgxn1SS/vyZw59mvbBd6eHD3ASN/vCsKnAyy/odO F91mGy2bF4Qvm/GU2qoSPxnhfrLAuqZ+U0+dgPKthhSH5Glb6i0XqVgdVgYvNEcvy4cU 18gArN8HlGDZFWl3atLB16qV6iXomlAN7iBoFM5MGCPp3ktfj/DiPzuXW57qTkAMwLs6 cjUw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=F4KzHyzo; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id t186si2035281pfd.68.2018.12.14.04.19.08; Fri, 14 Dec 2018 04:19:22 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=F4KzHyzo; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1732862AbeLNMRC (ORCPT + 99 others); Fri, 14 Dec 2018 07:17:02 -0500 Received: from mail.kernel.org ([198.145.29.99]:37202 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1732840AbeLNMQ5 (ORCPT ); Fri, 14 Dec 2018 07:16:57 -0500 Received: from localhost (5356596B.cm-6-7b.dynamic.ziggo.nl [83.86.89.107]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id 7DF22214C1; Fri, 14 Dec 2018 12:16:56 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1544789817; bh=zqn8TNlCjx0pGrXPIRxII2vEXmEDqvM5NYbICZw4L0M=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=F4KzHyzof8zeKhN3tRxH02dXgbYjHoP0t5aLlc16ce2vqgY/DU8EPbz/WdTOA+UJ8 7cnJGOqV2WDTPdJ0qaEPmuphUjwPJTSSrEEEFtFUG3nlTT4n8ogI11xYOqqIL4U4nk XJl7s5437P42yMgk/WM+5kb8Fv89sWy3hE829820= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Lorenzo Stoakes , Michal Hocko , Linus Torvalds , Ben Hutchings Subject: [PATCH 4.4 80/88] mm: replace __access_remote_vm() write parameter with gup_flags Date: Fri, 14 Dec 2018 13:00:54 +0100 Message-Id: <20181214115708.714280836@linuxfoundation.org> X-Mailer: git-send-email 2.20.0 In-Reply-To: <20181214115702.151309521@linuxfoundation.org> References: <20181214115702.151309521@linuxfoundation.org> User-Agent: quilt/0.65 X-stable: review X-Patchwork-Hint: ignore MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 4.4-stable review patch. If anyone has any objections, please let me know. ------------------ From: Lorenzo Stoakes commit 442486ec1096781c50227b73f721a63974b0fdda upstream. This removes the 'write' argument from __access_remote_vm() and replaces it with 'gup_flags' as use of this function previously silently implied FOLL_FORCE, whereas after this patch callers explicitly pass this flag. We make this explicit as use of FOLL_FORCE can result in surprising behaviour (and hence bugs) within the mm subsystem. Signed-off-by: Lorenzo Stoakes Acked-by: Michal Hocko Signed-off-by: Linus Torvalds [bwh: Backported to 4.4: adjust context] Signed-off-by: Ben Hutchings Signed-off-by: Greg Kroah-Hartman --- mm/memory.c | 23 +++++++++++++++-------- mm/nommu.c | 9 ++++++--- 2 files changed, 21 insertions(+), 11 deletions(-) --- a/mm/memory.c +++ b/mm/memory.c @@ -3711,14 +3711,11 @@ EXPORT_SYMBOL_GPL(generic_access_phys); * given task for page fault accounting. */ static int __access_remote_vm(struct task_struct *tsk, struct mm_struct *mm, - unsigned long addr, void *buf, int len, int write) + unsigned long addr, void *buf, int len, unsigned int gup_flags) { struct vm_area_struct *vma; void *old_buf = buf; - unsigned int flags = FOLL_FORCE; - - if (write) - flags |= FOLL_WRITE; + int write = gup_flags & FOLL_WRITE; down_read(&mm->mmap_sem); /* ignore errors, just check how much was successfully transferred */ @@ -3728,7 +3725,7 @@ static int __access_remote_vm(struct tas struct page *page = NULL; ret = get_user_pages(tsk, mm, addr, 1, - flags, &page, &vma); + gup_flags, &page, &vma); if (ret <= 0) { #ifndef CONFIG_HAVE_IOREMAP_PROT break; @@ -3787,7 +3784,12 @@ static int __access_remote_vm(struct tas int access_remote_vm(struct mm_struct *mm, unsigned long addr, void *buf, int len, int write) { - return __access_remote_vm(NULL, mm, addr, buf, len, write); + unsigned int flags = FOLL_FORCE; + + if (write) + flags |= FOLL_WRITE; + + return __access_remote_vm(NULL, mm, addr, buf, len, flags); } /* @@ -3800,12 +3802,17 @@ int access_process_vm(struct task_struct { struct mm_struct *mm; int ret; + unsigned int flags = FOLL_FORCE; mm = get_task_mm(tsk); if (!mm) return 0; - ret = __access_remote_vm(tsk, mm, addr, buf, len, write); + if (write) + flags |= FOLL_WRITE; + + ret = __access_remote_vm(tsk, mm, addr, buf, len, flags); + mmput(mm); return ret; --- a/mm/nommu.c +++ b/mm/nommu.c @@ -1929,9 +1929,10 @@ void filemap_map_pages(struct vm_area_st EXPORT_SYMBOL(filemap_map_pages); static int __access_remote_vm(struct task_struct *tsk, struct mm_struct *mm, - unsigned long addr, void *buf, int len, int write) + unsigned long addr, void *buf, int len, unsigned int gup_flags) { struct vm_area_struct *vma; + int write = gup_flags & FOLL_WRITE; down_read(&mm->mmap_sem); @@ -1973,7 +1974,8 @@ static int __access_remote_vm(struct tas int access_remote_vm(struct mm_struct *mm, unsigned long addr, void *buf, int len, int write) { - return __access_remote_vm(NULL, mm, addr, buf, len, write); + return __access_remote_vm(NULL, mm, addr, buf, len, + write ? FOLL_WRITE : 0); } /* @@ -1991,7 +1993,8 @@ int access_process_vm(struct task_struct if (!mm) return 0; - len = __access_remote_vm(tsk, mm, addr, buf, len, write); + len = __access_remote_vm(tsk, mm, addr, buf, len, + write ? FOLL_WRITE : 0); mmput(mm); return len;