linux_dsm_epyc7002/drivers/infiniband/sw/rdmavt
Kees Cook acafe7e302 treewide: Use struct_size() for kmalloc()-family
One of the more common cases of allocation size calculations is finding
the size of a structure that has a zero-sized array at the end, along
with memory for some number of elements for that array. For example:

struct foo {
    int stuff;
    void *entry[];
};

instance = kmalloc(sizeof(struct foo) + sizeof(void *) * count, GFP_KERNEL);

Instead of leaving these open-coded and prone to type mistakes, we can
now use the new struct_size() helper:

instance = kmalloc(struct_size(instance, entry, count), GFP_KERNEL);

This patch makes the changes for kmalloc()-family (and kvmalloc()-family)
uses. It was done via automatic conversion with manual review for the
"CHECKME" non-standard cases noted below, using the following Coccinelle
script:

// pkey_cache = kmalloc(sizeof *pkey_cache + tprops->pkey_tbl_len *
//                      sizeof *pkey_cache->table, GFP_KERNEL);
@@
identifier alloc =~ "kmalloc|kzalloc|kvmalloc|kvzalloc";
expression GFP;
identifier VAR, ELEMENT;
expression COUNT;
@@

- alloc(sizeof(*VAR) + COUNT * sizeof(*VAR->ELEMENT), GFP)
+ alloc(struct_size(VAR, ELEMENT, COUNT), GFP)

// mr = kzalloc(sizeof(*mr) + m * sizeof(mr->map[0]), GFP_KERNEL);
@@
identifier alloc =~ "kmalloc|kzalloc|kvmalloc|kvzalloc";
expression GFP;
identifier VAR, ELEMENT;
expression COUNT;
@@

- alloc(sizeof(*VAR) + COUNT * sizeof(VAR->ELEMENT[0]), GFP)
+ alloc(struct_size(VAR, ELEMENT, COUNT), GFP)

// Same pattern, but can't trivially locate the trailing element name,
// or variable name.
@@
identifier alloc =~ "kmalloc|kzalloc|kvmalloc|kvzalloc";
expression GFP;
expression SOMETHING, COUNT, ELEMENT;
@@

- alloc(sizeof(SOMETHING) + COUNT * sizeof(ELEMENT), GFP)
+ alloc(CHECKME_struct_size(&SOMETHING, ELEMENT, COUNT), GFP)

Signed-off-by: Kees Cook <keescook@chromium.org>
2018-06-06 11:15:43 -07:00
..
ah.c IB/rdmavt, hfi1, qib: Modify check_ah() to account for extended LIDs 2017-08-22 14:22:36 -04:00
ah.h IB/core: Rename struct ib_ah_attr to rdma_ah_attr 2017-05-01 14:32:43 -04:00
cq.c RDMA: Mark imm_data as be32 in the verbs uapi header 2018-01-15 15:33:21 -07:00
cq.h IB/rdmavt: Fix copyright date 2016-03-10 20:37:27 -05:00
Kconfig IB: Move PCI dependency from root KConfig to HW's KConfigs 2017-09-27 08:54:19 -04:00
mad.c IB/core: Rename ib_destroy_ah to rdma_destroy_ah 2017-05-01 14:32:43 -04:00
mad.h IB/rdmavt: Clean up distinction between port number and index 2016-03-10 20:37:31 -05:00
Makefile This is a tree wide change and has been kept separate for that reason. 2017-02-25 13:45:43 -08:00
mcast.c infiniband: fix sw/rdmavt/* kernel-doc notation 2018-01-10 22:00:35 -07:00
mcast.h IB/rdmavt: Fix copyright date 2016-03-10 20:37:27 -05:00
mmap.c infiniband: Fix alignment of mmap cookies to support VIPT caching 2017-03-24 16:50:51 -04:00
mmap.h IB/rdmavt: Remove unnecessary exported functions 2016-03-10 20:38:10 -05:00
mr.c treewide: Use struct_size() for kmalloc()-family 2018-06-06 11:15:43 -07:00
mr.h IB/rdmavt: Add support for ib_map_mr_sg 2016-08-02 16:00:58 -04:00
pd.c IB/hfi1, rdmavt: Update copy_sge to use boolean arguments 2017-02-19 09:18:41 -05:00
pd.h IB/rdmavt: Fix copyright date 2016-03-10 20:37:27 -05:00
qp.c First merge window pull request for 4.16 2018-01-31 12:05:10 -08:00
qp.h IB/rdmavt: Fix copyright date 2016-03-10 20:37:27 -05:00
rc.c IB/hfi1, qib, rdmavt: Move AETH defines to rdma/ib_hdrs.h 2017-02-19 09:18:44 -05:00
srq.c IB/rdmavt: Use correct numa node for SRQ allocation 2018-01-05 13:34:55 -05:00
srq.h IB/rdmavt: Add srq functionality to rdmavt 2016-03-10 20:37:30 -05:00
trace_cq.h IB/rdmavt: Add tracing for cq entry and poll 2017-04-05 14:45:09 -04:00
trace_mr.h IB/rdmavt: Compress adjacent SGEs in rvt_lkey_ok() 2017-06-27 16:56:33 -04:00
trace_qp.h IB/rdmavt: Add trace for RNRNAK timer 2018-01-05 13:34:55 -05:00
trace_rc.h IB/rdmavt, IB/hfi1: Fix timer migration regressions 2017-04-05 14:45:09 -04:00
trace_rvt.h IB/rdmavt: Fix trace hierarchy 2016-12-11 15:25:13 -05:00
trace_tx.h IB/rdmavt: Compress adjacent SGEs in rvt_lkey_ok() 2017-06-27 16:56:33 -04:00
trace.c IB/rdmavt: Fix copyright date 2016-03-10 20:37:27 -05:00
trace.h IB/{rdmavt, hfi1, qib}: Remove get_card_name() downcall 2018-01-05 13:34:55 -05:00
vt.c IB/uverbs: Extend uverbs_ioctl header with driver_id 2018-03-19 14:45:17 -06:00
vt.h IB: remove duplicate header files 2018-03-13 16:46:03 -04:00