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: <202306291300.7DBE393BC@keescook>
Date:   Thu, 29 Jun 2023 13:02:42 -0700
From:   Kees Cook <keescook@...omium.org>
To:     "Gustavo A. R. Silva" <gustavoars@...nel.org>
Cc:     "David S. Miller" <davem@...emloft.net>,
        sparclinux@...r.kernel.org, linux-kernel@...r.kernel.org,
        linux-hardening@...r.kernel.org
Subject: Re: [PATCH][next] openprom: Use struct_size() helper

On Thu, Jun 22, 2023 at 05:25:13PM -0600, Gustavo A. R. Silva wrote:
> Prefer struct_size() over open-coded versions.

This commit log could be more descriptive since the replacement below
isn't in the standard "sizeof(struct) + sizeof(element) * count" format.
:) It took me a moment to figure out what was going on:

struct openpromio
{
        unsigned int oprom_size;        /* Actual size of the oprom_array. */
        char    oprom_array[];          /* Holds property names and values. */
};

sizeof(struct openpromio) == sizeof(int)   :P


> 
> Link: https://github.com/KSPP/linux/issues/160
> Signed-off-by: Gustavo A. R. Silva <gustavoars@...nel.org>
> ---
>  drivers/sbus/char/openprom.c | 8 ++++++--
>  1 file changed, 6 insertions(+), 2 deletions(-)
> 
> diff --git a/drivers/sbus/char/openprom.c b/drivers/sbus/char/openprom.c
> index 30b9751aad30..de56c8fec373 100644
> --- a/drivers/sbus/char/openprom.c
> +++ b/drivers/sbus/char/openprom.c
> @@ -76,7 +76,9 @@ static int copyin(struct openpromio __user *info, struct openpromio **opp_p)
>  	if (bufsize > OPROMMAXPARAM)
>  		bufsize = OPROMMAXPARAM;
>  
> -	if (!(*opp_p = kzalloc(sizeof(int) + bufsize + 1, GFP_KERNEL)))
> +	*opp_p = kzalloc(struct_size(*opp_p, oprom_array, bufsize + 1),
> +			 GFP_KERNEL);
> +	if (!*opp_p)
>  		return -ENOMEM;
>  
>  	if (copy_from_user(&(*opp_p)->oprom_array,
> @@ -95,7 +97,9 @@ static int getstrings(struct openpromio __user *info, struct openpromio **opp_p)
>  	if (!info || !opp_p)
>  		return -EFAULT;
>  
> -	if (!(*opp_p = kzalloc(sizeof(int) + OPROMMAXPARAM + 1, GFP_KERNEL)))
> +	*opp_p = kzalloc(struct_size(*opp_p, oprom_array, OPROMMAXPARAM + 1),
> +			 GFP_KERNEL);
> +	if (!*opp_p)
>  		return -ENOMEM;

With that understood, yeah, these look good to me. :)

Reviewed-by: Kees Cook <keescook@...omium.org>

-- 
Kees Cook

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