Received: by 2002:a25:868d:0:0:0:0:0 with SMTP id z13csp1505139ybk; Thu, 21 May 2020 08:26:22 -0700 (PDT) X-Google-Smtp-Source: ABdhPJw0YHKT/1FQ3qlAlitZ6e4sOJ9NhJckmkCLOSe/SRvGhqGhRUjlNFP2qCfSWtvlcpk2vKor X-Received: by 2002:a17:906:a0c2:: with SMTP id bh2mr4226009ejb.458.1590074781906; Thu, 21 May 2020 08:26:21 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1590074781; cv=none; d=google.com; s=arc-20160816; b=Wxi4LVxfoarbE7iqr4bpK4yD2coKQg7e2dr+0kYuYS6/9ogJB2xmLfkOzjYammkhvF Qfzq01zkm7xSl/2x/BS36et1pVaJS/aLrhwdFdZ0i+7mknG7SWoejQ8uCHv0Ss/0ntJy 5zTbgjZWnJV79qwf778J/CyA+Jv+cjatAkxZMytcffHVh5BS4r9Y9CgT+TCnTzelSc8H +Tu+BbdYg77wmFiunNNP372MvJV61ucp1wcWRvtnxbFp8uFo7UNhPrCQasAqsdD3Nig4 M9DmR11+rk8hbQj2EFSx9z78adPJy0DDKsg+oeOQyAHU7maRqz+u2X+fpybc/AMnlYUQ 5voQ== 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 :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=Udb1HsxXlkIRS2Lej3Dlr2F0T8F8gkjArejHoQkqHz8=; b=c1JkV5A3gMNOZNlX5YEosxvzqPbm9901KBtSCIB0d69ofC9ibtyXGwfwNJSGQPsrGo Ph/xNwIjFnwhngDEQev78aaONde8tv91iVrIw3u/0xeql0G+bOQTIVkJvs8bUp2ggxyr PR2Gqww7/Le0ErKgDrnGdrcPlxcZJWiiBTNNPRES5c4moZKFyzWEdBTiXZMCmvKG8adr kOuzsTUjlwahwCPSjagN1MVL0S499Zxo3bQ1JpQmepcwJnKKirZjgCVoS6j1dKwSZGc0 Z4KcQgbnYpW7ie46qKLw2VeLPFTjAc2E6oQ4bJZpGslz3Sas40ge+24HNo6+HmIVt2Gu cu9g== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@infradead.org header.s=bombadil.20170209 header.b=PKL2apZ2; 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 Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id r3si3313416edo.395.2020.05.21.08.25.58; Thu, 21 May 2020 08:26:21 -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=fail header.i=@infradead.org header.s=bombadil.20170209 header.b=PKL2apZ2; 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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1730234AbgEUPX7 (ORCPT + 99 others); Thu, 21 May 2020 11:23:59 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:35228 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1730169AbgEUPX4 (ORCPT ); Thu, 21 May 2020 11:23:56 -0400 Received: from bombadil.infradead.org (bombadil.infradead.org [IPv6:2607:7c80:54:e::133]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 76238C061A0E; Thu, 21 May 2020 08:23:56 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=bombadil.20170209; h=Content-Transfer-Encoding: MIME-Version:References:In-Reply-To:Message-Id:Date:Subject:Cc:To:From:Sender :Reply-To:Content-Type:Content-ID:Content-Description; bh=Udb1HsxXlkIRS2Lej3Dlr2F0T8F8gkjArejHoQkqHz8=; b=PKL2apZ2zXd9QHSu1knAJete1P DAVdspm5rA5wd9eyP4jTGtJFC1WRUAZ2qcUY0D3GYNPCanRdHeaKVw8cjaEK84TgCwAuSs4V82iCK fejTdCOF4ESHskOwSqbbs06SZlLdjw0YhP+hCFAuPK4H2xlGHXl47haFMXufc8cXQ/nccpuyYcF/V ycwmm2uNmANTioI8LdFQ38+R4PuV4smV9TtQKWPRwSAWVKG47qFccKx6NKisN13V8tlhuQrSZHVy1 nVdnEjmNzgGyXp3GXLBw9se7paNHTNEMVrFhmAzaIPsluDc2MQZ8OnnndmJ/bScMlj7KTGnfMFWTG 3uM7gzMQ==; Received: from [2001:4bb8:18c:5da7:c70:4a89:bc61:2] (helo=localhost) by bombadil.infradead.org with esmtpsa (Exim 4.92.3 #3 (Red Hat Linux)) id 1jbn34-0004bq-Cs; Thu, 21 May 2020 15:23:55 +0000 From: Christoph Hellwig To: x86@kernel.org, Alexei Starovoitov , Daniel Borkmann , Masami Hiramatsu , Linus Torvalds , Andrew Morton Cc: linux-parisc@vger.kernel.org, linux-um@lists.infradead.org, netdev@vger.kernel.org, bpf@vger.kernel.org, linux-mm@kvack.org, linux-kernel@vger.kernel.org Subject: [PATCH 17/23] maccess: move user access routines together Date: Thu, 21 May 2020 17:22:55 +0200 Message-Id: <20200521152301.2587579-18-hch@lst.de> X-Mailer: git-send-email 2.26.2 In-Reply-To: <20200521152301.2587579-1-hch@lst.de> References: <20200521152301.2587579-1-hch@lst.de> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-SRS-Rewrite: SMTP reverse-path rewritten from by bombadil.infradead.org. See http://www.infradead.org/rpr.html Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Move kernel access vs user access routines together to ease upcoming ifdefs. Signed-off-by: Christoph Hellwig --- mm/maccess.c | 110 +++++++++++++++++++++++++-------------------------- 1 file changed, 55 insertions(+), 55 deletions(-) diff --git a/mm/maccess.c b/mm/maccess.c index 81a85c1e71165..ffde1ae86ec51 100644 --- a/mm/maccess.c +++ b/mm/maccess.c @@ -46,34 +46,6 @@ long probe_kernel_read(void *dst, const void *src, size_t size) } EXPORT_SYMBOL_GPL(probe_kernel_read); -/** - * probe_user_read(): safely attempt to read from a user-space location - * @dst: pointer to the buffer that shall take the data - * @src: address to read from. This must be a user address. - * @size: size of the data chunk - * - * Safely read from user address @src to the buffer at @dst. If a kernel fault - * happens, handle that and return -EFAULT. - */ -long probe_user_read(void *dst, const void __user *src, size_t size) -{ - long ret = -EFAULT; - mm_segment_t old_fs = get_fs(); - - set_fs(USER_DS); - if (access_ok(src, size)) { - pagefault_disable(); - ret = __copy_from_user_inatomic(dst, src, size); - pagefault_enable(); - } - set_fs(old_fs); - - if (ret) - return -EFAULT; - return 0; -} -EXPORT_SYMBOL_GPL(probe_user_read); - /** * probe_kernel_write(): safely attempt to write to a location * @dst: address to write to @@ -99,33 +71,6 @@ long probe_kernel_write(void *dst, const void *src, size_t size) return 0; } -/** - * probe_user_write(): safely attempt to write to a user-space location - * @dst: address to write to - * @src: pointer to the data that shall be written - * @size: size of the data chunk - * - * Safely write to address @dst from the buffer at @src. If a kernel fault - * happens, handle that and return -EFAULT. - */ -long probe_user_write(void __user *dst, const void *src, size_t size) -{ - long ret = -EFAULT; - mm_segment_t old_fs = get_fs(); - - set_fs(USER_DS); - if (access_ok(dst, size)) { - pagefault_disable(); - ret = __copy_to_user_inatomic(dst, src, size); - pagefault_enable(); - } - set_fs(old_fs); - - if (ret) - return -EFAULT; - return 0; -} - /** * strncpy_from_kernel_nofault: - Copy a NUL terminated string from unsafe * address. @@ -169,6 +114,61 @@ long strncpy_from_kernel_nofault(char *dst, const void *unsafe_addr, long count) return ret ? -EFAULT : src - unsafe_addr; } +/** + * probe_user_read(): safely attempt to read from a user-space location + * @dst: pointer to the buffer that shall take the data + * @src: address to read from. This must be a user address. + * @size: size of the data chunk + * + * Safely read from user address @src to the buffer at @dst. If a kernel fault + * happens, handle that and return -EFAULT. + */ +long probe_user_read(void *dst, const void __user *src, size_t size) +{ + long ret = -EFAULT; + mm_segment_t old_fs = get_fs(); + + set_fs(USER_DS); + if (access_ok(src, size)) { + pagefault_disable(); + ret = __copy_from_user_inatomic(dst, src, size); + pagefault_enable(); + } + set_fs(old_fs); + + if (ret) + return -EFAULT; + return 0; +} +EXPORT_SYMBOL_GPL(probe_user_read); + +/** + * probe_user_write(): safely attempt to write to a user-space location + * @dst: address to write to + * @src: pointer to the data that shall be written + * @size: size of the data chunk + * + * Safely write to address @dst from the buffer at @src. If a kernel fault + * happens, handle that and return -EFAULT. + */ +long probe_user_write(void __user *dst, const void *src, size_t size) +{ + long ret = -EFAULT; + mm_segment_t old_fs = get_fs(); + + set_fs(USER_DS); + if (access_ok(dst, size)) { + pagefault_disable(); + ret = __copy_to_user_inatomic(dst, src, size); + pagefault_enable(); + } + set_fs(old_fs); + + if (ret) + return -EFAULT; + return 0; +} + /** * strncpy_from_user_nofault: - Copy a NUL terminated string from unsafe user * address. -- 2.26.2