[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <a69d7917-daae-c8d9-5f4b-2300c99168b8@suse.com>
Date: Thu, 25 Aug 2022 12:13:21 +0200
From: Juergen Gross <jgross@...e.com>
To: Jan Beulich <jbeulich@...e.com>
Cc: Stefano Stabellini <sstabellini@...nel.org>,
Oleksandr Tyshchenko <oleksandr_tyshchenko@...m.com>,
stable@...r.kernel.org,
Rustam Subkhankulov <subkhankulov@...ras.ru>,
xen-devel@...ts.xenproject.org, linux-kernel@...r.kernel.org
Subject: Re: [PATCH v2] xen/privcmd: fix error exit of privcmd_ioctl_dm_op()
On 25.08.22 11:50, Jan Beulich wrote:
> 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@...r.kernel.org>
>> Fixes: ab520be8cd5d ("xen/privcmd: Add IOCTL_PRIVCMD_DM_OP")
>> Reported-by: Rustam Subkhankulov <subkhankulov@...ras.ru>
>> Signed-off-by: Juergen Gross <jgross@...e.com>
>
> Reviewed-by: Jan Beulich <jbeulich@...e.com>
>
> 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)?
This would require to rework the loop in lock_pages() to be able to
handle only a partial buffer.
This would add some complexity, but OTOH I'd get an exact error code
back in case of failure.
I'll have a try and see how the result would look like.
Juergen
Download attachment "OpenPGP_0xB0DE9DD628BF132F.asc" of type "application/pgp-keys" (3099 bytes)
Download attachment "OpenPGP_signature" of type "application/pgp-signature" (496 bytes)
Powered by blists - more mailing lists