Received: by 2002:a05:6a11:4021:0:0:0:0 with SMTP id ky33csp2319430pxb; Mon, 20 Sep 2021 18:42:32 -0700 (PDT) X-Google-Smtp-Source: ABdhPJy76Wx12rJcGxbhSiijY96jhj4dYVGw1BgVUc48ODzVaoU2KF9k+KWdCZNEHSQ461hHC9Ed X-Received: by 2002:a92:d2ca:: with SMTP id w10mr19205041ilg.222.1632188551903; Mon, 20 Sep 2021 18:42:31 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1632188551; cv=none; d=google.com; s=arc-20160816; b=qYdUEROFbEXBOj0CejLW296Hyl+F/rCQvJs/kg4P1QZ0/JJfyVLB5XXlJlwNHRWPXX CRA3CAXZCSHMQD//eD+s/5iQ/ZUOIgHWYTIPE4RArwBlQm40MGGQYbIsFXDRa8BdERFq srzfbAwSrb+J/Eud9ZRfhKvgBF+y+UB3ddrtVzXiPgFmTrvRrH33OUADC833rY+F/sS+ IKogHF7dSRm5VDsugEkDrkUAOcvUOCfjL3viXFJhltlACE8gIWPJ5vJoX8k3c6NsB9Yi QqqwPZ7UOEd/RZh5XDJhFqEq8jLSBNPIRFlaWe7AGcF36ZiK4PI3HRUNr21QXL4Osvn0 1jKw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=MQapg+Twx6wgFet4zRLDGO4Urhd9wU20AmWGgPl9drU=; b=Ig1uD3i7OQ+aAW5ypd0sGuioR0KnBH0gdKY9pwAjvxWfP51fXeXdxOcEZrjAhi7Kr+ 1tBWGiABPTlS1GYcjE6zkeXUD9SjXIxoG5bDgA9kxFXH9wlSomPJ1lWCDbZztx3eek9U XLOFNFuM8nCfzoQirsPo7/9ed0pB0ZbOyD6I8Xf88zUfqGT3qQN0J63scL+mHCu+6vZG b4sMSgwe81oPh4yXlDHp3fjgjwYtEhJZnymgqzHVFXevupDNRfvYhApoIWzgt7JYUP9z SOnQA8gUdppok0ITyQp98jVnKR3C8yIeKiraZcL7d4gOWzyJmvs76nbkdQ+vMk1C/xNv 0dPg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=UPNYZtJm; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id k3si7049274ilu.165.2021.09.20.18.42.21; Mon, 20 Sep 2021 18:42:31 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=UPNYZtJm; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S244237AbhITQuy (ORCPT + 99 others); Mon, 20 Sep 2021 12:50:54 -0400 Received: from mail.kernel.org ([198.145.29.99]:36518 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230322AbhITQtX (ORCPT ); Mon, 20 Sep 2021 12:49:23 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id B433761213; Mon, 20 Sep 2021 16:47:55 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1632156476; bh=xf0YbatEnMmfTs+5VSBVKKe7pFah5K7ZriwPi85SFwY=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=UPNYZtJmRu/6lvcoI/eXBZa9wir1CJpauq1umKEMhk9bm+/TdR4Kl5ETCI/2onfbk +yS2HXAik5CctOn4JvhMhdpLgK9CTCQy/c7KnXYnEukdRBqouuUU+as9ofkmTDK2M4 7WTRMVxgb+J4iDrN1qTW/E2EwKGGYHb/yYWNaYjA= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Hulk Robot , Jorgen Hansen , Wang Hai Subject: [PATCH 4.4 076/133] VMCI: fix NULL pointer dereference when unmapping queue pair Date: Mon, 20 Sep 2021 18:42:34 +0200 Message-Id: <20210920163915.132977555@linuxfoundation.org> X-Mailer: git-send-email 2.33.0 In-Reply-To: <20210920163912.603434365@linuxfoundation.org> References: <20210920163912.603434365@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Wang Hai commit a30dc6cf0dc51419021550152e435736aaef8799 upstream. 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. Only when the qp broker has mem, it can unregister the user memory when unmapping the qp broker. Only when the qp broker has no mem, it can register the user memory when mapping the qp broker. Fixes: 06164d2b72aa ("VMCI: queue pairs implementation.") Cc: stable Reported-by: Hulk Robot Reviewed-by: Jorgen Hansen Signed-off-by: Wang Hai Link: https://lore.kernel.org/r/20210818124845.488312-1-wanghai38@huawei.com Signed-off-by: Greg Kroah-Hartman --- drivers/misc/vmw_vmci/vmci_queue_pair.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) --- a/drivers/misc/vmw_vmci/vmci_queue_pair.c +++ b/drivers/misc/vmw_vmci/vmci_queue_pair.c @@ -2344,7 +2344,8 @@ int vmci_qp_broker_map(struct vmci_handl is_local = entry->qp.flags & VMCI_QPFLAG_LOCAL; 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; page_store.pages = guest_mem; @@ -2454,7 +2455,8 @@ int vmci_qp_broker_unmap(struct vmci_han is_local = entry->qp.flags & VMCI_QPFLAG_LOCAL; - 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)