[<prev] [next>] [<thread-prev] [day] [month] [year] [list]
Message-ID: <fd6b950f-4d5f-4f8f-b248-52239cbcb4bb@stanley.mountain>
Date: Fri, 7 Feb 2025 10:46:40 +0300
From: Dan Carpenter <dan.carpenter@...aro.org>
To: Alexey Dobriyan <adobriyan@...il.com>
Cc: Steffen Klassert <steffen.klassert@...unet.com>,
Herbert Xu <herbert@...dor.apana.org.au>,
"David S. Miller" <davem@...emloft.net>,
Eric Dumazet <edumazet@...gle.com>,
Jakub Kicinski <kuba@...nel.org>, Paolo Abeni <pabeni@...hat.com>,
Simon Horman <horms@...nel.org>, netdev@...r.kernel.org,
linux-kernel@...r.kernel.org, kernel-janitors@...r.kernel.org
Subject: Re: less size_t please (was Re: [PATCH net] xfrm: fix integer
overflow in xfrm_replay_state_esn_len())
On Thu, Feb 06, 2025 at 08:06:55PM +0300, Alexey Dobriyan wrote:
> On Thu, Jan 30, 2025 at 07:15:15PM +0300, Dan Carpenter wrote:
> > On Thu, Jan 30, 2025 at 04:44:42PM +0300, Alexey Dobriyan wrote:
> > > > -static inline unsigned int xfrm_replay_state_esn_len(struct xfrm_replay_state_esn *replay_esn)
> > > > +static inline size_t xfrm_replay_state_esn_len(struct xfrm_replay_state_esn *replay_esn)
> > > > {
> > > > - return sizeof(*replay_esn) + replay_esn->bmp_len * sizeof(__u32);
> > > > + return size_add(sizeof(*replay_esn), size_mul(replay_esn->bmp_len, sizeof(__u32)));
> > >
> > > Please don't do this.
> > >
> > > You can (and should!) make calculations and check for overflow at the
> > > same time. It's very efficient.
> > >
> > > > 1) Use size_add() and size_mul(). This change is necessary for 32bit systems.
> > >
> > > This bloats code on 32-bit.
> > >
> >
> > I'm not sure I understand. On 32-bit systems a size_t and an unsigned
> > int are the same size. Did you mean to say 64-bit?
>
> It looks like yes.
>
> > Declaring sizes as u32 leads to integer overflows like this one.
>
> No, the problem is unchecked C addition and mixing types which confuses
> people (in the opposite direction too -- there were fake CVEs because
> someone thought "size_t len" in write hooks could be big enough).
>
What was the CVE number?
regards,
dan carpenter
Powered by blists - more mailing lists