[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [PATCH v2 4/9] bsd-user/syscall: Replace alloca() by g_new()
From: |
Peter Maydell |
Subject: |
Re: [PATCH v2 4/9] bsd-user/syscall: Replace alloca() by g_new() |
Date: |
Thu, 6 May 2021 16:58:47 +0100 |
On Thu, 6 May 2021 at 15:57, Warner Losh <imp@bsdimp.com> wrote:
> malloc, on the other hand, involves taking out a number of mutexes
> and similar things to obtain the memory, which may not necessarily
> be safe in all the contexts system calls can be called from. System
> calls are, typically, async safe and can be called from signal handlers.
> alloca() is async safe, while malloc() is not. So changing the calls
> from alloca to malloc makes calls to system calls in signal handlers
> unsafe and potentially introducing buggy behavior as a result.
malloc() should definitely be fine in this context. The syscall
emulation is called after the cpu_loop() in bsd-user has called
cpu_exec(). cpu_exec() calls into the JIT, which will malloc
all over the place if it needs to in the course of JITting things.
This code should never be being called from a (host) signal handler.
In upstream the signal handling code for bsd-user appears to
be missing entirely. For linux-user when we take a host signal
we merely arrange for the guest to take a guest signal, we
don't try to execute guest code directly from the host handler.
(There are some pretty hairy races in emulated signal handling:
we did a big overhaul of the linux-user code in that area a
while back. If your bsd-user code doesn't have the 'safe_syscall'
stuff it probably needs it. But that's more about races between
"guest code wants to execute a syscall" and "incoming signal"
where we could fail to exit EINTR from an emulated syscall if
the signal arrives in a bad window.)
thanks
-- PMM
- Re: [PATCH v2 4/9] bsd-user/syscall: Replace alloca() by g_new(), (continued)
- Re: [PATCH v2 4/9] bsd-user/syscall: Replace alloca() by g_new(), Eric Blake, 2021/05/06
- Re: [PATCH v2 4/9] bsd-user/syscall: Replace alloca() by g_new(), Warner Losh, 2021/05/06
- Re: [PATCH v2 4/9] bsd-user/syscall: Replace alloca() by g_new(), Eric Blake, 2021/05/06
- Re: [PATCH v2 4/9] bsd-user/syscall: Replace alloca() by g_new(), Warner Losh, 2021/05/06
- Re: [PATCH v2 4/9] bsd-user/syscall: Replace alloca() by g_new(), Eric Blake, 2021/05/06
- Re: [PATCH v2 4/9] bsd-user/syscall: Replace alloca() by g_new(), Peter Maydell, 2021/05/06
- Re: [PATCH v2 4/9] bsd-user/syscall: Replace alloca() by g_new(), Warner Losh, 2021/05/06
- Re: [PATCH v2 4/9] bsd-user/syscall: Replace alloca() by g_new(),
Peter Maydell <=
- Re: [PATCH v2 4/9] bsd-user/syscall: Replace alloca() by g_new(), Warner Losh, 2021/05/06
[PATCH v2 6/9] gdbstub: Only call cmd_parse_params() with non-NULL command schema, Philippe Mathieu-Daudé, 2021/05/06
[PATCH v2 7/9] gdbstub: Replace alloca() + memset(0) by g_new0(), Philippe Mathieu-Daudé, 2021/05/06
[PATCH v2 8/9] hw/misc/pca9552: Replace g_newa() by g_new(), Philippe Mathieu-Daudé, 2021/05/06
[PATCH v2 9/9] target/ppc/kvm: Replace alloca() by g_malloc(), Philippe Mathieu-Daudé, 2021/05/06
Re: [PATCH v2 0/9] misc: Replace alloca() by g_malloc(), Warner Losh, 2021/05/06