Skip to contentSkip to conversation

net/failsafe: Fix crash due to global devargs syntax parsing from secondary process

PATCH In review [email protected] 5 participants 12 messages Feb 10, 2022 – Feb 16, 2022 Network drivers

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 net/failsafe: Fix crash due to global devargs syntax parsing from secondary process

From: Madhuker Mythri <[email protected]>

Failsafe pmd started crashing with global devargs syntax as devargs is not memset to zero. Access it to in rte_devargs_parse resulted in a crash when called from secondary process.

Bugzilla Id: 933

---
 drivers/net/failsafe/failsafe.c | 1 +
 1 file changed, 1 insertion(+)
drivers/net/failsafe/failsafe.c +1 -0
index 3c754a5f66..aa93cc6000 100644
@@ -360,6 +360,7 @@ rte_pmd_failsafe_probe(struct rte_vdev_device *vdev)
 			if (sdev->devargs.name[0] == '\0')
 				continue;
 
+			memset(&devargs, 0, sizeof(devargs));
 			/* rebuild devargs to be able to get the bus name. */
 			ret = rte_devargs_parse(&devargs,
 						sdev->devargs.name);
Signature · 1 line
2.32.0.windows.1
#1 lore raw

Quoted 18 lines · On 2/10/2022 7:10 AM, [email protected] wrote:

From: Madhuker Mythri <[email protected]>

Failsafe pmd started crashing with global devargs syntax as devargs is not memset to zero. Access it to in rte_devargs_parse resulted in a crash when called from secondary process.

Bugzilla Id: 933

---
  drivers/net/failsafe/failsafe.c | 1 +
  1 file changed, 1 insertion(+)
drivers/net/failsafe/failsafe.c +0 -0
index 3c754a5f66..aa93cc6000 100644

drivers/net/failsafe/failsafe.c rte_pmd_failsafe_probe(struct rte_vdev_device *vdev) · line 366

Quoted 7 lines
drivers/net/failsafe/failsafe.c +1 -0
@@ -360,6 +360,7 @@ rte_pmd_failsafe_probe(struct rte_vdev_device *vdev)
  			if (sdev->devargs.name[0] == '\0')
  				continue;
 
+			memset(&devargs, 0, sizeof(devargs));
  			/* rebuild devargs to be able to get the bus name. */
  			ret = rte_devargs_parse(&devargs,
  						sdev->devargs.name);

if 'rte_devargs_parse()' requires 'devargs' parameter to be memset, what do you think memset it in the API?
This prevents forgotten cases like this.

#2 lore raw

Re:

Quoted 22 lines · Ferruh Yigit
Quoted 21 lines · On 2/10/2022 7:10 AM, [email protected] wrote:

From: Madhuker Mythri <[email protected]>

Failsafe pmd started crashing with global devargs syntax as devargs is not memset to zero. Access it to in rte_devargs_parse resulted in a crash when called from secondary process.

Bugzilla Id: 933

---
  drivers/net/failsafe/failsafe.c | 1 +
  1 file changed, 1 insertion(+)
drivers/net/failsafe/failsafe.c +0 -0
index 3c754a5f66..aa93cc6000 100644
@@ -360,6 +360,7 @@ rte_pmd_failsafe_probe(struct rte_vdev_device *vdev)
  			if (sdev->devargs.name[0] == '\0')
  				continue;
 
Quoted 8 lines

drivers/net/failsafe/failsafe.c rte_pmd_failsafe_probe(struct rte_vdev_device *vdev) · line 366

Quoted 4 lines
drivers/net/failsafe/failsafe.c +1 -0
+			memset(&devargs, 0, sizeof(devargs));
  			/* rebuild devargs to be able to get the bus name. */
  			ret = rte_devargs_parse(&devargs,
  						sdev->devargs.name);

if 'rte_devargs_parse()' requires 'devargs' parameter to be memset, what do you think memset it in the API?
This prevents forgotten cases like this.

Hi,

I was looking at it this morning.
Before the last release, rte_devargs_parse() was only supporting legacy syntax. It never read from the devargs structure, only wrote to it. So it was safe to use with a non-memset devargs.

