From 89ce60056c160e1aa1af5fcc943778c647c65e6b Mon Sep 17 00:00:00 2001 From: Sasha Levin Date: Sun, 12 Nov 2023 14:19:17 -0500 Subject: [PATCH] Fixes for 6.5 Signed-off-by: Sasha Levin --- ...decompress-use-kvmalloc-consistently.patch | 71 +++++++++++++++++++ queue-6.5/series | 1 + 2 files changed, 72 insertions(+) create mode 100644 queue-6.5/module-decompress-use-kvmalloc-consistently.patch diff --git a/queue-6.5/module-decompress-use-kvmalloc-consistently.patch b/queue-6.5/module-decompress-use-kvmalloc-consistently.patch new file mode 100644 index 00000000000..8be22d11f04 --- /dev/null +++ b/queue-6.5/module-decompress-use-kvmalloc-consistently.patch @@ -0,0 +1,71 @@ +From 2d83945cffbd20257b4a682469486821bf6276cc Mon Sep 17 00:00:00 2001 +From: Sasha Levin +Date: Thu, 2 Nov 2023 09:19:14 +0100 +Subject: module/decompress: use kvmalloc() consistently + +From: Andrea Righi + +[ Upstream commit 17fc8084aa8f9d5235f252fc3978db657dd77e92 ] + +We consistently switched from kmalloc() to vmalloc() in module +decompression to prevent potential memory allocation failures with large +modules, however vmalloc() is not as memory-efficient and fast as +kmalloc(). + +Since we don't know in general the size of the workspace required by the +decompression algorithm, it is more reasonable to use kvmalloc() +consistently, also considering that we don't have special memory +requirements here. + +Suggested-by: Linus Torvalds +Tested-by: Andrea Righi +Signed-off-by: Andrea Righi +Signed-off-by: Linus Torvalds +Signed-off-by: Sasha Levin +--- + kernel/module/decompress.c | 8 ++++---- + 1 file changed, 4 insertions(+), 4 deletions(-) + +diff --git a/kernel/module/decompress.c b/kernel/module/decompress.c +index 4156d59be4408..474e68f0f0634 100644 +--- a/kernel/module/decompress.c ++++ b/kernel/module/decompress.c +@@ -100,7 +100,7 @@ static ssize_t module_gzip_decompress(struct load_info *info, + s.next_in = buf + gzip_hdr_len; + s.avail_in = size - gzip_hdr_len; + +- s.workspace = vmalloc(zlib_inflate_workspacesize()); ++ s.workspace = kvmalloc(zlib_inflate_workspacesize(), GFP_KERNEL); + if (!s.workspace) + return -ENOMEM; + +@@ -138,7 +138,7 @@ static ssize_t module_gzip_decompress(struct load_info *info, + out_inflate_end: + zlib_inflateEnd(&s); + out: +- vfree(s.workspace); ++ kvfree(s.workspace); + return retval; + } + #elif defined(CONFIG_MODULE_COMPRESS_XZ) +@@ -241,7 +241,7 @@ static ssize_t module_zstd_decompress(struct load_info *info, + } + + wksp_size = zstd_dstream_workspace_bound(header.windowSize); +- wksp = vmalloc(wksp_size); ++ wksp = kvmalloc(wksp_size, GFP_KERNEL); + if (!wksp) { + retval = -ENOMEM; + goto out; +@@ -284,7 +284,7 @@ static ssize_t module_zstd_decompress(struct load_info *info, + retval = new_size; + + out: +- vfree(wksp); ++ kvfree(wksp); + return retval; + } + #else +-- +2.42.0 + diff --git a/queue-6.5/series b/queue-6.5/series index 3f0f4f90b6c..69dbdcd499e 100644 --- a/queue-6.5/series +++ b/queue-6.5/series @@ -527,3 +527,4 @@ netfilter-xt_recent-fix-increase-ipv6-literal-buffer.patch netfilter-nat-fix-ipv6-nat-redirect-with-mapped-and-.patch net-sched-act_ct-always-fill-offloading-tuple-iifidx.patch risc-v-don-t-fail-in-riscv_of_parent_hartid-for-disa.patch +module-decompress-use-kvmalloc-consistently.patch -- 2.47.3