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

Re: [PATCH v2] 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 11:50:25 +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=LxT+5NAiXocn1FHo46V4cbpVzJwy9brM9OUlwqFBq0s=; b=YQEDVx+aOMm3MrTQUVb/ovJo8qyMDZaO6GxXa4VcTdEvO+c0lqMGJaNJQ/o3PZGt3sSyFV0dxYTNPBIyBKDFa5xbEsye3JHrgKqqiqjxLWOIYECPrb2lLc6BueH8wkxEI9j5eFQZivXXJey3sXkaYNB4A7IYVeDTTZyNlCQgVmmkPFX8KcVXUqJjP6/VqCiSK8n1KGx1Luj6lo0V9tpEBHQtL8A4TTT/JWx9VSXc+OU6KbQAaAYMQ88bi5LhUD7W4J+GRnKtzDsD1npy96vOqF0M5Z7i9p+jf/Arnz7UM2Ie1J28T/F837uD21C2mrF+gbvtF3RUqcQaxCil9bap1g==
  • Arc-seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=Ss9MezrMRiy9KviHtIlLuACS85pEn3ZY0dmHYBmXZtVTpirhKEo8b3XuQjzzlfj/ogvxT8sADksLVMLcHp1hIZdEurOx3HXI2ma4V5XvhUESujI9XqbYQCHz4Ua0/X62l42s81PBWBWpmpy8Ba4ZvyjKVLelgM05xA039OYCa2N2Q2gE/A67rN5vxGYIxrmi3OTNNF47f6BGhEpuScLcyHBoSRNW2uRcq0UmzfBEyoKVMkbT/SxKxufHtkZQOTR6Vx6RlicOtSu6zwJrJxrnVVv82S/flb3veGwYBbSuu5rIz8atmpwobnLAMRnssIYMwEvlTgNZk93AdgxCeD7qoA==
  • 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 09:50:31 +0000
  • List-id: Xen developer discussion <xen-devel.lists.xenproject.org>

On 25.08.2022 11: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.
> 
> Additionally lock_pages() doesn't check for pin_user_pages_fast()
> having been completely successful, resulting in potentially not
> locking all pages into memory. This could result in sporadic failures
> when using the related memory in user mode.
> 
> Fix all of that by calling unlock_pages() always with the real number
> of pinned pages, which will be zero in case pages being NULL, and by
> checking the number of patches pinned by pin_user_pages_fast()

Nit: s/patches/pages/

> matching the expected number of pages.
> 
> 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>

I have a question / suggestion, though:

> --- a/drivers/xen/privcmd.c
> +++ b/drivers/xen/privcmd.c
> @@ -602,6 +602,10 @@ static int lock_pages(
>               *pinned += page_count;
>               nr_pages -= page_count;
>               pages += page_count;
> +
> +             /* Exact reason isn't known, EFAULT is one possibility. */
> +             if (page_count < requested)
> +                     return -EFAULT;
>       }

I don't really know the inner workings of pin_user_pages_fast()
nor what future plans there are with it. To be as independent of
its behavior as possible, how about bailing here only when
page_count actually is zero (i.e. no forward progress)?

Jan



 


Rackspace

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