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 00CB633D4E9 for ; Tue, 2 Jun 2026 08:47:04 +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=1780390028; cv=none; b=uA3Zlad4wwYIxcluHKMRmLyHeQn+lzCblDNqDbVNNoH1TntOWNyz2Oot+DkUfBKKxa3o+jcIL6o0eOfyw0s8AaPYtNA14ShP/lNxk+dkEOh3TalYQRxzna2pSGPUofsTMc1TmGj1G7M3Y0foD54+vuWLvEbbMxk3N4ukJoy4RxI= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1780390028; c=relaxed/simple; bh=CxukwNaaHfPCgLLuHd8f2xWMx67xuC8tWT39iKS4wZo=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=B7VS+N98gBhBOxUqDd7ue7TFFmqdBYrG+SgOwJDSreqSdpm9U/fSvlG1Vg2n57Zl8OXCmBwAgtXdJjKFlNnk22Us1v59LPYj7Na7HinbK0WipqZnp8m/PghYiwnRFzkzLd06fYu1FqLvfhVFull5Zeo2+1DS2IBt6GXDY0n0U7M= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=j3yh+9ql; 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="j3yh+9ql" Received: by smtp.kernel.org (Postfix) with ESMTPSA id A98DB1F00898; Tue, 2 Jun 2026 08:47:02 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org; s=k20260515; t=1780390024; bh=qIFh0EHf36xuaiQUrsEboCGTYqr33D+g0zvT7LVweRs=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=j3yh+9qljNOGvMJg2vjR4qqPnlP9WDre9stzGTtmF/drPyf1BBSbJ0/CfzvDlDBv0 wR0Jk0sSLAsz4Os1NthdWFpgQvCaE3kGcv7mRLyPPD1krz5P5SO+BLo/gHi+6N/SAx xxUk3pNiLi5dhp1UqIewE2g0mDkfNrMmCQqteAFeCP1NrxixFdO8tmQlY8W3zjKZo8 USPQYbrIyrjBy3yj4N1RwnQfmNCyKqjUNNrAAEufVD4xWSt/SRc7vakmEzryWGsboa lm5YamYmdrkgnOy3Ig2SUZZ6+vHKjjz9RMyoF5HAOB3l0RAxF7XZB+tyOw0HKrIAOi YKahPcXI6EY5Q== 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 v2 6/8] signal: Add unsafe_copy_siginfo_to_user() Date: Tue, 2 Jun 2026 10:46:35 +0200 Message-ID: <026832f540ef269cf8693e3c3b58c759d0f63544.1780389863.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=owGbwMvMwCV2d0KB2p7V54MZT6slMWTJzcjb+N5K92ag76ubrK0FRWzqipmM7zaLRT7+ZRnF3 z0p4G17RykLgxgXg6yYIsvx/9y7ZnR9Sc2fuksfZg4rE8gQBi5OAZjIDk9GhoMJ3Y/YzIMiPt/d LnpFrevwgd2HlvZOnRbR3Mc4Q4pFRJGRYYHZzE+JjnyFOk6Kv3g6HzFuXJMhVmC06QfnAvErHoH fmQA= 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