DPDK patches and discussions
 help / color / mirror / Atom feed
* [PATCH 1/1] eal/linux: reject mountpt shorter than --huge-dir
@ 2023-01-03 18:57 Ashish Sadanandan
  2023-01-03 23:53 ` Ashish Sadanandan
                   ` (3 more replies)
  0 siblings, 4 replies; 13+ messages in thread
From: Ashish Sadanandan @ 2023-01-03 18:57 UTC (permalink / raw)
  To: dev; +Cc: Ashish Sadanandan, john.levon, stable

The code added for allowing --huge-dir to specify hugetlbfs
sub-directories has a bug where it incorrectly matches mounts that
contain a prefix of the specified --huge-dir.

Consider --huge-dir=/dev/hugepages1G is passed to rte_eal_init. Given
the following hugetlbfs mounts

$ mount | grep hugetlbfs
hugetlbfs on /dev/hugepages type hugetlbfs (rw,relatime,pagesize=2M)
hugetlbfs on /dev/hugepages1G type hugetlbfs (rw,relatime,pagesize=1024M)
hugetlbfs on /mnt/huge type hugetlbfs (rw,relatime,pagesize=2M)

get_hugepage_dir is first called with hugepage_sz=2097152. While
iterating over all mount points, /dev/hugepages is incorrectly
determined to be a match because it's a prefix of --huge-dir. The caller
then obtains an exclusive lock on --huge-dir.

In the next call to get_hugepage_dir, hugepage_sz=1073741824. This call
correctly determines /dev/hugepages1G is a match. The caller again
attempts to obtain an exclusive lock on --huge-dir and deadlocks because
it's already holding a lock.

This has been corrected by rejecting the mount point being considered if
its length is smaller than the specified --huge-dir.

Fixes: 24d5a1ce6b85 ("eal/linux: allow hugetlbfs sub-directories")
Cc: john.levon@nutanix.com
Cc: stable@dpdk.org
---
 lib/eal/linux/eal_hugepage_info.c | 11 +++++++----
 1 file changed, 7 insertions(+), 4 deletions(-)

diff --git a/lib/eal/linux/eal_hugepage_info.c b/lib/eal/linux/eal_hugepage_info.c
index a1b6cb31ff..fcc3d82fdf 100644
--- a/lib/eal/linux/eal_hugepage_info.c
+++ b/lib/eal/linux/eal_hugepage_info.c
@@ -269,16 +269,19 @@ get_hugepage_dir(uint64_t hugepage_sz, char *hugedir, int len)
 		 * Ignore any mount that doesn't contain the --huge-dir
 		 * directory.
 		 */
-		if (strncmp(internal_conf->hugepage_dir, splitstr[MOUNTPT],
-			strlen(splitstr[MOUNTPT])) != 0) {
+		size_t mountpt_len = strlen(splitstr[MOUNTPT]);
+
+		if (strlen(internal_conf->hugepage_dir) > mountpt_len)
+			continue;
+		else if (strncmp(internal_conf->hugepage_dir, splitstr[MOUNTPT],
+			mountpt_len) != 0)
 			continue;
-		}
 
 		/*
 		 * We found a match, but only prefer it if it's a longer match
 		 * (so /mnt/1 is preferred over /mnt for matching /mnt/1/2)).
 		 */
-		if (strlen(splitstr[MOUNTPT]) > strlen(found))
+		if (mountpt_len > strlen(found))
 			strlcpy(found, splitstr[MOUNTPT], len);
 	} /* end while fgets */
 
-- 
2.27.0


^ permalink raw reply	[flat|nested] 13+ messages in thread

* Re: [PATCH 1/1] eal/linux: reject mountpt shorter than --huge-dir
  2023-01-03 18:57 [PATCH 1/1] eal/linux: reject mountpt shorter than --huge-dir Ashish Sadanandan
