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 920EBA0573; Wed, 4 Mar 2020 17:15:21 +0100 (CET) Received: from [92.243.14.124] (localhost [127.0.0.1]) by dpdk.org (Postfix) with ESMTP id D801A2C4F; Wed, 4 Mar 2020 17:15:20 +0100 (CET) Received: from mail-pg1-f194.google.com (mail-pg1-f194.google.com [209.85.215.194]) by dpdk.org (Postfix) with ESMTP id C1C4D2C02 for ; Wed, 4 Mar 2020 17:15:19 +0100 (CET) Received: by mail-pg1-f194.google.com with SMTP id t3so1218837pgn.1 for ; Wed, 04 Mar 2020 08:15:19 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=networkplumber-org.20150623.gappssmtp.com; s=20150623; h=date:from:to:cc:subject:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=aobSqQm8Qpeqz45CXRVFvLp+9yw3W8RiTkbdPUT0Cww=; b=ob8Mk98ovGR+35GcMEUK6WK+mUU2aULHr8PCCnUGMTb4cgVA0cg9PH0tECnyG4V6Y1 +PghpJRgP2GqqleiUu4HG4/HN76gHyY4jvfaUffRzYNjViqiRwQFvteWhnJYrS/vhbLU S7Axk0qEqqb1xH198Z0VFF412WA5w1COi4vhLgTx5KSWjhyZFnnq7gyopts2xd85A+1I grmZru8KaK4lgHfquwMI5jXnELkLJf6yuvaixIXGGoLa8hRfiUExhTbb+Orw4qCmi2/1 Eb3C6bKpRfrplWNxfnL3fd5EALN54zCZdDnH4H0HMMq10dFpgCnxd6rT61VtYqqy3/Th C81w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:from:to:cc:subject:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=aobSqQm8Qpeqz45CXRVFvLp+9yw3W8RiTkbdPUT0Cww=; b=f+vjHMjD6puJzEPDwBpOdHP38LzS/H4FgCTT0Y8M6YbyuCmuATGnjHCP2WnL9Q9TKM KXNnMTkvmSILcc9+UmtaMqfBYWYp99rbrM+ruKmhN165tlsmzb9X7dzA6YM7dCsVQc9s DPlj2I7yud0rz7b34jx6ciSoPudDAJUEJoYK+Irz8aGlT2BOnSRVw25JZ9/3GhbyqN1x DqBMV2LtYMZ+j0VLD+T8cAGwKoNloY1oC21n/zRpdt4s3fiBT/hLsc7z9hPhbR0/pnZx kcholXqdfsbDfXfwm8a2ljbvsi2zUxf44wSxr79lnzSNKymwC/83kUz1ExuRZeW5MQ96 ypmA== X-Gm-Message-State: ANhLgQ2NDIsfjAN7PhkkvuYwyf0eQeXJTpwpNcf97qboheBi1EMvzR2j xA8wjqYECFojRssdvtDi9DhZqg== X-Google-Smtp-Source: ADFU+vv8RvnbweAxh8NGs3tVIqfPAh2QNpAJIclsWxQk2sLYz8iHGj1SaxG3gXzkU//N8RG+LkaXQA== X-Received: by 2002:aa7:8ad9:: with SMTP id b25mr3828145pfd.70.1583338518732; Wed, 04 Mar 2020 08:15:18 -0800 (PST) Received: from hermes.lan (204-195-22-127.wavecable.com. [204.195.22.127]) by smtp.gmail.com with ESMTPSA id j8sm3312877pjb.4.2020.03.04.08.15.17 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 04 Mar 2020 08:15:18 -0800 (PST) Date: Wed, 4 Mar 2020 08:15:09 -0800 From: Stephen Hemminger To: Tencent TGW team Cc: Thomas Monjalon , Ferruh Yigit , Andrew Rybchenko , dev@dpdk.org, Tencent TGW team Message-ID: <20200304081509.072c9d3b@hermes.lan> In-Reply-To: <20200304140543.31612-1-tgw_team@tencent.com> References: <20200304140543.31612-1-tgw_team@tencent.com> MIME-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit Subject: Re: [dpdk-dev] [PATCH] rte_ethdev: fix unsafe memory access by calling RX callback. 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 Wed, 4 Mar 2020 22:05:43 +0800 Tencent TGW team wrote: > When compiling with -O0, > the compiler does not optimize two memory accesses into one. > Leads to accessing a null pointer when calling the RX callback. > The way to access the TX callback is correct. > > Signed-off-by: Tencent TGW team > --- > lib/librte_ethdev/rte_ethdev.h | 6 ++---- > 1 file changed, 2 insertions(+), 4 deletions(-) > > diff --git a/lib/librte_ethdev/rte_ethdev.h b/lib/librte_ethdev/rte_ethdev.h > index d1a593ad1..35eb580ff 100644 > --- a/lib/librte_ethdev/rte_ethdev.h > +++ b/lib/librte_ethdev/rte_ethdev.h > @@ -4388,10 +4388,8 @@ rte_eth_rx_burst(uint16_t port_id, uint16_t queue_id, > rx_pkts, nb_pkts); > > #ifdef RTE_ETHDEV_RXTX_CALLBACKS > - if (unlikely(dev->post_rx_burst_cbs[queue_id] != NULL)) { > - struct rte_eth_rxtx_callback *cb = > - dev->post_rx_burst_cbs[queue_id]; > - > + struct rte_eth_rxtx_callback *cb = dev->post_rx_burst_cbs[queue_id]; > + if (unlikely(cb != NULL)) { > do { > nb_rx = cb->fn.rx(port_id, queue_id, rx_pkts, nb_rx, > nb_pkts, cb->param); To fix TOCTOU like this you need to use something like READ_ONCE() which does cast to volatile. For Developer Certificate of Origin (Signed-off-by) you must use a person not a team. It is a legal requirement. If you don't know what DCO is you should read what it means. Developer's Certificate of Origin 1.1 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ By making a contribution to this project, I certify that: (a) The contribution was created in whole or in part by me and I have the right to submit it under the open source license indicated in the file; or (b) The contribution is based upon previous work that, to the best of my knowledge, is covered under an appropriate open source license and I have the right under that license to submit that work with modifications, whether created in whole or in part by me, under the same open source license (unless I am permitted to submit under a different license), as indicated in the file; or (c) The contribution was provided directly to me by some other person who certified (a), (b) or (c) and I have not modified it. (d) I understand and agree that this project and the contribution are public and that a record of the contribution (including all personal information I submit with it, including my sign-off) is maintained indefinitely and may be redistributed consistent with this project or the open source license(s) involved. then you just add a line saying:: Signed-off-by: Random J Developer using your real name (sorry, no pseudonyms or anonymous contributions.)