Skip to content

Commit f68b2d5

Browse files
btw616jmberg-intel
authored andcommitted
um: Preserve errno within signal handler
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>
1 parent 0f61b18 commit f68b2d5

1 file changed

Lines changed: 3 additions & 3 deletions

File tree

arch/um/os-Linux/signal.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,6 @@ void (*sig_info[NSIG])(int, struct siginfo *, struct uml_pt_regs *, void *mc) =
3636
static void sig_handler_common(int sig, struct siginfo *si, mcontext_t *mc)
3737
{
3838
struct uml_pt_regs r;
39-
int save_errno = errno;
4039

4140
r.is_user = 0;
4241
if (sig == SIGSEGV) {
@@ -50,8 +49,6 @@ static void sig_handler_common(int sig, struct siginfo *si, mcontext_t *mc)
5049
unblock_signals_trace();
5150

5251
(*sig_info[sig])(sig, si, &r, mc);
53-
54-
errno = save_errno;
5552
}
5653

5754
/*
@@ -207,8 +204,11 @@ static void hard_handler(int sig, siginfo_t *si, void *p)
207204
{
208205
ucontext_t *uc = p;
209206
mcontext_t *mc = &uc->uc_mcontext;
207+
int save_errno = errno;
210208

211209
(*handlers[sig])(sig, (struct siginfo *)si, mc);
210+
211+
errno = save_errno;
212212
}
213213

214214
void set_handler(int sig)

0 commit comments

Comments
 (0)