Skip to contentSkip to conversation

eal/linux: reject mountpt shorter than --huge-dir

PATCH In review Ashish Sadanandan 4 participants 13 messages Jan 3, 2023 – Feb 10, 2023

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 eal/linux: reject mountpt shorter than --huge-dir

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")
---
 lib/eal/linux/eal_hugepage_info.c | 11 +++++++----
 1 file changed, 7 insertions(+), 4 deletions(-)
lib/eal/linux/eal_hugepage_info.c +7 -4
index a1b6cb31ff..fcc3d82fdf 100644
@@ -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 */
 
Signature · 1 line
2.27.0
#1 lore raw

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

Quoted 69 lines · 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 rejecting the mount point being considered if its length is smaller than the specified --huge-dir.

Fixes 24d5a1ce6b85 ("eal/linux: allow hugetlbfs sub-directories")
---
 lib/eal/linux/eal_hugepage_info.c | 11 +++++++----
 1 file changed, 7 insertions(+), 4 deletions(-)
lib/eal/linux/eal_hugepage_info.c +6 -3
index a1b6cb31ff..fcc3d82fdf 100644
@@ -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)).

                 */
lib/eal/linux/eal_hugepage_info.c +1 -2
-               if (strlen(splitstr[MOUNTPT]) > strlen(found))
+               if (mountpt_len > strlen(found))
                        strlcpy(found, splitstr[MOUNTPT], len);
        } /* end while fgets */
 
--

2.27.0

#2 lore raw

PATCH v2 1/1 eal/linux: reject --huge-dir not parent of mountpt

In reply to 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")
---
 lib/eal/linux/eal_hugepage_info.c | 15 +++++++++++++--
 1 file changed, 13 insertions(+), 2 deletions(-)
lib/eal/linux/eal_hugepage_info.c +13 -2
index a1b6cb31ff..180abd930c 100644
@@ -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 */
 
Signature · 1 line
2.27.0
Acked-by on v2 1/1
#3 lore raw

Re: [PATCH v2 1/1] eal/linux: reject --huge-dir not parent of mountpt

2023-01-03 17:00 (UTC-0700), Ashish Sadanandan:

Quoted 22 lines

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.

Quoted 7 lines

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")
Quoted 9 lines
---
 lib/eal/linux/eal_hugepage_info.c | 15 +++++++++++++--
 1 file changed, 13 insertions(+), 2 deletions(-)
lib/eal/linux/eal_hugepage_info.c +0 -0
index a1b6cb31ff..180abd930c 100644

lib/eal/linux/eal_hugepage_info.c get_hugepage_dir(uint64_t hugepage_sz, char *hugedir, int len) · line 269

Quoted 5 lines
lib/eal/linux/eal_hugepage_info.c +2 -0
@@ -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.

Quoted 6 lines
lib/eal/linux/eal_hugepage_info.c +1 -0
+
 		/*
 		 * Ignore any mount that doesn't contain the --huge-dir
 		 * directory.
 		 */
 		if (strncmp(internal_conf->hugepage_dir, splitstr[MOUNTPT],

lib/eal/linux/eal_hugepage_info.c get_hugepage_dir(uint64_t hugepage_sz, char *hugedir, int len) · line 284

Quoted 10 lines
lib/eal/linux/eal_hugepage_info.c +9 -1
-			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. */

Quoted 11 lines
lib/eal/linux/eal_hugepage_info.c +1 -1
 			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 */
#4 lore raw

Re: [PATCH v2 1/1] eal/linux: reject --huge-dir not parent of mountpt

Quoted 8 lines · Dmitry Kozlyuk

2023-01-03 17:00 (UTC-0700), Ashish Sadanandan:

Quoted 4 lines

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.

Thanks for reviewing

Quoted 4 lines

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

Done

Quoted 3 lines

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

Done

#5 lore raw

Re: [PATCH v2 1/1] eal/linux: reject --huge-dir not parent of mountpt

In reply to Ashish Sadanandan
Quoted 3 lines · 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.

Sorry for the trouble & thanks for the fix.

lib/eal/linux/eal_hugepage_info.c get_hugepage_dir(uint64_t hugepage_sz, char *hugedir, int len) · line 286

Quoted 8 lines
lib/eal/linux/eal_hugepage_info.c +6 -0
+		/*
+		 * 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

#6 lore raw

Re: [PATCH v2 1/1] eal/linux: reject --huge-dir not parent of mountpt

Quoted 8 lines · John Levon
Quoted 3 lines · 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.

Sorry for the trouble & thanks for the fix.

Thanks for reviewing

Quoted 4 lines

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.

Quoted 4 lines

regards
john

#7 lore raw

PATCH v3 1/1 eal/linux: reject --huge-dir not parent of mountpt

In reply to 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")
---
 lib/eal/linux/eal_hugepage_info.c | 15 +++++++++++----
 1 file changed, 11 insertions(+), 4 deletions(-)
lib/eal/linux/eal_hugepage_info.c +11 -4
index a1b6cb31ff..e26e4d7a7a 100644
@@ -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 */
 
Signature · 1 line
2.27.0
#8 lore raw

PATCH v4 1/1 eal/linux: reject mountpt not parent of --huge-dir

In reply to 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")
---
 lib/eal/linux/eal_hugepage_info.c | 15 +++++++++++----
 1 file changed, 11 insertions(+), 4 deletions(-)
lib/eal/linux/eal_hugepage_info.c +11 -4
index a1b6cb31ff..e26e4d7a7a 100644
@@ -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 */
 
Signature · 1 line
2.27.0
Reviewed-by on v4 1/1
#9 lore raw

Re: [PATCH v4 1/1] eal/linux: reject mountpt not parent of --huge-dir

Quoted 22 lines · 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.

Quoted 7 lines

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

thanks
john

#10 lore raw

Re: [PATCH v4 1/1] eal/linux: reject mountpt not parent of --huge-dir

Quoted 11 lines · John Levon
Quoted 8 lines · 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.

Fixes 24d5a1ce6b85 ("eal/linux: allow hugetlbfs sub-directories")
Quoted 5 lines

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

#11 lore raw

Re: [PATCH v4 1/1] eal/linux: reject mountpt not parent of --huge-dir

Quoted 12 lines · Ashish Sadanandan
Quoted 11 lines · John Levon
Quoted 8 lines · 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.

Fixes 24d5a1ce6b85 ("eal/linux: allow hugetlbfs sub-directories")
Quoted 7 lines
Quoted 4 lines

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: [email protected] in the commitlog.

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

Signature · 1 line
David Marchand
Reviewed-by John Levon Tested-by Julien Meunier on v4 1/1 Applied
#12 lore raw

Re: [PATCH v4 1/1] eal/linux: reject mountpt not parent of --huge-dir

In reply to Ashish Sadanandan
Quoted 23 lines · 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.

Quoted 7 lines

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

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

Applied, thanks Ashish.

Signature · 1 line
David Marchand