Received: by 2002:a05:6a10:1287:0:0:0:0 with SMTP id d7csp4458830pxv; Tue, 27 Jul 2021 07:54:00 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwxCbdXDGjPb8GK2AFuuPViqINhbChY6hPtoP33CsiwMHtgg9kTlTYoc5h4JZBKB2+b2EZj X-Received: by 2002:a17:907:7e89:: with SMTP id qb9mr9391115ejc.333.1627397640056; Tue, 27 Jul 2021 07:54:00 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1627397640; cv=none; d=google.com; s=arc-20160816; b=hQEn4IjiUzBT4snGbIInT7cQpf1j/12qMVBHPVH4qvMOY98wVACaCLoQDalR92JEGb byKtq/VNeRY+mzjH4VB7r1Yjk6B1LFZ34Vr623HqiO59ghOwhitaXPwn0eOjodDd8MUy dZmbwRAw3wBLjK99V7b5meMilTjFffJJSBveiaAI5M3nkqH1ZPmuMxY9Kxi2JmIHLtCE 8TqTF+O9qpux6+WccpiXkqKvimupdwCieGWDRjBNeKjRo0VIHccJ8DnsrIcS2zeCB6df Lov7alRDcG1TOif7WHdZqV9NjwX+4WFU1NUlkT4heoAAEh+4lwXG50aypz+XsENuG+iC yTCw== 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=kAu60bSWWWeNoYwQHOc5Uovj+LlyfCMP6o9Bu8bqiP0=; b=eEruAVyO9PZw8NQFCGFaeusVAsRgSYKDkV6+fp1uxWLPNBFV9dZze5vAsnaJw148ZM x+srKSs8CIUsJt9W25SgFEllFgJqcdbo833GorLPEn7+cHDjbRWopG2HixGkm5ajpd2z pdQssexgqiXSsBxx3l07j/PCsLcrtvHG4UMxOEqoOIU6PV0ZKbE11iztFA7MN2aFCRg+ p9R+KxX2Tqnq7itbBe6otzPd5uZviP0FMj0DsQdv7GmtDRDSLWsXsegXIcFBjW2QtKgg t/xjn1/WfTYbF9KIm0V/Ta7JgEi7C3pkdHpqkLI5miRzFvb3Epp0VUBwGUfxubrUYWK1 iRzA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=XenONNoS; 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=kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id jg41si3519257ejc.395.2021.07.27.07.53.37; Tue, 27 Jul 2021 07:54:00 -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=@kernel.org header.s=k20201202 header.b=XenONNoS; 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=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S237236AbhG0OvM (ORCPT + 99 others); Tue, 27 Jul 2021 10:51:12 -0400 Received: from mail.kernel.org ([198.145.29.99]:36248 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S236916AbhG0Ott (ORCPT ); Tue, 27 Jul 2021 10:49:49 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id D161461B00; Tue, 27 Jul 2021 14:49:31 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1627397377; bh=waF0yGZ/74FCKFwfsSHiFG6HeMntkph0RFHmK2X6nWk=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=XenONNoSK2cLncTqqJgIRWkdacJuUk3tCFtmqztNrzRf62E+2ZdCK0GnSIsIu+dlv qcGEi/Iz+oPD42JhJdKaGksnfmuNWft0N/+iDUWeJ7rsoW+OWZ/k6dWpnQNBt8+kwz dexqr+/4ut9vd2esm0RkG/KrcnY4zQzJKKhBn/yKPmH2x9fmtb66Xptq19HxJPEV88 wP2JALUBp2AhG0A5obwSEHOqw/gKNp57a1ov3O6nCYs5EhuqCiqke2DVgzbogxYnQ6 nDvN8P5s3b6EsJxE0INjFM3F2whAxtmFr66NDXEk2sJaVnRy/+I3N2hf+RsC784t9S 6SVvPCVxy9a/w== From: Arnd Bergmann To: Andrew Morton Cc: Arnd Bergmann , Catalin Marinas , Will Deacon , Thomas Bogendoerfer , "James E.J. Bottomley" , Helge Deller , Michael Ellerman , Benjamin Herrenschmidt , Paul Mackerras , Heiko Carstens , Vasily Gorbik , Christian Borntraeger , "David S. Miller" , Thomas Gleixner , Ingo Molnar , Borislav Petkov , x86@kernel.org, "H. Peter Anvin" , Al Viro , "Eric W. Biederman" , Christoph Hellwig , Feng Tang , linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org, linux-mips@vger.kernel.org, linux-parisc@vger.kernel.org, linuxppc-dev@lists.ozlabs.org, linux-s390@vger.kernel.org, sparclinux@vger.kernel.org, linux-arch@vger.kernel.org, linux-api@vger.kernel.org, linux-mm@kvack.org, Christoph Hellwig Subject: [PATCH v5 3/6] mm: simplify compat_sys_move_pages Date: Tue, 27 Jul 2021 16:48:56 +0200 Message-Id: <20210727144859.4150043-4-arnd@kernel.org> X-Mailer: git-send-email 2.29.2 In-Reply-To: <20210727144859.4150043-1-arnd@kernel.org> References: <20210727144859.4150043-1-arnd@kernel.org> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Arnd Bergmann The compat move_pages() implementation uses compat_alloc_user_space() for converting the pointer array. Moving the compat handling into the function itself is a bit simpler and lets us avoid the compat_alloc_user_space() call. Reviewed-by: Christoph Hellwig Signed-off-by: Arnd Bergmann --- mm/migrate.c | 45 ++++++++++++++++++++++++++++++--------------- 1 file changed, 30 insertions(+), 15 deletions(-) diff --git a/mm/migrate.c b/mm/migrate.c index 34a9ad3e0a4f..60634d2653b9 100644 --- a/mm/migrate.c +++ b/mm/migrate.c @@ -1820,6 +1820,23 @@ static void do_pages_stat_array(struct mm_struct *mm, unsigned long nr_pages, mmap_read_unlock(mm); } +static int get_compat_pages_array(const void __user *chunk_pages[], + const void __user * __user *pages, + unsigned long chunk_nr) +{ + compat_uptr_t __user *pages32 = (compat_uptr_t __user *)pages; + compat_uptr_t p; + int i; + + for (i = 0; i < chunk_nr; i++) { + if (get_user(p, pages32 + i)) + return -EFAULT; + chunk_pages[i] = compat_ptr(p); + } + + return 0; +} + /* * Determine the nodes of a user array of pages and store it in * a user array of status. @@ -1839,8 +1856,15 @@ static int do_pages_stat(struct mm_struct *mm, unsigned long nr_pages, if (chunk_nr > DO_PAGES_STAT_CHUNK_NR) chunk_nr = DO_PAGES_STAT_CHUNK_NR; - if (copy_from_user(chunk_pages, pages, chunk_nr * sizeof(*chunk_pages))) - break; + if (in_compat_syscall()) { + if (get_compat_pages_array(chunk_pages, pages, + chunk_nr)) + break; + } else { + if (copy_from_user(chunk_pages, pages, + chunk_nr * sizeof(*chunk_pages))) + break; + } do_pages_stat_array(mm, chunk_nr, chunk_pages, chunk_status); @@ -1945,23 +1969,14 @@ SYSCALL_DEFINE6(move_pages, pid_t, pid, unsigned long, nr_pages, #ifdef CONFIG_COMPAT COMPAT_SYSCALL_DEFINE6(move_pages, pid_t, pid, compat_ulong_t, nr_pages, - compat_uptr_t __user *, pages32, + compat_uptr_t __user *, pages, const int __user *, nodes, int __user *, status, int, flags) { - const void __user * __user *pages; - int i; - - pages = compat_alloc_user_space(nr_pages * sizeof(void *)); - for (i = 0; i < nr_pages; i++) { - compat_uptr_t p; - - if (get_user(p, pages32 + i) || - put_user(compat_ptr(p), pages + i)) - return -EFAULT; - } - return kernel_move_pages(pid, nr_pages, pages, nodes, status, flags); + return kernel_move_pages(pid, nr_pages, + (const void __user *__user *)pages, + nodes, status, flags); } #endif /* CONFIG_COMPAT */ -- 2.29.2