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 E7B99A034C; Tue, 2 Aug 2022 02:49:49 +0200 (CEST) Received: from [217.70.189.124] (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id 44A994281C; Tue, 2 Aug 2022 02:49:43 +0200 (CEST) Received: from smtp-out1.suse.de (smtp-out1.suse.de [195.135.220.28]) by mails.dpdk.org (Postfix) with ESMTP id CD2D1400D7 for ; Tue, 2 Aug 2022 02:49:40 +0200 (CEST) Received: from imap2.suse-dmz.suse.de (imap2.suse-dmz.suse.de [192.168.254.74]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-521) server-digest SHA512) (No client certificate requested) by smtp-out1.suse.de (Postfix) with ESMTPS id B11AB33E8C; Tue, 2 Aug 2022 00:49:40 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_rsa; t=1659401380; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=XLZnMjlOh2cyF/KD+SKZsd+F4Gahhz9WvO/X4H2+PE0=; b=2CM+4/FmS+PIO8HQR30qbGkVG++SWkHWDHnrua+CUeqzOn5JHxoq8zdfJbccXNbrem3AET ukJ0sHa6jWk5Opzsb6x2P+eiSOE6coz/50aX+AHV0bYiofrxUDmXE4TRCSC1e/0UQD6q5r PXSxynbTmE1qoinNIjTsbJJMgiLvKhc= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_ed25519; t=1659401380; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=XLZnMjlOh2cyF/KD+SKZsd+F4Gahhz9WvO/X4H2+PE0=; b=aus6G+WUwqFJMGtnmBaq3sAq1JA2CDKp4ZxWNqJWUXZS9zuNS6zjYkDOOib8zsW2/fQSX9 iF76k6Ysu3QFm9BQ== Received: from imap2.suse-dmz.suse.de (imap2.suse-dmz.suse.de [192.168.254.74]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-521) server-digest SHA512) (No client certificate requested) by imap2.suse-dmz.suse.de (Postfix) with ESMTPS id 763E913A99; Tue, 2 Aug 2022 00:49:40 +0000 (UTC) Received: from dovecot-director2.suse.de ([192.168.254.65]) by imap2.suse-dmz.suse.de with ESMTPSA id UMUuG6R06GLLMwAAMHmgww (envelope-from ); Tue, 02 Aug 2022 00:49:40 +0000 From: Claudio Fontana To: Maxime Coquelin , Chenbo Xia Cc: dev@dpdk.org, Claudio Fontana Subject: [PATCH v3 2/2] vhost: improve error handling in desc_to_mbuf Date: Tue, 2 Aug 2022 02:49:38 +0200 Message-Id: <20220802004938.23670-3-cfontana@suse.de> X-Mailer: git-send-email 2.26.2 In-Reply-To: <20220802004938.23670-1-cfontana@suse.de> References: <20220802004938.23670-1-cfontana@suse.de> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit 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 check when increasing vec_idx that it is still valid in the (buf_len < dev->vhost_hlen) case too. Tested-by: Claudio Fontana Signed-off-by: Claudio Fontana --- lib/vhost/virtio_net.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/lib/vhost/virtio_net.c b/lib/vhost/virtio_net.c index eb19e54c2b..20ed951979 100644 --- a/lib/vhost/virtio_net.c +++ b/lib/vhost/virtio_net.c @@ -2704,12 +2704,15 @@ desc_to_mbuf(struct virtio_net *dev, struct vhost_virtqueue *vq, if (unlikely(buf_len < dev->vhost_hlen)) { buf_offset = dev->vhost_hlen - buf_len; vec_idx++; + if (unlikely(vec_idx >= nr_vec)) + goto error; buf_addr = buf_vec[vec_idx].buf_addr; buf_iova = buf_vec[vec_idx].buf_iova; buf_len = buf_vec[vec_idx].buf_len; buf_avail = buf_len - buf_offset; } else if (buf_len == dev->vhost_hlen) { - if (unlikely(++vec_idx >= nr_vec)) + vec_idx++; + if (unlikely(vec_idx >= nr_vec)) goto error; buf_addr = buf_vec[vec_idx].buf_addr; buf_iova = buf_vec[vec_idx].buf_iova; -- 2.26.2