From: Richard Henderson <richard.henderson@linaro.org>
To: qemu-devel@nongnu.org
Subject: Re: [PATCH] linux-user: Check for EFAULT failure in nanosleep
Date: Thu, 10 Jul 2025 11:55:12 -0600 [thread overview]
Message-ID: <a78641f8-72ba-498f-a231-bb8adea9e072@linaro.org> (raw)
In-Reply-To: <20250710164355.1296648-1-peter.maydell@linaro.org>
On 7/10/25 10:43, Peter Maydell wrote:
> target_to_host_timespec() returns an error if the memory the guest
> passed us isn't actually readable. We check for this everywhere
> except the callsite in the TARGET_NR_nanosleep case, so this mistake
> was caught by a Coverity heuristic.
>
> Add the missing error checks to the calls that convert between the
> host and target timespec structs.
>
> Coverity: CID 1507104
> Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
> ---
> Tested via the LTP nanosleep tests, but they don't actually exercise
> the EFAULT codepaths...
>
> linux-user/syscall.c | 8 ++++++--
> 1 file changed, 6 insertions(+), 2 deletions(-)
Reviewed-by: Richard Henderson <richard.henderson@linaro.org>
r~
>
> diff --git a/linux-user/syscall.c b/linux-user/syscall.c
> index fc37028597c..c600d5ccc0e 100644
> --- a/linux-user/syscall.c
> +++ b/linux-user/syscall.c
> @@ -11630,10 +11630,14 @@ static abi_long do_syscall1(CPUArchState *cpu_env, int num, abi_long arg1,
> case TARGET_NR_nanosleep:
> {
> struct timespec req, rem;
> - target_to_host_timespec(&req, arg1);
> + if (target_to_host_timespec(&req, arg1)) {
> + return -TARGET_EFAULT;
> + }
> ret = get_errno(safe_nanosleep(&req, &rem));
> if (is_error(ret) && arg2) {
> - host_to_target_timespec(arg2, &rem);
> + if (host_to_target_timespec(arg2, &rem)) {
> + return -TARGET_EFAULT;
> + }
> }
> }
> return ret;
next prev parent reply other threads:[~2025-07-10 18:37 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-07-10 16:43 [PATCH] linux-user: Check for EFAULT failure in nanosleep Peter Maydell
2025-07-10 17:55 ` Richard Henderson [this message]
2025-07-10 17:56 ` Richard Henderson
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=a78641f8-72ba-498f-a231-bb8adea9e072@linaro.org \
--to=richard.henderson@linaro.org \
--cc=qemu-devel@nongnu.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).