[PATCH stable 6.12 9/9] um: Preserve errno within signal handler

From: Florian Fainelli

Date: Fri Jul 24 2026 - 17:42:26 EST


From: Tiwei Bie <tiwei.btw@xxxxxxxxxxxx>

commit f68b2d5a907b53eed99cf2efcaaae116df73c298 upstream

We rely on errno to determine whether a syscall has failed, so we
need to ensure that accessing errno is async-signal-safe. Currently,
we preserve the errno in sig_handler_common(), but it doesn't cover
every possible case. Let's do it in hard_handler() instead, which
is the signal handler we actually register.

Signed-off-by: Tiwei Bie <tiwei.btw@xxxxxxxxxxxx>
Link: https://patch.msgid.link/20260106001228.1531146-2-tiwei.btw@xxxxxxxxxxxx
Signed-off-by: Johannes Berg <johannes.berg@xxxxxxxxx>
[florian: hard_handler() in 6.12 retains the to_irq_stack/from_irq_stack
loop from before the upstream SMP refactoring; errno save/restore is wrapped
around that loop rather than replacing sig_handler_common's existing save/restore]
Signed-off-by: Florian Fainelli <florian.fainelli@xxxxxxxxxxxx>
---
arch/um/os-Linux/signal.c | 3 +++
1 file changed, 3 insertions(+)

diff --git a/arch/um/os-Linux/signal.c b/arch/um/os-Linux/signal.c
index b11ed66c8bb0..94abc9e3ec7e 100644
--- a/arch/um/os-Linux/signal.c
+++ b/arch/um/os-Linux/signal.c
@@ -190,6 +190,7 @@ static void hard_handler(int sig, siginfo_t *si, void *p)
{
ucontext_t *uc = p;
mcontext_t *mc = &uc->uc_mcontext;
+ int save_errno = errno;
unsigned long pending = 1UL << sig;

do {
@@ -227,6 +228,8 @@ static void hard_handler(int sig, siginfo_t *si, void *p)
if (!nested)
pending = from_irq_stack(nested);
} while (pending);
+
+ errno = save_errno;
}

void set_handler(int sig)
--
2.34.1