public inbox for libc-alpha@sourceware.org
 help / color / mirror / Atom feed
From: Florian Weimer <fweimer@redhat.com>
To: Siddhesh Poyarekar <siddhesh@sourceware.org>
Cc: libc-alpha@sourceware.org,  schwab@suse.de,  carlos@redhat.com
Subject: Re: [PATCH v3] getaddrinfo: Fix use after free in getcanonname (CVE-2023-4806)
Date: Thu, 14 Sep 2023 12:53:05 +0200	[thread overview]
Message-ID: <87il8d2fhq.fsf@oldenburg3.str.redhat.com> (raw)
In-Reply-To: <20230914101302.3128752-1-siddhesh@sourceware.org> (Siddhesh Poyarekar's message of "Thu, 14 Sep 2023 06:13:02 -0400")

* Siddhesh Poyarekar:

> diff --git a/nss/tst-nss-gai-hv2-canonname.root/postclean.req b/nss/tst-nss-gai-hv2-canonname.root/postclean.req
> new file mode 100644
> index 0000000000..e69de29bb2
> diff --git a/nss/tst-nss-gai-hv2-canonname.root/tst-nss-gai-hv2-canonname.script b/nss/tst-nss-gai-hv2-canonname.root/tst-nss-gai-hv2-canonname.script
> new file mode 100644
> index 0000000000..31848b4a28
> --- /dev/null
> +++ b/nss/tst-nss-gai-hv2-canonname.root/tst-nss-gai-hv2-canonname.script
> @@ -0,0 +1,2 @@
> +cp $B/nss/libnss_test_gai_hv2_canonname.so $L/libnss_test_gai_hv2_canonname.so.2
> +su
> diff --git a/sysdeps/posix/getaddrinfo.c b/sysdeps/posix/getaddrinfo.c

> @@ -238,6 +239,15 @@ convert_hostent_to_gaih_addrtuple (const struct addrinfo *req, int family,
>    res->at = array;
>    res->free_at = true;
>  
> +  /* Duplicate h_name because it may get reclaimed when the underlying storage
> +     is freed.  */
> +  if (res->hname == NULL)
> +    {
> +      res->hname = __strdup (h->h_name);
> +      if (res->hname == NULL)
> +	return false;
> +    }
> +
>    /* Update the next pointers on reallocation.  */
>    for (size_t i = 0; i < old; i++)
>      array[i].next = array + i + 1;
> @@ -262,7 +272,6 @@ convert_hostent_to_gaih_addrtuple (const struct addrinfo *req, int family,
>  	}
>        array[i].next = array + i + 1;
>      }
> -  array[0].name = h->h_name;
>    array[count - 1].next = NULL;

I would expect

  array[0].name = res->h_name;

here, but that's not needed because the assignment happens in
generate_addrinfo, from res->canon, which may have been set with
res->h_name as a fallback?

Thanks,
Florian


  reply	other threads:[~2023-09-14 10:53 UTC|newest]

Thread overview: 16+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-09-13 17:36 [PATCH] " Siddhesh Poyarekar
2023-09-13 19:03 ` Florian Weimer
2023-09-13 20:56 ` [PATCH v2] " Siddhesh Poyarekar
2023-09-14  8:37   ` Andreas Schwab
2023-09-14  9:48     ` Siddhesh Poyarekar
2023-09-14  9:55       ` Andreas Schwab
2023-09-14  9:57         ` Siddhesh Poyarekar
2023-09-14 10:00           ` Andreas Schwab
2023-09-14 10:06             ` Siddhesh Poyarekar
2023-09-14 10:12               ` Andreas Schwab
2023-09-14 10:24                 ` Siddhesh Poyarekar
2023-09-14 10:13 ` [PATCH v3] " Siddhesh Poyarekar
2023-09-14 10:53   ` Florian Weimer [this message]
2023-09-14 11:27     ` Siddhesh Poyarekar
2023-09-14 22:52   ` Carlos O'Donell
2023-09-15 18:41 ` [COMMITTED] " Siddhesh Poyarekar

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=87il8d2fhq.fsf@oldenburg3.str.redhat.com \
    --to=fweimer@redhat.com \
    --cc=carlos@redhat.com \
    --cc=libc-alpha@sourceware.org \
    --cc=schwab@suse.de \
    --cc=siddhesh@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).