From patchwork Sat May 15 10:18:02 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Arnd Bergmann X-Patchwork-Id: 1478857 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=none (no SPF record) smtp.mailfrom=lists.infradead.org (client-ip=2001:8b0:10b:1:d65d:64ff:fe57:4e05; helo=desiato.infradead.org; envelope-from=linux-um-bounces+incoming=patchwork.ozlabs.org@lists.infradead.org; receiver=) Authentication-Results: ozlabs.org; dkim=pass (2048-bit key; secure) header.d=lists.infradead.org header.i=@lists.infradead.org header.a=rsa-sha256 header.s=desiato.20200630 header.b=NZIRTBRh; dkim=fail reason="signature verification failed" (2048-bit key; secure) header.d=infradead.org header.i=@infradead.org header.a=rsa-sha256 header.s=bombadil.20210309 header.b=ZLDjbvvI; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20201202 header.b=qcRi/50l; dkim-atps=neutral Received: from desiato.infradead.org (desiato.infradead.org [IPv6:2001:8b0:10b:1:d65d:64ff:fe57:4e05]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 4Fj1bn4cNNz9sWH for ; Sat, 15 May 2021 20:19:49 +1000 (AEST) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=desiato.20200630; h=Sender:Content-Transfer-Encoding :Content-Type:List-Subscribe:List-Help:List-Post:List-Archive: List-Unsubscribe:List-Id:MIME-Version:References:In-Reply-To:Message-Id:Date: Subject:Cc:To:From:Reply-To:Content-ID:Content-Description:Resent-Date: Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Owner; bh=NDzFR7Z0cmMOLGpYQGd/kbyv/EL9TtH9KF9gZUyP+fo=; b=NZIRTBRhhUiR0KPiglPjIF5Er DVF1/1WjO0NNs3S8uCwfI2Vk3XffVmrn0G82hb+wnwSrrRwjPgDOpjRA9lHhMR8+RpXeT4cwUANX0 d/FxrvqM3I0Kx8RnVSAy16OAPXfEfbc9466fO7Aww3srD927MpM5otaToEJX7FaTnbvLt/KlnH4W9 RflU9lKUbvRsTD5afPpLky3zUb8hhZzgNEG2LFx5kAimVzs9BYnoowQgv5CrsChJgeQpIsLZH2qHP SzWDZfXUQ5EsmZkcMUIKtPW95Rl1emD3hYIuwE+Je+L9cb6HbMxftUMdbjfGl1frhKnUcaa2pQiBo DfbjKyl0w==; Received: from localhost ([::1] helo=desiato.infradead.org) by desiato.infradead.org with esmtp (Exim 4.94 #2 (Red Hat Linux)) id 1lhrOU-00A8kh-VW; Sat, 15 May 2021 10:19:39 +0000 Received: from bombadil.infradead.org ([2607:7c80:54:e::133]) by desiato.infradead.org with esmtps (Exim 4.94 #2 (Red Hat Linux)) id 1lhrOI-00A8eX-N3; Sat, 15 May 2021 10:19:26 +0000 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=bombadil.20210309; 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=FU4k2uMM9mwcp1WgQUinaWftWLJ6tL6ok/JHUHLhO1U=; b=ZLDjbvvIuiCTTZC+Dj4koBkiW2 ltVtaujtQ/TRzakEJqLkUnPrWASutLWy6J4TtLGtvX9XAr3KBkfqNCieVcHG8xYnYtmZutN9FUDTA o+xOTGCjop13Jng79xBYmnwwCeNVIwy60lNTZVwuC4dsXnwEM6Mj5kEnd+2BukAGFejxC3SkwcsDr d77y13CIgN8JPYD4EtdlDaOiA1txVDayAYcZzhuNioPqu8c9bSvGRN436cUbxtgEyAlNUl1Qc4TEP eG+dIry7hsx+1/zihELAWi5o7cLzWTZS+bHrA8AowwoRd+qDVK9uQ4Rp5PPt0laqLnjDZC3LN1rFH uBihVknQ==; Received: from mail.kernel.org ([198.145.29.99]) by bombadil.infradead.org with esmtps (Exim 4.94 #2 (Red Hat Linux)) id 1lhrOE-00CU5u-RZ; Sat, 15 May 2021 10:19:25 +0000 Received: by mail.kernel.org (Postfix) with ESMTPSA id 78078613F1; Sat, 15 May 2021 10:19:18 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1621073962; bh=OHYyLARVOpPFIbAcC7K6UIcn3rkRJrz96uQAgiEquDo=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=qcRi/50ljOQgAZf8i+VFhWF6uabdLpEfT7FHBTtxYuSMtemuV9LrEtTDSACDtVyfw salCHZmpn79xzNXb8B78wch24f//jkb6g+Fki5uCNdP8zNnv9UtDzG7e22EknaCACh mrPOxaZq4mdM1UsevzFRyixsupIwTAYWl49hqhEg3ck/tFFeNs7qINE0LN5ZtJSLfX H47TnEMDXTRGI4KAr0xEHobI2Wx0rYPpPUDbXbSo9MF06IlZHzfOPDMp3r4qLLEKvN GNVZauk3D4wviEHeU3e+G301vOcgnCYQ7ZvM9PTwWoO0iy7NC/13CbD7OJqRdxhixA j4vbx08vZ6TPA== From: Arnd Bergmann To: linux-arch@vger.kernel.org Cc: Arnd Bergmann , Christoph Hellwig , Al Viro , Vineet Gupta , Yoshinori Sato , Brian Cain , Geert Uytterhoeven , Paul Walmsley , Palmer Dabbelt , Albert Ou , Jeff Dike , Richard Weinberger , Anton Ivanov , Sid Manning , Andrew Morton , Mike Rapoport , linux-snps-arc@lists.infradead.org, linux-kernel@vger.kernel.org, uclinux-h8-devel@lists.sourceforge.jp, linux-hexagon@vger.kernel.org, linux-m68k@lists.linux-m68k.org, linux-riscv@lists.infradead.org, linux-um@lists.infradead.org Subject: [PATCH 5/6] [v2] asm-generic: uaccess: remove inline strncpy_from_user/strnlen_user Date: Sat, 15 May 2021 12:18:02 +0200 Message-Id: <20210515101803.924427-6-arnd@kernel.org> X-Mailer: git-send-email 2.29.2 In-Reply-To: <20210515101803.924427-1-arnd@kernel.org> References: <20210515101803.924427-1-arnd@kernel.org> MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20210515_031922_956360_01DE1088 X-CRM114-Status: GOOD ( 13.00 ) X-Spam-Score: -5.5 (-----) X-Spam-Report: Spam detection software, running on the system "bombadil.infradead.org", has NOT identified this incoming email as spam. The original message has been attached to this so you can view it or label similar future email. If you have any questions, see the administrator of that system for details. Content preview: From: Arnd Bergmann Consolidate the asm-generic implementation with the library version that is used everywhere else. These are the three versions for NOMMU kernels, which can in principle fall back to strncpy()/strnlen() as the version in asm-generic does, but this version is particularly inefficient when it scans t [...] Content analysis details: (-5.5 points, 5.0 required) pts rule name description ---- ---------------------- -------------------------------------------------- -5.0 RCVD_IN_DNSWL_HI RBL: Sender listed at https://www.dnswl.org/, high trust [198.145.29.99 listed in list.dnswl.org] 0.0 SPF_HELO_NONE SPF: HELO does not publish an SPF Record -0.0 SPF_PASS SPF: sender matches SPF record -0.1 DKIM_VALID Message has at least one valid DKIM or DK signature -0.1 DKIM_VALID_AU Message has a valid DKIM or DK signature from author's domain 0.1 DKIM_SIGNED Message has a DKIM or DK signature, not necessarily valid -0.1 DKIM_VALID_EF Message has a valid DKIM or DK signature from envelope-from domain -0.3 DKIMWL_WL_HIGH DKIMwl.org - High trust sender X-BeenThere: linux-um@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-um" Errors-To: linux-um-bounces+incoming=patchwork.ozlabs.org@lists.infradead.org From: Arnd Bergmann Consolidate the asm-generic implementation with the library version that is used everywhere else. These are the three versions for NOMMU kernels, which can in principle fall back to strncpy()/strnlen() as the version in asm-generic does, but this version is particularly inefficient when it scans the string one byte at a time twice. The generic version also lacks a check for user_addr_max(), but this is probably ok on NOMMU targets. Signed-off-by: Arnd Bergmann --- arch/h8300/Kconfig | 2 ++ arch/m68k/Kconfig | 4 +-- arch/riscv/Kconfig | 4 +-- include/asm-generic/uaccess.h | 46 ++++++----------------------------- 4 files changed, 14 insertions(+), 42 deletions(-) diff --git a/arch/h8300/Kconfig b/arch/h8300/Kconfig index 3e3e0f16f7e0..53dfd2d47e0e 100644 --- a/arch/h8300/Kconfig +++ b/arch/h8300/Kconfig @@ -11,6 +11,8 @@ config H8300 select GENERIC_IRQ_SHOW select FRAME_POINTER select GENERIC_CPU_DEVICES + select GENERIC_STRNCPY_FROM_USER + select GENERIC_STRNLEN_USER select MODULES_USE_ELF_RELA select COMMON_CLK select ARCH_WANT_FRAME_POINTERS diff --git a/arch/m68k/Kconfig b/arch/m68k/Kconfig index ed6b8050e3ed..5f1aafa7b2e2 100644 --- a/arch/m68k/Kconfig +++ b/arch/m68k/Kconfig @@ -17,8 +17,8 @@ config M68K select GENERIC_CPU_DEVICES select GENERIC_IOMAP select GENERIC_IRQ_SHOW - select GENERIC_STRNCPY_FROM_USER if MMU - select GENERIC_STRNLEN_USER if MMU + select GENERIC_STRNCPY_FROM_USER + select GENERIC_STRNLEN_USER select HAVE_AOUT if MMU select HAVE_ASM_MODVERSIONS select HAVE_DEBUG_BUGVERBOSE diff --git a/arch/riscv/Kconfig b/arch/riscv/Kconfig index a8ad8eb76120..ada7a2918c05 100644 --- a/arch/riscv/Kconfig +++ b/arch/riscv/Kconfig @@ -55,8 +55,8 @@ config RISCV select GENERIC_PTDUMP if MMU select GENERIC_SCHED_CLOCK select GENERIC_SMP_IDLE_THREAD - select GENERIC_STRNCPY_FROM_USER if MMU - select GENERIC_STRNLEN_USER if MMU + select GENERIC_STRNCPY_FROM_USER + select GENERIC_STRNLEN_USER select GENERIC_TIME_VSYSCALL if MMU && 64BIT select HANDLE_DOMAIN_IRQ select HAVE_ARCH_AUDITSYSCALL diff --git a/include/asm-generic/uaccess.h b/include/asm-generic/uaccess.h index c03889cc904c..83a48f430951 100644 --- a/include/asm-generic/uaccess.h +++ b/include/asm-generic/uaccess.h @@ -119,6 +119,11 @@ static inline void set_fs(mm_segment_t fs) #ifndef uaccess_kernel #define uaccess_kernel() (get_fs().seg == KERNEL_DS.seg) #endif + +#ifndef user_addr_max +#define user_addr_max() (uaccess_kernel() ? ~0UL : TASK_SIZE) +#endif + #endif /* CONFIG_SET_FS */ #define access_ok(addr, size) __access_ok((unsigned long)(addr),(size)) @@ -243,44 +248,6 @@ static inline int __get_user_fn(size_t size, const void __user *ptr, void *x) extern int __get_user_bad(void) __attribute__((noreturn)); -/* - * Copy a null terminated string from userspace. - */ -#ifndef strncpy_from_user -static inline long -strncpy_from_user(char *dst, const char __user *src, long count) -{ - char *tmp; - - if (!access_ok(src, 1)) - return -EFAULT; - - strncpy(dst, (const char __force *)src, count); - for (tmp = dst; *tmp && count > 0; tmp++, count--) - ; - return (tmp - dst); -} -#endif - -#ifndef strnlen_user -/* - * Return the size of a string (including the ending 0) - * - * Return 0 on exception, a value greater than N if too long - * - * Unlike strnlen, strnlen_user includes the nul terminator in - * its returned count. Callers should check for a returned value - * greater than N as an indication the string is too long. - */ -static inline long strnlen_user(const char __user *src, long n) -{ - if (!access_ok(src, 1)) - return 0; - - return strnlen(src, n) + 1; -} -#endif - /* * Zero Userspace */ @@ -305,4 +272,7 @@ clear_user(void __user *to, unsigned long n) #include +extern long strncpy_from_user(char *dst, const char __user *src, long count); +extern long strnlen_user(const char __user *src, long n); + #endif /* __ASM_GENERIC_UACCESS_H */