From patchwork Tue Jan 11 17:10:48 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Peter Maydell X-Patchwork-Id: 531124 Delivered-To: patch@linaro.org Received: by 2002:ad5:544f:0:0:0:0:0 with SMTP id a15csp3676729imp; Tue, 11 Jan 2022 09:23:12 -0800 (PST) X-Google-Smtp-Source: ABdhPJxJWbVTypysGyRVxdor5o9gaShXXPQ0VhY2H9rBkjxNzhtrYXhjicZE65t2Pcaah6Xg54/V X-Received: by 2002:a92:d08b:: with SMTP id h11mr3104951ilh.216.1641921792292; Tue, 11 Jan 2022 09:23:12 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1641921792; cv=none; d=google.com; s=arc-20160816; b=bFdjP1ctvMrYvisd4Xbsa1WAILwgg23wRum4WX885f7HZ9nvqLseVgXqly0Pkv2i9y tEpdu/1F4btJKpFtOab+FMWCwwFe1kK4VeRvTMOpoS3M3uC+IqwhudyVA00vKBT5PstX uQnEFG8sKIGq4zoWHqAHu/UCGKLo3OqN48EEj1HkN7UEtQS7qNbK3MJqHRRb8bCiapF1 t/i1BiuRbcFY+96yiqfBDOahGe9JKUNIK3Md7MlcEipv3qJmYemsm9nDBb8KnsFNBE0Z UZL9XhsN+CGo7vTsTdYWesF2K5rJtExUAQbxmODuiBEykU2VuKz/sVbxqIgewfW7l1sM apHw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:cc:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:content-transfer-encoding :mime-version:references:in-reply-to:message-id:date:subject:to:from :dkim-signature; bh=bD0PDqtOotm00lmQT/lZs8XVkkqOyVklOaZCqmm8ZmM=; b=a2DysfllQH/QzP8lsBitG+oQbwBIRDBim6+GinW1lu1Upkt7I8Ih/dATZL6iqRNEAG gOe7dLj/hI1OSd0NcSJq3RPvrc2v567YBEiuJHYHgpinb4I+tNDlCpvBfH4XqFeKXZn1 Jn9o3Xb/IeACnOzg0THXKmSfgd/Wpp9DuCIvXLnzgAWTDkLpnkh3wuPJAQUoORLTgLKd 7km3/bbvy6TcnxQTDlPNHnZmGsA5pTabeuRhKpirYlq3SKWX4Pfnx52V7BR1pn/vMC+3 QD720FC6KFF30NmJGSm7ZpYbYi338UXmqOHnX7BJziX1YI/49qAftbFyq9f7GWeylRl4 RF6A== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@linaro.org header.s=google header.b=F1eAfaZp; 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=fail (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 s23si4026838ioj.8.2022.01.11.09.23.12 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Tue, 11 Jan 2022 09:23:12 -0800 (PST) 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=fail header.i=@linaro.org header.s=google header.b=F1eAfaZp; 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=fail (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: from localhost ([::1]:55956 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1n7KrX-000108-QW for patch@linaro.org; Tue, 11 Jan 2022 12:23:11 -0500 Received: from eggs.gnu.org ([209.51.188.92]:35926) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1n7Kfq-0005DC-4g for qemu-devel@nongnu.org; Tue, 11 Jan 2022 12:11:11 -0500 Received: from [2a00:1450:4864:20::42c] (port=44655 helo=mail-wr1-x42c.google.com) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1n7Kfl-0007LC-GO for qemu-devel@nongnu.org; Tue, 11 Jan 2022 12:11:05 -0500 Received: by mail-wr1-x42c.google.com with SMTP id k18so34173169wrg.11 for ; Tue, 11 Jan 2022 09:11:00 -0800 (PST) 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=bD0PDqtOotm00lmQT/lZs8XVkkqOyVklOaZCqmm8ZmM=; b=F1eAfaZphieMMS6rwNRSadXE8oXaLTNK69dQf8YByZA/0xfinJyFTO4mtV8l+7RtGA +RwXEAQOq0F+jwLc7/U+CcScBu8+SaiVPW5C+thjq8f2dJtu09fdfYXchac4HJt3LNUW cKk8JldGCgR/J+Iv6Fh9MTtoUHpl4JEmzYoI5VdBQgJwjHPdcYXkPYFDJvLu3cSnCFdn k3jBTIS8/eKC5drfU0zkPY5vHB5o/3Ed62Wsi1CDs6IlL/rUUM2HLJFURBh+jWlDvB4H Tkd3PXjcqDI6O17E53WSce029r7oymx3rkdNSXO9wd5R5XyK+VoUqcBjtIl9iUEK7KBA sRMw== 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=bD0PDqtOotm00lmQT/lZs8XVkkqOyVklOaZCqmm8ZmM=; b=Jew02HBwzk0onzpJ7MhVDHa80JF/6DefWcffOYePiE+DS/6Afs0kA3Rl4VszwZ3H6x b1qkTly6HGKYUmUMrfZbmHCwTW4aH8kyeJDvQRKznZ6reFA1nqLQAftwrkx3GjN/oaCr KfEZw5GoRzW4UJ78FZB15SLr3QFiVoNcBbGINBXOw3UeUY5lVPmHJTCI3+6eyB/RE+jL ACVy6j9vtFJM3m7m+mV6ov5ZljJsYH2bJ/cPoWeYxw2Bb0Z2o3kCQGOVhOrEffSRVkN3 U592fWNtvujoP5JdtTbJ/oYeoNP6jkewZPUUczB+p6cMYwmWuRm1BJDNyGQoQdw9obvU aQGg== X-Gm-Message-State: AOAM533smX6uxAHTDlr0+fFh+Cal3yBb8rkAqmR6dAAaIbYzUA9u2fbI iecnhTLBM0pzKDV/R23BaciMyQ== X-Received: by 2002:a05:6000:1883:: with SMTP id a3mr4811662wri.565.1641921059907; Tue, 11 Jan 2022 09:10:59 -0800 (PST) Received: from orth.archaic.org.uk (orth.archaic.org.uk. [2001:8b0:1d0::2]) by smtp.gmail.com with ESMTPSA id c7sm11157941wri.21.2022.01.11.09.10.59 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 11 Jan 2022 09:10:59 -0800 (PST) From: Peter Maydell To: qemu-arm@nongnu.org, qemu-devel@nongnu.org Subject: [PATCH v2 13/13] hw/intc/arm_gicv3_its: Range-check ICID before indexing into collection table Date: Tue, 11 Jan 2022 17:10:48 +0000 Message-Id: <20220111171048.3545974-14-peter.maydell@linaro.org> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20220111171048.3545974-1-peter.maydell@linaro.org> References: <20220111171048.3545974-1-peter.maydell@linaro.org> MIME-Version: 1.0 X-Host-Lookup-Failed: Reverse DNS lookup failed for 2a00:1450:4864:20::42c (failed) Received-SPF: pass client-ip=2a00:1450:4864:20::42c; envelope-from=peter.maydell@linaro.org; helo=mail-wr1-x42c.google.com X-Spam_score_int: -12 X-Spam_score: -1.3 X-Spam_bar: - X-Spam_report: (-1.3 / 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, RDNS_NONE=0.793, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=no 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: , Cc: Shashi Mallela , =?utf-8?q?Alex_Benn=C3=A9e?= Errors-To: qemu-devel-bounces+patch=linaro.org@nongnu.org Sender: "Qemu-devel" In process_its_cmd(), we read an ICID out of the interrupt table entry, and then use it as an index into the collection table. Add a check that it is within range for the collection table first. This check is not strictly necessary, because: * we range check the ICID from the guest before writing it into the interrupt table entry, so the the only way to get an out of range ICID in process_its_cmd() is if a badly-behaved guest is writing directly to the interrupt table memory * the collection table is in guest memory, so QEMU won't fall over if we read off the end of it However, it seems clearer to include the check. Signed-off-by: Peter Maydell Reviewed-by: Alex Bennée Reviewed-by: Richard Henderson --- hw/intc/arm_gicv3_its.c | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/hw/intc/arm_gicv3_its.c b/hw/intc/arm_gicv3_its.c index ef6c0f55ff9..b2f6a8c7f00 100644 --- a/hw/intc/arm_gicv3_its.c +++ b/hw/intc/arm_gicv3_its.c @@ -299,6 +299,13 @@ static ItsCmdResult process_its_cmd(GICv3ITSState *s, uint64_t value, return CMD_CONTINUE; } + if (icid >= s->ct.num_ids) { + qemu_log_mask(LOG_GUEST_ERROR, + "%s: invalid ICID 0x%x in ITE (table corrupted?)\n", + __func__, icid); + return CMD_CONTINUE; + } + cte_valid = get_cte(s, icid, &cte, &res); if (res != MEMTX_OK) { return CMD_STALL;