From: Lasse Collin <lasse.collin@tukaani.org>
To: Randy Dunlap <rdunlap@infradead.org>, Dongyang Zhan <zdyzztq@gmail.com>
Cc: linux-kernel@vger.kernel.org
Subject: Re: Possible memory leak in unxz()
Date: Sun, 10 May 2020 22:15:07 +0300 [thread overview]
Message-ID: <20200510221507.53c65961@tukaani.org> (raw)
In-Reply-To: <daf2f87a-155c-0836-cf82-0b409b860d6d@infradead.org>
> On 5/3/20 12:23 AM, Dongyang Zhan wrote:
> > I am a security researcher, my name is Dongyang Zhan. I found a
> > potential bug.
Thank you for looking for bugs!
On 2020-05-03 Randy Dunlap wrote:
> On 5/3/20 12:23 AM, Dongyang Zhan wrote:
> > /lib/decompress_unxz.c forgets to free the pointer 'in', when the
> > statement if (fill == NULL && flush == NULL) is true.
>
> Adding xz contributor to email.
>
> I think that you are correct. (I am looking at 5.7-rc4.)
>
> However, I don't see any calls to __decompress() in the
> Linux kernel that pass a first argument of NULL, so while
> the code in unxz() could be fixed, we aren't currently leaking
> any memory AFAICT.
The supposedly leaked memory is allocated only when in == NULL, and
it's not freed when fill == NULL && flush == NULL. However, "in" and
"fill" must never be NULL at the same time if the caller is following
the decompress_fn API defined in include/linux/decompress/generic.h. So
there is no leak.
Some implementations of the API explicitly check for input == NULL &&
fill == NULL while some don't. E.g. decompress_unlz4.c checks it but in
addition it seems to also reject the case where input != NULL && fill
!= NULL. Perhaps that combination isn't used anywhere but it is allowed
by the API ("input" would be a temporary buffer for "fill"). I think
the decompress_fn API is more complex than it looks at glance.
--
Lasse Collin | IRC: Larhzu @ IRCnet & Freenode
prev parent reply other threads:[~2020-05-10 19:26 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2020-05-03 7:23 Dongyang Zhan
2020-05-04 3:58 ` Randy Dunlap
2020-05-10 19:15 ` Lasse Collin [this message]
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=20200510221507.53c65961@tukaani.org \
--to=lasse.collin@tukaani.org \
--cc=linux-kernel@vger.kernel.org \
--cc=rdunlap@infradead.org \
--cc=zdyzztq@gmail.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
all inboxes | Powered by JetHome®