* [PATCH 00/26] use array_size
@ 2023-06-23 21:14 Julia Lawall
2023-06-23 21:14 ` [PATCH 02/26] octeon_ep: " Julia Lawall
` (5 more replies)
0 siblings, 6 replies; 20+ messages in thread
From: Julia Lawall @ 2023-06-23 21:14 UTC (permalink / raw)
To: linux-staging
Cc: keescook, kernel-janitors, Tianshu Qiu, Bingbu Cao, linux-sgx,
H. Peter Anvin, Dave Hansen, kasan-dev, Andrey Konovalov,
Dmitry Vyukov, iommu, linux-tegra, Robin Murphy, Krishna Reddy,
linux-scsi, linux-rdma, dri-devel, linux-kernel, netdev,
Shailend Chand, Benjamin Gaignard, Liam Mark, Laura Abbott,
Brian Starkey, John Stultz, linux-media, linaro-mm-sig,
Xuan Zhuo, virtualization, mhi, linux-arm-msm, linux-btrfs,
intel-gvt-dev, intel-gfx, VMware Graphics Reviewers,
linux-hyperv
Use array_size to protect against multiplication overflows.
This follows up on the following patches by Kees Cook from 2018.
42bc47b35320 ("treewide: Use array_size() in vmalloc()")
fad953ce0b22 ("treewide: Use array_size() in vzalloc()")
The changes were done using the following Coccinelle semantic patch,
adapted from the one posted by Kees.
// Drop single-byte sizes and redundant parens.
@@
expression COUNT;
typedef u8;
typedef __u8;
type t = {u8,__u8,char,unsigned char};
identifier alloc = {vmalloc,vzalloc};
@@
alloc(
- (sizeof(t)) * (COUNT)
+ COUNT
, ...)
// 3-factor product with 2 sizeof(variable), with redundant parens removed.
@@
expression COUNT;
size_t e1, e2, e3;
identifier alloc = {vmalloc,vzalloc};
@@
(
alloc(
- (e1) * (e2) * (e3)
+ array3_size(e1, e2, e3)
,...)
|
alloc(
- (e1) * (e2) * (COUNT)
+ array3_size(COUNT, e1, e2)
,...)
)
// 3-factor product with 1 sizeof(type) or sizeof(expression), with
// redundant parens removed.
@@
expression STRIDE, COUNT;
size_t e;
identifier alloc = {vmalloc,vzalloc};
@@
alloc(
- (e) * (COUNT) * (STRIDE)
+ array3_size(COUNT, STRIDE, e)
,...)
// Any remaining multi-factor products, first at least 3-factor products
// when they're not all constants...
@@
expression E1, E2, E3;
constant C1, C2, C3;
identifier alloc = {vmalloc,vzalloc};
@@
(
alloc(C1 * C2 * C3,...)
|
alloc(
- (E1) * (E2) * (E3)
+ array3_size(E1, E2, E3)
,...)
)
// 2-factor product with sizeof(type/expression) and identifier or constant.
@@
size_t e1,e2;
expression COUNT;
identifier alloc = {vmalloc,vzalloc};
@@
(
alloc(
- (e1) * (e2)
+ array_size(e1, e2)
,...)
|
alloc(
- (e1) * (COUNT)
+ array_size(COUNT, e1)
,...)
)
// And then all remaining 2 factors products when they're not all constants.
@@
expression E1, E2;
constant C1, C2;
identifier alloc = {vmalloc,vzalloc};
@@
(
alloc(C1 * C2,...)
|
alloc(
- (E1) * (E2)
+ array_size(E1, E2)
,...)
)
---
arch/x86/kernel/cpu/sgx/main.c | 3 ++-
drivers/accel/habanalabs/common/device.c | 3 ++-
drivers/accel/habanalabs/common/state_dump.c | 6 +++---
drivers/bus/mhi/host/init.c | 4 ++--
drivers/comedi/comedi_buf.c | 4 ++--
drivers/dma-buf/heaps/system_heap.c | 2 +-
drivers/gpu/drm/gud/gud_pipe.c | 2 +-
drivers/gpu/drm/i915/gvt/gtt.c | 6 ++++--
drivers/gpu/drm/vmwgfx/vmwgfx_devcaps.c | 2 +-
drivers/infiniband/hw/bnxt_re/qplib_res.c | 4 ++--
drivers/infiniband/hw/erdma/erdma_verbs.c | 4 ++--
drivers/infiniband/sw/siw/siw_qp.c | 4 ++--
drivers/infiniband/sw/siw/siw_verbs.c | 6 +++---
drivers/iommu/tegra-gart.c | 4 ++--
drivers/net/ethernet/amd/pds_core/core.c | 4 ++--
drivers/net/ethernet/freescale/enetc/enetc.c | 4 ++--
drivers/net/ethernet/google/gve/gve_tx.c | 2 +-
drivers/net/ethernet/marvell/octeon_ep/octep_rx.c | 2 +-
drivers/net/ethernet/microsoft/mana/hw_channel.c | 2 +-
drivers/net/ethernet/pensando/ionic/ionic_lif.c | 4 ++--
drivers/scsi/fnic/fnic_trace.c | 2 +-
drivers/scsi/qla2xxx/qla_init.c | 4 ++--
drivers/staging/media/ipu3/ipu3-mmu.c | 2 +-
drivers/vdpa/vdpa_user/iova_domain.c | 3 +--
drivers/virtio/virtio_mem.c | 6 +++---
fs/btrfs/zoned.c | 5 +++--
kernel/kcov.c | 2 +-
lib/test_vmalloc.c | 12 ++++++------
28 files changed, 56 insertions(+), 52 deletions(-)
^ permalink raw reply [flat|nested] 20+ messages in thread
* [PATCH 02/26] octeon_ep: use array_size
2023-06-23 21:14 [PATCH 00/26] use array_size Julia Lawall
@ 2023-06-23 21:14 ` Julia Lawall
2023-06-24 15:46 ` Simon Horman
2023-06-24 22:28 ` Jakub Kicinski
2023-06-23 21:14 ` [PATCH 04/26] gve: " Julia Lawall
` (4 subsequent siblings)
5 siblings, 2 replies; 20+ messages in thread
From: Julia Lawall @ 2023-06-23 21:14 UTC (permalink / raw)
To: Veerasenareddy Burru
Cc: keescook, kernel-janitors, Abhijit Ayarekar, David S. Miller,
Eric Dumazet, Jakub Kicinski, Paolo Abeni, netdev, linux-kernel
Use array_size to protect against multiplication overflows.
The changes were done using the following Coccinelle semantic patch:
// <smpl>
@@
expression E1, E2;
constant C1, C2;
identifier alloc = {vmalloc,vzalloc};
@@
(
alloc(C1 * C2,...)
|
alloc(
- (E1) * (E2)
+ array_size(E1, E2)
,...)
)
// </smpl>
Signed-off-by: Julia Lawall <Julia.Lawall@inria.fr>
---
drivers/net/ethernet/marvell/octeon_ep/octep_rx.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/drivers/net/ethernet/marvell/octeon_ep/octep_rx.c b/drivers/net/ethernet/marvell/octeon_ep/octep_rx.c
index 392d9b0da0d7..185b7e50ee77 100644
--- a/drivers/net/ethernet/marvell/octeon_ep/octep_rx.c
+++ b/drivers/net/ethernet/marvell/octeon_ep/octep_rx.c
@@ -158,7 +158,7 @@ static int octep_setup_oq(struct octep_device *oct, int q_no)
goto desc_dma_alloc_err;
}
- oq->buff_info = vzalloc(oq->max_count * OCTEP_OQ_RECVBUF_SIZE);
+ oq->buff_info = vzalloc(array_size(oq->max_count, OCTEP_OQ_RECVBUF_SIZE));
if (unlikely(!oq->buff_info)) {
dev_err(&oct->pdev->dev,
"Failed to allocate buffer info for OQ-%d\n", q_no);
^ permalink raw reply related [flat|nested] 20+ messages in thread
* Re: [PATCH 02/26] octeon_ep: use array_size
2023-06-23 21:14 ` [PATCH 02/26] octeon_ep: " Julia Lawall
@ 2023-06-24 15:46 ` Simon Horman
2023-06-24 22:28 ` Jakub Kicinski
1 sibling, 0 replies; 20+ messages in thread
From: Simon Horman @ 2023-06-24 15:46 UTC (permalink / raw)
To: Julia Lawall
Cc: Veerasenareddy Burru, keescook, kernel-janitors,
Abhijit Ayarekar, David S. Miller, Eric Dumazet, Jakub Kicinski,
Paolo Abeni, netdev, linux-kernel
On Fri, Jun 23, 2023 at 11:14:33PM +0200, Julia Lawall wrote:
> Use array_size to protect against multiplication overflows.
>
> The changes were done using the following Coccinelle semantic patch:
>
> // <smpl>
> @@
> expression E1, E2;
> constant C1, C2;
> identifier alloc = {vmalloc,vzalloc};
> @@
>
> (
> alloc(C1 * C2,...)
> |
> alloc(
> - (E1) * (E2)
> + array_size(E1, E2)
> ,...)
> )
> // </smpl>
>
> Signed-off-by: Julia Lawall <Julia.Lawall@inria.fr>
Reviewed-by: Simon Horman <simon.horman@corigine.com>
^ permalink raw reply [flat|nested] 20+ messages in thread
* Re: [PATCH 02/26] octeon_ep: use array_size
2023-06-23 21:14 ` [PATCH 02/26] octeon_ep: " Julia Lawall
2023-06-24 15:46 ` Simon Horman
@ 2023-06-24 22:28 ` Jakub Kicinski
2023-06-25 20:14 ` Christophe JAILLET
1 sibling, 1 reply; 20+ messages in thread
From: Jakub Kicinski @ 2023-06-24 22:28 UTC (permalink / raw)
To: Julia Lawall
Cc: Veerasenareddy Burru, keescook, kernel-janitors,
Abhijit Ayarekar, David S. Miller, Eric Dumazet, Paolo Abeni,
netdev, linux-kernel
On Fri, 23 Jun 2023 23:14:33 +0200 Julia Lawall wrote:
> - oq->buff_info = vzalloc(oq->max_count * OCTEP_OQ_RECVBUF_SIZE);
> + oq->buff_info = vzalloc(array_size(oq->max_count, OCTEP_OQ_RECVBUF_SIZE));
vcalloc seems to exist, is there a reason array_size() is preferred?
--
pw-bot: cr
^ permalink raw reply [flat|nested] 20+ messages in thread
* Re: [PATCH 02/26] octeon_ep: use array_size
2023-06-24 22:28 ` Jakub Kicinski
@ 2023-06-25 20:14 ` Christophe JAILLET
2023-06-25 20:25 ` Julia Lawall
0 siblings, 1 reply; 20+ messages in thread
From: Christophe JAILLET @ 2023-06-25 20:14 UTC (permalink / raw)
To: Jakub Kicinski, Julia Lawall
Cc: Veerasenareddy Burru, keescook, kernel-janitors,
Abhijit Ayarekar, David S. Miller, Eric Dumazet, Paolo Abeni,
netdev, linux-kernel, corbet
Le 25/06/2023 à 00:28, Jakub Kicinski a écrit :
> On Fri, 23 Jun 2023 23:14:33 +0200 Julia Lawall wrote:
>> - oq->buff_info = vzalloc(oq->max_count * OCTEP_OQ_RECVBUF_SIZE);
>> + oq->buff_info = vzalloc(array_size(oq->max_count, OCTEP_OQ_RECVBUF_SIZE));
>
> vcalloc seems to exist, is there a reason array_size() is preferred?
Hi,
just for your information, I've just sent [1].
CJ
[1]:
https://lore.kernel.org/all/3484e46180dd2cf05d993ff1a78b481bc2ad1f71.1687723931.git.christophe.jaillet@wanadoo.fr/
^ permalink raw reply [flat|nested] 20+ messages in thread
* Re: [PATCH 02/26] octeon_ep: use array_size
2023-06-25 20:14 ` Christophe JAILLET
@ 2023-06-25 20:25 ` Julia Lawall
2023-06-25 20:32 ` Christophe JAILLET
0 siblings, 1 reply; 20+ messages in thread
From: Julia Lawall @ 2023-06-25 20:25 UTC (permalink / raw)
To: Christophe JAILLET
Cc: Jakub Kicinski, Julia Lawall, Veerasenareddy Burru, keescook,
kernel-janitors, Abhijit Ayarekar, David S. Miller, Eric Dumazet,
Paolo Abeni, netdev, linux-kernel, corbet
[-- Attachment #1: Type: text/plain, Size: 928 bytes --]
On Sun, 25 Jun 2023, Christophe JAILLET wrote:
> Le 25/06/2023 à 00:28, Jakub Kicinski a écrit :
> > On Fri, 23 Jun 2023 23:14:33 +0200 Julia Lawall wrote:
> > > - oq->buff_info = vzalloc(oq->max_count * OCTEP_OQ_RECVBUF_SIZE);
> > > + oq->buff_info = vzalloc(array_size(oq->max_count,
> > > OCTEP_OQ_RECVBUF_SIZE));
> >
> > vcalloc seems to exist, is there a reason array_size() is preferred?
>
> Hi,
>
> just for your information, I've just sent [1].
>
> CJ
>
> [1]:
> https://lore.kernel.org/all/3484e46180dd2cf05d993ff1a78b481bc2ad1f71.1687723931.git.christophe.jaillet@wanadoo.fr/
For some reason, I have only received Christophe's mail, not Jakub's...
In any case, thanks for pointing out the existence of these functions. I
just redid what Kees did in 2018, when I guess these functions didn't
exist. I will look more carefully to see what functions are now available
and resend the whole thing.
Thanks!
julia
^ permalink raw reply [flat|nested] 20+ messages in thread
* Re: [PATCH 02/26] octeon_ep: use array_size
2023-06-25 20:25 ` Julia Lawall
@ 2023-06-25 20:32 ` Christophe JAILLET
2023-06-25 20:57 ` Julia Lawall
0 siblings, 1 reply; 20+ messages in thread
From: Christophe JAILLET @ 2023-06-25 20:32 UTC (permalink / raw)
To: Julia Lawall
Cc: Jakub Kicinski, Veerasenareddy Burru, keescook, kernel-janitors,
Abhijit Ayarekar, David S. Miller, Eric Dumazet, Paolo Abeni,
netdev, linux-kernel, corbet
Le 25/06/2023 à 22:25, Julia Lawall a écrit :
>
>
> On Sun, 25 Jun 2023, Christophe JAILLET wrote:
>
>> Le 25/06/2023 à 00:28, Jakub Kicinski a écrit :
>>> On Fri, 23 Jun 2023 23:14:33 +0200 Julia Lawall wrote:
>>>> - oq->buff_info = vzalloc(oq->max_count * OCTEP_OQ_RECVBUF_SIZE);
>>>> + oq->buff_info = vzalloc(array_size(oq->max_count,
>>>> OCTEP_OQ_RECVBUF_SIZE));
>>>
>>> vcalloc seems to exist, is there a reason array_size() is preferred?
>>
>> Hi,
>>
>> just for your information, I've just sent [1].
>>
>> CJ
>>
>> [1]:
>> https://lore.kernel.org/all/3484e46180dd2cf05d993ff1a78b481bc2ad1f71.1687723931.git.christophe.jaillet@wanadoo.fr/
>
> For some reason, I have only received Christophe's mail, not Jakub's...
>
> In any case, thanks for pointing out the existence of these functions. I
> just redid what Kees did in 2018, when I guess these functions didn't
> exist. I will look more carefully to see what functions are now available
> and resend the whole thing.
Hi,
should you want to go 1 step further and simplify some code:
git grep v[mz]alloc.*array_size\( | wc -l
174
CJ
>
> Thanks!
>
> julia
^ permalink raw reply [flat|nested] 20+ messages in thread
* Re: [PATCH 02/26] octeon_ep: use array_size
2023-06-25 20:32 ` Christophe JAILLET
@ 2023-06-25 20:57 ` Julia Lawall
0 siblings, 0 replies; 20+ messages in thread
From: Julia Lawall @ 2023-06-25 20:57 UTC (permalink / raw)
To: Christophe JAILLET
Cc: Jakub Kicinski, Veerasenareddy Burru, keescook, kernel-janitors,
Abhijit Ayarekar, David S. Miller, Eric Dumazet, Paolo Abeni,
netdev, linux-kernel, corbet
[-- Attachment #1: Type: text/plain, Size: 1335 bytes --]
On Sun, 25 Jun 2023, Christophe JAILLET wrote:
> Le 25/06/2023 à 22:25, Julia Lawall a écrit :
> >
> >
> > On Sun, 25 Jun 2023, Christophe JAILLET wrote:
> >
> > > Le 25/06/2023 à 00:28, Jakub Kicinski a écrit :
> > > > On Fri, 23 Jun 2023 23:14:33 +0200 Julia Lawall wrote:
> > > > > - oq->buff_info = vzalloc(oq->max_count *
> > > > > OCTEP_OQ_RECVBUF_SIZE);
> > > > > + oq->buff_info = vzalloc(array_size(oq->max_count,
> > > > > OCTEP_OQ_RECVBUF_SIZE));
> > > >
> > > > vcalloc seems to exist, is there a reason array_size() is preferred?
> > >
> > > Hi,
> > >
> > > just for your information, I've just sent [1].
> > >
> > > CJ
> > >
> > > [1]:
> > > https://lore.kernel.org/all/3484e46180dd2cf05d993ff1a78b481bc2ad1f71.1687723931.git.christophe.jaillet@wanadoo.fr/
> >
> > For some reason, I have only received Christophe's mail, not Jakub's...
> >
> > In any case, thanks for pointing out the existence of these functions. I
> > just redid what Kees did in 2018, when I guess these functions didn't
> > exist. I will look more carefully to see what functions are now available
> > and resend the whole thing.
>
> Hi,
>
> should you want to go 1 step further and simplify some code:
>
> git grep v[mz]alloc.*array_size\( | wc -l
> 174
Yes, thanks for the suggestion.
julia
>
> CJ
>
> >
> > Thanks!
> >
> > julia
>
>
^ permalink raw reply [flat|nested] 20+ messages in thread
* [PATCH 04/26] gve: use array_size
2023-06-23 21:14 [PATCH 00/26] use array_size Julia Lawall
2023-06-23 21:14 ` [PATCH 02/26] octeon_ep: " Julia Lawall
@ 2023-06-23 21:14 ` Julia Lawall
2023-06-24 15:47 ` Simon Horman
2023-06-23 21:14 ` [PATCH 09/26] pds_core: " Julia Lawall
` (3 subsequent siblings)
5 siblings, 1 reply; 20+ messages in thread
From: Julia Lawall @ 2023-06-23 21:14 UTC (permalink / raw)
To: Jeroen de Borst
Cc: keescook, kernel-janitors, Praveen Kaligineedi, Shailend Chand,
David S. Miller, Eric Dumazet, Jakub Kicinski, Paolo Abeni,
netdev, linux-kernel
Use array_size to protect against multiplication overflows.
The changes were done using the following Coccinelle semantic patch:
// <smpl>
@@
size_t e1,e2;
expression COUNT;
identifier alloc = {vmalloc,vzalloc,kvmalloc,kvzalloc};
@@
(
alloc(
- (e1) * (e2)
+ array_size(e1, e2)
,...)
|
alloc(
- (e1) * (COUNT)
+ array_size(COUNT, e1)
,...)
)
// </smpl>
Signed-off-by: Julia Lawall <Julia.Lawall@inria.fr>
---
drivers/net/ethernet/google/gve/gve_tx.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/drivers/net/ethernet/google/gve/gve_tx.c b/drivers/net/ethernet/google/gve/gve_tx.c
index 813da572abca..d77ebbb24936 100644
--- a/drivers/net/ethernet/google/gve/gve_tx.c
+++ b/drivers/net/ethernet/google/gve/gve_tx.c
@@ -248,7 +248,7 @@ static int gve_tx_alloc_ring(struct gve_priv *priv, int idx)
tx->mask = slots - 1;
/* alloc metadata */
- tx->info = vzalloc(sizeof(*tx->info) * slots);
+ tx->info = vzalloc(array_size(slots, sizeof(*tx->info)));
if (!tx->info)
return -ENOMEM;
^ permalink raw reply related [flat|nested] 20+ messages in thread
* Re: [PATCH 04/26] gve: use array_size
2023-06-23 21:14 ` [PATCH 04/26] gve: " Julia Lawall
@ 2023-06-24 15:47 ` Simon Horman
0 siblings, 0 replies; 20+ messages in thread
From: Simon Horman @ 2023-06-24 15:47 UTC (permalink / raw)
To: Julia Lawall
Cc: Jeroen de Borst, keescook, kernel-janitors, Praveen Kaligineedi,
Shailend Chand, David S. Miller, Eric Dumazet, Jakub Kicinski,
Paolo Abeni, netdev, linux-kernel
On Fri, Jun 23, 2023 at 11:14:35PM +0200, Julia Lawall wrote:
> Use array_size to protect against multiplication overflows.
>
> The changes were done using the following Coccinelle semantic patch:
>
> // <smpl>
> @@
> size_t e1,e2;
> expression COUNT;
> identifier alloc = {vmalloc,vzalloc,kvmalloc,kvzalloc};
> @@
>
> (
> alloc(
> - (e1) * (e2)
> + array_size(e1, e2)
> ,...)
> |
> alloc(
> - (e1) * (COUNT)
> + array_size(COUNT, e1)
> ,...)
> )
> // </smpl>
>
> Signed-off-by: Julia Lawall <Julia.Lawall@inria.fr>
Reviewed-by: Simon Horman <simon.horman@corigine.com>
^ permalink raw reply [flat|nested] 20+ messages in thread
* [PATCH 09/26] pds_core: use array_size
2023-06-23 21:14 [PATCH 00/26] use array_size Julia Lawall
2023-06-23 21:14 ` [PATCH 02/26] octeon_ep: " Julia Lawall
2023-06-23 21:14 ` [PATCH 04/26] gve: " Julia Lawall
@ 2023-06-23 21:14 ` Julia Lawall
2023-06-24 15:47 ` Simon Horman
2023-06-26 16:02 ` Shannon Nelson
2023-06-23 21:14 ` [PATCH 11/26] ionic: " Julia Lawall
` (2 subsequent siblings)
5 siblings, 2 replies; 20+ messages in thread
From: Julia Lawall @ 2023-06-23 21:14 UTC (permalink / raw)
To: Shannon Nelson
Cc: keescook, kernel-janitors, Brett Creeley, David S. Miller,
Eric Dumazet, Jakub Kicinski, Paolo Abeni, netdev, linux-kernel
Use array_size to protect against multiplication overflows.
The changes were done using the following Coccinelle semantic patch:
// <smpl>
@@
expression E1, E2;
constant C1, C2;
identifier alloc = {vmalloc,vzalloc};
@@
(
alloc(C1 * C2,...)
|
alloc(
- (E1) * (E2)
+ array_size(E1, E2)
,...)
)
// </smpl>
Signed-off-by: Julia Lawall <Julia.Lawall@inria.fr>
---
drivers/net/ethernet/amd/pds_core/core.c | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/drivers/net/ethernet/amd/pds_core/core.c b/drivers/net/ethernet/amd/pds_core/core.c
index 483a070d96fa..d87f45a1ee2f 100644
--- a/drivers/net/ethernet/amd/pds_core/core.c
+++ b/drivers/net/ethernet/amd/pds_core/core.c
@@ -196,7 +196,7 @@ int pdsc_qcq_alloc(struct pdsc *pdsc, unsigned int type, unsigned int index,
dma_addr_t q_base_pa;
int err;
- qcq->q.info = vzalloc(num_descs * sizeof(*qcq->q.info));
+ qcq->q.info = vzalloc(array_size(num_descs, sizeof(*qcq->q.info)));
if (!qcq->q.info) {
err = -ENOMEM;
goto err_out;
@@ -219,7 +219,7 @@ int pdsc_qcq_alloc(struct pdsc *pdsc, unsigned int type, unsigned int index,
if (err)
goto err_out_free_q_info;
- qcq->cq.info = vzalloc(num_descs * sizeof(*qcq->cq.info));
+ qcq->cq.info = vzalloc(array_size(num_descs, sizeof(*qcq->cq.info)));
if (!qcq->cq.info) {
err = -ENOMEM;
goto err_out_free_irq;
^ permalink raw reply related [flat|nested] 20+ messages in thread
* Re: [PATCH 09/26] pds_core: use array_size
2023-06-23 21:14 ` [PATCH 09/26] pds_core: " Julia Lawall
@ 2023-06-24 15:47 ` Simon Horman
2023-06-26 16:02 ` Shannon Nelson
1 sibling, 0 replies; 20+ messages in thread
From: Simon Horman @ 2023-06-24 15:47 UTC (permalink / raw)
To: Julia Lawall
Cc: Shannon Nelson, keescook, kernel-janitors, Brett Creeley,
David S. Miller, Eric Dumazet, Jakub Kicinski, Paolo Abeni,
netdev, linux-kernel
On Fri, Jun 23, 2023 at 11:14:40PM +0200, Julia Lawall wrote:
> Use array_size to protect against multiplication overflows.
>
> The changes were done using the following Coccinelle semantic patch:
>
> // <smpl>
> @@
> expression E1, E2;
> constant C1, C2;
> identifier alloc = {vmalloc,vzalloc};
> @@
>
> (
> alloc(C1 * C2,...)
> |
> alloc(
> - (E1) * (E2)
> + array_size(E1, E2)
> ,...)
> )
> // </smpl>
>
> Signed-off-by: Julia Lawall <Julia.Lawall@inria.fr>
Reviewed-by: Simon Horman <simon.horman@corigine.com>
^ permalink raw reply [flat|nested] 20+ messages in thread
* Re: [PATCH 09/26] pds_core: use array_size
2023-06-23 21:14 ` [PATCH 09/26] pds_core: " Julia Lawall
2023-06-24 15:47 ` Simon Horman
@ 2023-06-26 16:02 ` Shannon Nelson
1 sibling, 0 replies; 20+ messages in thread
From: Shannon Nelson @ 2023-06-26 16:02 UTC (permalink / raw)
To: Julia Lawall
Cc: keescook, kernel-janitors, Brett Creeley, David S. Miller,
Eric Dumazet, Jakub Kicinski, Paolo Abeni, netdev, linux-kernel
On 6/23/23 2:14 PM, Julia Lawall wrote:
>
> Use array_size to protect against multiplication overflows.
>
> The changes were done using the following Coccinelle semantic patch:
>
> // <smpl>
> @@
> expression E1, E2;
> constant C1, C2;
> identifier alloc = {vmalloc,vzalloc};
> @@
>
> (
> alloc(C1 * C2,...)
> |
> alloc(
> - (E1) * (E2)
> + array_size(E1, E2)
> ,...)
> )
> // </smpl>
>
> Signed-off-by: Julia Lawall <Julia.Lawall@inria.fr>
Thanks,
Acked-by: Shannon Nelson <shannon.nelson@amd.com>
>
> ---
> drivers/net/ethernet/amd/pds_core/core.c | 4 ++--
> 1 file changed, 2 insertions(+), 2 deletions(-)
>
> diff --git a/drivers/net/ethernet/amd/pds_core/core.c b/drivers/net/ethernet/amd/pds_core/core.c
> index 483a070d96fa..d87f45a1ee2f 100644
> --- a/drivers/net/ethernet/amd/pds_core/core.c
> +++ b/drivers/net/ethernet/amd/pds_core/core.c
> @@ -196,7 +196,7 @@ int pdsc_qcq_alloc(struct pdsc *pdsc, unsigned int type, unsigned int index,
> dma_addr_t q_base_pa;
> int err;
>
> - qcq->q.info = vzalloc(num_descs * sizeof(*qcq->q.info));
> + qcq->q.info = vzalloc(array_size(num_descs, sizeof(*qcq->q.info)));
> if (!qcq->q.info) {
> err = -ENOMEM;
> goto err_out;
> @@ -219,7 +219,7 @@ int pdsc_qcq_alloc(struct pdsc *pdsc, unsigned int type, unsigned int index,
> if (err)
> goto err_out_free_q_info;
>
> - qcq->cq.info = vzalloc(num_descs * sizeof(*qcq->cq.info));
> + qcq->cq.info = vzalloc(array_size(num_descs, sizeof(*qcq->cq.info)));
> if (!qcq->cq.info) {
> err = -ENOMEM;
> goto err_out_free_irq;
>
^ permalink raw reply [flat|nested] 20+ messages in thread
* [PATCH 11/26] ionic: use array_size
2023-06-23 21:14 [PATCH 00/26] use array_size Julia Lawall
` (2 preceding siblings ...)
2023-06-23 21:14 ` [PATCH 09/26] pds_core: " Julia Lawall
@ 2023-06-23 21:14 ` Julia Lawall
2023-06-24 15:47 ` Simon Horman
2023-06-26 16:03 ` Shannon Nelson
2023-06-23 21:14 ` [PATCH 18/26] net: enetc: " Julia Lawall
2023-06-23 21:14 ` [PATCH 22/26] net: mana: " Julia Lawall
5 siblings, 2 replies; 20+ messages in thread
From: Julia Lawall @ 2023-06-23 21:14 UTC (permalink / raw)
To: Shannon Nelson
Cc: keescook, kernel-janitors, Brett Creeley, drivers,
David S. Miller, Eric Dumazet, Jakub Kicinski, Paolo Abeni,
netdev, linux-kernel
Use array_size to protect against multiplication overflows.
The changes were done using the following Coccinelle semantic patch:
// <smpl>
@@
expression E1, E2;
constant C1, C2;
identifier alloc = {vmalloc,vzalloc};
@@
(
alloc(C1 * C2,...)
|
alloc(
- (E1) * (E2)
+ array_size(E1, E2)
,...)
)
// </smpl>
Signed-off-by: Julia Lawall <Julia.Lawall@inria.fr>
---
drivers/net/ethernet/pensando/ionic/ionic_lif.c | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/drivers/net/ethernet/pensando/ionic/ionic_lif.c b/drivers/net/ethernet/pensando/ionic/ionic_lif.c
index 957027e546b3..f2e2c6853536 100644
--- a/drivers/net/ethernet/pensando/ionic/ionic_lif.c
+++ b/drivers/net/ethernet/pensando/ionic/ionic_lif.c
@@ -560,7 +560,7 @@ static int ionic_qcq_alloc(struct ionic_lif *lif, unsigned int type,
new->q.dev = dev;
new->flags = flags;
- new->q.info = vzalloc(num_descs * sizeof(*new->q.info));
+ new->q.info = vzalloc(array_size(num_descs, sizeof(*new->q.info)));
if (!new->q.info) {
netdev_err(lif->netdev, "Cannot allocate queue info\n");
err = -ENOMEM;
@@ -581,7 +581,7 @@ static int ionic_qcq_alloc(struct ionic_lif *lif, unsigned int type,
if (err)
goto err_out;
- new->cq.info = vzalloc(num_descs * sizeof(*new->cq.info));
+ new->cq.info = vzalloc(array_size(num_descs, sizeof(*new->cq.info)));
if (!new->cq.info) {
netdev_err(lif->netdev, "Cannot allocate completion queue info\n");
err = -ENOMEM;
^ permalink raw reply related [flat|nested] 20+ messages in thread
* Re: [PATCH 11/26] ionic: use array_size
2023-06-23 21:14 ` [PATCH 11/26] ionic: " Julia Lawall
@ 2023-06-24 15:47 ` Simon Horman
2023-06-26 16:03 ` Shannon Nelson
1 sibling, 0 replies; 20+ messages in thread
From: Simon Horman @ 2023-06-24 15:47 UTC (permalink / raw)
To: Julia Lawall
Cc: Shannon Nelson, keescook, kernel-janitors, Brett Creeley,
drivers, David S. Miller, Eric Dumazet, Jakub Kicinski,
Paolo Abeni, netdev, linux-kernel
On Fri, Jun 23, 2023 at 11:14:42PM +0200, Julia Lawall wrote:
> Use array_size to protect against multiplication overflows.
>
> The changes were done using the following Coccinelle semantic patch:
>
> // <smpl>
> @@
> expression E1, E2;
> constant C1, C2;
> identifier alloc = {vmalloc,vzalloc};
> @@
>
> (
> alloc(C1 * C2,...)
> |
> alloc(
> - (E1) * (E2)
> + array_size(E1, E2)
> ,...)
> )
> // </smpl>
>
> Signed-off-by: Julia Lawall <Julia.Lawall@inria.fr>
Reviewed-by: Simon Horman <simon.horman@corigine.com>
^ permalink raw reply [flat|nested] 20+ messages in thread
* Re: [PATCH 11/26] ionic: use array_size
2023-06-23 21:14 ` [PATCH 11/26] ionic: " Julia Lawall
2023-06-24 15:47 ` Simon Horman
@ 2023-06-26 16:03 ` Shannon Nelson
1 sibling, 0 replies; 20+ messages in thread
From: Shannon Nelson @ 2023-06-26 16:03 UTC (permalink / raw)
To: Julia Lawall
Cc: keescook, kernel-janitors, Brett Creeley, drivers,
David S. Miller, Eric Dumazet, Jakub Kicinski, Paolo Abeni,
netdev, linux-kernel
On 6/23/23 2:14 PM, Julia Lawall wrote:
>
> Use array_size to protect against multiplication overflows.
>
> The changes were done using the following Coccinelle semantic patch:
>
> // <smpl>
> @@
> expression E1, E2;
> constant C1, C2;
> identifier alloc = {vmalloc,vzalloc};
> @@
>
> (
> alloc(C1 * C2,...)
> |
> alloc(
> - (E1) * (E2)
> + array_size(E1, E2)
> ,...)
> )
> // </smpl>
>
> Signed-off-by: Julia Lawall <Julia.Lawall@inria.fr>
Thanks,
Acked-by: Shannon Nelson <shannon.nelson@amd.com>
>
> ---
> drivers/net/ethernet/pensando/ionic/ionic_lif.c | 4 ++--
> 1 file changed, 2 insertions(+), 2 deletions(-)
>
> diff --git a/drivers/net/ethernet/pensando/ionic/ionic_lif.c b/drivers/net/ethernet/pensando/ionic/ionic_lif.c
> index 957027e546b3..f2e2c6853536 100644
> --- a/drivers/net/ethernet/pensando/ionic/ionic_lif.c
> +++ b/drivers/net/ethernet/pensando/ionic/ionic_lif.c
> @@ -560,7 +560,7 @@ static int ionic_qcq_alloc(struct ionic_lif *lif, unsigned int type,
> new->q.dev = dev;
> new->flags = flags;
>
> - new->q.info = vzalloc(num_descs * sizeof(*new->q.info));
> + new->q.info = vzalloc(array_size(num_descs, sizeof(*new->q.info)));
> if (!new->q.info) {
> netdev_err(lif->netdev, "Cannot allocate queue info\n");
> err = -ENOMEM;
> @@ -581,7 +581,7 @@ static int ionic_qcq_alloc(struct ionic_lif *lif, unsigned int type,
> if (err)
> goto err_out;
>
> - new->cq.info = vzalloc(num_descs * sizeof(*new->cq.info));
> + new->cq.info = vzalloc(array_size(num_descs, sizeof(*new->cq.info)));
> if (!new->cq.info) {
> netdev_err(lif->netdev, "Cannot allocate completion queue info\n");
> err = -ENOMEM;
>
> --
> You received this message because you are subscribed to the Google Groups "Pensando Drivers" group.
> To unsubscribe from this group and stop receiving emails from it, send an email to drivers+unsubscribe@pensando.io.
> To view this discussion on the web visit https://groups.google.com/a/pensando.io/d/msgid/drivers/20230623211457.102544-12-Julia.Lawall%40inria.fr.
^ permalink raw reply [flat|nested] 20+ messages in thread
* [PATCH 18/26] net: enetc: use array_size
2023-06-23 21:14 [PATCH 00/26] use array_size Julia Lawall
` (3 preceding siblings ...)
2023-06-23 21:14 ` [PATCH 11/26] ionic: " Julia Lawall
@ 2023-06-23 21:14 ` Julia Lawall
2023-06-24 15:48 ` Simon Horman
2023-06-23 21:14 ` [PATCH 22/26] net: mana: " Julia Lawall
5 siblings, 1 reply; 20+ messages in thread
From: Julia Lawall @ 2023-06-23 21:14 UTC (permalink / raw)
To: Claudiu Manoil
Cc: keescook, kernel-janitors, Vladimir Oltean, David S. Miller,
Eric Dumazet, Jakub Kicinski, Paolo Abeni, netdev, linux-kernel
Use array_size to protect against multiplication overflows.
The changes were done using the following Coccinelle semantic patch:
// <smpl>
@@
expression E1, E2;
constant C1, C2;
identifier alloc = {vmalloc,vzalloc};
@@
(
alloc(C1 * C2,...)
|
alloc(
- (E1) * (E2)
+ array_size(E1, E2)
,...)
)
// </smpl>
Signed-off-by: Julia Lawall <Julia.Lawall@inria.fr>
---
drivers/net/ethernet/freescale/enetc/enetc.c | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/drivers/net/ethernet/freescale/enetc/enetc.c b/drivers/net/ethernet/freescale/enetc/enetc.c
index 9e1b2536e9a9..7231f8ea1ba4 100644
--- a/drivers/net/ethernet/freescale/enetc/enetc.c
+++ b/drivers/net/ethernet/freescale/enetc/enetc.c
@@ -1790,7 +1790,7 @@ static int enetc_alloc_tx_resource(struct enetc_bdr_resource *res,
res->bd_count = bd_count;
res->bd_size = sizeof(union enetc_tx_bd);
- res->tx_swbd = vzalloc(bd_count * sizeof(*res->tx_swbd));
+ res->tx_swbd = vzalloc(array_size(bd_count, sizeof(*res->tx_swbd)));
if (!res->tx_swbd)
return -ENOMEM;
@@ -1878,7 +1878,7 @@ static int enetc_alloc_rx_resource(struct enetc_bdr_resource *res,
if (extended)
res->bd_size *= 2;
- res->rx_swbd = vzalloc(bd_count * sizeof(struct enetc_rx_swbd));
+ res->rx_swbd = vzalloc(array_size(bd_count, sizeof(struct enetc_rx_swbd)));
if (!res->rx_swbd)
return -ENOMEM;
^ permalink raw reply related [flat|nested] 20+ messages in thread
* Re: [PATCH 18/26] net: enetc: use array_size
2023-06-23 21:14 ` [PATCH 18/26] net: enetc: " Julia Lawall
@ 2023-06-24 15:48 ` Simon Horman
0 siblings, 0 replies; 20+ messages in thread
From: Simon Horman @ 2023-06-24 15:48 UTC (permalink / raw)
To: Julia Lawall
Cc: Claudiu Manoil, keescook, kernel-janitors, Vladimir Oltean,
David S. Miller, Eric Dumazet, Jakub Kicinski, Paolo Abeni,
netdev, linux-kernel
On Fri, Jun 23, 2023 at 11:14:49PM +0200, Julia Lawall wrote:
> Use array_size to protect against multiplication overflows.
>
> The changes were done using the following Coccinelle semantic patch:
>
> // <smpl>
> @@
> expression E1, E2;
> constant C1, C2;
> identifier alloc = {vmalloc,vzalloc};
> @@
>
> (
> alloc(C1 * C2,...)
> |
> alloc(
> - (E1) * (E2)
> + array_size(E1, E2)
> ,...)
> )
> // </smpl>
>
> Signed-off-by: Julia Lawall <Julia.Lawall@inria.fr>
Reviewed-by: Simon Horman <simon.horman@corigine.com>
^ permalink raw reply [flat|nested] 20+ messages in thread
* [PATCH 22/26] net: mana: use array_size
2023-06-23 21:14 [PATCH 00/26] use array_size Julia Lawall
` (4 preceding siblings ...)
2023-06-23 21:14 ` [PATCH 18/26] net: enetc: " Julia Lawall
@ 2023-06-23 21:14 ` Julia Lawall
2023-06-24 15:48 ` Simon Horman
5 siblings, 1 reply; 20+ messages in thread
From: Julia Lawall @ 2023-06-23 21:14 UTC (permalink / raw)
To: K. Y. Srinivasan
Cc: keescook, kernel-janitors, Haiyang Zhang, Wei Liu, Dexuan Cui,
David S. Miller, Eric Dumazet, Jakub Kicinski, Paolo Abeni,
linux-hyperv, netdev, linux-kernel
Use array_size to protect against multiplication overflows.
The changes were done using the following Coccinelle semantic patch:
// <smpl>
@@
expression E1, E2;
constant C1, C2;
identifier alloc = {vmalloc,vzalloc};
@@
(
alloc(C1 * C2,...)
|
alloc(
- (E1) * (E2)
+ array_size(E1, E2)
,...)
)
// </smpl>
Signed-off-by: Julia Lawall <Julia.Lawall@inria.fr>
---
drivers/net/ethernet/microsoft/mana/hw_channel.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/drivers/net/ethernet/microsoft/mana/hw_channel.c b/drivers/net/ethernet/microsoft/mana/hw_channel.c
index 9d1507eba5b9..e82c513760f9 100644
--- a/drivers/net/ethernet/microsoft/mana/hw_channel.c
+++ b/drivers/net/ethernet/microsoft/mana/hw_channel.c
@@ -627,7 +627,7 @@ static int mana_hwc_establish_channel(struct gdma_context *gc, u16 *q_depth,
if (WARN_ON(cq->id >= gc->max_num_cqs))
return -EPROTO;
- gc->cq_table = vzalloc(gc->max_num_cqs * sizeof(struct gdma_queue *));
+ gc->cq_table = vzalloc(array_size(gc->max_num_cqs, sizeof(struct gdma_queue *)));
if (!gc->cq_table)
return -ENOMEM;
^ permalink raw reply related [flat|nested] 20+ messages in thread
* Re: [PATCH 22/26] net: mana: use array_size
2023-06-23 21:14 ` [PATCH 22/26] net: mana: " Julia Lawall
@ 2023-06-24 15:48 ` Simon Horman
0 siblings, 0 replies; 20+ messages in thread
From: Simon Horman @ 2023-06-24 15:48 UTC (permalink / raw)
To: Julia Lawall
Cc: K. Y. Srinivasan, keescook, kernel-janitors, Haiyang Zhang,
Wei Liu, Dexuan Cui, David S. Miller, Eric Dumazet,
Jakub Kicinski, Paolo Abeni, linux-hyperv, netdev, linux-kernel
On Fri, Jun 23, 2023 at 11:14:53PM +0200, Julia Lawall wrote:
> Use array_size to protect against multiplication overflows.
>
> The changes were done using the following Coccinelle semantic patch:
>
> // <smpl>
> @@
> expression E1, E2;
> constant C1, C2;
> identifier alloc = {vmalloc,vzalloc};
> @@
>
> (
> alloc(C1 * C2,...)
> |
> alloc(
> - (E1) * (E2)
> + array_size(E1, E2)
> ,...)
> )
> // </smpl>
>
> Signed-off-by: Julia Lawall <Julia.Lawall@inria.fr>
Reviewed-by: Simon Horman <simon.horman@corigine.com>
^ permalink raw reply [flat|nested] 20+ messages in thread
end of thread, other threads:[~2023-06-26 16:03 UTC | newest]
Thread overview: 20+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-06-23 21:14 [PATCH 00/26] use array_size Julia Lawall
2023-06-23 21:14 ` [PATCH 02/26] octeon_ep: " Julia Lawall
2023-06-24 15:46 ` Simon Horman
2023-06-24 22:28 ` Jakub Kicinski
2023-06-25 20:14 ` Christophe JAILLET
2023-06-25 20:25 ` Julia Lawall
2023-06-25 20:32 ` Christophe JAILLET
2023-06-25 20:57 ` Julia Lawall
2023-06-23 21:14 ` [PATCH 04/26] gve: " Julia Lawall
2023-06-24 15:47 ` Simon Horman
2023-06-23 21:14 ` [PATCH 09/26] pds_core: " Julia Lawall
2023-06-24 15:47 ` Simon Horman
2023-06-26 16:02 ` Shannon Nelson
2023-06-23 21:14 ` [PATCH 11/26] ionic: " Julia Lawall
2023-06-24 15:47 ` Simon Horman
2023-06-26 16:03 ` Shannon Nelson
2023-06-23 21:14 ` [PATCH 18/26] net: enetc: " Julia Lawall
2023-06-24 15:48 ` Simon Horman
2023-06-23 21:14 ` [PATCH 22/26] net: mana: " Julia Lawall
2023-06-24 15:48 ` Simon Horman
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).