From patchwork Tue Jul 19 19:17:37 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Peter Maydell X-Patchwork-Id: 591680 Delivered-To: patch@linaro.org Received: by 2002:a05:7000:5817:0:0:0:0 with SMTP id j23csp4263865max; Tue, 19 Jul 2022 12:18:17 -0700 (PDT) X-Google-Smtp-Source: AGRyM1t1urffkeYdDwFtAG7D32FbvcSU9lNvI31mmPISx4NMLgU/sPATSTmAVpELY6sIcPerK4+F X-Received: by 2002:a05:622a:2cc:b0:31f:523:c318 with SMTP id a12-20020a05622a02cc00b0031f0523c318mr753455qtx.286.1658258297456; Tue, 19 Jul 2022 12:18:17 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1658258297; cv=none; d=google.com; s=arc-20160816; b=IZY3p/75ggd8oa+rckpIWd91ICeh8RnngF/BjFRpub4+njgNahnTUthiIGXIue1XAX +Zss4mhxSbbfo0dOnQj2EPvM6GF6YTjFSHl+LLmVvEtSB7qfCvwB8JKQmewXLIigwI4P 2deBpX7fSVVTXY/XGtf3Esnmvmmd57Dn2Xwsb+YMhjTkYBPK3iy9JgFMTntoRyTePlBR pKqAqGhqkaDrMd9Tj3JIowDC65CJNwZasPWRqLmcD1HXwMlBViO+2GQ7+UtJec1nMUhu XSxgghvUuLNvV6COOJJLcLvmqRvZs8+ulWVu3Mx2b3Q9zkLaPrRuMJcp8HEJLyVnmaJ0 4NiA== 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:message-id:date:subject:cc:to:from:dkim-signature; bh=9v21Ix66GTJcQGhQxKIODW8bSYLFeuijiK0JgwHYvl0=; b=A9VLxzQCWpUC3/pR/d9FQd3lHWKDFAsmV0pxW+oVIcypRXqtf6uIGR/BxvJJrazcTM cBKLSzrqEWsXujEcKlA4e6VSGpZkTLrs0YfgvFfZ13Djr1BsXngLF5xr3t7K3by8uXBs CpzDsIVaNQTo65pluZ1bnnObcnKENsoU7TLUxx6zIuNzl/jxgsEQy9RPJDTKIAsCExcr 380tsHJu1OPOcwmYR6Wht5bX5YJuwY+wABMFX7f5ExQJdutkad1e55FBqpPEP0ve50yN NZzWBIg+WTdiZfoSjt35I/P1h6MYbK+U+bw3tmy5ZTn9VWvtlRIomtoMDoQFjdMO2M04 elMg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=O+1WgJzf; 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"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from lists.gnu.org (lists.gnu.org. [209.51.188.17]) by mx.google.com with ESMTPS id kj28-20020a056214529c00b0046b8c458607si7256564qvb.354.2022.07.19.12.18.17 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Tue, 19 Jul 2022 12:18:17 -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; dkim=pass header.i=@linaro.org header.s=google header.b=O+1WgJzf; 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"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: from localhost ([::1]:53368 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1oDsjZ-0005gH-2a for patch@linaro.org; Tue, 19 Jul 2022 15:18:17 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:58810) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1oDsj2-0005g9-NG for qemu-devel@nongnu.org; Tue, 19 Jul 2022 15:17:44 -0400 Received: from mail-wr1-x433.google.com ([2a00:1450:4864:20::433]:43936) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1oDsj0-0004oX-Vr for qemu-devel@nongnu.org; Tue, 19 Jul 2022 15:17:44 -0400 Received: by mail-wr1-x433.google.com with SMTP id d16so23023934wrv.10 for ; Tue, 19 Jul 2022 12:17:42 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=9v21Ix66GTJcQGhQxKIODW8bSYLFeuijiK0JgwHYvl0=; b=O+1WgJzfE3IiydKBLQUjnh2jLsr9Jhks1X8i6mvrmwwftsJ+8nX63/rR4+UlZ2UP+T JTNz5C+YAGJZkP8dknBWgMisuVO0biUtPg9YXyOwmNY3hfy1OQ0DwxWJDmyVo4JAATrx lb3hMt31GA7QNTOXIRp8bTi7YLgzZ0Y2pRewMKLku2pkjfMgHGnGGmEm85eCUVHFiF/C t9aVpfThoIPHAUmVMpUHo/2D6xs1ZLX4cl9GygWgNDCtyMjprfuZAFMspL8kMIv1lKnh FFP+cFqTyzkF+D25rpTUjIAY/a+EgpMsmzRbzp5Ed4VE8ASn4KTW5o51h321136qtoek W4lQ== 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:mime-version :content-transfer-encoding; bh=9v21Ix66GTJcQGhQxKIODW8bSYLFeuijiK0JgwHYvl0=; b=EKIwCm2pWeMdRIyZ8WJehgU2YlwdZ+LIUbnY/6xX6TWE6Acrjtw0Kn7oqIk3eIvwRB 0U3qHAqLLtXMomO4xCQtKpZ+0N1yEPbZCoF5+ctSR/psZNa/pR2lOZdYHFHjOY/nsfVl s1TgSKSJzK/aaRamUg7J5M6i/K6etrWFmbfwbLlUi5JSVgHkzh4gxak+cl3UzlNtyrdv 6bwXo0PDtFJzOaiZhrA3h4JtjSUhAddaaVuq4ne6aFyjyv5HjgHqMCun9fHMXYcg1I3e gKjINcg5fZc0ZaVQulegKvV2YzHwmwAR5NShp812VAlUQOsZZdOIzeC3MGzHH8VhKpMH tysw== X-Gm-Message-State: AJIora/RIYY1EVtq25pTadAJgn4c4tgEEuOOAH46AXhfWYroM+R8TMpK Kcir6MVcJ6FaCaTUSkjURtf1HRNCvGkuDg== X-Received: by 2002:a5d:6502:0:b0:21d:f19e:602b with SMTP id x2-20020a5d6502000000b0021df19e602bmr14031981wru.714.1658258260515; Tue, 19 Jul 2022 12:17:40 -0700 (PDT) Received: from orth.archaic.org.uk (orth.archaic.org.uk. [2001:8b0:1d0::2]) by smtp.gmail.com with ESMTPSA id d5-20020a5d6445000000b0021bae66362esm14017692wrw.58.2022.07.19.12.17.39 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 19 Jul 2022 12:17:39 -0700 (PDT) From: Peter Maydell To: qemu-devel@nongnu.org Cc: Richard Henderson , =?utf-8?q?Philippe_Mat?= =?utf-8?q?hieu-Daud=C3=A9?= , Aurelien Jarno , Jiaxun Yang , Aleksandar Rikalo Subject: [PATCH] target/mips: Handle lock_user() failure in UHI_plog semihosting call Date: Tue, 19 Jul 2022 20:17:37 +0100 Message-Id: <20220719191737.384744-1-peter.maydell@linaro.org> X-Mailer: git-send-email 2.25.1 MIME-Version: 1.0 Received-SPF: pass client-ip=2a00:1450:4864:20::433; envelope-from=peter.maydell@linaro.org; helo=mail-wr1-x433.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+patch=linaro.org@nongnu.org Sender: "Qemu-devel" Coverity notes that we forgot to check the error return from lock_user() in one place in the handling of the UHI_plog semihosting call. Add the missing error handling. report_fault() is rather brutal in that it will call abort(), but this is the same error-handling used in the rest of this file. Resolves: Coverity CID 1490684 Fixes: ea4210600db3c5 ("target/mips: Avoid qemu_semihosting_log_out for UHI_plog") Signed-off-by: Peter Maydell Reviewed-by: Richard Henderson Reviewed-by: Philippe Mathieu-Daudé --- NB: only tested with 'make check' and 'make check-tcg', which almost certainly don't actually exercise this codepath. --- target/mips/tcg/sysemu/mips-semi.c | 3 +++ 1 file changed, 3 insertions(+) diff --git a/target/mips/tcg/sysemu/mips-semi.c b/target/mips/tcg/sysemu/mips-semi.c index 5fb1ad90920..85f0567a7fa 100644 --- a/target/mips/tcg/sysemu/mips-semi.c +++ b/target/mips/tcg/sysemu/mips-semi.c @@ -321,6 +321,9 @@ void mips_semihosting(CPUMIPSState *env) if (use_gdb_syscalls()) { addr = gpr[29] - str->len; p = lock_user(VERIFY_WRITE, addr, str->len, 0); + if (!p) { + report_fault(env); + } memcpy(p, str->str, str->len); unlock_user(p, addr, str->len); semihost_sys_write(cs, uhi_cb, 2, addr, str->len);