The rte_devargs_layer_parse() however is more complex. To allow rte_dev_iterator_init() to call it without doing memory allocation, it reads parts of the devargs to make decisions.

Doing a first call to rte_devargs_layer_parse() as part of rte_devargs_parse() thus modified the contract it had with the users, that it would never read from devargs.

It is not possible to completely avoid reading from devargs in rte_devargs_layer_parse(). It is necessary for RTE_DEV_FOREACH() to be safe to interrupt without having to do iterator cleanup.

This is my current understanding. In that context, yes I think it is preferrable to
do memset() within rte_devargs_parse(). It will restore the previous part of the API saying that calling it with non-memset devargs was safe to do.

Thanks,

Signature · 1 line
Gaetan Rivet
#3 lore raw

RE: [External] : Re:

Hi Gaetan and Ferruh,

Quoted 50 lines

-----Original Message-----
From: Gaëtan Rivet <[email protected]>
Sent: 10 फरवरी 2022 21:39
To: Ferruh Yigit <[email protected]>; Madhuker Mythri <[email protected]>
Cc: [email protected]
Subject: [External] : Re:

Quoted 22 lines · Ferruh Yigit
Quoted 21 lines · On 2/10/2022 7:10 AM, [email protected] wrote:

From: Madhuker Mythri <[email protected]>

Failsafe pmd started crashing with global devargs syntax as devargs is not memset to zero. Access it to in rte_devargs_parse resulted in a crash when called from secondary process.

Bugzilla Id: 933

---
  drivers/net/failsafe/failsafe.c | 1 +
  1 file changed, 1 insertion(+)
(quoted diff) +0 -0

b/drivers/net/failsafe/failsafe.c index 3c754a5f66..aa93cc6000 100644

drivers/net/failsafe/failsafe.c +0 -0
@@ -360,6 +360,7 @@ rte_pmd_failsafe_probe(struct rte_vdev_device *vdev)
  			if (sdev->devargs.name[0] == '\0')
  				continue;
 
Quoted 8 lines

drivers/net/failsafe/failsafe.c rte_pmd_failsafe_probe(struct rte_vdev_device *vdev) · line 366

Quoted 4 lines
drivers/net/failsafe/failsafe.c +1 -0
+			memset(&devargs, 0, sizeof(devargs));
  			/* rebuild devargs to be able to get the bus name. */
  			ret = rte_devargs_parse(&devargs,
  						sdev->devargs.name);

if 'rte_devargs_parse()' requires 'devargs' parameter to be memset, what do you think memset it in the API?
This prevents forgotten cases like this.

Hi,

I was looking at it this morning.
Before the last release, rte_devargs_parse() was only supporting legacy syntax.
It never read from the devargs structure, only wrote to it. So it was safe to use with a non-memset devargs.

The rte_devargs_layer_parse() however is more complex. To allow rte_dev_iterator_init() to call it without doing memory allocation, it reads parts of the devargs to make decisions.

Doing a first call to rte_devargs_layer_parse() as part of rte_devargs_parse() thus modified the contract it had with the users, that it would never read from devargs.

Quoted 8 lines

It is not possible to completely avoid reading from devargs in rte_devargs_layer_parse(). It is necessary for RTE_DEV_FOREACH() to be safe to interrupt without having to do iterator cleanup.

This is my current understanding. In that context, yes I think it is preferrable to do memset() within rte_devargs_parse(). It will restore the previous part of the API saying that calling it with non-memset >devargs was safe to do.

Thanks,
--
Gaetan Rivet

Thanks for your comments.
The rte_devargs_parse() is used in other 'netvsc' PMD also in netvsc_hotadd_callback().
In this netvsc_hotadd_callback(), it was assigning the devargs with some other instance pointer(not sure, whether its just a pointer or with data values) before calling this rte_devargs_parse(), so if we memset inside this API, then the devargs data values will be nullified right. I'm not fully familiar with this parsing functionality. So, please let me know, doing memset() inside this rte_devargs_parse() is valid or not, as this is a generic function for all the PMD's.

Thanks,
Madhuker.

#4 lore raw

Re: [External] : Re: [PATCH] net/failsafe: Fix crash due to global devargs syntax parsing from secondary process

