From nobody Thu Apr 25 19:03:19 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=fail; 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=fail(p=none dis=none) header.from=linaro.org ARC-Seal: i=1; a=rsa-sha256; t=1616520408; cv=none; d=zohomail.com; s=zohoarc; b=QwUlzjlMRtaRbQRJuh2JsASCGFVUMSMCTe3u4FAc02ZkTR+C+meZaelW+8MWBkJJMSZJRDodUzppqlKC1N17ZXPhYY39Lax7iss2inmJ7OwSCNJQsz9+Q7qZ8EGetogLqvVPXEtp/Lt2WjBMOwN9VNiCI4QTxT1KfPlKcF2Yj6k= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1616520408; h=Content-Transfer-Encoding:Cc:Date:From:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:Sender:Subject:To; bh=i59NK8T1KKmM/jpHKwY4F5uG2e8WcL/wYXoZD+s8pas=; b=d0JzMpuGUth/gNFKnf8v92cqXSarXWjZ4gsYBlotMPrfk/mQqEwS4C0WF6UycwCXsU0Fa8JdT93F7AJO2cHnxCid0MqX6HM0DDh6p2j5uE4ujwvVU6I1W2tjczwDZFH+e5vtjO4QejgZK1TZHmjcoTbTb2m2t1sIUynRz4RGf1Q= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=fail; 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=fail header.from= (p=none dis=none) header.from= Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1616520408452644.5072349472969; Tue, 23 Mar 2021 10:26:48 -0700 (PDT) Received: from localhost ([::1]:48548 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1lOkni-0002LH-Eq for importer@patchew.org; Tue, 23 Mar 2021 13:26:42 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:52684) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1lOkAV-0004Up-ES for qemu-devel@nongnu.org; Tue, 23 Mar 2021 12:46:12 -0400 Received: from mail-wm1-x336.google.com ([2a00:1450:4864:20::336]:54965) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1lOkAP-0007RV-Sm for qemu-devel@nongnu.org; Tue, 23 Mar 2021 12:46:09 -0400 Received: by mail-wm1-x336.google.com with SMTP id k128so9027392wmk.4 for ; Tue, 23 Mar 2021 09:46:04 -0700 (PDT) Received: from orth.archaic.org.uk (orth.archaic.org.uk. [81.2.115.148]) by smtp.gmail.com with ESMTPSA id q15sm24045077wrr.58.2021.03.23.09.46.03 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 23 Mar 2021 09:46:03 -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=i59NK8T1KKmM/jpHKwY4F5uG2e8WcL/wYXoZD+s8pas=; b=n1YDtAvTnM6Fagg7I1Pw+qpfjIUD2eusTi4D+8adgkY1wG9E3XwIP+v3cbGcf2mVTq 30Ch6Zj7EBUZ7JWJzXpIs1rkjhEbbUot1tMUvOMEdJWyLVgrCGgThuY8eXPncYrXmSJS /3hm8hwLWvXg3qUqe5/hczTkWFRM9Z0e3GwyZrhrhJMkT+IN6iylVSuhi/mH5rb/ytt6 jvErrIF5MRxX6uAKvvwjnjz0hSR31q4BCHUXONCIhEFbLCDgsrlfRpLTBa1hFVV4MQuM IRO+LhHPukoaA11ydD5MS9kCoH8A0h4WWQ59dhep8M3Rgfas0nV9yqtrFUAaJ/11cQNQ ENZA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=i59NK8T1KKmM/jpHKwY4F5uG2e8WcL/wYXoZD+s8pas=; b=Ufloofg7LuLH/FnpOuwiF/0IVn3fY+DUZ085CUq2kvzGWFlwECHn/Hn2GTo/i+LmXW cfml/eVDQa1UAs45dx8IyVU7GxaNOPFrQKrTIIhf8qS4NUemqmuQghi6BqjunpGX7NLi sHZDio/lJzte6fNQ9MsaMfgbw6lIMUzIbtEBOp+n09htxVOXfrVtopCc1o3VdByj8j9z +bxX9EIX84QipfbArmWEnDxGSX7M+GAJ5hhOKrgEr0jwS8bP7Kqb1O76t9mkvrPhKHvc G4/5FFeVWnJkTVibcfBxFa6yqq+A5MJkeXIu80fVqgfRp93+LtlysXmepjGpYjI/xfyo yQdA== X-Gm-Message-State: AOAM532zfJcR3uKUSh5LT36q9w4yD47gaCNnritY3uvGQoKHyJfX/uju Qo1FDo7prlhNuZ9MXPD/hcHL+2eqi6CDxgqN X-Google-Smtp-Source: ABdhPJzYVIQT8xAkDe04Z70s6+kS9rZjRRFHYutjZ2ZBKk4apzk0Lhy3F0OrfqKTEPQO3CCQt3pLIg== X-Received: by 2002:a1c:7e16:: with SMTP id z22mr4182891wmc.74.1616517963690; Tue, 23 Mar 2021 09:46:03 -0700 (PDT) From: Peter Maydell To: qemu-devel@nongnu.org Subject: [PATCH] hw/pci/pci.c: Assert that pci_irq_handler() inputs are valid Date: Tue, 23 Mar 2021 16:46:01 +0000 Message-Id: <20210323164601.27200-1-peter.maydell@linaro.org> X-Mailer: git-send-email 2.20.1 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=2a00:1450:4864:20::336; envelope-from=peter.maydell@linaro.org; helo=mail-wm1-x336.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.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: "Michael S. Tsirkin" Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) Content-Type: text/plain; charset="utf-8" pci_irq_handler documents that it must be called with 0 <=3D irq_num <=3D 3 and level either 0 or 1. Add assertions that the caller has passed us in valid arguments. In particular, if a device model fails to set the PCI_INTERRUPT_PIN field in its config space correctly to indicate that it has an interrupt, and then tries to raise an interrupt (either by calling pci_set_irq(), or by getting a qemu_irq from pci_allocate_irq() and then calling qemu_set_irq() on that) we will now diagnose this device model bug with an assertion rather than engaging in the undefined behaviour of shifting by a negative number. Signed-off-by: Peter Maydell Reviewed-by: Isaku Yamahata Reviewed-by: Philippe Mathieu-Daud=C3=A9 --- hw/pci/pci.c | 3 +++ 1 file changed, 3 insertions(+) diff --git a/hw/pci/pci.c b/hw/pci/pci.c index 0eadcdbc9ec..38aefe22ab3 100644 --- a/hw/pci/pci.c +++ b/hw/pci/pci.c @@ -1449,6 +1449,9 @@ static void pci_irq_handler(void *opaque, int irq_num= , int level) PCIDevice *pci_dev =3D opaque; int change; =20 + assert(irq_num >=3D 0 && irq_num < PCI_NUM_PINS); + assert(level =3D=3D 0 || level =3D=3D 1); + change =3D level - pci_irq_state(pci_dev, irq_num); if (!change) return; --=20 2.20.1