@ 2023-01-03 23:53 ` Ashish Sadanandan
  2023-01-04  0:00 ` [PATCH v2 1/1] eal/linux: reject --huge-dir not parent of mountpt Ashish Sadanandan
                   ` (2 subsequent siblings)
  3 siblings, 0 replies; 13+ messages in thread
From: Ashish Sadanandan @ 2023-01-03 23:53 UTC (permalink / raw)
  To: dev; +Cc: john.levon, stable

[-- Attachment #1: Type: text/plain, Size: 3143 bytes --]

 Please ignore this patch, I'll submit an updated one. I somehow managed to
only execute a subset of the fast-tests suite initially and didn't run
eal_flags_misc_autotest at all. Now I see that my proposed fix is flawed, I
will submit another try soon.

Sorry for the noise

On Tue, Jan 3, 2023 at 11:57 AM Ashish Sadanandan <
ashish.sadanandan@gmail.com> wrote:

> The code added for allowing --huge-dir to specify hugetlbfs
> sub-directories has a bug where it incorrectly matches mounts that
> contain a prefix of the specified --huge-dir.
>
> Consider --huge-dir=/dev/hugepages1G is passed to rte_eal_init. Given
> the following hugetlbfs mounts
>
> $ mount | grep hugetlbfs
> hugetlbfs on /dev/hugepages type hugetlbfs (rw,relatime,pagesize=2M)
> hugetlbfs on /dev/hugepages1G type hugetlbfs (rw,relatime,pagesize=1024M)
> hugetlbfs on /mnt/huge type hugetlbfs (rw,relatime,pagesize=2M)
>
> get_hugepage_dir is first called with hugepage_sz=2097152. While
> iterating over all mount points, /dev/hugepages is incorrectly
> determined to be a match because it's a prefix of --huge-dir. The caller
> then obtains an exclusive lock on --huge-dir.
>
> In the next call to get_hugepage_dir, hugepage_sz=1073741824. This call
> correctly determines /dev/hugepages1G is a match. The caller again
> attempts to obtain an exclusive lock on --huge-dir and deadlocks because
> it's already holding a lock.
>
> This has been corrected by rejecting the mount point being considered if
> its length is smaller than the specified --huge-dir.
>
> Fixes: 24d5a1ce6b85 ("eal/linux: allow hugetlbfs sub-directories")
> Cc: john.levon@nutanix.com
> Cc: stable@dpdk.org
> ---
>  lib/eal/linux/eal_hugepage_info.c | 11 +++++++----
>  1 file changed, 7 insertions(+), 4 deletions(-)
>
> diff --git a/lib/eal/linux/eal_hugepage_info.c
> b/lib/eal/linux/eal_hugepage_info.c
> index a1b6cb31ff..fcc3d82fdf 100644
> --- a/lib/eal/linux/eal_hugepage_info.c
> +++ b/lib/eal/linux/eal_hugepage_info.c
> @@ -269,16 +269,19 @@ get_hugepage_dir(uint64_t hugepage_sz, char
> *hugedir, int len)
>                  * Ignore any mount that doesn't contain the --huge-dir
>                  * directory.
>                  */
> -               if (strncmp(internal_conf->hugepage_dir, splitstr[MOUNTPT],
> -                       strlen(splitstr[MOUNTPT])) != 0) {
> +               size_t mountpt_len = strlen(splitstr[MOUNTPT]);
> +
> +               if (strlen(internal_conf->hugepage_dir) > mountpt_len)
> +                       continue;
> +               else if (strncmp(internal_conf->hugepage_dir,
> splitstr[MOUNTPT],
> +                       mountpt_len) != 0)
>                         continue;
> -               }
>
>                 /*
>                  * We found a match, but only prefer it if it's a longer
> match
>                  * (so /mnt/1 is preferred over /mnt for matching
> /mnt/1/2)).
>                  */
> -               if (strlen(splitstr[MOUNTPT]) > strlen(found))
> +               if (mountpt_len > strlen(found))
>                         strlcpy(found, splitstr[MOUNTPT], len);
>         } /* end while fgets */
>
> --
> 2.27.0
>
>

[-- Attachment #2: Type: text/html, Size: 4006 bytes --]

^ permalink raw reply	[flat|nested] 13+ messages in thread

* [PATCH v2 1/1] eal/linux: reject --huge-dir not parent of mountpt
  2023-01-03 18:57 [PATCH 1/1] eal/linux: reject mountpt shorter than --huge-dir Ashish Sadanandan
  2023-01-03 23:53 ` Ashish Sadanandan
