From patchwork Tue Oct 4 13:01:20 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Alex_Benn=C3=A9e?= X-Patchwork-Id: 612244 Delivered-To: patch@linaro.org Received: by 2002:a17:522:c983:b0:460:3032:e3c4 with SMTP id kr3csp181755pvb; Tue, 4 Oct 2022 06:42:49 -0700 (PDT) X-Google-Smtp-Source: AMsMyM65+Au3+iYMxv3abNN48XV2SXUkpnVHUbQmCls0pdQFfBpfx1TaZUX+ovi5/mKosEVi5Cbu X-Received: by 2002:ad4:5dcf:0:b0:4b1:aa37:f4c7 with SMTP id m15-20020ad45dcf000000b004b1aa37f4c7mr3923547qvh.13.1664890969093; Tue, 04 Oct 2022 06:42:49 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1664890969; cv=none; d=google.com; s=arc-20160816; b=XOlYt8eRW3hNj02raKuzkB1jWDu2wzvt9K87uuiFFQWIUmHDBRYMyNlR8SJDIX+4pR 9EDiTICWB+GYPl3lGJBI7/9MSqP3oufhfCmNaE/VFmWE4+DV01uL/DNLFpiF5wW/5kxg hvptA0tl7flXSTEUwlqh6DlnJdgsjg1cbIHTmzRDe+0vO2PorK9XYK9HmY/tpoWiWC9J RmxWTaSKxMhvzd9OL3vgvsdq6DMJ5Pqsbxc8K/YTq8syfRgidvSNoO8PV785wQNSvZRl C3e4IBMjxHHSRrenMbG8PVFRCpXDgTBtHD3MSeiO5NoZcqWRU+yqAjisLy0EL6+mwTUu 5ZVQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:content-transfer-encoding :mime-version:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=jSmfjv0ctja6HwiXXo3PB6e8oy0gMZiBORhXoR2vclY=; b=bq4tx3ViLa9USDsISUaH8knXF3oKW32LDC8hJ32ov5YDpKtvHf62a0J3HnB09Dd/ly qOHqaHVWjwywtxx13sH4zCYEWYCAV3gyJAwkpIBfjDZDdofGmfuXR4PnF/4VW12uZ6y+ 09J9LOlEKyIQha1oprEUdq7Q2BJK/y2mYUzicDPdP44U+ocSM15K04MO4eKTRxwun0Wp OzkmlmECnokOUunqfoWwlnlVyfNYwRuj+Q63dLKKibjQ8rYpJr5W+qzztOrZKmuMuKsn mcIEff7+c6A3Lk849gn+nJBEdmFtzblO95QB1/AaOBkGqSBo94G2MOygauBjV4dpRrFD t3Rw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=scMcTcXF; 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 bl36-20020a05620a1aa400b006cbbc3ea96fsi119952qkb.265.2022.10.04.06.42.48 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Tue, 04 Oct 2022 06:42:49 -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=scMcTcXF; 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]:57666 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1ofiC8-00055A-IN for patch@linaro.org; Tue, 04 Oct 2022 09:42:48 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:54802) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1ofhgO-0007Q2-Ds for qemu-devel@nongnu.org; Tue, 04 Oct 2022 09:10:00 -0400 Received: from mail-wm1-x334.google.com ([2a00:1450:4864:20::334]:55888) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1ofhgM-00008g-P7 for qemu-devel@nongnu.org; Tue, 04 Oct 2022 09:10:00 -0400 Received: by mail-wm1-x334.google.com with SMTP id t4so8835027wmj.5 for ; Tue, 04 Oct 2022 06:09:57 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date; bh=jSmfjv0ctja6HwiXXo3PB6e8oy0gMZiBORhXoR2vclY=; b=scMcTcXFZW+0RHO5twtfPbureADnmoqR1EReSXJH64RUAC2ogM45OX82f0nasZePAg JIcmxq8GLF0dhyOyM0WQhDAKwAMSmATu7GEUkpy6JlL7sway6UvR5K90AtKrMZZ0PWAZ jmJBhAXxp32IIErAq6oWLgpo7qDSuhS6iU0TQVDsD7ZH5mhXPRAxy2helH8FlPDebQtn ZxY5M3B07TJjVbx3olbEq3pF0aXrHqfCh9mHTYmrfvyzeqJVftADWT/A9UIy1zaluCK0 BMW1uDP7nCOYGonpFn+ya+7WQRGwUsgyvdfCXsOIIyAIXMdTQei+GhMjLzLitKCO92er 11jw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; 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; bh=jSmfjv0ctja6HwiXXo3PB6e8oy0gMZiBORhXoR2vclY=; b=2TT/p9I0mdEbgJHk4LBDBoKjWLq6Rnopj4rAt/8TK1nzfXeTonDPrtOLpWJOK5G+iX 6SbZ4nBgpRBjSMq6Kx1YasNjYBifaLZYG/o5SQOR1CeCG48tRhK9HoRFBNfJiAkmxTA/ UmInW4BuuNeykyc0Q9NZKx6THg5HlKfqoxG2m8wV5Q7GCrzgQ5yvyPSb7C9Q6xbmfa3v ff8jCQilJppZNCTDJUK6Z1EyQkQE8mQuFjnrGTvrxRQvu2cE6/SnJxmDv4gImyNqIYJt wxifUMoxrMGE/TbOlZ3H2v5bcUUIjW1H6sCKBHj6b8GLPofTiTRx3F7yRphXoYhYCULM SVAw== X-Gm-Message-State: ACrzQf0gtg0Amia5p/7zNsYFhZJvrAvRGYSAY5dZn9gIpUg9l5utEcH2 y6ZtXk2NfA6cqJzL4Ig+rmBA8g== X-Received: by 2002:a7b:c8d6:0:b0:3b4:868b:afc3 with SMTP id f22-20020a7bc8d6000000b003b4868bafc3mr9917718wml.66.1664888996025; Tue, 04 Oct 2022 06:09:56 -0700 (PDT) Received: from zen.linaroharston ([185.81.254.11]) by smtp.gmail.com with ESMTPSA id 12-20020a05600c240c00b003b4764442f0sm14523827wmp.11.2022.10.04.06.09.52 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 04 Oct 2022 06:09:54 -0700 (PDT) Received: from zen.lan (localhost [127.0.0.1]) by zen.linaroharston (Postfix) with ESMTP id 67A981FFD8; Tue, 4 Oct 2022 14:01:42 +0100 (BST) From: =?utf-8?q?Alex_Benn=C3=A9e?= To: qemu-devel@nongnu.org Cc: stefanha@redhat.com, Richard Henderson , Damien Hedde , =?utf-8?q?Alex_Benn=C3=A9e?= , =?utf-8?q?Philippe_M?= =?utf-8?q?athieu-Daud=C3=A9?= , Alexandre Iooss , Mahmoud Mandour Subject: [PULL 36/54] plugins: Assert mmu_idx in range before use in qemu_plugin_get_hwaddr Date: Tue, 4 Oct 2022 14:01:20 +0100 Message-Id: <20221004130138.2299307-37-alex.bennee@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20221004130138.2299307-1-alex.bennee@linaro.org> References: <20221004130138.2299307-1-alex.bennee@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2a00:1450:4864:20::334; envelope-from=alex.bennee@linaro.org; helo=mail-wm1-x334.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+patch=linaro.org@nongnu.org Sender: "Qemu-devel" From: Richard Henderson Coverity reports out-of-bound accesses here. This should be a false positive due to how the index is decoded from MemOpIdx. Fixes: Coverity CID 1487201 Signed-off-by: Richard Henderson Reviewed-by: Damien Hedde Message-Id: <20220401190233.329360-1-richard.henderson@linaro.org> Signed-off-by: Alex Bennée Reviewed-by: Philippe Mathieu-Daudé Message-Id: <20220929114231.583801-37-alex.bennee@linaro.org> diff --git a/plugins/api.c b/plugins/api.c index 7bf71b189d..2078b16edb 100644 --- a/plugins/api.c +++ b/plugins/api.c @@ -289,6 +289,8 @@ struct qemu_plugin_hwaddr *qemu_plugin_get_hwaddr(qemu_plugin_meminfo_t info, enum qemu_plugin_mem_rw rw = get_plugin_meminfo_rw(info); hwaddr_info.is_store = (rw & QEMU_PLUGIN_MEM_W) != 0; + assert(mmu_idx < NB_MMU_MODES); + if (!tlb_plugin_lookup(cpu, vaddr, mmu_idx, hwaddr_info.is_store, &hwaddr_info)) { error_report("invalid use of qemu_plugin_get_hwaddr");