public inbox for libc-alpha@sourceware.org
 help / color / mirror / Atom feed
* [PATCH] elf: Fix marking root dir as nonexist in open_path
@ 2023-05-08 15:45 Moody Liu
  2023-05-08 20:04 ` Carlos O'Donell
                   ` (2 more replies)
  0 siblings, 3 replies; 9+ messages in thread
From: Moody Liu @ 2023-05-08 15:45 UTC (permalink / raw)
  To: libc-alpha; +Cc: Moody Liu, Qixing ksyx Xue

When dlopen is being called, efforts have been made to improve
future lookup performance. This includes marking a search path
as non-existent using `stat`. However, if the root directory
is given as a search path, there exists a bug which erroneously
marks it as non-existing.

The bug is reproduced under the following sequence:

  1. dlopen is called to open a shared library, with at least:
     1) a dependency 'A.so' not directly under the '/' directory
        (e.g. /lib/A.so), and
     2) another dependency 'B.so' resides in '/'.
  2. for this bug to reproduce, 'A.so' should be searched *before* 'B.so'.
  3. it first tries to find 'A.so' in /, (e.g. /A.so):
     - this will (obviously) fail,
     - since it's the first time we have seen the '/' directory,
       its 'status' is 'unknown'.
  4. `buf[buflen - namelen - 1] = '\0'` is executed:
     - it intends to remove the leaf and its final slash,
     - because of the speciality of '/', its buflen == namelen + 1,
     - it erroneously clears the entire buffer.
  6. it then calls 'stat' with the empty buffer:
     - which will result in an error.
  7. so it marks '/' as 'nonexisting', future lookups will not consider
     this path.
  8. while /B.so *does* exist, failure to look it up in the '/'
     directory leads to a 'cannot open shared object file' error.

This patch fixes the bug by preventing 'buflen', an index to put '\0',
from being set to 0, so that the root '/' is always kept.
Relative search paths are always considered as 'existing' so this
wont be affected.

Suggested-by: Qixing ksyx Xue <qixingxue@outlook.com>
---
 elf/dl-load.c | 6 +++++-
 1 file changed, 5 insertions(+), 1 deletion(-)

diff --git a/elf/dl-load.c b/elf/dl-load.c
index fcb39a78d4..10757dd5a5 100644
--- a/elf/dl-load.c
+++ b/elf/dl-load.c
@@ -1865,7 +1865,11 @@ open_path (const char *name, size_t namelen, int mode,
 		     test whether there is any directory at all.  */
 		  struct __stat64_t64 st;
 
-		  buf[buflen - namelen - 1] = '\0';
+		  /* We only have absolute paths go into this branch.
+		     In the rare case where 'this_dir' is only a '/', we
+		     must keep it.  */
+		  buflen = MAX(buflen - namelen - 1, 1);
+		  buf[buflen] = '\0';
 
 		  if (__stat64_time64 (buf, &st) != 0
 		      || ! S_ISDIR (st.st_mode))
-- 
2.40.1


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

* Re: [PATCH] elf: Fix marking root dir as nonexist in open_path
  2023-05-08 15:45 [PATCH] elf: Fix marking root dir as nonexist in open_path Moody Liu
@ 2023-05-08 20:04 ` Carlos O'Donell
  2023-05-09 22:56 ` [PATCH v2 1/2] elf: Fix marking root dir as nonexist in open_path (bug 30435) Qixing ksyx Xue
  2023-05-09 22:56 ` [PATCH v2 2/2] elf: Add test for finding libraries in root dir Qixing ksyx Xue
  2 siblings, 0 replies; 9+ messages in thread
From: Carlos O'Donell @ 2023-05-08 20:04 UTC (permalink / raw)
  To: Moody Liu, libc-alpha; +Cc: Qixing ksyx Xue

On 5/8/23 11:45, Moody Liu via Libc-alpha wrote:
> When dlopen is being called, efforts have been made to improve
> future lookup performance. This includes marking a search path
> as non-existent using `stat`. However, if the root directory
> is given as a search path, there exists a bug which erroneously
> marks it as non-existing.

Thanks for working on the patch.

Could you please file a bug in bugzilla for this?

> 
> The bug is reproduced under the following sequence:
> 
>   1. dlopen is called to open a shared library, with at least:
>      1) a dependency 'A.so' not directly under the '/' directory
>         (e.g. /lib/A.so), and
>      2) another dependency 'B.so' resides in '/'.

Are you able to write a containerized test case for this?

We have tests-container testing for just such "/" scenarios with a distinct
mount namespace for the tests.

>   2. for this bug to reproduce, 'A.so' should be searched *before* 'B.so'.
>   3. it first tries to find 'A.so' in /, (e.g. /A.so):
>      - this will (obviously) fail,
>      - since it's the first time we have seen the '/' directory,
>        its 'status' is 'unknown'.
>   4. `buf[buflen - namelen - 1] = '\0'` is executed:
>      - it intends to remove the leaf and its final slash,
>      - because of the speciality of '/', its buflen == namelen + 1,
>      - it erroneously clears the entire buffer.
>   6. it then calls 'stat' with the empty buffer:
>      - which will result in an error.
>   7. so it marks '/' as 'nonexisting', future lookups will not consider
>      this path.
>   8. while /B.so *does* exist, failure to look it up in the '/'
>      directory leads to a 'cannot open shared object file' error.
> 
> This patch fixes the bug by preventing 'buflen', an index to put '\0',
> from being set to 0, so that the root '/' is always kept.
> Relative search paths are always considered as 'existing' so this
> wont be affected.
> 
> Suggested-by: Qixing ksyx Xue <qixingxue@outlook.com>
> ---
>  elf/dl-load.c | 6 +++++-
>  1 file changed, 5 insertions(+), 1 deletion(-)
> 
> diff --git a/elf/dl-load.c b/elf/dl-load.c
> index fcb39a78d4..10757dd5a5 100644
> --- a/elf/dl-load.c
> +++ b/elf/dl-load.c
> @@ -1865,7 +1865,11 @@ open_path (const char *name, size_t namelen, int mode,
>  		     test whether there is any directory at all.  */
>  		  struct __stat64_t64 st;
>  
> -		  buf[buflen - namelen - 1] = '\0';
> +		  /* We only have absolute paths go into this branch.
> +		     In the rare case where 'this_dir' is only a '/', we
> +		     must keep it.  */
> +		  buflen = MAX(buflen - namelen - 1, 1);
> +		  buf[buflen] = '\0';

>  
>  		  if (__stat64_time64 (buf, &st) != 0
>  		      || ! S_ISDIR (st.st_mode))

-- 
Cheers,
Carlos.


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

* [PATCH v2 1/2] elf: Fix marking root dir as nonexist in open_path (bug 30435)
  2023-05-08 15:45 [PATCH] elf: Fix marking root dir as nonexist in open_path Moody Liu
  2023-05-08 20:04 ` Carlos O'Donell
@ 2023-05-09 22:56 ` Qixing ksyx Xue
  2023-05-09 22:56 ` [PATCH v2 2/2] elf: Add test for finding libraries in root dir Qixing ksyx Xue
  2 siblings, 0 replies; 9+ messages in thread
From: Qixing ksyx Xue @ 2023-05-09 22:56 UTC (permalink / raw)
  To: libc-alpha, carlos; +Cc: mooodyhunter, Qixing ksyx Xue

From: Moody Liu <mooodyhunter@outlook.com>

When dlopen is being called, efforts have been made to improve
future lookup performance. This includes marking a search path
as non-existent using `stat`. However, if the root directory
is given as a search path, there exists a bug which erroneously
marks it as non-existing.

The bug is reproduced under the following sequence:

  1. dlopen is called to open a shared library, with at least:
     1) a dependency 'A.so' not directly under the '/' directory
        (e.g. /lib/A.so), and
     2) another dependency 'B.so' resides in '/'.
  2. for this bug to reproduce, 'A.so' should be searched *before* 'B.so'.
  3. it first tries to find 'A.so' in /, (e.g. /A.so):
     - this will (obviously) fail,
     - since it's the first time we have seen the '/' directory,
       its 'status' is 'unknown'.
  4. `buf[buflen - namelen - 1] = '\0'` is executed:
     - it intends to remove the leaf and its final slash,
     - because of the speciality of '/', its buflen == namelen + 1,
     - it erroneously clears the entire buffer.
  6. it then calls 'stat' with the empty buffer:
     - which will result in an error.
  7. so it marks '/' as 'nonexisting', future lookups will not consider
     this path.
  8. while /B.so *does* exist, failure to look it up in the '/'
     directory leads to a 'cannot open shared object file' error.

