lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  linux-cve-announce  PHC 
Open Source and information security mailing list archives
 
Hash Suite: Windows password security audit tool. GUI, reports in PDF.
[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <fa304f0ef1dba4fcf5e495f3c2feb4d3816f20ac.camel@perches.com>
Date:   Tue, 23 Jun 2020 22:56:32 -0700
From:   Joe Perches <joe@...ches.com>
To:     Vinod Koul <vkoul@...nel.org>,
        "Gustavo A. R. Silva" <gustavoars@...nel.org>,
        Peter Ujfalusi <peter.ujfalusi@...com>
Cc:     Dan Williams <dan.j.williams@...el.com>, dmaengine@...r.kernel.org,
        linux-kernel@...r.kernel.org,
        "Gustavo A. R. Silva" <gustavo@...eddedor.com>
Subject: Re: [PATCH][next] dmaengine: ti: k3-udma: Use struct_size() in
 kzalloc()

On Wed, 2020-06-24 at 11:25 +0530, Vinod Koul wrote:
> On 19-06-20, 17:43, Gustavo A. R. Silva wrote:
> > Make use of the struct_size() helper instead of an open-coded version
> > in order to avoid any potential type mistakes.
> > 
> > This code was detected with the help of Coccinelle and, audited and
> > fixed manually.
> > 
> > Addresses-KSPP-ID: https://github.com/KSPP/linux/issues/83

Is this odd tag really useful?

> > Signed-off-by: Gustavo A. R. Silva <gustavoars@...nel.org>
> > ---
> >  drivers/dma/ti/k3-udma.c | 4 ++--
> >  1 file changed, 2 insertions(+), 2 deletions(-)
> > 
> > diff --git a/drivers/dma/ti/k3-udma.c b/drivers/dma/ti/k3-udma.c
> > index 0d5fb154b8e2..411c54b86ba8 100644
> > --- a/drivers/dma/ti/k3-udma.c
> > +++ b/drivers/dma/ti/k3-udma.c
> > @@ -2209,7 +2209,7 @@ udma_prep_slave_sg_pkt(struct udma_chan *uc, struct scatterlist *sgl,
> >  	u32 ring_id;
> >  	unsigned int i;
> >  
> > -	d = kzalloc(sizeof(*d) + sglen * sizeof(d->hwdesc[0]), GFP_NOWAIT);
> > +	d = kzalloc(struct_size(d, hwdesc, sglen), GFP_NOWAIT);
> 
> struct_size() is a * b + c but here we need, a + b * c.. the trailing
> struct is N times here..
> 
> 
> >  	if (!d)
> >  		return NULL;
> >  
> > @@ -2525,7 +2525,7 @@ udma_prep_dma_cyclic_pkt(struct udma_chan *uc, dma_addr_t buf_addr,
> >  	if (period_len >= SZ_4M)
> >  		return NULL;
> >  
> > -	d = kzalloc(sizeof(*d) + periods * sizeof(d->hwdesc[0]), GFP_NOWAIT);
> > +	d = kzalloc(struct_size(d, hwdesc, periods), GFP_NOWAIT);
> >  	if (!d)
> >  		return NULL;
> >  
> > -- 
> > 2.27.0

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