public inbox for libc-alpha@sourceware.org
 help / color / mirror / Atom feed
From: Stefan Liebler <stli@linux.ibm.com>
To: "Carlos O'Donell" <carlos@redhat.com>, "H.J. Lu" <hjl.tools@gmail.com>
Cc: GNU C Library <libc-alpha@sourceware.org>
Subject: Re: [PATCH] Use libnss_files.so for tests posix/bug-ga2 and resolv/tst-leaks2 [BZ #26821]
Date: Fri, 20 Nov 2020 13:10:14 +0100	[thread overview]
Message-ID: <2dbe4614-0ef1-0b0b-5c88-2aa1f64ba358@linux.ibm.com> (raw)
In-Reply-To: <a641a779-de94-25a3-160d-54ad8e2388a1@redhat.com>

On 11/19/20 4:34 PM, Carlos O'Donell wrote:
> On 11/19/20 10:11 AM, H.J. Lu via Libc-alpha wrote:
>> On Thu, Nov 19, 2020 at 4:32 AM Stefan Liebler via Libc-alpha
>> <libc-alpha@sourceware.org> wrote:
>>>
>>> The tests posix/bug-ga2-mem and resolv/mtrace-tst-leaks2 are failing on
>>> fedora 33 as mtrace reports memory leaks.
>>>
>>> The /etc/nsswitch.conf differs between
>>> Fedora 32: hosts:      files dns myhostname
>>> Fedora 33: hosts:      files resolve [!UNAVAIL=return] myhostname dns
>>>
>>> Therefore /lib64/libnss_resolve.so.2 (from systemd) and the dependencies
>>> libgcc_s.so.1 and libpthread.so.0 are loaded.
>>>
>>> Usually all malloc'ed resources from getaddrinfo / gethostbyname are freed
>>> and the libraries are dlclose'd in nss/nsswitch.c:libc_freeres_fn (free_mem).
>>> Unfortunately, /lib64/libnss_resolve.so.2 is marked with DF_1_NODELETE.
>>> As this library is not unmapped, you'll see "Memory not freed".
>>>
>>> Therefore those tests are now only rely on libnss_files.so by preparing
>>> a chroot with all required configuration files and executing the test in
>>> a subprocess.
>>>
>>> This patch also added support for /etc/services and /etc/nsswitch.conf
>>> in struct support_chroot_configuration.
>>>
>>> Note:
>>> We can't use __nss_configure_lookup as it would lead to not setting up
>>> nsswitch.c:service_table before calling __getservbyname_r / __gethostbyname_r.
>>> nsswitch.c:nss_load_library would then add resources to default_table which
>>> are not freed by nsswitch.c:libc_freeres_fn (free_mem)
>>> ---
>>>  posix/Makefile           |  1 +
>>>  posix/bug-ga2.c          | 68 +++++++++++++++++++++++++++++++++++-----
>>>  resolv/Makefile          |  1 +
>>>  resolv/tst-leaks2.c      | 63 +++++++++++++++++++++++++++++++++----
>>>  support/namespace.h      |  4 +++
>>>  support/support_chroot.c |  9 +++++-
>>>  6 files changed, 132 insertions(+), 14 deletions(-)
>>>
>>> diff --git a/posix/Makefile b/posix/Makefile
>>> index 693082ed28..0ef4e7f4be 100644
>>> --- a/posix/Makefile
>>> +++ b/posix/Makefile
>>> @@ -361,6 +361,7 @@ $(objpfx)bug-ga2-mem.out: $(objpfx)bug-ga2.out
>>>         $(common-objpfx)malloc/mtrace $(objpfx)bug-ga2.mtrace > $@; \
>>>         $(evaluate-test)
>>>
>>> +$(objpfx)bug-ga2: $(libdl)
>>>  bug-ga2-ENV = MALLOC_TRACE=$(objpfx)bug-ga2.mtrace
>>>
>>>  bug-glob2-ENV = MALLOC_TRACE=$(objpfx)bug-glob2.mtrace
>>> diff --git a/posix/bug-ga2.c b/posix/bug-ga2.c
>>> index 5ea759b8ce..889f100358 100644
>>> --- a/posix/bug-ga2.c
>>> +++ b/posix/bug-ga2.c
>>> @@ -1,16 +1,46 @@
>>>  /* Test case by Sam Varshavchik <mrsam@courier-mta.com>.  */
>>>  #include <mcheck.h>
>>>  #include <netdb.h>
>>> -#include <stdio.h>
>>> +#include <stdlib.h>
>>>  #include <string.h>
>>> +#include <dlfcn.h>
>>> +#include <gnu/lib-names.h>
>>> +#include <support/check.h>
>>> +#include <support/namespace.h>
>>> +#include <support/test-driver.h>
>>> +#include <support/xunistd.h>
>>>
>>> -int
>>> -main (void)
>>> +struct support_chroot *chroot_env;
>>> +
>>> +static void
>>> +prepare (int argc, char **argv)
>>> +{
>>> +  /* Generate a /etc/nsswitch.conf instead of using __nss_configure_lookup
>>> +     as it would lead to not setting up nsswitch.c:service_table before calling
>>> +     __getservbyname_r.  nss_load_library would then add resources to
>>> +     default_table which are not freed by
>>> +     nss/nsswitch.c:libc_freeres_fn (free_mem).  */
>>> +  chroot_env = support_chroot_create
>>> +    ((struct support_chroot_configuration)
>>> +     {
>>> +       .nsswitch_conf =
>>> +       "services: files\n"
>>> +       "hosts: files\n",
>>> +       .host_conf = "multi on\n",
>>> +       .hosts = "192.0.2.1 www.gnu.org\n",
>>> +       .services = "http 80/tcp\n"
>>> +     });
>>> +}
>>> +
>>> +static void
>>> +subprocess_test (void *closure)
>>>  {
>>>    struct addrinfo hints, *res;
>>>    int i, ret;
>>>
>>>    mtrace ();
>>> +  xchroot (chroot_env->path_chroot);
>>> +
>>>    for (i = 0; i < 100; i++)
>>>      {
>>>        memset (&hints, 0, sizeof (hints));
>>> @@ -20,11 +50,35 @@ main (void)
>>>        ret = getaddrinfo ("www.gnu.org", "http", &hints, &res);
>>>
>>>        if (ret)
>>> -       {
>>> -         printf ("%s\n", gai_strerror (ret));
>>> -         return 1;
>>> -       }
>>> +       FAIL_EXIT1 ("%s\n", gai_strerror (ret));
>>> +
>>>        freeaddrinfo (res);
>>>      }
>>> +
>>> +  /* Ensure that the resources malloc'ed by getaddrinfo are freed by
>>> +     nss/nsswitch.c:libc_freeres_fn (free_mem).  */
>>> +  exit (EXIT_SUCCESS);
>>> +}
>>> +
>>> +
>>> +static int
>>> +do_test (void)
>>> +{
>>> +  support_become_root ();
>>> +  if (!support_can_chroot ())
>>> +    return EXIT_UNSUPPORTED;
>>> +
>>> +  /* Load the libraries now as those are not available in chroot.  */
>>> +  if (dlopen (LIBNSS_FILES_SO, RTLD_LAZY) == NULL)
>>> +    FAIL_EXIT1 ("could not load " LIBNSS_FILES_SO ": %s", dlerror ());
>>> +
>>
>> Can you copy the needed shared libraries to chroot?
>  
> You can make it a test-container test which has the installed
> glibc in the sysroot, and provide a nsswitch.conf for the test that
> does exactly what you want.
> 
> Examples:
> ./nss/tst-nss-db-endgrent.root/etc/nsswitch.conf
> ./nss/tst-nss-db-endpwent.root/etc/nsswitch.conf
> ./nss/tst-nss-test3.root/etc/nsswitch.conf
> 
> 

Sure. The test is now a container test and libnss_files is loaded as
usual. I've just send a new patch (unfortunately I've missed to add "-v2"):
"[PATCH] Use libnss_files.so for tests posix/bug-ga2 and
resolv/tst-leaks2 [BZ #26821]"
https://sourceware.org/pipermail/libc-alpha/2020-November/119860.html

Bye,
Stefan

  reply	other threads:[~2020-11-20 12:10 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-11-19 12:28 Stefan Liebler
2020-11-19 15:11 ` H.J. Lu
2020-11-19 15:34   ` Carlos O'Donell
2020-11-20 12:10     ` Stefan Liebler [this message]
2020-11-20 12:06 Stefan Liebler
2020-11-20 13:40 ` H.J. Lu
2020-11-23  9:56   ` Stefan Liebler

Reply instructions:

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

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

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

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

  git send-email \
    --in-reply-to=2dbe4614-0ef1-0b0b-5c88-2aa1f64ba358@linux.ibm.com \
    --to=stli@linux.ibm.com \
    --cc=carlos@redhat.com \
    --cc=hjl.tools@gmail.com \
    --cc=libc-alpha@sourceware.org \
    /path/to/YOUR_REPLY

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

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