This patch fixes the bug by preventing 'buflen', an index to put '\0',
from being set to 0, so that the root '/' is always kept.
Relative search paths are always considered as 'existing' so this
wont be affected.

Suggested-by: Qixing ksyx Xue <qixingxue@outlook.com>
---
 elf/dl-load.c | 6 +++++-
 1 file changed, 5 insertions(+), 1 deletion(-)

diff --git a/elf/dl-load.c b/elf/dl-load.c
index 9a0e40c0e9..36cf635c03 100644
--- a/elf/dl-load.c
+++ b/elf/dl-load.c
@@ -1855,7 +1855,11 @@ open_path (const char *name, size_t namelen, int mode,
 		     test whether there is any directory at all.  */
 		  struct __stat64_t64 st;
 
-		  buf[buflen - namelen - 1] = '\0';
+		  /* We only have absolute paths go into this branch.
+		     In the rare case where 'this_dir' is only a '/', we
+		     must keep it.  */
+		  buflen = MAX(buflen - namelen - 1, 1);
+		  buf[buflen] = '\0';
 
 		  if (__stat64_time64 (buf, &st) != 0
 		      || ! S_ISDIR (st.st_mode))
-- 
2.25.1


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

* [PATCH v2 2/2] elf: Add test for finding libraries in root dir
  2023-05-08 15:45 [PATCH] elf: Fix marking root dir as nonexist in open_path Moody Liu
  2023-05-08 20:04 ` Carlos O'Donell
  2023-05-09 22:56 ` [PATCH v2 1/2] elf: Fix marking root dir as nonexist in open_path (bug 30435) Qixing ksyx Xue
@ 2023-05-09 22:56 ` Qixing ksyx Xue
  2023-05-25 12:51   ` Siddhesh Poyarekar
  2 siblings, 1 reply; 9+ messages in thread
From: Qixing ksyx Xue @ 2023-05-09 22:56 UTC (permalink / raw)
  To: libc-alpha, carlos; +Cc: mooodyhunter, Qixing ksyx Xue

Suggested-by: Carlos O'Donell <carlos@redhat.com>
Signed-off-by: Qixing ksyx Xue <qixingxue@outlook.com>
---
 elf/Makefile                      |  3 +++
 elf/tst-rootdir-lib.c             | 23 +++++++++++++++++++
 elf/tst-rootdir.c                 | 37 +++++++++++++++++++++++++++++++
 elf/tst-rootdir.root/preclean.req |  0
 elf/tst-rootdir.script            |  1 +
 5 files changed, 64 insertions(+)
 create mode 100644 elf/tst-rootdir-lib.c
 create mode 100644 elf/tst-rootdir.c
 create mode 100644 elf/tst-rootdir.root/preclean.req
 create mode 100644 elf/tst-rootdir.script

diff --git a/elf/Makefile b/elf/Makefile
index 396ec51424..ee81575cbb 100644
--- a/elf/Makefile
+++ b/elf/Makefile
@@ -325,6 +325,7 @@ static-dlopen-environment = \
   LD_LIBRARY_PATH=$(ld-library-path):$(common-objpfx)dlfcn
 tst-tls9-static-ENV = $(static-dlopen-environment)
 tst-single_threaded-static-dlopen-ENV = $(static-dlopen-environment)
+tst-rootdir-ENV = LD_LIBRARY_PATH=/
 
 tests += \
   argv0test \
@@ -506,6 +507,7 @@ tests-container += \
   tst-dlopen-tlsmodid-container \
   tst-pldd \
   tst-preload-pthread-libc \
+  tst-rootdir \
   # tests-container
 
 test-srcs = \
@@ -854,6 +856,7 @@ modules-names += \
   tst-relsort1mod1 \
   tst-relsort1mod2 \
   tst-ro-dynamic-mod \
+  tst-rootdir-lib \
   tst-single_threaded-mod1 \
   tst-single_threaded-mod2 \
   tst-single_threaded-mod3 \
diff --git a/elf/tst-rootdir-lib.c b/elf/tst-rootdir-lib.c
new file mode 100644
index 0000000000..22b7bdad70
--- /dev/null
+++ b/elf/tst-rootdir-lib.c
@@ -0,0 +1,23 @@
+/* Simple library for testing locating library in root directories.
+   Copyright (C) 2023 Free Software Foundation, Inc.
+   This file is part of the GNU C Library.
+
+   The GNU C Library is free software; you can redistribute it and/or
+   modify it under the terms of the GNU Lesser General Public
+   License as published by the Free Software Foundation; either
+   version 2.1 of the License, or (at your option) any later version.
+
+   The GNU C Library is distributed in the hope that it will be useful,
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+   Lesser General Public License for more details.
+
+   You should have received a copy of the GNU Lesser General Public
+   License along with the GNU C Library; if not, see
+   <http://www.gnu.org/licenses/>.  */
+
+const char *
+test_func (void)
+{
+  return "Success";
+}
diff --git a/elf/tst-rootdir.c b/elf/tst-rootdir.c
new file mode 100644
index 0000000000..a31d4237af
--- /dev/null
+++ b/elf/tst-rootdir.c
@@ -0,0 +1,37 @@
+/* Test code for locating libraries in root directories.
+   Copyright (C) 2023 Free Software Foundation, Inc.
+   This file is part of the GNU C Library.
+
+   The GNU C Library is free software; you can redistribute it and/or
+   modify it under the terms of the GNU Lesser General Public
+   License as published by the Free Software Foundation; either
+   version 2.1 of the License, or (at your option) any later version.
+
+   The GNU C Library is distributed in the hope that it will be useful,
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+   Lesser General Public License for more details.
+
+   You should have received a copy of the GNU Lesser General Public
+   License along with the GNU C Library; if not, see
+   <http://www.gnu.org/licenses/>.  */
+
+#include <support/test-driver.h>
+#include <support/check.h>
+#include <dlfcn.h>
+#include <assert.h>
+
+static int
+do_test (void)
+{
+  void *handle = dlopen ("libtest.so", RTLD_LAZY);
+  TEST_VERIFY_EXIT (handle != NULL);
+  typedef const char *(test_func_t) (void);
+  test_func_t *func = dlsym (handle, "test_func");
+  assert (func != NULL);
+  TEST_COMPARE_STRING (func (), "Success");
+  dlclose (handle);
+  return 0;
+}
+
+#include <support/test-driver.c>
diff --git a/elf/tst-rootdir.root/preclean.req b/elf/tst-rootdir.root/preclean.req
new file mode 100644
index 0000000000..e69de29bb2
diff --git a/elf/tst-rootdir.script b/elf/tst-rootdir.script
new file mode 100644
index 0000000000..f852c0ec34
--- /dev/null
+++ b/elf/tst-rootdir.script
@@ -0,0 +1 @@
+cp $B/elf/tst-rootdir-lib.so /libtest.so
-- 
2.25.1


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

* Re: [PATCH v2 2/2] elf: Add test for finding libraries in root dir
  2023-05-09 22:56 ` [PATCH v2 2/2] elf: Add test for finding libraries in root dir Qixing ksyx Xue
@ 2023-05-25 12:51   ` Siddhesh Poyarekar
  2023-05-25 13:29     ` [PATCH v3] elf: Add test for locating libraries in root dir (bug 30435) Qixing ksyx Xue
  0 siblings, 1 reply; 9+ messages in thread
From: Siddhesh Poyarekar @ 2023-05-25 12:51 UTC (permalink / raw)
  To: Qixing ksyx Xue, libc-alpha, carlos; +Cc: mooodyhunter

On 2023-05-09 18:56, Qixing ksyx Xue via Libc-alpha wrote:
> Suggested-by: Carlos O'Donell <carlos@redhat.com>
> Signed-off-by: Qixing ksyx Xue <qixingxue@outlook.com>
> ---
>   elf/Makefile                      |  3 +++
>   elf/tst-rootdir-lib.c             | 23 +++++++++++++++++++
>   elf/tst-rootdir.c                 | 37 +++++++++++++++++++++++++++++++
>   elf/tst-rootdir.root/preclean.req |  0
>   elf/tst-rootdir.script            |  1 +
>   5 files changed, 64 insertions(+)
>   create mode 100644 elf/tst-rootdir-lib.c
>   create mode 100644 elf/tst-rootdir.c
>   create mode 100644 elf/tst-rootdir.root/preclean.req
>   create mode 100644 elf/tst-rootdir.script

Sorry, I acked Andreas' patch to fix the same issue; it's also a 
slightly cleaner fix.  It didn't have a test case though, so thank you 
for writing the test!  Could you please send a v3 of the test with the 
following nits fixed and also quote the BZ number in the subject?

Thanks,
Sid

> 
> diff --git a/elf/Makefile b/elf/Makefile
> index 396ec51424..ee81575cbb 100644
> --- a/elf/Makefile
> +++ b/elf/Makefile
> @@ -325,6 +325,7 @@ static-dlopen-environment = \
>     LD_LIBRARY_PATH=$(ld-library-path):$(common-objpfx)dlfcn
>   tst-tls9-static-ENV = $(static-dlopen-environment)
>   tst-single_threaded-static-dlopen-ENV = $(static-dlopen-environment)
> +tst-rootdir-ENV = LD_LIBRARY_PATH=/
>   
>   tests += \
>     argv0test \
> @@ -506,6 +507,7 @@ tests-container += \
>     tst-dlopen-tlsmodid-container \
>     tst-pldd \
>     tst-preload-pthread-libc \
> +  tst-rootdir \
>     # tests-container
>   
>   test-srcs = \
> @@ -854,6 +856,7 @@ modules-names += \
>     tst-relsort1mod1 \
>     tst-relsort1mod2 \
>     tst-ro-dynamic-mod \
> +  tst-rootdir-lib \
>     tst-single_threaded-mod1 \
>     tst-single_threaded-mod2 \
>     tst-single_threaded-mod3 \
> diff --git a/elf/tst-rootdir-lib.c b/elf/tst-rootdir-lib.c
> new file mode 100644
> index 0000000000..22b7bdad70
> --- /dev/null
> +++ b/elf/tst-rootdir-lib.c
> @@ -0,0 +1,23 @@
> +/* Simple library for testing locating library in root directories.
> +   Copyright (C) 2023 Free Software Foundation, Inc.

Please change this to "Copyright The GNU Toolchain Authors." for both files.

> +   This file is part of the GNU C Library.
> +
> +   The GNU C Library is free software; you can redistribute it and/or
> +   modify it under the terms of the GNU Lesser General Public
> +   License as published by the Free Software Foundation; either
> +   version 2.1 of the License, or (at your option) any later version.
> +
> +   The GNU C Library is distributed in the hope that it will be useful,
> +   but WITHOUT ANY WARRANTY; without even the implied warranty of
> +   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
> +   Lesser General Public License for more details.
> +
> +   You should have received a copy of the GNU Lesser General Public
> +   License along with the GNU C Library; if not, see
> +   <http://www.gnu.org/licenses/>.  */
> +
> +const char *
> +test_func (void)
> +{
> +  return "Success";
> +}
> diff --git a/elf/tst-rootdir.c b/elf/tst-rootdir.c
> new file mode 100644
> index 0000000000..a31d4237af
> --- /dev/null
> +++ b/elf/tst-rootdir.c
> @@ -0,0 +1,37 @@
> +/* Test code for locating libraries in root directories.
> +   Copyright (C) 2023 Free Software Foundation, Inc.
> +   This file is part of the GNU C Library.
> +
> +   The GNU C Library is free software; you can redistribute it and/or
> +   modify it under the terms of the GNU Lesser General Public
> +   License as published by the Free Software Foundation; either
> +   version 2.1 of the License, or (at your option) any later version.
> +
> +   The GNU C Library is distributed in the hope that it will be useful,
> +   but WITHOUT ANY WARRANTY; without even the implied warranty of
> +   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
> +   Lesser General Public License for more details.
> +
> +   You should have received a copy of the GNU Lesser General Public
> +   License along with the GNU C Library; if not, see
> +   <http://www.gnu.org/licenses/>.  */
> +
> +#include <support/test-driver.h>
> +#include <support/check.h>
> +#include <dlfcn.h>
> +#include <assert.h>
> +
> +static int
> +do_test (void)
> +{
> +  void *handle = dlopen ("libtest.so", RTLD_LAZY);
> +  TEST_VERIFY_EXIT (handle != NULL);
> +  typedef const char *(test_func_t) (void);
> +  test_func_t *func = dlsym (handle, "test_func");
> +  assert (func != NULL);
> +  TEST_COMPARE_STRING (func (), "Success");
> +  dlclose (handle);
> +  return 0;
> +}
> +
> +#include <support/test-driver.c>
> diff --git a/elf/tst-rootdir.root/preclean.req b/elf/tst-rootdir.root/preclean.req
> new file mode 100644
> index 0000000000..e69de29bb2
> diff --git a/elf/tst-rootdir.script b/elf/tst-rootdir.script
> new file mode 100644
> index 0000000000..f852c0ec34
> --- /dev/null
> +++ b/elf/tst-rootdir.script
> @@ -0,0 +1 @@
> +cp $B/elf/tst-rootdir-lib.so /libtest.so

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

* [PATCH v3] elf: Add test for locating libraries in root dir  (bug 30435)
  2023-05-25 12:51   ` Siddhesh Poyarekar
@ 2023-05-25 13:29     ` Qixing ksyx Xue
  2023-05-25 14:52       ` Siddhesh Poyarekar
  0 siblings, 1 reply; 9+ messages in thread
From: Qixing ksyx Xue @ 2023-05-25 13:29 UTC (permalink / raw)
  To: libc-alpha, siddhesh; +Cc: carlos, mooodyhunter, Qixing ksyx Xue

When dlopen is being called, efforts have been made to improve
future lookup performance. This includes marking a search path
as non-existent using `stat`. However, if the root directory
is given as a search path, there exists a bug which erroneously
marks it as non-existing.

The bug is reproduced under the following sequence:

  1. dlopen is called to open a shared library, with at least:
     1) a dependency 'A.so' not directly under the '/' directory
        (e.g. /lib/A.so), and
     2) another dependency 'B.so' resides in '/'.
  2. for this bug to reproduce, 'A.so' should be searched *before* 'B.so'.
  3. it first tries to find 'A.so' in /, (e.g. /A.so):
     - this will (obviously) fail,
     - since it's the first time we have seen the '/' directory,
       its 'status' is 'unknown'.
  4. `buf[buflen - namelen - 1] = '\0'` is executed:
     - it intends to remove the leaf and its final slash,
     - because of the speciality of '/', its buflen == namelen + 1,
     - it erroneously clears the entire buffer.
  6. it then calls 'stat' with the empty buffer:
     - which will result in an error.
  7. so it marks '/' as 'nonexisting', future lookups will not consider
     this path.
  8. while /B.so *does* exist, failure to look it up in the '/'
     directory leads to a 'cannot open shared object file' error.

