From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 2A3952F067F; Wed, 27 Aug 2025 20:24:22 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1756326262; cv=none; b=iuTitesTuvkDJpA8XjjFnBokuDxFHXwQDpclL7YIdKrkcBJ5LpIV5nV/K702nb5C/RhSD8Lw6Fz/c8KIcltWjNhrUA/iagmePzqY+onTwSZ0gVCjX9qJyBHsZGCcYWSJR8/Pd2wY+sjTnpTn3R/8lnxvVTKgzhqN+cd98Xno2gs= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1756326262; c=relaxed/simple; bh=9DGYOak7Ae5XlKZdQ526RyiUN8nEqGcQcjxucaA0vCE=; h=Message-ID:Date:From:To:Cc:Subject:References:MIME-Version: Content-Type; b=h1rXF0vfCwSSEOFZyy6IZBWtj0Z/wr/v1vWrW/OuZ5HGKVHvz2ewZkuLUDi3WAsI12fIJg1ZI0bkUZAR3npn6BDLIzva7IKSKnbPBZ+9ZmwGLKmzLzgMw1gdnBJU5s2hRWEzXTfCDwQsUW/1oBOM9BjQXe2IBjFFdqG4/3wTdjg= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=uD6fUQul; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="uD6fUQul" Received: by smtp.kernel.org (Postfix) with ESMTPSA id EC60DC4CEFA; Wed, 27 Aug 2025 20:24:21 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1756326262; bh=9DGYOak7Ae5XlKZdQ526RyiUN8nEqGcQcjxucaA0vCE=; h=Date:From:To:Cc:Subject:References:From; b=uD6fUQul7jGwMwd0pdicfjuDGMGvYaTnma/cswsDEi0rEctVtMwElXwDIHdTv/AbZ dyyGb3atnSgx+QnouhQCLZunOwkxUxjh/HbGQTJDSgDd2gXYRtWF7y00tHaG9DYijj Ffknt95uk6DXlUhqQPDIK90jecAXtlZNYxy0f5bksVsiUJYQvbpeZsUyUzzFcSsx2+ jpcrKQpZL/Ubtr8KFzCcTqwHrFjfrOwm9S1zZiG2meR6vp9k5DyyAaBmGBpHnXcy1o dEdOWtTCAKB3hm36EGOnBpeT0Nc2C2rJp52yqLZkua4Q0qiaT3NW3/34emUmhxhj4I z/6Y/Cm2PgFgQ== Received: from rostedt by gandalf with local (Exim 4.98.2) (envelope-from ) id 1urMhE-00000003kxM-3B90; Wed, 27 Aug 2025 16:24:40 -0400 Message-ID: <20250827202440.610489845@kernel.org> User-Agent: quilt/0.68 Date: Wed, 27 Aug 2025 16:15:51 -0400 From: Steven Rostedt To: linux-kernel@vger.kernel.org, linux-trace-kernel@vger.kernel.org, bpf@vger.kernel.org, x86@kernel.org Cc: Masami Hiramatsu , Mathieu Desnoyers , Josh Poimboeuf , Peter Zijlstra , Ingo Molnar , Jiri Olsa , Arnaldo Carvalho de Melo , Namhyung Kim , Thomas Gleixner , Andrii Nakryiko , Indu Bhagat , "Jose E. Marchesi" , Beau Belgrave , Jens Remus , Linus Torvalds , Andrew Morton , Florian Weimer , Sam James , Kees Cook , "Carlos O'Donell" Subject: [PATCH v10 03/11] x86/uaccess: Add unsafe_copy_from_user() implementation References: <20250827201548.448472904@kernel.org> Precedence: bulk X-Mailing-List: bpf@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 From: Josh Poimboeuf Add an x86 implementation of unsafe_copy_from_user() similar to the existing unsafe_copy_to_user(). Signed-off-by: Josh Poimboeuf Signed-off-by: Steven Rostedt (Google) --- arch/x86/include/asm/uaccess.h | 39 +++++++++++++++++++++++++--------- 1 file changed, 29 insertions(+), 10 deletions(-) diff --git a/arch/x86/include/asm/uaccess.h b/arch/x86/include/asm/uaccess.h index 3a7755c1a441..3caf02d0503e 100644 --- a/arch/x86/include/asm/uaccess.h +++ b/arch/x86/include/asm/uaccess.h @@ -599,7 +599,7 @@ _label: \ * We want the unsafe accessors to always be inlined and use * the error labels - thus the macro games. */ -#define unsafe_copy_loop(dst, src, len, type, label) \ +#define unsafe_copy_to_user_loop(dst, src, len, type, label) \ while (len >= sizeof(type)) { \ unsafe_put_user(*(type *)(src),(type __user *)(dst),label); \ dst += sizeof(type); \ @@ -607,15 +607,34 @@ _label: \ len -= sizeof(type); \ } -#define unsafe_copy_to_user(_dst,_src,_len,label) \ -do { \ - char __user *__ucu_dst = (_dst); \ - const char *__ucu_src = (_src); \ - size_t __ucu_len = (_len); \ - unsafe_copy_loop(__ucu_dst, __ucu_src, __ucu_len, u64, label); \ - unsafe_copy_loop(__ucu_dst, __ucu_src, __ucu_len, u32, label); \ - unsafe_copy_loop(__ucu_dst, __ucu_src, __ucu_len, u16, label); \ - unsafe_copy_loop(__ucu_dst, __ucu_src, __ucu_len, u8, label); \ +#define unsafe_copy_to_user(_dst, _src, _len, label) \ +do { \ + void __user *__dst = (_dst); \ + const void *__src = (_src); \ + size_t __len = (_len); \ + unsafe_copy_to_user_loop(__dst, __src, __len, u64, label); \ + unsafe_copy_to_user_loop(__dst, __src, __len, u32, label); \ + unsafe_copy_to_user_loop(__dst, __src, __len, u16, label); \ + unsafe_copy_to_user_loop(__dst, __src, __len, u8, label); \ +} while (0) + +#define unsafe_copy_from_user_loop(dst, src, len, type, label) \ + while (len >= sizeof(type)) { \ + unsafe_get_user(*(type *)(dst), (type __user *)(src), label); \ + dst += sizeof(type); \ + src += sizeof(type); \ + len -= sizeof(type); \ + } + +#define unsafe_copy_from_user(_dst, _src, _len, label) \ +do { \ + void *__dst = (_dst); \ + void __user *__src = (_src); \ + size_t __len = (_len); \ + unsafe_copy_from_user_loop(__dst, __src, __len, u64, label); \ + unsafe_copy_from_user_loop(__dst, __src, __len, u32, label); \ + unsafe_copy_from_user_loop(__dst, __src, __len, u16, label); \ + unsafe_copy_from_user_loop(__dst, __src, __len, u8, label); \ } while (0) #ifdef CONFIG_CC_HAS_ASM_GOTO_OUTPUT -- 2.50.1