Richard W.M. Jones
2017-Aug-03 12:59 UTC
[Libguestfs] [PATCH supermin 0/9] kernel: Multiple fixes to handling of kernels (RHBZ#1477758).
This patch series fixes several problems in the way that supermin handles kernels. The most pressing problem is that supermin doesn't handle bogus vmlinuz files which aren't actual kernels. Along the way there is a lot of clean up. The patches look much better if you view them with ‘-w’. This series will require plenty of time to be tested in Fedora, especially on non-x86 arches. Rich.
Richard W.M. Jones
2017-Aug-03 12:59 UTC
[Libguestfs] [PATCH supermin 1/9] kernel: Refactor code for locating the kernel.
Refactor the code for locating the kernel into separate functions, making clear the purpose of each part of the code. This is pure refactoring and doesn't change the meaning of the code. --- src/format_ext2_kernel.ml | 126 ++++++++++++++++++++++++++-------------------- 1 file changed, 72 insertions(+), 54 deletions(-) diff --git a/src/format_ext2_kernel.ml b/src/format_ext2_kernel.ml index 5d1ae66..a12fbd2 100644 --- a/src/format_ext2_kernel.ml +++ b/src/format_ext2_kernel.ml @@ -40,49 +40,21 @@ let patt_of_cpu host_cpu List.map (fun model -> sprintf "vmlinu?-*-%s" model) models let rec build_kernel debug host_cpu copy_kernel kernel - (* Locate the kernel. *) + (* Locate the kernel. + * SUPERMIN_* environment variables override everything. If those + * are not present then we look in /lib/modules and /boot. + *) let kernel_file, kernel_name, kernel_version, modpath - try - let kernel_env = getenv "SUPERMIN_KERNEL" in - if debug >= 1 then - printf "supermin: kernel: SUPERMIN_KERNEL environment variable %s\n%!" - kernel_env; - let kernel_version - try - let v = getenv "SUPERMIN_KERNEL_VERSION" in - if debug >= 1 then - printf "supermin: kernel: SUPERMIN_KERNEL_VERSION environment variable %s\n%!" v; - v - with Not_found -> get_kernel_version_from_file kernel_env in - if debug >= 1 then - printf "supermin: kernel: SUPERMIN_KERNEL version %s\n%!" - kernel_version; - let kernel_name = Filename.basename kernel_env in - let modpath = find_modpath debug kernel_version in - kernel_env, kernel_name, kernel_version, modpath - with Not_found -> - let kernels - let files = glob "/lib/modules/*/vmlinuz" [GLOB_NOSORT; GLOB_NOESCAPE] in - let files = Array.to_list files in - let kernels - List.map ( - fun f -> - let modpath = Filename.dirname f in - f, Filename.basename f, Filename.basename modpath, modpath - ) files in - List.sort ( - fun (_, _, a, _) (_, _, b, _) -> compare_version b a - ) kernels in - - if kernels <> [] then ( - let kernel = List.hd kernels in - if debug >= 1 then ( - let kernel_file, _, _, _ = kernel in - printf "supermin: kernel: picked vmlinuz %s\n%!" kernel_file; - ); - kernel - ) else - find_kernel debug host_cpu kernel in + match find_kernel_from_env_vars debug with + | Some k -> k + | None -> + match find_kernel_from_lib_modules debug with + | Some k -> k + | None -> + match find_kernel_from_boot debug host_cpu with + | Some k -> k + | None -> + error_no_kernels host_cpu in if debug >= 1 then ( printf "supermin: kernel: kernel_version %s\n" kernel_version; @@ -93,7 +65,52 @@ let rec build_kernel debug host_cpu copy_kernel kernel (kernel_version, modpath) -and find_kernel debug host_cpu kernel +and find_kernel_from_env_vars debug + try + let kernel_env = getenv "SUPERMIN_KERNEL" in + if debug >= 1 then + printf "supermin: kernel: SUPERMIN_KERNEL environment variable %s\n%!" + kernel_env; + let kernel_version + try + let v = getenv "SUPERMIN_KERNEL_VERSION" in + if debug >= 1 then + printf "supermin: kernel: SUPERMIN_KERNEL_VERSION environment variable %s\n%!" v; + v + with Not_found -> get_kernel_version_from_file kernel_env in + if debug >= 1 then + printf "supermin: kernel: SUPERMIN_KERNEL version %s\n%!" + kernel_version; + let kernel_name = Filename.basename kernel_env in + let modpath = find_modpath debug kernel_version in + Some (kernel_env, kernel_name, kernel_version, modpath) + with Not_found -> None + +and find_kernel_from_lib_modules debug + let kernels + let files = glob "/lib/modules/*/vmlinuz" [GLOB_NOSORT; GLOB_NOESCAPE] in + let files = Array.to_list files in + let kernels + List.map ( + fun f -> + let modpath = Filename.dirname f in + f, Filename.basename f, Filename.basename modpath, modpath + ) files in + List.sort ( + fun (_, _, a, _) (_, _, b, _) -> compare_version b a + ) kernels in + + if kernels <> [] then ( + let kernel = List.hd kernels in + if debug >= 1 then ( + let kernel_file, _, _, _ = kernel in + printf "supermin: kernel: picked vmlinuz %s\n%!" kernel_file; + ); + Some kernel + ) else + None + +and find_kernel_from_boot debug host_cpu let is_arm String.length host_cpu >= 3 && host_cpu.[0] = 'a' && host_cpu.[1] = 'r' && host_cpu.[2] = 'm' in @@ -111,19 +128,20 @@ and find_kernel debug host_cpu kernel (* In original: ls -1dvr /boot/vmlinuz-* 2>/dev/null | grep -v xen *) kernel_filter ["vmlinu?-*"] is_arm all_files in - if files = [] then no_kernels host_cpu; - - let files = List.sort (fun a b -> compare_version b a) files in - let kernel_name = List.hd files in - let kernel_version = get_kernel_version kernel_name in + if files = [] then None + else ( + let files = List.sort (fun a b -> compare_version b a) files in + let kernel_name = List.hd files in + let kernel_version = get_kernel_version kernel_name in - if debug >= 1 then - printf "supermin: kernel: picked kernel %s\n%!" kernel_name; + if debug >= 1 then + printf "supermin: kernel: picked kernel %s\n%!" kernel_name; - (* Get the kernel modules. *) - let modpath = find_modpath debug kernel_version in + (* Get the kernel modules. *) + let modpath = find_modpath debug kernel_version in - ("/boot" // kernel_name), kernel_name, kernel_version, modpath + Some (("/boot" // kernel_name), kernel_name, kernel_version, modpath) + ) and kernel_filter patterns is_arm all_files let files @@ -143,7 +161,7 @@ and kernel_filter patterns is_arm all_files ) in List.filter (fun filename -> has_modpath filename) files -and no_kernels host_cpu +and error_no_kernels host_cpu error "\ failed to find a suitable kernel (host_cpu=%s). -- 2.13.1
Richard W.M. Jones
2017-Aug-03 12:59 UTC
[Libguestfs] [PATCH supermin 2/9] kernel: Tweak debug messages.
Rework the debug messages so it's clearer in debugging messages how the kernel was located. Also removes duplicated debugging information. This is cleanup, there is no functional change. --- src/format_ext2_kernel.ml | 35 ++++++++++++++--------------------- 1 file changed, 14 insertions(+), 21 deletions(-) diff --git a/src/format_ext2_kernel.ml b/src/format_ext2_kernel.ml index a12fbd2..90fa56f 100644 --- a/src/format_ext2_kernel.ml +++ b/src/format_ext2_kernel.ml @@ -45,20 +45,27 @@ let rec build_kernel debug host_cpu copy_kernel kernel * are not present then we look in /lib/modules and /boot. *) let kernel_file, kernel_name, kernel_version, modpath + if debug >= 1 then + printf "supermin: kernel: looking for kernel using environment variables ...\n%!"; match find_kernel_from_env_vars debug with | Some k -> k | None -> + if debug >= 1 then + printf "supermin: kernel: looking for kernels in /lib/modules/*/vmlinuz ...\n%!"; match find_kernel_from_lib_modules debug with | Some k -> k | None -> + if debug >= 1 then + printf "supermin: kernel: looking for kernels in /boot ...\n%!"; match find_kernel_from_boot debug host_cpu with | Some k -> k | None -> error_no_kernels host_cpu in if debug >= 1 then ( + printf "supermin: kernel: picked vmlinuz %s\n%!" kernel_file; printf "supermin: kernel: kernel_version %s\n" kernel_version; - printf "supermin: kernel: modules %s\n%!" modpath; + printf "supermin: kernel: modpath %s\n%!" modpath; ); copy_or_symlink_file copy_kernel kernel_file kernel; @@ -69,18 +76,14 @@ and find_kernel_from_env_vars debug try let kernel_env = getenv "SUPERMIN_KERNEL" in if debug >= 1 then - printf "supermin: kernel: SUPERMIN_KERNEL environment variable %s\n%!" - kernel_env; + printf "supermin: kernel: SUPERMIN_KERNEL=%s\n%!" kernel_env; let kernel_version try let v = getenv "SUPERMIN_KERNEL_VERSION" in if debug >= 1 then - printf "supermin: kernel: SUPERMIN_KERNEL_VERSION environment variable %s\n%!" v; + printf "supermin: kernel: SUPERMIN_KERNEL_VERSION=%s\n%!" v; v with Not_found -> get_kernel_version_from_file kernel_env in - if debug >= 1 then - printf "supermin: kernel: SUPERMIN_KERNEL version %s\n%!" - kernel_version; let kernel_name = Filename.basename kernel_env in let modpath = find_modpath debug kernel_version in Some (kernel_env, kernel_name, kernel_version, modpath) @@ -100,15 +103,9 @@ and find_kernel_from_lib_modules debug fun (_, _, a, _) (_, _, b, _) -> compare_version b a ) kernels in - if kernels <> [] then ( - let kernel = List.hd kernels in - if debug >= 1 then ( - let kernel_file, _, _, _ = kernel in - printf "supermin: kernel: picked vmlinuz %s\n%!" kernel_file; - ); - Some kernel - ) else - None + match kernels with + | kernel :: _ -> Some kernel + | [] -> None and find_kernel_from_boot debug host_cpu let is_arm @@ -134,9 +131,6 @@ and find_kernel_from_boot debug host_cpu let kernel_name = List.hd files in let kernel_version = get_kernel_version kernel_name in - if debug >= 1 then - printf "supermin: kernel: picked kernel %s\n%!" kernel_name; - (* Get the kernel modules. *) let modpath = find_modpath debug kernel_version in @@ -176,8 +170,7 @@ and find_modpath debug kernel_version try let modpath = getenv "SUPERMIN_MODULES" in if debug >= 1 then - printf "supermin: kernel: SUPERMIN_MODULES environment variable = %s\n%!" - modpath; + printf "supermin: kernel: SUPERMIN_MODULES=%s\n%!" modpath; modpath with Not_found -> let modpath = "/lib/modules/" ^ kernel_version in -- 2.13.1
Richard W.M. Jones
2017-Aug-03 12:59 UTC
[Libguestfs] [PATCH supermin 3/9] kernel: Rearrange the order of functions.
Rearrange the order of functions more logically. Just code motion, no functional change. --- src/format_ext2_kernel.ml | 50 +++++++++++++++++++++++------------------------ 1 file changed, 25 insertions(+), 25 deletions(-) diff --git a/src/format_ext2_kernel.ml b/src/format_ext2_kernel.ml index 90fa56f..e2f8e4b 100644 --- a/src/format_ext2_kernel.ml +++ b/src/format_ext2_kernel.ml @@ -24,21 +24,6 @@ open Ext2fs open Fnmatch open Glob -let patt_of_cpu host_cpu - let models - match host_cpu with - | "mips" | "mips64" -> [host_cpu; "*-malta"] - | "ppc" | "powerpc" | "powerpc64" -> ["ppc"; "powerpc"; "powerpc64"] - | "sparc" | "sparc64" -> ["sparc"; "sparc64"] - | "amd64" | "x86_64" -> ["amd64"; "x86_64"] - | "parisc" | "parisc64" -> ["hppa"; "hppa64"] - | "ppc64el" -> ["powerpc64le"] - | _ when host_cpu.[0] = 'i' && host_cpu.[2] = '8' && host_cpu.[3] = '6' -> ["?86"] - | _ when String.length host_cpu >= 5 && String.sub host_cpu 0 5 = "armv7" -> ["armmp"] - | _ -> [host_cpu] - in - List.map (fun model -> sprintf "vmlinu?-*-%s" model) models - let rec build_kernel debug host_cpu copy_kernel kernel (* Locate the kernel. * SUPERMIN_* environment variables override everything. If those @@ -72,6 +57,17 @@ let rec build_kernel debug host_cpu copy_kernel kernel (kernel_version, modpath) +and error_no_kernels host_cpu + error "\ +failed to find a suitable kernel (host_cpu=%s). + +I looked for kernels in /boot and modules in /lib/modules. + +If this is a Xen guest, and you only have Xen domU kernels +installed, try installing a fullvirt kernel (only for +supermin use, you shouldn't boot the Xen guest with it)." + host_cpu + and find_kernel_from_env_vars debug try let kernel_env = getenv "SUPERMIN_KERNEL" in @@ -155,16 +151,20 @@ and kernel_filter patterns is_arm all_files ) in List.filter (fun filename -> has_modpath filename) files -and error_no_kernels host_cpu - error "\ -failed to find a suitable kernel (host_cpu=%s). - -I looked for kernels in /boot and modules in /lib/modules. - -If this is a Xen guest, and you only have Xen domU kernels -installed, try installing a fullvirt kernel (only for -supermin use, you shouldn't boot the Xen guest with it)." - host_cpu +and patt_of_cpu host_cpu + let models + match host_cpu with + | "mips" | "mips64" -> [host_cpu; "*-malta"] + | "ppc" | "powerpc" | "powerpc64" -> ["ppc"; "powerpc"; "powerpc64"] + | "sparc" | "sparc64" -> ["sparc"; "sparc64"] + | "amd64" | "x86_64" -> ["amd64"; "x86_64"] + | "parisc" | "parisc64" -> ["hppa"; "hppa64"] + | "ppc64el" -> ["powerpc64le"] + | _ when host_cpu.[0] = 'i' && host_cpu.[2] = '8' && host_cpu.[3] = '6' -> ["?86"] + | _ when String.length host_cpu >= 5 && String.sub host_cpu 0 5 = "armv7" -> ["armmp"] + | _ -> [host_cpu] + in + List.map (fun model -> sprintf "vmlinu?-*-%s" model) models and find_modpath debug kernel_version try -- 2.13.1
Richard W.M. Jones
2017-Aug-03 12:59 UTC
[Libguestfs] [PATCH supermin 4/9] kernel: Filter /boot kernels using has_modpath later.
/boot kernels are filtered using the has_modpath function. This change just moves the test later, which has no effect here but makes subsequent cleanups simpler. --- src/format_ext2_kernel.ml | 25 +++++++++++++++---------- 1 file changed, 15 insertions(+), 10 deletions(-) diff --git a/src/format_ext2_kernel.ml b/src/format_ext2_kernel.ml index e2f8e4b..c44ae23 100644 --- a/src/format_ext2_kernel.ml +++ b/src/format_ext2_kernel.ml @@ -121,17 +121,22 @@ and find_kernel_from_boot debug host_cpu (* In original: ls -1dvr /boot/vmlinuz-* 2>/dev/null | grep -v xen *) kernel_filter ["vmlinu?-*"] is_arm all_files in - if files = [] then None - else ( - let files = List.sort (fun a b -> compare_version b a) files in - let kernel_name = List.hd files in - let kernel_version = get_kernel_version kernel_name in + let files = List.sort (fun a b -> compare_version b a) files in + let kernels + List.map ( + fun kernel_name -> + let kernel_version = get_kernel_version kernel_name in + let kernel_file = "/boot" // kernel_name in + let modpath = find_modpath debug kernel_version in + (kernel_file, kernel_name, kernel_version, modpath) + ) files in - (* Get the kernel modules. *) - let modpath = find_modpath debug kernel_version in + let kernels + List.filter (fun (_, kernel_name, _, _) -> has_modpath kernel_name) kernels in - Some (("/boot" // kernel_name), kernel_name, kernel_version, modpath) - ) + match kernels with + | kernel :: _ -> Some kernel + | [] -> None and kernel_filter patterns is_arm all_files let files @@ -149,7 +154,7 @@ and kernel_filter patterns is_arm all_files find filename "tegra" = -1 ) files ) in - List.filter (fun filename -> has_modpath filename) files + files and patt_of_cpu host_cpu let models -- 2.13.1
Richard W.M. Jones
2017-Aug-03 12:59 UTC
[Libguestfs] [PATCH supermin 5/9] kernel: Change has_modpath function so it checks for modpath // modules.dep.
--- src/format_ext2_kernel.ml | 11 ++++------- 1 file changed, 4 insertions(+), 7 deletions(-) diff --git a/src/format_ext2_kernel.ml b/src/format_ext2_kernel.ml index c44ae23..0bb67fe 100644 --- a/src/format_ext2_kernel.ml +++ b/src/format_ext2_kernel.ml @@ -132,7 +132,7 @@ and find_kernel_from_boot debug host_cpu ) files in let kernels - List.filter (fun (_, kernel_name, _, _) -> has_modpath kernel_name) kernels in + List.filter (fun (_, _, _, modpath) -> has_modpath modpath) kernels in match kernels with | kernel :: _ -> Some kernel @@ -183,12 +183,9 @@ and find_modpath debug kernel_version printf "supermin: kernel: picked modules path %s\n%!" modpath; modpath -and has_modpath kernel_name - try - let kv = get_kernel_version kernel_name in - modules_dep_exists kv - with - | Not_found -> false +and has_modpath modpath + try (stat (modpath // "modules.dep")).st_kind = S_REG + with Unix_error _ -> false and get_kernel_version kernel_name if (string_prefix "vmlinuz-" kernel_name) || -- 2.13.1
Richard W.M. Jones
2017-Aug-03 12:59 UTC
[Libguestfs] [PATCH supermin 6/9] kernel: Replace how kernel version information is found.
The old code was fairly bogus. In the new code there is one "public" function: val get_kernel_version : bool -> string -> string option which takes a full vmlinuz path and returns the kernel version from it if possible (or None if not). This function first looks at the file content to see if the version can be extracted, and if that fails looks at the filename. As a side effect of making this change, we also filter out kernels from /boot where we cannot read the kernel version. --- src/format_ext2_kernel.ml | 78 +++++++++++++++++++++++++++++++---------------- 1 file changed, 51 insertions(+), 27 deletions(-) diff --git a/src/format_ext2_kernel.ml b/src/format_ext2_kernel.ml index 0bb67fe..55c5af9 100644 --- a/src/format_ext2_kernel.ml +++ b/src/format_ext2_kernel.ml @@ -79,7 +79,10 @@ and find_kernel_from_env_vars debug if debug >= 1 then printf "supermin: kernel: SUPERMIN_KERNEL_VERSION=%s\n%!" v; v - with Not_found -> get_kernel_version_from_file kernel_env in + with Not_found -> + match get_kernel_version debug kernel_env with + | Some v -> v + | None -> raise Not_found in let kernel_name = Filename.basename kernel_env in let modpath = find_modpath debug kernel_version in Some (kernel_env, kernel_name, kernel_version, modpath) @@ -123,17 +126,17 @@ and find_kernel_from_boot debug host_cpu let files = List.sort (fun a b -> compare_version b a) files in let kernels - List.map ( + filter_map ( fun kernel_name -> - let kernel_version = get_kernel_version kernel_name in let kernel_file = "/boot" // kernel_name in - let modpath = find_modpath debug kernel_version in - (kernel_file, kernel_name, kernel_version, modpath) + match get_kernel_version debug kernel_file with + | None -> None + | Some kernel_version -> + let modpath = find_modpath debug kernel_version in + if not (has_modpath modpath) then None + else Some (kernel_file, kernel_name, kernel_version, modpath) ) files in - let kernels - List.filter (fun (_, _, _, modpath) -> has_modpath modpath) kernels in - match kernels with | kernel :: _ -> Some kernel | [] -> None @@ -187,24 +190,43 @@ and has_modpath modpath try (stat (modpath // "modules.dep")).st_kind = S_REG with Unix_error _ -> false -and get_kernel_version kernel_name - if (string_prefix "vmlinuz-" kernel_name) || - (string_prefix "vmlinux-" kernel_name) then ( - let kv = String.sub kernel_name 8 (String.length kernel_name - 8) in - if modules_dep_exists kv then kv - else get_kernel_version_from_name kernel_name - ) else get_kernel_version_from_name kernel_name - -and modules_dep_exists kv - try (lstat ("/lib/modules/" ^ kv ^ "/modules.dep")).st_kind = S_REG - with Unix_error _ -> false - -and get_kernel_version_from_name kernel_name - get_kernel_version_from_file ("/boot" // kernel_name) +(* Extract the kernel version from a Linux kernel file. + * + * This first sees if we can get the information from the file + * content (see below) and if that fails tries to parse the + * filename. + *) +and get_kernel_version debug kernel_file + if debug >= 1 then + printf "supermin: kernel: kernel version of %s%!" kernel_file; + match get_kernel_version_from_file_content kernel_file with + | Some version -> + if debug >= 1 then printf " = %s (from content)\n%!" version; + Some version + | None -> + (* Try to work it out from the filename instead. *) + let basename = Filename.basename kernel_file in + if string_prefix "vmlinuz-" basename || string_prefix "vmlinux-" basename + then ( + let version = String.sub basename 8 (String.length basename - 8) in + (* Does the version look reasonable? *) + let modpath = "/lib/modules" // version in + if has_modpath modpath then ( + if debug >= 1 then printf " = %s (from filename)\n%!" version; + Some version + ) else ( + if debug >= 1 then printf " = error, no modpath\n%!"; + None + ) + ) + else ( + if debug >= 1 then printf " = error, cannot parse filename\n%!"; + None + ) (* Extract the kernel version from a Linux kernel file. * - * Returns a string containing the version or [Not_found] if the + * Returns a string containing the version or [None] if the * file can't be read, is not a Linux kernel, or the version can't * be found. * @@ -217,7 +239,7 @@ and get_kernel_version_from_name kernel_name * * Bugs: probably limited to x86 kernels. *) -and get_kernel_version_from_file file +and get_kernel_version_from_file_content file try let chan = open_in file in let buf = read_string chan 514 4 in @@ -247,10 +269,12 @@ and get_kernel_version_from_file file ) else raise Not_found in - loop 0 + let version = loop 0 in + Some version with - | Sys_error _ -> raise Not_found - | Invalid_argument _ -> raise Not_found + | Not_found + | Sys_error _ + | Invalid_argument _ -> None (* Read an unsigned little endian short at a specified offset in a file. *) and read_leshort chan offset -- 2.13.1
Richard W.M. Jones
2017-Aug-03 12:59 UTC
[Libguestfs] [PATCH supermin 7/9] kernel: Don't allow End_of_file exception to escape if kernel is bogus (RHBZ#1477758).
If the kernel file is truncated (zero length or too short) then functions such as ‘really_input’ raise End_of_file. Unfortunately this exception could escape and kill the program. What we want to do instead is to ignore such kernels. The combination of this commit and the last commit ignores such kernels if they are found in /boot. Reported by Charlie Martinez. --- src/format_ext2_kernel.ml | 1 + 1 file changed, 1 insertion(+) diff --git a/src/format_ext2_kernel.ml b/src/format_ext2_kernel.ml index 55c5af9..e329adb 100644 --- a/src/format_ext2_kernel.ml +++ b/src/format_ext2_kernel.ml @@ -273,6 +273,7 @@ and get_kernel_version_from_file_content file Some version with | Not_found + | End_of_file | Sys_error _ | Invalid_argument _ -> None -- 2.13.1
Richard W.M. Jones
2017-Aug-03 12:59 UTC
[Libguestfs] [PATCH supermin 8/9] kernel: Simple renaming to make find_kernel_from_* functions consistent.
No functional change, just renaming variables. --- src/format_ext2_kernel.ml | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/src/format_ext2_kernel.ml b/src/format_ext2_kernel.ml index e329adb..44ba035 100644 --- a/src/format_ext2_kernel.ml +++ b/src/format_ext2_kernel.ml @@ -94,9 +94,11 @@ and find_kernel_from_lib_modules debug let files = Array.to_list files in let kernels List.map ( - fun f -> - let modpath = Filename.dirname f in - f, Filename.basename f, Filename.basename modpath, modpath + 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 ) files in List.sort ( fun (_, _, a, _) (_, _, b, _) -> compare_version b a -- 2.13.1
Richard W.M. Jones
2017-Aug-03 12:59 UTC
[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
Pino Toscano
2017-Aug-03 15:13 UTC
Re: [Libguestfs] [PATCH supermin 0/9] kernel: Multiple fixes to handling of kernels (RHBZ#1477758).
On Thursday, 3 August 2017 14:59:22 CEST Richard W.M. Jones wrote:> This patch series fixes several problems in the way that supermin > handles kernels. The most pressing problem is that supermin doesn't > handle bogus vmlinuz files which aren't actual kernels. Along the way > there is a lot of clean up. > > The patches look much better if you view them with ‘-w’. > > This series will require plenty of time to be tested in Fedora, > especially on non-x86 arches.LGTM. -- Pino Toscano
Richard Jones
2017-Aug-03 19:41 UTC
[Libguestfs] check-syntax FAILED (was: Re: [PATCH supermin 9/9] kernel: Reject implausibly small kernels in /lib/modules (RHBZ#1477758).)
Checking out sources from https://github.com/libguestfs/supermin ... /var/tmp/tmpngZZnL/supermin /var/tmp/tmpngZZnL Reset branch 'master' Branch master set up to track remote branch master from origin. Your branch is up-to-date with 'origin/master'.>From github.com:libguestfs/superminec1dd57..ea3b3dc master -> origin/master Updating ec1dd57..ea3b3dc Fast-forward src/format_ext2_kernel.ml | 256 +++++++++++++++++++++++++++------------------- src/mode_prepare.ml | 9 +- 2 files changed, 157 insertions(+), 108 deletions(-) /var/tmp/tmpngZZnL Applying patches ... /var/tmp/tmpngZZnL/supermin /var/tmp/tmpngZZnL error: patch failed: src/format_ext2_kernel.ml:40 error: src/format_ext2_kernel.ml: patch does not apply Applying: kernel: Refactor code for locating the kernel. Patch failed at 0001 kernel: Refactor code for locating the kernel. The copy of the patch that failed is found in: .git/rebase-apply/patch When you have resolved this problem, run "git am --continue". If you prefer to skip this patch, run "git am --skip" instead. To restore the original branch and stop patching, run "git am --abort".
Richard Jones
2017-Aug-03 19:41 UTC
[Libguestfs] check-release FAILED (was: Re: [PATCH supermin 9/9] kernel: Reject implausibly small kernels in /lib/modules (RHBZ#1477758).)
Checking out sources from https://github.com/libguestfs/supermin ... /var/tmp/tmpbxkAPf/supermin /var/tmp/tmpbxkAPf Reset branch 'master' Branch master set up to track remote branch master from origin. Your branch is up-to-date with 'origin/master'.>From github.com:libguestfs/superminec1dd57..ea3b3dc master -> origin/master Updating ec1dd57..ea3b3dc Fast-forward src/format_ext2_kernel.ml | 256 +++++++++++++++++++++++++++------------------- src/mode_prepare.ml | 9 +- 2 files changed, 157 insertions(+), 108 deletions(-) /var/tmp/tmpbxkAPf Applying patches ... /var/tmp/tmpbxkAPf/supermin /var/tmp/tmpbxkAPf error: patch failed: src/format_ext2_kernel.ml:40 error: src/format_ext2_kernel.ml: patch does not apply Applying: kernel: Refactor code for locating the kernel. Patch failed at 0001 kernel: Refactor code for locating the kernel. The copy of the patch that failed is found in: .git/rebase-apply/patch When you have resolved this problem, run "git am --continue". If you prefer to skip this patch, run "git am --skip" instead. To restore the original branch and stop patching, run "git am --abort".
Pino Toscano
2017-Aug-08 12:32 UTC
Re: [Libguestfs] [PATCH supermin 0/9] kernel: Multiple fixes to handling of kernels (RHBZ#1477758).
On Thursday, 3 August 2017 14:59:22 CEST Richard W.M. Jones wrote:> This patch series fixes several problems in the way that supermin > handles kernels. The most pressing problem is that supermin doesn't > handle bogus vmlinuz files which aren't actual kernels. Along the way > there is a lot of clean up. > > The patches look much better if you view them with ‘-w’. > > This series will require plenty of time to be tested in Fedora, > especially on non-x86 arches.Except for the notes for patch #3, the rest LGTM. Thanks, -- Pino Toscano
Pino Toscano
2017-Aug-08 12:59 UTC
Re: [Libguestfs] [PATCH supermin 0/9] kernel: Multiple fixes to handling of kernels (RHBZ#1477758).
On Tuesday, 8 August 2017 14:32:55 CEST Pino Toscano wrote:> On Thursday, 3 August 2017 14:59:22 CEST Richard W.M. Jones wrote: > > This patch series fixes several problems in the way that supermin > > handles kernels. The most pressing problem is that supermin doesn't > > handle bogus vmlinuz files which aren't actual kernels. Along the way > > there is a lot of clean up. > > > > The patches look much better if you view them with ‘-w’. > > > > This series will require plenty of time to be tested in Fedora, > > especially on non-x86 arches. > > Except for the notes for patch #3, the rest LGTM.Forget this, not sure why I sent this note here ... -- Pino Toscano
Seemingly Similar Threads
- [PATCH supermin 0/9] kernel: Multiple fixes to handling of kernels (RHBZ#1477758).
- [PATCH 2/2] kernel: find vmlinuz kernels in modules path (RHBZ#1394699)
- [PATCH 1/2] kernel: refactor build_kernel & find_kernel
- [supermin] Be smarter about finding suitable kernel images
- Re: libguestfs supermin error