This patch fixes the bug by preventing 'buflen', an index to put '\0',
from being set to 0, so that the root '/' is always kept.
Relative search paths are always considered as 'existing' so this
wont be affected.

Writeup by Moody Liu <mooodyhunter@outlook.com>

Suggested-by: Carlos O'Donell <carlos@redhat.com>
Signed-off-by: Qixing ksyx Xue <qixingxue@outlook.com>
---
 elf/Makefile                      |  3 +++
 elf/tst-rootdir-lib.c             | 23 +++++++++++++++++++
 elf/tst-rootdir.c                 | 37 +++++++++++++++++++++++++++++++
 elf/tst-rootdir.root/preclean.req |  0
 elf/tst-rootdir.script            |  1 +
 5 files changed, 64 insertions(+)
 create mode 100644 elf/tst-rootdir-lib.c
 create mode 100644 elf/tst-rootdir.c
 create mode 100644 elf/tst-rootdir.root/preclean.req
 create mode 100644 elf/tst-rootdir.script

diff --git a/elf/Makefile b/elf/Makefile
index e262f3e6b1..8640138a72 100644
--- a/elf/Makefile
+++ b/elf/Makefile
@@ -325,6 +325,7 @@ static-dlopen-environment = \
   LD_LIBRARY_PATH=$(ld-library-path):$(common-objpfx)dlfcn
 tst-tls9-static-ENV = $(static-dlopen-environment)
 tst-single_threaded-static-dlopen-ENV = $(static-dlopen-environment)
