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.5 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,URIBL_BLOCKED,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 722E4C433E1 for ; Wed, 13 May 2020 16:00:59 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id 81D9B20659 for ; Wed, 13 May 2020 16:00:59 +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="K7vXcJeQ" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 81D9B20659 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 2D33B80013; Wed, 13 May 2020 12:00:56 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 286B18000B; Wed, 13 May 2020 12:00:56 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 14D8680013; Wed, 13 May 2020 12:00:56 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0088.hostedemail.com [216.40.44.88]) by kanga.kvack.org (Postfix) with ESMTP id EB9778000B for ; Wed, 13 May 2020 12:00:55 -0400 (EDT) Received: from smtpin04.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay01.hostedemail.com (Postfix) with ESMTP id AB79E180AD83E for ; Wed, 13 May 2020 16:00:55 +0000 (UTC) X-FDA: 76812159270.04.fight11_5f59d3062c763 X-HE-Tag: fight11_5f59d3062c763 X-Filterd-Recvd-Size: 6717 Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) by imf24.hostedemail.com (Postfix) with ESMTP for ; Wed, 13 May 2020 16:00:55 +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=K7vXcJeQdZ4RxFlFwWFM087V2s ELGL5A58AHOSBzKj7tSKyX1/5d/XvhoN/lFQJNE8Ml8PL7igR4gDP0nge0LibB2gH9sYX5OPVbtRV XsCsiBJYRNog7EKtYR2j8v3RYS7UaXLJPMfeuVRw3DkSpo4rga4+m4uPkRWfT1yDlkmSNOKnpNw7/ DXby0rgCEtH1QjbS7puSqf7dUsnzCY0wQEzDivuEktT3SVj643l7vgfi7h8f+lE226/hsFFsRa8ri LtYKe2R97TArhfTeE8v4HwzdzypRNsAiSvWdvbhYUyq5tW10XFMdVgovAN/qZzCyyLB+F4CeycFLP zl+XNRDg==; Received: from [2001:4bb8:180:9d3f:c70:4a89:bc61:2] (helo=localhost) by bombadil.infradead.org with esmtpsa (Exim 4.92.3 #3 (Red Hat Linux)) id 1jYtoR-0004j2-24; Wed, 13 May 2020 16:00:51 +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/18] maccess: clarify kerneldoc comments Date: Wed, 13 May 2020 18:00:24 +0200 Message-Id: <20200513160038.2482415-5-hch@lst.de> X-Mailer: git-send-email 2.26.2 In-Reply-To: <20200513160038.2482415-1-hch@lst.de> References: <20200513160038.2482415-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