mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Kees Cook <keescook@chromium.org>
To: Jason Gunthorpe <jgg@ziepe.ca>
Cc: "Kees Cook" <keescook@chromium.org>,
	"Leon Romanovsky" <leon@kernel.org>,
	"Håkon Bugge" <haakon.bugge@oracle.com>,
	"Avihai Horon" <avihaih@nvidia.com>,
	"Anand Khoje" <anand.a.khoje@oracle.com>,
	"Mark Bloch" <mbloch@nvidia.com>,
	linux-rdma@vger.kernel.org,
	"Dennis Dalessandro" <dennis.dalessandro@cornelisnetworks.com>,
	"Christian Benvenuti" <benve@cisco.com>,
	"Nelson Escobar" <neescoba@cisco.com>,
	"Bernard Metzler" <bmt@zurich.ibm.com>,
	"Bart Van Assche" <bvanassche@acm.org>,
	"Gustavo A. R. Silva" <gustavoars@kernel.org>,
	"Nathan Chancellor" <nathan@kernel.org>,
	"Nick Desaulniers" <ndesaulniers@google.com>,
	"Tom Rix" <trix@redhat.com>,
	"Patrisious Haddad" <phaddad@nvidia.com>,
	"Chuck Lever" <chuck.lever@oracle.com>,
	"Tom Talpey" <tom@talpey.com>, wangjianli <wangjianli@cdjrlc.com>,
	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	[thread overview]
Message-ID: <20230929180431.3005464-2-keescook@chromium.org> (raw)
In-Reply-To: <20230929180305.work.590-kees@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 <jgg@ziepe.ca>
Cc: Leon Romanovsky <leon@kernel.org>
Cc: "Håkon Bugge" <haakon.bugge@oracle.com>
Cc: Avihai Horon <avihaih@nvidia.com>
Cc: Anand Khoje <anand.a.khoje@oracle.com>
Cc: Mark Bloch <mbloch@nvidia.com>
Cc: linux-rdma@vger.kernel.org
Signed-off-by: Kees Cook <keescook@chromium.org>
---
 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 {
-- 
2.34.1


  parent reply	other threads:[~2023-09-29 18:05 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-09-29 18:04 [PATCH 0/7] RDMA: Annotate structs " Kees Cook
2023-09-29 18:04 ` [PATCH 1/7] RDMA: Annotate struct rdma_hw_stats " Kees Cook
2023-09-29 18:04 ` Kees Cook [this message]
2023-09-29 18:04 ` [PATCH 3/7] RDMA/usnic: Annotate struct usnic_uiom_chunk " Kees Cook
2023-09-29 18:04 ` [PATCH 4/7] RDMA/siw: Annotate struct siw_pbl " Kees Cook
2023-09-29 18:04 ` [PATCH 5/7] IB/srp: Annotate struct srp_fr_pool " Kees Cook
2023-09-29 18:04 ` [PATCH 6/7] IB/mthca: Annotate struct mthca_icm_table " Kees Cook
2023-09-29 18:04 ` [PATCH 7/7] IB/hfi1: Annotate struct tid_rb_node " Kees Cook
2023-10-02 11:45 ` [PATCH 0/7] RDMA: Annotate structs " Leon Romanovsky

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20230929180431.3005464-2-keescook@chromium.org \
    --to=keescook@chromium.org \
    --cc=anand.a.khoje@oracle.com \
    --cc=avihaih@nvidia.com \
    --cc=benve@cisco.com \
    --cc=bmt@zurich.ibm.com \
    --cc=bvanassche@acm.org \
    --cc=chuck.lever@oracle.com \
    --cc=dennis.dalessandro@cornelisnetworks.com \
    --cc=gustavoars@kernel.org \
    --cc=haakon.bugge@oracle.com \
    --cc=jgg@ziepe.ca \
    --cc=leon@kernel.org \
    --cc=linux-hardening@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-rdma@vger.kernel.org \
    --cc=llvm@lists.linux.dev \
    --cc=mbloch@nvidia.com \
    --cc=nathan@kernel.org \
    --cc=ndesaulniers@google.com \
    --cc=neescoba@cisco.com \
    --cc=phaddad@nvidia.com \
    --cc=tom@talpey.com \
    --cc=trix@redhat.com \
    --cc=wangjianli@cdjrlc.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®