[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]

[Libguestfs] [PATCH supermin 9/9] kernel: Reject implausibly small kernels in /lib/modules (RHBZ#1477758).



Previous changes will reject truncated / implausibly small kernel
files found under /boot, but because the code that looks for kernels
in /lib/modules works slightly differently it would not work there.
This uses a simple stat check to reject kernels there too.

Reported by Charlie Martinez.
---
 src/format_ext2_kernel.ml | 14 +++++++++-----
 1 file changed, 9 insertions(+), 5 deletions(-)

diff --git a/src/format_ext2_kernel.ml b/src/format_ext2_kernel.ml
index 44ba035..d5d529d 100644
--- a/src/format_ext2_kernel.ml
+++ b/src/format_ext2_kernel.ml
@@ -93,12 +93,16 @@ and find_kernel_from_lib_modules debug =
     let files = glob "/lib/modules/*/vmlinuz" [GLOB_NOSORT; GLOB_NOESCAPE] in
     let files = Array.to_list files in
     let kernels =
-      List.map (
+      filter_map (
         fun kernel_file ->
-          let kernel_name = Filename.basename kernel_file in
-          let modpath = Filename.dirname kernel_file in
-          let kernel_version = Filename.basename modpath in
-          kernel_file, kernel_name, kernel_version, modpath
+          let size = try (stat kernel_file).st_size with Unix_error _ -> 0 in
+          if size < 10000 then None
+          else (
+            let kernel_name = Filename.basename kernel_file in
+            let modpath = Filename.dirname kernel_file in
+            let kernel_version = Filename.basename modpath in
+            Some (kernel_file, kernel_name, kernel_version, modpath)
+          )
       ) files in
     List.sort (
       fun (_, _, a, _) (_, _, b, _) -> compare_version b a
-- 
2.13.1


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]