@ 2023-01-04  0:00 ` Ashish Sadanandan
  2023-01-04 11:24   ` Dmitry Kozlyuk
  2023-01-04 16:22   ` John Levon
  2023-01-04 18:17 ` [PATCH v3 " Ashish Sadanandan
  2023-01-09  1:52 ` [PATCH v4 1/1] eal/linux: reject mountpt not parent of --huge-dir Ashish Sadanandan
  3 siblings, 2 replies; 13+ messages in thread
From: Ashish Sadanandan @ 2023-01-04  0:00 UTC (permalink / raw)
  To: dev; +Cc: Ashish Sadanandan, john.levon, stable

The code added for allowing --huge-dir to specify hugetlbfs
sub-directories has a bug where it incorrectly matches mounts that
contain a prefix of the specified --huge-dir.

Consider --huge-dir=/dev/hugepages1G is passed to rte_eal_init. Given
the following hugetlbfs mounts

$ mount | grep hugetlbfs
hugetlbfs on /dev/hugepages type hugetlbfs (rw,relatime,pagesize=2M)
hugetlbfs on /dev/hugepages1G type hugetlbfs (rw,relatime,pagesize=1024M)
hugetlbfs on /mnt/huge type hugetlbfs (rw,relatime,pagesize=2M)

get_hugepage_dir is first called with hugepage_sz=2097152. While
iterating over all mount points, /dev/hugepages is incorrectly
determined to be a match because it's a prefix of --huge-dir. The caller
then obtains an exclusive lock on --huge-dir.

In the next call to get_hugepage_dir, hugepage_sz=1073741824. This call
correctly determines /dev/hugepages1G is a match. The caller again
attempts to obtain an exclusive lock on --huge-dir and deadlocks because
it's already holding a lock.

This has been corrected by ensuring any matched mount point is either an
exact match or a parent path of --huge-dir.

Fixes: 24d5a1ce6b85 ("eal/linux: allow hugetlbfs sub-directories")
Cc: john.levon@nutanix.com
Cc: stable@dpdk.org
Signed-off-by: Ashish Sadanandan <ashish.sadanandan@gmail.com>
---
 lib/eal/linux/eal_hugepage_info.c | 15 +++++++++++++--
 1 file changed, 13 insertions(+), 2 deletions(-)

diff --git a/lib/eal/linux/eal_hugepage_info.c b/lib/eal/linux/eal_hugepage_info.c
index a1b6cb31ff..180abd930c 100644
--- a/lib/eal/linux/eal_hugepage_info.c
+++ b/lib/eal/linux/eal_hugepage_info.c
@@ -265,12 +265,23 @@ get_hugepage_dir(uint64_t hugepage_sz, char *hugedir, int len)
 			break;
 		}
 
+		size_t mountpt_len = strlen(splitstr[MOUNTPT]);
+		size_t hugepage_dir_len = strlen(internal_conf->hugepage_dir);
+
 		/*
 		 * Ignore any mount that doesn't contain the --huge-dir
 		 * directory.
 		 */
 		if (strncmp(internal_conf->hugepage_dir, splitstr[MOUNTPT],
-			strlen(splitstr[MOUNTPT])) != 0) {
+			mountpt_len) != 0) {
+			continue;
+		}
+		/*
+		 * Ignore any mount where hugepage_dir is not a parent path of
+		 * the mount
+		 */
+		else if(hugepage_dir_len > mountpt_len &&
+			internal_conf->hugepage_dir[mountpt_len] != '/') {
 			continue;
 		}
 
@@ -278,7 +289,7 @@ get_hugepage_dir(uint64_t hugepage_sz, char *hugedir, int len)
 		 * We found a match, but only prefer it if it's a longer match
 		 * (so /mnt/1 is preferred over /mnt for matching /mnt/1/2)).
 		 */
-		if (strlen(splitstr[MOUNTPT]) > strlen(found))
+		if (mountpt_len > strlen(found))
 			strlcpy(found, splitstr[MOUNTPT], len);
 	} /* end while fgets */
 
-- 
2.27.0


^ permalink raw reply	[flat|nested] 13+ messages in thread

* Re: [PATCH v2 1/1] eal/linux: reject --huge-dir not parent of mountpt
  2023-01-04  0:00 ` [PATCH v2 1/1] eal/linux: reject --huge-dir not parent of mountpt Ashish Sadanandan
@ 2023-01-04 11:24   ` Dmitry Kozlyuk
  2023-01-04 18:17     ` Ashish Sadanandan
  2023-01-04 16:22   ` John Levon
  1 sibling, 1 reply; 13+ messages in thread
From: Dmitry Kozlyuk @ 2023-01-04 11:24 UTC (permalink / raw)
  To: Ashish Sadanandan; +Cc: dev, john.levon, stable

2023-01-03 17:00 (UTC-0700), Ashish Sadanandan:
> The code added for allowing --huge-dir to specify hugetlbfs
> sub-directories has a bug where it incorrectly matches mounts that
> contain a prefix of the specified --huge-dir.
> 
> Consider --huge-dir=/dev/hugepages1G is passed to rte_eal_init. Given
> the following hugetlbfs mounts
> 
> $ mount | grep hugetlbfs
> hugetlbfs on /dev/hugepages type hugetlbfs (rw,relatime,pagesize=2M)
> hugetlbfs on /dev/hugepages1G type hugetlbfs (rw,relatime,pagesize=1024M)
> hugetlbfs on /mnt/huge type hugetlbfs (rw,relatime,pagesize=2M)
> 
> get_hugepage_dir is first called with hugepage_sz=2097152. While
> iterating over all mount points, /dev/hugepages is incorrectly
> determined to be a match because it's a prefix of --huge-dir. The caller
> then obtains an exclusive lock on --huge-dir.
> 
> In the next call to get_hugepage_dir, hugepage_sz=1073741824. This call
> correctly determines /dev/hugepages1G is a match. The caller again
> attempts to obtain an exclusive lock on --huge-dir and deadlocks because
> it's already holding a lock.
> 
> This has been corrected by ensuring any matched mount point is either an
> exact match or a parent path of --huge-dir.
> 
> Fixes: 24d5a1ce6b85 ("eal/linux: allow hugetlbfs sub-directories")
> Cc: john.levon@nutanix.com
> Cc: stable@dpdk.org
> Signed-off-by: Ashish Sadanandan <ashish.sadanandan@gmail.com>

Acked-by: Dmitry Kozlyuk <dmitry.kozliuk@gmail.com>

> ---
>  lib/eal/linux/eal_hugepage_info.c | 15 +++++++++++++--
>  1 file changed, 13 insertions(+), 2 deletions(-)
> 
> diff --git a/lib/eal/linux/eal_hugepage_info.c b/lib/eal/linux/eal_hugepage_info.c
> index a1b6cb31ff..180abd930c 100644
> --- a/lib/eal/linux/eal_hugepage_info.c
> +++ b/lib/eal/linux/eal_hugepage_info.c
> @@ -265,12 +265,23 @@ get_hugepage_dir(uint64_t hugepage_sz, char *hugedir, int len)
>  			break;
>  		}
>  
> +		size_t mountpt_len = strlen(splitstr[MOUNTPT]);
> +		size_t hugepage_dir_len = strlen(internal_conf->hugepage_dir);

The second one can be done before the loop.
Please declare all variables at the beginning of the block per code style.

> +
>  		/*
>  		 * Ignore any mount that doesn't contain the --huge-dir
>  		 * directory.
>  		 */
>  		if (strncmp(internal_conf->hugepage_dir, splitstr[MOUNTPT],
> -			strlen(splitstr[MOUNTPT])) != 0) {
> +			mountpt_len) != 0) {
> +			continue;
> +		}
> +		/*
> +		 * Ignore any mount where hugepage_dir is not a parent path of
> +		 * the mount
> +		 */
> +		else if(hugepage_dir_len > mountpt_len &&
> +			internal_conf->hugepage_dir[mountpt_len] != '/') {

Nit: maybe a single comment for both conditions would be more clear:

/*
 * Ignore any mount that is not --huge-dir or its subdirectory.
 */

>  			continue;
>  		}
>  
> @@ -278,7 +289,7 @@ get_hugepage_dir(uint64_t hugepage_sz, char *hugedir, int len)
>  		 * We found a match, but only prefer it if it's a longer match
>  		 * (so /mnt/1 is preferred over /mnt for matching /mnt/1/2)).
>  		 */
> -		if (strlen(splitstr[MOUNTPT]) > strlen(found))
> +		if (mountpt_len > strlen(found))
>  			strlcpy(found, splitstr[MOUNTPT], len);
>  	} /* end while fgets */

^ permalink raw reply	[flat|nested] 13+ messages in thread

* Re: [PATCH v2 1/1] eal/linux: reject --huge-dir not parent of mountpt
  2023-01-04  0:00 ` [PATCH v2 1/1] eal/linux: reject --huge-dir not parent of mountpt Ashish Sadanandan
  2023-01-04 11:24   ` Dmitry Kozlyuk
@ 2023-01-04 16:22   ` John Levon
  2023-01-04 18:17     ` Ashish Sadanandan
  1 sibling, 1 reply; 13+ messages in thread
From: John Levon @ 2023-01-04 16:22 UTC (permalink / raw)
  To: Ashish Sadanandan; +Cc: dev, stable

On Tue, Jan 03, 2023 at 05:00:30PM -0700, Ashish Sadanandan wrote:

> The code added for allowing --huge-dir to specify hugetlbfs
> sub-directories has a bug where it incorrectly matches mounts that
> contain a prefix of the specified --huge-dir.

Sorry for the trouble & thanks for the fix.

> +		/*
> +		 * Ignore any mount where hugepage_dir is not a parent path of
> +		 * the mount
> +		 */
> +		else if(hugepage_dir_len > mountpt_len &&
> +			internal_conf->hugepage_dir[mountpt_len] != '/') {
>  			continue;
>  		}

Shouldn't this comment say "Ignore any mount that is not a parent path of
hugepage_dir" ?

regards
john

^ permalink raw reply	[flat|nested] 13+ messages in thread

* [PATCH v3 1/1] eal/linux: reject --huge-dir not parent of mountpt
  2023-01-03 18:57 [PATCH 1/1] eal/linux: reject mountpt shorter than --huge-dir Ashish Sadanandan
  2023-01-03 23:53 ` Ashish Sadanandan
  2023-01-04  0:00 ` [PATCH v2 1/1] eal/linux: reject --huge-dir not parent of mountpt Ashish Sadanandan
@ 2023-01-04 18:17 ` Ashish Sadanandan
  2023-01-09  1:52 ` [PATCH v4 1/1] eal/linux: reject mountpt not parent of --huge-dir Ashish Sadanandan
  3 siblings, 0 replies; 13+ messages in thread
From: Ashish Sadanandan @ 2023-01-04 18:17 UTC (permalink / raw)
  To: dev; +Cc: Ashish Sadanandan, john.levon, stable

The code added for allowing --huge-dir to specify hugetlbfs
sub-directories has a bug where it incorrectly matches mounts that
contain a prefix of the specified --huge-dir.

Consider --huge-dir=/dev/hugepages1G is passed to rte_eal_init. Given
the following hugetlbfs mounts

$ mount | grep hugetlbfs
hugetlbfs on /dev/hugepages type hugetlbfs (rw,relatime,pagesize=2M)
hugetlbfs on /dev/hugepages1G type hugetlbfs (rw,relatime,pagesize=1024M)
hugetlbfs on /mnt/huge type hugetlbfs (rw,relatime,pagesize=2M)

get_hugepage_dir is first called with hugepage_sz=2097152. While
iterating over all mount points, /dev/hugepages is incorrectly
determined to be a match because it's a prefix of --huge-dir. The caller
then obtains an exclusive lock on --huge-dir.

In the next call to get_hugepage_dir, hugepage_sz=1073741824. This call
correctly determines /dev/hugepages1G is a match. The caller again
attempts to obtain an exclusive lock on --huge-dir and deadlocks because
it's already holding a lock.

This has been corrected by ensuring any matched mount point is either an
exact match or a parent path of --huge-dir.

Fixes: 24d5a1ce6b85 ("eal/linux: allow hugetlbfs sub-directories")
Cc: john.levon@nutanix.com
Cc: stable@dpdk.org
Signed-off-by: Ashish Sadanandan <ashish.sadanandan@gmail.com>
---
 lib/eal/linux/eal_hugepage_info.c | 15 +++++++++++----
 1 file changed, 11 insertions(+), 4 deletions(-)

diff --git a/lib/eal/linux/eal_hugepage_info.c b/lib/eal/linux/eal_hugepage_info.c
index a1b6cb31ff..e26e4d7a7a 100644
--- a/lib/eal/linux/eal_hugepage_info.c
+++ b/lib/eal/linux/eal_hugepage_info.c
@@ -214,6 +214,8 @@ get_hugepage_dir(uint64_t hugepage_sz, char *hugedir, int len)
 	char buf[BUFSIZ];
 	const struct internal_config *internal_conf =
 		eal_get_internal_configuration();
+	const size_t hugepage_dir_len = (internal_conf->hugepage_dir != NULL) ?
+		strlen(internal_conf->hugepage_dir) : 0;
 	struct stat st;
 
 	/*
@@ -233,6 +235,7 @@ get_hugepage_dir(uint64_t hugepage_sz, char *hugedir, int len)
 
 	while (fgets(buf, sizeof(buf), fd)){
 		const char *pagesz_str;
+		size_t mountpt_len = 0;
 
 		if (rte_strsplit(buf, sizeof(buf), splitstr, _FIELDNAME_MAX,
 				split_tok) != _FIELDNAME_MAX) {
@@ -265,12 +268,16 @@ get_hugepage_dir(uint64_t hugepage_sz, char *hugedir, int len)
 			break;
 		}
 
+		mountpt_len = strlen(splitstr[MOUNTPT]);
+
 		/*
-		 * Ignore any mount that doesn't contain the --huge-dir
-		 * directory.
+		 * Ignore any mount that doesn't contain the --huge-dir directory
+		 * or where mount point is not a parent path of --huge-dir
 		 */
 		if (strncmp(internal_conf->hugepage_dir, splitstr[MOUNTPT],
-			strlen(splitstr[MOUNTPT])) != 0) {
+				mountpt_len) != 0 ||
+			(hugepage_dir_len > mountpt_len &&
+				internal_conf->hugepage_dir[mountpt_len] != '/')) {
 			continue;
 		}
 
@@ -278,7 +285,7 @@ get_hugepage_dir(uint64_t hugepage_sz, char *hugedir, int len)
 		 * We found a match, but only prefer it if it's a longer match
 		 * (so /mnt/1 is preferred over /mnt for matching /mnt/1/2)).
 		 */
-		if (strlen(splitstr[MOUNTPT]) > strlen(found))
+		if (mountpt_len > strlen(found))
 			strlcpy(found, splitstr[MOUNTPT], len);
 	} /* end while fgets */
 
-- 
2.27.0


^ permalink raw reply	[flat|nested] 13+ messages in thread

* Re: [PATCH v2 1/1] eal/linux: reject --huge-dir not parent of mountpt
  2023-01-04 11:24   ` Dmitry Kozlyuk
@ 2023-01-04 18:17     ` Ashish Sadanandan
  0 siblings, 0 replies; 13+ messages in thread
From: Ashish Sadanandan @ 2023-01-04 18:17 UTC (permalink / raw)
  To: Dmitry Kozlyuk; +Cc: dev, john.levon, stable

[-- Attachment #1: Type: text/plain, Size: 618 bytes --]

On Wed, Jan 4, 2023 at 4:24 AM Dmitry Kozlyuk <dmitry.kozliuk@gmail.com>
wrote:

> 2023-01-03 17:00 (UTC-0700), Ashish Sadanandan:
> > The code added for allowing --huge-dir to specify hugetlbfs
> > sub-directories has a bug where it incorrectly matches mounts that
> > contain a prefix of the specified --huge-dir.
> >
>
> Acked-by: Dmitry Kozlyuk <dmitry.kozliuk@gmail.com>
>

Thanks for reviewing


>
> The second one can be done before the loop.
> Please declare all variables at the beginning of the block per code style.
>

Done


>
> Nit: maybe a single comment for both conditions would be more clear:
>

Done

[-- Attachment #2: Type: text/html, Size: 1426 bytes --]

^ permalink raw reply	[flat|nested] 13+ messages in thread

* Re: [PATCH v2 1/1] eal/linux: reject --huge-dir not parent of mountpt
  2023-01-04 16:22   ` John Levon
@ 2023-01-04 18:17     ` Ashish Sadanandan
  0 siblings, 0 replies; 13+ messages in thread
From: Ashish Sadanandan @ 2023-01-04 18:17 UTC (permalink / raw)
  To: John Levon; +Cc: dev, stable

[-- Attachment #1: Type: text/plain, Size: 585 bytes --]

On Wed, Jan 4, 2023 at 9:22 AM John Levon <john.levon@nutanix.com> wrote:

> On Tue, Jan 03, 2023 at 05:00:30PM -0700, Ashish Sadanandan wrote:
>
> > The code added for allowing --huge-dir to specify hugetlbfs
> > sub-directories has a bug where it incorrectly matches mounts that
> > contain a prefix of the specified --huge-dir.
>
> Sorry for the trouble & thanks for the fix.
>

Thanks for reviewing


>
> Shouldn't this comment say "Ignore any mount that is not a parent path of
> hugepage_dir" ?
>

Doh, typed the opposite of what I wanted to say :) Fixed.


>
> regards
> john
>

[-- Attachment #2: Type: text/html, Size: 1304 bytes --]

^ permalink raw reply	[flat|nested] 13+ messages in thread

* [PATCH v4 1/1] eal/linux: reject mountpt not parent of --huge-dir
  2023-01-03 18:57 [PATCH 1/1] eal/linux: reject mountpt shorter than --huge-dir Ashish Sadanandan
                   ` (2 preceding siblings ...)
  2023-01-04 18:17 ` [PATCH v3 " Ashish Sadanandan
@ 2023-01-09  1:52 ` Ashish Sadanandan
  2023-01-11 12:11   ` John Levon
  2023-02-10 11:01   ` David Marchand
  3 siblings, 2 replies; 13+ messages in thread
From: Ashish Sadanandan @ 2023-01-09  1:52 UTC (permalink / raw)
  To: dev; +Cc: Ashish Sadanandan, john.levon, stable

The code added for allowing --huge-dir to specify hugetlbfs
sub-directories has a bug where it incorrectly matches mounts that
contain a prefix of the specified --huge-dir.

Consider --huge-dir=/dev/hugepages1G is passed to rte_eal_init. Given
the following hugetlbfs mounts

$ mount | grep hugetlbfs
hugetlbfs on /dev/hugepages type hugetlbfs (rw,relatime,pagesize=2M)
hugetlbfs on /dev/hugepages1G type hugetlbfs (rw,relatime,pagesize=1024M)
hugetlbfs on /mnt/huge type hugetlbfs (rw,relatime,pagesize=2M)

get_hugepage_dir is first called with hugepage_sz=2097152. While
iterating over all mount points, /dev/hugepages is incorrectly
determined to be a match because it's a prefix of --huge-dir. The caller
then obtains an exclusive lock on --huge-dir.

In the next call to get_hugepage_dir, hugepage_sz=1073741824. This call
correctly determines /dev/hugepages1G is a match. The caller again
attempts to obtain an exclusive lock on --huge-dir and deadlocks because
it's already holding a lock.

This has been corrected by ensuring any matched mount point is either an
exact match or a parent path of --huge-dir.

Fixes: 24d5a1ce6b85 ("eal/linux: allow hugetlbfs sub-directories")
Cc: john.levon@nutanix.com
Cc: stable@dpdk.org
Signed-off-by: Ashish Sadanandan <ashish.sadanandan@gmail.com>
---
 lib/eal/linux/eal_hugepage_info.c | 15 +++++++++++----
 1 file changed, 11 insertions(+), 4 deletions(-)

diff --git a/lib/eal/linux/eal_hugepage_info.c b/lib/eal/linux/eal_hugepage_info.c
index a1b6cb31ff..e26e4d7a7a 100644
--- a/lib/eal/linux/eal_hugepage_info.c
+++ b/lib/eal/linux/eal_hugepage_info.c
@@ -214,6 +214,8 @@ get_hugepage_dir(uint64_t hugepage_sz, char *hugedir, int len)
 	char buf[BUFSIZ];
 	const struct internal_config *internal_conf =
 		eal_get_internal_configuration();
+	const size_t hugepage_dir_len = (internal_conf->hugepage_dir != NULL) ?
+		strlen(internal_conf->hugepage_dir) : 0;
 	struct stat st;
 
 	/*
@@ -233,6 +235,7 @@ get_hugepage_dir(uint64_t hugepage_sz, char *hugedir, int len)
 
 	while (fgets(buf, sizeof(buf), fd)){
 		const char *pagesz_str;
+		size_t mountpt_len = 0;
 
 		if (rte_strsplit(buf, sizeof(buf), splitstr, _FIELDNAME_MAX,
 				split_tok) != _FIELDNAME_MAX) {
@@ -265,12 +268,16 @@ get_hugepage_dir(uint64_t hugepage_sz, char *hugedir, int len)
 			break;
 		}
 
+		mountpt_len = strlen(splitstr[MOUNTPT]);
+
 		/*
-		 * Ignore any mount that doesn't contain the --huge-dir
-		 * directory.
+		 * Ignore any mount that doesn't contain the --huge-dir directory
+		 * or where mount point is not a parent path of --huge-dir
 		 */
 		if (strncmp(internal_conf->hugepage_dir, splitstr[MOUNTPT],
-			strlen(splitstr[MOUNTPT])) != 0) {
+				mountpt_len) != 0 ||
+			(hugepage_dir_len > mountpt_len &&
+				internal_conf->hugepage_dir[mountpt_len] != '/')) {
 			continue;
 		}
 
