public inbox for libc-alpha@sourceware.org
 help / color / mirror / Atom feed
From: liqingqing <liqingqing3@huawei.com>
To: DJ Delorie <dj@redhat.com>
Cc: <libc-alpha@sourceware.org>, <wuxu.wu@huawei.com>,
	Liusirui <liusirui@huawei.com>
Subject: Re: [PATCH] malloc: Print error when oldsize is not equal to the current size.
Date: Fri, 23 Apr 2021 10:23:13 +0800	[thread overview]
Message-ID: <1128ec85-bd4f-a6e8-cc3b-ae17aa94d96b@huawei.com> (raw)
In-Reply-To: <xnzgy1de8d.fsf@rhel8.vm>


On 2021/4/14 6:14, DJ Delorie wrote:
> liqingqing <liqingqing3@huawei.com> writes:
>> the read of the oldsize is not protected by any lock, so check this value to avoid causing bigger mistakes. 
> Normally nothing can change oldsize until the oldp chunk is returned to
> the arena, and at the point where you added the check that hasn't
> happened.  Could you be more specific about how this value might change
> out from under us?
>
> Is this a case of "some other thread might corrupt this"?  But that can
> happen regardless of lock.
>
> Are you assuming some other malloc/free call could corrupt oldsize while
> they hold the lock?  If so, is there a published exploit description for
> this?
>
> .

>> hello DJ, thanks for your reply. there have two scenarios,

1, if two threads  call  realloc at the same time, and for the same  ptr.

   cause the oldsize is not protected by any lock, so if one thread has already finish resize the ptr and update the size,

  but the other thread still use the oldsize. so  after this thread got the mutex lock “__libc_lock_lock (ar_ptr->mutex)” in the _int_realloc,

  we should verify the  oldsize again.

2, two threads, one call free and the other call realloc,  with the same ptr.

    if the first " free" thread trigger memory consolidate and modify the ptr's size, 

   and then the other "realloc"  thread get the lock , but still use the oldsize, this'will cause corrupt.


although the man page has said this  will course unknow behavior, but i think this patch can reduce the impact.




  reply	other threads:[~2021-04-23  2:23 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-03-26 11:05 liqingqing
2021-04-01  8:51 ` liqingqing
2021-04-13 22:14   ` DJ Delorie
2021-04-23  2:23     ` liqingqing [this message]
2022-09-22 19:51 ` DJ Delorie

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=1128ec85-bd4f-a6e8-cc3b-ae17aa94d96b@huawei.com \
    --to=liqingqing3@huawei.com \
    --cc=dj@redhat.com \
    --cc=libc-alpha@sourceware.org \
    --cc=liusirui@huawei.com \
    --cc=wuxu.wu@huawei.com \
    /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).