+tst-rootdir-ENV = LD_LIBRARY_PATH=/
 
 tests += \
   argv0test \
@@ -506,6 +507,7 @@ tests-container += \
   tst-dlopen-tlsmodid-container \
   tst-pldd \
   tst-preload-pthread-libc \
+  tst-rootdir \
   # tests-container
 
 test-srcs = \
@@ -855,6 +857,7 @@ modules-names += \
   tst-relsort1mod1 \
   tst-relsort1mod2 \
   tst-ro-dynamic-mod \
+  tst-rootdir-lib \
   tst-single_threaded-mod1 \
   tst-single_threaded-mod2 \
   tst-single_threaded-mod3 \
diff --git a/elf/tst-rootdir-lib.c b/elf/tst-rootdir-lib.c
new file mode 100644
index 0000000000..441960864e
--- /dev/null
+++ b/elf/tst-rootdir-lib.c
@@ -0,0 +1,23 @@
+/* Simple library for testing locating library in root directories.
+   Copyright (C) 2023 The GNU Toolchain Authors.
+   This file is part of the GNU C Library.
+
+   The GNU C Library is free software; you can redistribute it and/or
+   modify it under the terms of the GNU Lesser General Public
+   License as published by the Free Software Foundation; either
+   version 2.1 of the License, or (at your option) any later version.
+
+   The GNU C Library is distributed in the hope that it will be useful,
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+   Lesser General Public License for more details.
+
+   You should have received a copy of the GNU Lesser General Public
+   License along with the GNU C Library; if not, see
+   <http://www.gnu.org/licenses/>.  */
+
+const char *
+test_func (void)
+{
+  return "Success";
+}
diff --git a/elf/tst-rootdir.c b/elf/tst-rootdir.c
new file mode 100644
index 0000000000..cb61a1db3a
--- /dev/null
+++ b/elf/tst-rootdir.c
@@ -0,0 +1,37 @@
+/* Test code for locating libraries in root directories.
+   Copyright (C) 2023 The GNU Toolchain Authors.
+   This file is part of the GNU C Library.
+
+   The GNU C Library is free software; you can redistribute it and/or
+   modify it under the terms of the GNU Lesser General Public
+   License as published by the Free Software Foundation; either
+   version 2.1 of the License, or (at your option) any later version.
+
+   The GNU C Library is distributed in the hope that it will be useful,
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+   Lesser General Public License for more details.
+
+   You should have received a copy of the GNU Lesser General Public
+   License along with the GNU C Library; if not, see
+   <http://www.gnu.org/licenses/>.  */
+
+#include <support/test-driver.h>
+#include <support/check.h>
+#include <dlfcn.h>
+#include <assert.h>
+
+static int
+do_test (void)
+{
+  void *handle = dlopen ("libtest.so", RTLD_LAZY);
+  TEST_VERIFY_EXIT (handle != NULL);
+  typedef const char *(test_func_t) (void);
+  test_func_t *func = dlsym (handle, "test_func");
+  assert (func != NULL);
+  TEST_COMPARE_STRING (func (), "Success");
+  dlclose (handle);
+  return 0;
+}
+
+#include <support/test-driver.c>
diff --git a/elf/tst-rootdir.root/preclean.req b/elf/tst-rootdir.root/preclean.req
new file mode 100644
index 0000000000..e69de29bb2
diff --git a/elf/tst-rootdir.script b/elf/tst-rootdir.script
new file mode 100644
index 0000000000..f852c0ec34
--- /dev/null
+++ b/elf/tst-rootdir.script
@@ -0,0 +1 @@
+cp $B/elf/tst-rootdir-lib.so /libtest.so
-- 
2.25.1


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