@@ -278,7 +285,7 @@ get_hugepage_dir(uint64_t hugepage_sz, char *hugedir, int len)
 		 * We found a match, but only prefer it if it's a longer match
 		 * (so /mnt/1 is preferred over /mnt for matching /mnt/1/2)).
 		 */
-		if (strlen(splitstr[MOUNTPT]) > strlen(found))
+		if (mountpt_len > strlen(found))
 			strlcpy(found, splitstr[MOUNTPT], len);
 	} /* end while fgets */
 
-- 
2.27.0


^ permalink raw reply	[flat|nested] 13+ messages in thread

* Re: [PATCH v4 1/1] eal/linux: reject mountpt not parent of --huge-dir
  2023-01-09  1:52 ` [PATCH v4 1/1] eal/linux: reject mountpt not parent of --huge-dir Ashish Sadanandan
@ 2023-01-11 12:11   ` John Levon
  2023-01-16 18:25     ` Ashish Sadanandan
  2023-02-10 11:01   ` David Marchand
  1 sibling, 1 reply; 13+ messages in thread
From: John Levon @ 2023-01-11 12:11 UTC (permalink / raw)
  To: Ashish Sadanandan; +Cc: dev, stable

On Sun, Jan 08, 2023 at 06:52:39PM -0700, Ashish Sadanandan wrote:

