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] [day] [month] [year] [list]
Message-ID: <202006162048.A22F1C14@keescook>
Date:   Tue, 16 Jun 2020 20:48:48 -0700
From:   Kees Cook <keescook@...omium.org>
To:     "Gustavo A. R. Silva" <gustavo@...eddedor.com>
Cc:     "Gustavo A. R. Silva" <gustavoars@...nel.org>,
        linux-kernel@...r.kernel.org
Subject: Re: [PATCH v2] overflow.h: Add flex_array_size() helper

On Tue, Jun 16, 2020 at 03:48:51PM -0500, Gustavo A. R. Silva wrote:
> 
> 
> On 6/10/20 16:38, Kees Cook wrote:
> 
> >> -#define struct_size(p, member, n)					\
> >> -	__ab_c_size(n,							\
> >> +#define struct_size(p, member, count)					\
> >> +	__ab_c_size(count,							\
> >>  		    sizeof(*(p)->member) + __must_be_array((p)->member),\
> >>  		    sizeof(*(p)))
> > 
> > I like the "count" change -- "n" can be seen as either count or bytes,
> > so I like this being distinctly "count".
> > 
> 
> Yep. :)
> 
> >>  
> >> +/**
> >> + * flex_array_size() - Calculate size, in bytes, of a flexible array member
> >> + * within an enclosing structure. Read on for more details.
> >> + *
> >> + * @p: Pointer to the structure.
> >> + * @member: Name of the flexible array member.
> >> + * @count: Number of elements in the array.
> >> + *
> >> + * Calculates size, in bytes, of a flexible array @member of @count elements
> >> + * within structure @p.
> >> + *
> >> + * Return: number of bytes needed or SIZE_MAX on overflow.
> >> + */
> >> +#define flex_array_size(p, member, count)					\
> >> +	array_size(count,							\
> >> +		    sizeof(*(p)->member) + __must_be_array((p)->member))
> >> +
> >>  #endif /* __LINUX_OVERFLOW_H */
> > 
> > I like it! You mentioned off-list that maybe this could be named
> > sizeof_flex_array() (like sizeof_field(), etc), and that does seem
> > attractive. As you also mentioned, it begs the question of renaming
> > struct_size() to sizeof_struct().
> > 
> > Looking back through the thread[1], it seems the name came from Linus[2],
> > and was more related to the existing array_size() helper.
> > 
> > So, how about this, as a convention we can use to make a choice:
> > 
> > For things that are strictly constant in size, we can use sizeof_*. For
> > things that have a dynamic component, we'll use *_size(). So, this patch
> > is correct as-is.
> > 
> 
> I like the idea. I haven't thought it in terms of dynamic and constant size,
> but it sounds sensible.
> 
> > Acked-by: Kees Cook <keescook@...omium.org>
> > 
> > (I wonder who's tree this should go via?)
> > 
> 
> Yours? :)

Done; I'll see if Linus will take this for -rc2 so you'll be able to use
it for v5.9 patches...

Thanks!

-- 
Kees Cook

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