]> git.ipfire.org Git - thirdparty/qemu.git/commitdiff
linux-user: Check for EFAULT failure in nanosleep
authorPeter Maydell <peter.maydell@linaro.org>
Thu, 10 Jul 2025 16:43:54 +0000 (17:43 +0100)
committerMichael Tokarev <mjt@tls.msk.ru>
Sun, 13 Jul 2025 08:21:51 +0000 (11:21 +0300)
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>
Reviewed-by: Richard Henderson <richard.henderson@linaro.org>
Signed-off-by: Richard Henderson <richard.henderson@linaro.org>
Message-ID: <20250710164355.1296648-1-peter.maydell@linaro.org>
(cherry picked from commit c4828cb8502d0b2adc39b9cde93df7d2886df897)
Signed-off-by: Michael Tokarev <mjt@tls.msk.ru>
linux-user/syscall.c

index 9b397bac7edc229b17f05242b024dce3a075bb19..a8eea5dd52fa717eddbc0c5ae669cf9f3a8d717f 100644 (file)
@@ -11639,10 +11639,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;