From patchwork Fri Sep 22 17:52:57 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Kees Cook X-Patchwork-Id: 13396267 Received: from lindbergh.monkeyblade.net (lindbergh.monkeyblade.net [23.128.96.19]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 280364446E for ; Fri, 22 Sep 2023 17:53:20 +0000 (UTC) Received: from mail-pg1-x530.google.com (mail-pg1-x530.google.com [IPv6:2607:f8b0:4864:20::530]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 3854B269E for ; Fri, 22 Sep 2023 10:53:00 -0700 (PDT) Received: by mail-pg1-x530.google.com with SMTP id 41be03b00d2f7-5789ffc8ae0so1921322a12.0 for ; Fri, 22 Sep 2023 10:52:59 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; t=1695405179; x=1696009979; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:from:to:cc:subject:date:message-id:reply-to; bh=R6n/dIamPeUMVNuFW4cdEBQ5hVxUiI5G+G4L0zhGFPQ=; b=Zkx7sA+8UIosoEu+ylBRpTK1i5PtoHGq8oXWeXSVq53apmr+B5J8IFiq2l0HEfOIEq v9z2KT99HS0eHYprPyDrzzDuvEH8FUi9DkX/eTSmqj7BuGefJ/sdHzlohxqvQ3C1YA5Y a7l0wPZTnJFtMwLVEUMqf7Pr7c/Rc0veVi/v4= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1695405179; x=1696009979; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=R6n/dIamPeUMVNuFW4cdEBQ5hVxUiI5G+G4L0zhGFPQ=; b=LT2jrNA246SLjj+xnPW1MllO8XP+IEfN4M+uNM1NMzzCfaUk04LMH6RgOBz8exWcxM JkTbkE4JMda63ZtyBbqxQEApdwTY0QAxZI0awxLoLhw+fEyaW5pVCLXgAFqQ8dM80oq9 9l/4PFsZI0C0CWFOHiAI/vxBtLLaxjxuTtHAFHkcfVnze+4LgsiW5OhCQTk1AUVkTyzG +GpTMnWdJRgmiKDEIvT+chr5XGoHSBWTYjsnOEwIVF9kWLvZDPH9rddNtgYguL67RNdA pGd9wACEG72LxLTLnwtMAgUEItvG9iWWcYZaR/XhulrJCD95s7V87lfLnC4v5UMQB6gb O0pA== X-Gm-Message-State: AOJu0Yw+oiYcpGTvkfboxbikoo1GIyuA1zqUAhlMt/AtZRK9xlSQMJIM nAz5QPNnKj35p5gNxkqs0RBozw== X-Google-Smtp-Source: AGHT+IHs/kWRYrx0882mgjeumpR6xf+dWnB3lwAWwCO7lNvryszSCtcH04kTeCrZkbhmP/XPZZVTRg== X-Received: by 2002:a17:90b:fca:b0:273:f848:7da2 with SMTP id gd10-20020a17090b0fca00b00273f8487da2mr391578pjb.45.1695405179414; Fri, 22 Sep 2023 10:52:59 -0700 (PDT) Received: from www.outflux.net (198-0-35-241-static.hfc.comcastbusiness.net. [198.0.35.241]) by smtp.gmail.com with ESMTPSA id lt22-20020a17090b355600b00276d039aecasm3613376pjb.13.2023.09.22.10.52.58 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 22 Sep 2023 10:52:58 -0700 (PDT) From: Kees Cook To: "K. Y. Srinivasan" Cc: Kees Cook , Haiyang Zhang , Wei Liu , Dexuan Cui , Lorenzo Pieralisi , =?utf-8?q?Krzysztof_Wilczy=C5=84?= =?utf-8?q?ski?= , Rob Herring , Bjorn Helgaas , linux-hyperv@vger.kernel.org, linux-pci@vger.kernel.org, Nathan Chancellor , Nick Desaulniers , Tom Rix , linux-kernel@vger.kernel.org, llvm@lists.linux.dev, linux-hardening@vger.kernel.org Subject: [PATCH] PCI: hv: Annotate struct hv_dr_state with __counted_by Date: Fri, 22 Sep 2023 10:52:57 -0700 Message-Id: <20230922175257.work.900-kees@kernel.org> X-Mailer: git-send-email 2.34.1 Precedence: bulk X-Mailing-List: linux-hardening@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-Developer-Signature: v=1; a=openpgp-sha256; l=1513; i=keescook@chromium.org; h=from:subject:message-id; bh=HwvhrIzwS1OngYd5h25a5+mvpp+30OatzAtcoVNIjeY=; b=owEBbQKS/ZANAwAKAYly9N/cbcAmAcsmYgBlDdR5RsFIE1XK7abVppH8HIyRHCNnXLkIt/UkZ OCZ2BX0XXmJAjMEAAEKAB0WIQSlw/aPIp3WD3I+bhOJcvTf3G3AJgUCZQ3UeQAKCRCJcvTf3G3A JncDD/46utmowUFXG6KoCyjTSlzv++ojxe1IcbrO+gufqTuw+Zx9r3xXs4QIoyKi0eoj4jJJ2+/ 3G3V1RQtSXyo2+80fzGYwvGjiAxWZFUqpdWP89olIkZkeSRr4BZb3gPdRtaf3z5yqnYeFB7Ziw1 7zEQEML3k5dIZKlwVoX6voveJFbeZA18/d7KXyr/+YM2bpBa4rhYjLYPc5zqZKU0pMUgRK18NyM sXIRpCsfnMA7Pv5Wpl/MfhbaUYg8DL6+1Lc1nyv2pcoXpAj6UDyOsPbVS2oISWnG0syC/qeiz3y 6fhUJJv1t5jR2Fy4i25bMMqUIROm3k9XEmdslvlFRhVi5pejG2ExMka2HTOsamwrf2ckt+FLkDG 66GyvAsPqpuOsIpO8IlKusDoYNyHAcN3PJZ/dQJHjyEwClZUOC8XxxJrmdT8PZqsU5pzBxzXfun fTkpKGSLKCXIidLcdyXyKD2bZtgS9DiKYIdZ+Pdis2gpsl7RS/cCOMdfmHUeddFhXkNtca9K7Od 4/maxSa3KshNdnfJ0J1lxw+j3JMSjksAybCVgcQujf2TFW4p3cuG4n2P+9b4FfsyqCFgV2Fm6aH YQa8Y6HUI5fH7IAPonRww1YpCuZugNBdNzDh24gdEPiNlYqOl5sTEs9jIEtOcLrrd+NZFj2CmuD mOQAEY6 dJELRjrw== X-Developer-Key: i=keescook@chromium.org; a=openpgp; fpr=A5C3F68F229DD60F723E6E138972F4DFDC6DC026 X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF, RCVD_IN_DNSWL_BLOCKED,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Prepare for the coming implementation by GCC and Clang of the __counted_by attribute. Flexible array members annotated with __counted_by can have their accesses bounds-checked at run-time checking via CONFIG_UBSAN_BOUNDS (for array indexing) and CONFIG_FORTIFY_SOURCE (for strcpy/memcpy-family functions). As found with Coccinelle[1], add __counted_by for struct hv_dr_state. [1] https://github.com/kees/kernel-tools/blob/trunk/coccinelle/examples/counted_by.cocci Cc: "K. Y. Srinivasan" Cc: Haiyang Zhang Cc: Wei Liu Cc: Dexuan Cui Cc: Lorenzo Pieralisi Cc: "Krzysztof WilczyƄski" Cc: Rob Herring Cc: Bjorn Helgaas Cc: linux-hyperv@vger.kernel.org Cc: linux-pci@vger.kernel.org Signed-off-by: Kees Cook Acked-by: Wei Liu Reviewed-by: Gustavo A. R. Silva --- drivers/pci/controller/pci-hyperv.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/drivers/pci/controller/pci-hyperv.c b/drivers/pci/controller/pci-hyperv.c index bed3cefdaf19..30c7dfeccb16 100644 --- a/drivers/pci/controller/pci-hyperv.c +++ b/drivers/pci/controller/pci-hyperv.c @@ -545,7 +545,7 @@ struct hv_pcidev_description { struct hv_dr_state { struct list_head list_entry; u32 device_count; - struct hv_pcidev_description func[]; + struct hv_pcidev_description func[] __counted_by(device_count); }; struct hv_pci_dev {