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: 13404719 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 4F3B7E728CF for ; Fri, 29 Sep 2023 18:05:22 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233741AbjI2SFU (ORCPT ); Fri, 29 Sep 2023 14:05:20 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:58292 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233874AbjI2SFG (ORCPT ); Fri, 29 Sep 2023 14:05:06 -0400 Received: from mail-pg1-x52c.google.com (mail-pg1-x52c.google.com [IPv6:2607:f8b0:4864:20::52c]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id CDE7ACF4 for ; Fri, 29 Sep 2023 11:04:36 -0700 (PDT) Received: by mail-pg1-x52c.google.com with SMTP id 41be03b00d2f7-5859b06509cso975460a12.2 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=IZTf9cfgTv+ZEXmrSLmAjcnmkNM/3FMNtNzh3w2Gh+dWelL/LVwR1u1fNO5xqJwtaX ahM1fvhQAGNAlvnO6MUJ+CBka16GcNSUFYDE7jgpUeo6yvtjel/x+iAp/xAMAOYKOhHg 8C7ZTIKGPaMyaalRRoBADXgNznIM72zzurbpmMkgmSG+UCSp8TrdkOAVfvskd0896DZf zXRS6Cpc5cBlZ99JWU3XEcQqTFdwIQKDC0eY36XHOck0IwNrCQbiOranbQN3RuIhQAaQ 647Oj4THc7WAfeTX+DsuiMs3dxN0V+3CkSqTeHgsQI8Eo3sBzbDHehcv14I2LDYKesw8 isiw== X-Gm-Message-State: AOJu0Ywxj6sXE7DbDxRz1+GlfBibSGqpqAP6RaUHpCS3oXV7TZ9O9V0n YUHxBbGr6X5baiMk0DXlaXU7Ow== 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> 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 Precedence: bulk List-ID: X-Mailing-List: linux-rdma@vger.kernel.org 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: 13404717 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id C0F67E728D9 for ; Fri, 29 Sep 2023 18:05:19 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233702AbjI2SFT (ORCPT ); Fri, 29 Sep 2023 14:05:19 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:34202 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233876AbjI2SFG (ORCPT ); Fri, 29 Sep 2023 14:05:06 -0400 Received: from mail-pf1-x435.google.com (mail-pf1-x435.google.com [IPv6:2607:f8b0:4864:20::435]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 291FECEE for ; Fri, 29 Sep 2023 11:04:35 -0700 (PDT) Received: by mail-pf1-x435.google.com with SMTP id d2e1a72fcca58-690f7bf73ddso11479927b3a.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=R9kQtSAY/OGISOTIXFdcrPYBV3O6ke94lAwM+dtRU2RXrrL0VgWdeDuP6YREfUnyWa jwKck1nTikX9gPwzYp8EkCrTLpmLJhH6VPJy20tKmEkaz2tcJfCYRTMNyvuWX5THvM13 8sPt/5S2ukV/uRZnZvBHNNC1vR2yjoLedmKQP6IpXalvIgEwGRL0tQt/24D22jyZ9SDr tH3o0vB9uHHZAyymtPKmu1O8wwZ7eE440ijcXIpONwCw++iblYrqA1FRwG4ztEC3pKdZ ckzkZS5kqqjGHVBnhj/CEpTvczl+Dvtwcz20i48uE7HG0jDG8czbnVssog0/AO/qYXKD gECw== X-Gm-Message-State: AOJu0YwR+Hb9WXuR5y8t8tJ7oHg4v5/ezO6JJSc8Y3WQS71hgo5NerNy 0guVCKvi8/4iLj5lNFofIqOAXA== 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> 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 Precedence: bulk List-ID: X-Mailing-List: linux-rdma@vger.kernel.org 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: 13404713 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 49E06E728CF for ; Fri, 29 Sep 2023 18:05:17 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233144AbjI2SFQ (ORCPT ); Fri, 29 Sep 2023 14:05:16 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:38098 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233847AbjI2SFE (ORCPT ); Fri, 29 Sep 2023 14:05:04 -0400 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 DA689CC8 for ; Fri, 29 Sep 2023 11:04:33 -0700 (PDT) Received: by mail-pl1-x631.google.com with SMTP id d9443c01a7336-1c3d6d88231so109441235ad.0 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=wKeQI6nD43iZ2vc0hmeIJZsy+ClYmOTeJlSlmrjwEKpOsdc+7puVFvChEzT7zwwyA/ dnd6nO9ypYpmkFgC1RzlsDTkawkDP+Ac7Fay+ctrr5vu7ow6kuD5a1/xd2oZTMlCRcaz abyAtderSobGD0VcpoftaC66Qy0pvg8BNxrTUcDBR3pC/SyEhsr4uETVWoAmfGdf+eaJ QL3gBPXl7zY1tHo34LNt5kV+ZyZnKjUy1NlVTO1qCrixPY703jAI/rUpGAQ+jsU8AcT6 jRdVR2BNsJIegd3yXlOx08kHN8Hum44JGYjwmWAp/kH9Lux9VX8KuugreP8YaWAk8xwo pkrQ== X-Gm-Message-State: AOJu0Yx2G9C5reLAWjA1Vf+WRYJBkHbofJBvJj4jeCNQENmOJi5SEHb9 28D+Li1kp5opX4wFubrkWHkKpw== 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> 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 Precedence: bulk List-ID: X-Mailing-List: linux-rdma@vger.kernel.org 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: 13404715 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 1CABBE728D6 for ; Fri, 29 Sep 2023 18:05:18 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233538AbjI2SFR (ORCPT ); Fri, 29 Sep 2023 14:05:17 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:34158 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233845AbjI2SFG (ORCPT ); Fri, 29 Sep 2023 14:05:06 -0400 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 88986CEA for ; Fri, 29 Sep 2023 11:04:34 -0700 (PDT) Received: by mail-pf1-x42c.google.com with SMTP id d2e1a72fcca58-692a885f129so10367253b3a.0 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=FdnvwmITNooRE06DVCazuuwQKxUP/h/7WTOrEOpkY5Hhh3YAkYsyI2UGUouSBi97LJ sSEwwMCvtPnksl6or5VS9yDHxvWFHJ8ckHZFeIhevnlT0QEJ6j/sJty81emVQAR5XSNe nCnYBLuK/DRxjx0cuMWoRAnjx8b1yyw1pG1emrQD4Oe6r8e533IuMX68x3ZtHauGRrBX 3hz+VmPE1reWJckDNKFEDCOFs1qVfHgU38q/CE8jvbNptPvTLC3C6ebkDGkSvs9zyyu9 szUyZb+byZLAnnHeDsZQIwlaDCLzr/aOx+l74QSfjQWltSM5LfPwisY7MkRSKZORRUaw fe1Q== X-Gm-Message-State: AOJu0YzkYQgzvy6Xvq7bs0FmCdEe8r85nvIXOPIeQsVfkiT/F2Ko/ktL QBYqxQE8cIE3nKem3x9z088QXKaVkimIm2+kGko= 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> 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 Precedence: bulk List-ID: X-Mailing-List: linux-rdma@vger.kernel.org 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: 13404716 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 6FE3DE728D5 for ; Fri, 29 Sep 2023 18:05:19 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229508AbjI2SFT (ORCPT ); Fri, 29 Sep 2023 14:05:19 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:33914 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233868AbjI2SFG (ORCPT ); Fri, 29 Sep 2023 14:05:06 -0400 Received: from mail-pf1-x42f.google.com (mail-pf1-x42f.google.com [IPv6:2607:f8b0:4864:20::42f]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id AAC02CF0 for ; Fri, 29 Sep 2023 11:04:35 -0700 (PDT) Received: by mail-pf1-x42f.google.com with SMTP id d2e1a72fcca58-690fe10b6a4so12758782b3a.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=LwMA2pn/r3c/YMDsB7iMmlCKTufnZnc/8TCzGL5GJQpvTEv+xKbjm9lRdroKgugKtY Yyj9kPzPFhURcGSSOxywmJNr300i9YmupR/qjiKSKAoUS7jSh+y1dnHVICdE2AutOIcP Bj/Y2zgP/K3JgFNJaL6P8ZykEGopHpAZ3dyp/CC8yStjmIWXZeCDIetfkk7Ek3fPyP0+ HfFpu46IHhKcqBX0i43VwTqwtMwi2Hn9ycOZeTHfWG9gx1huXNQCX7bAebVXdGAms8KZ 3oaa9c5kP0ICxUjOzEGrLHyn3pSolVV2aLb4e3LwOAmW938YHqqagKTg1xMSwTiJKVWf 5W2Q== X-Gm-Message-State: AOJu0YxcgE02KwfzsoRAb/B94FW8Lb2JyMD36f4pmfe28QkN5ZVAaMWw k/VAngpAZFNPU+CZoH5If0DpaA== 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> 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 Precedence: bulk List-ID: X-Mailing-List: linux-rdma@vger.kernel.org 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: 13404714 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id AE4F8E728D7 for ; Fri, 29 Sep 2023 18:05:18 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232923AbjI2SFS (ORCPT ); Fri, 29 Sep 2023 14:05:18 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:33946 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233832AbjI2SFG (ORCPT ); Fri, 29 Sep 2023 14:05:06 -0400 Received: from mail-pf1-x42d.google.com (mail-pf1-x42d.google.com [IPv6:2607:f8b0:4864:20::42d]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 45B31CF7 for ; Fri, 29 Sep 2023 11:04:38 -0700 (PDT) Received: by mail-pf1-x42d.google.com with SMTP id d2e1a72fcca58-68c576d35feso12742093b3a.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=pq9V6tjfFvBfAyothmtbhlJPTOVBazheP9n5YenfklZRV/XaaYWGkNmUcoBKfND+ui KTQDIrNuZL68GDRQ/6PKFPnb3/hcmnocYJqTADGTWiI9QUtJmvWJUmd40+/GjZosM313 j6EYByfAG2yMX1gKJShZYdV7awdXWbeJPO8aumUFPAuEcE4yT9FEix6Y8p4W1Dz1TxmB cfAczJvaGDWA+zx0WmkbKDy29/n/N2qHVdNvbKEfxKLOCyPHKIFsYd1CcIj/2ST5Zh0O 8eRyWzmRFiF2Ed4bb4VD0YUT9WHhas6PPLAXhi4F/HBdEsM+YbPp/o/fBT3lAlqs9+5+ PZoA== X-Gm-Message-State: AOJu0YwkiqFi8pO/droSsKvLd2vw/BK0Uf5dMiF1MwdicBJEs7h/t3mA YDQKkqGsJUgZqjzwhmJWcu/AeA== 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> 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 Precedence: bulk List-ID: X-Mailing-List: linux-rdma@vger.kernel.org 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: 13404718 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 11D65E728DA for ; Fri, 29 Sep 2023 18:05:21 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233709AbjI2SFU (ORCPT ); Fri, 29 Sep 2023 14:05:20 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:34204 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233807AbjI2SFG (ORCPT ); Fri, 29 Sep 2023 14:05:06 -0400 Received: from mail-oi1-x229.google.com (mail-oi1-x229.google.com [IPv6:2607:f8b0:4864:20::229]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 6385BCE5 for ; Fri, 29 Sep 2023 11:04:37 -0700 (PDT) Received: by mail-oi1-x229.google.com with SMTP id 5614622812f47-3ae0135c4deso8287851b6e.3 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=EGLG9xJxtpqyY9HO/gtX7+aKsj9t8ZK+MJXlsD1Z1qBlUnIafwMhRw8wO/jFKYAxlp eBBNCRAxoOXqqvqwAx0C6ut1suQC7yNHgdcBogXR9MSh4Ld75aN+V3MAVC7pCtooXurr gZvjhFo4eZUSXHs271bGeMMLe7vaT9v1ZNf5wbeYsUTP1rX3UglgPjnuQb0IfaIK6DPH zEbJ8OVzoaMyRnsrSC490qBLIbzsKatWmQxPsPHVLRUBWfuOY76DQG/AuM5brV3V0qiG xgurq2o8wRH/o747NwncTe1GfIMW79nHMziKJb4l8WwXnonFDjbqBu1lM52wqoPnMJrm OcbA== X-Gm-Message-State: AOJu0YywT7y/4ffRgmfbqKfIhpoqOS9tIKayoV2QUuYJ97SrKvBO5voR lTYX0JQpux9P6mA6ksXNFaQX9A== 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> 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 Precedence: bulk List-ID: X-Mailing-List: linux-rdma@vger.kernel.org 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,