* Re: [PATCH v3] elf: Add test for locating libraries in root dir (bug 30435)
  2023-05-25 13:29     ` [PATCH v3] elf: Add test for locating libraries in root dir (bug 30435) Qixing ksyx Xue
@ 2023-05-25 14:52       ` Siddhesh Poyarekar
  2023-05-25 14:56         ` Qixing ksyx Xue
  0 siblings, 1 reply; 9+ messages in thread
From: Siddhesh Poyarekar @ 2023-05-25 14:52 UTC (permalink / raw)
  To: Qixing ksyx Xue, libc-alpha; +Cc: carlos, mooodyhunter



On 2023-05-25 09:29, Qixing ksyx Xue wrote:
> When dlopen is being called, efforts have been made to improve
> future lookup performance. This includes marking a search path
> as non-existent using `stat`. However, if the root directory
> is given as a search path, there exists a bug which erroneously
> marks it as non-existing.
> 
> The bug is reproduced under the following sequence:
> 
>    1. dlopen is called to open a shared library, with at least:
>       1) a dependency 'A.so' not directly under the '/' directory
>          (e.g. /lib/A.so), and
>       2) another dependency 'B.so' resides in '/'.
>    2. for this bug to reproduce, 'A.so' should be searched *before* 'B.so'.
>    3. it first tries to find 'A.so' in /, (e.g. /A.so):
>       - this will (obviously) fail,
>       - since it's the first time we have seen the '/' directory,
>         its 'status' is 'unknown'.
>    4. `buf[buflen - namelen - 1] = '\0'` is executed:
>       - it intends to remove the leaf and its final slash,
>       - because of the speciality of '/', its buflen == namelen + 1,
>       - it erroneously clears the entire buffer.
>    6. it then calls 'stat' with the empty buffer:
>       - which will result in an error.
>    7. so it marks '/' as 'nonexisting', future lookups will not consider
>       this path.
>    8. while /B.so *does* exist, failure to look it up in the '/'
>       directory leads to a 'cannot open shared object file' error.
> 
> This patch fixes the bug by preventing 'buflen', an index to put '\0',
> from being set to 0, so that the root '/' is always kept.
> Relative search paths are always considered as 'existing' so this
> wont be affected.
> 
> Writeup by Moody Liu <mooodyhunter@outlook.com>
> 
> Suggested-by: Carlos O'Donell <carlos@redhat.com>
> Signed-off-by: Qixing ksyx Xue <qixingxue@outlook.com>
> ---
>   elf/Makefile                      |  3 +++
>   elf/tst-rootdir-lib.c             | 23 +++++++++++++++++++
>   elf/tst-rootdir.c                 | 37 +++++++++++++++++++++++++++++++
>   elf/tst-rootdir.root/preclean.req |  0
>   elf/tst-rootdir.script            |  1 +
>   5 files changed, 64 insertions(+)
>   create mode 100644 elf/tst-rootdir-lib.c
>   create mode 100644 elf/tst-rootdir.c
>   create mode 100644 elf/tst-rootdir.root/preclean.req
>   create mode 100644 elf/tst-rootdir.script
> 
> diff --git a/elf/Makefile b/elf/Makefile
> index e262f3e6b1..8640138a72 100644
> --- a/elf/Makefile
> +++ b/elf/Makefile
> @@ -325,6 +325,7 @@ static-dlopen-environment = \
>     LD_LIBRARY_PATH=$(ld-library-path):$(common-objpfx)dlfcn
>   tst-tls9-static-ENV = $(static-dlopen-environment)
>   tst-single_threaded-static-dlopen-ENV = $(static-dlopen-environment)
> +tst-rootdir-ENV = LD_LIBRARY_PATH=/
>   
>   tests += \
>     argv0test \
> @@ -506,6 +507,7 @@ tests-container += \
>     tst-dlopen-tlsmodid-container \
>     tst-pldd \
>     tst-preload-pthread-libc \
> +  tst-rootdir \
>     # tests-container
>   
>   test-srcs = \
> @@ -855,6 +857,7 @@ modules-names += \
>     tst-relsort1mod1 \
>     tst-relsort1mod2 \
>     tst-ro-dynamic-mod \
> +  tst-rootdir-lib \
>     tst-single_threaded-mod1 \
>     tst-single_threaded-mod2 \
>     tst-single_threaded-mod3 \
> diff --git a/elf/tst-rootdir-lib.c b/elf/tst-rootdir-lib.c
> new file mode 100644
> index 0000000000..441960864e
> --- /dev/null
> +++ b/elf/tst-rootdir-lib.c
> @@ -0,0 +1,23 @@
> +/* Simple library for testing locating library in root directories.
> +   Copyright (C) 2023 The GNU Toolchain Authors.

Sorry, this needs to be exactly "Copyright The GNU Toolchain Authors". 
We don't put a year for this notice.

Thanks,
Sid

> +   This file is part of the GNU C Library.
> +
> +   The GNU C Library is free software; you can redistribute it and/or
> +   modify it under the terms of the GNU Lesser General Public
> +   License as published by the Free Software Foundation; either
> +   version 2.1 of the License, or (at your option) any later version.
> +
> +   The GNU C Library is distributed in the hope that it will be useful,
> +   but WITHOUT ANY WARRANTY; without even the implied warranty of
> +   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
> +   Lesser General Public License for more details.
> +
> +   You should have received a copy of the GNU Lesser General Public
> +   License along with the GNU C Library; if not, see
> +   <http://www.gnu.org/licenses/>.  */
> +
> +const char *
> +test_func (void)
> +{
> +  return "Success";
> +}
> diff --git a/elf/tst-rootdir.c b/elf/tst-rootdir.c
> new file mode 100644
> index 0000000000..cb61a1db3a
> --- /dev/null
> +++ b/elf/tst-rootdir.c
> @@ -0,0 +1,37 @@
> +/* Test code for locating libraries in root directories.
> +   Copyright (C) 2023 The GNU Toolchain Authors.
> +   This file is part of the GNU C Library.
> +
> +   The GNU C Library is free software; you can redistribute it and/or
> +   modify it under the terms of the GNU Lesser General Public
> +   License as published by the Free Software Foundation; either
> +   version 2.1 of the License, or (at your option) any later version.
> +
> +   The GNU C Library is distributed in the hope that it will be useful,
> +   but WITHOUT ANY WARRANTY; without even the implied warranty of
> +   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
> +   Lesser General Public License for more details.
> +
> +   You should have received a copy of the GNU Lesser General Public
> +   License along with the GNU C Library; if not, see
> +   <http://www.gnu.org/licenses/>.  */
> +
> +#include <support/test-driver.h>
> +#include <support/check.h>
> +#include <dlfcn.h>
> +#include <assert.h>
> +
> +static int
> +do_test (void)
> +{
> +  void *handle = dlopen ("libtest.so", RTLD_LAZY);
> +  TEST_VERIFY_EXIT (handle != NULL);
> +  typedef const char *(test_func_t) (void);
> +  test_func_t *func = dlsym (handle, "test_func");
> +  assert (func != NULL);
> +  TEST_COMPARE_STRING (func (), "Success");
> +  dlclose (handle);
> +  return 0;
> +}
> +
> +#include <support/test-driver.c>
> diff --git a/elf/tst-rootdir.root/preclean.req b/elf/tst-rootdir.root/preclean.req
> new file mode 100644
> index 0000000000..e69de29bb2
> diff --git a/elf/tst-rootdir.script b/elf/tst-rootdir.script
> new file mode 100644
> index 0000000000..f852c0ec34
> --- /dev/null
> +++ b/elf/tst-rootdir.script
> @@ -0,0 +1 @@
> +cp $B/elf/tst-rootdir-lib.so /libtest.so

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

* [PATCH v3] elf: Add test for locating libraries in root dir  (bug 30435)
  2023-05-25 14:52       ` Siddhesh Poyarekar
