]> git.ipfire.org Git - thirdparty/kernel/stable.git/commitdiff
um: Preserve errno within signal handler
authorTiwei Bie <tiwei.btw@antgroup.com>
Tue, 6 Jan 2026 00:12:27 +0000 (08:12 +0800)
committerJohannes Berg <johannes.berg@intel.com>
Tue, 13 Jan 2026 18:39:09 +0000 (19:39 +0100)
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@antgroup.com>
Link: https://patch.msgid.link/20260106001228.1531146-2-tiwei.btw@antgroup.com
Signed-off-by: Johannes Berg <johannes.berg@intel.com>
arch/um/os-Linux/signal.c

index 327fb3c52fc79348e4c61366a9c607b46ffbe4c8..de372b936a8041fad5a8176ec05ac27a0f9adcfc 100644 (file)
@@ -36,7 +36,6 @@ void (*sig_info[NSIG])(int, struct siginfo *, struct uml_pt_regs *, void *mc) =
 static void sig_handler_common(int sig, struct siginfo *si, mcontext_t *mc)
 {
        struct uml_pt_regs r;
-       int save_errno = errno;
 
        r.is_user = 0;
        if (sig == SIGSEGV) {
@@ -50,8 +49,6 @@ static void sig_handler_common(int sig, struct siginfo *si, mcontext_t *mc)
                unblock_signals_trace();
 
        (*sig_info[sig])(sig, si, &r, mc);
-
-       errno = save_errno;
 }
 
 /*
@@ -207,8 +204,11 @@ 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;
 
        (*handlers[sig])(sig, (struct siginfo *)si, mc);
+
+       errno = save_errno;
 }
 
 void set_handler(int sig)