Skip to content

Commit 3737df7

Browse files
Andrea Righimcgrof
authored andcommitted
module/decompress: use vmalloc() for gzip decompression workspace
Use a similar approach as commit a419bea ("module/decompress: use vmalloc() for zstd decompression workspace") and replace kmalloc() with vmalloc() also for the gzip module decompression workspace. In this case the workspace is represented by struct inflate_workspace that can be fairly large for kmalloc() and it can potentially lead to allocation errors on certain systems: $ pahole inflate_workspace struct inflate_workspace { struct inflate_state inflate_state; /* 0 9544 */ /* --- cacheline 149 boundary (9536 bytes) was 8 bytes ago --- */ unsigned char working_window[32768]; /* 9544 32768 */ /* size: 42312, cachelines: 662, members: 2 */ /* last cacheline: 8 bytes */ }; Considering that there is no need to use continuous physical memory, simply switch to vmalloc() to provide a more reliable in-kernel module decompression. Fixes: b1ae6dc ("module: add in-kernel support for decompressing") Signed-off-by: Andrea Righi <andrea.righi@canonical.com> Signed-off-by: Luis Chamberlain <mcgrof@kernel.org>
1 parent 62eedac commit 3737df7

1 file changed

Lines changed: 2 additions & 2 deletions

File tree

kernel/module/decompress.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,7 @@ static ssize_t module_gzip_decompress(struct load_info *info,
100100
s.next_in = buf + gzip_hdr_len;
101101
s.avail_in = size - gzip_hdr_len;
102102

103-
s.workspace = kmalloc(zlib_inflate_workspacesize(), GFP_KERNEL);
103+
s.workspace = vmalloc(zlib_inflate_workspacesize());
104104
if (!s.workspace)
105105
return -ENOMEM;
106106

@@ -138,7 +138,7 @@ static ssize_t module_gzip_decompress(struct load_info *info,
138138
out_inflate_end:
139139
zlib_inflateEnd(&s);
140140
out:
141-
kfree(s.workspace);
141+
vfree(s.workspace);
142142
return retval;
143143
}
144144
#elif defined(CONFIG_MODULE_COMPRESS_XZ)

0 commit comments

Comments
 (0)