From nobody Tue Feb 10 04:55:11 2026 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=1658758185; cv=none; d=zohomail.com; s=zohoarc; b=ge6FvenMDy5rpAO3yLfqTfs6y18cjGNqWNTg5MhOeZk8IjW/V6FLXigMp/lTzrvrphFqTJyedvaAwGgP1hmO1YGK+3SiU+k8x/X3DnFK/feWGuiKUgUiGnbAI9eklz+GzaSOMsbv9D1TWOx0nQoY/ZL00p65tiu8Yb8atP2yj20= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1658758185; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=QS8/Mz4m9SIuDGhgYB4lvPLK9Hni5wZ7MVsQ4sSUUEo=; b=M6Nnioz+E2inVd3LLe3+JDvnxjdVeeUKS1o5XONc0AjdqxHRrCLd9YFHqWPx4+MZVSJUV6ztQaVHmJGJ8mh+kEP3faeSba4REJC81i/OM2F/oh0KSDvZ2ApFASOV4IKx+nthoX6PZsB+gQKJolY4rRrRqwku9u2yPrmsNqKVhtQ= 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 1658758185213580.5608199885444; Mon, 25 Jul 2022 07:09:45 -0700 (PDT) Received: from localhost ([::1]:41664 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1oFym9-0003oL-HE for importer@patchew.org; Mon, 25 Jul 2022 10:09:38 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:47782) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1oFyiD-0000t7-PJ for qemu-devel@nongnu.org; Mon, 25 Jul 2022 10:05:34 -0400 Received: from mail-wr1-x42e.google.com ([2a00:1450:4864:20::42e]:38575) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1oFyiC-0000Fk-3Q for qemu-devel@nongnu.org; Mon, 25 Jul 2022 10:05:33 -0400 Received: by mail-wr1-x42e.google.com with SMTP id k11so15663810wrx.5 for ; Mon, 25 Jul 2022 07:05:31 -0700 (PDT) Received: from zen.linaroharston ([185.81.254.11]) by smtp.gmail.com with ESMTPSA id f8-20020a05600c4e8800b003a31673515bsm20185235wmq.7.2022.07.25.07.05.23 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 25 Jul 2022 07:05:25 -0700 (PDT) Received: from zen.lan (localhost [127.0.0.1]) by zen.linaroharston (Postfix) with ESMTP id 45A071FFC0; Mon, 25 Jul 2022 15:05:21 +0100 (BST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=QS8/Mz4m9SIuDGhgYB4lvPLK9Hni5wZ7MVsQ4sSUUEo=; b=hF6YZy1VAcTK6qC1lTDtiUryQZ2Z8uxqJk6BbwyoJJu+/4lSm98/cdut9K+znTnWqh fZZiJsYlwujll5l3T/iesUTUrLTo6hiezc8grwPcrBLdxA0EnJKknzcgVmgmhDN3kEL9 wpGMR7IVTsmzBtq/6Cq/p8Pa7HvHuC2go5//XpCGk7vYlfxKmoTe9n2DBy05RLmBMKkG DtqJ4g1iVgt8HZGrfKepWt+SzEoH3ztlY6/0zqD2XMnCpD9HCGnY+gAsneqoNb3C9MYz D6J069kb9TsfEXkKpGWAk1ZauAwL3Ie8Nj+D4YZwvJluM10cg7kvAhBuOWqtoUnM3nl3 VxeA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=QS8/Mz4m9SIuDGhgYB4lvPLK9Hni5wZ7MVsQ4sSUUEo=; b=7KPRrrIqL4D5G0T0FMpzk5k2VKeOhh/Ilfip13DWU7KWsVqTC2/yN2tVp5kfOmoDhJ lFS9YB7phuGizre2+hLx7+7L5n2NHYvzoReYxYlHtEaIeWq/hnsPIROFK449AC/lPxNa 5NKkAo78XAYk60qMULvAG0Bg+Z+R6DWx9RAGS+OrAJu54xT6H+lhKuVWBcWHes9PYD8+ cxKnfqfAJnT0gVMl5un9v/NhLTRs4VrS/4CKVI2aoWLE6CQ3XoygN3MQJYur2jc4Rqo9 tswMCyUXY+KTtg4sw9Te+HGq2NQiW4wIv/B/YoVva07/RWkO2xZjqFOXC2hs1Sw+o9/m mi2g== X-Gm-Message-State: AJIora8qiG34iBBWQKY7AxoNjJsIrZYsPFECANtfvhqqSCw9pyag0dwV tygorfFnI8LoKgvgFpnHQvnWDARzr1/Ejw== X-Google-Smtp-Source: AGRyM1ug4ZGilnwe4U2/U1lxPPTx/Pc4TAt6nbEySY+9O7YlH0tkemRiU0VR984F+iz4XFxsmvFlug== X-Received: by 2002:a5d:434a:0:b0:21d:aa7e:b1bb with SMTP id u10-20020a5d434a000000b0021daa7eb1bbmr8292689wrr.619.1658757930685; Mon, 25 Jul 2022 07:05:30 -0700 (PDT) From: =?UTF-8?q?Alex=20Benn=C3=A9e?= To: qemu-devel@nongnu.org Cc: fam@euphon.net, berrange@redhat.com, f4bug@amsat.org, aurelien@aurel32.net, pbonzini@redhat.com, stefanha@redhat.com, crosa@redhat.com, peter.maydell@linaro.org, Richard Henderson , =?UTF-8?q?Alex=20Benn=C3=A9e?= Subject: [PATCH v1 08/13] semihosting: Check for errors on SET_ARG() Date: Mon, 25 Jul 2022 15:05:15 +0100 Message-Id: <20220725140520.515340-9-alex.bennee@linaro.org> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20220725140520.515340-1-alex.bennee@linaro.org> References: <20220725140520.515340-1-alex.bennee@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=2a00:1450:4864:20::42e; envelope-from=alex.bennee@linaro.org; helo=mail-wr1-x42e.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, T_SCC_BODY_TEXT_LINE=-0.01 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" X-ZohoMail-DKIM: pass (identity @linaro.org) X-ZM-MESSAGEID: 1658758187310100001 From: Peter Maydell The SET_ARG() macro returns an error indication; we check this in the TARGET_SYS_GET_CMDLINE case but not when we use it in implementing TARGET_SYS_ELAPSED. Check for and handle the errors via the do_fault codepath, and update the comment documenting the SET_ARG() and GET_ARG() macros to note how they handle memory access errors. Resolves: Coverity CID 1490287 Signed-off-by: Peter Maydell Reviewed-by: Richard Henderson Message-Id: <20220719121110.225657-4-peter.maydell@linaro.org> Signed-off-by: Alex Benn=C3=A9e --- semihosting/arm-compat-semi.c | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) diff --git a/semihosting/arm-compat-semi.c b/semihosting/arm-compat-semi.c index 1a1e2a6960..d12288fc80 100644 --- a/semihosting/arm-compat-semi.c +++ b/semihosting/arm-compat-semi.c @@ -171,6 +171,12 @@ static LayoutInfo common_semi_find_bases(CPUState *cs) * Read the input value from the argument block; fail the semihosting * call if the memory read fails. Eventually we could use a generic * CPUState helper function here. + * Note that GET_ARG() handles memory access errors by jumping to + * do_fault, so must be used as the first thing done in handling a + * semihosting call, to avoid accidentally leaking allocated resources. + * SET_ARG(), since it unavoidably happens late, instead returns an + * error indication (0 on success, non-0 for error) which the caller + * should check. */ =20 #define GET_ARG(n) do { \ @@ -739,10 +745,14 @@ void do_common_semihosting(CPUState *cs) case TARGET_SYS_ELAPSED: elapsed =3D get_clock() - clock_start; if (sizeof(target_ulong) =3D=3D 8) { - SET_ARG(0, elapsed); + if (SET_ARG(0, elapsed)) { + goto do_fault; + } } else { - SET_ARG(0, (uint32_t) elapsed); - SET_ARG(1, (uint32_t) (elapsed >> 32)); + if (SET_ARG(0, (uint32_t) elapsed) || + SET_ARG(1, (uint32_t) (elapsed >> 32))) { + goto do_fault; + } } common_semi_set_ret(cs, 0); break; --=20 2.30.2