From: Tiwei Bie <[email protected]>

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 <[email protected]>
Link: https://patch.msgid.link/[email protected]
Signed-off-by: Johannes Berg <[email protected]>
[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 <[email protected]>
---
 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


Reply via email to