From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from dpdk.org (dpdk.org [92.243.14.124]) by inbox.dpdk.org (Postfix) with ESMTP id 686AFA04B1; Tue, 29 Sep 2020 22:20:07 +0200 (CEST) Received: from [92.243.14.124] (localhost [127.0.0.1]) by dpdk.org (Postfix) with ESMTP id D4B431DA97; Tue, 29 Sep 2020 22:20:04 +0200 (CEST) Received: from mail-io1-f68.google.com (mail-io1-f68.google.com [209.85.166.68]) by dpdk.org (Postfix) with ESMTP id 9C28D1DA84 for ; Tue, 29 Sep 2020 22:20:02 +0200 (CEST) Received: by mail-io1-f68.google.com with SMTP id j2so6227846ioj.7 for ; Tue, 29 Sep 2020 13:20:02 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=cE9diRJOcwb/9ha12UUVDeqDoJfFBmIEhZSfvFmfkKk=; b=UjaVRexJSKg0SI8tsSZUyrYS9LWf9iGKotfqHON7+rWSGqNq5K11r886QwwkM+bh4p 8dhaCjhGHIHRatNXPaVin+td2BX1p7v0VxE7TXJ5qBvwlyI6C7mcLgdoqjBJ6q+rGHY3 v4tzmtcviL2je9zEgvFDE7EH9JB0UE5ByU1JvEmmG3QV7ysQy9BKFQgq6qbEzwdxrvEu LKATFRKXG+i65eh7SrT9gzpQtF1oixGMqH8EcHv6opGZBVea46wDaHSKEKH+SZD1zAN5 +U0QDn2NSJ56E1BFuRz4xS0YexnnBsEXHejg0lM84W9H9jCBtiGWRXS+psjbLP80Z7zt VReA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=cE9diRJOcwb/9ha12UUVDeqDoJfFBmIEhZSfvFmfkKk=; b=LK+hLUf0KymzZHnrcc+TaPcr6eyzxJpxLZK4k52SzgTdQQdK6P9L46jGCipjWiYsjw wT5vhqMPBHFH8Na+xcmh6rC9odn4uE+0KoE3/dRbc8zW+Tb5fDuw08U1JIhLeHcwCFiq ziZCQrRk8NgYcdfEathgshvwdncEZsSaLAPF0FAwQmEkBasUlszD1hKHAPFji8OUH3oP uHO4ur5XxeKGjo+JGDth8LiLy9GQaTQOreLjDHjv0rpUnmzf8XAYSy1g8/xCcVfgasL/ /gHAW4ayNSR6xm7awdcKOg7CUzyDpj4GTNRdX7O3dXaJTifk5SgqrPXosoo8Q/N6GABS l+hw== X-Gm-Message-State: AOAM532u6oWIYJ0sWODD1pHf8risuW/f5JoYYN/w28Ruqiu/SAl6wZcQ vp8yUcPbRIY3UQ5UQQkNWzUDGr1is1auiDoo1Vo= X-Google-Smtp-Source: ABdhPJxVY0SjeRYtshjpvDi4xcubBskTG6dHffaCGEevU+FQcjE/uLWXmKfck0rnRtHP8wTra28NjgJXT0iShvK6YUc= X-Received: by 2002:a05:6638:2185:: with SMTP id s5mr4577519jaj.120.1601410800963; Tue, 29 Sep 2020 13:20:00 -0700 (PDT) MIME-Version: 1.0 References: <20200928153219.285343-1-3chas3@gmail.com> <34EFBCA9F01B0748BEB6B629CE643AE60DA7D32B@DGGEMM533-MBX.china.huawei.com> In-Reply-To: <34EFBCA9F01B0748BEB6B629CE643AE60DA7D32B@DGGEMM533-MBX.china.huawei.com> From: Chas Williams <3chas3@gmail.com> Date: Tue, 29 Sep 2020 16:19:50 -0400 Message-ID: To: wangyunjian , "dev@dpdk.org" Cc: "olivier.matz@6wind.com" , xudingke Content-Type: text/plain; charset="UTF-8" Subject: Re: [dpdk-dev] [PATCH] 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" On 9/28/20 11:01 PM, wangyunjian wrote: >> -----Original Message----- >> From: dev [mailto:dev-bounces@dpdk.org] On Behalf Of Chas Williams >> Sent: Monday, September 28, 2020 11:32 PM >> To: dev@dpdk.org >> Cc: olivier.matz@6wind.com; Chas Williams <3chas3@gmail.com> >> Subject: [dpdk-dev] [PATCH] net: check that seg is valid before dereference >> >> 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. >> >> Fixes: c442fed81bb9 ("net: add function to calculate checksum in mbuf") >> >> Signed-off-by: Chas Williams <3chas3@gmail.com> >> --- >> lib/librte_net/rte_ip.h | 1 + >> 1 file changed, 1 insertion(+) >> >> diff --git a/lib/librte_net/rte_ip.h b/lib/librte_net/rte_ip.h index >> fcd1eb342..6b3e4cdda 100644 >> --- a/lib/librte_net/rte_ip.h >> +++ b/lib/librte_net/rte_ip.h >> @@ -225,6 +225,7 @@ rte_raw_cksum_mbuf(const struct rte_mbuf *m, >> uint32_t off, uint32_t len, >> break; >> off -= seglen; >> } >> + RTE_ASSERT(seg != NULL); > > Is it better to return an error code? Maybe. However, to get into this state your mbuf chain is already badly broken. Personally, I would prefer an immediate failure in the application so I can track down the source of this error. No one is checking the return code now, so returning one wouldn't really help unless I also fix the callers. Lastly, would everyone be happy with an extra branch in the virtio RX path? > >> seglen -= off; >> buf = rte_pktmbuf_mtod_offset(seg, const char *, off); >> if (seglen >= len) { >> -- >> 2.26.2 >