@ 2023-05-25 14:56         ` Qixing ksyx Xue
  2023-05-25 15:12           ` Siddhesh Poyarekar
  0 siblings, 1 reply; 9+ messages in thread
From: Qixing ksyx Xue @ 2023-05-25 14:56 UTC (permalink / raw)
  To: libc-alpha, siddhesh; +Cc: carlos, mooodyhunter, Qixing ksyx Xue

When dlopen is being called, efforts have been made to improve
future lookup performance. This includes marking a search path
as non-existent using `stat`. However, if the root directory
is given as a search path, there exists a bug which erroneously
marks it as non-existing.

The bug is reproduced under the following sequence:

  1. dlopen is called to open a shared library, with at least:
     1) a dependency 'A.so' not directly under the '/' directory
        (e.g. /lib/A.so), and
     2) another dependency 'B.so' resides in '/'.
  2. for this bug to reproduce, 'A.so' should be searched *before* 'B.so'.
  3. it first tries to find 'A.so' in /, (e.g. /A.so):
     - this will (obviously) fail,
     - since it's the first time we have seen the '/' directory,
       its 'status' is 'unknown'.
  4. `buf[buflen - namelen - 1] = '\0'` is executed:
     - it intends to remove the leaf and its final slash,
     - because of the speciality of '/', its buflen == namelen + 1,
     - it erroneously clears the entire buffer.
  6. it then calls 'stat' with the empty buffer:
     - which will result in an error.
  7. so it marks '/' as 'nonexisting', future lookups will not consider
     this path.
  8. while /B.so *does* exist, failure to look it up in the '/'
     directory leads to a 'cannot open shared object file' error.

This patch fixes the bug by preventing 'buflen', an index to put '\0',
from being set to 0, so that the root '/' is always kept.
Relative search paths are always considered as 'existing' so this
wont be affected.

Writeup by Moody Liu <mooodyhunter@outlook.com>

Suggested-by: Carlos O'Donell <carlos@redhat.com>
Signed-off-by: Qixing ksyx Xue <qixingxue@outlook.com>
---
 elf/Makefile                      |  3 +++
 elf/tst-rootdir-lib.c             | 23 +++++++++++++++++++
 elf/tst-rootdir.c                 | 37 +++++++++++++++++++++++++++++++
 elf/tst-rootdir.root/preclean.req |  0
 elf/tst-rootdir.script            |  1 +
 5 files changed, 64 insertions(+)
 create mode 100644 elf/tst-rootdir-lib.c
 create mode 100644 elf/tst-rootdir.c
 create mode 100644 elf/tst-rootdir.root/preclean.req
 create mode 100644 elf/tst-rootdir.script

