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: <20231002164103.56e6a2b4.alex.williamson@redhat.com>
Date:   Mon, 2 Oct 2023 16:41:03 -0600
From:   Alex Williamson <alex.williamson@...hat.com>
To:     Cong Liu <liucong2@...inos.cn>
Cc:     jgg@...pe.ca, kvm@...r.kernel.org, linux-kernel@...r.kernel.org
Subject: Re: [PATCH v3] vfio: Fix uninitialized symbol and potential
 dereferencing errors in vfio_combine_iova_ranges

On Wed, 20 Sep 2023 17:55:31 +0800
Cong Liu <liucong2@...inos.cn> wrote:

> when compiling with smatch check, the following errors were encountered:
> 
> drivers/vfio/vfio_main.c:957 vfio_combine_iova_ranges() error: uninitialized symbol 'last'.
> drivers/vfio/vfio_main.c:978 vfio_combine_iova_ranges() error: potentially dereferencing uninitialized 'comb_end'.
> drivers/vfio/vfio_main.c:978 vfio_combine_iova_ranges() error: potentially dereferencing uninitialized 'comb_start'.
> 
> This patch initializes the variables last, comb_end, and comb_start
> to avoid compiler warnings and add proper argument checks to ensure
> interval_tree_iter_first() does not return NULL.
> 
> Signed-off-by: Cong Liu <liucong2@...inos.cn>
> ---
>  drivers/vfio/vfio_main.c | 9 +++++++--
>  1 file changed, 7 insertions(+), 2 deletions(-)
> 
> diff --git a/drivers/vfio/vfio_main.c b/drivers/vfio/vfio_main.c
> index 40732e8ed4c6..ecd4dd8e6b05 100644
> --- a/drivers/vfio/vfio_main.c
> +++ b/drivers/vfio/vfio_main.c
> @@ -938,12 +938,17 @@ static int vfio_ioctl_device_feature_migration(struct vfio_device *device,
>  void vfio_combine_iova_ranges(struct rb_root_cached *root, u32 cur_nodes,
>  			      u32 req_nodes)
>  {
> -	struct interval_tree_node *prev, *curr, *comb_start, *comb_end;
> +	if (!cur_nodes || cur_nodes <= req_nodes ||
> +		WARN_ON(!req_nodes || !root->rb_root.rb_node))
> +		return;

Code should not precede variable declaration.  The wrapped line should
align inside the parenthesis of the previous line.

> +
> +	struct interval_tree_node *prev, *curr;
> +	struct interval_tree_node *comb_start = NULL, *comb_end = NULL;

These only mask the issue reported by smatch, should we encounter the
condition where these are used uninitialized, derefencing NULL is only
marginally better.

>  	unsigned long min_gap, curr_gap;
>  
>  	/* Special shortcut when a single range is required */
>  	if (req_nodes == 1) {
> -		unsigned long last;
> +		unsigned long last = 0;

This also masks the actual error, which can only occur from an empty
list which still results in a NULL pointer derefence.  Should we even
make use of @last, a zero value is arbitrary.

I'll follow-up with a patch that I believe better resolves the report.
Thanks,

Alex

>  
>  		comb_start = interval_tree_iter_first(root, 0, ULONG_MAX);
>  		curr = comb_start;

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