mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Ivy Lopez <skunkolee@gmail.com>
To: akpm@linux-foundation.org, lasse.collin@tukaani.org
Cc: linux-kernel@vger.kernel.org, Ivy Lopez <skunkolee@gmail.com>
Subject: [PATCH] lib: decompress_unxz: fix memory leak of 'in' buffer in single-call mode
Date: Tue, 25 Aug 2026 13:13:33 -0600	[thread overview]
Message-ID: <20260825191333.34276-1-skunkolee@gmail.com> (raw)

When fill and flush are both NULL (single-call mode), unxz() takes
the xz_dec_run() fast path and skips straight to xz_dec_end(s),
bypassing the free(in)/free(b.out) cleanup that only runs inside the
multi-call (fill/flush) branch. If 'in' was NULL on entry, it gets
allocated locally (must_free_in = true) and is never freed on this
path, leaking XZ_IOBUF_SIZE bytes on every single-call decompression
that doesn't supply its own input buffer.

Move the must_free_in/flush cleanup out of the multi-call branch so
it runs after both paths.

Link: https://bugzilla.kernel.org/show_bug.cgi?id=207113
Signed-off-by: Ivy Lopez <skunkolee@gmail.com>
---
 lib/decompress_unxz.c | 10 +++++-----
 1 file changed, 5 insertions(+), 5 deletions(-)

diff --git a/lib/decompress_unxz.c b/lib/decompress_unxz.c
index 05d5cb490a44..9ccded9934c6 100644
--- a/lib/decompress_unxz.c
+++ b/lib/decompress_unxz.c
@@ -342,13 +342,13 @@ STATIC int INIT unxz(unsigned char *in, long in_size,
 				b.out_pos = 0;
 			}
 		} while (ret == XZ_OK);
+	}
 
-		if (must_free_in)
-			free(in);
+	if (must_free_in)
+		free(in);
 
-		if (flush != NULL)
-			free(b.out);
-	}
+	if (flush != NULL)
+		free(b.out);
 
 	if (in_used != NULL)
 		*in_used += b.in_pos;
-- 
2.55.0


             reply	other threads:[~2026-08-25 19:13 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-08-25 19:13 Ivy Lopez [this message]
2026-08-25 20:08 ` Lasse Collin
2026-08-26 18:04   ` Lasse Collin

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=20260825191333.34276-1-skunkolee@gmail.com \
    --to=skunkolee@gmail.com \
    --cc=akpm@linux-foundation.org \
    --cc=lasse.collin@tukaani.org \
    --cc=linux-kernel@vger.kernel.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

all inboxes | Powered by JetHome®