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 3AD3D4262B; Mon, 25 Sep 2023 10:15:23 +0200 (CEST) Received: from mails.dpdk.org (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id 0FA93402CC; Mon, 25 Sep 2023 10:15:23 +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 6A30A402B7 for ; Mon, 25 Sep 2023 10:15:21 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1695629720; 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=ropogNGknf92WODQJ+8ACwx5CZL4h5N/SqY6OhM2QE4=; b=YfDYCfqweMEG6ZBy/Mi0erLBEWqhBFa1cv8Brh8daJpdNaoGxO1tDXTpxdDj9o00He9I4w jud5L2Txy7Q/CCH3bj4IOGagzG40Tc0Mv0e0w+RJwzq5M8ya95AgT8RmAC9Upy8w2fFrPd cGQgXwCPSrcLj/4pqtkqWizczSBWgbY= 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-99-44O26U_uNSuyCFdaG4eEeA-1; Mon, 25 Sep 2023 04:15:16 -0400 X-MC-Unique: 44O26U_uNSuyCFdaG4eEeA-1 Received: from smtp.corp.redhat.com (int-mx08.intmail.prod.int.rdu2.redhat.com [10.11.54.8]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id BF5B6101AA6E; Mon, 25 Sep 2023 08:15:15 +0000 (UTC) Received: from [10.39.208.35] (unknown [10.39.208.35]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 15193C15BB8; Mon, 25 Sep 2023 08:15:14 +0000 (UTC) Message-ID: <7136f05c-023b-fda5-44ee-8a26b0c8e548@redhat.com> Date: Mon, 25 Sep 2023 10:15:13 +0200 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:102.0) Gecko/20100101 Thunderbird/102.13.0 To: Li Feng , Chenbo Xia Cc: dev@dpdk.org References: <20230912074217.2480397-1-fengli@smartx.com> From: Maxime Coquelin Subject: Re: [PATCH v3] vhost: avoid potential null pointer access In-Reply-To: <20230912074217.2480397-1-fengli@smartx.com> X-Scanned-By: MIMEDefang 3.1 on 10.11.54.8 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 On 9/12/23 09:42, Li Feng wrote: > If the user calls rte_vhost_vring_call() on a ring that has been > invalidated, we will encounter SEGV. > > We should check the pointer firstly before accessing it. > > Signed-off-by: Li Feng > --- > v2 -> v3: > - Also fix the rte_vhost_vring_call_nonblock. > > v1 -> v2: > - Fix rebase error. > > > > lib/vhost/vhost.c | 14 ++++++++------ > lib/vhost/vhost.h | 12 ++++++++++-- > 2 files changed, 18 insertions(+), 8 deletions(-) Thanks for posting the fix, the segmentation fault may indeed happen when injecting IRQ from the app directly using the Vhost API. It cannot happen when vhost_vring_call() is calle directly from rte_enqueue_burst/rte_dequeue_burst though. so I think below patch would be better: diff --git a/lib/vhost/vhost.c b/lib/vhost/vhost.c index eb6309b681..733e0ab289 100644 --- a/lib/vhost/vhost.c +++ b/lib/vhost/vhost.c @@ -1341,6 +1341,9 @@ rte_vhost_vring_call(int vid, uint16_t vring_idx) rte_rwlock_read_lock(&vq->access_lock); + if (unlikely(!vq->access_ok)) + return -1; + if (vq_is_packed(dev)) vhost_vring_call_packed(dev, vq); else @@ -1371,6 +1374,9 @@ rte_vhost_vring_call_nonblock(int vid, uint16_t vring_idx) if (rte_rwlock_read_trylock(&vq->access_lock)) return -EAGAIN; + if (unlikely(!vq->access_ok)) + return -1; + if (vq_is_packed(dev)) vhost_vring_call_packed(dev, vq); else Do you confirm that fixes your issue? Thanks, Maxime