mirror of
https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
synced 2026-01-12 01:20:14 +00:00
1) Protect the event mask modification against the membarrier() IPI as
otherwise the RmW operation is unprotected and events might be lost.
2) Fix the weak symbol reference in rseq selftests
The current weak RSEQ symbols definitions which were added to allow
static linkage are not working correctly as the effectively re-define
the glibc symbols leading to multiple versions of the symbols when
compiled with -fno-common. Mark them as 'extern' to convert them from
weak symbol definitions to weak symbol references. That works with
static and dynamic linkage independent of -fcommon and -fno-common.
-----BEGIN PGP SIGNATURE-----
iQJHBAABCgAxFiEEQp8+kY+LLUocC4bMphj1TA10mKEFAmjaQc4THHRnbHhAbGlu
dXRyb25peC5kZQAKCRCmGPVMDXSYoTj1D/0Un97b1GJRNUjmvrhSE8uFy5RxgYdX
R2dJkfuQSF0fx4MzcrUg9b2KeklwDkYtq0YkmbStQeihp4jYpgODNFAdFdB4Cfhv
e1JfgQ6iTS9zWq625ImygHNZv5NOiDBxf9jtsRTUA3lv804taoS/jHost4Qi9HwO
jO9YoBrSmxZIZA1cPO9mA/AEpAdhKFxpwZK6yNNA4lH83gVhhSXKyEOFJQ0nWlZJ
pycEmwM+v9iW67QZEbWkEBPukflnMXYtcUDLmawYDsMZ2gsB4yPYvZwHNTeiB7gu
n0dfZH4jfw4DkO7MuU1CV1xlXhTO4sJQjmRsJuu2ypnZFVPh6iR+J2DxnZ5PcgvR
LifuEa/+mN/LM5/gjohDJwny10EXysrEDJ/vZUR4BBTdTsWK6FwLdSnTuP8WF3wo
LyY+PfeUmosHYOAa6Q8pLJUJzgXHtzlJLjVhYgb61dQjlgFuRB/0ksA8VoVeVhSz
6A5v/rcVoZIhRj/fxzsJOXtfP24ghIXtRFyfeDeNsWWlqEuL/X28xYf45YBjws7F
zApbCqeg+JYwJRaWmCDxjmmLsyMvpH3yujvlPZxuit6TX2PfxYG5CNpIxt192wZ2
fFk8qcsgJ5x/9ah5mpio7wHDESiDkdaPanYA+ercdXogbzI/8Y7fUua8RgJKm4Mj
3eo3tY3e8q9A3A==
=VV+N
-----END PGP SIGNATURE-----
Merge tag 'core-rseq-2025-09-29' of git://git.kernel.org/pub/scm/linux/kernel/git/tip/tip
Pull rseq updates from Thomas Gleixner:
"Two fixes for RSEQ:
- Protect the event mask modification against the membarrier() IPI as
otherwise the RmW operation is unprotected and events might be lost
- Fix the weak symbol reference in rseq selftests
The current weak RSEQ symbols definitions which were added to allow
static linkage are not working correctly as they effectively
re-define the glibc symbols leading to multiple versions of the
symbols when compiled with -fno-common.
Mark them as 'extern' to convert them from weak symbol definitions
to weak symbol references. That works with static and dynamic
linkage independent of -fcommon and -fno-common"
* tag 'core-rseq-2025-09-29' of git://git.kernel.org/pub/scm/linux/kernel/git/tip/tip:
rseq/selftests: Use weak symbol reference, not definition, to link with glibc
rseq: Protect event mask against membarrier IPI
137 lines
3.1 KiB
C
137 lines
3.1 KiB
C
/* SPDX-License-Identifier: GPL-2.0+ WITH Linux-syscall-note */
|
|
#ifndef _LINUX_RSEQ_H
|
|
#define _LINUX_RSEQ_H
|
|
|
|
#ifdef CONFIG_RSEQ
|
|
|
|
#include <linux/preempt.h>
|
|
#include <linux/sched.h>
|
|
|
|
#ifdef CONFIG_MEMBARRIER
|
|
# define RSEQ_EVENT_GUARD irq
|
|
#else
|
|
# define RSEQ_EVENT_GUARD preempt
|
|
#endif
|
|
|
|
/*
|
|
* Map the event mask on the user-space ABI enum rseq_cs_flags
|
|
* for direct mask checks.
|
|
*/
|
|
enum rseq_event_mask_bits {
|
|
RSEQ_EVENT_PREEMPT_BIT = RSEQ_CS_FLAG_NO_RESTART_ON_PREEMPT_BIT,
|
|
RSEQ_EVENT_SIGNAL_BIT = RSEQ_CS_FLAG_NO_RESTART_ON_SIGNAL_BIT,
|
|
RSEQ_EVENT_MIGRATE_BIT = RSEQ_CS_FLAG_NO_RESTART_ON_MIGRATE_BIT,
|
|
};
|
|
|
|
enum rseq_event_mask {
|
|
RSEQ_EVENT_PREEMPT = (1U << RSEQ_EVENT_PREEMPT_BIT),
|
|
RSEQ_EVENT_SIGNAL = (1U << RSEQ_EVENT_SIGNAL_BIT),
|
|
RSEQ_EVENT_MIGRATE = (1U << RSEQ_EVENT_MIGRATE_BIT),
|
|
};
|
|
|
|
static inline void rseq_set_notify_resume(struct task_struct *t)
|
|
{
|
|
if (t->rseq)
|
|
set_tsk_thread_flag(t, TIF_NOTIFY_RESUME);
|
|
}
|
|
|
|
void __rseq_handle_notify_resume(struct ksignal *sig, struct pt_regs *regs);
|
|
|
|
static inline void rseq_handle_notify_resume(struct ksignal *ksig,
|
|
struct pt_regs *regs)
|
|
{
|
|
if (current->rseq)
|
|
__rseq_handle_notify_resume(ksig, regs);
|
|
}
|
|
|
|
static inline void rseq_signal_deliver(struct ksignal *ksig,
|
|
struct pt_regs *regs)
|
|
{
|
|
scoped_guard(RSEQ_EVENT_GUARD)
|
|
__set_bit(RSEQ_EVENT_SIGNAL_BIT, ¤t->rseq_event_mask);
|
|
rseq_handle_notify_resume(ksig, regs);
|
|
}
|
|
|
|
/* rseq_preempt() requires preemption to be disabled. */
|
|
static inline void rseq_preempt(struct task_struct *t)
|
|
{
|
|
__set_bit(RSEQ_EVENT_PREEMPT_BIT, &t->rseq_event_mask);
|
|
rseq_set_notify_resume(t);
|
|
}
|
|
|
|
/* rseq_migrate() requires preemption to be disabled. */
|
|
static inline void rseq_migrate(struct task_struct *t)
|
|
{
|
|
__set_bit(RSEQ_EVENT_MIGRATE_BIT, &t->rseq_event_mask);
|
|
rseq_set_notify_resume(t);
|
|
}
|
|
|
|
/*
|
|
* If parent process has a registered restartable sequences area, the
|
|
* child inherits. Unregister rseq for a clone with CLONE_VM set.
|
|
*/
|
|
static inline void rseq_fork(struct task_struct *t, u64 clone_flags)
|
|
{
|
|
if (clone_flags & CLONE_VM) {
|
|
t->rseq = NULL;
|
|
t->rseq_len = 0;
|
|
t->rseq_sig = 0;
|
|
t->rseq_event_mask = 0;
|
|
} else {
|
|
t->rseq = current->rseq;
|
|
t->rseq_len = current->rseq_len;
|
|
t->rseq_sig = current->rseq_sig;
|
|
t->rseq_event_mask = current->rseq_event_mask;
|
|
}
|
|
}
|
|
|
|
static inline void rseq_execve(struct task_struct *t)
|
|
{
|
|
t->rseq = NULL;
|
|
t->rseq_len = 0;
|
|
t->rseq_sig = 0;
|
|
t->rseq_event_mask = 0;
|
|
}
|
|
|
|
#else
|
|
|
|
static inline void rseq_set_notify_resume(struct task_struct *t)
|
|
{
|
|
}
|
|
static inline void rseq_handle_notify_resume(struct ksignal *ksig,
|
|
struct pt_regs *regs)
|
|
{
|
|
}
|
|
static inline void rseq_signal_deliver(struct ksignal *ksig,
|
|
struct pt_regs *regs)
|
|
{
|
|
}
|
|
static inline void rseq_preempt(struct task_struct *t)
|
|
{
|
|
}
|
|
static inline void rseq_migrate(struct task_struct *t)
|
|
{
|
|
}
|
|
static inline void rseq_fork(struct task_struct *t, u64 clone_flags)
|
|
{
|
|
}
|
|
static inline void rseq_execve(struct task_struct *t)
|
|
{
|
|
}
|
|
|
|
#endif
|
|
|
|
#ifdef CONFIG_DEBUG_RSEQ
|
|
|
|
void rseq_syscall(struct pt_regs *regs);
|
|
|
|
#else
|
|
|
|
static inline void rseq_syscall(struct pt_regs *regs)
|
|
{
|
|
}
|
|
|
|
#endif
|
|
|
|
#endif /* _LINUX_RSEQ_H */
|