From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-9.6 required=3.0 tests=DKIM_INVALID,DKIM_SIGNED, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_PATCH,MAILING_LIST_MULTI,SIGNED_OFF_BY, SPF_HELO_NONE,SPF_PASS,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 038EDC4725A for ; Wed, 6 May 2020 06:22:42 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id B15CE208DB for ; Wed, 6 May 2020 06:22:41 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=fail reason="signature verification failed" (2048-bit key) header.d=infradead.org header.i=@infradead.org header.b="EwXRGNoK" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org B15CE208DB Authentication-Results: mail.kernel.org; dmarc=none (p=none dis=none) header.from=lst.de Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=owner-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix) id 623B28E0009; Wed, 6 May 2020 02:22:41 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 5AD608E0003; Wed, 6 May 2020 02:22:41 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 44E538E0009; Wed, 6 May 2020 02:22:41 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0162.hostedemail.com [216.40.44.162]) by kanga.kvack.org (Postfix) with ESMTP id 2E5E88E0003 for ; Wed, 6 May 2020 02:22:41 -0400 (EDT) Received: from smtpin13.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay04.hostedemail.com (Postfix) with ESMTP id E9DCC988D for ; Wed, 6 May 2020 06:22:40 +0000 (UTC) X-FDA: 76785300480.13.nest93_17631b5184b61 X-HE-Tag: nest93_17631b5184b61 X-Filterd-Recvd-Size: 6711 Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) by imf28.hostedemail.com (Postfix) with ESMTP for ; Wed, 6 May 2020 06:22:40 +0000 (UTC) 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=mSMXwSYIg6w8Djb8jfs2EjgdqI2tqBJvsH4pyf4a+s4=; b=EwXRGNoKH27CubtAt4lkBokJUF 5JjLZZPOvxWOpLNVT3vSpiAaHrvPR2g78jaTgcWV+0/8g85x3jBiyZonYNkK192ZIsD6rw6/yEHpw xbHTeQciZhCksVZFeb/5wjPBfxKlPP5Ied1SCyBI+dwchWXSQ1KiiGpotpe+WYKQcI0Wx8KP6e3rJ fDK8cDxVD02hxmcTkxEvztO+7vByfhIp0Euvz52EluPRDoAwYFvRmIhQQ7AFucvGa5PbJE3bgMp+Y vBtQGudsD6VH4TDkd7AnnB+u3zFf+RbjeT0qSQ7ILy5x1ho1TwCMB2zxhmLv0/t3KOlY5+ySGvz50 yHXLfNow==; Received: from [2001:4bb8:191:66b6:c70:4a89:bc61:2] (helo=localhost) by bombadil.infradead.org with esmtpsa (Exim 4.92.3 #3 (Red Hat Linux)) id 1jWDS1-0006Yc-IH; Wed, 06 May 2020 06:22:38 +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 04/15] maccess: clarify kerneldoc comments Date: Wed, 6 May 2020 08:22:12 +0200 Message-Id: <20200506062223.30032-5-hch@lst.de> X-Mailer: git-send-email 2.26.2 In-Reply-To: <20200506062223.30032-1-hch@lst.de> References: <20200506062223.30032-1-hch@lst.de> MIME-Version: 1.0 X-SRS-Rewrite: SMTP reverse-path rewritten from by bombadil.infradead.org. See http://www.infradead.org/rpr.html Content-Transfer-Encoding: quoted-printable X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: Add proper kerneldoc comments for probe_kernel_read_strict and probe_kernel_read strncpy_from_unsafe_strict and explain the different versus the non-strict version. Signed-off-by: Christoph Hellwig --- mm/maccess.c | 61 ++++++++++++++++++++++++++++++++++++---------------- 1 file changed, 43 insertions(+), 18 deletions(-) diff --git a/mm/maccess.c b/mm/maccess.c index 4e7f3b6eb05ae..747581ac50dc9 100644 --- a/mm/maccess.c +++ b/mm/maccess.c @@ -31,29 +31,35 @@ probe_write_common(void __user *dst, const void *src,= size_t size) } =20 /** - * probe_kernel_read(): safely attempt to read from a kernel-space locat= ion + * probe_kernel_read(): safely attempt to read from any location * @dst: pointer to the buffer that shall take the data * @src: address to read from * @size: size of the data chunk * - * Safely read from address @src to the buffer at @dst. If a kernel fau= lt - * happens, handle that and return -EFAULT. + * Same as probe_kernel_read_strict() except that for architectures with + * not fully separated user and kernel address spaces this function also= works + * for user address tanges. + * + * DO NOT USE THIS FUNCTION - it is broken on architectures with entirel= y + * separate kernel and user address spaces, and also a bad idea otherwis= e. + */ +long __weak probe_kernel_read(void *dst, const void *src, size_t size) + __attribute__((alias("__probe_kernel_read"))); + +/** + * probe_kernel_read_strict(): safely attempt to read from kernel-space + * @dst: pointer to the buffer that shall take the data + * @src: address to read from + * @size: size of the data chunk + * + * Safely read from kernel address @src to the buffer at @dst. If a ker= nel + * fault happens, handle that and return -EFAULT. * * We ensure that the copy_from_user is executed in atomic context so th= at * do_page_fault() doesn't attempt to take mmap_sem. This makes * probe_kernel_read() suitable for use within regions where the caller * already holds mmap_sem, or other locks which nest inside mmap_sem. - * - * probe_kernel_read_strict() is the same as probe_kernel_read() except = for - * the case where architectures have non-overlapping user and kernel add= ress - * ranges: probe_kernel_read_strict() will additionally return -EFAULT f= or - * probing memory on a user address range where probe_user_read() is sup= posed - * to be used instead. */ - -long __weak probe_kernel_read(void *dst, const void *src, size_t size) - __attribute__((alias("__probe_kernel_read"))); - long __weak probe_kernel_read_strict(void *dst, const void *src, size_t = size) __attribute__((alias("__probe_kernel_read"))); =20 @@ -153,15 +159,34 @@ long probe_user_write(void __user *dst, const void = *src, size_t size) * If @count is smaller than the length of the string, copies @count-1 b= ytes, * sets the last byte of @dst buffer to NUL and returns @count. * - * strncpy_from_unsafe_strict() is the same as strncpy_from_unsafe() exc= ept - * for the case where architectures have non-overlapping user and kernel= address - * ranges: strncpy_from_unsafe_strict() will additionally return -EFAULT= for - * probing memory on a user address range where strncpy_from_unsafe_user= () is - * supposed to be used instead. + * Same as strncpy_from_unsafe_strict() except that for architectures wi= th + * not fully separated user and kernel address spaces this function also= works + * for user address tanges. + * + * DO NOT USE THIS FUNCTION - it is broken on architectures with entirel= y + * separate kernel and user address spaces, and also a bad idea otherwis= e. */ long __weak strncpy_from_unsafe(char *dst, const void *unsafe_addr, long= count) __attribute__((alias("__strncpy_from_unsafe"))); =20 +/** + * strncpy_from_unsafe_strict: - Copy a NUL terminated string from unsaf= e + * address. + * @dst: Destination address, in kernel space. This buffer must be at + * least @count bytes long. + * @unsafe_addr: Unsafe address. + * @count: Maximum number of bytes to copy, including the trailing NUL. + * + * Copies a NUL-terminated string from unsafe address to kernel buffer. + * + * On success, returns the length of the string INCLUDING the trailing N= UL. + * + * If access fails, returns -EFAULT (some data may have been copied + * and the trailing NUL added). + * + * If @count is smaller than the length of the string, copies @count-1 b= ytes, + * sets the last byte of @dst buffer to NUL and returns @count. + */ long __weak strncpy_from_unsafe_strict(char *dst, const void *unsafe_add= r, long count) __attribute__((alias("__strncpy_from_unsafe"))); --=20 2.26.2