diff --git a/elf/Makefile b/elf/Makefile
index e262f3e6b1..8640138a72 100644
--- a/elf/Makefile
+++ b/elf/Makefile
@@ -325,6 +325,7 @@ static-dlopen-environment = \
   LD_LIBRARY_PATH=$(ld-library-path):$(common-objpfx)dlfcn
 tst-tls9-static-ENV = $(static-dlopen-environment)
 tst-single_threaded-static-dlopen-ENV = $(static-dlopen-environment)
+tst-rootdir-ENV = LD_LIBRARY_PATH=/
 
 tests += \
   argv0test \
@@ -506,6 +507,7 @@ tests-container += \
   tst-dlopen-tlsmodid-container \
   tst-pldd \
   tst-preload-pthread-libc \
+  tst-rootdir \
   # tests-container
 
 test-srcs = \
@@ -855,6 +857,7 @@ modules-names += \
   tst-relsort1mod1 \
   tst-relsort1mod2 \
   tst-ro-dynamic-mod \
+  tst-rootdir-lib \
   tst-single_threaded-mod1 \
   tst-single_threaded-mod2 \
   tst-single_threaded-mod3 \
diff --git a/elf/tst-rootdir-lib.c b/elf/tst-rootdir-lib.c
new file mode 100644
index 0000000000..007c4b0095
--- /dev/null
+++ b/elf/tst-rootdir-lib.c
@@ -0,0 +1,23 @@
+/* Simple library for testing locating library in root directories.
+   Copyright The GNU Toolchain Authors.
+   This file is part of the GNU C Library.
+
+   The GNU C Library is free software; you can redistribute it and/or
+   modify it under the terms of the GNU Lesser General Public
+   License as published by the Free Software Foundation; either
+   version 2.1 of the License, or (at your option) any later version.
+
+   The GNU C Library is distributed in the hope that it will be useful,
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+   Lesser General Public License for more details.
+
+   You should have received a copy of the GNU Lesser General Public
+   License along with the GNU C Library; if not, see
+   <http://www.gnu.org/licenses/>.  */
+
+const char *
+test_func (void)
+{
+  return "Success";
+}
diff --git a/elf/tst-rootdir.c b/elf/tst-rootdir.c
new file mode 100644
index 0000000000..83284ea59e
--- /dev/null
+++ b/elf/tst-rootdir.c
@@ -0,0 +1,37 @@
+/* Test code for locating libraries in root directories.
+   Copyright The GNU Toolchain Authors.
+   This file is part of the GNU C Library.
+
+   The GNU C Library is free software; you can redistribute it and/or
+   modify it under the terms of the GNU Lesser General Public
+   License as published by the Free Software Foundation; either
+   version 2.1 of the License, or (at your option) any later version.
+
+   The GNU C Library is distributed in the hope that it will be useful,
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+   Lesser General Public License for more details.
+
+   You should have received a copy of the GNU Lesser General Public
+   License along with the GNU C Library; if not, see
+   <http://www.gnu.org/licenses/>.  */
+
+#include <support/test-driver.h>
+#include <support/check.h>
+#include <dlfcn.h>
+#include <assert.h>
+
+static int
+do_test (void)
+{
+  void *handle = dlopen ("libtest.so", RTLD_LAZY);
+  TEST_VERIFY_EXIT (handle != NULL);
+  typedef const char *(test_func_t) (void);
+  test_func_t *func = dlsym (handle, "test_func");
+  assert (func != NULL);
+  TEST_COMPARE_STRING (func (), "Success");
+  dlclose (handle);
+  return 0;
+}
+
+#include <support/test-driver.c>
diff --git a/elf/tst-rootdir.root/preclean.req b/elf/tst-rootdir.root/preclean.req
new file mode 100644
index 0000000000..e69de29bb2
diff --git a/elf/tst-rootdir.script b/elf/tst-rootdir.script
new file mode 100644
index 0000000000..f852c0ec34
--- /dev/null
+++ b/elf/tst-rootdir.script
@@ -0,0 +1 @@
+cp $B/elf/tst-rootdir-lib.so /libtest.so
-- 
2.25.1


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

* Re: [PATCH v3] elf: Add test for locating libraries in root dir (bug 30435)
  2023-05-25 14:56         ` Qixing ksyx Xue
@ 2023-05-25 15:12           ` Siddhesh Poyarekar
  0 siblings, 0 replies; 9+ messages in thread
From: Siddhesh Poyarekar @ 2023-05-25 15:12 UTC (permalink / raw)
  To: Qixing ksyx Xue, libc-alpha; +Cc: carlos, mooodyhunter



On 2023-05-25 10:56, Qixing ksyx Xue wrote:
> When dlopen is being called, efforts have been made to improve
> future lookup performance. This includes marking a search path
> as non-existent using `stat`. However, if the root directory
> is given as a search path, there exists a bug which erroneously
> marks it as non-existing.
> 
> The bug is reproduced under the following sequence:
> 
>    1. dlopen is called to open a shared library, with at least:
>       1) a dependency 'A.so' not directly under the '/' directory
>          (e.g. /lib/A.so), and
>       2) another dependency 'B.so' resides in '/'.
>    2. for this bug to reproduce, 'A.so' should be searched *before* 'B.so'.
>    3. it first tries to find 'A.so' in /, (e.g. /A.so):
>       - this will (obviously) fail,
>       - since it's the first time we have seen the '/' directory,
>         its 'status' is 'unknown'.
>    4. `buf[buflen - namelen - 1] = '\0'` is executed:
>       - it intends to remove the leaf and its final slash,
>       - because of the speciality of '/', its buflen == namelen + 1,
>       - it erroneously clears the entire buffer.
>    6. it then calls 'stat' with the empty buffer:
>       - which will result in an error.
>    7. so it marks '/' as 'nonexisting', future lookups will not consider
>       this path.
>    8. while /B.so *does* exist, failure to look it up in the '/'
>       directory leads to a 'cannot open shared object file' error.
> 
> This patch fixes the bug by preventing 'buflen', an index to put '\0',
> from being set to 0, so that the root '/' is always kept.
> Relative search paths are always considered as 'existing' so this
> wont be affected.
> 
> Writeup by Moody Liu <mooodyhunter@outlook.com>
> 
> Suggested-by: Carlos O'Donell <carlos@redhat.com>
> Signed-off-by: Qixing ksyx Xue <qixingxue@outlook.com>

