mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: "wanghai (M)" <wanghai38@huawei.com>
To: <jhansen@vmware.com>, <vdasa@vmware.com>, <arnd@arndb.de>,
	<gregkh@linuxfoundation.org>, <dtor@vmware.com>,
	<georgezhang@vmware.com>, <acking@vmware.com>
Cc: <pv-drivers@vmware.com>, <linux-kernel@vger.kernel.org>
Subject: Re: [PATCH] VMCI: fix NULL pointer dereference when unmapping queue pair
Date: Thu, 5 Aug 2021 10:05:42 +0800	[thread overview]
Message-ID: <4e66f922-c081-0b00-d77e-fb1e1d5e9d49@huawei.com> (raw)
In-Reply-To: <20210804134853.3175473-1-wanghai38@huawei.com>


在 2021/8/4 21:48, Wang Hai 写道:
> I got a NULL pointer dereference report when doing fuzz test:
>
> Call Trace:
>    qp_release_pages+0xae/0x130
>    qp_host_unregister_user_memory.isra.25+0x2d/0x80
>    vmci_qp_broker_unmap+0x191/0x320
>    ? vmci_host_do_alloc_queuepair.isra.9+0x1c0/0x1c0
>    vmci_host_unlocked_ioctl+0x59f/0xd50
>    ? do_vfs_ioctl+0x14b/0xa10
>    ? tomoyo_file_ioctl+0x28/0x30
>    ? vmci_host_do_alloc_queuepair.isra.9+0x1c0/0x1c0
>    __x64_sys_ioctl+0xea/0x120
>    do_syscall_64+0x34/0xb0
>    entry_SYSCALL_64_after_hwframe+0x44/0xae
>
> When a queue pair is created by the following call, it will not
> register the user memory if the page_store is NULL, and the
> entry->state will be set to VMCIQPB_CREATED_NO_MEM.
>
> vmci_host_unlocked_ioctl
>    vmci_host_do_alloc_queuepair
>      vmci_qp_broker_alloc
>        qp_broker_alloc
>          qp_broker_create // set entry->state = VMCIQPB_CREATED_NO_MEM;
>
> When unmapping this queue pair, qp_host_unregister_user_memory() will
> be called to unregister the non-existent user memory, which will
> result in a null pointer reference. It will also change
> VMCIQPB_CREATED_NO_MEM to VMCIQPB_CREATED_MEM, which should not be
> present in this operation.
>
> If the qp broker has mem, there no need to register or unregister
> the user memory when mapping or unmapping the qp broker.

If the qp broker has mem, there no need to register the user memory when mapping the qp broker.
If the qp broker has no mem, there no need to unregister the user memory when ummapping the qp broker.

> Fixes: 06164d2b72aa ("VMCI: queue pairs implementation.")
> Reported-by: Hulk Robot <hulkci@huawei.com>
> Signed-off-by: Wang Hai <wanghai38@huawei.com>
> ---
>   drivers/misc/vmw_vmci/vmci_queue_pair.c | 6 ++++--
>   1 file changed, 4 insertions(+), 2 deletions(-)
>
> diff --git a/drivers/misc/vmw_vmci/vmci_queue_pair.c b/drivers/misc/vmw_vmci/vmci_queue_pair.c
> index 880c33ab9f47..0c6fb4c0d5ac 100644
> --- a/drivers/misc/vmw_vmci/vmci_queue_pair.c
> +++ b/drivers/misc/vmw_vmci/vmci_queue_pair.c
> @@ -2243,7 +2243,8 @@ int vmci_qp_broker_map(struct vmci_handle handle,
>   
>   	result = VMCI_SUCCESS;
>   
> -	if (context_id != VMCI_HOST_CONTEXT_ID) {
> +	if (context_id != VMCI_HOST_CONTEXT_ID &&
> +	    QPBROKERSTATE_HAS_MEM(entry)) {
>   		struct vmci_qp_page_store page_store;
>   

should be:
-	if (context_id != VMCI_HOST_CONTEXT_ID) {
+	if (context_id != VMCI_HOST_CONTEXT_ID &&
+	    !QPBROKERSTATE_HAS_MEM(entry)) {

>   		page_store.pages = guest_mem;
> @@ -2350,7 +2351,8 @@ int vmci_qp_broker_unmap(struct vmci_handle handle,
>   		goto out;
>   	}
>   
> -	if (context_id != VMCI_HOST_CONTEXT_ID) {
> +	if (context_id != VMCI_HOST_CONTEXT_ID &&
> +	    QPBROKERSTATE_HAS_MEM(entry)) {
>   		qp_acquire_queue_mutex(entry->produce_q);
>   		result = qp_save_headers(entry);
>   		if (result < VMCI_SUCCESS)

      reply	other threads:[~2021-08-05  2:05 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-08-04 13:48 Wang Hai
2021-08-05  2:05 ` wanghai (M) [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=4e66f922-c081-0b00-d77e-fb1e1d5e9d49@huawei.com \
    --to=wanghai38@huawei.com \
    --cc=acking@vmware.com \
    --cc=arnd@arndb.de \
    --cc=dtor@vmware.com \
    --cc=georgezhang@vmware.com \
    --cc=gregkh@linuxfoundation.org \
    --cc=jhansen@vmware.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=pv-drivers@vmware.com \
    --cc=vdasa@vmware.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®