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: <6016329a-4dac-ac23-9e6f-5da3dd3fefa0@embeddedor.com>
Date:   Fri, 24 Jan 2020 15:12:59 -0600
From:   "Gustavo A. R. Silva" <gustavo@...eddedor.com>
To:     Stephen Kitt <steve@....org>,
        Philipp Reisner <philipp.reisner@...bit.com>,
        Lars Ellenberg <lars.ellenberg@...bit.com>,
        Jens Axboe <axboe@...nel.dk>, drbd-dev@...ts.linbit.com
Cc:     linux-block@...r.kernel.org, linux-kernel@...r.kernel.org
Subject: Re: [PATCH] drbd fifo_alloc: use struct_size



On 1/24/20 14:03, Stephen Kitt wrote:
> Switching to struct_size for the allocation in fifo_alloc avoids
> hard-coding the type of fifo_buffer.values in fifo_alloc. It also
> provides overflow protection; to avoid pessimistic code being
> generated by the compiler as a result, this patch also switches
> fifo_size to unsigned, propagating the change as appropriate.
> 
> Signed-off-by: Stephen Kitt <steve@....org>

Reviewed-by: Gustavo A. R. Silva <gustavo@...eddedor.com>

Thanks
--
Gustavo

> ---
>  drivers/block/drbd/drbd_int.h      | 2 +-
>  drivers/block/drbd/drbd_nl.c       | 3 ++-
>  drivers/block/drbd/drbd_receiver.c | 2 +-
>  drivers/block/drbd/drbd_worker.c   | 4 ++--
>  4 files changed, 6 insertions(+), 5 deletions(-)
> 
> diff --git a/drivers/block/drbd/drbd_int.h b/drivers/block/drbd/drbd_int.h
> index ddbf56014c51..aae99a2d7bd4 100644
> --- a/drivers/block/drbd/drbd_int.h
> +++ b/drivers/block/drbd/drbd_int.h
> @@ -622,7 +622,7 @@ struct fifo_buffer {
>  	int total; /* sum of all values */
>  	int values[0];
>  };
> -extern struct fifo_buffer *fifo_alloc(int fifo_size);
> +extern struct fifo_buffer *fifo_alloc(unsigned int fifo_size);
>  
>  /* flag bits per connection */
>  enum {
> diff --git a/drivers/block/drbd/drbd_nl.c b/drivers/block/drbd/drbd_nl.c
> index de2f94d0103a..da4a3ebe04ef 100644
> --- a/drivers/block/drbd/drbd_nl.c
> +++ b/drivers/block/drbd/drbd_nl.c
> @@ -1575,7 +1575,8 @@ int drbd_adm_disk_opts(struct sk_buff *skb, struct genl_info *info)
>  	struct drbd_device *device;
>  	struct disk_conf *new_disk_conf, *old_disk_conf;
>  	struct fifo_buffer *old_plan = NULL, *new_plan = NULL;
> -	int err, fifo_size;
> +	int err;
> +	unsigned int fifo_size;
>  
>  	retcode = drbd_adm_prepare(&adm_ctx, skb, info, DRBD_ADM_NEED_MINOR);
>  	if (!adm_ctx.reply_skb)
> diff --git a/drivers/block/drbd/drbd_receiver.c b/drivers/block/drbd/drbd_receiver.c
> index 2b3103c30857..79e216446030 100644
> --- a/drivers/block/drbd/drbd_receiver.c
> +++ b/drivers/block/drbd/drbd_receiver.c
> @@ -3887,7 +3887,7 @@ static int receive_SyncParam(struct drbd_connection *connection, struct packet_i
>  	struct disk_conf *old_disk_conf = NULL, *new_disk_conf = NULL;
>  	const int apv = connection->agreed_pro_version;
>  	struct fifo_buffer *old_plan = NULL, *new_plan = NULL;
> -	int fifo_size = 0;
> +	unsigned int fifo_size = 0;
>  	int err;
>  
>  	peer_device = conn_peer_device(connection, pi->vnr);
> diff --git a/drivers/block/drbd/drbd_worker.c b/drivers/block/drbd/drbd_worker.c
> index 5bdcc70ad589..b7f605c6e231 100644
> --- a/drivers/block/drbd/drbd_worker.c
> +++ b/drivers/block/drbd/drbd_worker.c
> @@ -482,11 +482,11 @@ static void fifo_add_val(struct fifo_buffer *fb, int value)
>  		fb->values[i] += value;
>  }
>  
> -struct fifo_buffer *fifo_alloc(int fifo_size)
> +struct fifo_buffer *fifo_alloc(unsigned int fifo_size)
>  {
>  	struct fifo_buffer *fb;
>  
> -	fb = kzalloc(sizeof(struct fifo_buffer) + sizeof(int) * fifo_size, GFP_NOIO);
> +	fb = kzalloc(struct_size(fb, values, fifo_size), GFP_NOIO);
>  	if (!fb)
>  		return NULL;
>  
> 

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