DPDK patches and discussions
 help / color / mirror / Atom feed
From: Ferruh Yigit <ferruh.yigit@intel.com>
To: Andrew Rybchenko <arybchenko@solarflare.com>,
	Thomas Monjalon <thomas@monjalon.net>
Cc: dev@dpdk.org, stable@dpdk.org
Subject: Re: [dpdk-dev] [PATCH] ethdev: avoid undefined behaviour on configuration copying
Date: Tue, 19 Nov 2019 13:19:21 +0000	[thread overview]
Message-ID: <e3f472fb-97a2-8ed1-b332-634c09bc70e4@intel.com> (raw)
In-Reply-To: <34e94334-931f-cd89-dc76-ce3a73f34b1a@solarflare.com>

On 11/19/2019 12:36 PM, Andrew Rybchenko wrote:
> On 11/19/19 3:24 PM, Ferruh Yigit wrote:
>> On 11/19/2019 8:22 AM, Andrew Rybchenko wrote:
>>> memcpy() source and destination areas must not overlap and equal
>>> pointers is the case which is really met, so handle it.
>> Agree providing same config as input can cause problem with current
>> implementation, but it is the limitation of the memcpy, the API doesn't request
>> this.
>>
>> We can fix as you suggested, in this case we should document this in API
>> documentation I think,
> 
> Basically the patch solves it and there is nothing to document.
> If pointers are equal there is nothing to do, no copying required.

You are right, scratch my comment. I overlooked as just overlapping memory issue.

> 
>> we can also solve this by updating the implementation to let this, using an
>> interim buffer in the simplest measure, not sure which one is better.
> 
> I don't think that interim buffer is required, 'if' perfectly does the job.
> 
>> Any practical reason to prevent this other than 'memcpy' limitation?
> 
> Nothing except application should not play with dev->data,

+1.
Bonding PMD though not exactly an application, not sure to let or not it to
update 'dev->data'

> but I'm not sure if it is the right place to forbid it.
> 
> Alternative solution is to fix bonding and return error if dev_conf is
> equal to &dev->data->dev_conf since usecase is unclear and callers
> should not use dev->data.
> 
>>> Fixes: 68b931bff287 ("ethdev: eliminate interim variable")
>>> Cc: stable@dpdk.org
>>>
>>> Signed-off-by: Andrew Rybchenko <arybchenko@solarflare.com>
>>> ---
>>> slave_configure() in drivers/net/bonding calls rte_eth_dev_configure()
>>> with &slave_eth_dev->data->dev_conf.
>>>
>>> Alternative solution is to fix bonding and return error if dev_conf is
>>> equal to &dev->data->dev_conf since usecase is unclear and callers
>>> should not use dev->data.
>>>
>>>  lib/librte_ethdev/rte_ethdev.c | 4 +++-
>>>  1 file changed, 3 insertions(+), 1 deletion(-)
>>>
>>> diff --git a/lib/librte_ethdev/rte_ethdev.c b/lib/librte_ethdev/rte_ethdev.c
>>> index 8f48e8d659..8d2ce31a81 100644
>>> --- a/lib/librte_ethdev/rte_ethdev.c
>>> +++ b/lib/librte_ethdev/rte_ethdev.c
>>> @@ -1245,7 +1245,9 @@ rte_eth_dev_configure(uint16_t port_id, uint16_t nb_rx_q, uint16_t nb_tx_q,
>>>  	 * Copy the dev_conf parameter into the dev structure.
>>>  	 * rte_eth_dev_info_get() requires dev_conf, copy it before dev_info get
>>>  	 */
>>> -	memcpy(&dev->data->dev_conf, dev_conf, sizeof(dev->data->dev_conf));
>>> +	if (dev_conf != &dev->data->dev_conf)
>>> +		memcpy(&dev->data->dev_conf, dev_conf,
>>> +		       sizeof(dev->data->dev_conf));
>>>  
>>>  	ret = rte_eth_dev_info_get(port_id, &dev_info);
>>>  	if (ret != 0)
>>>
> 


  reply	other threads:[~2019-11-19 13:19 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-11-19  8:22 Andrew Rybchenko
2019-11-19 12:24 ` Ferruh Yigit
2019-11-19 12:36   ` Andrew Rybchenko
2019-11-19 13:19     ` Ferruh Yigit [this message]
2019-11-19 13:25       ` Andrew Rybchenko
2019-11-19 13:37       ` [dpdk-dev] [dpdk-stable] " Ferruh Yigit
2019-11-19 13:59         ` Andrew Rybchenko
2019-11-19 14:57 ` [dpdk-dev] " Ferruh Yigit
2019-11-19 15:47   ` [dpdk-dev] [dpdk-stable] " Ferruh Yigit

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=e3f472fb-97a2-8ed1-b332-634c09bc70e4@intel.com \
    --to=ferruh.yigit@intel.com \
    --cc=arybchenko@solarflare.com \
    --cc=dev@dpdk.org \
    --cc=stable@dpdk.org \
    --cc=thomas@monjalon.net \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).