From patchwork Fri May 14 22:09:38 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Arnd Bergmann X-Patchwork-Id: 12259225 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=-17.7 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,INCLUDES_CR_TRAILER,INCLUDES_PATCH,MAILING_LIST_MULTI, SPF_HELO_NONE,SPF_PASS,USER_AGENT_GIT autolearn=unavailable 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 16B55C433B4 for ; Fri, 14 May 2021 22:11:19 +0000 (UTC) Received: from desiato.infradead.org (desiato.infradead.org [90.155.92.199]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 81DF361182 for ; Fri, 14 May 2021 22:11:18 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 81DF361182 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=kernel.org Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=linux-riscv-bounces+linux-riscv=archiver.kernel.org@lists.infradead.org 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=DEGxVSgyvBiDo3MCKbxW4KB/EkBSSger8AHhbvepGA4=; b=hkBjKrMMOvif80w/27iq/fkZd drrJ0FyOQVlU3khl8Rs7N22mL/ADoINN6386IGPc3Zaqktv/6jaP/jL4Ow8Z0PiVEaUluFqXI8vzI RW5RSkt22XgyU6cUMPxjC0VvIAW6xQlN4YQxPY43vo8UU7upYynXQUVFbnOtWURt9u84LKLTkZpJk v6lQZtFBRQ7DpUTUYfQnWzl6A4Ce8kvwGJVJTMUa1qoXfLp0Qi95tH2YHtQbQHbMIiiRCjZBYMmwN DjdcRnPCL0ByfvlVsd0SS6JjW2pkSkg7UZwHQTpaXLpw7rUZawxDgjb7xYOZc5jVKyrf15+eAuQkS wzN6PLRiQ==; Received: from localhost ([::1] helo=desiato.infradead.org) by desiato.infradead.org with esmtp (Exim 4.94 #2 (Red Hat Linux)) id 1lhg1K-0098CR-TV; Fri, 14 May 2021 22:10:58 +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 1lhg1I-0098Be-CI; Fri, 14 May 2021 22:10:56 +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=tNtVzum3+jmItql2AdkblZN0kg2xjCy6+6H3Mnz/RAM=; b=fUlZez16U5xQoXNckzom2MaqT+ IBJgsZhOVA98kqyhYs++A4JglgbWvQasmZcTxydOkA5TftQgvxhrW/sNg2/faVMBpUJPLTWWE7iFY 8tVr0jXmZ2VX3WRNmgaMtfKbG7D5OrKhc0eSC1KIYcn0OTVBNrCAaPFciyEMFs9ztsbkSShmdH8OC Eg6TgUKd478rrBOq5AdJR8LshbLQ2iN3aztBbRZI4mXd9VVHmObL/m5PDPolH/6+3LSRsd29toh+a VVLxWoghPRPwQWsT7S0DLNixsTBkHYcRkGBPNeAsT+Hw+PreLQBJXmbTlPoH7s8H6a3Xt6/rdS2Pl /nt9PX+Q==; Received: from mail.kernel.org ([198.145.29.99]) by bombadil.infradead.org with esmtps (Exim 4.94 #2 (Red Hat Linux)) id 1lhg1F-00CIB7-EB; Fri, 14 May 2021 22:10:55 +0000 Received: by mail.kernel.org (Postfix) with ESMTPSA id 1050861442; Fri, 14 May 2021 22:10:48 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1621030253; bh=aUw+r/nEodOPwyLxBnACR72ulITbwIstVbqXf4RRoJE=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=oYBr8bGKcTRMUOp2zoQGJPX5679NcgVqQDZoScnhBl/RG3Kf9VFROFuxnZ2PYbUQp HbMeDK9xehouxSDKBmgv5lyhLy6L8QEuCI09B8k636PJ4PIx+RMZ86BZJ+1SDBOjtI w6x/8vaq2LgB/oHRDPceRLy95NS/naosQOIONqbCHDfwcxS1vZmYhqRX8HywJHQy7Z oN85ZsVRRgEdcYYERghpTitKtDHkJAUTk4nmz4zUq84KFTvm2HT4FkLgUi4AN1teug 0D5rRFn5LTD1UcK81AXhl4m0dGa5I4XmVban0KVqOcblgEZp8Xu4oMFybVHbboBLKp nqjttqDBqwHiA== 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 1/5] asm-generic/uaccess.h: remove __strncpy_from_user/__strnlen_user Date: Sat, 15 May 2021 00:09:38 +0200 Message-Id: <20210514220942.879805-2-arnd@kernel.org> X-Mailer: git-send-email 2.29.2 In-Reply-To: <20210514220942.879805-1-arnd@kernel.org> References: <20210514220942.879805-1-arnd@kernel.org> MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20210514_151053_546066_28DDB6CA X-CRM114-Status: GOOD ( 19.00 ) X-BeenThere: linux-riscv@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-riscv" Errors-To: linux-riscv-bounces+linux-riscv=archiver.kernel.org@lists.infradead.org From: Arnd Bergmann This is a preparation for changing over architectures to the generic implementation one at a time. As there are no callers of either __strncpy_from_user() or __strnlen_user(), fold these into the strncpy_from_user() strnlen_user() functions to make each implementation independent of the others. Many of these implementations have known bugs, but the intention here is to not change behavior at all and stay compatible with those bugs for the moment. Signed-off-by: Arnd Bergmann --- arch/arc/include/asm/uaccess.h | 14 ++++++++++---- arch/hexagon/include/asm/uaccess.h | 22 +++++++++++++--------- arch/um/include/asm/uaccess.h | 8 ++++---- arch/um/kernel/skas/uaccess.c | 5 ++++- include/asm-generic/uaccess.h | 28 +++++++++++----------------- 5 files changed, 42 insertions(+), 35 deletions(-) diff --git a/arch/arc/include/asm/uaccess.h b/arch/arc/include/asm/uaccess.h index ea40ec7f6cae..3476348f361e 100644 --- a/arch/arc/include/asm/uaccess.h +++ b/arch/arc/include/asm/uaccess.h @@ -661,6 +661,9 @@ __arc_strncpy_from_user(char *dst, const char __user *src, long count) long res = 0; char val; + if (!access_ok(src, 1)) + return -EFAULT; + if (count == 0) return 0; @@ -693,6 +696,9 @@ static inline long __arc_strnlen_user(const char __user *s, long n) long res, tmp1, cnt; char val; + if (!access_ok(s, 1)) + return 0; + __asm__ __volatile__( " mov %2, %1 \n" "1: ldb.ab %3, [%0, 1] \n" @@ -724,8 +730,8 @@ static inline long __arc_strnlen_user(const char __user *s, long n) #define INLINE_COPY_FROM_USER #define __clear_user(d, n) __arc_clear_user(d, n) -#define __strncpy_from_user(d, s, n) __arc_strncpy_from_user(d, s, n) -#define __strnlen_user(s, n) __arc_strnlen_user(s, n) +#define strncpy_from_user(d, s, n) __arc_strncpy_from_user(d, s, n) +#define strnlen_user(s, n) __arc_strnlen_user(s, n) #else extern unsigned long arc_clear_user_noinline(void __user *to, unsigned long n); @@ -734,8 +740,8 @@ extern long arc_strncpy_from_user_noinline (char *dst, const char __user *src, extern long arc_strnlen_user_noinline(const char __user *src, long n); #define __clear_user(d, n) arc_clear_user_noinline(d, n) -#define __strncpy_from_user(d, s, n) arc_strncpy_from_user_noinline(d, s, n) -#define __strnlen_user(s, n) arc_strnlen_user_noinline(s, n) +#define strncpy_from_user(d, s, n) arc_strncpy_from_user_noinline(d, s, n) +#define strnlen_user(s, n) arc_strnlen_user_noinline(s, n) #endif diff --git a/arch/hexagon/include/asm/uaccess.h b/arch/hexagon/include/asm/uaccess.h index c1019a736ff1..59aa3a50744f 100644 --- a/arch/hexagon/include/asm/uaccess.h +++ b/arch/hexagon/include/asm/uaccess.h @@ -57,23 +57,27 @@ unsigned long raw_copy_to_user(void __user *to, const void *from, __kernel_size_t __clear_user_hexagon(void __user *dest, unsigned long count); #define __clear_user(a, s) __clear_user_hexagon((a), (s)) -#define __strncpy_from_user(dst, src, n) hexagon_strncpy_from_user(dst, src, n) +extern long __strnlen_user(const char __user *src, long n); -/* get around the ifndef in asm-generic/uaccess.h */ -#define __strnlen_user __strnlen_user +static inline strnlen_user(const char __user *src, long n) +{ + if (!access_ok(src, 1)) + return 0; -extern long __strnlen_user(const char __user *src, long n); + return __strnlen_user(src, n); +} +/* get around the ifndef in asm-generic/uaccess.h */ +#define strnlen_user strnlen_user -static inline long hexagon_strncpy_from_user(char *dst, const char __user *src, - long n); +static inline long strncpy_from_user(char *dst, const char __user *src, long n); +#define strncpy_from_user strncpy_from_user #include /* Todo: an actual accelerated version of this. */ -static inline long hexagon_strncpy_from_user(char *dst, const char __user *src, - long n) +static inline long strncpy_from_user(char *dst, const char __user *src, long n) { - long res = __strnlen_user(src, n); + long res = strnlen_user(src, n); if (unlikely(!res)) return -EFAULT; diff --git a/arch/um/include/asm/uaccess.h b/arch/um/include/asm/uaccess.h index fe66d659acad..3bf209f683f8 100644 --- a/arch/um/include/asm/uaccess.h +++ b/arch/um/include/asm/uaccess.h @@ -23,16 +23,16 @@ extern unsigned long raw_copy_from_user(void *to, const void __user *from, unsigned long n); extern unsigned long raw_copy_to_user(void __user *to, const void *from, unsigned long n); -extern long __strncpy_from_user(char *dst, const char __user *src, long count); -extern long __strnlen_user(const void __user *str, long len); +extern long strncpy_from_user(char *dst, const char __user *src, long count); +extern long strnlen_user(const void __user *str, long len); extern unsigned long __clear_user(void __user *mem, unsigned long len); static inline int __access_ok(unsigned long addr, unsigned long size); /* Teach asm-generic/uaccess.h that we have C functions for these. */ #define __access_ok __access_ok #define __clear_user __clear_user -#define __strnlen_user __strnlen_user -#define __strncpy_from_user __strncpy_from_user +#define strnlen_user strnlen_user +#define strncpy_from_user strncpy_from_user #define INLINE_COPY_FROM_USER #define INLINE_COPY_TO_USER diff --git a/arch/um/kernel/skas/uaccess.c b/arch/um/kernel/skas/uaccess.c index 2dec915abe6f..205679cc4bb7 100644 --- a/arch/um/kernel/skas/uaccess.c +++ b/arch/um/kernel/skas/uaccess.c @@ -188,11 +188,14 @@ static int strncpy_chunk_from_user(unsigned long from, int len, void *arg) return 0; } -long __strncpy_from_user(char *dst, const char __user *src, long count) +long strncpy_from_user(char *dst, const char __user *src, long count) { long n; char *ptr = dst; + if (!access_ok(src, 1)) + return -EFAULT; + if (uaccess_kernel()) { strncpy(dst, (__force void *) src, count); return strnlen(dst, count); diff --git a/include/asm-generic/uaccess.h b/include/asm-generic/uaccess.h index 4973328f3c6e..c03889cc904c 100644 --- a/include/asm-generic/uaccess.h +++ b/include/asm-generic/uaccess.h @@ -246,11 +246,15 @@ extern int __get_user_bad(void) __attribute__((noreturn)); /* * Copy a null terminated string from userspace. */ -#ifndef __strncpy_from_user +#ifndef strncpy_from_user static inline long -__strncpy_from_user(char *dst, const char __user *src, long count) +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--) ; @@ -258,24 +262,12 @@ __strncpy_from_user(char *dst, const char __user *src, long count) } #endif -static inline long -strncpy_from_user(char *dst, const char __user *src, long count) -{ - if (!access_ok(src, 1)) - return -EFAULT; - return __strncpy_from_user(dst, src, count); -} - +#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 - */ -#ifndef __strnlen_user -#define __strnlen_user(s, n) (strnlen((s), (n)) + 1) -#endif - -/* + * * 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. @@ -284,8 +276,10 @@ static inline long strnlen_user(const char __user *src, long n) { if (!access_ok(src, 1)) return 0; - return __strnlen_user(src, n); + + return strnlen(src, n) + 1; } +#endif /* * Zero Userspace From patchwork Fri May 14 22:09:39 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Arnd Bergmann X-Patchwork-Id: 12259227 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=-17.7 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,INCLUDES_CR_TRAILER,INCLUDES_PATCH,MAILING_LIST_MULTI, SPF_HELO_NONE,SPF_PASS,USER_AGENT_GIT autolearn=unavailable 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 DA050C433B4 for ; Fri, 14 May 2021 22:11:27 +0000 (UTC) Received: from desiato.infradead.org (desiato.infradead.org [90.155.92.199]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 5CEF861442 for ; Fri, 14 May 2021 22:11:27 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 5CEF861442 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=kernel.org Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=linux-riscv-bounces+linux-riscv=archiver.kernel.org@lists.infradead.org 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=yHmmbaZ8CwsgReKVbjqjpjNow5dgSxJCcP56VUXrgN0=; b=XugyrF/2CENiRyUui8vgyN0ms R/Jz5qjrf18Irslwz/laG1CYIIAhG8+kf6f2AV7zYVpZudlB8ftfLsx9RHCU8ac2aWcn7ZXJ5vkk4 TWp+Yl5HakwHhRSZpeqnaYnG0FfQgAZWk7SQ/E2dYv44Gm+KukQxCa+xTIF5rIuH8KdkFRmiyX3S6 wKvjgupgiaH+sDW9L4Fu6Mv/lIYijeg55yEcadQfzINiJhX1FsaIgpD9tRNtAPbQW3cimMUOe/xrT hsdbda3OTLMoOde/sTFXBILDntNZ2Iq+qrtKwDWjn2QSM7jV0DAEqZuE4jKsH3xynBeTflZVImny5 R/W30a+kw==; Received: from localhost ([::1] helo=desiato.infradead.org) by desiato.infradead.org with esmtp (Exim 4.94 #2 (Red Hat Linux)) id 1lhg1T-0098EU-2z; Fri, 14 May 2021 22:11:07 +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 1lhg1M-0098Ci-Kr; Fri, 14 May 2021 22:11:00 +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=t67mP9peqauTq/lcJTAETubGLXwvfgTMxqXqturIzRY=; b=AAH7JgrZKtQxu6KephHcNkpdmF lAHjUC5ISYetkKfstE2u9zsRGjfm03A9Yf/5FbyA8cEO/xBhQbZJ/YzzJVvtVDOaE+DmszBFl/eu9 vmlH1FLuYACKsWr6nkK4QIPyvXNjv40Fg5Y1prifQ9LMSZ/f6cYOyQZVl14gawjoUAOl4/u9ETMbM eT72f4BK4cDJZq61TelkmajbmBJutcDmuZaXTRXpMZJLuPb3hD2soj1Ptz9IrsIaSJvYYcSoAqM66 bQXXKT8P0GyWa3Vd9rI8lAbdRmuWIbfK7XfMJ84vmhkyUgfEEYiKF6f+Xmh8UB1ZyEqqR3NMgCHLo cjHnhXQA==; Received: from mail.kernel.org ([198.145.29.99]) by bombadil.infradead.org with esmtps (Exim 4.94 #2 (Red Hat Linux)) id 1lhg1J-00CIBe-SK; Fri, 14 May 2021 22:10:59 +0000 Received: by mail.kernel.org (Postfix) with ESMTPSA id 80B576145B; Fri, 14 May 2021 22:10:53 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1621030257; bh=17R9VLcVBjZHK1p0TjuOM/WkP9/nvk9aZUliXX6kj64=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=oFeHzcUseyUMJp7uHOcMKKkxSBJPV4vnIneuQ7kwCXoJZ32vUX560eldPt9jad+Z1 7UoYcr3zmjwRw54gF9GzOqwDqMszyfrRDC3+AlrfNtKzhD4bCdtyOEGX4UQYQHI8zn dLFvCaj2WyzcTbrS63IWmlvbad4E3uYc68gB+NeBZFhuc4Qyp5L32N1T1nUbeJoFeg 0mbHJBFgjiQ39p2vtzkvxk5kUAwqnm+I+vIrWfrhHFDVYehcY3Y+L50Ei6IIqF6ula cp4fMELiDeHnlg+poHpg9Q4SgGwgEz05KI8c6SmwaEw2UvLv8utcS9YE4QmFJg+UBF +Z2NMWLNRUxew== 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 2/5] hexagon: use generic strncpy/strnlen from_user Date: Sat, 15 May 2021 00:09:39 +0200 Message-Id: <20210514220942.879805-3-arnd@kernel.org> X-Mailer: git-send-email 2.29.2 In-Reply-To: <20210514220942.879805-1-arnd@kernel.org> References: <20210514220942.879805-1-arnd@kernel.org> MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20210514_151057_981449_86251A50 X-CRM114-Status: GOOD ( 17.66 ) X-BeenThere: linux-riscv@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-riscv" Errors-To: linux-riscv-bounces+linux-riscv=archiver.kernel.org@lists.infradead.org From: Arnd Bergmann Most per-architecture versions of these functions are broken in some form, and they are almost certainly slower than the generic code as well. Remove the ones for hexagon and instead use the generic version. Signed-off-by: Arnd Bergmann --- arch/hexagon/Kconfig | 2 + arch/hexagon/include/asm/uaccess.h | 33 +------- arch/hexagon/kernel/hexagon_ksyms.c | 1 - arch/hexagon/mm/Makefile | 2 +- arch/hexagon/mm/strnlen_user.S | 126 ---------------------------- 5 files changed, 5 insertions(+), 159 deletions(-) delete mode 100644 arch/hexagon/mm/strnlen_user.S diff --git a/arch/hexagon/Kconfig b/arch/hexagon/Kconfig index 44a409967af1..c7ecb5e894d2 100644 --- a/arch/hexagon/Kconfig +++ b/arch/hexagon/Kconfig @@ -19,6 +19,8 @@ config HEXAGON # GENERIC_ALLOCATOR is used by dma_alloc_coherent() select GENERIC_ALLOCATOR select GENERIC_IRQ_SHOW + select GENERIC_STRNCPY_FROM_USER + select GENERIC_STRNLEN_USER select HAVE_ARCH_KGDB select HAVE_ARCH_TRACEHOOK select NEED_SG_DMA_LENGTH diff --git a/arch/hexagon/include/asm/uaccess.h b/arch/hexagon/include/asm/uaccess.h index 59aa3a50744f..d950df12d8c5 100644 --- a/arch/hexagon/include/asm/uaccess.h +++ b/arch/hexagon/include/asm/uaccess.h @@ -57,42 +57,13 @@ unsigned long raw_copy_to_user(void __user *to, const void *from, __kernel_size_t __clear_user_hexagon(void __user *dest, unsigned long count); #define __clear_user(a, s) __clear_user_hexagon((a), (s)) -extern long __strnlen_user(const char __user *src, long n); - -static inline strnlen_user(const char __user *src, long n) -{ - if (!access_ok(src, 1)) - return 0; - - return __strnlen_user(src, n); -} -/* get around the ifndef in asm-generic/uaccess.h */ +extern long strnlen_user(const char __user *src, long n); #define strnlen_user strnlen_user -static inline long strncpy_from_user(char *dst, const char __user *src, long n); +extern long strncpy_from_user(char *dst, const char __user *src, long n) #define strncpy_from_user strncpy_from_user #include -/* Todo: an actual accelerated version of this. */ -static inline long strncpy_from_user(char *dst, const char __user *src, long n) -{ - long res = strnlen_user(src, n); - - if (unlikely(!res)) - return -EFAULT; - - if (res > n) { - long left = raw_copy_from_user(dst, src, n); - if (unlikely(left)) - memset(dst + (n - left), 0, left); - return n; - } else { - long left = raw_copy_from_user(dst, src, res); - if (unlikely(left)) - memset(dst + (res - left), 0, left); - return res-1; - } -} #endif diff --git a/arch/hexagon/kernel/hexagon_ksyms.c b/arch/hexagon/kernel/hexagon_ksyms.c index 35545a7386a0..ec56ce2d92a2 100644 --- a/arch/hexagon/kernel/hexagon_ksyms.c +++ b/arch/hexagon/kernel/hexagon_ksyms.c @@ -15,7 +15,6 @@ EXPORT_SYMBOL(__clear_user_hexagon); EXPORT_SYMBOL(raw_copy_from_user); EXPORT_SYMBOL(raw_copy_to_user); EXPORT_SYMBOL(iounmap); -EXPORT_SYMBOL(__strnlen_user); EXPORT_SYMBOL(__vmgetie); EXPORT_SYMBOL(__vmsetie); EXPORT_SYMBOL(__vmyield); diff --git a/arch/hexagon/mm/Makefile b/arch/hexagon/mm/Makefile index 893838499591..49911a906fd0 100644 --- a/arch/hexagon/mm/Makefile +++ b/arch/hexagon/mm/Makefile @@ -4,4 +4,4 @@ # obj-y := init.o ioremap.o uaccess.o vm_fault.o cache.o -obj-y += copy_to_user.o copy_from_user.o strnlen_user.o vm_tlb.o +obj-y += copy_to_user.o copy_from_user.o vm_tlb.o diff --git a/arch/hexagon/mm/strnlen_user.S b/arch/hexagon/mm/strnlen_user.S deleted file mode 100644 index 4b5574a7cc9c..000000000000 --- a/arch/hexagon/mm/strnlen_user.S +++ /dev/null @@ -1,126 +0,0 @@ -/* SPDX-License-Identifier: GPL-2.0-only */ -/* - * User string length functions for kernel - * - * Copyright (c) 2010-2011, The Linux Foundation. All rights reserved. - */ - -#define isrc r0 -#define max r1 /* Do not change! */ - -#define end r2 -#define tmp1 r3 - -#define obo r6 /* off-by-one */ -#define start r7 -#define mod8 r8 -#define dbuf r15:14 -#define dcmp r13:12 - -/* - * The vector mask version of this turned out *really* badly. - * The hardware loop version also turned out *really* badly. - * Seems straight pointer arithmetic basically wins here. - */ - -#define fname __strnlen_user - - .text - .global fname - .type fname, @function - .p2align 5 /* why? */ -fname: - { - mod8 = and(isrc,#7); - end = add(isrc,max); - start = isrc; - } - { - P0 = cmp.eq(mod8,#0); - mod8 = and(end,#7); - dcmp = #0; - if (P0.new) jump:t dw_loop; /* fire up the oven */ - } - -alignment_loop: -fail_1: { - tmp1 = memb(start++#1); - } - { - P0 = cmp.eq(tmp1,#0); - if (P0.new) jump:nt exit_found; - P1 = cmp.gtu(end,start); - mod8 = and(start,#7); - } - { - if (!P1) jump exit_error; /* hit the end */ - P0 = cmp.eq(mod8,#0); - } - { - if (!P0) jump alignment_loop; - } - - - -dw_loop: -fail_2: { - dbuf = memd(start); - obo = add(start,#1); - } - { - P0 = vcmpb.eq(dbuf,dcmp); - } - { - tmp1 = P0; - P0 = cmp.gtu(end,start); - } - { - tmp1 = ct0(tmp1); - mod8 = and(end,#7); - if (!P0) jump end_check; - } - { - P0 = cmp.eq(tmp1,#32); - if (!P0.new) jump:nt exit_found; - if (!P0.new) start = add(obo,tmp1); - } - { - start = add(start,#8); - jump dw_loop; - } /* might be nice to combine these jumps... */ - - -end_check: - { - P0 = cmp.gt(tmp1,mod8); - if (P0.new) jump:nt exit_error; /* neverfound! */ - start = add(obo,tmp1); - } - -exit_found: - { - R0 = sub(start,isrc); - jumpr R31; - } - -exit_error: - { - R0 = add(max,#1); - jumpr R31; - } - - /* Uh, what does the "fixup" return here? */ - .falign -fix_1: - { - R0 = #0; - jumpr R31; - } - - .size fname,.-fname - - -.section __ex_table,"a" -.long fail_1,fix_1 -.long fail_2,fix_1 -.previous From patchwork Fri May 14 22:09:40 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Arnd Bergmann X-Patchwork-Id: 12259229 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=-17.7 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,INCLUDES_CR_TRAILER,INCLUDES_PATCH,MAILING_LIST_MULTI, SPF_HELO_NONE,SPF_PASS,USER_AGENT_GIT autolearn=unavailable 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 8B212C43460 for ; Fri, 14 May 2021 22:11:29 +0000 (UTC) Received: from desiato.infradead.org (desiato.infradead.org [90.155.92.199]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 0EED061442 for ; Fri, 14 May 2021 22:11:29 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 0EED061442 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=kernel.org Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=linux-riscv-bounces+linux-riscv=archiver.kernel.org@lists.infradead.org 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=3+OO0n0NnK15GET1TIjlAerKxPd5c9R7pTxSndEfhxo=; b=kh36vN/6ScAaU9cIuv23XY0or owgKLp2w7WxP5s3w0bXe0TE1mEhA1fg4wRshsgLCTwzESroCeBIvJwwGroUrendU8VfV0ZguOOzAi wGNDthH1mw08ARJeFsB4CWKBPFeroUybc0NIB7Gv+kXXlJTl2mmthGuv4HOi0TMh886whUP5Y4d1f sGfMFvRvc3jqx/S98nPutKb7ojFhnR9jdPks1W+cR9NwaSUV8oxm42ZCFenAESI4OXptZXFdDfgRo wypX/z7SJV0D5Lyn55/5WOAlZI3kUFpdIeimJaQyZIDj6N/4epSGt5QQavqBRLOfKnHRUmeut2vDg 1rwcD8X4A==; Received: from localhost ([::1] helo=desiato.infradead.org) by desiato.infradead.org with esmtp (Exim 4.94 #2 (Red Hat Linux)) id 1lhg1b-0098Hf-2j; Fri, 14 May 2021 22:11:15 +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 1lhg1R-0098Dy-1r; Fri, 14 May 2021 22:11:06 +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=vPNEWNfxajpOuZHDGEjaAwEFAAWSpJad8YLr9zZP008=; b=RCVye9/EaIhP6KB/HLQ2TA1EHS ZgU+MWxo63egwn2TsQqqZeeKxwJIDr60zj2Te7WalCrqXMYBe1OxYKDE3K3ytm1DFB6WUNZUichfe WKtCJ9kmLwKCU1RBxU7P8GpUm2CqZEXTWPPyRYAUm9GM5s4/3ieP8tBQ+sFlk5W+vIiq8qY+u2h5G B9fShNjmM4WyBXrpFy2BGt09WHjaJx7FRDbJ9FZrcLl5w4rp9ZcxuV6mvKwhbN9mQur2ROaqrJTcS pUV292hZ8QULwUa+mjNsr6Xstek593nrJYC2IX/woPqX5Zbmd5WXJsL8at8iTzndvAMHAAvQEufhI dOh2YbsQ==; Received: from mail.kernel.org ([198.145.29.99]) by bombadil.infradead.org with esmtps (Exim 4.94 #2 (Red Hat Linux)) id 1lhg1O-00CIC9-C7; Fri, 14 May 2021 22:11:03 +0000 Received: by mail.kernel.org (Postfix) with ESMTPSA id F00E661440; Fri, 14 May 2021 22:10:57 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1621030262; bh=n3IjLuSr3h2pDECqv/rSPCb8yGwiqfSbFhYV6qfMYfA=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=hMv1xdQUTM1N2R8mepU61Lbm+L/FkVGRGeZpBwh+Ez3YaZwxM62wJCy6X8lgiAjCi yHbIkRTukSzGyXNLkolOGVhrv/ePLTSa3IVc6r7hktpnuH/a2bp7IoG+npMP+poOc6 t4sABgyzrKkBwxnXdq84rK/HJfZcD4CWswhxbqIkbJQe663MJEz01vT3niqoOtJ6r1 L4PmOHQDEt/dnK7uVzX59S7ST5f7GGTPdRnemSpSCWtqg5jGxxZKzRHpiNhCr2XbMc kBfz19VaPeAm+WuzIEHk3epVkInnP9qvRWDsKNRyKQu7eAyHE9aYBRilGsN8tT8jhc z0iEBDnj5mcpQ== 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 3/5] arc: use generic strncpy/strnlen from_user Date: Sat, 15 May 2021 00:09:40 +0200 Message-Id: <20210514220942.879805-4-arnd@kernel.org> X-Mailer: git-send-email 2.29.2 In-Reply-To: <20210514220942.879805-1-arnd@kernel.org> References: <20210514220942.879805-1-arnd@kernel.org> MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20210514_151102_475259_0766054D X-CRM114-Status: GOOD ( 11.52 ) X-BeenThere: linux-riscv@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-riscv" Errors-To: linux-riscv-bounces+linux-riscv=archiver.kernel.org@lists.infradead.org From: Arnd Bergmann Most per-architecture versions of these functions are broken in some form, and they are almost certainly slower than the generic code as well. Remove the ones for arc and instead use the generic version. Signed-off-by: Arnd Bergmann --- arch/arc/Kconfig | 2 + arch/arc/include/asm/uaccess.h | 83 ++-------------------------------- arch/arc/mm/extable.c | 12 ----- 3 files changed, 7 insertions(+), 90 deletions(-) diff --git a/arch/arc/Kconfig b/arch/arc/Kconfig index 2d98501c0897..a38f403a8811 100644 --- a/arch/arc/Kconfig +++ b/arch/arc/Kconfig @@ -27,6 +27,8 @@ config ARC select GENERIC_PENDING_IRQ if SMP select GENERIC_SCHED_CLOCK select GENERIC_SMP_IDLE_THREAD + select GENERIC_STRNCPY_FROM_USER + select GENERIC_STRNLEN_USER select HAVE_ARCH_KGDB select HAVE_ARCH_TRACEHOOK select HAVE_ARCH_TRANSPARENT_HUGEPAGE if ARC_MMU_V4 diff --git a/arch/arc/include/asm/uaccess.h b/arch/arc/include/asm/uaccess.h index 3476348f361e..754a23f26736 100644 --- a/arch/arc/include/asm/uaccess.h +++ b/arch/arc/include/asm/uaccess.h @@ -655,96 +655,23 @@ static inline unsigned long __arc_clear_user(void __user *to, unsigned long n) return res; } -static inline long -__arc_strncpy_from_user(char *dst, const char __user *src, long count) -{ - long res = 0; - char val; - - if (!access_ok(src, 1)) - return -EFAULT; - - if (count == 0) - return 0; - - __asm__ __volatile__( - " mov lp_count, %5 \n" - " lp 3f \n" - "1: ldb.ab %3, [%2, 1] \n" - " breq.d %3, 0, 3f \n" - " stb.ab %3, [%1, 1] \n" - " add %0, %0, 1 # Num of NON NULL bytes copied \n" - "3: \n" - " .section .fixup, \"ax\" \n" - " .align 4 \n" - "4: mov %0, %4 # sets @res as -EFAULT \n" - " j 3b \n" - " .previous \n" - " .section __ex_table, \"a\" \n" - " .align 4 \n" - " .word 1b, 4b \n" - " .previous \n" - : "+r"(res), "+r"(dst), "+r"(src), "=r"(val) - : "g"(-EFAULT), "r"(count) - : "lp_count", "memory"); - - return res; -} - -static inline long __arc_strnlen_user(const char __user *s, long n) -{ - long res, tmp1, cnt; - char val; - - if (!access_ok(s, 1)) - return 0; - - __asm__ __volatile__( - " mov %2, %1 \n" - "1: ldb.ab %3, [%0, 1] \n" - " breq.d %3, 0, 2f \n" - " sub.f %2, %2, 1 \n" - " bnz 1b \n" - " sub %2, %2, 1 \n" - "2: sub %0, %1, %2 \n" - "3: ;nop \n" - " .section .fixup, \"ax\" \n" - " .align 4 \n" - "4: mov %0, 0 \n" - " j 3b \n" - " .previous \n" - " .section __ex_table, \"a\" \n" - " .align 4 \n" - " .word 1b, 4b \n" - " .previous \n" - : "=r"(res), "=r"(tmp1), "=r"(cnt), "=r"(val) - : "0"(s), "1"(n) - : "memory"); - - return res; -} - #ifndef CONFIG_CC_OPTIMIZE_FOR_SIZE #define INLINE_COPY_TO_USER #define INLINE_COPY_FROM_USER #define __clear_user(d, n) __arc_clear_user(d, n) -#define strncpy_from_user(d, s, n) __arc_strncpy_from_user(d, s, n) -#define strnlen_user(s, n) __arc_strnlen_user(s, n) #else extern unsigned long arc_clear_user_noinline(void __user *to, unsigned long n); -extern long arc_strncpy_from_user_noinline (char *dst, const char __user *src, - long count); -extern long arc_strnlen_user_noinline(const char __user *src, long n); - #define __clear_user(d, n) arc_clear_user_noinline(d, n) -#define strncpy_from_user(d, s, n) arc_strncpy_from_user_noinline(d, s, n) -#define strnlen_user(s, n) arc_strnlen_user_noinline(s, n) - #endif +extern long strncpy_from_user(char *dst, const char __user *src, long count); +#define strncpy_from_user(d, s, n) strncpy_from_user(d, s, n) +extern long strnlen_user(const char __user *src, long n); +#define strnlen_user(s, n) strnlen_user(s, n) + #include #include diff --git a/arch/arc/mm/extable.c b/arch/arc/mm/extable.c index b06b09ddf924..4e14c4244ea2 100644 --- a/arch/arc/mm/extable.c +++ b/arch/arc/mm/extable.c @@ -32,16 +32,4 @@ unsigned long arc_clear_user_noinline(void __user *to, } EXPORT_SYMBOL(arc_clear_user_noinline); -long arc_strncpy_from_user_noinline(char *dst, const char __user *src, - long count) -{ - return __arc_strncpy_from_user(dst, src, count); -} -EXPORT_SYMBOL(arc_strncpy_from_user_noinline); - -long arc_strnlen_user_noinline(const char __user *src, long n) -{ - return __arc_strnlen_user(src, n); -} -EXPORT_SYMBOL(arc_strnlen_user_noinline); #endif From patchwork Fri May 14 22:09:41 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Arnd Bergmann X-Patchwork-Id: 12259231 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=-17.7 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,INCLUDES_CR_TRAILER,INCLUDES_PATCH,MAILING_LIST_MULTI, SPF_HELO_NONE,SPF_PASS,USER_AGENT_GIT autolearn=unavailable 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 D310BC433ED for ; Fri, 14 May 2021 22:11:33 +0000 (UTC) Received: from desiato.infradead.org (desiato.infradead.org [90.155.92.199]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 5182661264 for ; Fri, 14 May 2021 22:11:33 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 5182661264 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=kernel.org Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=linux-riscv-bounces+linux-riscv=archiver.kernel.org@lists.infradead.org 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=BBeztAHnNFz3sFQhxd8J9epiLE3+ylM/IOw6imZKHAE=; b=mwgRaZ+yk4CeFYcENEYeRB8Va PJn91c9qF8QFMPTaMJr9ewXxPpBr8Mayw3qEMcy7qkS4SiWRdBw5oth5kASkekXzF5BeKnYSpYdmP Kdu5lEGADPBCFO3aZFc23bC2ktAf1PheQNUGXLIrkFXmqOvTpMG5v8xiaUQ7l1QGL5hsAUUFAivzh jaZxLtXIezaRKF2d5/RLIRcZwgM0UoGlyVbX1jsdVXM2/HvF+qqAPPws6wt6x24L6aSYRp7shlpJq QZyTGA3mR8+wI4AGSbnknNJBkqAtJyVqEQqOKRiVTJz+sHzVKxfhYYZE1vPi80/C5UGzFOFuZkBje WQS6if7sA==; Received: from localhost ([::1] helo=desiato.infradead.org) by desiato.infradead.org with esmtp (Exim 4.94 #2 (Red Hat Linux)) id 1lhg1g-0098KE-6l; Fri, 14 May 2021 22:11:20 +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 1lhg1V-0098FP-Du; Fri, 14 May 2021 22:11:09 +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=jV2mxN4BYOArlmQhqpMd21mJDoeBHfzht68iEFrQhRI=; b=1k3NybtSOo9hymPPyxz9JhqzLj BPMjRnRe+uWqE/cb4dbdDQc5E9I8BfJBrY3CuA9PTHYgCnGCM2WVt9qpIL0vFVb4/fGnLu3gQeG+h kw824lNvDCbVU52F6dT/lgoll0tkYjxQwWNGPSFP8XiSoUukURmhf5yWy7EietVzBv2XjDRZO+SQw DFm3a1ipFRSDNYdKtGsoltaqCacoAtuxQaRr4vJYrP4kR29RyoVkpknJIDbstMOePZKzqzq2ZYf+n n3Q1wKNuBS7gUAEVxmIELqhjx7qmTAkQBN3HH/VQDd57EJb7rQ39jaQuzkh42SbhD9x2KOfMQ4cfO UWYDVRzw==; Received: from mail.kernel.org ([198.145.29.99]) by bombadil.infradead.org with esmtps (Exim 4.94 #2 (Red Hat Linux)) id 1lhg1S-00CICa-Qd; Fri, 14 May 2021 22:11:08 +0000 Received: by mail.kernel.org (Postfix) with ESMTPSA id 70A936145B; Fri, 14 May 2021 22:11:02 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1621030266; bh=VrxpV/PlyT0N3FVgNX+0ElK7BNcTmlFqFdqTpIbA/vc=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=r6EVJRjLyTEsZ77Ez7LlKQO8neT5nJpKu+LyZeS00HAbC1xyg9Z61/7wXc+8J2w0y zIJ+7i4QsmAULSF+tE8NhM2K9mTBa7iUi6e4NGc5edP4Y+eTC3HFEdLNblooGh2+Us AJOfFVkyoOhCXhWgI/phpYCs43WsyReCjgQ1BO7rdJmfRdVNmOktH5LHVL2JbgZvaQ rkZNeZi+hYtl37vhAjg3sUg7OnOrgfXQ0XVTMfwOIbLmMjV4QbslD8S+NSH6yf0x0z cvmbwsShRh/hT1MJZFdon/TXfHhrPMxuTeRQAndnej2AiGRl7NwR8CabX6tXwgyPx/ 5DMTe6Pe7gmMg== 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 4/5] asm-generic: uaccess: remove inline strncpy_from_user/strnlen_user Date: Sat, 15 May 2021 00:09:41 +0200 Message-Id: <20210514220942.879805-5-arnd@kernel.org> X-Mailer: git-send-email 2.29.2 In-Reply-To: <20210514220942.879805-1-arnd@kernel.org> References: <20210514220942.879805-1-arnd@kernel.org> MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20210514_151106_925837_67B8137D X-CRM114-Status: GOOD ( 12.11 ) X-BeenThere: linux-riscv@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-riscv" Errors-To: linux-riscv-bounces+linux-riscv=archiver.kernel.org@lists.infradead.org From: Arnd Bergmann Consolidate the asm-generic implementation with the library version that is used everywhere else. Signed-off-by: Arnd Bergmann Reviewed-by: Geert Uytterhoeven Acked-by: Geert Uytterhoeven --- 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 372e4e69c43a..8e5241598007 100644 --- a/arch/m68k/Kconfig +++ b/arch/m68k/Kconfig @@ -16,8 +16,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 */ From patchwork Fri May 14 22:09:42 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Arnd Bergmann X-Patchwork-Id: 12259233 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=-17.7 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,INCLUDES_CR_TRAILER,INCLUDES_PATCH,MAILING_LIST_MULTI, SPF_HELO_NONE,SPF_PASS,USER_AGENT_GIT autolearn=unavailable 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 55A05C433B4 for ; Fri, 14 May 2021 22:11:47 +0000 (UTC) Received: from desiato.infradead.org (desiato.infradead.org [90.155.92.199]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id CCA43611BE for ; Fri, 14 May 2021 22:11:46 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org CCA43611BE Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=kernel.org Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=linux-riscv-bounces+linux-riscv=archiver.kernel.org@lists.infradead.org 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=DgVytqFjBuVcwQKGFL4Kyasoz451RwvwlrvkCBSqVBs=; b=fq9SZIMgrXINcpehq6Q1NtWWo HlYZZWzx5KQHZXR3p7P2/tVGxj+AG4OR6k4RWIyM8qkBPluYYw58zPGovWBydelPEObysgPJSmKd+ WGzOPsSJtr00N8n7NdW0uvE1T1Rfgm/hvvLDSd/o0QC8LBPgcR4EiDbB+cxjSrx/9KjuQkLkaCUGm WGZtitZcNTbPYHhTRMyj1rdZKEiNyJnqahfvkQM5sQGJvWFxc5qq6O2w2Ga53zavYFRwBJ4xUuDBB d53RlLULckwXUGX8UURtctO0maHnHsahJ3ncEGp+q4Zz1y+moI4yiDdDtvvgxaqkf5wn/A++tNsDU /0fjCS0EA==; Received: from localhost ([::1] helo=desiato.infradead.org) by desiato.infradead.org with esmtp (Exim 4.94 #2 (Red Hat Linux)) id 1lhg1k-0098Lr-1A; Fri, 14 May 2021 22:11:24 +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 1lhg1Z-0098H1-Ui; Fri, 14 May 2021 22:11:14 +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=9Fw1IFvYq/KjZTRKKWVzQNRcjazScUqC2uvuOnLwQW0=; b=bif7u50Z1vmQ/P8jtNsSrbo1eT t2UKZ6jqnjQ0hDNReppAYSQUYIJyKjvkNPf05AUPjVYVDVaPCqkUEcyBjMg2zPKQkFkX5Cx5mVaX5 aRIYgB+tSWPNP5st/OKkEWgQtJEHCnUbxXZhWYLrB+ex7aNWkqx9Cr5Re0I7eoI0ht28A5rSUgomP Z1HGXxg2J3f11LCfRIkg8SGteuX1I/JFhppMzBR7RV3bWPmCPLyXwRw5rmcOI8dZyDFSlpV3xIGw/ FMGuFLkLUaOd9IrPFF/JZum5gbB6kPJRvjWOgk42yFG4CCWTO97YPJzzUkJVRkczHdknct06+yfxS vN4u7IjA==; Received: from mail.kernel.org ([198.145.29.99]) by bombadil.infradead.org with esmtps (Exim 4.94 #2 (Red Hat Linux)) id 1lhg1X-00CID4-C2; Fri, 14 May 2021 22:11:12 +0000 Received: by mail.kernel.org (Postfix) with ESMTPSA id E33CE61442; Fri, 14 May 2021 22:11:06 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1621030271; bh=Lb/DGS9E/FUSMtSHAOCH5rcc8a7ucnqACx5B/SB9r64=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=PFd/GiDiedFSPvNHS9H1fNeAbz58qXcETZ9s7Wy+PgQIcJHm1fghiifKcptGhNQcH E9xwCqrZnkWmOkStLA1rGcLATFgz1srjJnsRR+SvXqlQ30B4ugit6miQJPmDBUyECE OYiQ2EtXiwqwKPnArJZ2GB/MI9ZoVyU/OlAdMXqkgw2DQ1T3ALdjynFTidsayU+Z/m R3ZuvZBAZ7uaKBLBrrVX/1gywhxhZpzl4fyzaEPLMuBdGe2PhtZvpdXI0qGUWY06Jp 26NUno68FQo0wFbx/BSrHTsv0FPFVjNgAr8L9PjM5+wfIU+1fYPgA2Sy1e7v8oh0pj kkG3PdWqkdfDA== 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/5] asm-generic: remove extra strn{cpy_from, len}_user declarations Date: Sat, 15 May 2021 00:09:42 +0200 Message-Id: <20210514220942.879805-6-arnd@kernel.org> X-Mailer: git-send-email 2.29.2 In-Reply-To: <20210514220942.879805-1-arnd@kernel.org> References: <20210514220942.879805-1-arnd@kernel.org> MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20210514_151111_469462_1CDE403A X-CRM114-Status: GOOD ( 10.21 ) X-BeenThere: linux-riscv@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-riscv" Errors-To: linux-riscv-bounces+linux-riscv=archiver.kernel.org@lists.infradead.org From: Arnd Bergmann As these are now in asm-generic, it's no longer necessary to declare them in the architecture. Signed-off-by: Arnd Bergmann --- arch/arc/include/asm/uaccess.h | 5 ----- arch/hexagon/include/asm/uaccess.h | 6 ------ arch/um/include/asm/uaccess.h | 5 +---- 3 files changed, 1 insertion(+), 15 deletions(-) diff --git a/arch/arc/include/asm/uaccess.h b/arch/arc/include/asm/uaccess.h index 754a23f26736..783bfdb3bfa3 100644 --- a/arch/arc/include/asm/uaccess.h +++ b/arch/arc/include/asm/uaccess.h @@ -667,11 +667,6 @@ extern unsigned long arc_clear_user_noinline(void __user *to, #define __clear_user(d, n) arc_clear_user_noinline(d, n) #endif -extern long strncpy_from_user(char *dst, const char __user *src, long count); -#define strncpy_from_user(d, s, n) strncpy_from_user(d, s, n) -extern long strnlen_user(const char __user *src, long n); -#define strnlen_user(s, n) strnlen_user(s, n) - #include #include diff --git a/arch/hexagon/include/asm/uaccess.h b/arch/hexagon/include/asm/uaccess.h index d950df12d8c5..ef5bfef8d490 100644 --- a/arch/hexagon/include/asm/uaccess.h +++ b/arch/hexagon/include/asm/uaccess.h @@ -57,12 +57,6 @@ unsigned long raw_copy_to_user(void __user *to, const void *from, __kernel_size_t __clear_user_hexagon(void __user *dest, unsigned long count); #define __clear_user(a, s) __clear_user_hexagon((a), (s)) -extern long strnlen_user(const char __user *src, long n); -#define strnlen_user strnlen_user - -extern long strncpy_from_user(char *dst, const char __user *src, long n) -#define strncpy_from_user strncpy_from_user - #include diff --git a/arch/um/include/asm/uaccess.h b/arch/um/include/asm/uaccess.h index 3bf209f683f8..191ef36dd543 100644 --- a/arch/um/include/asm/uaccess.h +++ b/arch/um/include/asm/uaccess.h @@ -23,16 +23,13 @@ extern unsigned long raw_copy_from_user(void *to, const void __user *from, unsigned long n); extern unsigned long raw_copy_to_user(void __user *to, const void *from, unsigned long n); -extern long strncpy_from_user(char *dst, const char __user *src, long count); -extern long strnlen_user(const void __user *str, long len); extern unsigned long __clear_user(void __user *mem, unsigned long len); static inline int __access_ok(unsigned long addr, unsigned long size); /* Teach asm-generic/uaccess.h that we have C functions for these. */ #define __access_ok __access_ok #define __clear_user __clear_user -#define strnlen_user strnlen_user -#define strncpy_from_user strncpy_from_user + #define INLINE_COPY_FROM_USER #define INLINE_COPY_TO_USER