Quoted 57 lines · Madhuker Mythri

Hi Gaetan and Ferruh,

Quoted 55 lines

-----Original Message-----
From: Gaëtan Rivet <[email protected]>
Sent: 10 फरवरी 2022 21:39
To: Ferruh Yigit <[email protected]>; Madhuker Mythri <[email protected]>
Cc: [email protected]
Subject: [External] : Re:

Quoted 22 lines · Ferruh Yigit
Quoted 21 lines · On 2/10/2022 7:10 AM, [email protected] wrote:

From: Madhuker Mythri <[email protected]>

Failsafe pmd started crashing with global devargs syntax as devargs is not memset to zero. Access it to in rte_devargs_parse resulted in a crash when called from secondary process.

Bugzilla Id: 933

---
   drivers/net/failsafe/failsafe.c | 1 +
   1 file changed, 1 insertion(+)
(quoted diff) +0 -0

b/drivers/net/failsafe/failsafe.c index 3c754a5f66..aa93cc6000 100644

drivers/net/failsafe/failsafe.c +0 -0
@@ -360,6 +360,7 @@ rte_pmd_failsafe_probe(struct rte_vdev_device *vdev)
   			if (sdev->devargs.name[0] == '\0')
   				continue;
 
Quoted 8 lines

drivers/net/failsafe/failsafe.c rte_pmd_failsafe_probe(struct rte_vdev_device *vdev) · line 366

Quoted 4 lines
drivers/net/failsafe/failsafe.c +1 -0
+			memset(&devargs, 0, sizeof(devargs));
   			/* rebuild devargs to be able to get the bus name. */
   			ret = rte_devargs_parse(&devargs,
   						sdev->devargs.name);

if 'rte_devargs_parse()' requires 'devargs' parameter to be memset, what do you think memset it in the API?
This prevents forgotten cases like this.

Hi,

I was looking at it this morning.
Before the last release, rte_devargs_parse() was only supporting legacy syntax.
It never read from the devargs structure, only wrote to it. So it was safe to use with a non-memset devargs.

The rte_devargs_layer_parse() however is more complex. To allow rte_dev_iterator_init() to call it without doing memory allocation, it reads parts of the devargs to make decisions.

Doing a first call to rte_devargs_layer_parse() as part of rte_devargs_parse() thus modified the contract it had with the users, that it would never read from devargs.

It is not possible to completely avoid reading from devargs in rte_devargs_layer_parse(). It is necessary for RTE_DEV_FOREACH() to be safe to interrupt without having to do iterator cleanup.

This is my current understanding. In that context, yes I think it is preferrable to do memset() within rte_devargs_parse(). It will restore the previous part of the API saying that calling it with non-memset >devargs was safe to do.

Quoted 9 lines
Quoted 3 lines

Thanks,
--
Gaetan Rivet

Thanks for your comments.
The rte_devargs_parse() is used in other 'netvsc' PMD also in netvsc_hotadd_callback().
In this netvsc_hotadd_callback(), it was assigning the devargs with some other instance pointer(not sure, whether its just a pointer or with data values) before calling this rte_devargs_parse(), so if we memset inside this API, then the devargs data values will be nullified right. I'm not fully familiar with this parsing functionality. So, please let me know, doing memset() inside this rte_devargs_parse() is valid or not, as this is a generic function for all the PMD's.

Hi Madhuker,

Gaetan already sent a patch for it:
https://patches.dpdk.org/project/dpdk/patch/[email protected]/

#5 lore raw

Re: [External] : Re:

In reply to Madhuker Mythri
Quoted 73 lines · Madhuker Mythri

Hi Gaetan and Ferruh,

Quoted 50 lines

-----Original Message-----
From: Gaëtan Rivet <[email protected]>
Sent: 10 फरवरी 2022 21:39
To: Ferruh Yigit <[email protected]>; Madhuker Mythri <[email protected]>
Cc: [email protected]
Subject: [External] : Re:

Quoted 22 lines · Ferruh Yigit
Quoted 21 lines · On 2/10/2022 7:10 AM, [email protected] wrote:

From: Madhuker Mythri <[email protected]>

