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,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 426D0C433DF for ; Thu, 21 May 2020 15:23:34 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id ED5992084C for ; Thu, 21 May 2020 15:23:33 +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="SdN5eLQs" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org ED5992084C 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 D712480010; Thu, 21 May 2020 11:23:30 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id D00DD8000A; Thu, 21 May 2020 11:23:30 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id B018780010; Thu, 21 May 2020 11:23:30 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0155.hostedemail.com [216.40.44.155]) by kanga.kvack.org (Postfix) with ESMTP id 95EF48000A for ; Thu, 21 May 2020 11:23:30 -0400 (EDT) Received: from smtpin06.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay03.hostedemail.com (Postfix) with ESMTP id 5F9408248047 for ; Thu, 21 May 2020 15:23:30 +0000 (UTC) X-FDA: 76841095380.06.smell07_58c7b524b734d X-HE-Tag: smell07_58c7b524b734d X-Filterd-Recvd-Size: 6717 Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) by imf36.hostedemail.com (Postfix) with ESMTP for ; Thu, 21 May 2020 15:23:29 +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=SdN5eLQsE5p+1g7PTpF1jYpRoM DO7R5ngx5JrKGEnObtTZw9tuX7A2BgZheYionwPg/xTO212u0BV8ZXcJGhkQ82mTWupVNtjgiVbMp OhYuyQM6+o9hFqzSLLJDEux6PCvweNwsPOF/Xvu5UMTei2I7yXHdpK3/Bgtrr6GO7GIH7J/A/psV2 Q88exWPFKbLB6QHpxMyDdHEaAAoN27xtTckPt0YHFRfdPWiVoiATiPOpcS9MdR2w9XG8zf3ninTph kEJM3WJrWLP01F3B5xmpe+KMNHbz51Pft23YEULJ5Zi3UeacZXwytPAzyKJbH9xAzLwQYwRaOwVNF 7EZvB6YA==; 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 1jbn2Q-00048H-I5; Thu, 21 May 2020 15:23:15 +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/23] maccess: clarify kerneldoc comments Date: Thu, 21 May 2020 17:22:42 +0200 Message-Id: <20200521152301.2587579-5-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 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