RDMA/core: Use flexible array for mad data
authorKees Cook <keescook@chromium.org>
Wed, 16 Jun 2021 20:26:15 +0000 (13:26 -0700)
committerJason Gunthorpe <jgg@nvidia.com>
Tue, 22 Jun 2021 17:05:34 +0000 (14:05 -0300)
In preparation for FORTIFY_SOURCE performing compile-time and run-time
field bounds checking for memcpy(), memmove(), and memset(), avoid
intentionally reading across neighboring array fields.

Without a flexible array, this looks like an attempt to perform a memcpy()
read beyond the end of the packet->mad.data array:

drivers/infiniband/core/user_mad.c:
memcpy(packet->msg->mad, packet->mad.data, IB_MGMT_MAD_HDR);

Switch from [0] to [] to use the appropriately handled type for trailing
bytes.

Link: https://lore.kernel.org/r/20210616202615.1247242-1-keescook@chromium.org
Signed-off-by: Kees Cook <keescook@chromium.org>
Signed-off-by: Jason Gunthorpe <jgg@nvidia.com>
include/uapi/rdma/ib_user_mad.h

index 90c0cf228020dca8ad241a5617e1fb8ad7764954..10b5f6a4c677355bcefb295879e84ff92e9b15e3 100644 (file)
@@ -143,7 +143,7 @@ struct ib_user_mad_hdr {
  */
 struct ib_user_mad {
        struct ib_user_mad_hdr hdr;
-       __aligned_u64   data[0];
+       __aligned_u64   data[];
 };
 
 /*