public inbox for libc-alpha@sourceware.org
 help / color / mirror / Atom feed
From: Xi Ruoyao <xry111@xry111.site>
To: DJ Delorie <dj@redhat.com>
Cc: libc-alpha@sourceware.org
Subject: Re: [PATCH v5 1/1] memalign: Support scanning for aligned chunks.
Date: Thu, 13 Apr 2023 01:26:15 +0800	[thread overview]
Message-ID: <701d23906ce7c22e4dff8f0e113c6196b63c0575.camel@xry111.site> (raw)
In-Reply-To: <xnfs95xbq8.fsf@greed.delorie.com>

On Wed, 2023-04-12 at 13:16 -0400, DJ Delorie wrote:
> Xi Ruoyao <xry111@xry111.site> writes:
> > On LoongArch (with a GCC 12.2 but LoongArch backend patched to match
> > GCC
> > trunk), this causes an almost deterministic failure of malloc/tst-
> > malloc-thread-fail-malloc-hugetlb2:
> 
> (1) What's in malloc/tst-malloc-thread-fail-malloc-hugetlb2.out ?
> 
> (2) Have you tried with "export TIMEOUTFACTOR=20" ? some tests fail
>     reliably on slower systems due to timeouts.

No, it's not a timeout, but a segment fault.  The output is just "error:
exit status 139 from child process".

I'm not an expert with ptmalloc, but there is some code like:

  arena_get (ar_ptr, bytes + alignment + MINSIZE);

  p = _int_memalign (ar_ptr, alignment, bytes);
  if (!p && ar_ptr != NULL)
    {
      LIBC_PROBE (memory_memalign_retry, 2, bytes, alignment);
      ar_ptr = arena_get_retry (ar_ptr, bytes);
      p = _int_memalign (ar_ptr, alignment, bytes);
    }

arena_get can set ar_ptr to NULL (at least when the system memory is not
enough).

Then _int_memalign is dereferencing ar_ptr w/o any nullity check (bin_at
seems a "fancy" dereference operation to me).

Then we test ar_ptr != NULL in the if statement.

Now it looks like a notorious "NULL check after dereferencing" pattern.
So I added a nullity check:

diff --git a/malloc/malloc.c b/malloc/malloc.c
index 0315ac5d16..ed10b6b0e3 100644
--- a/malloc/malloc.c
+++ b/malloc/malloc.c
@@ -5025,7 +5025,7 @@ _int_memalign (mstate av, size_t alignment, size_t
bytes)
   mchunkptr victim;
 
   nb = checked_request2size (bytes);
-  if (nb == 0)
+  if (nb == 0 || !av)
     {
       __set_errno (ENOMEM);
       return NULL;

And it indeed fixed the test for me.  But I'm not sure if it's the
correct solution and I've not ran the complete test suite with the
change yet.


-- 
Xi Ruoyao <xry111@xry111.site>
School of Aerospace Science and Technology, Xidian University

  reply	other threads:[~2023-04-12 17:26 UTC|newest]

Thread overview: 38+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-07-14  3:58 [PATCH v1 " DJ Delorie
2022-07-19  2:54 ` Carlos O'Donell
2022-07-19  3:57   ` [PATCH v2 " DJ Delorie
2022-07-19  9:19     ` Florian Weimer
2022-07-19 17:32       ` DJ Delorie
2022-07-20  0:32       ` [PATCH v3 " DJ Delorie
2022-07-22 20:21         ` DJ Delorie
2022-07-22 20:28         ` Joseph Myers
2022-07-28 19:50           ` [PATCH v4 " DJ Delorie
2022-08-17 19:00             ` DJ Delorie
2022-11-10 21:40               ` Ping^2: " DJ Delorie
2023-03-20 21:49                 ` Ping^3: " DJ Delorie
2023-03-28 19:07             ` Adhemerval Zanella Netto
2023-03-29  4:20               ` [PATCH v5 " DJ Delorie
2023-03-29 19:41                 ` Adhemerval Zanella Netto
2023-03-29 20:36                   ` DJ Delorie
2023-03-30 10:04                     ` Cristian Rodríguez
2023-03-30 10:50                       ` Adhemerval Zanella Netto
2023-03-30 21:43                         ` Cristian Rodríguez
2023-04-12 17:04                           ` Xi Ruoyao
2023-04-12 17:16                             ` DJ Delorie
2023-04-12 17:26                               ` Xi Ruoyao [this message]
2023-04-13  1:52                                 ` [PATCH v6 " DJ Delorie
2023-04-13  5:51                                   ` Xi Ruoyao
2023-04-17 21:48                                   ` Carlos O'Donell
2023-04-18  1:25                                     ` [PATCH v7] " DJ Delorie
2023-04-18 13:58                                       ` Carlos O'Donell
2023-04-18 15:02                                         ` DJ Delorie
2023-04-12 17:33                             ` [PATCH v5 1/1] " Adhemerval Zanella Netto
2023-04-12 17:40                               ` DJ Delorie
2023-04-12 18:01                                 ` Adhemerval Zanella Netto
2023-04-13  1:57                                   ` DJ Delorie
2023-04-13 10:46                                     ` Adhemerval Zanella Netto
2023-04-05 14:07                     ` Stefan Liebler
2023-04-05 17:58                       ` DJ Delorie
2023-04-11 11:40                         ` Stefan Liebler
2023-04-12 11:23                           ` Stefan Liebler
2023-03-31 15:39                 ` Adhemerval Zanella Netto

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=701d23906ce7c22e4dff8f0e113c6196b63c0575.camel@xry111.site \
    --to=xry111@xry111.site \
    --cc=dj@redhat.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).