Failsafe pmd started crashing with global devargs syntax as devargs is not memset to zero. Access it to in rte_devargs_parse resulted in a crash when called from secondary process.

Bugzilla Id: 933

---
  drivers/net/failsafe/failsafe.c | 1 +
  1 file changed, 1 insertion(+)
(quoted diff) +0 -0

b/drivers/net/failsafe/failsafe.c index 3c754a5f66..aa93cc6000 100644

drivers/net/failsafe/failsafe.c +0 -0
@@ -360,6 +360,7 @@ rte_pmd_failsafe_probe(struct rte_vdev_device *vdev)
  			if (sdev->devargs.name[0] == '\0')
  				continue;
 
Quoted 8 lines

drivers/net/failsafe/failsafe.c rte_pmd_failsafe_probe(struct rte_vdev_device *vdev) · line 366

Quoted 4 lines
drivers/net/failsafe/failsafe.c +1 -0
+			memset(&devargs, 0, sizeof(devargs));
  			/* rebuild devargs to be able to get the bus name. */
  			ret = rte_devargs_parse(&devargs,
  						sdev->devargs.name);

if 'rte_devargs_parse()' requires 'devargs' parameter to be memset, what do you think memset it in the API?
This prevents forgotten cases like this.

Hi,

I was looking at it this morning.
Before the last release, rte_devargs_parse() was only supporting legacy syntax.
It never read from the devargs structure, only wrote to it. So it was safe to use with a non-memset devargs.

The rte_devargs_layer_parse() however is more complex. To allow rte_dev_iterator_init() to call it without doing memory allocation, it reads parts of the devargs to make decisions.

Doing a first call to rte_devargs_layer_parse() as part of rte_devargs_parse() thus modified the contract it had with the users, that it would never read from devargs.

Quoted 8 lines

It is not possible to completely avoid reading from devargs in rte_devargs_layer_parse(). It is necessary for RTE_DEV_FOREACH() to be safe to interrupt without having to do iterator cleanup.

This is my current understanding. In that context, yes I think it is preferrable to do memset() within rte_devargs_parse(). It will restore the previous part of the API saying that calling it with non-memset >devargs was safe to do.

Thanks,
--
Gaetan Rivet

Thanks for your comments.
The rte_devargs_parse() is used in other 'netvsc' PMD also in netvsc_hotadd_callback().
In this netvsc_hotadd_callback(), it was assigning the devargs with some other instance pointer(not sure, whether its just a pointer or with data values) before calling this rte_devargs_parse(), so if we memset inside this API, then the devargs data values will be nullified right.
I'm not fully familiar with this parsing functionality. So, please let me know, doing memset() inside this rte_devargs_parse() is valid or not, as this is a generic function for all the PMD's.

Quoted 2 lines

Thanks,
Madhuker.

Hi Madhuker,

I have just checked the code, it does not seem that netvsc relies on values being kept in the devargs structure across calls, so it seems that it would be safe. It would be better to check with the maintainers however, I'm adding them to this thread.

Signature · 1 line
Gaetan Rivet
#6 lore raw

RE: [External] : Re:

Quoted 95 lines

Subject: Re: [External] : Re:

Quoted 26 lines · Madhuker Mythri

Hi Gaetan and Ferruh,

Quoted 24 lines

-----Original Message-----
From: Gaëtan Rivet <[email protected]>
Sent: 10 फरवरी 2022 21:39
To: Ferruh Yigit <[email protected]>; Madhuker Mythri <[email protected]>
Cc: [email protected]
Subject: [External] : Re:

Quoted 14 lines · Ferruh Yigit
Quoted 13 lines · On 2/10/2022 7:10 AM, [email protected] wrote:

From: Madhuker Mythri <[email protected]>

Failsafe pmd started crashing with global devargs syntax as devargs is not memset to zero. Access it to in rte_devargs_parse resulted in a crash when called from secondary process.

Bugzilla Id: 933

---
  drivers/net/failsafe/failsafe.c | 1 +
  1 file changed, 1 insertion(+)
Quoted 6 lines
Quoted 6 lines
Quoted 6 lines

