From patchwork Fri Sep 29 18:04:24 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Kees Cook X-Patchwork-Id: 13404732 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 8B1C066681 for ; Fri, 29 Sep 2023 18:04:38 +0000 (UTC) Received: from mail-pg1-x534.google.com (mail-pg1-x534.google.com [IPv6:2607:f8b0:4864:20::534]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id CC33BCF3 for ; Fri, 29 Sep 2023 11:04:36 -0700 (PDT) Received: by mail-pg1-x534.google.com with SMTP id 41be03b00d2f7-5855333fbadso3240305a12.1 for ; Fri, 29 Sep 2023 11:04:36 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; t=1696010676; x=1696615476; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=J1v3O8Y0CLFHcIVug6/xydUDIhYw4BbQ+Ux1bHhPShA=; b=cbTOKtunlDcbaub/tWHdE6pCd5d3tSM1bl91q2hx3xWKEudWNUrov2insAI/zlAV32 jtQuwhYnYDt9ShE5SHmvd1z+cBIA57CUO39EXzIOb6kTX2BUMxVSpDuVdD+PqWp0mSrw xS7OUaXrwasRnjtgKB+MPP6Yls3vT1d1uOqo0= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1696010676; x=1696615476; 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:message-id:reply-to; bh=J1v3O8Y0CLFHcIVug6/xydUDIhYw4BbQ+Ux1bHhPShA=; b=BkxDX1v73iQ7tPxSFftxzpZCfGcZZdU+HZ13m7IqVFd9nRnsuLxURfv1W0ZmLp3661 2BFVKJAIcwy97C4PRbxSvQVlLCQEdizi3yy+TmdYzZrQgWvgCJ0rK9yE9E/80iSf0NxR rJGigFUPLAsutUgg32IKEwy4E7W+F2a/aa4tNWFpiVB2rxlRbVDZWigo2/kZilDqKFyA xqTyQDLYKbuZ8Ue8FZO4iuS27fES/RgpPQWdd9SQDwjiR/rQdpNM46cHTia0GqoUyIca s8P4iIoy0X3ngvufi867iliA0WHcFeGSMxRQC6x1Erp3zSW9dlhyTPT6QHEYp+/lpF3P oYCg== X-Gm-Message-State: AOJu0YwdhikQp2ehPlDZ45NLqzqI99fHo7OGWv3+6pQD3R1rycvWR+NQ 1WEDZl7cdwZ7OuuLQkOesAyIvg== X-Google-Smtp-Source: AGHT+IHKYAnhCdsp9/XUAjoT8AOVwZwLCEjfmC0BrAcjWZiOg0t25ONKgJp0Zm+bImAEicHDnkFA+Q== X-Received: by 2002:a17:90a:ca90:b0:26d:355a:47e3 with SMTP id y16-20020a17090aca9000b0026d355a47e3mr4692859pjt.38.1696010676160; Fri, 29 Sep 2023 11:04:36 -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 c9-20020a17090ab28900b00279163e52bbsm1786686pjr.17.2023.09.29.11.04.32 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 29 Sep 2023 11:04:34 -0700 (PDT) From: Kees Cook To: Jason Gunthorpe Cc: Kees Cook , Leon Romanovsky , linux-rdma@vger.kernel.org, Dennis Dalessandro , =?utf-8?q?H?= =?utf-8?q?=C3=A5kon_Bugge?= , Avihai Horon , Anand Khoje , Mark Bloch , Christian Benvenuti , Nelson Escobar , Bernard Metzler , Bart Van Assche , "Gustavo A. R. Silva" , Nathan Chancellor , Nick Desaulniers , Tom Rix , Patrisious Haddad , Chuck Lever , Tom Talpey , wangjianli , linux-kernel@vger.kernel.org, linux-hardening@vger.kernel.org, llvm@lists.linux.dev Subject: [PATCH 1/7] RDMA: Annotate struct rdma_hw_stats with __counted_by Date: Fri, 29 Sep 2023 11:04:24 -0700 Message-Id: <20230929180431.3005464-1-keescook@chromium.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230929180305.work.590-kees@kernel.org> References: <20230929180305.work.590-kees@kernel.org> 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=1154; i=keescook@chromium.org; h=from:subject; bh=yQF+4e/aqHGB0srQ03GVNPOtQXH2kpsbv4fi3QGNdHI=; b=owEBbQKS/ZANAwAKAYly9N/cbcAmAcsmYgBlFxGtgBLXF4g50iVq6EwmS+sUwzqICeThKMiiq qjLqq6vT+iJAjMEAAEKAB0WIQSlw/aPIp3WD3I+bhOJcvTf3G3AJgUCZRcRrQAKCRCJcvTf3G3A JmJbEACVWuoy65M7vBgTJIDcKZPUvKhfzgLipudCYXts5TRyUgUktR6iJw19uk3BoRwPxFocyM3 ExfOcE8LBavCmfabOcJ39ktmgXtRjV58WqVSvO2/j5sSyvKRz7LGsfWAGZSR/DWCjHEAh+VMZhU Z8OPkNfIJj7YTE+E9jOGy/F04iicCdFqr8JQa2ewd1laq1+UWvf7EUi1hHFAZJnsJNQz+mmLi0F UzE8KI22713mH9lZvekZjD3P4XWexgfHDNfB5dN9IeQL64dQuNSTgKjXi24c05ztrn/fM5MbpUw pADkVjP2pObgLKlNZm2IBCmdiay5gjdGOEF6hVKkM6wctvZFLvaJR+C0hHLALyE8ETpnAlI11Pj LPkJY48XnA6eqip5rHG9dSFxp+AMmY3b5JwYyobAjt06jhz7rP84urhSYKpr8Yh6/hLBIGxo23u 70TdBMtN7JrvnKMZ4f9QVTMo7IA2bg+aTqPN5wpsGB9lnVXPRmROUU/uFp01np3OeFDtkP0klBD gZDscuQtcb6PUFOnZ0vTXaWFZ0B/BHfq//tDhTWm4Ld8cgX/z7d5/roVZ5Ff1aWEj5FykucrrJL vLwSQDrgsIHWx806Gkwz/89heSeoInGCh1noMh3fU8iXAxEfa7W0Vd8ey3taoQsTzjtgAvWSvWg zv8haP9PfQ1toZA== 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 autolearn=ham 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 rdma_hw_stats. [1] https://github.com/kees/kernel-tools/blob/trunk/coccinelle/examples/counted_by.cocci Cc: Jason Gunthorpe Cc: Leon Romanovsky Cc: linux-rdma@vger.kernel.org Signed-off-by: Kees Cook --- include/rdma/ib_verbs.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/include/rdma/ib_verbs.h b/include/rdma/ib_verbs.h index e36c0d9aad27..79bcdebbe228 100644 --- a/include/rdma/ib_verbs.h +++ b/include/rdma/ib_verbs.h @@ -607,7 +607,7 @@ struct rdma_hw_stats { const struct rdma_stat_desc *descs; unsigned long *is_disabled; int num_counters; - u64 value[]; + u64 value[] __counted_by(num_counters); }; #define RDMA_HW_STATS_DEFAULT_LIFESPAN 10 From patchwork Fri Sep 29 18:04:25 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Kees Cook X-Patchwork-Id: 13404729 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 CC26B66674 for ; Fri, 29 Sep 2023 18:04:36 +0000 (UTC) Received: from mail-pf1-x42a.google.com (mail-pf1-x42a.google.com [IPv6:2607:f8b0:4864:20::42a]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 2800DCED for ; Fri, 29 Sep 2023 11:04:35 -0700 (PDT) Received: by mail-pf1-x42a.google.com with SMTP id d2e1a72fcca58-690f7bf73ddso11479932b3a.2 for ; Fri, 29 Sep 2023 11:04:35 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; t=1696010674; x=1696615474; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=vbdv0/nW296h6ChWMtIgFAyyvGlVNRpufvyfuyvShzQ=; b=IW5AVcAkiaAj4s7fJRndl3MMjtUWjDjxTQlKnjnaHjAjwt+vUsYxz9JgvlYoaK3M6f Ol9y9wATgMc/u+YmhVAdfTUrWxP1HZJ0oPNZltX2EtwlMLEg2h6mTN8CI/YTP0t0yyUe dD46nq7X5i+JeJMH2faLvf889/DSNBnZtgr6M= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1696010674; x=1696615474; 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:message-id:reply-to; bh=vbdv0/nW296h6ChWMtIgFAyyvGlVNRpufvyfuyvShzQ=; b=YvboUgi3z9VcRl+iM2JoXOHwA9gm+h1U+nTs2hSQrEAJYs/Yp+Gfn4kAZR87zT0Xl3 OCfVK4VcWoSi2n/cUfChHdotOq5te2djqgDrEInzZpljq6ELafKaY2C0S3cJ45fikWca Jc1zj1OylTlAl815u5AJz7CgDrOD/+bUpK+0I7/E5ylAqh9DbOmCa/gVPM0TbMrRj3A0 JQ6gqrEUhbTGYMpnjDBeK0+ExGAmNcLFZQFLi0Y5fuZNPtd0jZpNv+tr54zxTiRb7OMY Oq4sF6zUcgoc9zhu3YgTEyV1nATgvjJb0EbYpQhaBaeKkG28ZKIERKAkXHvxkvMMub8c pmBQ== X-Gm-Message-State: AOJu0YyVq2hdJ9xG0U+qE2hQotiYbiFhKv/nSTO82lcoGDBr8VNvRxOZ QPIsyf43wNkPvdwDeHLAxJgTKw== X-Google-Smtp-Source: AGHT+IGy74o21jxyozHb5het0OocJE/38B/v79t1GwFxGzhnGj1DFYoNecBZWdRxEDYr4YXo4bZcjg== X-Received: by 2002:a05:6a20:6a23:b0:159:cf93:9b50 with SMTP id p35-20020a056a206a2300b00159cf939b50mr5241500pzk.46.1696010674631; Fri, 29 Sep 2023 11:04:34 -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 s2-20020a639242000000b0057825bd3448sm14577546pgn.51.2023.09.29.11.04.32 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 29 Sep 2023 11:04:32 -0700 (PDT) From: Kees Cook To: Jason Gunthorpe Cc: Kees Cook , Leon Romanovsky , =?utf-8?q?H=C3=A5kon_Bugge?= , Avihai Horon , Anand Khoje , Mark Bloch , linux-rdma@vger.kernel.org, Dennis Dalessandro , Christian Benvenuti , Nelson Escobar , Bernard Metzler , Bart Van Assche , "Gustavo A. R. Silva" , Nathan Chancellor , Nick Desaulniers , Tom Rix , Patrisious Haddad , Chuck Lever , Tom Talpey , wangjianli , linux-kernel@vger.kernel.org, linux-hardening@vger.kernel.org, llvm@lists.linux.dev Subject: [PATCH 2/7] RDMA/core: Annotate struct ib_pkey_cache with __counted_by Date: Fri, 29 Sep 2023 11:04:25 -0700 Message-Id: <20230929180431.3005464-2-keescook@chromium.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230929180305.work.590-kees@kernel.org> References: <20230929180305.work.590-kees@kernel.org> 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=1301; i=keescook@chromium.org; h=from:subject; bh=8qTIqTpqch+dyj739sghT5yZ5j+JjtWjxI1TdxYuFP8=; b=owEBbQKS/ZANAwAKAYly9N/cbcAmAcsmYgBlFxGtnlN5Fv7CxLg4EAHhoDTEkyA2uohAKbEuJ GpqdYgLKF6JAjMEAAEKAB0WIQSlw/aPIp3WD3I+bhOJcvTf3G3AJgUCZRcRrQAKCRCJcvTf3G3A JsP9EAC0DgrjiUKiy5qvIIyWJvdycEGXOMygwychR18Ef+pgg5+zSsDS92qrEYrYtFz76UNEjXu 17JwoDffv1yCBXGPdCC533oDBSgVr+TlqtP2MZGJpAFB2jDA29+Dh4hzGUwpMr/6MnWn0bTR+Vf CpNLYII3OIAvmJ7tmaGaoHilX1gORNFvw6QXwwBjPqGo4OVFa8kBf1B0rtFRYcv3mAjY6/NICJX SHYsUU4Ics30sqUiukI13sfP3+hBHWUsXPfxlfPua60GazyoI3Knfr67AHenGUpiY+IW4aLoKdS o2kCcBAN7fkiUfZ1gZ78iamlNXXX0OSwijoe8XxuBtjfZazk6bZ+fvQocUBNAtcWA1GpKYkmzuD WZM7ZiZAb+AikXlQapk0bMLGL+lDIHr8vZDe4wCguY0+c2vj7sF53jCbCxvyHROPFaIf6NOF8Sl WgTV/v+kMTa9AYlUC/XwuF6+IkQA9oAN3SwwYjVJ8fIpCpFEr2BsgBBh3Ga0GVx1N+voyDpWY3G F+h9MTIiqcG9+eMOkNDRxa/356g84qJQVkHabmIondLkPx4Fhxi4sl0Q/z0lMrXCKQWUEiD0CZ+ EyY/I2qS70/lsYtItOwfyhWLxUvHwRLNmkGx3T7/t7+KYvzbr3n9McTs1R8tzNlYTWrKwQ52ImD 13o2YAgRaZPedeg== 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 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 ib_pkey_cache. [1] https://github.com/kees/kernel-tools/blob/trunk/coccinelle/examples/counted_by.cocci Cc: Jason Gunthorpe Cc: Leon Romanovsky Cc: "HÃ¥kon Bugge" Cc: Avihai Horon Cc: Anand Khoje Cc: Mark Bloch Cc: linux-rdma@vger.kernel.org Signed-off-by: Kees Cook --- drivers/infiniband/core/cache.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/drivers/infiniband/core/cache.c b/drivers/infiniband/core/cache.c index 7acc0f936dad..c02a96d3572a 100644 --- a/drivers/infiniband/core/cache.c +++ b/drivers/infiniband/core/cache.c @@ -46,7 +46,7 @@ struct ib_pkey_cache { int table_len; - u16 table[]; + u16 table[] __counted_by(table_len); }; struct ib_update_work { From patchwork Fri Sep 29 18:04:26 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Kees Cook X-Patchwork-Id: 13404727 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 33A0866677 for ; Fri, 29 Sep 2023 18:04:35 +0000 (UTC) Received: from mail-pl1-x631.google.com (mail-pl1-x631.google.com [IPv6:2607:f8b0:4864:20::631]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id DBCDCCE8 for ; Fri, 29 Sep 2023 11:04:33 -0700 (PDT) Received: by mail-pl1-x631.google.com with SMTP id d9443c01a7336-1c752caeaa6so439445ad.1 for ; Fri, 29 Sep 2023 11:04:33 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; t=1696010673; x=1696615473; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=rjv7XjWCeDrMXMYTb/YTTJo8q29FnAz83pH22uwoIO0=; b=g1MY3owXfmVFxC4qubpH9QOenRmlMJxfCvYyfu535aURz8GzIhvHdPQi6Xnp+Q6cZP Dd/hyifEZpAuLeFZ/ZckowK9PM3Rej+d/uOGZNunWhN3cv0KyPO+Za15HExnXJnmcUjr ha8BpBHJmCpV4lWAKEaVTlAymyXWoz6eDqMy8= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1696010673; x=1696615473; 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:message-id:reply-to; bh=rjv7XjWCeDrMXMYTb/YTTJo8q29FnAz83pH22uwoIO0=; b=BymmrzFxDw8/DuvKn/IohhlDql09x5kgj07JogJsmWr1ipqX4TAZGoE0U56B8JbU4E tFfNY1hXa4NEknMsoXrF6R72Sezg0TH2a8D9zbIaaiou1SCVXF0f3FJPK82UNfcrbomX xKK5We100KdRqjiFpKncNYyvUjJuhy68OqySXNZ+sR45kJw4gzWqcZFlx5MF9bqw9BwJ UuwKC21YNp2dKnOU57oSRm2CXgbBbSviYvufmBj/E1pQNs4565/ZKUCaQezi5Qux4M/9 hXnAChyg4RHZO0HIEXsAKvyvadcWZdvi/6C89LA9EM0Geb3lCI/dxWmdw4Oz33EnC/08 5xpQ== X-Gm-Message-State: AOJu0YxvUsBQPAP1bYDVDgJ9xE+8C2apT0jBwIHlA0tKjjCO0MSWt4BC IGzms6z1+MvE4ars2SPl7P3yMw== X-Google-Smtp-Source: AGHT+IEqbxt2iHBD3gT66BfcF4+zqgw5KnT5DPsKrmGXzyU2z5+ZNSV0Qlc7B//NeDlD+AqaM/ce+g== X-Received: by 2002:a17:902:ea8d:b0:1bf:c59:c944 with SMTP id x13-20020a170902ea8d00b001bf0c59c944mr5046186plb.22.1696010673179; Fri, 29 Sep 2023 11:04:33 -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 c4-20020a170902c1c400b001bf8779e051sm9028480plc.289.2023.09.29.11.04.32 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 29 Sep 2023 11:04:32 -0700 (PDT) From: Kees Cook To: Jason Gunthorpe Cc: Kees Cook , Christian Benvenuti , Nelson Escobar , Leon Romanovsky , linux-rdma@vger.kernel.org, Dennis Dalessandro , =?utf-8?q?H?= =?utf-8?q?=C3=A5kon_Bugge?= , Avihai Horon , Anand Khoje , Mark Bloch , Bernard Metzler , Bart Van Assche , "Gustavo A. R. Silva" , Nathan Chancellor , Nick Desaulniers , Tom Rix , Patrisious Haddad , Chuck Lever , Tom Talpey , wangjianli , linux-kernel@vger.kernel.org, linux-hardening@vger.kernel.org, llvm@lists.linux.dev Subject: [PATCH 3/7] RDMA/usnic: Annotate struct usnic_uiom_chunk with __counted_by Date: Fri, 29 Sep 2023 11:04:26 -0700 Message-Id: <20230929180431.3005464-3-keescook@chromium.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230929180305.work.590-kees@kernel.org> References: <20230929180305.work.590-kees@kernel.org> 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=1357; i=keescook@chromium.org; h=from:subject; bh=PVnuNq2a519xhVqwBmJpJ/aQUk1MR7UGuxLJSDkBI0M=; b=owEBbQKS/ZANAwAKAYly9N/cbcAmAcsmYgBlFxGtOkrR3aIgB88Z3xMRuRsPr/pj6t6EgVcik IpjUEiLnaKJAjMEAAEKAB0WIQSlw/aPIp3WD3I+bhOJcvTf3G3AJgUCZRcRrQAKCRCJcvTf3G3A Jo5iEACbnoHJcJyHp7utyWJvDOGHq949IF3S9dIbHV2PkP642qwnvv3riAf4djGdAw0JTTF2VJA MU/bRdHd3fBmNGyf3uqPtz2avADi5Qrp02tF1gz8VOt4pgD6QJHfIkVFJBj04+VrIZuK2Xpusn5 zoL6iEHRd/jUJFJlUNUlFEtm10nT5JkbkjpWKBD3g05vhRufE87afPIg60R61DQSA81h73t1O99 N8qlbD2jKbuzlEb2IAko+pN/GNVvCV2qahIAEtBS60B3xkkwvKNCrmFJiAxvlqF0iYznuXBuAhb ojrSJRP1p5DwjajmTvpHROPJKipMvIs9Thufh+djwWCvfpWWwetI7bc+evEM/rUF2jiXl7oGOLO zMSAIhCHessLhv0mt6qrDF7OJxSwdxs4/1lRwzQt/aYCgyrWDAdKjUzS8JxgZAqdwdsBTPwD2+v gbbWHmXQQZOltmtew5a6N+hwlDI/zQCj9ZJCvAHH1HIp0cvAYznJNvjkZzsoP+HJKs/UgzFuONt Np1NLzVO+JKDE04zcP4DQftGbxQ5BSm4lRlfttV8DqLSbna6Nixk+T1lcO4SZdykPmMskePTb5G uzmYpw1ScL3aEag5bNei8eBBCxG2sdmOx/PPAsdh8knLy4FlBAed695G3bGcv1GWSKMtnzfP1IF OFHIWV/FkLGL9YQ== 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 autolearn=ham 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 usnic_uiom_chunk. [1] https://github.com/kees/kernel-tools/blob/trunk/coccinelle/examples/counted_by.cocci Cc: Christian Benvenuti Cc: Nelson Escobar Cc: Jason Gunthorpe Cc: Leon Romanovsky Cc: linux-rdma@vger.kernel.org Signed-off-by: Kees Cook --- drivers/infiniband/hw/usnic/usnic_uiom.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/drivers/infiniband/hw/usnic/usnic_uiom.h b/drivers/infiniband/hw/usnic/usnic_uiom.h index 5a9acf941510..70d51d919d12 100644 --- a/drivers/infiniband/hw/usnic/usnic_uiom.h +++ b/drivers/infiniband/hw/usnic/usnic_uiom.h @@ -77,7 +77,7 @@ struct usnic_uiom_reg { struct usnic_uiom_chunk { struct list_head list; int nents; - struct scatterlist page_list[]; + struct scatterlist page_list[] __counted_by(nents); }; struct usnic_uiom_pd *usnic_uiom_alloc_pd(struct device *dev); From patchwork Fri Sep 29 18:04:27 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Kees Cook X-Patchwork-Id: 13404728 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 9B7F366663 for ; Fri, 29 Sep 2023 18:04:35 +0000 (UTC) Received: from mail-pf1-x42e.google.com (mail-pf1-x42e.google.com [IPv6:2607:f8b0:4864:20::42e]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 85ADDCE9 for ; Fri, 29 Sep 2023 11:04:34 -0700 (PDT) Received: by mail-pf1-x42e.google.com with SMTP id d2e1a72fcca58-690d9cda925so11673164b3a.3 for ; Fri, 29 Sep 2023 11:04:34 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; t=1696010674; x=1696615474; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=Sk2AIw2pt4hARdmfDz+pJbA65TQJu27TBdJQsR6YVso=; b=jbPktZ7pq3R5vQZkDKPITPCb0VWyGBYip46/QkIIxuajAsGyY4AZapz/t64rlgA9VO 6ihBTOllHCUaBUnDzfPJY1Wc8Eh6FbTJBslHt+zm0OrmdLm7eYPgsVidUtJtQuWF80bY PXawxC1fIDXDuUyNyAf/SfByF0NaKGuoGce+k= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1696010674; x=1696615474; 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:message-id:reply-to; bh=Sk2AIw2pt4hARdmfDz+pJbA65TQJu27TBdJQsR6YVso=; b=i9J9KE1H7WPTyGGvoLycZWEJycNJhTi9LKk1RTBP3lW2+f301JCZfwBwNCRDRXHLf+ cCkE2EshzGd2wNF4DNmWnYtxTeMVm1LSaPWJgLCi3WjZCZBiypDgcTr7WxtwHIxWsLsC thj/T7VH+nuR5oOwq+HFwlaM26SSgOxMFBgJmMcit+W/1YhXcEBApTVg6FZzjR3MCr8r eW+Cjs7BtlkOPEmvrP+yTfXTIFtL2VxUeK+aRl87qaqFRPNi5a8T7y6IvyTHVPJXZ2eZ eogsgvMS0DQoRK5EnwLT2uhwQVLT40vr0WY0MsuwQ3wmwey++/YShA9/DHjRPu9YuyU+ LwEg== X-Gm-Message-State: AOJu0Ywj/VcTvkgqnijC5zx3c/hfE6qqDRXz/Y3H9tPxnhXwdSnDtYoL JYaP2gFvFuiOLZSjo8H3bQfKvQ== X-Google-Smtp-Source: AGHT+IF52bKA/fkpG//8ng6o8+pByKARjWnzC4wFfcw/5B8Vi+BbgRJtb1w+TaWQ21ul0/hLPN0rXA== X-Received: by 2002:a05:6a00:1589:b0:693:4a43:1c7e with SMTP id u9-20020a056a00158900b006934a431c7emr5259056pfk.29.1696010673936; Fri, 29 Sep 2023 11:04:33 -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 s196-20020a6377cd000000b005789cbd2cacsm14718511pgc.20.2023.09.29.11.04.32 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 29 Sep 2023 11:04:32 -0700 (PDT) From: Kees Cook To: Jason Gunthorpe Cc: Kees Cook , Bernard Metzler , Leon Romanovsky , linux-rdma@vger.kernel.org, Dennis Dalessandro , =?utf-8?q?H?= =?utf-8?q?=C3=A5kon_Bugge?= , Avihai Horon , Anand Khoje , Mark Bloch , Christian Benvenuti , Nelson Escobar , Bart Van Assche , "Gustavo A. R. Silva" , Nathan Chancellor , Nick Desaulniers , Tom Rix , Patrisious Haddad , Chuck Lever , Tom Talpey , wangjianli , linux-kernel@vger.kernel.org, linux-hardening@vger.kernel.org, llvm@lists.linux.dev Subject: [PATCH 4/7] RDMA/siw: Annotate struct siw_pbl with __counted_by Date: Fri, 29 Sep 2023 11:04:27 -0700 Message-Id: <20230929180431.3005464-4-keescook@chromium.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230929180305.work.590-kees@kernel.org> References: <20230929180305.work.590-kees@kernel.org> 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=1176; i=keescook@chromium.org; h=from:subject; bh=8TFS+r6rwfEZHwFvOLksc3v8PZIOUrROKrYJlwQtijk=; b=owEBbQKS/ZANAwAKAYly9N/cbcAmAcsmYgBlFxGu773COsQ9qpU+8QNaYwhfW/LhcAaSb6gVg FWhje/hPFOJAjMEAAEKAB0WIQSlw/aPIp3WD3I+bhOJcvTf3G3AJgUCZRcRrgAKCRCJcvTf3G3A JoKwD/98GIMcp1DtQPrGoXgjgRKK4LtdowIapfABsa34RZm6dmv5HgM9bCb+SlhpMQ0LbdOmLDi QpNAWZz/IIMNujaAkdZNQoGNvE4WXfkmDvsyLByCirVuOambsysBvy7ZxEKX78YWT4Fgr/BIkt7 YQTLgXeEGLUz3pXd5DV/UOkYEaiOocsWiEjNJgQezzsRjk080yecZE8Uuofk3lBnLmHXVVlezDE 1F14N790wyRyXR+1F2EnBtHDBb3SzKoTUm5ZzPfi8o3eZmhR+/Qgk8yqXcJuVQ1lGxbIkGZE4HQ k4FQSCvpLBWvQKmC9iS9CWs5w4uPGbAUgX2De3P5wtipK4ahcpgWianBFJ2lfoVUTX4QVWBGpqr NZ9XSnhMyXywgMW4Vn8fI8po9Bnrty6JCNekXPpquacZOz0arMq/32cCWmetdys0Qi6EODNhALD /ABu3vViC1ZK5pViwpHiK1JtFlum9I/mp4gUrbpn9VU8skPh3dyUH9VWlq2rAV4BK83IlPVw02P 4pmkldLl63CWi/d7mvhfPtgmc1Etz33xHDSk31DEEBvqh4AQ3kmn1G6+2RtoBsV9QPV3qkjhH9H V3wP50SqbitWnN107wLHRygD085ais4LIDR4xdFyC4K6FmyxVY1CJKjlPyiLCPKJVA8KV1TGqqz pSuxYgQ0Gj82THw== 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_NONE, SPF_HELO_NONE,SPF_PASS autolearn=ham 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 siw_pbl. [1] https://github.com/kees/kernel-tools/blob/trunk/coccinelle/examples/counted_by.cocci Cc: Bernard Metzler Cc: Jason Gunthorpe Cc: Leon Romanovsky Cc: linux-rdma@vger.kernel.org Signed-off-by: Kees Cook --- drivers/infiniband/sw/siw/siw.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/drivers/infiniband/sw/siw/siw.h b/drivers/infiniband/sw/siw/siw.h index 1c78c1ca7d7a..cec5cccd2e75 100644 --- a/drivers/infiniband/sw/siw/siw.h +++ b/drivers/infiniband/sw/siw/siw.h @@ -137,7 +137,7 @@ struct siw_pble { struct siw_pbl { unsigned int num_buf; unsigned int max_buf; - struct siw_pble pbe[]; + struct siw_pble pbe[] __counted_by(max_buf); }; /* From patchwork Fri Sep 29 18:04:28 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Kees Cook X-Patchwork-Id: 13404730 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 2C52C6667E for ; Fri, 29 Sep 2023 18:04:38 +0000 (UTC) Received: from mail-pf1-x42e.google.com (mail-pf1-x42e.google.com [IPv6:2607:f8b0:4864:20::42e]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id A9C02CEF for ; Fri, 29 Sep 2023 11:04:35 -0700 (PDT) Received: by mail-pf1-x42e.google.com with SMTP id d2e1a72fcca58-690fe10b6a4so12758781b3a.3 for ; Fri, 29 Sep 2023 11:04:35 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; t=1696010675; x=1696615475; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=bQWutlCB4bHLvq/a2I2458S6BRe72rUYx34sxiTinJw=; b=eApxWndlLNXcLGDI7qdNZZXvHgci1hddOTLOhu2ZPumPdirclzCbXrx/UzYxxuK0eD p2z0XYHuVas4oelrIZMhfDyeUFbXATdjTD9Ogue+SYg/G1AyWb11seS0QDRvbzupQZX1 zELlgXbgnnC0U5dllKFjhO7JuB9eI0OPI1Qpc= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1696010675; x=1696615475; 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:message-id:reply-to; bh=bQWutlCB4bHLvq/a2I2458S6BRe72rUYx34sxiTinJw=; b=KvsYpBnwFqxgzuV+FXe2g8Lg/6cFzQyqrapx3Q9GMcie8sEdjn1URLTw0LsfiaBXOX wbNc4TAq+TpW++J0b59mfXHODatJ+G21xYBdrYuy/g/ywumpIc431UrvxnJQdeUBxuJD gTJBC8BK4jF0JSMTXEimutdp9nQspvvFze2EqfaI0XMw9JGhmP728XXXdJx5ElKXQgVf 3JO23IgnajhKn8450lAJIfZeyuKlkjs5LXFz6TeZXZ5+72ChZ6U0TOWCRhhVRnXevFiu Lo0z/h/SENsZRPLMbg59hipTjQO0VmjBzYo4Pmpd9jCP2pDQ9iO5ScsrkczHU5+XvmHy INTA== X-Gm-Message-State: AOJu0YxJCRG0aHEy7o7HXNqnGFDDR+qW6eX2WabpQDHz2bY/mfqHKtQL qb6cfMvxeK7wj1nxtZy3vZVjL/bHt7kKwUuEjxU= X-Google-Smtp-Source: AGHT+IEavR5/wZq99qXsCEoXnSicEQATy8IvkCqg4JpNcBj3w9YLOUXqOXUW6iCClkidWBr7Q/KDng== X-Received: by 2002:a05:6a20:8e12:b0:161:28dd:c09d with SMTP id y18-20020a056a208e1200b0016128ddc09dmr5598820pzj.15.1696010675201; Fri, 29 Sep 2023 11:04:35 -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 c16-20020aa78e10000000b0068c61848785sm15228538pfr.208.2023.09.29.11.04.33 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 29 Sep 2023 11:04:34 -0700 (PDT) From: Kees Cook To: Jason Gunthorpe Cc: Kees Cook , Bart Van Assche , Leon Romanovsky , linux-rdma@vger.kernel.org, Dennis Dalessandro , =?utf-8?q?H?= =?utf-8?q?=C3=A5kon_Bugge?= , Avihai Horon , Anand Khoje , Mark Bloch , Christian Benvenuti , Nelson Escobar , Bernard Metzler , "Gustavo A. R. Silva" , Nathan Chancellor , Nick Desaulniers , Tom Rix , Patrisious Haddad , Chuck Lever , Tom Talpey , wangjianli , linux-kernel@vger.kernel.org, linux-hardening@vger.kernel.org, llvm@lists.linux.dev Subject: [PATCH 5/7] IB/srp: Annotate struct srp_fr_pool with __counted_by Date: Fri, 29 Sep 2023 11:04:28 -0700 Message-Id: <20230929180431.3005464-5-keescook@chromium.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230929180305.work.590-kees@kernel.org> References: <20230929180305.work.590-kees@kernel.org> 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=1220; i=keescook@chromium.org; h=from:subject; bh=f7YIXZ1Qz/PkvmeFE/JHjleuWcRLUOMOaQc0DRTvzX0=; b=owEBbQKS/ZANAwAKAYly9N/cbcAmAcsmYgBlFxGu9/IB5ROJ/iD1IoxO8XdZ0HuofI5lXB9aL 4bAV2SnX/yJAjMEAAEKAB0WIQSlw/aPIp3WD3I+bhOJcvTf3G3AJgUCZRcRrgAKCRCJcvTf3G3A JoxWD/0ZjY+XrVB7gRnT53mKtziWVn+VsfedclKqQTgWGlk9obHRRC5h+bABdwKSf2M/x0wCQFH mVEbvAQDpHgR+Dff6jNIv+1QcHHO5DEpLiYDrFKCu1/+V+cLcW3uIl03j4j6xaJezo6eOsw7zsV qHzukxETpc8mlb33IZR04S4xPeQwpdejzndnDFde/ViDV8t7iidPzE4mWvdYon1+2aPCgI7eBj7 bDR2OEb2yciSxCKdenFa3rByvJjqQPe6KHlxylQVLI29zQl5R+r/Sj4Z8gKsqvOBTRFFL8iQkdf TGtYluwh/Ok9tXHWmhOgxLEGkSuf3GZXYI+1zMXmpbcd1EOuD6WN0sZs5M2+FWQS/ZkTn7pzuR3 Qqc3lS05bvXdyE+BCBVWVGygCQvfDP5e2QbVTnBFC5yP9AzrhU9jErH+oUyQu+gLRyZGKGudIo6 ZhmGK2XtDlfZi0gaOKPQBdxkczkTLGAZ5NOKJQ+3k3WAfZ/7Xgg7NYu7Jdp2BudK2CvN5uRrond /rlpeDTxx2K62/qlY2LI7OmJWB7Px2i5bSW5g77AzDdVNvqzIRyg4mgIKNvjaYTCoeRWVCGCb9X cfBJppmtpmPQhtwSnT8SALM8cw5PP2q7Rci6HUL9dTUXHDHKCIQW1muP+rHVMhXbvap6GSo1vMt 1AjoxAt0tusmfDA== 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_NONE, SPF_HELO_NONE,SPF_PASS 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 srp_fr_pool. [1] https://github.com/kees/kernel-tools/blob/trunk/coccinelle/examples/counted_by.cocci Cc: Bart Van Assche Cc: Jason Gunthorpe Cc: Leon Romanovsky Cc: linux-rdma@vger.kernel.org Signed-off-by: Kees Cook --- drivers/infiniband/ulp/srp/ib_srp.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/drivers/infiniband/ulp/srp/ib_srp.h b/drivers/infiniband/ulp/srp/ib_srp.h index 5d94db453df3..349576ff3845 100644 --- a/drivers/infiniband/ulp/srp/ib_srp.h +++ b/drivers/infiniband/ulp/srp/ib_srp.h @@ -306,7 +306,7 @@ struct srp_fr_pool { int max_page_list_len; spinlock_t lock; struct list_head free_list; - struct srp_fr_desc desc[]; + struct srp_fr_desc desc[] __counted_by(size); }; /** From patchwork Fri Sep 29 18:04:29 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Kees Cook X-Patchwork-Id: 13404731 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 9BB4B66663 for ; Fri, 29 Sep 2023 18:04:39 +0000 (UTC) Received: from mail-pf1-x42c.google.com (mail-pf1-x42c.google.com [IPv6:2607:f8b0:4864:20::42c]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 4302ECE9 for ; Fri, 29 Sep 2023 11:04:38 -0700 (PDT) Received: by mail-pf1-x42c.google.com with SMTP id d2e1a72fcca58-68c576d35feso12742089b3a.2 for ; Fri, 29 Sep 2023 11:04:38 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; t=1696010678; x=1696615478; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=G6dSgw/viVX1hF9GiVxg31bNXS5ti9jq2oLyQe/SrHc=; b=RAgSKSo4zQtWvBRw+50KgyVoBcddzo6Bxc8UevyFsYod4tHXTeT445CN4cpaSQ+9sM jOM9XQdA5XkKkBphfL4rm7rHzTioY2SgCLph1lWbeQrTteSM5PHvldaQAcEbXfyrYhri GWh0z9UUYr0L30xAZqh1/AdgcZ6F2Bh/NGmfU= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1696010678; x=1696615478; 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:message-id:reply-to; bh=G6dSgw/viVX1hF9GiVxg31bNXS5ti9jq2oLyQe/SrHc=; b=beyllyfs3w6kModoWGIKocYXEJpLX3CLLzZFNb5yHSlTi41+tW9/nn/YSHMA5SJN1g e80k/FyK0abtT0jTCK1t9Pmy5y+aSWYIosELzTBAtPo3CdbgUA8x8NEuy540MFQh3f5x SvaX1OVH9ePGyefPry2tYou6lHCNQRvbgn6ib42GpnR7Rv2Mpvl68dV1q8u56Kjc/szh PMTYSZESZr0G/wOIngAp9SeiRk3Afhv5UArmpw5tJMviUTIKXXFptxJIhqvz2y4W9KLf eMWrLBf//Kc66fK69T4QH+PhwrwtV/6uOY9bNbd5Xr5GRSS1PN6G9bjhJATQF5t3ocHX DKtQ== X-Gm-Message-State: AOJu0Yx+M7S5OOUNf5cf4eFbHFnQYWaNxkfZTtRSp4zhog8n9dEKGU7W xm703fBIm4jtU+vkOls5pDJ5jg== X-Google-Smtp-Source: AGHT+IE20otJ4RSneK87xPc+d9C9PCpIJ8g8LIGpqUyyhEz7f1L4BvfQ+bBNZm9ZhHkhttGWrv8vlQ== X-Received: by 2002:a05:6a20:549a:b0:14b:8023:33cb with SMTP id i26-20020a056a20549a00b0014b802333cbmr5761090pzk.11.1696010677683; Fri, 29 Sep 2023 11:04:37 -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 d18-20020aa78692000000b00690fb385ea9sm15316956pfo.47.2023.09.29.11.04.33 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 29 Sep 2023 11:04:34 -0700 (PDT) From: Kees Cook To: Jason Gunthorpe Cc: Kees Cook , Leon Romanovsky , linux-rdma@vger.kernel.org, Dennis Dalessandro , =?utf-8?q?H?= =?utf-8?q?=C3=A5kon_Bugge?= , Avihai Horon , Anand Khoje , Mark Bloch , Christian Benvenuti , Nelson Escobar , Bernard Metzler , Bart Van Assche , "Gustavo A. R. Silva" , Nathan Chancellor , Nick Desaulniers , Tom Rix , Patrisious Haddad , Chuck Lever , Tom Talpey , wangjianli , linux-kernel@vger.kernel.org, linux-hardening@vger.kernel.org, llvm@lists.linux.dev Subject: [PATCH 6/7] IB/mthca: Annotate struct mthca_icm_table with __counted_by Date: Fri, 29 Sep 2023 11:04:29 -0700 Message-Id: <20230929180431.3005464-6-keescook@chromium.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230929180305.work.590-kees@kernel.org> References: <20230929180305.work.590-kees@kernel.org> 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=1251; i=keescook@chromium.org; h=from:subject; bh=KnzErPDnGsoACiNJdVcsN/BX+MW+GH0rlXVaL/E2pIg=; b=owEBbQKS/ZANAwAKAYly9N/cbcAmAcsmYgBlFxGudlYNxBZwxaAdfN5vXxcaqFfVqmj7dgAXy KxCK6A4NgOJAjMEAAEKAB0WIQSlw/aPIp3WD3I+bhOJcvTf3G3AJgUCZRcRrgAKCRCJcvTf3G3A Jq2fD/wOjmJ/GTNcAOHMWxIkPbGB6y5ReI6NRHk1MISbwnUZHxFPl3cbxT4uBJ/tSFMWvYBIaZd CHF5KasHHeSkYcZgmCwOmDN1uWLSey/4j8PDvrpfKYLZ6trEcfgkT79P1w8JSgXNi/O8mBA7P3b 7skNWfNzTtAOq3D9GCfGkKoa7SOuU+Zs+g2so6pg3TInolHbr36AlerV403JYrGfIAQROPlltvf 6HbSLVByZEh4E3MlUrYKQhxmGo350//eAiVrjrpgj8zp6ASrjFLr5MSG5EZ1K1SOUhb1z1M710M KCxJhPfcH804qdRPlcPegKvBN3JwbexhAiuJUv81lEL8aIud2X5tFi8lJZfHbAtREW3ZALi+1XC qsi6RyjGH/EaSX65t5UCRLFRRnLK1Fu1L0ad+ny7oCoS+zPSFELwsvSsgeO1Ay3V9M3VM/t6xi9 nPKdHSmc8EFPNM4xPJRu584TvMccInO4cFOq4JyjHaWZ9NX3EalXvkRQA6TUx4zo+AD2xJeYXb2 lQWAJnl0LZCQ42huxY9W+Jj0X6J9hT32sjj6XnQGW65WPWCcGRBrEUoubExTgbb5eFqErnOwKcA R/RCcDiXvP+N2bi7MXqQ+DBgsFWZ4P1MaCRmEolelIiFmKGq3vm8m7RdjYnD9qmODro0EDfFQCR iOTFHqonxskMATQ== 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 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 mthca_icm_table. [1] https://github.com/kees/kernel-tools/blob/trunk/coccinelle/examples/counted_by.cocci Cc: Jason Gunthorpe Cc: Leon Romanovsky Cc: linux-rdma@vger.kernel.org Signed-off-by: Kees Cook --- drivers/infiniband/hw/mthca/mthca_memfree.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/drivers/infiniband/hw/mthca/mthca_memfree.h b/drivers/infiniband/hw/mthca/mthca_memfree.h index f9a2e65e2ff5..61d5bbba293a 100644 --- a/drivers/infiniband/hw/mthca/mthca_memfree.h +++ b/drivers/infiniband/hw/mthca/mthca_memfree.h @@ -68,7 +68,7 @@ struct mthca_icm_table { int lowmem; int coherent; struct mutex mutex; - struct mthca_icm *icm[]; + struct mthca_icm *icm[] __counted_by(num_icm); }; struct mthca_icm_iter { From patchwork Fri Sep 29 18:04:30 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Kees Cook X-Patchwork-Id: 13404733 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 1A48B66678 for ; Fri, 29 Sep 2023 18:04:41 +0000 (UTC) Received: from mail-oi1-x233.google.com (mail-oi1-x233.google.com [IPv6:2607:f8b0:4864:20::233]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 73026CF5 for ; Fri, 29 Sep 2023 11:04:37 -0700 (PDT) Received: by mail-oi1-x233.google.com with SMTP id 5614622812f47-3aec067556dso2975896b6e.2 for ; Fri, 29 Sep 2023 11:04:37 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; t=1696010676; x=1696615476; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=7loYy4I0V9WbaRkyDORfpVOvXKBDkMaDU3HmTq6aaCo=; b=EZhw26pMBtemT4/sbnEq4t0BUiSO5I0ZuBVJVi5aM9lw9Lp0W2ALRUOyFGjYBl5Vyu y7MMLy7tzTqQFIXSJov2bN+Tljn+5Sp9+RfB4PBIbdf0Ed9vAuC+cKFxO19l/T1/uYr6 Ul0lfTGAq/j6aGv5LYk46VAqe3XgjMNSLT5Ik= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1696010676; x=1696615476; 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:message-id:reply-to; bh=7loYy4I0V9WbaRkyDORfpVOvXKBDkMaDU3HmTq6aaCo=; b=ReU15hercAIJJP4c4EAt4KbH2PsJbwwLk72h4Q/u72JTq4D49iHAsNf2EL0KlkZY2p P1/RYls92ajn/JfI6qkV8mR2nqaJdt8zpXpdB13te4V/KSh6zBN3CIwdHiMXHrSN6v1l sCTMzwPXwco6LE5IAK/nTt+mm86fHoW3fJoaqGYraI7FMwBB+8D88htkyAuZxkjwmNMX vtl7I1T+M4e+Dhh5o68sKt0gTj7gftRRrBQ2154vwE1IFa96Qai6JSxbEVK9MraOwFov LoB92+8zaCk61UtBGs1P1W/bzu8q5yW3EVjnUHrDXgjKov/F9k1AeyKDC+tRjxxC/Hfc 8Vjw== X-Gm-Message-State: AOJu0Yyi0RqT4Kt7czfbdeF2DWCFMaCIV1XL9E1NY6gETBewTn9Iad9p dwKQPYj9CJj4R4UbjdunRvKisA== X-Google-Smtp-Source: AGHT+IFp3QSM5ekw8j1tI8tUgHc/WNycC/Pf0i2hoCRkySu8Sy7s2YFcq9MZ1lU4xH4xRaStQRdeLg== X-Received: by 2002:a05:6808:18a6:b0:3af:79e3:68d7 with SMTP id bi38-20020a05680818a600b003af79e368d7mr1401295oib.59.1696010676667; Fri, 29 Sep 2023 11:04:36 -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 k67-20020a633d46000000b00577bc070c6bsm13985771pga.68.2023.09.29.11.04.33 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 29 Sep 2023 11:04:34 -0700 (PDT) From: Kees Cook To: Jason Gunthorpe Cc: Kees Cook , Dennis Dalessandro , Leon Romanovsky , linux-rdma@vger.kernel.org, =?utf-8?q?H?= =?utf-8?q?=C3=A5kon_Bugge?= , Avihai Horon , Anand Khoje , Mark Bloch , Christian Benvenuti , Nelson Escobar , Bernard Metzler , Bart Van Assche , "Gustavo A. R. Silva" , Nathan Chancellor , Nick Desaulniers , Tom Rix , Patrisious Haddad , Chuck Lever , Tom Talpey , wangjianli , linux-kernel@vger.kernel.org, linux-hardening@vger.kernel.org, llvm@lists.linux.dev Subject: [PATCH 7/7] IB/hfi1: Annotate struct tid_rb_node with __counted_by Date: Fri, 29 Sep 2023 11:04:30 -0700 Message-Id: <20230929180431.3005464-7-keescook@chromium.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230929180305.work.590-kees@kernel.org> References: <20230929180305.work.590-kees@kernel.org> 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=1296; i=keescook@chromium.org; h=from:subject; bh=5+hginCoO40gXVEhDd2TzT5efPqXVR+knLSWVnfU8ow=; b=owEBbQKS/ZANAwAKAYly9N/cbcAmAcsmYgBlFxGuDgcPnSEEDSvhCdq3C2vJgb3qdw/LhpW2x tim/TyUa5iJAjMEAAEKAB0WIQSlw/aPIp3WD3I+bhOJcvTf3G3AJgUCZRcRrgAKCRCJcvTf3G3A Jg7CD/9IO6sfIhcdiDAPuO2CKDNVoq4p3SdHoXmM2XBp1YwBoHT7gEwQR4RT3mIzlG0I74nKm73 H1EX/Yd0bkul503BOk+eormeqtpn+hLrIuRDPEbk8HlrZYFYWvVNa8D2yREVfyds3CgOwE6UyXc aSMx//AL8Z/qpDmeqBlbNL3O7OK6ht9K/mK42LORZkAY2hzmq0WV4kXhrC4PlektH2akmXS5DGj wlAO77pgLRGhcEKrZmaPjMsGzh7bZQ8houJ4w45ShKUjDBRQZM88fq4pbM8ImffIF2X0VUTXa8Y 09T4SWVZEMw8sEudVJrENBXRQNVGyCNnhLA7UYvmfVX4tu7PhZOUpUpEQPy3OiRIFRedVNs1DnW NJ4fSKoAyJ70B8mH6FuSf70jLl4QpvpoFrsVzCYqLrYyMd6KLqEp8LdtoN/BR5NTtZVusEHHeuK 6klHggoNRwySEq5Vx0C2HRXgbtytwRw+9wx+62nvwql58uSwlMWbkRW2pipsMK0VFMf4HrM+DZL plMPJQ5nI6HHBKsq9E9A4u4Q+EXFpmiMlhxgVfHlUWxmDUhKAevh2CY7xXj8qOBqh9CA+6KWM8o EfcCi4Zo4YfCzhn6C6lTC6EHSFNVRp42NhaUyL4yADcXaSwX2WpfvsaYkzZQGYOy7O8AMn4zzEM gPF6o2m6oJt8Efg== 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 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 tid_rb_node. [1] https://github.com/kees/kernel-tools/blob/trunk/coccinelle/examples/counted_by.cocci Cc: Dennis Dalessandro Cc: Jason Gunthorpe Cc: Leon Romanovsky Cc: linux-rdma@vger.kernel.org Signed-off-by: Kees Cook --- drivers/infiniband/hw/hfi1/user_exp_rcv.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/drivers/infiniband/hw/hfi1/user_exp_rcv.h b/drivers/infiniband/hw/hfi1/user_exp_rcv.h index b85de9070aee..055726f7c139 100644 --- a/drivers/infiniband/hw/hfi1/user_exp_rcv.h +++ b/drivers/infiniband/hw/hfi1/user_exp_rcv.h @@ -36,7 +36,7 @@ struct tid_rb_node { dma_addr_t dma_addr; bool freed; unsigned int npages; - struct page *pages[]; + struct page *pages[] __counted_by(npages); }; static inline int num_user_pages(unsigned long addr,