[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [PATCH] xen/privcmd: fix error exit of privcmd_ioctl_dm_op()


  • To: Juergen Gross <jgross@xxxxxxxx>
  • From: Jan Beulich <jbeulich@xxxxxxxx>
  • Date: Thu, 25 Aug 2022 09:38:52 +0200
  • Arc-authentication-results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=suse.com; dmarc=pass action=none header.from=suse.com; dkim=pass header.d=suse.com; arc=none
  • Arc-message-signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=3O6AAcG197ZLgdwKvrbRJiihxehoeIAjIb3c4a1ELTU=; b=RkQ5PqP+bz2F2eCJAr3MYdHe96zh+TCCW0mvZux58xK1o4B2dfqAt9At9VPT/BomORaD7YPRDMk+U319LU7dF3cM3wc2rn6lKd30UZok4imWvHagU7oJCxkEn37jUepmwFh4fFyeER2kjQFABZQa9ZNEljj1A4kWNIgjfwtYMtbM7NbBVDZQ5NB/fYv2QE/2pUu4mbcLJjwMqBpHpYu7VqPEM7RIOmR5r63MPOnHRqCK2oJbo9pap+nrQ5hc+9L69ylZl8dWzn+Oad1PMmu60tDfBf4CUtvD7Z6tGlCrt3L8ta21mANUGyPH0jIcXl+RSHSJte9y4LvuZbmnMw+PqQ==
  • Arc-seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=a/AKPh8Hk1ifObUG3hELu5YepjSW4zGG3CTra13N1BWu2hRl+rKaLtMLx1w9Y7r5GDYVggMN8msCrN5xcljzbzTSyvqeQOX+j46JwdNMBa2ofemWkW6CGbcEOPCQuIhejVGqLOJfyF3HJyrdBXC4S1K0AldGUb5pZTYmfzdk/QgQ7G+7Mw7lWpH9N3mfiHD3hviQl3IvOVC99ZFZn8cPIRDPKXqek8rT6k36oNi/uOuPs4JMVOxNGMmSekSGLVwQrBw+4drAsgHH6vWz95F8JW3XYem5GSKTvK5IUg5JuMTIX4odhqhW84QUDmUYNkIPyinjZKGA2Os6PtHYntW5Qw==
  • Authentication-results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=suse.com;
  • Cc: Stefano Stabellini <sstabellini@xxxxxxxxxx>, Oleksandr Tyshchenko <oleksandr_tyshchenko@xxxxxxxx>, stable@xxxxxxxxxxxxxxx, Rustam Subkhankulov <subkhankulov@xxxxxxxxx>, xen-devel@xxxxxxxxxxxxxxxxxxxx, linux-kernel@xxxxxxxxxxxxxxx
  • Delivery-date: Thu, 25 Aug 2022 07:39:04 +0000
  • List-id: Xen developer discussion <xen-devel.lists.xenproject.org>

On 24.08.2022 16:26, Juergen Gross wrote:
> The error exit of privcmd_ioctl_dm_op() is calling unlock_pages()
> potentially with pages being NULL, leading to a NULL dereference.
> 
> Fix that by calling unlock_pages only if lock_pages() was at least
> partially successful.
> 
> Cc: <stable@xxxxxxxxxxxxxxx>
> Fixes: ab520be8cd5d ("xen/privcmd: Add IOCTL_PRIVCMD_DM_OP")
> Reported-by: Rustam Subkhankulov <subkhankulov@xxxxxxxxx>
> Signed-off-by: Juergen Gross <jgross@xxxxxxxx>

Reviewed-by: Jan Beulich <jbeulich@xxxxxxxx>
albeit I wonder whether you did consider the variant actually
reducing code size (and avoiding the need for yet another label),
...

> --- a/drivers/xen/privcmd.c
> +++ b/drivers/xen/privcmd.c
> @@ -679,7 +679,7 @@ static long privcmd_ioctl_dm_op(struct file *file, void 
> __user *udata)
>       rc = lock_pages(kbufs, kdata.num, pages, nr_pages, &pinned);
>       if (rc < 0) {
>               nr_pages = pinned;

... dropping this line and ...

> -             goto out;
> +             goto unlock;
>       }
>  
>       for (i = 0; i < kdata.num; i++) {
> @@ -691,8 +691,9 @@ static long privcmd_ioctl_dm_op(struct file *file, void 
> __user *udata)
>       rc = HYPERVISOR_dm_op(kdata.dom, kdata.num, xbufs);
>       xen_preemptible_hcall_end();
>  
> -out:
> + unlock:
>       unlock_pages(pages, nr_pages);

... passing "pinned" here.

Jan

> + out:
>       kfree(xbufs);
>       kfree(pages);
>       kfree(kbufs);




 


Rackspace

Lists.xenproject.org is hosted with RackSpace, monitoring our
servers 24x7x365 and backed by RackSpace's Fanatical Support®.