> The code added for allowing --huge-dir to specify hugetlbfs
> sub-directories has a bug where it incorrectly matches mounts that
> contain a prefix of the specified --huge-dir.
> 
> Consider --huge-dir=/dev/hugepages1G is passed to rte_eal_init. Given
> the following hugetlbfs mounts
> 
> $ mount | grep hugetlbfs
> hugetlbfs on /dev/hugepages type hugetlbfs (rw,relatime,pagesize=2M)
> hugetlbfs on /dev/hugepages1G type hugetlbfs (rw,relatime,pagesize=1024M)
> hugetlbfs on /mnt/huge type hugetlbfs (rw,relatime,pagesize=2M)
> 
> get_hugepage_dir is first called with hugepage_sz=2097152. While
> iterating over all mount points, /dev/hugepages is incorrectly
> determined to be a match because it's a prefix of --huge-dir. The caller
> then obtains an exclusive lock on --huge-dir.
> 
> In the next call to get_hugepage_dir, hugepage_sz=1073741824. This call
> correctly determines /dev/hugepages1G is a match. The caller again
> attempts to obtain an exclusive lock on --huge-dir and deadlocks because
> it's already holding a lock.
> 
> This has been corrected by ensuring any matched mount point is either an
> exact match or a parent path of --huge-dir.
> 
> Fixes: 24d5a1ce6b85 ("eal/linux: allow hugetlbfs sub-directories")
> Cc: john.levon@nutanix.com
> Cc: stable@dpdk.org
> Signed-off-by: Ashish Sadanandan <ashish.sadanandan@gmail.com>

