From patchwork Thu Apr 18 20:02:03 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Michael Tokarev X-Patchwork-Id: 789857 Delivered-To: patch@linaro.org Received: by 2002:adf:e6ca:0:b0:346:15ad:a2a with SMTP id y10csp747489wrm; Thu, 18 Apr 2024 13:04:12 -0700 (PDT) X-Forwarded-Encrypted: i=2; AJvYcCVn8y+Ba7c8DuruQAeTzoq8v2HnzwfltzE3LMtnz6OR5VJXnhoJLag7eSqTX6A/IMtGNBupY4p4TkvtmVKzwBGc X-Google-Smtp-Source: AGHT+IFGCBq63D607+JWx9y/Gof1tUn+pzMw0Jtr4I9+hhJpGqjd9gFHWF6ZOWqZgaltS+uYoG3k X-Received: by 2002:a25:b317:0:b0:dcf:9018:67 with SMTP id l23-20020a25b317000000b00dcf90180067mr4090666ybj.42.1713470652616; Thu, 18 Apr 2024 13:04:12 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1713470652; cv=none; d=google.com; s=arc-20160816; b=uT56dBtpb0M73/Piy6FqeVeKxR292U0eItOghFuV9Iws2hajizWY36M+/jaycf9Xp7 wsYsMJanenaGSqq/qgnB0sVHJDlw98xvpehccVc4S7bK0igTBPUiL3JrxW2POcZ84l9X /jOKFM1u5lWU0SYz4Jg0RnY4ZDQjwccQQFuRpVesm8fgtN6NI16k1HeSZRGcPdajolVJ l5A4sQMYfDA9Tx8bFvb1RKa+7rXOAzy7/cBD04kVcNnr64xmdKHrg3YHH3NDuIIrP0Mc MbmCME+CMIKcV+7Vd9U+0uG3cTx3om9zwfjfe0CD+YE9g0s/pJRD5YPl0KnRLzVNvqfL xKfA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:content-transfer-encoding :mime-version:references:in-reply-to:message-id:date:subject:cc:to :from; bh=c2D3JGI20LJLWt+r4+mwa+QK1SZ7eJhW2z5cPvRg3+Q=; fh=s1gKKDhkFfgLQwKUGKCVkWVHhmnGAhWn+inBTI2XnyU=; b=e1icojrEIbLgR3cRylsGnE8C/B8bS5NXOW+KF7qZDO3jvFCQBhQiwVcpe2l9gwg9oH AUdQwVulNpaUJV5uWljAvnl8lZZvgUc4z8YCoItzkiSFLo/zKKcVfBu1ICyAjRxLqUC/ 6wTgyHjTtcloGz4Ku77aqh3GI5KxN1non2tK1jmnF9uHFfO9rCSWwWObyxDd7MsJjST8 cUZUR96xFMmn++rcheRtQRkegAcpmULa2TXiYSXWiAvUAUCyrTmpikarIwfHsRjZ4tDO aKYNzRcp91Cr6a0E1Y+76dEf8lbhmBTikGuOyrZoLnommgGXKuJNcsh1uUIwmbXeh5aL uTUA==; dara=google.com ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org" Return-Path: Received: from lists.gnu.org (lists.gnu.org. [209.51.188.17]) by mx.google.com with ESMTPS id m1-20020ac5cac1000000b004daa91c11f3si490631vkl.204.2024.04.18.13.04.12 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Thu, 18 Apr 2024 13:04:12 -0700 (PDT) Received-SPF: pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; Authentication-Results: mx.google.com; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org" Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1rxXxx-0001WB-Ic; Thu, 18 Apr 2024 16:02:43 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1rxXxq-0001Ur-S2; Thu, 18 Apr 2024 16:02:35 -0400 Received: from isrv.corpit.ru ([86.62.121.231]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1rxXxo-0005GT-Uj; Thu, 18 Apr 2024 16:02:34 -0400 Received: from tsrv.corpit.ru (tsrv.tls.msk.ru [192.168.177.2]) by isrv.corpit.ru (Postfix) with ESMTP id 45E395FE0A; Thu, 18 Apr 2024 23:02:27 +0300 (MSK) Received: from tls.msk.ru (mjt.wg.tls.msk.ru [192.168.177.130]) by tsrv.corpit.ru (Postfix) with SMTP id A59BBB93F0; Thu, 18 Apr 2024 23:02:24 +0300 (MSK) Received: (nullmailer pid 952845 invoked by uid 1000); Thu, 18 Apr 2024 20:02:24 -0000 From: Michael Tokarev To: qemu-devel@nongnu.org Cc: qemu-stable@nongnu.org, Richard Henderson , Alex Fan , =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= , Michael Tokarev Subject: [Stable-7.2.11 43/59] linux-user: Fix waitid return of siginfo_t and rusage Date: Thu, 18 Apr 2024 23:02:03 +0300 Message-Id: <20240418200224.952785-2-mjt@tls.msk.ru> X-Mailer: git-send-email 2.39.2 In-Reply-To: References: MIME-Version: 1.0 Received-SPF: pass client-ip=86.62.121.231; envelope-from=mjt@tls.msk.ru; helo=isrv.corpit.ru X-Spam_score_int: -68 X-Spam_score: -6.9 X-Spam_bar: ------ X-Spam_report: (-6.9 / 5.0 requ) BAYES_00=-1.9, RCVD_IN_DNSWL_HI=-5, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+patch=linaro.org@nongnu.org Sender: qemu-devel-bounces+patch=linaro.org@nongnu.org From: Richard Henderson The copy back to siginfo_t should be conditional only on arg3, not the specific values that might have been written. The copy back to rusage was missing entirely. Resolves: https://gitlab.com/qemu-project/qemu/-/issues/2262 Signed-off-by: Richard Henderson Tested-by: Alex Fan Reviewed-by: Philippe Mathieu-Daudé (cherry picked from commit f0907ff4cae743f1a4ef3d0a55a047029eed06ff) Signed-off-by: Michael Tokarev diff --git a/linux-user/syscall.c b/linux-user/syscall.c index aead0f6ac9..41017b0df2 100644 --- a/linux-user/syscall.c +++ b/linux-user/syscall.c @@ -8759,14 +8759,24 @@ static abi_long do_syscall1(CPUArchState *cpu_env, int num, abi_long arg1, #ifdef TARGET_NR_waitid case TARGET_NR_waitid: { + struct rusage ru; siginfo_t info; - info.si_pid = 0; - ret = get_errno(safe_waitid(arg1, arg2, &info, arg4, NULL)); - if (!is_error(ret) && arg3 && info.si_pid != 0) { - if (!(p = lock_user(VERIFY_WRITE, arg3, sizeof(target_siginfo_t), 0))) + + ret = get_errno(safe_waitid(arg1, arg2, (arg3 ? &info : NULL), + arg4, (arg5 ? &ru : NULL))); + if (!is_error(ret)) { + if (arg3) { + p = lock_user(VERIFY_WRITE, arg3, + sizeof(target_siginfo_t), 0); + if (!p) { + return -TARGET_EFAULT; + } + host_to_target_siginfo(p, &info); + unlock_user(p, arg3, sizeof(target_siginfo_t)); + } + if (arg5 && host_to_target_rusage(arg5, &ru)) { return -TARGET_EFAULT; - host_to_target_siginfo(p, &info); - unlock_user(p, arg3, sizeof(target_siginfo_t)); + } } } return ret;