Skip to contentSkip to conversation

xen/gunzip: free the code-length table on an overlong length run

PATCH In review Stefano Stabellini 2 participants 2 messages Oct 30 – Nov 2

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 xen/gunzip: free the code-length table on an overlong length run

inflate_dynamic() builds a decoding table from the code-length code lengths of a dynamic block and reads the literal/length and distance code lengths through it. A run of repeated or zero lengths that would go past the number of codes the block declares makes it refuse the block with 1, but that path only frees the list of code lengths: the table is left allocated, and nothing else frees it.

Free the table before returning on each of the three kinds of run. The other exits of inflate_dynamic() already free what they built, or are taken only after error() has stopped Xen.

Fixes e2b1ebf4de50 ("x86: Support booting a bzImage format domain 0 kernel.")
Cc Andrew Cooper <[email protected]>
Cc Anthony PERARD <[email protected]>
Cc Michal Orzel <[email protected]>
Cc Jan Beulich <[email protected]>
Cc Julien Grall <[email protected]>
Cc Roger Pau Monne <[email protected]>
---
 xen/common/gzip/inflate.c | 3 +++
 1 file changed, 3 insertions(+)
xen/common/gzip/inflate.c +3 -0
index cb146555c8..69bed78a38 100644
@@ -858,6 +858,7 @@ static int noinline __init inflate_dynamic(struct gunzip_state *s)
             j = 3 + ((unsigned)b & 3);
             DUMPBITS(2);
             if ((unsigned)i + j > n) {
+                huft_free(tl);
                 ret = 1;
                 goto out;
             }
@@ -870,6 +871,7 @@ static int noinline __init inflate_dynamic(struct gunzip_state *s)
             j = 3 + ((unsigned)b & 7);
             DUMPBITS(3);
             if ((unsigned)i + j > n) {
+                huft_free(tl);
                 ret = 1;
                 goto out;
             }
@@ -883,6 +885,7 @@ static int noinline __init inflate_dynamic(struct gunzip_state *s)
             j = 11 + ((unsigned)b & 0x7f);
             DUMPBITS(7);
             if ((unsigned)i + j > n) {
+                huft_free(tl);
                 ret = 1;
                 goto out;
             }
Signature · 1 line
2.47.3
Reviewed-by on v1 1/1
#1 lore raw
Quoted 7 lines · Stefano Stabellini

inflate_dynamic() builds a decoding table from the code-length code lengths of a dynamic block and reads the literal/length and distance code lengths through it. A run of repeated or zero lengths that would go past the number of codes the block declares makes it refuse the block with 1, but that path only frees the list of code lengths: the table is left allocated, and nothing else frees it.

Quoted 6 lines

Free the table before returning on each of the three kinds of run. The other exits of inflate_dynamic() already free what they built, or are taken only after error() has stopped Xen.

Fixes e2b1ebf4de50 ("x86: Support booting a bzImage format domain 0 kernel.")

Fiddling with code inherited from Linux isn't nice, but Linux long moved to a newer zlib baseline. Perhaps we should follow that, by doing a fresh import.

Jan