Reviewed-by: John Levon <john.levon@nutanix.com>

thanks
john

^ permalink raw reply	[flat|nested] 13+ messages in thread

* Re: [PATCH v4 1/1] eal/linux: reject mountpt not parent of --huge-dir
  2023-01-11 12:11   ` John Levon
@ 2023-01-16 18:25     ` Ashish Sadanandan
  2023-02-10 11:04       ` David Marchand
  0 siblings, 1 reply; 13+ messages in thread
From: Ashish Sadanandan @ 2023-01-16 18:25 UTC (permalink / raw)
  To: John Levon; +Cc: dev, stable

[-- Attachment #1: Type: text/plain, Size: 796 bytes --]

On Wed, Jan 11, 2023 at 5:11 AM John Levon <john.levon@nutanix.com> wrote:

> On Sun, Jan 08, 2023 at 06:52:39PM -0700, Ashish Sadanandan wrote:
>
> > The code added for allowing --huge-dir to specify hugetlbfs
> > sub-directories has a bug where it incorrectly matches mounts that
> > contain a prefix of the specified --huge-dir.
> >
> > Fixes: 24d5a1ce6b85 ("eal/linux: allow hugetlbfs sub-directories")
> > Cc: john.levon@nutanix.com
> > Cc: stable@dpdk.org
> > Signed-off-by: Ashish Sadanandan <ashish.sadanandan@gmail.com>
>
> Reviewed-by: John Levon <john.levon@nutanix.com>
>
> thanks
> john
>

Thanks for reviewing again, John. Do I need to CC anyone else to get this
committed or any other steps I need to follow? I was hoping to get this
merged into 22.11 stable branch too.

- Ashish

[-- Attachment #2: Type: text/html, Size: 1457 bytes --]

^ permalink raw reply	[flat|nested] 13+ messages in thread

* Re: [PATCH v4 1/1] eal/linux: reject mountpt not parent of --huge-dir
  2023-01-09  1:52 ` [PATCH v4 1/1] eal/linux: reject mountpt not parent of --huge-dir Ashish Sadanandan
  2023-01-11 12:11   ` John Levon
@ 2023-02-10 11:01   ` David Marchand
  1 sibling, 0 replies; 13+ messages in thread