drivers/net/failsafe/failsafe.c rte_pmd_failsafe_probe(struct

Quoted 6 lines
(quoted diff) +0 -0

b/drivers/net/failsafe/failsafe.c index 3c754a5f66..aa93cc6000 100644

drivers/net/failsafe/failsafe.c +0 -0
@@ -360,6 +360,7 @@ rte_pmd_failsafe_probe(struct

rte_vdev_device *vdev)

Quoted 12 lines
Quoted 12 lines
Quoted 11 lines

drivers/net/failsafe/failsafe.c rte_pmd_failsafe_probe(struct rte_vdev_device *vdev) · line 366

Quoted 7 lines
drivers/net/failsafe/failsafe.c +1 -0
  			if (sdev->devargs.name[0] == '\0')
  				continue;
 
+			memset(&devargs, 0, sizeof(devargs));
  			/* rebuild devargs to be able to get the bus name. */
  			ret = rte_devargs_parse(&devargs,
  						sdev->devargs.name);

if 'rte_devargs_parse()' requires 'devargs' parameter to be memset, what do you think memset it in the API?
This prevents forgotten cases like this.

Quoted 4 lines
Quoted 4 lines

Hi,

I was looking at it this morning.
Before the last release, rte_devargs_parse() was only supporting legacy

syntax.

Quoted 1 line
Quoted 1 line

It never read from the devargs structure, only wrote to it. So it was safe to

use with a non-memset devargs.

Quoted 2 lines
Quoted 2 lines

The rte_devargs_layer_parse() however is more complex. To allow

rte_dev_iterator_init() to call it without doing memory allocation, it reads parts of the devargs to make decisions.

Quoted 2 lines
Quoted 2 lines

Doing a first call to rte_devargs_layer_parse() as part of

rte_devargs_parse() thus modified the contract it had with the users, that it would never read from devargs.

Quoted 2 lines
Quoted 2 lines

It is not possible to completely avoid reading from devargs in

rte_devargs_layer_parse().

Quoted 1 line
Quoted 1 line

It is necessary for RTE_DEV_FOREACH() to be safe to interrupt without

having to do iterator cleanup.

Quoted 2 lines
Quoted 2 lines

This is my current understanding. In that context, yes I think it is

preferrable to do memset() within rte_devargs_parse(). It will restore the previous part of the API saying that calling it with non-memset >devargs was safe to do.

Quoted 17 lines
Quoted 4 lines

Thanks,
--
Gaetan Rivet

Thanks for your comments.
The rte_devargs_parse() is used in other 'netvsc' PMD also in netvsc_hotadd_callback().
In this netvsc_hotadd_callback(), it was assigning the devargs with some other instance pointer(not sure, whether its just a pointer or with data values) before calling this rte_devargs_parse(), so if we memset inside this API, then the devargs data values will be nullified right.
I'm not fully familiar with this parsing functionality. So, please let me know, doing memset() inside this rte_devargs_parse() is valid or not, as this is a generic function for all the PMD's.

Quoted 2 lines

Thanks,
Madhuker.

Hi Madhuker,

Quoted 7 lines

I have just checked the code, it does not seem that netvsc relies on values being kept in the devargs structure across calls, so it seems that it would be safe. It would be better to check with the maintainers however, I'm adding them to this thread.

--
Gaetan Rivet

When netvsc calls rte_devargs_parse, it assumes the value in rte_devargs will be overwritten. There is an issue with netvsc dealing multiple devices, that is on my todo list.

In this case, I think it's safe to do memset() within rte_devargs_parse().

Long

#7 lore raw

PATCH 1/1 devargs: Fix rte_devargs_parse uninitialized calls

In reply to [email protected]

The function rte_devargs_parse() previously was safe to call with non-initialized devargs structure as parameter.

When adding the support for the global device syntax, this assumption was broken. Restore it by forcing memset as part of the call itself.

Bugzilla Id: 933

Fixes b344eb5d941a ("devargs: parse global device syntax")
---
 lib/eal/common/eal_common_devargs.c | 1 +
 1 file changed, 1 insertion(+)
lib/eal/common/eal_common_devargs.c +1 -0
index 8c7650cf6c..184fe676aa 100644
@@ -191,6 +191,7 @@ rte_devargs_parse(struct rte_devargs *da, const char *dev)
 
 	if (da == NULL)
 		return -EINVAL;
+	memset(da, 0, sizeof(*da));
 
 	/* First parse according global device syntax. */
 	if (rte_devargs_layers_parse(da, dev) == 0) {
Signature · 1 line
2.31.1
#8 lore raw

Re: [PATCH] devargs: Fix rte_devargs_parse uninitialized calls

Quoted 10 lines · Gaetan Rivet

The function rte_devargs_parse() previously was safe to call with non-initialized devargs structure as parameter.

When adding the support for the global device syntax, this assumption was broken. Restore it by forcing memset as part of the call itself.

Bugzilla Id: 933

Fixes b344eb5d941a ("devargs: parse global device syntax")

Since Madhuker did the initial analysis and the patch I think fair to give credit for the work.

Thanks,
ferruh

Quoted 16 lines
---
  lib/eal/common/eal_common_devargs.c | 1 +
  1 file changed, 1 insertion(+)
lib/eal/common/eal_common_devargs.c +1 -0
index 8c7650cf6c..184fe676aa 100644
@@ -191,6 +191,7 @@ rte_devargs_parse(struct rte_devargs *da, const char *dev)
 
  	if (da == NULL)
  		return -EINVAL;
+	memset(da, 0, sizeof(*da));
 
  	/* First parse according global device syntax. */
  	if (rte_devargs_layers_parse(da, dev) == 0) {
#9 lore raw

Re: [PATCH] devargs: Fix rte_devargs_parse uninitialized calls

Quoted 12 lines · Ferruh Yigit
Quoted 10 lines · Gaetan Rivet

The function rte_devargs_parse() previously was safe to call with non-initialized devargs structure as parameter.

When adding the support for the global device syntax, this assumption was broken. Restore it by forcing memset as part of the call itself.

Bugzilla Id: 933

Fixes b344eb5d941a ("devargs: parse global device syntax")
Quoted 8 lines

Since Madhuker did the initial analysis and the patch I think fair to give credit for the work.

Thanks,
ferruh

Sure, thanks Ferruh. Whichever patch is fine by me.

Signature · 1 line
Gaetan Rivet
#10 lore raw

Re: [PATCH] devargs: Fix rte_devargs_parse uninitialized calls

In reply to Gaetan Rivet
Quoted 9 lines · Gaetan Rivet

The function rte_devargs_parse() previously was safe to call with non-initialized devargs structure as parameter.

When adding the support for the global device syntax, this assumption was broken. Restore it by forcing memset as part of the call itself.

Bugzilla Id: 933

Nit: Bugzilla ID*

Quoted 1 line
Fixes b344eb5d941a ("devargs: parse global device syntax")

We need a backport in 21.11, right?

Quoted 18 lines
---
 lib/eal/common/eal_common_devargs.c | 1 +
 1 file changed, 1 insertion(+)
lib/eal/common/eal_common_devargs.c +1 -1
index 8c7650cf6c..184fe676aa 100644
@@ -191,6 +191,7 @@ rte_devargs_parse(struct rte_devargs *da, const char *dev)
 
        if (da == NULL)
                return -EINVAL;
+       memset(da, 0, sizeof(*da));
 
        /* First parse according global device syntax. */
        if (rte_devargs_layers_parse(da, dev) == 0) {
--
Quoted 2 lines

2.31.1

Otherwise lgtm.

Signature · 1 line
David Marchand
#11 lore raw

Re: [PATCH] devargs: Fix rte_devargs_parse uninitialized calls

Quoted 9 lines · David Marchand
Quoted 8 lines · Gaetan Rivet

The function rte_devargs_parse() previously was safe to call with non-initialized devargs structure as parameter.

When adding the support for the global device syntax, this assumption was broken. Restore it by forcing memset as part of the call itself.

Quoted 7 lines
Quoted 1 line

Bugzilla Id: 933

Nit: Bugzilla ID*

Quoted 1 line
Fixes b344eb5d941a ("devargs: parse global device syntax")

We need a backport in 21.11, right?

Hi David, yes it should be in 21.11 as well.

Signature · 1 line
Gaetan Rivet