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 {