From patchwork Thu Oct 1 10:22:44 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Chas Williams <3chas3@gmail.com> X-Patchwork-Id: 79460 X-Patchwork-Delegate: thomas@monjalon.net Return-Path: X-Original-To: patchwork@inbox.dpdk.org Delivered-To: patchwork@inbox.dpdk.org Received: from dpdk.org (dpdk.org [92.243.14.124]) by inbox.dpdk.org (Postfix) with ESMTP id 05694A04B5; Thu, 1 Oct 2020 12:36:53 +0200 (CEST) Received: from [92.243.14.124] (localhost [127.0.0.1]) by dpdk.org (Postfix) with ESMTP id 9136C1DAFE; Thu, 1 Oct 2020 12:22:53 +0200 (CEST) Received: from mail-qt1-f194.google.com (mail-qt1-f194.google.com [209.85.160.194]) by dpdk.org (Postfix) with ESMTP id EBF831DAF8 for ; Thu, 1 Oct 2020 12:22:50 +0200 (CEST) Received: by mail-qt1-f194.google.com with SMTP id y11so3832879qtn.9 for ; Thu, 01 Oct 2020 03:22:50 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=TfhGEOwCD8FHLioOVqBXNZ7zon0lRTk22WIVFBrFGkI=; b=o6xScIeSd5RRaHf/UCQoWTwddKiD/T7rPlLRtWxwNy9jS6g+iKHpoF23v1Y3bReL2z SbXB8TDE+WCo3k8Uo6+o/nwART5nJgPXcjqeEfEl6keXQvSMdapKLsbMjhqUobqYuH46 6Z5M4mw5xKBX2Da2d/Ruwu1d8uPmsOq8w4yYw7i2WGSLV40lRLC8tOm/XQuZekKCF8Sd y/xVYFEWNSNGB9zL2xRR2nBI/YFb+L5dI3braWuUq2ZcSUD0ZqdrYJuw+LDMuJ8qa2OU LdBBeW4ZcYldw588nZm+D8gI11stbXO4GyJRe3m8C5Ow+pKuguDHSc/In2df9U5jsvF+ t1hQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=TfhGEOwCD8FHLioOVqBXNZ7zon0lRTk22WIVFBrFGkI=; b=CBBZHYYCoWugiK0jAeJXxQRNvDwx9AlVLObgXQPQHfzNfAxQwKXxuyFAqLHNLEtBBy a3Prl+qYsmadv3n2cmSdTRaUzk7+TrlDyVX7aLRwNGMnaZoJ+JbH/wPcBCS/V2LK8CU0 RfCMGXVSVpZk4Drxa/9c0s1oT9XQWY3seEhjCKXWCHqDzg8Qfe9n9/1tv5+A7FGJC6yC /pL6hmO1/N7IpvM2LNRUnl9IQgbvIuohK5xOll0BBUzqRkgHlCw5oxsKgmBjtkhuxVMY NPnryiTXdt7urbUcsi7nMl1vdwstyWBUHVjNgkPc22zdW0RWkj4plzGLpPJvKxUUWKhT XUOw== X-Gm-Message-State: AOAM5307B8b6u6aXRQstXAiQubizZNaoG6X7swmo1rddoEHfPULCaqNJ QL5KGUrhSGkXFcSElJSweMC4tDimT4J10g== X-Google-Smtp-Source: ABdhPJyHdvcujaaJ7nkuI9irwxpm1G/BJHExk8JNKLFiIYNYKzCwKRp4fvFXOFOy5+Zv5xuAefL/dg== X-Received: by 2002:ac8:1a7b:: with SMTP id q56mr6736136qtk.56.1601547770297; Thu, 01 Oct 2020 03:22:50 -0700 (PDT) Received: from monolith.fios-router.home (pool-96-255-60-31.washdc.fios.verizon.net. [96.255.60.31]) by smtp.googlemail.com with ESMTPSA id q185sm5662399qke.25.2020.10.01.03.22.49 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 01 Oct 2020 03:22:49 -0700 (PDT) From: Chas Williams <3chas3@gmail.com> To: dev@dpdk.org Cc: olivier.matz@6wind.com, Chas Williams <3chas3@gmail.com> Date: Thu, 1 Oct 2020 06:22:44 -0400 Message-Id: <20201001102245.326223-1-3chas3@gmail.com> X-Mailer: git-send-email 2.26.2 In-Reply-To: <20200928153219.285343-1-3chas3@gmail.com> References: <20200928153219.285343-1-3chas3@gmail.com> MIME-Version: 1.0 Subject: [dpdk-dev] [PATCH v2 1/2] net: check that seg is valid before dereference X-BeenThere: dev@dpdk.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: DPDK patches and discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: dev-bounces@dpdk.org Sender: "dev" If the overall pkt_len and segment lengths are out of agreement, it is possible for the seg to be NULL after the loop. Add assert to check this condition in debug builds. Otherwise, return failure. Fixes: c442fed81bb9 ("net: add function to calculate checksum in mbuf") Signed-off-by: Chas Williams <3chas3@gmail.com> --- lib/librte_net/rte_ip.h | 3 +++ 1 file changed, 3 insertions(+) diff --git a/lib/librte_net/rte_ip.h b/lib/librte_net/rte_ip.h index fcd1eb342..b2bb5d7b9 100644 --- a/lib/librte_net/rte_ip.h +++ b/lib/librte_net/rte_ip.h @@ -225,6 +225,9 @@ rte_raw_cksum_mbuf(const struct rte_mbuf *m, uint32_t off, uint32_t len, break; off -= seglen; } + RTE_ASSERT(seg != NULL); + if (seg == NULL) + return -1; seglen -= off; buf = rte_pktmbuf_mtod_offset(seg, const char *, off); if (seglen >= len) { From patchwork Thu Oct 1 10:22:45 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Chas Williams <3chas3@gmail.com> X-Patchwork-Id: 79461 X-Patchwork-Delegate: thomas@monjalon.net Return-Path: X-Original-To: patchwork@inbox.dpdk.org Delivered-To: patchwork@inbox.dpdk.org Received: from dpdk.org (dpdk.org [92.243.14.124]) by inbox.dpdk.org (Postfix) with ESMTP id EF484A04B5; Thu, 1 Oct 2020 12:37:10 +0200 (CEST) Received: from [92.243.14.124] (localhost [127.0.0.1]) by dpdk.org (Postfix) with ESMTP id EC0D91DB0E; Thu, 1 Oct 2020 12:22:54 +0200 (CEST) Received: from mail-qv1-f49.google.com (mail-qv1-f49.google.com [209.85.219.49]) by dpdk.org (Postfix) with ESMTP id 067921DB02 for ; Thu, 1 Oct 2020 12:22:53 +0200 (CEST) Received: by mail-qv1-f49.google.com with SMTP id j10so2602090qvk.11 for ; Thu, 01 Oct 2020 03:22:52 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=QsNSmj8dHOEqvPCitDXTJm/kWCYlAG7sGv/g1y2H5uc=; b=MhVVFkV7ox/AFi8/EL7IreiD3Dbzld126PHa2iKEDoJWb3Bxmm3wOn9R4O/iiDq7A7 i0KjXPpxrpCdTZSTjTOWe7BQSPGpQgQdatOb8GYSzDQyrUmGnHdokVj3U44Z/n9eX7fY y4K7bcIyPU4EIju/HbT1aXD+343IuH6SkqGiW05iD+fPUBEUWIlA5CZu61sk2wEOGcxN M1ERy2dPd13BVgocWTZW8QvClz34Ql+4btIgvk9hKurkxWj+MornWjj5ms9IevTc7byp 2pdRzdSX8ySt6bFGvMQtt5dHELOG6sObR0LlUeqCDfwn9gonvz/c68XOkFn6rmUvsHdm Namg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=QsNSmj8dHOEqvPCitDXTJm/kWCYlAG7sGv/g1y2H5uc=; b=h/JBfop4bWquwelcNPrVWCczBmogK0v9xrHXcCR7yOqH5TiHCsXd52wQ0nDwgWmDN/ 9jG/MzWlg6pjEdkto8yYklJIg/Q+JvPFJmzcWovgu0Xff5H2KsOFbd+W1ibipKAB/Bm1 38G2W2QzEg5+SB8ybaYztn2++CH4FH/rd5RBwEljCYEfmJcCehC42JoKr6RSnHiRFSgA W4vOLdG9ydAhUL7laGR4/G9Z84DFQTua0qhZiYE6vac0vwBrRVvyqtfyEREj69IHEuRU A4xw0Zlw/XDRWWNHK/qF/H1E+P9dgBjhBJThxyj/IoyYE072t1YlhxAJGkmp+CgOeFqa qCXg== X-Gm-Message-State: AOAM532Zj6aBMUd4XotyvqqeAPZMJHkp15ghI4hAfJI/rJOTWEEnAE8l YGpKhJrqg+5rZytpyV74tXBEWlP+ZTKVRA== X-Google-Smtp-Source: ABdhPJylZR8LvD/JuDjX0dnYBdgKzQ70y8iBQqn2SVMttGl8BoCUUJUTJJhfqyoskH1MxUN9C+UniQ== X-Received: by 2002:a0c:b60c:: with SMTP id f12mr7129606qve.2.1601547772366; Thu, 01 Oct 2020 03:22:52 -0700 (PDT) Received: from monolith.fios-router.home (pool-96-255-60-31.washdc.fios.verizon.net. [96.255.60.31]) by smtp.googlemail.com with ESMTPSA id q185sm5662399qke.25.2020.10.01.03.22.51 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 01 Oct 2020 03:22:51 -0700 (PDT) From: Chas Williams <3chas3@gmail.com> To: dev@dpdk.org Cc: olivier.matz@6wind.com, Chas Williams <3chas3@gmail.com> Date: Thu, 1 Oct 2020 06:22:45 -0400 Message-Id: <20201001102245.326223-2-3chas3@gmail.com> X-Mailer: git-send-email 2.26.2 In-Reply-To: <20201001102245.326223-1-3chas3@gmail.com> References: <20200928153219.285343-1-3chas3@gmail.com> <20201001102245.326223-1-3chas3@gmail.com> MIME-Version: 1.0 Subject: [dpdk-dev] [PATCH v2 2/2] net/virtio: check return from rte_raw_cksum_mbuf X-BeenThere: dev@dpdk.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: DPDK patches and discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: dev-bounces@dpdk.org Sender: "dev" rte_raw_cksum_mbuf can fail, so we should check to see if it has. If so, return with an error. Fixes: 96cb6711939e ("net/virtio: support Rx checksum offload") Signed-off-by: Chas Williams <3chas3@gmail.com> Reviewed-by: Maxime Coquelin --- drivers/net/virtio/virtio_rxtx.c | 5 +++-- drivers/net/virtio/virtio_rxtx_packed_avx.c | 5 +++-- 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/drivers/net/virtio/virtio_rxtx.c b/drivers/net/virtio/virtio_rxtx.c index 0ade35215..019187bf9 100644 --- a/drivers/net/virtio/virtio_rxtx.c +++ b/drivers/net/virtio/virtio_rxtx.c @@ -910,9 +910,10 @@ virtio_rx_offload(struct rte_mbuf *m, struct virtio_net_hdr *hdr) */ uint16_t csum = 0, off; - rte_raw_cksum_mbuf(m, hdr->csum_start, + if (rte_raw_cksum_mbuf(m, hdr->csum_start, rte_pktmbuf_pkt_len(m) - hdr->csum_start, - &csum); + &csum) < 0) + return -EINVAL; if (likely(csum != 0xffff)) csum = ~csum; off = hdr->csum_offset + hdr->csum_start; diff --git a/drivers/net/virtio/virtio_rxtx_packed_avx.c b/drivers/net/virtio/virtio_rxtx_packed_avx.c index 6a8214725..67a55abce 100644 --- a/drivers/net/virtio/virtio_rxtx_packed_avx.c +++ b/drivers/net/virtio/virtio_rxtx_packed_avx.c @@ -328,9 +328,10 @@ virtio_vec_rx_offload(struct rte_mbuf *m, struct virtio_net_hdr *hdr) */ uint16_t csum = 0, off; - rte_raw_cksum_mbuf(m, hdr->csum_start, + if (rte_raw_cksum_mbuf(m, hdr->csum_start, rte_pktmbuf_pkt_len(m) - hdr->csum_start, - &csum); + &csum) < 0) + return -1; if (likely(csum != 0xffff)) csum = ~csum; off = hdr->csum_offset + hdr->csum_start;