Received: by 2002:a05:7412:37c9:b0:e2:908c:2ebd with SMTP id jz9csp2973840rdb; Fri, 22 Sep 2023 13:56:05 -0700 (PDT) X-Google-Smtp-Source: AGHT+IFPrf9iB4idvOg+kpnIgDLFcrHcAUOsNOCV0XaaVED+/mTvQQHfv9dFWLuSPGII2X5tkvWQ X-Received: by 2002:a17:902:e845:b0:1c4:4a24:dfe2 with SMTP id t5-20020a170902e84500b001c44a24dfe2mr598370plg.68.1695416164775; Fri, 22 Sep 2023 13:56:04 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1695416164; cv=none; d=google.com; s=arc-20160816; b=lE94Jdfscuf6zQOqYDBciKKLvdQLJrKnw39GtvHRadgnKpZeY2/lra+bLFWm0ZR0m2 QdVaC++AMdbFLRWTnaCH8si2sp3ZnYDpkb4eLo1NFBvr5A4M/wmHXJsmuTKB9MVQUZJB vriLqXLG0+1joZI4eztli1xlavV8LDtrOvQqmB8q6zsTmV9MRVC/zBbCmhKlzA6ButTn soeBhIo16oMDW91NG5w7r94tElh2U01hrDVVFkGAYRzr029aI/a6wD0xfYW0I10UNP9Y MK6DPAv1Zvc9pln87m9Qyf3tFD9ZSymM+7bHCH3v2EviseK4ZGBNzGdH+nw0hYmsMUCH BSLQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :message-id:date:subject:cc:to:from:dkim-signature; bh=R6n/dIamPeUMVNuFW4cdEBQ5hVxUiI5G+G4L0zhGFPQ=; fh=QFS9Rlnx6CZDvGL8OTq6s6ghrT8BM8h60Y/Egl+Ieh4=; b=rp5SwH5S1+B+PxZL0+RDTifD3Bg3k6useBqRfVnI3maE2N5LEav1/tmFD5UCSHYVdV 5H+qZwZRdUb4DaQDAgG/HJCIqjdf3wSes1/3FEShmq9UAZpRLvR0MlRqly2uAFoVEhDz 80nOkgJD2bNt5etLKDYIP6FD1jGZz6Gol9mLtHSw0qL0tztjsRR9/oqc+RRLWLCmCTWy Fmc2gQDKBz/tW/dwjEH4ukT1eP4uFjkpGKculTUMQ1md9ox6fK2mrndo/h0CttnaQO1i AtJhMjOlbLj1ZnpGZqP+iYKuBSkzF+CH2BVADpMJweUX4U7mwKcJuf2H6zzM1oGoCZNW n4Ew== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@chromium.org header.s=google header.b=Zkx7sA+8; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:1 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=chromium.org Return-Path: Received: from morse.vger.email (morse.vger.email. [2620:137:e000::3:1]) by mx.google.com with ESMTPS id 6-20020a170902e9c600b001b9e9b21287si4260583plk.427.2023.09.22.13.56.04 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 22 Sep 2023 13:56:04 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:1 as permitted sender) client-ip=2620:137:e000::3:1; Authentication-Results: mx.google.com; dkim=pass header.i=@chromium.org header.s=google header.b=Zkx7sA+8; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:1 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=chromium.org Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by morse.vger.email (Postfix) with ESMTP id 7C789837A4D1; Fri, 22 Sep 2023 10:55:30 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at morse.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232828AbjIVRzU (ORCPT + 99 others); Fri, 22 Sep 2023 13:55:20 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:34648 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233996AbjIVRyp (ORCPT ); Fri, 22 Sep 2023 13:54:45 -0400 Received: from mail-pg1-x52f.google.com (mail-pg1-x52f.google.com [IPv6:2607:f8b0:4864:20::52f]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 388D726A0 for ; Fri, 22 Sep 2023 10:52:59 -0700 (PDT) Received: by mail-pg1-x52f.google.com with SMTP id 41be03b00d2f7-578a91ac815so1913466a12.1 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=wR0XyiANwIpslRFUBR4dMqcMofgu7PCELNNYm3dxq6syekrMvIc72Y/yno6ZcuSAgO p5wQ8WccT4FpLfFuRtqqoGSjL+er6HyRZZZNpQSxJG0lvRRrBpRVFk+zPKSaDBcGREGb B55qgmp1Tjiwtxl4veJ3XeszCbBjXOm8737PkVtPjDaiiAueWCIRyiyvUUEehesUwHDr oVTql6vym7IljvH041PolzgRR9fjFDGn9+OOogf0+OuMuBDQ8tkxplCoiDO3Aq8YeyH0 6eQBF7o+WJAaDwiyvrF6YhKf8Q5T6/w4TVmpQV32+Sx0v03fJa7GFzmfx9Zjz/DIkdIU v1Dg== X-Gm-Message-State: AOJu0Yypn4+KY32sVQktxLSf8nT74jdWzfTXiPLcHw80SK3YfXIt+EdR +7KrnfDnQKKWrvBAAdDTIiTB7Q== 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=20Wilczy=C5=84ski?= , 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 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 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 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-0.9 required=5.0 tests=DKIMWL_WL_HIGH,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,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 morse.vger.email Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (morse.vger.email [0.0.0.0]); Fri, 22 Sep 2023 10:55:30 -0700 (PDT) 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 --- 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 { -- 2.34.1