From: David Marchand @ 2023-02-10 11:01 UTC (permalink / raw)
  To: Ashish Sadanandan
  Cc: dev, john.levon, stable, Meunier, Julien (Nokia - FR/Paris-Saclay)

On Mon, Jan 9, 2023 at 2:52 AM Ashish Sadanandan
<ashish.sadanandan@gmail.com> wrote:
>
> The code added for allowing --huge-dir to specify hugetlbfs
> sub-directories has a bug where it incorrectly matches mounts that
> contain a prefix of the specified --huge-dir.
>
> Consider --huge-dir=/dev/hugepages1G is passed to rte_eal_init. Given
> the following hugetlbfs mounts
>
> $ mount | grep hugetlbfs
> hugetlbfs on /dev/hugepages type hugetlbfs (rw,relatime,pagesize=2M)
> hugetlbfs on /dev/hugepages1G type hugetlbfs (rw,relatime,pagesize=1024M)
> hugetlbfs on /mnt/huge type hugetlbfs (rw,relatime,pagesize=2M)
>
> get_hugepage_dir is first called with hugepage_sz=2097152. While
> iterating over all mount points, /dev/hugepages is incorrectly
> determined to be a match because it's a prefix of --huge-dir. The caller
> then obtains an exclusive lock on --huge-dir.
>
> In the next call to get_hugepage_dir, hugepage_sz=1073741824. This call
> correctly determines /dev/hugepages1G is a match. The caller again
> attempts to obtain an exclusive lock on --huge-dir and deadlocks because
> it's already holding a lock.
>
> This has been corrected by ensuring any matched mount point is either an
> exact match or a parent path of --huge-dir.
>
> Fixes: 24d5a1ce6b85 ("eal/linux: allow hugetlbfs sub-directories")
> Cc: stable@dpdk.org

