From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-alma10-1.taild15c8.ts.net [100.103.45.18]) (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 198693C76A0 for ; Fri, 22 May 2026 09:56:53 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=100.103.45.18 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1779443815; cv=none; b=NRSHFUblw9HsX2lDQmZM5zzBfXl3XCKrDGhSRyPsVIpci3CJLt4XaCz8dzCSoETbZtNhWwe/hSBnDP5JRcNp/JDIxn2WscZmQwX+/zXnrcFhjtA16u1TrM8FL4YmfFoJ8ewHr7IzmYTDs1m11dxa0qD1AlCHDhQJo6nsf+/ekD0= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1779443815; c=relaxed/simple; bh=CxukwNaaHfPCgLLuHd8f2xWMx67xuC8tWT39iKS4wZo=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=MKpRSPtG4wgN5o1QRnp6/BtBpHn8zzp3sHIyclpXfrXzU5l9gW5VYboao7jfyaFDwwHgCkjg3EsSxFLimn3zU1Y2d8BQu9LXhMYMwPDzutEjsd5HnHWqOzUcHVWveB21qC/kBrrYjpXPyIMuNj3y653f9hZYNtQmrjtfb7LHJWo= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=GK/+SCV1; arc=none smtp.client-ip=100.103.45.18 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="GK/+SCV1" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 1B38C1F00A3D; Fri, 22 May 2026 09:56:51 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org; s=k20260515; t=1779443813; bh=qIFh0EHf36xuaiQUrsEboCGTYqr33D+g0zvT7LVweRs=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=GK/+SCV19DAEftkWYjgk7KGHdZ26g54nGTimIvMTlmEhHFo2m7E4L3ZMiSkWmRjl9 LebQlYbpBMcDeyeowHBXdMpuNXCgGi4Eu4FKT+FdkFj2VbOtkr//nZPpuy6dbGOb5A 9Bx6QOLPalVGAj6A/SQG2+vTL8jBZ31/LtTA6ckpnSa2ubouz+qeLakiQfrYUoOxBf 3WkL6+qAS/KaszDC/ZXhZcajoroGm3oXukSR8XAd0S9lC5TsvARsLcu3+wFeV0lgxk HBCfvARIHuN9Zmhq96C2HqgJr6tJk/oGBWQUVy0IYQ9lH76UBLqERH6lKnBmBgQA+w Id6FLoY1W/yug== From: "Christophe Leroy (CS GROUP)" To: Michael Ellerman , Nicholas Piggin , Madhavan Srinivasan Cc: "Christophe Leroy (CS GROUP)" , linux-kernel@vger.kernel.org, linuxppc-dev@lists.ozlabs.org Subject: [PATCH v1 6/8] signal: Add unsafe_copy_siginfo_to_user() Date: Fri, 22 May 2026 11:56:06 +0200 Message-ID: <07697a42c8ac6ea6ac600cbf0dabbdcbf814da31.1779441786.git.chleroy@kernel.org> X-Mailer: git-send-email 2.54.0 In-Reply-To: References: Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-Developer-Signature: v=1; a=openpgp-sha256; l=2953; i=chleroy@kernel.org; h=from:subject:message-id; bh=CxukwNaaHfPCgLLuHd8f2xWMx67xuC8tWT39iKS4wZo=; b=owGbwMvMwCV2d0KB2p7V54MZT6slMWQJaNhfqth079aduR3nLp8+V6t/eN3eGzvOZTu0qwbf/ XhckW9vREcpC4MYF4OsmCLL8f/cu2Z0fUnNn7pLH2YOKxPIEAYuTgGYSNghRoaOKz3vFjPEsF7s ey3xdqeW1IL3oUHBYvVCQidv75VJXsbDyPAp4sfTzolvkqRnxjd/neo2u6hi+odXVcmaO4rd2hK Dq/kA X-Developer-Key: i=chleroy@kernel.org; a=openpgp; fpr=10FFE6F8B390DE17ACC2632368A92FEB01B8DD78 Content-Transfer-Encoding: 8bit In the same spirit as commit fb05121fd6a2 ("signal: Add unsafe_get_compat_sigset()"), implement an 'unsafe' version of copy_siginfo_to_user() in order to use it within user access blocks. For that, also add an 'unsafe' version of clear_user(). This commit adds the generic fallback for unsafe_clear_user(). Architectures wanting to use unsafe_copy_siginfo_to_user() within a user_access_begin() section have to make sure they have their own unsafe_clear_user(). Signed-off-by: Christophe Leroy (CS GROUP) --- include/linux/signal.h | 15 +++++++++++++++ include/linux/uaccess.h | 1 + kernel/signal.c | 5 ----- 3 files changed, 16 insertions(+), 5 deletions(-) diff --git a/include/linux/signal.h b/include/linux/signal.h index f19816832f05..3ee6c9463f8b 100644 --- a/include/linux/signal.h +++ b/include/linux/signal.h @@ -36,6 +36,21 @@ static inline void copy_siginfo_to_external(siginfo_t *to, int copy_siginfo_to_user(siginfo_t __user *to, const kernel_siginfo_t *from); int copy_siginfo_from_user(kernel_siginfo_t *to, const siginfo_t __user *from); +static __always_inline char __user *si_expansion(const siginfo_t __user *info) +{ + return ((char __user *)info) + sizeof(struct kernel_siginfo); +} + +#define unsafe_copy_siginfo_to_user(to, from, label) do { \ + siginfo_t __user *__ucs_to = to; \ + const kernel_siginfo_t *__ucs_from = from; \ + char __user *__ucs_expansion = si_expansion(__ucs_to); \ + \ + unsafe_copy_to_user(__ucs_to, __ucs_from, \ + sizeof(struct kernel_siginfo), label); \ + unsafe_clear_user(__ucs_expansion, SI_EXPANSION_SIZE, label); \ +} while (0) + enum siginfo_layout { SIL_KILL, SIL_TIMER, diff --git a/include/linux/uaccess.h b/include/linux/uaccess.h index 56328601218c..43e573b172a2 100644 --- a/include/linux/uaccess.h +++ b/include/linux/uaccess.h @@ -636,6 +636,7 @@ do { \ #define unsafe_put_user(x,p,e) unsafe_op_wrap(__put_user(x,p),e) #define unsafe_copy_to_user(d,s,l,e) unsafe_op_wrap(__copy_to_user(d,s,l),e) #define unsafe_copy_from_user(d,s,l,e) unsafe_op_wrap(__copy_from_user(d,s,l),e) +#define unsafe_clear_user(d, l, e) unsafe_op_wrap(__clear_user(d, l), e) static inline unsigned long user_access_save(void) { return 0UL; } static inline void user_access_restore(unsigned long flags) { } #endif /* !user_access_begin */ diff --git a/kernel/signal.c b/kernel/signal.c index 2d102e025883..2c5eb741fe8c 100644 --- a/kernel/signal.c +++ b/kernel/signal.c @@ -3493,11 +3493,6 @@ enum siginfo_layout siginfo_layout(unsigned sig, int si_code) return layout; } -static inline char __user *si_expansion(const siginfo_t __user *info) -{ - return ((char __user *)info) + sizeof(struct kernel_siginfo); -} - int copy_siginfo_to_user(siginfo_t __user *to, const kernel_siginfo_t *from) { char __user *expansion = si_expansion(to); -- 2.54.0