From nobody Tue Dec 16 04:38:55 2025 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=linaro.org ARC-Seal: i=1; a=rsa-sha256; t=1752254663; cv=none; d=zohomail.com; s=zohoarc; b=QRl8SoNVErGemiIYv8W0M1y9zwImtcHsI301+4zeg1f0ZooW1EU+U4QU9RUg/MIwI0cdwsARXQ4YFiYXMgkq+tK6cVacP8dIeMiu+l6ApfQfevzBj88Y8yL3+e4kMj3yYTgvcidaaOIVwgwX1/+gd18palUwo8WODX7Ehur16zE= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1752254663; h=Content-Type:Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=F4bSMi3Nc0BLTJTdgmUkBHkPEiCcYcFpM0gdgLBlkKo=; b=hHv09XeqjQeFniR3TuqnZ3e1lDgGPabgfwg1UNWT9AH5Vnoau57zDZWITPo46ECjp6oXQeEm0Qc4WSNLB15pvEPpX/s6BIeJ6KHdZuBZJEdeAkVaM3pFpDQweffhnab02vXlwwM4pQgHEqsdvR2o4LxPtW1UiATzqmpMjbpv3Tk= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1752254663629508.76446979828586; Fri, 11 Jul 2025 10:24:23 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1uaHSj-0001jb-3x; Fri, 11 Jul 2025 13:23:05 -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 1uaHSh-0001ge-0O for qemu-devel@nongnu.org; Fri, 11 Jul 2025 13:23:03 -0400 Received: from mail-oi1-x22f.google.com ([2607:f8b0:4864:20::22f]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1uaHSe-0002zS-5H for qemu-devel@nongnu.org; Fri, 11 Jul 2025 13:23:02 -0400 Received: by mail-oi1-x22f.google.com with SMTP id 5614622812f47-40aef72f252so718698b6e.0 for ; Fri, 11 Jul 2025 10:22:59 -0700 (PDT) Received: from localhost.localdomain (fixed-187-189-51-143.totalplay.net. [187.189.51.143]) by smtp.gmail.com with ESMTPSA id 5614622812f47-4141c77ada0sm602041b6e.44.2025.07.11.10.22.57 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 11 Jul 2025 10:22:58 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1752254579; x=1752859379; darn=nongnu.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=F4bSMi3Nc0BLTJTdgmUkBHkPEiCcYcFpM0gdgLBlkKo=; b=RWg79fR5C7maHQ/SLuglI5rk46/iJtdhZYJ+Lc6czslJX6Drzo5GTYmFw06uvBE7Mq xOnXHyYMGR/zwFbY7B59VRsKuT+kH/f2a51kNidN2p1n1jDAJDYUN6mWql2wJNlMhck/ og5unExO/PJ6l4cLBWFpXV7nFdAqxj9Yre2WLhXmYrvFXQFivBeP1UqxR5GhukkakLBo IsiPYL0XbkiuDou1Ujcf8TLFLjjcQc3vWwQQP2qJs1ND8fAwwLHWQNZHf9AaGL69le3+ KUj3xObt+UIUXrwdG339O4vy+7FOCFO5aYfhQljOIWhEvFFs1R/dRNzdxi1MIYR4AnwX gnDw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1752254579; x=1752859379; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=F4bSMi3Nc0BLTJTdgmUkBHkPEiCcYcFpM0gdgLBlkKo=; b=HhNjyal1V+y7djd8n+f8n9qGqDbdGMjhfTa9U0cQI02fQpXE8ZqPrcbu4qh8TFmZJd 4VgkfALb+L0aL4Wj5nNOPRogi6QSiCjSHqfme7mOT1ODmARNLcUulk737T0g5rS6t1jk TGXQoRUGIdD7jzhe4jrx2R8YqQaC//SUTaKKc9weO/sOIenDefBbKibzGzTwzHfWogfC VmeY6vaftRamvRu2YEJjCgMUEZ6rAblBuLOGB9y39ivCjUrIVcgjgNUO2HW6ElutR9I0 zvnxZbM2OT4K2KEMPLpDkxPS5j+YAZUey0FcyjF0AQwE5yGsnKZsK7gE55dL2FcryJHX cw4g== X-Gm-Message-State: AOJu0Ywbwt1ParD0UMPxFiUa1uGp/PCKnCxZg+xCUQ8xGwvb2+zOZZXP f+gQehluIwpepmBukLXFdKqSeE9PYl3rolnqqG81bBhdf8fvz7LqukNYfYU4fRlCdrGn+Eg2lrG Yq9ID4CA= X-Gm-Gg: ASbGncvZmLGPCHrmAp5Zu82l5ZBKRlQ2V/sHADdDkMq94oKXBK07UNDx3dVLr9N6VHB NTD0oJ+dML7gFQaybNEJz/0Atft9mSb8A8Mq8rA54Q6Y4uqu4mAcdsjarxxbu4ueoiWsKi5cwoA XeOoklf1B6DVOe6qOrQfTezm+QqG86/0SNVUoGnOMpM0D30eEhUlbgCTquMCuChASkrhvbOqfgr 80TkS6Ko/SW7qt943Om7vNaPMk6xaijdsJr+tPSsbQ5KdEW6fr4ZX0UqumQr4sqFN1+VLyWMY3A LRrqgv3LE+iJdUiMWObuFFNwEAcgdmRIDXAe5BtmmnazFiyxnVg4HR5FvOOFAu1VxLf0SrzejI3 LpbAuRNRXag6NRudxM2EeaUu5lUmvW5/VZbzlgnfq+yTTY8OiTOqi8kJkn3bWn/QneKGT0BsG7i FjNHBuErk5kcnQ9QvF3N4= X-Google-Smtp-Source: AGHT+IHAYV5GrI+8/SU6OSnjlp8tsfE83mcXb72e6vGL95FOllWtqP1+KhScS7iW4u/dWcab89JuwA== X-Received: by 2002:a05:6808:1483:b0:408:e711:9aa with SMTP id 5614622812f47-4151008211bmr3271568b6e.37.1752254578622; Fri, 11 Jul 2025 10:22:58 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Cc: WANG Rui , =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= Subject: [PULL 1/9] fpu: Process float_muladd_negate_result after rounding Date: Fri, 11 Jul 2025 11:22:46 -0600 Message-ID: <20250711172254.229201-2-richard.henderson@linaro.org> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20250711172254.229201-1-richard.henderson@linaro.org> References: <20250711172254.229201-1-richard.henderson@linaro.org> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=2607:f8b0:4864:20::22f; envelope-from=richard.henderson@linaro.org; helo=mail-oi1-x22f.google.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, 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+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @linaro.org) X-ZM-MESSAGEID: 1752254666355116600 Changing the sign before rounding affects the correctness of the asymmetric rouding modes: float_round_up and float_round_down. Reported-by: WANG Rui Reviewed-by: Philippe Mathieu-Daud=C3=A9 Signed-off-by: Richard Henderson --- fpu/softfloat.c | 54 +++++++++++++++++++++++------ tests/tcg/multiarch/fnmsub.c | 37 ++++++++++++++++++++ fpu/softfloat-parts.c.inc | 4 --- tests/tcg/multiarch/Makefile.target | 1 + 4 files changed, 82 insertions(+), 14 deletions(-) create mode 100644 tests/tcg/multiarch/fnmsub.c diff --git a/fpu/softfloat.c b/fpu/softfloat.c index 34c962d6bd..8094358c2e 100644 --- a/fpu/softfloat.c +++ b/fpu/softfloat.c @@ -1731,11 +1731,8 @@ static float64 float64_round_pack_canonical(FloatPar= ts64 *p, return float64_pack_raw(p); } =20 -static float64 float64r32_round_pack_canonical(FloatParts64 *p, - float_status *s) +static float64 float64r32_pack_raw(FloatParts64 *p) { - parts_uncanon(p, s, &float32_params); - /* * In parts_uncanon, we placed the fraction for float32 at the lsb. * We need to adjust the fraction higher so that the least N bits are @@ -1776,6 +1773,13 @@ static float64 float64r32_round_pack_canonical(Float= Parts64 *p, return float64_pack_raw(p); } =20 +static float64 float64r32_round_pack_canonical(FloatParts64 *p, + float_status *s) +{ + parts_uncanon(p, s, &float32_params); + return float64r32_pack_raw(p); +} + static void float128_unpack_canonical(FloatParts128 *p, float128 f, float_status *s) { @@ -2240,7 +2244,12 @@ float16_muladd_scalbn(float16 a, float16 b, float16 = c, float16_unpack_canonical(&pc, c, status); pr =3D parts_muladd_scalbn(&pa, &pb, &pc, scale, flags, status); =20 - return float16_round_pack_canonical(pr, status); + /* Round before applying negate result. */ + parts_uncanon(pr, status, &float16_params); + if ((flags & float_muladd_negate_result) && !is_nan(pr->cls)) { + pr->sign ^=3D 1; + } + return float16_pack_raw(pr); } =20 float16 float16_muladd(float16 a, float16 b, float16 c, @@ -2260,7 +2269,12 @@ float32_muladd_scalbn(float32 a, float32 b, float32 = c, float32_unpack_canonical(&pc, c, status); pr =3D parts_muladd_scalbn(&pa, &pb, &pc, scale, flags, status); =20 - return float32_round_pack_canonical(pr, status); + /* Round before applying negate result. */ + parts_uncanon(pr, status, &float32_params); + if ((flags & float_muladd_negate_result) && !is_nan(pr->cls)) { + pr->sign ^=3D 1; + } + return float32_pack_raw(pr); } =20 float64 QEMU_SOFTFLOAT_ATTR @@ -2274,7 +2288,12 @@ float64_muladd_scalbn(float64 a, float64 b, float64 = c, float64_unpack_canonical(&pc, c, status); pr =3D parts_muladd_scalbn(&pa, &pb, &pc, scale, flags, status); =20 - return float64_round_pack_canonical(pr, status); + /* Round before applying negate result. */ + parts_uncanon(pr, status, &float64_params); + if ((flags & float_muladd_negate_result) && !is_nan(pr->cls)) { + pr->sign ^=3D 1; + } + return float64_pack_raw(pr); } =20 static bool force_soft_fma; @@ -2428,7 +2447,12 @@ float64 float64r32_muladd(float64 a, float64 b, floa= t64 c, float64_unpack_canonical(&pc, c, status); pr =3D parts_muladd_scalbn(&pa, &pb, &pc, 0, flags, status); =20 - return float64r32_round_pack_canonical(pr, status); + /* Round before applying negate result. */ + parts_uncanon(pr, status, &float32_params); + if ((flags & float_muladd_negate_result) && !is_nan(pr->cls)) { + pr->sign ^=3D 1; + } + return float64r32_pack_raw(pr); } =20 bfloat16 QEMU_FLATTEN bfloat16_muladd(bfloat16 a, bfloat16 b, bfloat16 c, @@ -2441,7 +2465,12 @@ bfloat16 QEMU_FLATTEN bfloat16_muladd(bfloat16 a, bf= loat16 b, bfloat16 c, bfloat16_unpack_canonical(&pc, c, status); pr =3D parts_muladd_scalbn(&pa, &pb, &pc, 0, flags, status); =20 - return bfloat16_round_pack_canonical(pr, status); + /* Round before applying negate result. */ + parts_uncanon(pr, status, &bfloat16_params); + if ((flags & float_muladd_negate_result) && !is_nan(pr->cls)) { + pr->sign ^=3D 1; + } + return bfloat16_pack_raw(pr); } =20 float128 QEMU_FLATTEN float128_muladd(float128 a, float128 b, float128 c, @@ -2454,7 +2483,12 @@ float128 QEMU_FLATTEN float128_muladd(float128 a, fl= oat128 b, float128 c, float128_unpack_canonical(&pc, c, status); pr =3D parts_muladd_scalbn(&pa, &pb, &pc, 0, flags, status); =20 - return float128_round_pack_canonical(pr, status); + /* Round before applying negate result. */ + parts_uncanon(pr, status, &float128_params); + if ((flags & float_muladd_negate_result) && !is_nan(pr->cls)) { + pr->sign ^=3D 1; + } + return float128_pack_raw(pr); } =20 /* diff --git a/tests/tcg/multiarch/fnmsub.c b/tests/tcg/multiarch/fnmsub.c new file mode 100644 index 0000000000..15dd41d3bd --- /dev/null +++ b/tests/tcg/multiarch/fnmsub.c @@ -0,0 +1,37 @@ +/* SPDX-License-Identifier: GPL-2.0-or-later */ + +#include +#include +#include + +union U { + double d; + unsigned long long l; +}; + +union U x =3D { .l =3D 0x4ff0000000000000ULL }; +union U y =3D { .l =3D 0x2ff0000000000000ULL }; +union U r; + +int main() +{ +#ifdef FE_DOWNWARD + fesetround(FE_DOWNWARD); + +#if defined(__loongarch__) + asm("fnmsub.d %0, %1, %1, %2" : "=3Df"(r.d) : "f"(x.d), "f"(y.d)); +#elif defined(__powerpc64__) + asm("fnmsub %0,%1,%1,%2" : "=3Df"(r.d) : "f"(x.d), "f"(y.d)); +#elif defined(__s390x__) && 0 /* need -march=3Dz14 */ + asm("vfnms %0,%1,%1,%2,0,3" : "=3Df"(r.d) : "f"(x.d), "f"(y.d)); +#else + r.d =3D -fma(x.d, x.d, -y.d); +#endif + + if (r.l !=3D 0xdfefffffffffffffULL) { + printf("r =3D %.18a (%016llx)\n", r.d, r.l); + return 1; + } +#endif + return 0; +} diff --git a/fpu/softfloat-parts.c.inc b/fpu/softfloat-parts.c.inc index 171bfd06e3..5e0438fc0b 100644 --- a/fpu/softfloat-parts.c.inc +++ b/fpu/softfloat-parts.c.inc @@ -708,10 +708,6 @@ static FloatPartsN *partsN(muladd_scalbn)(FloatPartsN = *a, FloatPartsN *b, return_normal: a->exp +=3D scale; finish_sign: - if (flags & float_muladd_negate_result) { - a->sign ^=3D 1; - } - /* * All result types except for "return the default NaN * because this is an Invalid Operation" go through here; diff --git a/tests/tcg/multiarch/Makefile.target b/tests/tcg/multiarch/Make= file.target index 45c9cfe18c..bfdf7197a7 100644 --- a/tests/tcg/multiarch/Makefile.target +++ b/tests/tcg/multiarch/Makefile.target @@ -29,6 +29,7 @@ run-float_%: float_% $(call run-test,$<, $(QEMU) $(QEMU_OPTS) $<) $(call conditional-diff-out,$<,$(SRC_PATH)/tests/tcg/$(TARGET_NAME)/$<.re= f) =20 +fnmsub: LDFLAGS+=3D-lm =20 testthread: LDFLAGS+=3D-lpthread =20 --=20 2.43.0 From nobody Tue Dec 16 04:38:55 2025 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=linaro.org ARC-Seal: i=1; a=rsa-sha256; t=1752254680; cv=none; d=zohomail.com; s=zohoarc; b=GGJP0WbEnGFKklcK9GlrhTXaSrrWrkvvzS3Y7DaFCYaTRUdufH+0A3c81rrjsq5c63o1KIDR+7Up2JKSz4TolgUJa+lp2dB0ZgtkChk+TUos7BmXyg4j4E4ctoybYow4O+ta3gd4mkhMbPH0LgUN7C0vsTpmahAbQEDRUx7mnTA= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1752254680; h=Content-Type:Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=6qpBCj8B3P31E5+6mdM0X+L5puDyaY4r0XRv24VE9kQ=; b=ZVZylHMpKBoHBxlgnE+lH9zETRu7Jy1nULQlM30IxkObOaK/l1w3mj3UmYNaKd0h2Odhqw8Z/y1B+rVnL4aPzJK/FOtAfgTGvafXOm77AkghD5XQw0CHmhX62T5qfLYbFzFMD7ZhzkKvGBOdDY1cxPzgC+cvHgvv6+3Fq8Hq0WI= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1752254680797492.93814838637377; Fri, 11 Jul 2025 10:24:40 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1uaHSj-0001jR-48; Fri, 11 Jul 2025 13:23:05 -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 1uaHSh-0001h4-Dq for qemu-devel@nongnu.org; Fri, 11 Jul 2025 13:23:03 -0400 Received: from mail-oi1-x229.google.com ([2607:f8b0:4864:20::229]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1uaHSf-0002zp-L2 for qemu-devel@nongnu.org; Fri, 11 Jul 2025 13:23:03 -0400 Received: by mail-oi1-x229.google.com with SMTP id 5614622812f47-40a6692b75cso1515176b6e.1 for ; Fri, 11 Jul 2025 10:23:01 -0700 (PDT) Received: from localhost.localdomain (fixed-187-189-51-143.totalplay.net. [187.189.51.143]) by smtp.gmail.com with ESMTPSA id 5614622812f47-4141c77ada0sm602041b6e.44.2025.07.11.10.22.58 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 11 Jul 2025 10:22:59 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1752254580; x=1752859380; darn=nongnu.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=6qpBCj8B3P31E5+6mdM0X+L5puDyaY4r0XRv24VE9kQ=; b=gFdtRsZcfqEYuUu9CvxGcWca5w5aVKN/Kk7uVDGiHgxmN09C+iT4YMLkr+n9PkRTbM SDVqpIOvFo/AcNRSViETzZ5dX6rwOjWujXYWB0msi7fab6CZr+MfK0XECDME8JlaJJdX sI1RkccnzxHx+fDQOqA3xu7/cVDt46mz5+jGFh2gU2k1kgpqs03ykHv5MtHJEq50ML41 vSoIhZEX5Kso1BLpEudV/1dtAWWiiL8EVA1iHMSU5h7n+NJwylvhq+ilv9MRivxPi3ma t71asZcxHw5LKVvHQFO+9mXgY5ANBx/ppHIa08/lHg5+kW86tUmoX+DG+vntYiTKkzvv OsJQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1752254580; x=1752859380; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=6qpBCj8B3P31E5+6mdM0X+L5puDyaY4r0XRv24VE9kQ=; b=kUnwWOJh6khNe7Qu9HE5l5e4ARDPaQ4v1VT4iSI7iBH+Lc4s73dJA6ujeYW9M/fxRF jDMr78RBWkp2jxR+7OY/Hf1FWKtJfaqyM0HskCmlbZdKHqhHbr1htShd9PyguLNfVZ6Z Fy7YAAnWu4vD4czVF7CiuJzLu1fH+UtgrxcmFSM3tjzDE0Wzc8y/gm8lWMWyAGubA9nA A1OtKiqQwzo2wlcoYv9pXsoNUBHwtYYa4XUrIQbwvPR5sSScLALPxzJyOb4VyIYbZcZq oXW0FPhATyDsEhoxuTC7dsGaeX6CTxc254vx24N98RHIJbpjIxPFMqzS2ljv006bvJC0 PwOQ== X-Gm-Message-State: AOJu0YxxJ/OwTrrqFoBADBQ8LftIyy4H17ACWUTSEKC2zptFTEiHz2eL QsuW+rSz0RAm2IYE/u4gxzR7mOosBicL7gGVk/sBlb3ukYGlj1y0alqgU9pq8Eq8XGtH+nsZfve KgvVJ4V4= X-Gm-Gg: ASbGnctZhxfL861is7B2fspVMHzHyqf9dhNI93G6WVjM+ByB/2eFwh92SPj7ePVc10b xhofBETtiu5aUJZOo869L+yDFZgKa50ju/MrXEQN0Uv7xQ5Qe1TYL/wMKyW0CEls4IS9jjwZBea sRWIbJ8ILWPh6DQSnUvytajuk8+w+abBzHSyDWSlG/4hCd0hFmHXy8W54lUuIvhgk5qTWjAL8jT gJAOW/58A9sr+sF0hWEJMhnzvnHVwfxAKkQmxQs1hidGef0K3gb0bSyI6Et40CeUJAi91b4ySA3 qqAVOFbkCRhFOvOUp4XXHk7E05rhYFqy/FEbIuM/DwurCTgpyz0Dk4o+5MQduzeEzPn2FOjCaFZ hNcstmbK97KcT1lVbARaIlYGvsu/S3axm0IFxWOtclmSjtxIF8FQGoZ2mmrKB6afR0e3lJYfRR+ Z6GEu7C/SJbyN/xPglEL0= X-Google-Smtp-Source: AGHT+IFjzrbmncPLFSof2n6hqBlix3Hxng8UxTF+98oEWqkCL+svbgzX3lMO4hwMKO3iSZbe+Y6KtQ== X-Received: by 2002:a05:6808:ec3:b0:40b:555b:9a9a with SMTP id 5614622812f47-4153a27afe3mr2435391b6e.36.1752254580120; Fri, 11 Jul 2025 10:23:00 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Cc: Peter Maydell , =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= Subject: [PULL 2/9] linux-user: Implement fchmodat2 syscall Date: Fri, 11 Jul 2025 11:22:47 -0600 Message-ID: <20250711172254.229201-3-richard.henderson@linaro.org> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20250711172254.229201-1-richard.henderson@linaro.org> References: <20250711172254.229201-1-richard.henderson@linaro.org> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=2607:f8b0:4864:20::229; envelope-from=richard.henderson@linaro.org; helo=mail-oi1-x229.google.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, 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+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @linaro.org) X-ZM-MESSAGEID: 1752254681890116600 From: Peter Maydell The fchmodat2 syscall is new from Linux 6.6; it is like the existing fchmodat syscall except that it takes a flags parameter. Resolves: https://gitlab.com/qemu-project/qemu/-/issues/3019 Signed-off-by: Peter Maydell Reviewed-by: Philippe Mathieu-Daud=C3=A9 Reviewed-by: Richard Henderson Signed-off-by: Richard Henderson Message-ID: <20250710113123.1109461-1-peter.maydell@linaro.org> --- linux-user/syscall.c | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/linux-user/syscall.c b/linux-user/syscall.c index fc37028597..e1b1476936 100644 --- a/linux-user/syscall.c +++ b/linux-user/syscall.c @@ -790,6 +790,10 @@ safe_syscall6(ssize_t, copy_file_range, int, infd, lof= f_t *, pinoff, int, outfd, loff_t *, poutoff, size_t, length, unsigned int, flags) #endif +#if defined(TARGET_NR_fchmodat2) && defined(__NR_fchmodat2) +safe_syscall4(int, fchmodat2, int, dfd, const char *, filename, + unsigned short, mode, unsigned int, flags) +#endif =20 /* We do ioctl like this rather than via safe_syscall3 to preserve the * "third argument might be integer or pointer or not present" behaviour of @@ -10713,6 +10717,15 @@ static abi_long do_syscall1(CPUArchState *cpu_env,= int num, abi_long arg1, ret =3D get_errno(fchmodat(arg1, p, arg3, 0)); unlock_user(p, arg2, 0); return ret; +#endif +#if defined(TARGET_NR_fchmodat2) && defined(__NR_fchmodat2) + case TARGET_NR_fchmodat2: + if (!(p =3D lock_user_string(arg2))) { + return -TARGET_EFAULT; + } + ret =3D get_errno(safe_fchmodat2(arg1, p, arg3, arg4)); + unlock_user(p, arg2, 0); + return ret; #endif case TARGET_NR_getpriority: /* Note that negative values are valid for getpriority, so we must --=20 2.43.0 From nobody Tue Dec 16 04:38:55 2025 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=linaro.org ARC-Seal: i=1; a=rsa-sha256; t=1752254620; cv=none; d=zohomail.com; s=zohoarc; b=Q+KovSULqCRdaITnsKssbQHbeAFbc+5rX/hTIpjsYk2ZdWTumElIjYmKHJNECKNKDyR+KceYAKhcq9bDzbMbGy1KtDjeEvjeG4yyTGnYOuju3fUqXA6+3Tvqyk3sAKtgee/7fjux2T6AYrch/LjtedtfBHmMbFIEEQUbIZzSbos= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1752254620; h=Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=S6Y1zvZ+TyIUNt8VCXescuyiWq5vvXL67wwRHefGUWY=; b=nT+VwJSVvQ/A/4KE6JWygktsxoMuf2EaxuovPHfbqZIbUGHyxMDIIRWftWglPIhvtSgZa0+L767fF7Ml9X8gZhNX9oxikUwcWEMcvsp8DTK0tNIF4XBvd9g7nTjuZI+NIil1WLkoU/cMPriQJ2z72r5aGyrWatiUkJIGYzhQWe4= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1752254620547474.5538364423669; Fri, 11 Jul 2025 10:23:40 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1uaHSj-0001ky-ON; Fri, 11 Jul 2025 13:23:05 -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 1uaHSi-0001hk-91 for qemu-devel@nongnu.org; Fri, 11 Jul 2025 13:23:04 -0400 Received: from mail-oi1-x234.google.com ([2607:f8b0:4864:20::234]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1uaHSg-00030H-DU for qemu-devel@nongnu.org; Fri, 11 Jul 2025 13:23:03 -0400 Received: by mail-oi1-x234.google.com with SMTP id 5614622812f47-40ad1f7c23bso1349109b6e.2 for ; Fri, 11 Jul 2025 10:23:01 -0700 (PDT) Received: from localhost.localdomain (fixed-187-189-51-143.totalplay.net. [187.189.51.143]) by smtp.gmail.com with ESMTPSA id 5614622812f47-4141c77ada0sm602041b6e.44.2025.07.11.10.23.00 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 11 Jul 2025 10:23:00 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1752254581; x=1752859381; darn=nongnu.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=S6Y1zvZ+TyIUNt8VCXescuyiWq5vvXL67wwRHefGUWY=; b=xMmj3gPs3nz1+HV28woHf+2JVOOFrpFuA5BaBy3uYzU+zcs48F4oVnD8k0dH450JgO zBppeikr7EEt+JQc8Bve++o1nGeRuBZyuZ9rfd0gUzg5GSL/T1boVsNjN2b2qtNMnTrZ 3d7ENnATRS8TOgrmxVPzE6fhjrUc7fmCbRBvrey1yD91y+B0b5hRkmcsMdBSO4oe4T1q rQCti75kBNKMJXlqFJ1XBnQo1EaT0W51WOh/ddJZ/pQ8PTSZ4cLUdHIVKXPdIBE32OgF gS2DMOnA7p7YwQfOWeL1qDrqzyyM190NMbEupVo8LW7v+wPPfUYB7ayDYWcCsveoWxlY kxCg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1752254581; x=1752859381; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=S6Y1zvZ+TyIUNt8VCXescuyiWq5vvXL67wwRHefGUWY=; b=ATAJWDbyT+VzIznQ9JhJxTkdJOD0Fqi7WDt5H9ye4lVs9D8NzpIlpq58AnEF9q6xMS S5TjbSZe5zzPholsX+CKtgMwkWAwPGOrM93UXUHtyDn6Y559MllM4jFCEPich39l+iOD 8yKU9U7DTrXqrnJJo/E5XGJKqeeL2KdBagMVtfQ66O0tvaDEutYtBq7wavz8inGQeZ+k hdqykhlM+W2A/A7B5ojLdqjvhsOsVwel+3lZJJmEWb4a17Pmb5qqhGwXReb1XuUlgL9O mwjB3W0hczBQpxO8rM3vC6+AOSiNgchSNyz1M03IWc1vkCz7ziOKcZktG0TRVNrfcAOC THBA== X-Gm-Message-State: AOJu0YzoCsvcQr7YfI/C2ZA693epw+vtRNIWC7SEmMKpiNHh7Qo/Psu0 I8PTKBuFV4jVfrkwHu1f9nkPCc0B981johWqIEElChAMMH4QvV6mCAHoWK/7SLXsDvHlSoyPihR jwatBLOk= X-Gm-Gg: ASbGncvBfWivTgrS5YsbhmUx3KxqoyKwtrogAm/B9wWcDv6q+3UHtDK5SMUl1sOpxHL CJ43XbqiQ9AIki1QOI4zuEfTeTWTiZQWwU5OhItE0otQN2iTWLcKJ/YdrWwV2bi83biigQYZFrs m3nWhAqrAfpHCob8JVbntHdcrjG4YPiZWD0lcMDwKN+x554TC4xXG1I/pNzir0q6qx2zkjXEW7I YvakmrkMoBiODsPzqODPuXGQ65dUjMdtGXUrJ2ky3K+iw9GUHYngHbZfQtryanhDIz1dv/fA8v8 ho7T3PyLsmLBA0nKs5W2Hqm7f8bKVnhLMw5mLWxBN0NCxxSaKD4+lpDD0CzJLaELK2AztAc+Dzl AbFTGRZFAtoIY8vdp3s96g3cVHFXvY7jYIQWps50kw+5pIa8BKqAp0Dv46di2AVwRCQnKzOH4cQ tVZlt5sg1iq+vP0+m+hMU= X-Google-Smtp-Source: AGHT+IHZ+emkZ4nA0Pbm/C8To5NjaC7MULEW7wooV1IUml5bWgeQRAn7w6pUlMKyvKK2z+Nf/IRM5Q== X-Received: by 2002:a05:6808:6ec6:b0:40a:533c:c9cb with SMTP id 5614622812f47-41539f929cfmr2618040b6e.38.1752254580946; Fri, 11 Jul 2025 10:23:00 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Cc: Peter Maydell Subject: [PULL 3/9] linux-user: Check for EFAULT failure in nanosleep Date: Fri, 11 Jul 2025 11:22:48 -0600 Message-ID: <20250711172254.229201-4-richard.henderson@linaro.org> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20250711172254.229201-1-richard.henderson@linaro.org> References: <20250711172254.229201-1-richard.henderson@linaro.org> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=2607:f8b0:4864:20::234; envelope-from=richard.henderson@linaro.org; helo=mail-oi1-x234.google.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, 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+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @linaro.org) X-ZM-MESSAGEID: 1752254621582116600 Content-Type: text/plain; charset="utf-8" From: Peter Maydell 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 Reviewed-by: Richard Henderson Signed-off-by: Richard Henderson Message-ID: <20250710164355.1296648-1-peter.maydell@linaro.org> --- linux-user/syscall.c | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/linux-user/syscall.c b/linux-user/syscall.c index e1b1476936..38dd563166 100644 --- a/linux-user/syscall.c +++ b/linux-user/syscall.c @@ -11643,10 +11643,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 =3D 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; --=20 2.43.0 From nobody Tue Dec 16 04:38:55 2025 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=linaro.org ARC-Seal: i=1; a=rsa-sha256; t=1752254663; cv=none; d=zohomail.com; s=zohoarc; b=hAa3isKVS1w1ruTNExlbztA9OiW8l/5bdYv2EcqoVPme12ySepBTFFH006q7qh1bspd/MfvBfosDQx/L6RHJ7fPYIygc4yuO1LsOf317+95fmdgWREAZT1zO0Ht9K1cF2EoMzBNYwyy0SztyFk2x6lpeSZWmQm77b42OQow8kl8= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1752254663; h=Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=KbvFJbF5XPFsYap/Rj9OWqngvL2EB4p0iDRPnlUGu/U=; b=J4m8tQ/AB3kUGMJbiCNLdZhVw8qE1uoL/fKWMR5sLwdbWL/wnS3ATcwfL3TJEBTTNj5QQT/qx8sNFf35UBD9XlR/nP7++4ht/iQI+xHgVvLyJqvwuKVtj//CUmWuZEUgyJyv97PAkDgJRK/D356TK/wX/ZNl5ppAdUIzeS91XH8= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1752254663146783.9058432079323; Fri, 11 Jul 2025 10:24:23 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1uaHSm-0001ob-OC; Fri, 11 Jul 2025 13:23:08 -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 1uaHSj-0001jv-7g for qemu-devel@nongnu.org; Fri, 11 Jul 2025 13:23:05 -0400 Received: from mail-oi1-x233.google.com ([2607:f8b0:4864:20::233]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1uaHSh-00030m-Iz for qemu-devel@nongnu.org; Fri, 11 Jul 2025 13:23:04 -0400 Received: by mail-oi1-x233.google.com with SMTP id 5614622812f47-40b31468da3so742593b6e.0 for ; Fri, 11 Jul 2025 10:23:03 -0700 (PDT) Received: from localhost.localdomain (fixed-187-189-51-143.totalplay.net. [187.189.51.143]) by smtp.gmail.com with ESMTPSA id 5614622812f47-4141c77ada0sm602041b6e.44.2025.07.11.10.23.01 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 11 Jul 2025 10:23:01 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1752254582; x=1752859382; darn=nongnu.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=KbvFJbF5XPFsYap/Rj9OWqngvL2EB4p0iDRPnlUGu/U=; b=y7YNWV8Hbn7MsX7taoPKf03IL900ngkmaJklhsLLCFxTQJNaKeLG7WE3/CtGbSNtJC RMBEnEIJIBaHXcfRzlzbwJOTdn9z2xZR8UqoSSDnN//LQ7dxmsYKjZX/5MFjlJIq9Lei KgWSGLgXUASrptzOAhOdNeIQw0jAT0U6AmF0qlb3qBVVCsljCQ2hYKcQgUmPDsya/LbN MmwCZ9taTimzdxBZIP0HrW7rSGewEtYdeJVwusKgJm+OUBERXGXZYTAoBlDNGxz+fuiU APv62OKLY7waLbfNISRpoPTMIMyuQcnTtWgQAtaDNYMDSC5rzJ1wk8JTxZqrRJVQQkPj ekuQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1752254582; x=1752859382; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=KbvFJbF5XPFsYap/Rj9OWqngvL2EB4p0iDRPnlUGu/U=; b=Xg8MiwAT+hP8SqRnaNudOH9kCOOV7nYHEr8b9IY8v0QHdKA+kXTDgeQ9P6mzl3xn92 wfO+PmnmWzLIrNq2hxpOIEcT3MG/54tvIUxBbltNmM378cDWcnxAYHrZI1ORTBgLgNYt cjoyo1jimVfmow/cumlxNZq+TExNcpc5hXkMfLdWs71xoL6/htLn6WD2RJ58sGz4b62x zhiNzoKieeJBkc/mexY6oHHKI0lnSe5BpyD5Fpru58btqI9E/axUvyRja1ly0RnKTZhg 4mPJhywdm+WCuAGtOvTK4mxHlxAfY/N80fcED0p9KzjQyaMRO3ItR+iXgBdoYbO9IqUj 8OBw== X-Gm-Message-State: AOJu0Yy6VYkh2rN9J/jgpN92Lo5I/GG44QCLJ7Pw2y9UrqMh2wGhNikV uj2yY1iFLLhlmwbDwF9bE2XfVbKWIF0d1RCTrjgLWF5ZASnCU4hVNexFfzRG+8XXQ0dg9MtAtZk 6WQJ2j+s= X-Gm-Gg: ASbGncuI0hS0JIKxEEZDDM0sw+T5hsyRclhyDxpEPIS54jc0m8Pm18HHAHOnG2gisuc odI+Rx99zefhKa+fWeMx+ZyV/QgNyAX0FwFqzibKMOxi2YEp7Htypsfx0qFvNsIgKWxzfSKAuTN 6O/U/mow4PW/IOxZ1Wqb6ZJ9Us/nD9i8fpSobDGkyIpuOvZiiaUqYhHfTHDdduyMRKtA97vEujw I2ovw8LoK0I7gmIrEB5VUj7aB7vEdk6zCI/PU8vT8Cry3W8YNIqvlRrUIF3beKnWft1NAmnfoRw S3I7RftLcMDuZjT32GSxSvvxodbNiKbZa1LSu8hbaBuuCRcXqDTKBALsw5j5yHWOqlzTKIX9JF6 qnMpD7XF+5Ycmx2E1zf9BAjF20+9Oe7gsmyuvhsaLQeb/BQ/rrkWuLggyu2So0oKT6o63Lxau7l 4hzC7wAeWj X-Google-Smtp-Source: AGHT+IESlgROdwpepOV+/wYlJRog07cgPlcOGuNab3KUFrXmBvMGhd5f8grJwmewYoCab7KqCd8G8g== X-Received: by 2002:a05:6808:6547:20b0:40b:9948:f26c with SMTP id 5614622812f47-4150dc288bbmr2277044b6e.12.1752254582130; Fri, 11 Jul 2025 10:23:02 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Cc: Peter Maydell Subject: [PULL 4/9] linux-user/gen-vdso: Handle fseek() failure Date: Fri, 11 Jul 2025 11:22:49 -0600 Message-ID: <20250711172254.229201-5-richard.henderson@linaro.org> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20250711172254.229201-1-richard.henderson@linaro.org> References: <20250711172254.229201-1-richard.henderson@linaro.org> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=2607:f8b0:4864:20::233; envelope-from=richard.henderson@linaro.org; helo=mail-oi1-x233.google.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, 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+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @linaro.org) X-ZM-MESSAGEID: 1752254663662116600 Content-Type: text/plain; charset="utf-8" From: Peter Maydell Coverity points out that we don't check for fseek() failure in gen-vdso.c, and so we might pass -1 to malloc(). Add the error checking. (This is a standalone executable that doesn't link against glib, so we can't do the easy thing and use g_file_get_contents().) Coverity: CID 1523742 Signed-off-by: Peter Maydell Reviewed-by: Richard Henderson Signed-off-by: Richard Henderson Message-ID: <20250710170707.1299926-2-peter.maydell@linaro.org> --- linux-user/gen-vdso.c | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/linux-user/gen-vdso.c b/linux-user/gen-vdso.c index fce9d5cbc3..1c406d1b10 100644 --- a/linux-user/gen-vdso.c +++ b/linux-user/gen-vdso.c @@ -113,9 +113,16 @@ int main(int argc, char **argv) * We expect the vdso to be small, on the order of one page, * therefore we do not expect a partial read. */ - fseek(inf, 0, SEEK_END); + if (fseek(inf, 0, SEEK_END) < 0) { + goto perror_inf; + } total_len =3D ftell(inf); - fseek(inf, 0, SEEK_SET); + if (total_len < 0) { + goto perror_inf; + } + if (fseek(inf, 0, SEEK_SET) < 0) { + goto perror_inf; + } =20 buf =3D malloc(total_len); if (buf =3D=3D NULL) { --=20 2.43.0 From nobody Tue Dec 16 04:38:55 2025 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=linaro.org ARC-Seal: i=1; a=rsa-sha256; t=1752254730; cv=none; d=zohomail.com; s=zohoarc; b=PndzWsUXO+GrNFhAWhe97egF0DFUQVpp2FNf0Qa3yiWvta3JZsADXDutBEGSuZHz8m+s4t8AAtN3YN9+If/0ZhY6qdsCGiq8W7gqpb9jXA5/cUAqLLxlKUmX5dlopqRqWY1sBw7f5S83+iFImKacB97alojyF9P0Cf0t6cFLbXs= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1752254730; h=Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=jlf4WqrmYk0iCutXq0TkvLl72vNt4ux4AtRsxMUkqTg=; b=mERKYNwRqk2DhoZ8vPIwSf4Luvd4vGrbTIhg7CPohPLL9fKnGg8M8boxMjLYDDNC4SLG6i0JTFCbftQrymp3YJS0Npgb6Rz31g8BOl3yblP3CNHEm5HGm9bKvfU8I+NmJLbNItRBHreIBJegBrrolhjeZwZd+iwbQ/O4dwgBZSQ= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1752254730604579.9719220370588; Fri, 11 Jul 2025 10:25:30 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1uaHSn-0001ol-F0; Fri, 11 Jul 2025 13:23:09 -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 1uaHSk-0001mP-7g for qemu-devel@nongnu.org; Fri, 11 Jul 2025 13:23:06 -0400 Received: from mail-ot1-x335.google.com ([2607:f8b0:4864:20::335]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1uaHSi-00031N-Du for qemu-devel@nongnu.org; Fri, 11 Jul 2025 13:23:05 -0400 Received: by mail-ot1-x335.google.com with SMTP id 46e09a7af769-73a44512c8aso677069a34.0 for ; Fri, 11 Jul 2025 10:23:04 -0700 (PDT) Received: from localhost.localdomain (fixed-187-189-51-143.totalplay.net. [187.189.51.143]) by smtp.gmail.com with ESMTPSA id 5614622812f47-4141c77ada0sm602041b6e.44.2025.07.11.10.23.02 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 11 Jul 2025 10:23:02 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1752254583; x=1752859383; darn=nongnu.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=jlf4WqrmYk0iCutXq0TkvLl72vNt4ux4AtRsxMUkqTg=; b=ASZz3eeiOYoY+11LeIOuO867wMPc7v1Wm+pEyIyy0zqfR3PLDrzB31k1NaVKy78Zs8 PypMSDQ8aAEiWdZeVhiXlw2yeYK9l4JbExj0ZqCesgjjS9hIUA0k92XE4pg/SjhYcyOt 4nPgAE7DqGt2S+DFUafB+szR1jnbIALvQsyeuE3UC/qdbsFIJ04/c2aX7b05CrcNrSdo TQXUcd9N7JB6lbyfpDuGmFwpayIlIUYt8ILg8/c92lV2Odt4pCN5dg44O/709Z/WIEBo hKY+5mVQ+9y1YspdtytL30UModzR7DY/PHTZHMA0aQUkGUV1yL5/WaukfHyhJd0ScN9b xKdg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1752254583; x=1752859383; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=jlf4WqrmYk0iCutXq0TkvLl72vNt4ux4AtRsxMUkqTg=; b=mXAdOcCr4b8ENGhWYyUDGW/n0CSZY1TCvwKXAum+o/f9UEXrA4wBd0tfhyDXIDKhwE P6xL6ifA7IwGYzDI9+zOks96GLpLhHV+3y3m2CllGw6uVS7YyM0MSBOFGCkcHlrw7CkM Dasj2zaMlRNM/CBjpgKoVDt7iMKpTdPN3jVu/cMYOMh6zg7RdKyQ/LBnYVBN/3dPh7Tf sx6DTlRTd5uhwbsvmYNuYrcuDomaYrso3vCdsu8mSSGRGwLDkzbRu15tWIh+xyvQ5q5Y 8B1XoJAWFk+JrOJheD+84vwSbk277h9apFnMEk3CtfPiJwjRBi9m0mZfSnG6a21VrRaf 3J8Q== X-Gm-Message-State: AOJu0Yxu20t8ZcLjFki06Dgx7/jZMguGCEDqev5rN1btFx4aL/7CXeBS g8LV3otZrnUOPyi60DHD9KyIy572Z8GfkiXaPGvctnEvIwAPJ5U+CPV/OLtfja4m/pgsl+bLct1 p/K9yMXI= X-Gm-Gg: ASbGncsb39JjCpbNG5Rd0iuNIFRWUmwTGAjaE91+sDABouYBHrJhGrLerjSiS+AC0C8 w1ZeS/AeaqPOSQtFs5m/7ydrRGrz1n3MOACadvFbZhHclMFubbzSY01hEP1hTxo+iwKwYfdw7X3 9vOx/yQa7+t+6CylAmn9Fu7BZntIteDgbmF8CJjFIrqQ5MJI6t2gP30Oc7I6MShymGelMSppE5D 3ptGEsiu9QZr9ynbM5RbQOm1kCb9qatIIjaUUmTGyAJcmaiAwLkFtVjWxv9h1EzGseoEh2NggRf 846NOYwfjBc6YnV+vmXfciPbVjxRUJR1CEU8vZez6T5NW68vk1E9OvjXfiP+o9mA0+nEtYIgHRn 1/lyfir6ujFq62LEGFgF/pqZ4MdG7e61Aede0na1JUJ35ZCgwrpWOAA+In/FHJd+kVuUTEUUgtl HK0LtgFL2K X-Google-Smtp-Source: AGHT+IHinaVlHBSnhuzSQBIYX+I8Tsa/P14/idsXjyRrvI+ADN4ne3fKTQh9+rWSsYubFfSzm7iyew== X-Received: by 2002:a05:6808:3505:b0:40b:3390:397a with SMTP id 5614622812f47-4150d746c38mr3089082b6e.7.1752254582985; Fri, 11 Jul 2025 10:23:02 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Cc: Peter Maydell Subject: [PULL 5/9] linux-user/gen-vdso: Don't read off the end of buf[] Date: Fri, 11 Jul 2025 11:22:50 -0600 Message-ID: <20250711172254.229201-6-richard.henderson@linaro.org> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20250711172254.229201-1-richard.henderson@linaro.org> References: <20250711172254.229201-1-richard.henderson@linaro.org> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=2607:f8b0:4864:20::335; envelope-from=richard.henderson@linaro.org; helo=mail-ot1-x335.google.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, 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+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @linaro.org) X-ZM-MESSAGEID: 1752254732351116600 Content-Type: text/plain; charset="utf-8" From: Peter Maydell In gen-vdso we load in a file and assume it's a valid ELF file. In particular we assume it's big enough to be able to read the ELF information in e_ident in the ELF header. Add a check that the total file length is at least big enough for all the e_ident bytes, which is good enough for the code in gen-vdso.c. This will catch the most obvious possible bad input file (truncated) and allow us to run the sanity checks like "not actually an ELF file" without potentially crashing. The code in elf32_process() and elf64_process() still makes assumptions about the file being well-formed, but this is OK because we only run it on the vdso binaries that we create ourselves in the build process by running the compiler. Signed-off-by: Peter Maydell Reviewed-by: Richard Henderson Signed-off-by: Richard Henderson Message-ID: <20250710170707.1299926-3-peter.maydell@linaro.org> --- linux-user/gen-vdso.c | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/linux-user/gen-vdso.c b/linux-user/gen-vdso.c index 1c406d1b10..aeaa927db8 100644 --- a/linux-user/gen-vdso.c +++ b/linux-user/gen-vdso.c @@ -124,6 +124,11 @@ int main(int argc, char **argv) goto perror_inf; } =20 + if (total_len < EI_NIDENT) { + fprintf(stderr, "%s: file too small (truncated?)\n", inf_name); + return EXIT_FAILURE; + } + buf =3D malloc(total_len); if (buf =3D=3D NULL) { goto perror_inf; --=20 2.43.0 From nobody Tue Dec 16 04:38:55 2025 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=linaro.org ARC-Seal: i=1; a=rsa-sha256; t=1752254735; cv=none; d=zohomail.com; s=zohoarc; b=l4rdrOQmaQ9rEai0jHG5sEtIvRSw75AA8ppF/bMnV51Cs0YQdfUvkfqN4pXGZpRB/FPyOOL/Id79X7jZL1lKPM+x9/J7q49cKvikQm07wgQv8YVt/mB027MEWfplaCbj5pQtB0g/NKD+Mnmd0AXGiMZaiSPFmBc5mDGeumaazPw= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1752254735; h=Content-Type:Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=CVx2jKX8CzeoLD3wyy6xeP6kf7orExLEfbHtWwveu1s=; b=FRNCwEo0crrgr1yUbg3/iTtRFWW+2pEMQ1SRXI+9SquJG8S27MJETdVk0L0r89qqaU+nti/YJtJ6Y0A3PsnIw7JNGNYU8rVpZoDjJwYa/aKoNqnE4QO2Ji75sLAHlDPJ1m0O3lIQ5pQrOZFPvRSf+Tm91APGfByAmS+ho53S5pY= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 17522547356071002.479864310795; Fri, 11 Jul 2025 10:25:35 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1uaHSo-0001qF-6D; Fri, 11 Jul 2025 13:23:10 -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 1uaHSl-0001nX-0Y for qemu-devel@nongnu.org; Fri, 11 Jul 2025 13:23:07 -0400 Received: from mail-oi1-x236.google.com ([2607:f8b0:4864:20::236]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1uaHSj-00031e-Dx for qemu-devel@nongnu.org; Fri, 11 Jul 2025 13:23:06 -0400 Received: by mail-oi1-x236.google.com with SMTP id 5614622812f47-40b31468da3so742601b6e.0 for ; Fri, 11 Jul 2025 10:23:05 -0700 (PDT) Received: from localhost.localdomain (fixed-187-189-51-143.totalplay.net. [187.189.51.143]) by smtp.gmail.com with ESMTPSA id 5614622812f47-4141c77ada0sm602041b6e.44.2025.07.11.10.23.03 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 11 Jul 2025 10:23:03 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1752254584; x=1752859384; darn=nongnu.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=CVx2jKX8CzeoLD3wyy6xeP6kf7orExLEfbHtWwveu1s=; b=PfWUrxuMVRVRSNfdpT6g4m+evupNlOzm8bDVsKlPeUg7V5SkeqsMsEBfHJJnnKXWvd TXC+n11NNZESiW2/+itufdsEhexH7EYV2b5nLlYpn8AJW1fm6CclAjluojN6tVazStRJ mX/1AJ5+usJFg693i9oqYK6et/Req4Rs/Spw9Hpbywo+8M1GR7VdGN4OErJZvjOHtcdw vDNv+HRjH7YTqNH3myU9mLntRrNT34AnCiLNf9u7oYC9S3o+1iaQatENKpqf+IRnEblL WhJj1btrFO9K/3eIu/COkH9P5P/WB6+djeSC/6Vy4e7MdYVqXhF/ALntnBw/AGBAGH4P ng6Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1752254584; x=1752859384; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=CVx2jKX8CzeoLD3wyy6xeP6kf7orExLEfbHtWwveu1s=; b=gEL68ENj/K4TCFdMYUCo6RYKQdGKVstOkNPOApbKtCGc3A1Y6dpbIUvZSwTENxw1Tv I+yGJJdLS5VfwP9QxknTxtDXtSVIyOjTgsQ6BnY7knm4IbKJfRh14RqC4RyaoAbIJZL/ PTHwD9yhWpP0TpF9EVMEe/4nl8hLz256hiaBoCaVisAySsoOnH55lcb4Tzs8fPN/dgdF QkH+otSnC4JOQt9QTVBECnjUr6uIYBCzhVrXb3d8e7oUaVDbXnlMZnFTycXoq01zzJi/ QlUR/r/w5APwfH4BdCfCSSQxt6aGRiyNZtOrkIN3pHp277lFCD0p5Y3t8jydE/G/uJd9 PUOA== X-Gm-Message-State: AOJu0Yz3sa1CcnXHe7QbcZSMKrAHYT9u1tNqxd5GIIAtdtLiIAJY4bIJ oxTEtOBALpfcvK8i2TW1XyRVwnUAThUO3EaTc1vq2Ksk8P093LpAjXprcU/FCBi3JqFldH+93Jy CyyX9sC8= X-Gm-Gg: ASbGnctDxqQ7oTfe5Kx/bJ0VvfZWAaHv2vhK12S2DiD0xaG15mV/eAFlwxvI3qSMaPf TOaYC2rWBW2lXW1MUHTSRiI4R4aguMOg+CknHpP9sfY4Qg6fkH7ze5ETsnaptpCy3HgEMk8Ydz5 OxrDSiWkdm9fZGuRubKsAC2dnLzmmnt+LyVP+rh2VY8ngxKkedfuLDMFyC8VXff5XUi8G6zbia+ PUcxYmec/kFn6n8bCnx3ZjhX4oPru3IMysO5IYZ0TI8uprVn3W70mY5tGk4svYd+LWeyK8pSghZ Qt2PoBlZn+FT3r5YJlXOyM4PuI+bgo3H48IwCiuNXUEezP5WKtgTuXYyYesfvgYDcyWbOQuXwA/ IjWYoMDn0zS2wyfuj39Z5kjgHLOMnbPQb6COBJ3swreuN2/knigvauH6LvjTTbZJg54Vua4UKYq jeGYsb4dF5 X-Google-Smtp-Source: AGHT+IHx6iQNIDyK/HnjodRuXDdYKAXcrjhKyPGcm8Lia4QklcQUe9kuTwYI/JaOJmNjfvMcAVBhuA== X-Received: by 2002:a05:6808:508d:b0:402:18a1:843f with SMTP id 5614622812f47-4150f9a7c9amr3236179b6e.32.1752254584061; Fri, 11 Jul 2025 10:23:04 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Cc: =?UTF-8?q?Thomas=20Wei=C3=9Fschuh?= , =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= Subject: [PULL 6/9] linux-user/mips/o32: Drop sa_restorer functionality Date: Fri, 11 Jul 2025 11:22:51 -0600 Message-ID: <20250711172254.229201-7-richard.henderson@linaro.org> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20250711172254.229201-1-richard.henderson@linaro.org> References: <20250711172254.229201-1-richard.henderson@linaro.org> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=2607:f8b0:4864:20::236; envelope-from=richard.henderson@linaro.org; helo=mail-oi1-x236.google.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, 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+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @linaro.org) X-ZM-MESSAGEID: 1752254736579116600 From: Thomas Wei=C3=9Fschuh The Linux kernel dropped support for sa_restorer on O32 MIPS in the release 2.5.48 because it was unused. See the comment in arch/mips/include/uapi/asm/signal.h. Applications using the kernels UAPI headers will not reserve enough space for qemu-user to copy the sigaction.sa_restorer field to. Unrelated data may be overwritten. Align qemu-user with the kernel by also dropping sa_restorer support. Signed-off-by: Thomas Wei=C3=9Fschuh Reviewed-by: Philippe Mathieu-Daud=C3=A9 Signed-off-by: Richard Henderson Message-ID: <20250709-mips-sa-restorer-v1-1-fc17120e4afe@t-8ch.de> --- linux-user/mips/target_signal.h | 1 - linux-user/syscall_defs.h | 4 ---- 2 files changed, 5 deletions(-) diff --git a/linux-user/mips/target_signal.h b/linux-user/mips/target_signa= l.h index fa542c1f4e..4481426b99 100644 --- a/linux-user/mips/target_signal.h +++ b/linux-user/mips/target_signal.h @@ -64,7 +64,6 @@ typedef struct target_sigaltstack { #define TARGET_SA_NODEFER 0x40000000 #define TARGET_SA_RESTART 0x10000000 #define TARGET_SA_RESETHAND 0x80000000 -#define TARGET_SA_RESTORER 0x04000000 /* Only for O32 */ =20 #define TARGET_MINSIGSTKSZ 2048 =20 diff --git a/linux-user/syscall_defs.h b/linux-user/syscall_defs.h index 5d22759992..df26a2d28f 100644 --- a/linux-user/syscall_defs.h +++ b/linux-user/syscall_defs.h @@ -515,10 +515,6 @@ struct target_sigaction { abi_ulong _sa_handler; #endif target_sigset_t sa_mask; -#ifdef TARGET_ARCH_HAS_SA_RESTORER - /* ??? This is always present, but ignored unless O32. */ - abi_ulong sa_restorer; -#endif }; #else struct target_old_sigaction { --=20 2.43.0 From nobody Tue Dec 16 04:38:55 2025 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=linaro.org ARC-Seal: i=1; a=rsa-sha256; t=1752254630; cv=none; d=zohomail.com; s=zohoarc; b=hDaozRZSn+NHR8XxtBFCG57PE+bupDQpml4txbaFbbqj/6q83k4E+A4dM3T0cwSSLhQHMQYUYM9gITQJA7aJZDjP20/EQZfEtFK+VMMvzxnkPC9poqgnKSh08NtyWvDQsgKKVSfPwZB0c8PBBL8eVkcbwj3W8qjRKqVtsqJ6pSs= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1752254630; h=Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=xI3qXJJNrbG+1eXwshqtVlZ2UKNtJqDGVC4tuDSKaLE=; b=V2S6AWQYeYOcZJ7sI2jbQfQ665LX/cVhrx4P1CmiDepE+NbMdb+ac/w+0ArnhDrngcVj8I7aIZGVT9t7JwoDnLUiuzso/+2pBrbXidczYuW5sxAmidaZRltEM/0+rR7DSTrKAxy6BNmMETgEc/QrHXPuHv0mWS2slADOccDcFcg= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1752254630329396.7285491936059; Fri, 11 Jul 2025 10:23:50 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1uaHSn-0001pd-Ld; Fri, 11 Jul 2025 13:23:09 -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 1uaHSl-0001nk-Vs for qemu-devel@nongnu.org; Fri, 11 Jul 2025 13:23:08 -0400 Received: from mail-oi1-x22b.google.com ([2607:f8b0:4864:20::22b]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1uaHSk-00032F-A9 for qemu-devel@nongnu.org; Fri, 11 Jul 2025 13:23:07 -0400 Received: by mail-oi1-x22b.google.com with SMTP id 5614622812f47-407a6c6a6d4so704253b6e.1 for ; Fri, 11 Jul 2025 10:23:05 -0700 (PDT) Received: from localhost.localdomain (fixed-187-189-51-143.totalplay.net. [187.189.51.143]) by smtp.gmail.com with ESMTPSA id 5614622812f47-4141c77ada0sm602041b6e.44.2025.07.11.10.23.04 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 11 Jul 2025 10:23:04 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1752254585; x=1752859385; darn=nongnu.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=xI3qXJJNrbG+1eXwshqtVlZ2UKNtJqDGVC4tuDSKaLE=; b=f8jL89sDYu/WspPQJwifkawB3FDMqdGtMEcIkfTb0un3BiAlhNhyIvHybMy3cvqnFa 9dKqH5T7yQDApkD7MTNMCaI1k+MJJVEddI7mthpXEdMvXa4SJP6Al6R9WOirIsV/ICt0 ebeQo5nhvegQdvUsenBfRouDP9zqTpRKh8oyR/LHx6rqLYlGXO4+JJN6SxPccPgwY1YR vtt8yFReNmvRsaAZvzy0pVWXrheswJz/YB0B5E0fKj4mIc4GSV3bhrCwxecZtC8dMB/2 FakBzCj6ZUz0NAEq+4kmPKIx8SLuQcPiBOSVstFqopmk/acOdEfhEBCqDBLUk+hwNHOC GRQg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1752254585; x=1752859385; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=xI3qXJJNrbG+1eXwshqtVlZ2UKNtJqDGVC4tuDSKaLE=; b=n9nrnH+0nPWRfc3A/tdjgC19VGX10qC8MlSdv1IRDwwj1Q7T/2F73r+WziunJfUsAe anzhR1WJNJlOY1GwwqgH8xBYWF7UXPGLmRHzhpMpKNxQUH0vsK8OVNeNYF4N8cn1yuQW Q/VLMwkYvHI15RjwOIlE/g1K/TC758a/ZRuQhW/qubsX3qTcjUzJWR42QT4f06Sfnn5T ZZ69AU15wHM5c+OvYL23wVT3rCTY8fNXivbd4w1Wp5y5Woil8HA2uDBzzrzUDL+52xyj j9FMy69pSo7jTjQ7DC7e3ALEHpz/HNjYL1aFO+lWLo0XFoB+zI8E5b3V4f2XiW2Isxsi p48A== X-Gm-Message-State: AOJu0YxPDMLg2Sb4Hozz2DPC15lB+xuDpZwJCCAHZwgstfKa977i8DiT vcCLDVNv3he3E2kNcApTI0YTSjW84o5HnlK7DAj9VtzpMhNcaNcw7MsGfsutsKmfjC/KWjv1Fro j6h9pLrM= X-Gm-Gg: ASbGnctXJ8P5AQ1hCbCrx3PBd6rtH1rzhl80AXcLoa3/wtO4z4rI6en3WsKvilgx+8z NrdL6mN+BAvg5RjsrHkdL+S6Gxq0wMiQJQ33RQcQRSlHi+VNTHm8YFe9jaHC2PMFyTdN+8qbWIb 4Ah+QhjEi8DQDsmhluhkwIl4+CF+FSjx4Lgba/9bZTvS+RbM+3EjdKw+es2rbj+OirTVjg9dXQT 4SUHkWYkzJdKsJkueOslAVCNQ7QlDV00L+KpRpCDbb18Yb8LC73D9SHigL7ExDWDGwI9GbgEM3H L9pZdy2xX+POFtja29EaPCztrOJ6uLn9U39C5grV0sRkFlN9yDNcQbX75CL7BHQqhwk8a2MWYNX 05iD1Z4V/etRWtzRmGmmCQBEdJBsYPe2XPsrd+OFUKTXZD8VxpvvvAaAY+6QnMxgZR+w4qF3e0U om1poXyHIL X-Google-Smtp-Source: AGHT+IGOTasE1tX7VK2+32/MarPTidOjsEui7ZD0DIFTEZtrd+12wp2Qovx5MKFfRTgbUcN1pp+Wjg== X-Received: by 2002:a05:6808:3307:b0:408:548:8050 with SMTP id 5614622812f47-4150f5bb2ccmr3030102b6e.18.1752254585113; Fri, 11 Jul 2025 10:23:05 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Cc: Geoffrey Thomas , qemu-stable@nongnu.org Subject: [PULL 7/9] linux-user: Hold the fd-trans lock across fork Date: Fri, 11 Jul 2025 11:22:52 -0600 Message-ID: <20250711172254.229201-8-richard.henderson@linaro.org> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20250711172254.229201-1-richard.henderson@linaro.org> References: <20250711172254.229201-1-richard.henderson@linaro.org> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=2607:f8b0:4864:20::22b; envelope-from=richard.henderson@linaro.org; helo=mail-oi1-x22b.google.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, 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+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @linaro.org) X-ZM-MESSAGEID: 1752254631455116600 Content-Type: text/plain; charset="utf-8" From: Geoffrey Thomas If another thread is holding target_fd_trans_lock during a fork, then the lock becomes permanently locked in the child and the emulator deadlocks at the next interaction with the fd-trans table. As with other locks, acquire the lock in fork_start() and release it in fork_end(). Cc: qemu-stable@nongnu.org Signed-off-by: Geoffrey Thomas Fixes: c093364f4d91 "fd-trans: Fix race condition on reallocation of the tr= anslation table." Resolves: https://gitlab.com/qemu-project/qemu/-/issues/2846 Buglink: https://github.com/astral-sh/uv/issues/6105 Reviewed-by: Richard Henderson Signed-off-by: Richard Henderson Message-ID: <20250314124742.4965-1-geofft@ldpreload.com> --- linux-user/fd-trans.h | 10 ++++++++++ linux-user/main.c | 2 ++ 2 files changed, 12 insertions(+) diff --git a/linux-user/fd-trans.h b/linux-user/fd-trans.h index 910faaf237..e14f96059c 100644 --- a/linux-user/fd-trans.h +++ b/linux-user/fd-trans.h @@ -36,6 +36,16 @@ static inline void fd_trans_init(void) qemu_mutex_init(&target_fd_trans_lock); } =20 +static inline void fd_trans_prefork(void) +{ + qemu_mutex_lock(&target_fd_trans_lock); +} + +static inline void fd_trans_postfork(void) +{ + qemu_mutex_unlock(&target_fd_trans_lock); +} + static inline TargetFdDataFunc fd_trans_target_to_host_data(int fd) { if (fd < 0) { diff --git a/linux-user/main.c b/linux-user/main.c index a9142ee726..f4f2007439 100644 --- a/linux-user/main.c +++ b/linux-user/main.c @@ -149,12 +149,14 @@ void fork_start(void) cpu_list_lock(); qemu_plugin_user_prefork_lock(); gdbserver_fork_start(); + fd_trans_prefork(); } =20 void fork_end(pid_t pid) { bool child =3D pid =3D=3D 0; =20 + fd_trans_postfork(); qemu_plugin_user_postfork(child); mmap_fork_end(child); if (child) { --=20 2.43.0 From nobody Tue Dec 16 04:38:55 2025 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=linaro.org ARC-Seal: i=1; a=rsa-sha256; t=1752254683; cv=none; d=zohomail.com; s=zohoarc; b=SX9jN7LzpxqgA20+Y519LetmURWn0YbpypMfPn7AO4DqaA0PmyWzJwZzsKCDyQr99R+ddWqp4q3OKOBuihOQ1NB3wFgJYS3HckYPPRlRSDjMZjS0+COzOWSSqtBDKNDBmkRNvgidBgOZMVjeS4GJqwBcgsmyQTCKTZgPiMKd6FM= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1752254683; h=Content-Type:Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=j9c7MLf28ZTbIKD23Oq32+PYqLQBAflgfhnsqzK3gkY=; b=lfTlEkW0f4EuohYajQhKtxCcdqqZcLHy4ba3qeAkMCvPmC6eJD75IecTWMR32IAc9ifiWAVT3qXvSPuekuSwguP3wnQsyTq5lWYtbzjpzANPkNR4Shcm899p0PBPpKPtt8AbCFpI2mBPmkwEwW8S9NQizb+8aElZSRyS9aoAVaI= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1752254683844212.15006343771518; Fri, 11 Jul 2025 10:24:43 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1uaHSp-0001qo-Rb; Fri, 11 Jul 2025 13:23:11 -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 1uaHSn-0001ok-7I for qemu-devel@nongnu.org; Fri, 11 Jul 2025 13:23:09 -0400 Received: from mail-oi1-x234.google.com ([2607:f8b0:4864:20::234]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1uaHSl-00032i-8R for qemu-devel@nongnu.org; Fri, 11 Jul 2025 13:23:08 -0400 Received: by mail-oi1-x234.google.com with SMTP id 5614622812f47-40af40aef06so1221813b6e.3 for ; Fri, 11 Jul 2025 10:23:06 -0700 (PDT) Received: from localhost.localdomain (fixed-187-189-51-143.totalplay.net. [187.189.51.143]) by smtp.gmail.com with ESMTPSA id 5614622812f47-4141c77ada0sm602041b6e.44.2025.07.11.10.23.05 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 11 Jul 2025 10:23:05 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1752254586; x=1752859386; darn=nongnu.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=j9c7MLf28ZTbIKD23Oq32+PYqLQBAflgfhnsqzK3gkY=; b=oM2kXR7886O8HgUWOwnHd0sKxjKNTw4NNVl1g9spxybWIMwxxgOOHu31UDFfkNqN6a WjtImwiGZlSwTloGC8kYwB2H0e0PBJtp7qarA4lflVCpOqYohJfT2huGZpCTTntXhAlp NshE4JPi7I67E+voOEVcHBkR7Q6cd9Fa2QimYTR83qUEeemvdfzmwOm9bS0bZC3iTe47 rezX3QS33dma7pROyK1orkLbM63osAE9wjauFC5fOCVd/o/pNwq6koemtNJEExVeVQN5 JSnTnTJSxlp4WKW884SOZTGC+HyDXUmGG7KcZZyoV7MLIFVa9EN9kxKViftneaweV9xD IopA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1752254586; x=1752859386; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=j9c7MLf28ZTbIKD23Oq32+PYqLQBAflgfhnsqzK3gkY=; b=iqzimvofFjMWfuosjdLdLss9/okxXbCgIDGdVKr72kESHlx9GE2smF99oIwuN6gEVl bVNE8ngKFo2PndQo/L+jOcQH0d4oCxvGGOmlZAOCDDBhdZVb8ZS+GOyX95n8atuYCabv UQFHpaiAsSgO71/2UyfdWuwuYwvurGHGW7jXmwm5ghUtbf0OmCRrOpX46zLOzAqksN3i rKtAcvfqnvFCRoiZWJVXrMVMDGW57yN3h7RetzmWFffzqfJr9RUOV7QFmBdWcl1yQv7x BUChGMmBTUNZNPAi00tUFaMfvYycI/ZH+YUzImUishUjeEmrge9xAUNKOGSAh9idshVq aSeQ== X-Gm-Message-State: AOJu0YyUa0M5eDTZuesuFUh2Fcta+iFWkI+96zLEywpfzCdo0mfjSh+G sKwx0aNdHZMl3nbYKXWJUVhQ3ljp8mJrZFNqGY1Ok+sGvgvP+806BOeyjXKNtvfdwgheTIYziic 1yrbOUvw= X-Gm-Gg: ASbGncvBinx6BGdImJdkKs+xdzNhFCOTrOIMBSTwxFL2MmuiBFjT/PjcaYFEDQvrtul aZNEOeyGRxf3IiBaatV46FwRcbrg2AXzNEO0O7Lcy7JGBQYQu6D1gv8z37aTCIDvVdn4jA1sLjU +ehxr8+X0vCdo8fYueVco+z1m9MSCaVkjKPBFbqnZFxMmniGNaBcv5WimpAevdqykTNIqqJy3PX C4Ir5d2pMBX3XnoIbPWZf+VCZ6z9Kkysn7/XtMbGk97G96cLauTQXK9doVRtIlPbAotbokbxbNI AJUz4fdCVOOUfys2SLhp96rlamxvrygZl/84widjwU0jmM8zRN9R61mXJkrbGiqb/SHXvQwIh65 H7+s47hBe/KUGK9pYtN19LmzXUp8AY1ZUrINvrKHYSZ5ZzcMdXRX30MrD57TyvP9vl0rXdZiwvE HFYYI4vjvkA+lBGYi0eck= X-Google-Smtp-Source: AGHT+IHw3/nyT7cZtyEpyd8w5NxmZGvRfePs4WqPwcA4C1pXWxVaZiuhULOGMvaDsmQcz5tnAp7MSQ== X-Received: by 2002:a05:6808:f91:b0:40c:f680:7775 with SMTP id 5614622812f47-41511814a77mr3485333b6e.31.1752254586012; Fri, 11 Jul 2025 10:23:06 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Cc: Ilya Leoshkevich , =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= Subject: [PULL 8/9] tcg: Use uintptr_t in tcg_malloc implementation Date: Fri, 11 Jul 2025 11:22:53 -0600 Message-ID: <20250711172254.229201-9-richard.henderson@linaro.org> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20250711172254.229201-1-richard.henderson@linaro.org> References: <20250711172254.229201-1-richard.henderson@linaro.org> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=2607:f8b0:4864:20::234; envelope-from=richard.henderson@linaro.org; helo=mail-oi1-x234.google.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, 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+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @linaro.org) X-ZM-MESSAGEID: 1752254685853116600 Avoid ubsan failure with clang-20, tcg.h:715:19: runtime error: applying non-zero offset 64 to null pointer by not using pointers. Acked-by: Ilya Leoshkevich Reviewed-by: Philippe Mathieu-Daud=C3=A9 Signed-off-by: Richard Henderson --- include/tcg/tcg.h | 6 +++--- tcg/tcg.c | 9 +++++---- 2 files changed, 8 insertions(+), 7 deletions(-) diff --git a/include/tcg/tcg.h b/include/tcg/tcg.h index 125323f153..0c2a319c11 100644 --- a/include/tcg/tcg.h +++ b/include/tcg/tcg.h @@ -357,7 +357,7 @@ static inline TCGRegSet output_pref(const TCGOp *op, un= signed i) } =20 struct TCGContext { - uint8_t *pool_cur, *pool_end; + uintptr_t pool_cur, pool_end; TCGPool *pool_first, *pool_current, *pool_first_large; int nb_labels; int nb_globals; @@ -706,7 +706,7 @@ size_t tcg_nb_tbs(void); static inline void *tcg_malloc(int size) { TCGContext *s =3D tcg_ctx; - uint8_t *ptr, *ptr_end; + uintptr_t ptr, ptr_end; =20 /* ??? This is a weak placeholder for minimum malloc alignment. */ size =3D QEMU_ALIGN_UP(size, 8); @@ -717,7 +717,7 @@ static inline void *tcg_malloc(int size) return tcg_malloc_internal(tcg_ctx, size); } else { s->pool_cur =3D ptr_end; - return ptr; + return (void *)ptr; } } =20 diff --git a/tcg/tcg.c b/tcg/tcg.c index 50d40b9cbe..afac55a203 100644 --- a/tcg/tcg.c +++ b/tcg/tcg.c @@ -1331,8 +1331,9 @@ void *tcg_malloc_internal(TCGContext *s, int size) p =3D s->pool_current; if (!p) { p =3D s->pool_first; - if (!p) + if (!p) { goto new_pool; + } } else { if (!p->next) { new_pool: @@ -1351,8 +1352,8 @@ void *tcg_malloc_internal(TCGContext *s, int size) } } s->pool_current =3D p; - s->pool_cur =3D p->data + size; - s->pool_end =3D p->data + p->size; + s->pool_cur =3D (uintptr_t)p->data + size; + s->pool_end =3D (uintptr_t)p->data + p->size; return p->data; } =20 @@ -1364,7 +1365,7 @@ void tcg_pool_reset(TCGContext *s) g_free(p); } s->pool_first_large =3D NULL; - s->pool_cur =3D s->pool_end =3D NULL; + s->pool_cur =3D s->pool_end =3D 0; s->pool_current =3D NULL; } =20 --=20 2.43.0 From nobody Tue Dec 16 04:38:55 2025 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=linaro.org ARC-Seal: i=1; a=rsa-sha256; t=1752254652; cv=none; d=zohomail.com; s=zohoarc; b=LwmOJZVvORyTLSsj6NlpHamGJXMJlwZ/r9b22shObFm1ofC4BE/5bQ6oLmdyqeBcbGbLfjuvO1ixfvH7iX43z8n2zXHjiH3pGWwE2MKsjuCwFf9GeHW+IJ3zNvTND7/cNfvDagt0Us6JUf5OPzGxWCWn1LahcGSFF+x/hlD2dwY= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1752254652; h=Content-Type:Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=n7yoiT0H1cbWcezhhOOQ6JGPwf+lfIZ37AHWPBQOdyo=; b=f3/9ttFD6/4T55qLW3Td9TY2Wy+R/X2rZHsnoMSdOieZ/kDTpFvvyAIabnQv6AE9pa1Yip/HhE4bceVv/DVDMRoSSCYqn1rZpPvxWjhq7JRR35C5mKtvBbDaOzFkUlpgzaNogsztURmFVDszTeSzN+prE10yzD2korhS26azivs= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1752254652751284.5206951492729; Fri, 11 Jul 2025 10:24:12 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1uaHSq-0001qx-Bv; Fri, 11 Jul 2025 13:23:12 -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 1uaHSo-0001qa-Kb for qemu-devel@nongnu.org; Fri, 11 Jul 2025 13:23:10 -0400 Received: from mail-oi1-x22a.google.com ([2607:f8b0:4864:20::22a]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1uaHSn-00033E-0f for qemu-devel@nongnu.org; Fri, 11 Jul 2025 13:23:10 -0400 Received: by mail-oi1-x22a.google.com with SMTP id 5614622812f47-40a4de175a3so1253767b6e.0 for ; Fri, 11 Jul 2025 10:23:08 -0700 (PDT) Received: from localhost.localdomain (fixed-187-189-51-143.totalplay.net. [187.189.51.143]) by smtp.gmail.com with ESMTPSA id 5614622812f47-4141c77ada0sm602041b6e.44.2025.07.11.10.23.06 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 11 Jul 2025 10:23:06 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1752254587; x=1752859387; darn=nongnu.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=n7yoiT0H1cbWcezhhOOQ6JGPwf+lfIZ37AHWPBQOdyo=; b=YJf2Itm8WCT5tX02ZGpisVtQjRAJCwFIX6EoRyE7jZkgPGeaSlmJQ1IUA/q311/7CF LUnso58m8NC2xCAzDFyBffnjyJf71Ar/D3/in6NBKvDVCI1Z+5Qn/j4LJA4r8Cs5NohO 0hdpuJocUUDxqnvBjHUs23esazN36yZUCNT3RS7P00zprGGYUoPSlpVc8sh82Z1HJMfV VRUFlTkhIFk2VqOovuYoJTzFYhyT2MGqTJkRNRfb44iNCE77sAVvyKSjbG+RNy+jyZ/u n/0hMLqUcjstRfEhGnZ0gtby6oR8R/pcn0dh1atsonrWCMvqGO4/xOv7u53qY62Vujdq +hkA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1752254587; x=1752859387; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=n7yoiT0H1cbWcezhhOOQ6JGPwf+lfIZ37AHWPBQOdyo=; b=VZ0AfZ1BKP5e5SOo2KwXMcHwqzabuEKngvy/ZkT2zWT6RmxGDjnovjnFabsysWHP75 H3NDxr0T1EDpa6CJ8HCYTt0JKxIP38l3DACoNrwWhlEOzUvLz8nnzVEW5GhEVXbtBXCP kARpd7oL/NNW3zh4jXlp2svZOQ4GTtfkwMM7zlTyhOEV0y+2fLK4RYjDyEk6ZpEradTw rKmdRJkrRjk2RSJWXoQ18BaAsXK1FkcKT/dlegjkgidLo8anf8mpwYLoiZPinjucFIn0 vRqLt1KNMD9Idz1gjMCBpaiDRVQ2x5wtXtxhCxlfkskIFYw2D/nR+FHWZxtbM04E0Hps HRlA== X-Gm-Message-State: AOJu0Yz52sFLI/F5EtUNRNt3HDBiWsNGqj5YKVixqJpGhOmwiEdqyvKZ Tfg5CbEoasEoD74JHT+LCflASc4B+vkgbYSA9LUNP5i1r9kfRlgw4EYe1E4GBYog3EUdslPLjif Iuhyuzfk= X-Gm-Gg: ASbGnctiZmBEsBj3Uf1bxUfRQPBdf2B8+//6Qmcl8Op05cYZGyAFS5B97aqFmayf3zN HaHvLqEK6gkqFu5LPVuE9fcP9BSB9ZW5LuFdkl2UtmBdRq0gedeaQFzF1UQYi6okOqy0d9OIier v8ox+MWuGLPJWg/PeiSolMvKtGx7ozECwnlbinBSkfh6iS5jd/Anti8Syh6pf6I1uydxZYlTCWc nVlB2iGdtIFQQ6EdrhV5yfYJYONcUsn+2+6BfK7CC03ZxLWHz0eGDjRWb3u1xMsTVLQoujslfNe eXDUJxQEkjyTzTWYHTodRAZWIO+Vt1H17UUh1P7qoWo01szmWYCHRVXFYbhnMarQ744s+6zzjiM hDa1ELTXwtzurM0I1YGceUPGBmtROpzullVRG+essQzx58A1VqaHpNxoddhIngJzvsii4SNrs1T wjlIzqPwZL X-Google-Smtp-Source: AGHT+IE8ATu6rvRtAq+VDKQptqyzFJFW9y8FvFg/GlYZ37hN/CgoUWYzo8rK2ZA8B2mFYanyq3XTtA== X-Received: by 2002:a05:6808:1587:b0:40b:555b:9024 with SMTP id 5614622812f47-4150e31d37amr3350526b6e.17.1752254587398; Fri, 11 Jul 2025 10:23:07 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Cc: Peter Maydell , =?UTF-8?q?Daniel=20P=20=2E=20Berrang=C3=A9?= Subject: [PULL 9/9] linux-user: Use qemu_set_cloexec() to mark pidfd as FD_CLOEXEC Date: Fri, 11 Jul 2025 11:22:54 -0600 Message-ID: <20250711172254.229201-10-richard.henderson@linaro.org> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20250711172254.229201-1-richard.henderson@linaro.org> References: <20250711172254.229201-1-richard.henderson@linaro.org> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=2607:f8b0:4864:20::22a; envelope-from=richard.henderson@linaro.org; helo=mail-oi1-x22a.google.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, 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+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @linaro.org) X-ZM-MESSAGEID: 1752254653938116600 From: Peter Maydell In the linux-user do_fork() function we try to set the FD_CLOEXEC flag on a pidfd like this: fcntl(pid_fd, F_SETFD, fcntl(pid_fd, F_GETFL) | FD_CLOEXEC); This has two problems: (1) it doesn't check errors, which Coverity complains about (2) we use F_GETFL when we mean F_GETFD Deal with both of these problems by using qemu_set_cloexec() instead. That function will assert() if the fcntls fail, which is fine (we are inside fork_start()/fork_end() so we know nothing can mess around with our file descriptors here, and we just got this one from pidfd_open()). (As we are touching the if() statement here, we correct the indentation.) Coverity: CID 1508111 Signed-off-by: Peter Maydell Reviewed-by: Richard Henderson Reviewed-by: Daniel P. Berrang=C3=A9 Signed-off-by: Richard Henderson Message-ID: <20250711141217.1429412-1-peter.maydell@linaro.org> --- linux-user/syscall.c | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/linux-user/syscall.c b/linux-user/syscall.c index 38dd563166..91360a072c 100644 --- a/linux-user/syscall.c +++ b/linux-user/syscall.c @@ -6747,10 +6747,9 @@ static int do_fork(CPUArchState *env, unsigned int f= lags, abi_ulong newsp, int pid_child =3D ret; pid_fd =3D pidfd_open(pid_child, 0); if (pid_fd >=3D 0) { - fcntl(pid_fd, F_SETFD, fcntl(pid_fd, F_GETFL) - | FD_CLOEXEC); + qemu_set_cloexec(pid_fd); } else { - pid_fd =3D 0; + pid_fd =3D 0; } #endif put_user_u32(pid_fd, parent_tidptr); --=20 2.43.0