> Signed-off-by: Ashish Sadanandan <ashish.sadanandan@gmail.com>
Reviewed-by: John Levon <john.levon@nutanix.com>

I got pinged by Julien who reported a similar issue.
He confirmed later that this fix works for him too.

Tested-by: Julien Meunier <julien.meunier@nokia.com>


Applied, thanks Ashish.

-- 
David Marchand


^ permalink raw reply	[flat|nested] 13+ messages in thread

* Re: [PATCH v4 1/1] eal/linux: reject mountpt not parent of --huge-dir
  2023-01-16 18:25     ` Ashish Sadanandan
@ 2023-02-10 11:04       ` David Marchand
  0 siblings, 0 replies; 13+ messages in thread
From: David Marchand @ 2023-02-10 11:04 UTC (permalink / raw)
  To: Ashish Sadanandan; +Cc: John Levon, dev, stable

On Mon, Jan 16, 2023 at 7:26 PM Ashish Sadanandan
<ashish.sadanandan@gmail.com> wrote:
> On Wed, Jan 11, 2023 at 5:11 AM John Levon <john.levon@nutanix.com> wrote:
>> On Sun, Jan 08, 2023 at 06:52:39PM -0700, Ashish Sadanandan wrote:
>>
>> > The code added for allowing --huge-dir to specify hugetlbfs
>> > sub-directories has a bug where it incorrectly matches mounts that
>> > contain a prefix of the specified --huge-dir.
>> >
>> > Fixes: 24d5a1ce6b85 ("eal/linux: allow hugetlbfs sub-directories")
>> > Cc: john.levon@nutanix.com
>> > Cc: stable@dpdk.org
>> > Signed-off-by: Ashish Sadanandan <ashish.sadanandan@gmail.com>
>>
>> Reviewed-by: John Levon <john.levon@nutanix.com>
>>
>> thanks
>> john
>
>
> Thanks for reviewing again, John. Do I need to CC anyone else to get this committed or any other steps I need to follow? I was hoping to get this merged into 22.11 stable branch too.

You already did what was necessary, by putting a Fixes: tag and adding
Cc: stable@dpdk.org in the commitlog.

LTS maintainers scripts will catch this fix later, and it will likely
end up in 22.11 and 21.11 branches.


-- 
David Marchand


^ permalink raw reply	[flat|nested] 13+ messages in thread

end of thread, other threads:[~2023-02-10 11:04 UTC | newest]

Thread overview: 13+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-01-03 18:57 [PATCH 1/1] eal/linux: reject mountpt shorter than --huge-dir Ashish Sadanandan
2023-01-03 23:53 ` Ashish Sadanandan
2023-01-04  0:00 ` [PATCH v2 1/1] eal/linux: reject --huge-dir not parent of mountpt Ashish Sadanandan
2023-01-04 11:24   ` Dmitry Kozlyuk
2023-01-04 18:17     ` Ashish Sadanandan
2023-01-04 16:22   ` John Levon
2023-01-04 18:17     ` Ashish Sadanandan
2023-01-04 18:17 ` [PATCH v3 " Ashish Sadanandan
2023-01-09  1:52 ` [PATCH v4 1/1] eal/linux: reject mountpt not parent of --huge-dir Ashish Sadanandan
2023-01-11 12:11   ` John Levon
2023-01-16 18:25     ` Ashish Sadanandan
2023-02-10 11:04       ` David Marchand
2023-02-10 11:01   ` David Marchand

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).