From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mails.dpdk.org (mails.dpdk.org [217.70.189.124]) by inbox.dpdk.org (Postfix) with ESMTP id 9E206A0548; Wed, 1 Jun 2022 09:58:24 +0200 (CEST) Received: from [217.70.189.124] (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id 724D740A84; Wed, 1 Jun 2022 09:58:24 +0200 (CEST) Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by mails.dpdk.org (Postfix) with ESMTP id 7D2D840A84 for ; Wed, 1 Jun 2022 09:58:23 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1654070303; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=DzGoYFEzhCIBCw7Zk4xBkzrEv9sg/+PlF1R5npRM3Zg=; b=fOj1oSw+gg3RXYhOKoHrlJHDNn+XD3+6RgMZtc3X4CdRVK4+qEI7PMh9SFHGMolpwOWYbB 3CXkfifZfTysTh5kgeFLbAOVKkIiGDPgNdo5EpnbN/g2Yv5ovSRyVhamutn9N8Y2Dsd1OG ymKSWNcHVoJMYOSkjsIt/tZGBWlHjlU= Received: from mimecast-mx02.redhat.com (mimecast-mx02.redhat.com [66.187.233.88]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-491-kDFcc_RhMWa1avCR6m5Atw-1; Wed, 01 Jun 2022 03:58:20 -0400 X-MC-Unique: kDFcc_RhMWa1avCR6m5Atw-1 Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.rdu2.redhat.com [10.11.54.2]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id C87CC811E81; Wed, 1 Jun 2022 07:58:19 +0000 (UTC) Received: from [10.39.208.26] (unknown [10.39.208.26]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 02094414A7E7; Wed, 1 Jun 2022 07:58:18 +0000 (UTC) Message-ID: <969db8c8-7e9e-755f-a436-bc230a591905@redhat.com> Date: Wed, 1 Jun 2022 09:58:17 +0200 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:91.0) Gecko/20100101 Thunderbird/91.9.0 Subject: Re: [PATCH] vhost: fix null pointer dereference To: Jiayu Hu Cc: dev , dpdk stable , David Marchand References: <20220328020754.1155063-1-jiayu.hu@intel.com> From: Maxime Coquelin In-Reply-To: X-Scanned-By: MIMEDefang 2.84 on 10.11.54.2 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=maxime.coquelin@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Language: en-US Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit X-BeenThere: dev@dpdk.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: DPDK patches and discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: dev-bounces@dpdk.org HI Jiayu, On 3/28/22 09:04, David Marchand wrote: > On Mon, Mar 28, 2022 at 4:08 AM Jiayu Hu wrote: >> >> NULL check for vq->async must be protected by lock. Otherwise, it is >> possible that the data plane thread dereferences vq->async with NULL >> value, since the control plane thread is freeing vq->async. >> >> Fixes: ee8024b3d4ad (vhost: move async data in dedicated structure) >> Cc: stable@dpdk.org >> >> Signed-off-by: Jiayu Hu >> --- >> lib/vhost/vhost.c | 6 +++--- >> 1 file changed, 3 insertions(+), 3 deletions(-) >> >> diff --git a/lib/vhost/vhost.c b/lib/vhost/vhost.c >> index bc88148347..7f60c2824f 100644 >> --- a/lib/vhost/vhost.c >> +++ b/lib/vhost/vhost.c >> @@ -1887,9 +1887,6 @@ rte_vhost_async_get_inflight(int vid, uint16_t queue_id) >> if (vq == NULL) >> return ret; >> >> - if (!vq->async) >> - return ret; >> - >> if (!rte_spinlock_trylock(&vq->access_lock)) { >> VHOST_LOG_CONFIG(DEBUG, >> "(%s) failed to check in-flight packets. virtqueue busy.\n", >> @@ -1897,6 +1894,9 @@ rte_vhost_async_get_inflight(int vid, uint16_t queue_id) >> return ret; >> } >> >> + if (!vq->async) >> + return ret; > > Lock is still taken at this point. > > FYI, I'll post a series to instrument locks in vhost, soon. Could you please send a v2 which does not return with the lock taken? >> + >> ret = vq->async->pkts_inflight_n; >> rte_spinlock_unlock(&vq->access_lock); >> > > Thanks, Maxime