Reviewed-by: Siddhesh Poyarekar <siddhesh@sourceware.org>

I'll test and commit this shortly.

Thanks,
Sid

> ---
>   elf/Makefile                      |  3 +++
>   elf/tst-rootdir-lib.c             | 23 +++++++++++++++++++
>   elf/tst-rootdir.c                 | 37 +++++++++++++++++++++++++++++++
>   elf/tst-rootdir.root/preclean.req |  0
>   elf/tst-rootdir.script            |  1 +
>   5 files changed, 64 insertions(+)
>   create mode 100644 elf/tst-rootdir-lib.c
>   create mode 100644 elf/tst-rootdir.c
>   create mode 100644 elf/tst-rootdir.root/preclean.req
>   create mode 100644 elf/tst-rootdir.script
> 
> diff --git a/elf/Makefile b/elf/Makefile
> index e262f3e6b1..8640138a72 100644
> --- a/elf/Makefile
> +++ b/elf/Makefile
> @@ -325,6 +325,7 @@ static-dlopen-environment = \
>     LD_LIBRARY_PATH=$(ld-library-path):$(common-objpfx)dlfcn
>   tst-tls9-static-ENV = $(static-dlopen-environment)
>   tst-single_threaded-static-dlopen-ENV = $(static-dlopen-environment)
> +tst-rootdir-ENV = LD_LIBRARY_PATH=/
>   
>   tests += \
>     argv0test \
> @@ -506,6 +507,7 @@ tests-container += \
>     tst-dlopen-tlsmodid-container \
>     tst-pldd \
>     tst-preload-pthread-libc \
> +  tst-rootdir \
>     # tests-container
>   
>   test-srcs = \
> @@ -855,6 +857,7 @@ modules-names += \
>     tst-relsort1mod1 \
>     tst-relsort1mod2 \
>     tst-ro-dynamic-mod \
> +  tst-rootdir-lib \
>     tst-single_threaded-mod1 \
>     tst-single_threaded-mod2 \
>     tst-single_threaded-mod3 \
> diff --git a/elf/tst-rootdir-lib.c b/elf/tst-rootdir-lib.c
> new file mode 100644
> index 0000000000..007c4b0095
> --- /dev/null
> +++ b/elf/tst-rootdir-lib.c
> @@ -0,0 +1,23 @@
> +/* Simple library for testing locating library in root directories.
> +   Copyright The GNU Toolchain Authors.
> +   This file is part of the GNU C Library.
> +
> +   The GNU C Library is free software; you can redistribute it and/or
> +   modify it under the terms of the GNU Lesser General Public
> +   License as published by the Free Software Foundation; either
> +   version 2.1 of the License, or (at your option) any later version.
> +
> +   The GNU C Library is distributed in the hope that it will be useful,
> +   but WITHOUT ANY WARRANTY; without even the implied warranty of
> +   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
> +   Lesser General Public License for more details.
> +
> +   You should have received a copy of the GNU Lesser General Public
> +   License along with the GNU C Library; if not, see
> +   <http://www.gnu.org/licenses/>.  */
> +
> +const char *
> +test_func (void)
> +{
> +  return "Success";
> +}
> diff --git a/elf/tst-rootdir.c b/elf/tst-rootdir.c
> new file mode 100644
> index 0000000000..83284ea59e
> --- /dev/null
> +++ b/elf/tst-rootdir.c
> @@ -0,0 +1,37 @@
> +/* Test code for locating libraries in root directories.
> +   Copyright The GNU Toolchain Authors.
> +   This file is part of the GNU C Library.
> +
> +   The GNU C Library is free software; you can redistribute it and/or
> +   modify it under the terms of the GNU Lesser General Public
> +   License as published by the Free Software Foundation; either
> +   version 2.1 of the License, or (at your option) any later version.
> +
> +   The GNU C Library is distributed in the hope that it will be useful,
> +   but WITHOUT ANY WARRANTY; without even the implied warranty of
> +   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
> +   Lesser General Public License for more details.
> +
> +   You should have received a copy of the GNU Lesser General Public
> +   License along with the GNU C Library; if not, see
> +   <http://www.gnu.org/licenses/>.  */
> +
> +#include <support/test-driver.h>
> +#include <support/check.h>
> +#include <dlfcn.h>
> +#include <assert.h>
> +
> +static int
> +do_test (void)
> +{
> +  void *handle = dlopen ("libtest.so", RTLD_LAZY);
> +  TEST_VERIFY_EXIT (handle != NULL);
> +  typedef const char *(test_func_t) (void);
> +  test_func_t *func = dlsym (handle, "test_func");
> +  assert (func != NULL);
> +  TEST_COMPARE_STRING (func (), "Success");
> +  dlclose (handle);
> +  return 0;
> +}
> +
> +#include <support/test-driver.c>
> diff --git a/elf/tst-rootdir.root/preclean.req b/elf/tst-rootdir.root/preclean.req
> new file mode 100644
> index 0000000000..e69de29bb2
> diff --git a/elf/tst-rootdir.script b/elf/tst-rootdir.script
> new file mode 100644
> index 0000000000..f852c0ec34
> --- /dev/null
> +++ b/elf/tst-rootdir.script
> @@ -0,0 +1 @@
> +cp $B/elf/tst-rootdir-lib.so /libtest.so

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

end of thread, other threads:[~2023-05-25 15:12 UTC | newest]

Thread overview: 9+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-05-08 15:45 [PATCH] elf: Fix marking root dir as nonexist in open_path Moody Liu
2023-05-08 20:04 ` Carlos O'Donell
2023-05-09 22:56 ` [PATCH v2 1/2] elf: Fix marking root dir as nonexist in open_path (bug 30435) Qixing ksyx Xue
2023-05-09 22:56 ` [PATCH v2 2/2] elf: Add test for finding libraries in root dir Qixing ksyx Xue
2023-05-25 12:51   ` Siddhesh Poyarekar
2023-05-25 13:29     ` [PATCH v3] elf: Add test for locating libraries in root dir (bug 30435) Qixing ksyx Xue
2023-05-25 14:52       ` Siddhesh Poyarekar
2023-05-25 14:56         ` Qixing ksyx Xue
2023-05-25 15:12           ` Siddhesh Poyarekar

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 read-only IMAP folder(s) and NNTP newsgroup(s).